Automatic scale adjustment + plot shift
This commit is contained in:
parent
7d66ec91da
commit
da06f3e791
|
@ -4,33 +4,33 @@
|
||||||
#include "OBP60Extensions.h"
|
#include "OBP60Extensions.h"
|
||||||
#include "Pagedata.h"
|
#include "Pagedata.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class CircularBuffer {
|
class CircularBuffer {
|
||||||
// provides a circular buffer to store wind history values
|
// provides a circular buffer to store wind history values
|
||||||
private:
|
private:
|
||||||
static const int SIZE = 202;
|
// static const int SIZE = 202;
|
||||||
int buffer[SIZE];
|
int SIZE;
|
||||||
|
// int buffer[SIZE];
|
||||||
|
std::vector<int> buffer;
|
||||||
int head = 0; // points to the next insertion index
|
int head = 0; // points to the next insertion index
|
||||||
int count = 0; // number of valid elements
|
int count = 0; // number of valid elements
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool begin(int size)
|
bool begin(int size)
|
||||||
// Constructor specifies buffer size
|
// specifies buffer size
|
||||||
{
|
{
|
||||||
if (size <= 0 || size > 1000) {
|
if (size <= 0 || size > 1000) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// SIZE = size;
|
SIZE = size;
|
||||||
// buffer = new int[SIZE]; // allocate buffer
|
buffer.resize(size); // allocate buffer
|
||||||
if (!buffer) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
~CircularBuffer()
|
~CircularBuffer()
|
||||||
{
|
{
|
||||||
// delete[] buffer; // Free allocated memory
|
// delete[] buffer; // Free allocated memory
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(int value)
|
void add(int value)
|
||||||
|
@ -57,6 +57,16 @@ public:
|
||||||
{
|
{
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mvStart(int start)
|
||||||
|
// Move the start index for the buffer forward by <start> positions
|
||||||
|
{
|
||||||
|
head = (head + start) % SIZE;
|
||||||
|
if (count > start)
|
||||||
|
count -= start;
|
||||||
|
else
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PageWindPlot : public Page {
|
class PageWindPlot : public Page {
|
||||||
|
@ -99,24 +109,29 @@ public:
|
||||||
int width = getdisplay().width(); // Get screen width
|
int width = getdisplay().width(); // Get screen width
|
||||||
int height = getdisplay().height(); // Get screen height
|
int height = getdisplay().height(); // Get screen height
|
||||||
int cHeight = height - 98; // height of chart area
|
int cHeight = height - 98; // height of chart area
|
||||||
|
// int cHeight = 50; // height of chart area
|
||||||
int xCenter = width / 2; // Center of screen in x direction
|
int xCenter = width / 2; // Center of screen in x direction
|
||||||
// int yOffset = 76; // Offset for y coordinate to center chart area vertically
|
static const int yOffset = 76; // Offset for y coordinate to center chart area vertically
|
||||||
int yOffset = 275; // Offset for y coordinate to center chart area vertically
|
|
||||||
int x, y, lastX, lastY; // x and y coordinates for drawing
|
|
||||||
static const float radToDeg = 180.0 / M_PI; // Conversion factor from radians to degrees
|
static const float radToDeg = 180.0 / M_PI; // Conversion factor from radians to degrees
|
||||||
|
|
||||||
static int chartRng = 40; // Range of wind values from mid wind value to min/max wind value in degrees
|
static int wndCenter = -400; // chart wind center value position; init value indicates that wndCenter is not set yet
|
||||||
static int chartMidVal; // Mid wind value in degrees
|
static int wndLeft; // chart wind left value position
|
||||||
int chartScl; // Scale for wind values in pixels per degree
|
static int wndRight; // chart wind right value position
|
||||||
int chartVal; // Current wind value
|
static int chrtRng; // Range of wind values from mid wind value to min/max wind value in degrees
|
||||||
|
int diffRng; // Difference between mid and current wind value
|
||||||
|
int x, y; // x and y coordinates for drawing
|
||||||
|
static int lastX, lastY; // Last x and y coordinates for drawing
|
||||||
|
int chrtScl; // Scale for wind values in pixels per degree
|
||||||
|
int chrtVal; // Current wind value
|
||||||
int count; // index for next wind value in buffer
|
int count; // index for next wind value in buffer
|
||||||
|
|
||||||
static CircularBuffer windValues; // Circular buffer to store wind values
|
static CircularBuffer windValues; // Circular buffer to store wind values
|
||||||
/* if (!windValues.begin(cHeight)) { // buffer holds as many values as the height of the chart area
|
// CircularBuffer::SIZE = 202; // Set buffer size to 202 values
|
||||||
|
if (!windValues.begin(cHeight)) { // buffer holds as many values as the height of the chart area
|
||||||
logger->logDebug(GwLog::ERROR, "Failed to initialize wind values buffer");
|
logger->logDebug(GwLog::ERROR, "Failed to initialize wind values buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
LOG_DEBUG(GwLog::LOG, "Display page WindPlot");
|
LOG_DEBUG(GwLog::LOG, "Display page WindPlot");
|
||||||
|
|
||||||
// Get config data
|
// Get config data
|
||||||
|
@ -198,9 +213,37 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store wind value in buffer
|
// Store wind value in buffer
|
||||||
windValues.add(int(value3 * radToDeg)); // Store TWA value (degree) in buffer
|
windValues.add(int((value3 * radToDeg) + 0.5)); // Store TWA value (degree) in buffer (rounded to integer)
|
||||||
count = windValues.size(); // Get number of valid elements in buffer; maximum is cHeight
|
count = windValues.size(); // Get number of valid elements in buffer; maximum is cHeight
|
||||||
|
|
||||||
|
// specify and check chart border values
|
||||||
|
if (wndCenter == -400) {
|
||||||
|
wndCenter = windValues.get(0);
|
||||||
|
chrtRng = 20;
|
||||||
|
wndLeft = wndCenter - chrtRng;
|
||||||
|
if (wndLeft < 0)
|
||||||
|
wndLeft += 360;
|
||||||
|
wndRight = wndCenter + chrtRng;
|
||||||
|
if (wndRight >= 360)
|
||||||
|
wndRight -= 360;
|
||||||
|
|
||||||
|
LOG_DEBUG(GwLog::LOG, "PageWindPlot: wndCenter + chrtRng initialized");
|
||||||
|
}
|
||||||
|
diffRng = abs(windValues.get(count - 1) - wndCenter);
|
||||||
|
if (diffRng > chrtRng) {
|
||||||
|
chrtRng = int(ceil(diffRng / 10.0) * 10); // Round to next 10 degree value
|
||||||
|
wndLeft = wndCenter - chrtRng;
|
||||||
|
if (wndLeft < 0)
|
||||||
|
wndLeft += 360;
|
||||||
|
wndRight = wndCenter + chrtRng;
|
||||||
|
if (wndRight >= 360)
|
||||||
|
wndRight -= 360;
|
||||||
|
}
|
||||||
|
LOG_DEBUG(GwLog::LOG, "PageWindPlot Value3: %f, windValue: %d, count: %d, Range: %d, ChartRng: %d", float(value3 * radToDeg), windValues.get(count - 1), count, diffRng, chrtRng);
|
||||||
|
|
||||||
|
// was, wenn alle Werte kleiner als current wind range sind?
|
||||||
|
// passe wndCenter an, wenn chrtRng > std und alle Werte > oder < wndCenter sind
|
||||||
|
|
||||||
// Optical warning by limit violation (unused)
|
// Optical warning by limit violation (unused)
|
||||||
if (String(flashLED) == "Limit Violation") {
|
if (String(flashLED) == "Limit Violation") {
|
||||||
setBlinkingLED(false);
|
setBlinkingLED(false);
|
||||||
|
@ -211,7 +254,7 @@ public:
|
||||||
if (bvalue1 == NULL)
|
if (bvalue1 == NULL)
|
||||||
return;
|
return;
|
||||||
LOG_DEBUG(GwLog::LOG, "PageWindPlot, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f, cnt: %d, wind: %f", name1.c_str(), value1, name2.c_str(),
|
LOG_DEBUG(GwLog::LOG, "PageWindPlot, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f, cnt: %d, wind: %f", name1.c_str(), value1, name2.c_str(),
|
||||||
value2, name3.c_str(), value3, name4.c_str(), value4, name5.c_str(), value5, count, windValues.get(count-1));
|
value2, name3.c_str(), value3, name4.c_str(), value4, name5.c_str(), value5, count, windValues.get(count - 1));
|
||||||
|
|
||||||
// Draw page
|
// Draw page
|
||||||
//***********************************************************
|
//***********************************************************
|
||||||
|
@ -220,18 +263,18 @@ public:
|
||||||
getdisplay().setPartialWindow(0, 0, width, height); // Set partial update
|
getdisplay().setPartialWindow(0, 0, width, height); // Set partial update
|
||||||
getdisplay().setTextColor(commonData->fgcolor);
|
getdisplay().setTextColor(commonData->fgcolor);
|
||||||
|
|
||||||
// getdisplay().fillRect(0, 20, width, 1, commonData->fgcolor); // Horizontal top line for orientation -> to be deleted
|
getdisplay().fillRect(0, 20, width, 1, commonData->fgcolor); // Horizontal top line for orientation -> to be deleted
|
||||||
|
|
||||||
// Show TWS value on top right
|
// Show TWS value on top right
|
||||||
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
|
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
|
||||||
getdisplay().setCursor(262, 58);
|
getdisplay().setCursor(252, 58);
|
||||||
getdisplay().print(svalue2); // Value
|
getdisplay().print(svalue2); // Value
|
||||||
getdisplay().setFont(&Ubuntu_Bold12pt7b);
|
getdisplay().setFont(&Ubuntu_Bold12pt7b);
|
||||||
getdisplay().setCursor(344, 48);
|
getdisplay().setCursor(334, 48);
|
||||||
getdisplay().print(name2); // Name
|
getdisplay().print(name2); // Name
|
||||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||||
getdisplay().setCursor(340, 59);
|
getdisplay().setCursor(330, 59);
|
||||||
// getdisplay().print(" ");
|
getdisplay().print(" ");
|
||||||
if (holdvalues == false) {
|
if (holdvalues == false) {
|
||||||
getdisplay().print(unit2); // Unit
|
getdisplay().print(unit2); // Unit
|
||||||
} else {
|
} else {
|
||||||
|
@ -242,47 +285,40 @@ public:
|
||||||
getdisplay().fillRect(0, yOffset, width, 2, commonData->fgcolor);
|
getdisplay().fillRect(0, yOffset, width, 2, commonData->fgcolor);
|
||||||
getdisplay().fillRect(xCenter - 1, yOffset, 2, cHeight, commonData->fgcolor);
|
getdisplay().fillRect(xCenter - 1, yOffset, 2, cHeight, commonData->fgcolor);
|
||||||
|
|
||||||
// initial chart labels
|
// chart labels
|
||||||
int twdCenter = windValues.get(0); // TWD center value position
|
|
||||||
int twdLeft = twdCenter - 40; // TWD left value position
|
|
||||||
int twdRight = twdCenter + 40; // TWD right value position
|
|
||||||
getdisplay().setFont(&Ubuntu_Bold10pt7b);
|
getdisplay().setFont(&Ubuntu_Bold10pt7b);
|
||||||
getdisplay().setCursor(xCenter - 15, 73);
|
getdisplay().setCursor(xCenter - 68, yOffset - 3);
|
||||||
getdisplay().print(twdCenter); // TWD center value
|
getdisplay().print(name3); // Wind name
|
||||||
getdisplay().drawCircle(xCenter + 22, 63, 2, commonData->fgcolor); // <degree> symbol
|
getdisplay().setCursor(xCenter - 18, yOffset - 3);
|
||||||
getdisplay().drawCircle(xCenter + 22, 63, 3, commonData->fgcolor); // <degree> symbol
|
getdisplay().print(wndCenter); // Wind center value
|
||||||
getdisplay().setCursor(2, 73);
|
getdisplay().drawCircle(xCenter + 19, 63, 2, commonData->fgcolor); // <degree> symbol
|
||||||
getdisplay().print(twdLeft); // TWD left value
|
getdisplay().drawCircle(xCenter + 19, 63, 3, commonData->fgcolor); // <degree> symbol
|
||||||
getdisplay().drawCircle(40, 63, 2, commonData->fgcolor); // <degree> symbol
|
getdisplay().setCursor(5, yOffset - 3);
|
||||||
getdisplay().drawCircle(40, 63, 3, commonData->fgcolor); // <degree> symbol
|
getdisplay().print(wndLeft); // Wind left value
|
||||||
getdisplay().setCursor(width - 35, 73);
|
getdisplay().drawCircle(44, 63, 2, commonData->fgcolor); // <degree> symbol
|
||||||
getdisplay().print(twdRight); // TWD right value
|
getdisplay().drawCircle(44, 63, 3, commonData->fgcolor); // <degree> symbol
|
||||||
getdisplay().drawCircle(width - 5, 63, 2, commonData->fgcolor); // <degree> symbol
|
getdisplay().setCursor(width - 45, yOffset - 3);
|
||||||
getdisplay().drawCircle(width - 5, 63, 3, commonData->fgcolor); // <degree> symbol
|
getdisplay().print(wndRight); // Wind right value
|
||||||
|
getdisplay().drawCircle(width - 6, 63, 2, commonData->fgcolor); // <degree> symbol
|
||||||
|
getdisplay().drawCircle(width - 6, 63, 3, commonData->fgcolor); // <degree> symbol
|
||||||
|
|
||||||
// Draw wind values in chart
|
// Draw wind values in chart
|
||||||
//***********************************************************
|
//***********************************************************
|
||||||
|
|
||||||
chartMidVal = windValues.get(0); // Get 1st value from buffer for specifcation of chart middle value
|
|
||||||
lastX = xCenter;
|
lastX = xCenter;
|
||||||
lastY = 275 + count;
|
lastY = yOffset + cHeight;
|
||||||
LOG_DEBUG(GwLog::LOG, "PageWindPlot Start: lastX: %d, lastY: %d", lastX, lastY);
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
chartVal = windValues.get(i); // Get value from buffer
|
chrtVal = windValues.get(i); // Get value from buffer
|
||||||
chartScl = xCenter / chartRng; // current scale
|
chrtScl = xCenter / chrtRng; // current scale
|
||||||
// Calculate x and y position for the pointer
|
x = xCenter + ((chrtVal - wndCenter) * chrtScl); // Scale to chart width
|
||||||
x = xCenter + ((chartVal - chartMidVal) * chartScl); // Scale to chart width
|
y = yOffset + cHeight - i; // Position in chart area
|
||||||
// y = yOffset + (count - i); // Position in chart area
|
|
||||||
y = 275 - i; // Position in chart area
|
|
||||||
// Draw the pointer
|
|
||||||
getdisplay().drawLine(lastX, lastY, x, y, commonData->fgcolor);
|
getdisplay().drawLine(lastX, lastY, x, y, commonData->fgcolor);
|
||||||
getdisplay().drawLine(lastX, lastY-1, x, y-1, commonData->fgcolor);
|
getdisplay().drawLine(lastX, lastY - 1, x, y - 1, commonData->fgcolor);
|
||||||
lastX = x;
|
lastX = x;
|
||||||
lastY = y;
|
lastY = y;
|
||||||
// LOG_DEBUG(GwLog::LOG, "PageWindPlot: loop-Counter: %d, X: %d, Y: %d", count, x, y);
|
// LOG_DEBUG(GwLog::LOG, "PageWindPlot: loop-Counter: %d, X: %d, Y: %d", count, x, y);
|
||||||
if (count = 200) {
|
if (i == (cHeight - 1)) { // Reaching chart area top end
|
||||||
count -= 40; // move plotting area down by 40 pixels
|
windValues.mvStart(40); // virtually delete 40 values from buffer
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG_DEBUG(GwLog::LOG, "PageWindPlot End: lastX: %d, lastY: %d, loop-Counter: %d", lastX, lastY, count);
|
LOG_DEBUG(GwLog::LOG, "PageWindPlot End: lastX: %d, lastY: %d, loop-Counter: %d", lastX, lastY, count);
|
||||||
|
|
Loading…
Reference in New Issue