Code improvements: commonData, config and logger in page class

This commit is contained in:
Thomas Hooge 2025-08-12 21:35:52 +02:00
parent 15ca3614ba
commit 1ada6e5a82
32 changed files with 285 additions and 368 deletions

View File

@ -19,8 +19,6 @@
class PageAIS : public Page
{
private:
GwConfigHandler *config;
GwLog *logger;
bool simulation = false;
bool holdvalues = false;
String flashLED;
@ -84,11 +82,8 @@ private:
}
public:
PageAIS(CommonData &common)
PageAIS(CommonData &common) : Page(common)
{
commonData = &common;
config = commonData->config;
logger = commonData->logger;
logger->logDebug(GwLog::LOG,"Instantiate PageAIS");
// preload configuration data

View File

@ -51,8 +51,6 @@ static unsigned char anchor_bits[] = {
class PageAnchor : public Page
{
private:
GwConfigHandler *config;
GwLog *logger;
bool simulation = false;
bool holdvalues = false;
String flashLED;
@ -244,11 +242,8 @@ private:
}
public:
PageAnchor(CommonData &common)
PageAnchor(CommonData &common) : Page(common)
{
commonData = &common;
config = commonData->config;
logger = commonData->logger;
logger->logDebug(GwLog::LOG,"Instantiate PageAnchor");
// preload configuration data

View File

@ -12,8 +12,6 @@
class PageAutopilot : public Page
{
private:
GwConfigHandler *config;
GwLog *logger;
bool simulation = false;
bool holdvalues = false;
String flashLED;
@ -48,12 +46,9 @@ private:
}
public:
PageAutopilot(CommonData &common)
PageAutopilot(CommonData &common) : Page(common)
{
commonData = &common;
config = commonData->config;
logger = commonData->logger;
logger->logDebug(GwLog::LOG,"Instantiate PageAutopilot");
logger->logDebug(GwLog::LOG, "Instantiate PageAutopilot");
// preload configuration data
simulation = config->getBool(config->useSimuData);

View File

@ -6,10 +6,10 @@
class PageBME280 : public Page
{
public:
PageBME280(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageBME280");
public:
PageBME280(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG,"Instantiate PageBME280");
}
virtual int handleKey(int key){
@ -22,8 +22,6 @@ class PageBME280 : public Page
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
double value1 = 0;
double value2 = 0;

View File

@ -9,9 +9,9 @@ class PageBattery : public Page
int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s, 3=300s
public:
PageBattery(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageBattery");
PageBattery(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageBattery");
}
virtual void setupKeys(){
@ -36,9 +36,7 @@ class PageBattery : public Page
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
// Old values for hold function
double value1 = 0;
static String svalue1old = "";

View File

@ -13,17 +13,17 @@ bool trend = true; // Trend indicator [0|1], 0=off, 1=on
double raw = 0;
public:
PageBattery2(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageBattery2");
PageBattery2(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageBattery2");
}
virtual void setupKeys(){
void setupKeys(){
Page::setupKeys();
commonData->keydata[0].label = "AVG";
}
virtual int handleKey(int key){
int handleKey(int key) {
// Change average
if(key == 1){
average ++;
@ -45,11 +45,7 @@ public:
return key;
}
int displayPage(PageData &pageData)
{
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
// Polynominal coefficients second order for battery energy level calculation
// index 0 = Pb, 1 = Gel, 2 = AGM, 3 = LiFePo4
float x0[4] = {+3082.5178, +1656.1571, +1316.8766, +14986.9336}; // Offset

View File

@ -17,34 +17,35 @@
class PageClock : public Page
{
bool simulation = false;
int simtime;
bool keylock = false;
char source = 'R'; // time source (R)TC | (G)PS | (N)TP
char mode = 'A'; // display mode (A)nalog | (D)igital | race (T)imer
char tz = 'L'; // time zone (L)ocal | (U)TC
double timezone = 0; // there are timezones with non int offsets, e.g. 5.5 or 5.75
double homelat;
double homelon;
bool homevalid = false; // homelat and homelon are valid
private:
bool simulation = false;
int simtime;
bool keylock = false;
char source = 'R'; // time source (R)TC | (G)PS | (N)TP
char mode = 'A'; // display mode (A)nalog | (D)igital | race (T)imer
char tz = 'L'; // time zone (L)ocal | (U)TC
double timezone = 0; // there are timezones with non int offsets, e.g. 5.5 or 5.75
double homelat;
double homelon;
bool homevalid = false; // homelat and homelon are valid
public:
PageClock(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageClock");
public:
PageClock(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageClock");
// WIP time source
#ifdef BOARD_OBP60S3
String use_rtc = common.config->getString(common.config->useRTC);
String use_rtc = config->getString(config->useRTC);
if (use_rtc == "off") {
source = 'G';
}
#endif
simulation = common.config->getBool(common.config->useSimuData);
timezone = common.config->getString(common.config->timeZone).toDouble();
homelat = common.config->getString(common.config->homeLAT).toDouble();
homelon = common.config->getString(common.config->homeLON).toDouble();
simulation = config->getBool(config->useSimuData);
timezone = config->getString(config->timeZone).toDouble();
homelat = config->getString(config->homeLAT).toDouble();
homelon = config->getString(config->homeLON).toDouble();
homevalid = homelat >= -180.0 and homelat <= 180 and homelon >= -90.0 and homelon <= 90.0;
simtime = 38160; // time value 11:36
}
@ -97,9 +98,6 @@ bool homevalid = false; // homelat and homelon are valid
int displayPage(PageData &pageData)
{
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
static String svalue1old = "";
static String unit1old = "";
static String svalue2old = "";

View File

@ -29,9 +29,9 @@ class PageCompass : public Page
int WhichDataDisplay = ShowHDM;
public:
PageCompass(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageCompass");
PageCompass(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageCompass");
}
virtual void setupKeys(){
@ -63,9 +63,7 @@ class PageCompass : public Page
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
// Old values for hold function
static String OldDataText[HowManyValues] = {"", "", "","", "", ""};
static String OldDataUnits[HowManyValues] = {"", "", "","", "", ""};

View File

@ -7,9 +7,9 @@
class PageDST810 : public Page
{
public:
PageDST810(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageDST810");
PageDST810(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageDST810");
}
virtual int handleKey(int key){
@ -22,8 +22,6 @@ public:
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
// Old values for hold function
static String svalue1old = "";

View File

@ -12,8 +12,6 @@
class PageEPropulsion : public Page
{
private:
GwConfigHandler *config;
GwLog *logger;
bool simulation = false;
bool holdvalues = false;
String flashLED;
@ -48,11 +46,8 @@ private:
}
public:
PageEPropulsion(CommonData &common)
PageEPropulsion(CommonData &common) : Page(common)
{
commonData = &common;
config = commonData->config;
logger = commonData->logger;
logger->logDebug(GwLog::LOG,"Instantiate PageEPropulsion");
// preload configuration data

View File

@ -75,11 +75,11 @@ class PageFluid : public Page
int fluidtype;
public:
PageFluid(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageFluid");
simulation = common.config->getBool(common.config->useSimuData);
holdvalues = common.config->getBool(common.config->holdvalues);
PageFluid(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG,"Instantiate PageFluid");
simulation = config->getBool(config->useSimuData);
holdvalues = config->getBool(config->holdvalues);
simval = double(random(0, 100));
simgoto = double(random(0, 100));
simstep = (simgoto - simval) / 20.0;
@ -95,13 +95,11 @@ class PageFluid : public Page
}
virtual void displayNew(PageData &pageData){
fluidtype = commonData->config->getInt("page" + String(pageData.pageNumber) + "fluid", 0);
commonData->logger->logDebug(GwLog::LOG,"New PageFluid: fluidtype=%d", fluidtype);
fluidtype = config->getInt("page" + String(pageData.pageNumber) + "fluid", 0);
logger->logDebug(GwLog::LOG, "New PageFluid: fluidtype=%d", fluidtype);
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
// Old values for hold function
static double value1old;

View File

@ -7,13 +7,13 @@
class PageFourValues : public Page
{
public:
PageFourValues(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageFourValues");
public:
PageFourValues(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageFourValues");
}
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -23,8 +23,6 @@ class PageFourValues : public Page
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
// Old values for hold function
static String svalue1old = "";

View File

@ -7,10 +7,10 @@
class PageFourValues2 : public Page
{
public:
PageFourValues2(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageFourValues2");
public:
PageFourValues2(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG,"Instantiate PageFourValues2");
}
virtual int handleKey(int key){
@ -23,8 +23,6 @@ class PageFourValues2 : public Page
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
// Old values for hold function
static String svalue1old = "";

View File

@ -8,11 +8,12 @@
class PageGenerator : public Page
{
public:
PageGenerator(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageGenerator");
PageGenerator(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageGenerator");
}
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -21,10 +22,7 @@ public:
return key;
}
int displayPage(PageData &pageData)
{
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
// Get config data
bool simulation = config->getBool(config->useSimuData);

View File

@ -7,13 +7,13 @@
class PageKeelPosition : public Page
{
public:
PageKeelPosition(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageKeelPosition");
PageKeelPosition(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageKeelPosition");
}
// Key functions
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -22,10 +22,7 @@ public:
return key;
}
int displayPage(PageData &pageData)
{
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
double value1 = 0;
double value1old = 0;

View File

@ -8,12 +8,12 @@
class PageOneValue : public Page
{
public:
PageOneValue(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageOneValue");
PageOneValue(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageOneValue");
}
virtual int handleKey(int key){
int handleKey(int key) {
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -22,9 +22,7 @@ class PageOneValue : public Page
return key;
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
// Old values for hold function
static String svalue1old = "";

View File

@ -7,13 +7,13 @@
class PageRollPitch : public Page
{
public:
PageRollPitch(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageRollPitch");
PageRollPitch(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageRollPitch");
}
// Key functions
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -22,9 +22,7 @@ public:
return key;
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
double value1 = 0;
double value2 = 0;
@ -33,7 +31,6 @@ public:
String svalue2 = "";
String svalue2old = "";
// Get config data
String lengthformat = config->getString(config->lengthFormat);
bool simulation = config->getBool(config->useSimuData);

View File

@ -8,13 +8,13 @@
class PageRudderPosition : public Page
{
public:
PageRudderPosition(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Show PageRudderPosition");
PageRudderPosition(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Show PageRudderPosition");
}
// Key functions
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -23,9 +23,7 @@ public:
return key;
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
static String unit1old = "";
double value1 = 0.1;

View File

@ -15,10 +15,10 @@ const int HowManyValues = 6;
class PageSixValues : public Page
{
public:
PageSixValues(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageSixValues");
public:
PageSixValues(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageSixValues");
}
virtual int handleKey(int key){
@ -30,130 +30,127 @@ class PageSixValues : public Page
return key;
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
// Old values for hold function
static String OldDataText[HowManyValues] = {"", "", "", "", "", ""};
static String OldDataUnits[HowManyValues] = {"", "", "", "", "", ""};
// Old values for hold function
static String OldDataText[HowManyValues] = {"", "", "", "", "", ""};
static String OldDataUnits[HowManyValues] = {"", "", "", "", "", ""};
// Get config data
String lengthformat = config->getString(config->lengthFormat);
// 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
String lengthformat = config->getString(config->lengthFormat);
// bool simulation = config->getBool(config->useSimuData);
bool holdvalues = config->getBool(config->holdvalues);
String flashLED = config->getString(config->flashLED);
String backlightMode = config->getString(config->backlight);
GwApi::BoatValue *bvalue;
String DataName[HowManyValues];
double DataValue[HowManyValues];
bool DataValid[HowManyValues];
String DataText[HowManyValues];
String DataUnits[HowManyValues];
String DataFormat[HowManyValues];
GwApi::BoatValue *bvalue;
String DataName[HowManyValues];
double DataValue[HowManyValues];
bool DataValid[HowManyValues];
String DataText[HowManyValues];
String DataUnits[HowManyValues];
String DataFormat[HowManyValues];
for (int i = 0; i < HowManyValues; i++){
bvalue = pageData.values[i];
DataName[i] = xdrDelete(bvalue->getName());
DataName[i] = DataName[i].substring(0, 6); // String length limit for value name
calibrationData.calibrateInstance(bvalue, logger); // Check if boat data value is to be calibrated
DataValue[i] = bvalue->value; // Value as double in SI unit
DataValid[i] = bvalue->valid;
DataText[i] = formatValue(bvalue, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places
DataUnits[i] = formatValue(bvalue, *commonData).unit;
DataFormat[i] = bvalue->getFormat(); // Unit of value
}
for (int i = 0; i < HowManyValues; i++){
bvalue = pageData.values[i];
DataName[i] = xdrDelete(bvalue->getName());
DataName[i] = DataName[i].substring(0, 6); // String length limit for value name
calibrationData.calibrateInstance(bvalue, logger); // Check if boat data value is to be calibrated
DataValue[i] = bvalue->value; // Value as double in SI unit
DataValid[i] = bvalue->valid;
DataText[i] = formatValue(bvalue, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places
DataUnits[i] = formatValue(bvalue, *commonData).unit;
DataFormat[i] = bvalue->getFormat(); // Unit of value
}
// Optical warning by limit violation (unused)
if(String(flashLED) == "Limit Violation"){
setBlinkingLED(false);
setFlashLED(false);
}
// Optical warning by limit violation (unused)
if(String(flashLED) == "Limit Violation"){
setBlinkingLED(false);
setFlashLED(false);
}
if (bvalue == NULL) return PAGE_OK; // WTF why this statement?
if (bvalue == NULL) return PAGE_OK; // WTF why this statement?
// Draw page
//***********************************************************
// Set display in partial refresh mode
epd->setPartialWindow(0, 0, epd->width(), epd->height()); // Set partial update
epd->setTextColor(commonData->fgcolor);
// Draw page
//***********************************************************
for (int i = 0; i < ( HowManyValues / 2 ); i++){
if (i < (HowManyValues / 2) - 1) { // Don't draw horizontal line after last line of values -> standard design
// Horizontal line 3 pix
epd->fillRect(0, SixValues_y1+(i+1)*SixValues_DeltaY, 400, 3, commonData->fgcolor);
}
for (int j = 0; j < 2; j++){
int ValueIndex = i * 2 + j;
int x0 = SixValues_x1 + j * SixValues_DeltaX;
int y0 = SixValues_y1 + i * SixValues_DeltaY;
LOG_DEBUG(GwLog::LOG,"Drawing at PageSixValue: %d %s %f %s", ValueIndex, DataName[ValueIndex], DataValue[ValueIndex], DataFormat[ValueIndex] );
// Show name
epd->setFont(&Ubuntu_Bold12pt8b);
epd->setCursor(x0, y0+25);
epd->print(DataName[ValueIndex]); // Page name
// Show unit
epd->setFont(&Ubuntu_Bold8pt8b);
epd->setCursor(x0, y0+72);
if(holdvalues == false){
epd->print(DataUnits[ValueIndex]); // Unit
}
else{
epd->print(OldDataUnits[ValueIndex]);
}
// Switch font if format for any values
if(DataFormat[ValueIndex] == "formatLatitude" || DataFormat[ValueIndex] == "formatLongitude"){
epd->setFont(&Ubuntu_Bold12pt8b);
epd->setCursor(x0+10, y0+60);
}
else if(DataFormat[ValueIndex] == "formatTime" || DataFormat[ValueIndex] == "formatDate"){
epd->setFont(&Ubuntu_Bold16pt8b);
epd->setCursor(x0+20,y0+55);
}
// pressure in hPa
else if(DataFormat[ValueIndex] == "formatXdr:P:P"){
epd->setFont(&DSEG7Classic_BoldItalic26pt7b);
epd->setCursor(x0+5, y0+70);
}
// RPM
else if(DataFormat[ValueIndex] == "formatXdr:T:R"){
epd->setFont(&DSEG7Classic_BoldItalic16pt7b);
epd->setCursor(x0+25, y0+70);
}
else{
epd->setFont(&DSEG7Classic_BoldItalic26pt7b);
if ( DataText[ValueIndex][0] == '-' )
epd->setCursor(x0+25, y0+70);
else
epd->setCursor(x0+65, y0+70);
}
// Show bus data
if(holdvalues == false){
epd->print(DataText[ValueIndex]); // Real value as formated string
}
else{
epd->print(OldDataText[ValueIndex]); // Old value as formated string
}
if(DataValid[ValueIndex] == true){
OldDataText[ValueIndex] = DataText[ValueIndex]; // Save the old value
OldDataUnits[ValueIndex] = DataUnits[ValueIndex]; // Save the old unit
}
}
// Vertical line 3 pix
epd->fillRect(SixValues_x1+SixValues_DeltaX-8, SixValues_y1+i*SixValues_DeltaY, 3, SixValues_DeltaY, commonData->fgcolor);
// Set display in partial refresh mode
epd->setPartialWindow(0, 0, epd->width(), epd->height()); // Set partial update
epd->setTextColor(commonData->fgcolor);
for (int i = 0; i < ( HowManyValues / 2 ); i++) {
if (i < (HowManyValues / 2) - 1) { // Don't draw horizontal line after last line of values -> standard design
// Horizontal line 3 pix
epd->fillRect(0, SixValues_y1+(i+1)*SixValues_DeltaY, 400, 3, commonData->fgcolor);
}
for (int j = 0; j < 2; j++) {
int ValueIndex = i * 2 + j;
int x0 = SixValues_x1 + j * SixValues_DeltaX;
int y0 = SixValues_y1 + i * SixValues_DeltaY;
LOG_DEBUG(GwLog::LOG, "Drawing at PageSixValue: %d %s %f %s", ValueIndex, DataName[ValueIndex], DataValue[ValueIndex], DataFormat[ValueIndex]);
return PAGE_UPDATE;
};
// Show name
epd->setFont(&Ubuntu_Bold12pt8b);
epd->setCursor(x0, y0+25);
epd->print(DataName[ValueIndex]); // Page name
// Show unit
epd->setFont(&Ubuntu_Bold8pt8b);
epd->setCursor(x0, y0+72);
if (holdvalues == false) {
epd->print(DataUnits[ValueIndex]); // Unit
} else {
epd->print(OldDataUnits[ValueIndex]);
}
// Switch font if format for any values
if (DataFormat[ValueIndex] == "formatLatitude" || DataFormat[ValueIndex] == "formatLongitude") {
epd->setFont(&Ubuntu_Bold12pt8b);
epd->setCursor(x0+10, y0+60);
}
else if (DataFormat[ValueIndex] == "formatTime" || DataFormat[ValueIndex] == "formatDate") {
epd->setFont(&Ubuntu_Bold16pt8b);
epd->setCursor(x0+20,y0+55);
}
// pressure in hPa
else if (DataFormat[ValueIndex] == "formatXdr:P:P") {
epd->setFont(&DSEG7Classic_BoldItalic26pt7b);
epd->setCursor(x0+5, y0+70);
}
// RPM
else if (DataFormat[ValueIndex] == "formatXdr:T:R") {
epd->setFont(&DSEG7Classic_BoldItalic16pt7b);
epd->setCursor(x0+25, y0+70);
}
else {
epd->setFont(&DSEG7Classic_BoldItalic26pt7b);
if (DataText[ValueIndex][0] == '-' ) {
epd->setCursor(x0+25, y0+70);
} else {
epd->setCursor(x0+65, y0+70);
}
}
// Show bus data
if (holdvalues == false) {
epd->print(DataText[ValueIndex]); // Real value as formated string
} else{
epd->print(OldDataText[ValueIndex]); // Old value as formated string
}
if (DataValid[ValueIndex] == true) {
OldDataText[ValueIndex] = DataText[ValueIndex]; // Save the old value
OldDataUnits[ValueIndex] = DataUnits[ValueIndex]; // Save the old unit
}
} // for j
// Vertical line 3 pix
epd->fillRect(SixValues_x1+SixValues_DeltaX-8, SixValues_y1+i*SixValues_DeltaY, 3, SixValues_DeltaY, commonData->fgcolor);
} // for i
return PAGE_UPDATE;
};
};
static Page *createPage(CommonData &common){
return new PageSixValues(common);
}/**

View File

@ -11,9 +11,9 @@
class PageSkyView : public Page
{
public:
PageSkyView(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Show PageSkyView");
PageSkyView(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG,"Instantiate PageSkyView");
}
int handleKey(int key){
@ -26,8 +26,6 @@ public:
}
int displayPage(PageData &pageData) {
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
// Get config data
String flashLED = config->getString(config->flashLED);
@ -41,7 +39,7 @@ public:
}
// Logging boat values
LOG_DEBUG(GwLog::LOG,"Drawing at PageSkyView");
logger->logDebug(GwLog::LOG, "Drawing at PageSkyView");
// Draw page
//***********************************************************

View File

@ -8,11 +8,12 @@
class PageSolar : public Page
{
public:
PageSolar(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageSolar");
PageSolar(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG,"Instantiate PageSolar");
}
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -21,9 +22,7 @@ public:
return key;
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
// Get config data
bool simulation = config->getBool(config->useSimuData);

View File

@ -267,7 +267,7 @@ private:
for (int i = 0 ; i < menu->getItemCount(); i++) {
ConfigMenuItem *itm = menu->getItemByIndex(i);
if (!itm) {
LOG_DEBUG(GwLog::ERROR, "Menu item not found: %d", i);
logger->logDebug(GwLog::ERROR, "Menu item not found: %d", i);
} else {
Rect r = menu->getItemRect(i);
bool inverted = (i == menu->getActiveIndex());
@ -416,36 +416,33 @@ private:
}
public:
PageSystem(CommonData &common){
commonData = &common;
config = commonData->config;
logger = commonData->logger;
PageSystem(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageSystem");
if (hasFRAM) {
mode = fram.read(FRAM_SYSTEM_MODE);
logger->logDebug(GwLog::LOG, "Loaded mode '%c' from FRAM", mode);
}
flashLED = common.config->getString(common.config->flashLED);
flashLED = config->getString(config->flashLED);
chipid = ESP.getEfuseMac();
simulation = common.config->getBool(common.config->useSimuData);
simulation = config->getBool(config->useSimuData);
#ifdef BOARD_OBP40S3
sdcard = common.config->getBool(common.config->useSDCard);
sdcard = config->getBool(config->useSDCard);
#endif
buzzer_mode = common.config->getString(common.config->buzzerMode);
buzzer_mode = config->getString(config->buzzerMode);
buzzer_mode.toLowerCase();
buzzer_power = common.config->getInt(common.config->buzzerPower);
cpuspeed = common.config->getString(common.config->cpuSpeed);
env_module = common.config->getString(common.config->useEnvSensor);
rtc_module = common.config->getString(common.config->useRTC);
gps_module = common.config->getString(common.config->useGPS);
batt_sensor = common.config->getString(common.config->usePowSensor1);
solar_sensor = common.config->getString(common.config->usePowSensor2);
gen_sensor = common.config->getString(common.config->usePowSensor3);
rot_sensor = common.config->getString(common.config->useRotSensor);
homelat = common.config->getString(common.config->homeLAT).toDouble();
homelon = common.config->getString(common.config->homeLON).toDouble();
buzzer_power = config->getInt(config->buzzerPower);
cpuspeed = config->getString(config->cpuSpeed);
env_module = config->getString(config->useEnvSensor);
rtc_module = config->getString(config->useRTC);
gps_module = config->getString(config->useGPS);
batt_sensor = config->getString(config->usePowSensor1);
solar_sensor = config->getString(config->usePowSensor2);
gen_sensor = config->getString(config->usePowSensor3);
rot_sensor = config->getString(config->useRotSensor);
homelat = config->getString(config->homeLAT).toDouble();
homelon = config->getString(config->homeLON).toDouble();
// CPU speed: 80 | 160 | 240
// Power mode: Max | 5V | Min
@ -478,7 +475,7 @@ public:
virtual int handleKey(int key){
// do *NOT* handle key #1 this handled by obp60task as exit
// Switch display mode
commonData->logger->logDebug(GwLog::LOG, "System keyboard handler");
logger->logDebug(GwLog::LOG, "System keyboard handler");
if (key == 2) {
incMode();
return 0;
@ -547,14 +544,12 @@ public:
}
void displayNew(PageData &pageData){
// Get references from API
NMEA2000 = pageData.api->getNMEA2000();
};
int displayPage(PageData &pageData){
// GwConfigHandler *config = commonData->config;
// GwLog *logger = commonData->logger;
NMEA2000 = pageData.api->getNMEA2000();
logger->logDebug(GwLog::LOG, "PageSystem: N2k source address=%d", NMEA2000->GetN2kSource());
// Optical warning by limit violation (unused)
if(flashLED == "Limit Violation"){
@ -563,11 +558,7 @@ public:
}
// Logging page information
logger->logDebug(GwLog::LOG,"Drawing at PageSystem, Mode=%c", mode);
// Get references from API
// NMEA2000 = pageData.api->getNMEA2000();
// LOG_DEBUG(GwLog::LOG,"N2k source address=%d", NMEA2000->GetN2kSource());
logger->logDebug(GwLog::LOG, "Drawing at PageSystem, Mode=%c", mode);
// Set display in partial refresh mode
epd->setPartialWindow(0, 0, epd->width(), epd->height());

View File

@ -8,12 +8,12 @@
class PageThreeValues : public Page
{
public:
PageThreeValues(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageThreeValue");
PageThreeValues(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageThreeValue");
}
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -22,9 +22,7 @@ class PageThreeValues : public Page
return key;
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
// Old values for hold function
static String svalue1old = "";

View File

@ -8,12 +8,12 @@
class PageTwoValues : public Page
{
public:
PageTwoValues(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageTwoValue");
PageTwoValues(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageTwoValue");
}
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -22,9 +22,7 @@ class PageTwoValues : public Page
return key;
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
// Old values for hold function
static String svalue1old = "";

View File

@ -15,12 +15,9 @@ private:
char mode = 'D'; // display mode (A)nalog | (D)igital
public:
PageVoltage(CommonData &common){
commonData = &common;
config = commonData->config;
logger = commonData->logger;
logger->logDebug(GwLog::LOG,"Instantiate PageVoltage");
PageVoltage(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageVoltage");
if (hasFRAM) {
average = fram.read(FRAM_VOLTAGE_AVG);
trend = fram.read(FRAM_VOLTAGE_TREND);
@ -29,17 +26,17 @@ public:
}
~PageVoltage(){
logger->logDebug(GwLog::LOG,"Destroy PageVoltage");
logger->logDebug(GwLog::LOG, "Destroy PageVoltage");
}
virtual void setupKeys(){
void setupKeys(){
Page::setupKeys();
commonData->keydata[0].label = "AVG";
commonData->keydata[1].label = "MODE";
commonData->keydata[4].label = "TRD";
}
virtual int handleKey(int key){
int handleKey(int key){
// Change average
if(key == 1){
average ++;
@ -109,9 +106,7 @@ public:
epd->fillRect(x + 16, y + 11, 6, 3, color);
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
// Get config data
bool simulation = config->getBool(config->useSimuData);

View File

@ -17,9 +17,9 @@ class PageWhite : public Page
char mode = 'W'; // display mode (W)hite | (L)ogo | (M)FD logo
public:
PageWhite(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageWhite");
PageWhite(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageWhite");
refreshtime = 15000;
}
@ -39,8 +39,6 @@ public:
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
// Get config data
String flashLED = config->getString(config->flashLED);

View File

@ -221,9 +221,9 @@ char mode = 'N'; // page mode (N)ormal | (L)ens | e(X)ample
char source = 'A'; // data source (A)pparent | (T)rue
public:
PageWind(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageWind");
PageWind(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageWind");
if (hasFRAM) {
lp = fram.read(FRAM_WIND_SIZE);
source = fram.read(FRAM_WIND_SRC);
@ -231,7 +231,7 @@ public:
}
}
virtual void setupKeys(){
void setupKeys(){
Page::setupKeys();
commonData->keydata[0].label = "MODE";
if (mode == 'X') {
@ -243,7 +243,7 @@ public:
}
// Key functions
virtual int handleKey(int key){
int handleKey(int key){
if(key == 1){ // Mode switch
if(mode == 'N'){
@ -297,10 +297,7 @@ public:
return key;
}
int displayPage(PageData &pageData)
{
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
static String svalue1old = "";
static String unit1old = "";

View File

@ -57,13 +57,12 @@ class PageWindPlot : public Page {
bool showTWS = true; // Show TWS value in chart area
public:
PageWindPlot(CommonData& common)
PageWindPlot(CommonData& common) : Page(common)
{
commonData = &common;
common.logger->logDebug(GwLog::LOG, "Instantiate PageWindPlot");
logger->logDebug(GwLog::LOG, "Instantiate PageWindPlot");
}
virtual void setupKeys()
void setupKeys()
{
Page::setupKeys();
// commonData->keydata[0].label = "MODE";
@ -72,7 +71,7 @@ public:
}
// Key functions
virtual int handleKey(int key)
int handleKey(int key)
{
// Set chart mode TWD | TWS -> to be implemented
if (key == 1) {
@ -114,10 +113,7 @@ public:
return key;
}
int displayPage(PageData& pageData)
{
GwConfigHandler* config = commonData->config;
GwLog* logger = commonData->logger;
int displayPage(PageData& pageData) {
float twsValue; // TWS value in chart area
static String twdName, twdUnit; // TWD name and unit

View File

@ -10,13 +10,13 @@ class PageWindRose : public Page
int16_t lp = 80; // Pointer length
public:
PageWindRose(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageWindRose");
PageWindRose(CommonData &common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageWindRose");
}
// Key functions
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -25,9 +25,7 @@ public:
return key;
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
int displayPage(PageData &pageData) {
static String svalue1old = "";
static String unit1old = "";

View File

@ -10,13 +10,13 @@ class PageWindRoseFlex : public Page
int16_t lp = 80; // Pointer length
public:
PageWindRoseFlex(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageWindRoseFlex");
PageWindRoseFlex(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageWindRoseFlex");
}
// Key functions
virtual int handleKey(int key){
int handleKey(int key){
// Code for keylock
if(key == 11){
commonData->keylock = !commonData->keylock;
@ -26,8 +26,6 @@ public:
}
int displayPage(PageData &pageData){
GwConfigHandler *config = commonData->config;
GwLog *logger = commonData->logger;
static String svalue1old = "";
static String unit1old = "";
@ -142,7 +140,7 @@ public:
// Logging boat values
if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement?
LOG_DEBUG(GwLog::LOG,"Drawing at PageWindRoseFlex, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3, name4.c_str(), value4, name5.c_str(), value5, name6.c_str(), value6);
LOG_DEBUG(GwLog::LOG, "Drawing at PageWindRoseFlex, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3, name4.c_str(), value4, name5.c_str(), value5, name6.c_str(), value6);
// Draw page
//***********************************************************

View File

@ -33,11 +33,11 @@ class PageXTETrack : public Page
bool holdvalues = false;
public:
PageXTETrack(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageXTETrack");
simulation = common.config->getBool(common.config->useSimuData);
holdvalues = common.config->getBool(common.config->holdvalues);
PageXTETrack(CommonData &common) : Page(common)
{
logger->logDebug(GwLog::LOG, "Instantiate PageXTETrack");
simulation = config->getBool(config->useSimuData);
holdvalues = config->getBool(config->holdvalues);
}
void drawSegment(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,

View File

@ -130,6 +130,12 @@ protected:
GwConfigHandler *config;
GwLog *logger;
public:
Page(){}
Page(CommonData &common) {
commonData = &common;
config = commonData->config;
logger = commonData->logger;
}
int refreshtime = 1000;
virtual int displayPage(PageData &pageData)=0;
virtual void displayNew(PageData &pageData){}