Fix for compass page

This commit is contained in:
norbert-walter 2025-07-04 14:11:22 +02:00
parent 07a1b2388e
commit d1c620a858
3 changed files with 167 additions and 156 deletions

View File

@ -19,8 +19,8 @@ const int ShowDBS = 5;
const int Compass_X0 = 200; // center point of compass band const int Compass_X0 = 200; // center point of compass band
const int Compass_Y0 = 220; // position of compass lines const int Compass_Y0 = 220; // position of compass lines
const int Compass_LineLength = 22; // length of compass lines const int Compass_LineLength = 22; // length of compass lines
const float Compass_LineDelta = 8.0; // compass band: 1deg = 5 Pixels, 10deg = 50 Pixels const float Compass_LineDelta = 8.0;// compass band: 1deg = 5 Pixels, 10deg = 50 Pixels
class PageCompass : public Page class PageCompass : public Page
{ {
@ -65,179 +65,178 @@ class PageCompass : public Page
GwConfigHandler *config = commonData->config; GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger; GwLog *logger = commonData->logger;
// Old values for hold function
static String OldDataText[HowManyValues] = {"", "", "","", "", ""};
static String OldDataUnits[HowManyValues] = {"", "", "","", "", ""};
// Old values for hold function // Get config data
static String OldDataText[HowManyValues] = {"", "", "","", "", ""}; String lengthformat = config->getString(config->lengthFormat);
static String OldDataUnits[HowManyValues] = {"", "", "","", "", ""}; // bool simulation = config->getBool(config->useSimuData);
bool holdvalues = config->getBool(config->holdvalues);
String flashLED = config->getString(config->flashLED);
String backlightMode = config->getString(config->backlight);
// Get config data GwApi::BoatValue *bvalue;
String lengthformat = config->getString(config->lengthFormat); String DataName[HowManyValues];
// bool simulation = config->getBool(config->useSimuData); double DataValue[HowManyValues];
bool holdvalues = config->getBool(config->holdvalues); bool DataValid[HowManyValues];
String flashLED = config->getString(config->flashLED); String DataText[HowManyValues];
String backlightMode = config->getString(config->backlight); String DataUnits[HowManyValues];
String DataFormat[HowManyValues];
FormatedData TheFormattedData;
GwApi::BoatValue *bvalue; for (int i = 0; i < HowManyValues; i++){
String DataName[HowManyValues]; bvalue = pageData.values[i];
double DataValue[HowManyValues]; TheFormattedData = formatValue(bvalue, *commonData);
bool DataValid[HowManyValues]; DataName[i] = xdrDelete(bvalue->getName());
String DataText[HowManyValues]; DataName[i] = DataName[i].substring(0, 6); // String length limit for value name
String DataUnits[HowManyValues]; DataUnits[i] = formatValue(bvalue, *commonData).unit;
String DataFormat[HowManyValues]; DataText[i] = TheFormattedData.svalue; // Formatted value as string including unit conversion and switching decimal places
FormatedData TheFormattedData; DataValue[i] = TheFormattedData.value; // Value as double in SI unit
DataValid[i] = bvalue->valid;
DataFormat[i] = bvalue->getFormat(); // Unit of value
LOG_DEBUG(GwLog::LOG,"Drawing at PageCompass: %d %s %f %s %s", i, DataName[i], DataValue[i], DataFormat[i], DataText[i] );
}
for (int i = 0; i < HowManyValues; i++){ // Optical warning by limit violation (unused)
bvalue = pageData.values[i]; if(String(flashLED) == "Limit Violation"){
TheFormattedData = formatValue(bvalue, *commonData); setBlinkingLED(false);
DataName[i] = xdrDelete(bvalue->getName()); setFlashLED(false);
DataName[i] = DataName[i].substring(0, 6); // String length limit for value name }
DataUnits[i] = formatValue(bvalue, *commonData).unit;
DataText[i] = TheFormattedData.svalue; // Formatted value as string including unit conversion and switching decimal places
DataValue[i] = TheFormattedData.value; // Value as double in SI unit
DataValid[i] = bvalue->valid;
DataFormat[i] = bvalue->getFormat(); // Unit of value
LOG_DEBUG(GwLog::LOG,"Drawing at PageCompass: %d %s %f %s %s", i, DataName[i], DataValue[i], DataFormat[i], DataText[i] );
}
// Optical warning by limit violation (unused) if (bvalue == NULL) return;
if(String(flashLED) == "Limit Violation"){
setBlinkingLED(false);
setFlashLED(false);
}
if (bvalue == NULL) return; //***********************************************************
//*********************************************************** // Set display in partial refresh mode
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
getdisplay().setTextColor(commonData->fgcolor);
// Set display in partial refresh mode // Horizontal line 2 pix top & bottom
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update // Print data on top half
getdisplay().setTextColor(commonData->fgcolor); getdisplay().fillRect(0, 130, 400, 2, commonData->fgcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(10, 70);
getdisplay().print(DataName[WhichDataDisplay]); // Page name
// Show unit
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(10, 120);
getdisplay().print(DataUnits[WhichDataDisplay]);
getdisplay().setCursor(190, 120);
getdisplay().setFont(&DSEG7Classic_BoldItalic42pt7b);
// Horizontal line 3 pix top & bottom if(holdvalues == false){
// print Data on top half getdisplay().print(DataText[WhichDataDisplay]); // Real value as formated string
getdisplay().fillRect(0, 23, 400, 3, commonData->fgcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(10, 70);
getdisplay().print(DataName[WhichDataDisplay]); // Page name
// Show unit
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(10, 120);
getdisplay().print(DataUnits[WhichDataDisplay]);
getdisplay().setCursor(200, 120);
getdisplay().setFont(&DSEG7Classic_BoldItalic42pt7b);
if(holdvalues == false){
getdisplay().print(DataText[WhichDataDisplay]); // Real value as formated string
} }
else{ else{
getdisplay().print(OldDataText[WhichDataDisplay]); // Old value as formated string getdisplay().print(OldDataText[WhichDataDisplay]); // Old value as formated string
} }
if(DataValid[WhichDataDisplay] == true){ if(DataValid[WhichDataDisplay] == true){
OldDataText[WhichDataDisplay] = DataText[WhichDataDisplay]; // Save the old value OldDataText[WhichDataDisplay] = DataText[WhichDataDisplay]; // Save the old value
OldDataUnits[WhichDataDisplay] = DataUnits[WhichDataDisplay]; // Save the old unit OldDataUnits[WhichDataDisplay] = DataUnits[WhichDataDisplay]; // Save the old unit
} }
// now draw compass band
// get the data
double TheAngle = DataValue[WhichDataCompass];
static double AvgAngle = 0;
AvgAngle = ( AvgAngle * AverageValues + TheAngle ) / (AverageValues + 1 );
int TheTrend = round( ( TheAngle - AvgAngle) * 180.0 / M_PI ); // Now draw compass band
// Get the data
double TheAngle = DataValue[WhichDataCompass];
static double AvgAngle = 0;
AvgAngle = ( AvgAngle * AverageValues + TheAngle ) / (AverageValues + 1 );
static const int bsize = 30; int TheTrend = round( ( TheAngle - AvgAngle) * 180.0 / M_PI );
char buffer[bsize+1];
buffer[0]=0;
getdisplay().setFont(&Ubuntu_Bold16pt7b); static const int bsize = 30;
getdisplay().setCursor(10, Compass_Y0-60); char buffer[bsize+1];
getdisplay().print(DataName[WhichDataCompass]); // Page name buffer[0]=0;
getdisplay().setFont(&Ubuntu_Bold16pt7b);
getdisplay().setCursor(10, Compass_Y0-60);
getdisplay().print(DataName[WhichDataCompass]); // Page name
// draw compass base line and pointer // Draw compass base line and pointer
getdisplay().fillRect(0, Compass_Y0, 400, 3, commonData->fgcolor); getdisplay().fillRect(0, Compass_Y0, 400, 3, commonData->fgcolor);
getdisplay().fillTriangle(Compass_X0,Compass_Y0-40,Compass_X0-10,Compass_Y0-80,Compass_X0+10,Compass_Y0-80,commonData->fgcolor); getdisplay().fillTriangle(Compass_X0,Compass_Y0-40,Compass_X0-10,Compass_Y0-80,Compass_X0+10,Compass_Y0-80,commonData->fgcolor);
// draw trendlines // Draw trendlines
for ( int i = 1; i < abs(TheTrend) / 2; i++){ for ( int i = 1; i < abs(TheTrend) / 2; i++){
int x1; int x1;
if ( TheTrend < 0 ) if ( TheTrend < 0 )
x1 = Compass_X0 + 20 * i; x1 = Compass_X0 + 20 * i;
else else
x1 = Compass_X0 - 20 * ( i + 1 ); x1 = Compass_X0 - 20 * ( i + 1 );
getdisplay().fillRect(x1, Compass_Y0 -60, 10, 6, commonData->fgcolor); getdisplay().fillRect(x1, Compass_Y0 -55, 10, 6, commonData->fgcolor);
}
// central line + satellite lines
double NextSector = round(TheAngle / ( M_PI / 9 )) * ( M_PI / 9 ); // get the next 20degree value
double Offset = - ( NextSector - TheAngle); // offest of the center line compared to TheAngle in Radian
int Delta_X = int ( Offset * 180.0 / M_PI * Compass_LineDelta );
for ( int i = 0; i <=4; i++ )
{
int x0;
x0 = Compass_X0 + Delta_X + 2 * i * 5 * Compass_LineDelta;
getdisplay().fillRect(x0-1, Compass_Y0 - 2 * Compass_LineLength,3, 2 * Compass_LineLength, commonData->fgcolor);
x0 = Compass_X0 + Delta_X + ( 2 * i + 1 ) * 5 * Compass_LineDelta;
getdisplay().fillRect(x0-1, Compass_Y0 - Compass_LineLength,3, Compass_LineLength, commonData->fgcolor);
x0 = Compass_X0 + Delta_X - 2 * i * 5 * Compass_LineDelta;
getdisplay().fillRect(x0-1, Compass_Y0 - 2 * Compass_LineLength,3, 2 * Compass_LineLength, commonData->fgcolor);
x0 = Compass_X0 + Delta_X - ( 2 * i + 1 ) * 5 * Compass_LineDelta;
getdisplay().fillRect(x0-1, Compass_Y0 - Compass_LineLength,3, Compass_LineLength, commonData->fgcolor);
} }
// Central line + satellite lines
double NextSector = round(TheAngle / ( M_PI / 9 )) * ( M_PI / 9 ); // Get the next 20degree value
double Offset = - ( NextSector - TheAngle); // Offest of the center line compared to TheAngle in Radian
getdisplay().fillRect(0, Compass_Y0, 400, 3, commonData->fgcolor); int Delta_X = int ( Offset * 180.0 / M_PI * Compass_LineDelta );
// add the numbers to the compass band for ( int i = 0; i <=4; i++ ){
int x0; int x0;
float AngleToDisplay = NextSector * 180.0 / M_PI; x0 = Compass_X0 + Delta_X + 2 * i * 5 * Compass_LineDelta;
getdisplay().fillRect(x0-2, Compass_Y0 - 2 * Compass_LineLength, 5, 2 * Compass_LineLength, commonData->fgcolor);
x0 = Compass_X0 + Delta_X + ( 2 * i + 1 ) * 5 * Compass_LineDelta;
getdisplay().fillRect(x0-1, Compass_Y0 - Compass_LineLength, 3, Compass_LineLength, commonData->fgcolor);
x0 = Compass_X0 + Delta_X; x0 = Compass_X0 + Delta_X - 2 * i * 5 * Compass_LineDelta;
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b); getdisplay().fillRect(x0-2, Compass_Y0 - 2 * Compass_LineLength, 5, 2 * Compass_LineLength, commonData->fgcolor);
x0 = Compass_X0 + Delta_X - ( 2 * i + 1 ) * 5 * Compass_LineDelta;
getdisplay().fillRect(x0-1, Compass_Y0 - Compass_LineLength, 3, Compass_LineLength, commonData->fgcolor);
}
do { getdisplay().fillRect(0, Compass_Y0, 400, 3, commonData->fgcolor);
getdisplay().setCursor(x0 - 40, Compass_Y0 + 40); // Add the numbers to the compass band
snprintf(buffer,bsize,"%03.0f", AngleToDisplay); int x0;
getdisplay().print(buffer); float AngleToDisplay = NextSector * 180.0 / M_PI;
AngleToDisplay += 20;
if ( AngleToDisplay >= 360.0 )
AngleToDisplay -= 360.0;
x0 -= 4 * 5 * Compass_LineDelta;
} while ( x0 >= 0 - 60 );
AngleToDisplay = NextSector * 180.0 / M_PI - 20; x0 = Compass_X0 + Delta_X;
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
do {
getdisplay().setCursor(x0 - 40, Compass_Y0 + 40);
snprintf(buffer,bsize,"%03.0f", AngleToDisplay);
getdisplay().print(buffer);
AngleToDisplay += 20;
if ( AngleToDisplay >= 360.0 )
AngleToDisplay -= 360.0;
x0 -= 4 * 5 * Compass_LineDelta;
} while ( x0 >= 0 - 60 );
AngleToDisplay = NextSector * 180.0 / M_PI - 20;
if ( AngleToDisplay < 0 )
AngleToDisplay += 360.0;
x0 = Compass_X0 + Delta_X + 4 * 5 * Compass_LineDelta;
do {
getdisplay().setCursor(x0 - 40, Compass_Y0 + 40);
snprintf(buffer,bsize,"%03.0f", AngleToDisplay);
// Quick and dirty way to prevent wrapping text in next line
if ( ( x0 - 40 ) > 380 )
buffer[0] = 0;
else if ( ( x0 - 40 ) > 355 )
buffer[1] = 0;
else if ( ( x0 - 40 ) > 325 )
buffer[2] = 0;
getdisplay().print(buffer);
AngleToDisplay -= 20;
if ( AngleToDisplay < 0 ) if ( AngleToDisplay < 0 )
AngleToDisplay += 360.0; AngleToDisplay += 360.0;
x0 += 4 * 5 * Compass_LineDelta;
} while (x0 < ( 400 - 20 -40 ) );
x0 = Compass_X0 + Delta_X + 4 * 5 * Compass_LineDelta; // static int x_test = 320;
do { // x_test += 2;
getdisplay().setCursor(x0 - 40, Compass_Y0 + 40);
snprintf(buffer,bsize,"%03.0f", AngleToDisplay);
// quick and dirty way to prevent wrapping text in next line
if ( ( x0 - 40 ) > 380 )
buffer[0] = 0;
else if ( ( x0 - 40 ) > 355 )
buffer[1] = 0;
else if ( ( x0 - 40 ) > 325 )
buffer[2] = 0;
getdisplay().print(buffer); // snprintf(buffer,bsize,"%03d", x_test);
// getdisplay().setCursor(x_test, Compass_Y0 - 60);
// getdisplay().print(buffer);
// if ( x_test > 390)
// x_test = 320;
AngleToDisplay -= 20; // Update display
if ( AngleToDisplay < 0 ) getdisplay().nextPage(); // Partial update (fast)
AngleToDisplay += 360.0;
x0 += 4 * 5 * Compass_LineDelta;
} while (x0 < ( 400 - 20 -40 ) );
// static int x_test = 320;
// x_test += 2;
// snprintf(buffer,bsize,"%03d", x_test);
// getdisplay().setCursor(x_test, Compass_Y0 - 60);
// getdisplay().print(buffer);
// if ( x_test > 390)
// x_test = 320;
// Update display
getdisplay().nextPage(); // Partial update (fast)
}; };

View File

@ -1187,6 +1187,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -1466,6 +1467,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -1742,6 +1744,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -2015,6 +2018,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -2285,6 +2289,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -2552,6 +2557,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -2816,6 +2822,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -3077,6 +3084,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -3335,6 +3343,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",
@ -3590,6 +3599,7 @@
"Battery", "Battery",
"Battery2", "Battery2",
"Clock", "Clock",
"Compass",
"DST810", "DST810",
"Fluid", "Fluid",
"FourValues", "FourValues",

View File

@ -285,6 +285,8 @@ void registerAllPages(PageList &list){
list.add(&registerPageDST810); list.add(&registerPageDST810);
extern PageDescription registerPageClock; extern PageDescription registerPageClock;
list.add(&registerPageClock); list.add(&registerPageClock);
extern PageDescription registerPageCompass;
list.add(&registerPageCompass);
extern PageDescription registerPageWhite; extern PageDescription registerPageWhite;
list.add(&registerPageWhite); list.add(&registerPageWhite);
extern PageDescription registerPageBME280; extern PageDescription registerPageBME280;