PlotShift

This commit is contained in:
Ulrich Meine 2025-06-05 22:51:25 +02:00
parent da06f3e791
commit f153d82825
1 changed files with 23 additions and 17 deletions

View File

@ -9,9 +9,7 @@
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;
int SIZE; int SIZE;
// int buffer[SIZE];
std::vector<int> buffer; 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
@ -28,11 +26,6 @@ public:
return true; return true;
} }
~CircularBuffer()
{
// delete[] buffer; // Free allocated memory
}
void add(int value) void add(int value)
// Add a new value // Add a new value
{ {
@ -58,6 +51,12 @@ public:
return count; return count;
} }
int getSIZE() const
// Get number of SIZE
{
return SIZE;
}
void mvStart(int start) void mvStart(int start)
// Move the start index for the buffer forward by <start> positions // Move the start index for the buffer forward by <start> positions
{ {
@ -70,7 +69,6 @@ public:
}; };
class PageWindPlot : public Page { class PageWindPlot : public Page {
// int16_t lp = 80; // Pointer length
public: public:
PageWindPlot(CommonData& common) PageWindPlot(CommonData& common)
@ -109,7 +107,6 @@ 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
static const 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
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
@ -119,6 +116,8 @@ public:
static int wndRight; // chart wind right value position static int wndRight; // chart wind right value position
static int chrtRng; // Range of wind values from mid wind value to min/max wind value in degrees 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 diffRng; // Difference between mid and current wind value
static bool plotShift = false; // Flag to indicate if the plot has been shifted
int x, y; // x and y coordinates for drawing int x, y; // x and y coordinates for drawing
static int lastX, lastY; // Last 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 chrtScl; // Scale for wind values in pixels per degree
@ -126,13 +125,14 @@ public:
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
// CircularBuffer::SIZE = 202; // Set buffer size to 202 values if (windValues.size() == 0) {
if (!windValues.begin(cHeight)) { // buffer holds as many values as the height of the chart area 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, SIZE = %d", windValues.getSIZE());
// Get config data // Get config data
String lengthformat = config->getString(config->lengthFormat); String lengthformat = config->getString(config->lengthFormat);
@ -226,7 +226,6 @@ public:
wndRight = wndCenter + chrtRng; wndRight = wndCenter + chrtRng;
if (wndRight >= 360) if (wndRight >= 360)
wndRight -= 360; wndRight -= 360;
LOG_DEBUG(GwLog::LOG, "PageWindPlot: wndCenter + chrtRng initialized"); LOG_DEBUG(GwLog::LOG, "PageWindPlot: wndCenter + chrtRng initialized");
} }
diffRng = abs(windValues.get(count - 1) - wndCenter); diffRng = abs(windValues.get(count - 1) - wndCenter);
@ -304,8 +303,14 @@ public:
// Draw wind values in chart // Draw wind values in chart
//*********************************************************** //***********************************************************
if (plotShift) { // If plot was shifted, set lastX to 1st chart wind value
lastX = windValues.get(0); // set to new start of buffer
plotShift = false;
} else {
lastX = xCenter; lastX = xCenter;
lastY = yOffset + cHeight; }
lastY = yOffset + cHeight; // Reset lastY to bottom of chart
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
chrtVal = windValues.get(i); // Get value from buffer chrtVal = windValues.get(i); // Get value from buffer
chrtScl = xCenter / chrtRng; // current scale chrtScl = xCenter / chrtRng; // current scale
@ -318,6 +323,7 @@ public:
// 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 (i == (cHeight - 1)) { // Reaching chart area top end if (i == (cHeight - 1)) { // Reaching chart area top end
windValues.mvStart(40); // virtually delete 40 values from buffer windValues.mvStart(40); // virtually delete 40 values from buffer
plotShift = true; // Set flag to shift plot
continue; continue;
} }
} }