diff --git a/lib/obp60task/PageVoltage.cpp b/lib/obp60task/PageVoltage.cpp new file mode 100644 index 0000000..1bc634a --- /dev/null +++ b/lib/obp60task/PageVoltage.cpp @@ -0,0 +1,140 @@ +#include "Pagedata.h" +#include "OBP60ExtensionPort.h" + +class PageVoltage : public Page +{ + int dummy=0; //an example on how you would maintain some status + //for a page +public: + PageVoltage(CommonData &common){ + common.logger->logDebug(GwLog::LOG,"created PageApparentWind"); + dummy=1; + } + virtual int handleKey(int key){ + if(key == 3){ + dummy++; + return 0; // Commit the key + } + return key; + } + + virtual void displayPage(CommonData &commonData, PageData &pageData) + { + GwConfigHandler *config = commonData.config; + GwLog *logger=commonData.logger; + + // Get config data + bool simulation = config->getBool(config->useSimuData); + String displaycolor = config->getString(config->displaycolor); + bool holdvalues = config->getBool(config->holdvalues); + String flashLED = config->getString(config->flashLED); + int batVoltage = config->getInt(config->batteryVoltage); + String batType = config->getString(config->batteryType); + + // Get voltage value + String name1 = "VBat"; + double value1 = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 + bool valid1 = true; + + // Optical warning by limit violation + if(String(flashLED) == "Limit Violation"){ + if(String(batType) == "Pb" && (value1 < 10.0 || value1 > 14.5)){ + setPortPin(OBP_FLASH_LED, true); + } + else{ + setPortPin(OBP_FLASH_LED, false); + } + } + else{ + setPortPin(OBP_FLASH_LED, false); + } + + // Logging voltage value + if (value1 == NULL) return; + LOG_DEBUG(GwLog::LOG,"Drawing at PageVoltage, p=%s, v=%f", name1, value1); + + // Draw page + //*********************************************************** + + // Clear display, set background color and text color + int textcolor = GxEPD_BLACK; + int pixelcolor = GxEPD_BLACK; + int bgcolor = GxEPD_WHITE; + if(displaycolor == "Normal"){ + textcolor = GxEPD_BLACK; + pixelcolor = GxEPD_BLACK; + bgcolor = GxEPD_WHITE; + } + else{ + textcolor = GxEPD_WHITE; + pixelcolor = GxEPD_WHITE; + bgcolor = GxEPD_BLACK; + } + display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, bgcolor); // Draw white sreen + display.setTextColor(textcolor); + + // Show name + display.setFont(&Ubuntu_Bold32pt7b); + display.setCursor(20, 100); + display.print(name1); // Page name + display.setFont(&Ubuntu_Bold20pt7b); + display.setCursor(270, 100); + // Show unit + display.print("V"); + display.setFont(&DSEG7Classic_BoldItalic60pt7b); + display.setCursor(20, 240); + + // Reading bus data or using simulation data + if(simulation == true){ + value1 = batVoltage; + value1 += float(random(0, 5)) / 10; // Simulation data + display.print(value1,1); + } + else{ + // Check vor valid real data, display also if hold values activated + if(valid1 == true || holdvalues == true){ + // Resolution switching + if(value1 < 10){ + display.print(value1,2); + } + if(value1 >= 10 && value1 < 100){ + display.print(value1,1); + } + if(value1 >= 100){ + display.print(value1,0); + } + } + else{ + display.print("---"); // Missing bus data + } + } + + // Key Layout + display.setFont(&Ubuntu_Bold8pt7b); + display.setCursor(115, 290); + display.print(" [ <<<<<< >>>>>> ]"); + display.setCursor(343, 290); + display.print("[ILUM]"); + + // Update display + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) + }; +}; + +static Page *createPage(CommonData &common){ + return new PageVoltage(common); +} +/** + * with the code below we make this page known to the PageTask + * we give it a type (name) that can be selected in the config + * we define which function is to be called + * and we provide the number of user parameters we expect (0 here) + * and will will provide the names of the fixed values we need + */ +PageDescription registerPageVoltage( + "Voltage", + createPage, + 0, + {}, + true +); \ No newline at end of file diff --git a/lib/obp60task/config.json b/lib/obp60task/config.json index 736a91f..6d49633 100644 --- a/lib/obp60task/config.json +++ b/lib/obp60task/config.json @@ -401,7 +401,7 @@ "Off", "Bus Data", "GPS Fix", - "Limits Overrun" + "Limit Violation" ], "category": "OBP60 Display", "capabilities": { @@ -491,7 +491,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 1", - "list":["oneValue","twoValues","threeValues","forValues","apparentWind"], + "list":["oneValue","twoValues","threeValues","forValues","apparentWind","Voltage"], "category": "OBP60 Page 1", "capabilities": { "obp60":"true" @@ -551,7 +551,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 2", - "list":["oneValue","twoValues","threeValues","forValues","apparentWind"], + "list":["oneValue","twoValues","threeValues","forValues","apparentWind","Voltage"], "category": "OBP60 Page 2", "capabilities": { "obp60":"true" @@ -611,7 +611,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 3", - "list":["oneValue","twoValues","threeValues","forValues","apparentWind"], + "list":["oneValue","twoValues","threeValues","forValues","apparentWind","Voltage"], "category": "OBP60 Page 3", "capabilities": { "obp60":"true" @@ -671,7 +671,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 4", - "list":["oneValue","twoValues","threeValues","forValues","apparentWind"], + "list":["oneValue","twoValues","threeValues","forValues","apparentWind","Voltage"], "category": "OBP60 Page 4", "capabilities": { "obp60":"true" diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 8d58d0b..102a66e 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -39,7 +39,9 @@ bool gps_ready = false; // GPS initialized and ready to use // Hardware initialization before start all services //################################################## void OBP60Init(GwApi *api){ + GwLog *logger = api->getLogger(); api->getLogger()->logDebug(GwLog::LOG,"obp60init running"); + // Define timer interrupts bool uvoltage = api->getConfig()->getConfigItem(api->getConfig()->underVoltage,true)->asBoolean(); if(uvoltage == true){ @@ -56,7 +58,7 @@ void OBP60Init(GwApi *api){ initComplete = false; } else{ - // Start communication + // Init extension port MCP23017Init(); // Settings for 1Wire @@ -243,6 +245,8 @@ void registerAllPages(PageList &list){ list.add(®isterPageForValues); extern PageDescription registerPageApparentWind; list.add(®isterPageApparentWind); + extern PageDescription registerPageVoltage; + list.add(®isterPageVoltage); } // OBP60 Task @@ -368,11 +372,33 @@ void OBP60Task(GwApi *api){ int pageNumber=0; int lastPage=pageNumber; long starttime0 = millis(); // Mainloop - long starttime1 = millis(); // Full disolay refresh + long starttime1 = millis(); // Full display refresh while (true){ if(millis() > starttime0 + 100){ starttime0 = millis(); - //check if there is a keyboard message + + // Send NMEA0183 GPS data on several bus systems + bool gps = api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asBoolean(); + if(gps == true){ // If config enabled + if(gps_ready = true){ + tNMEA0183Msg NMEA0183Msg; + while(NMEA0183.GetMessage(NMEA0183Msg)){ + api->sendNMEA0183Message(NMEA0183Msg); + } + } + } +/* + // LED on by GPS fix + String gpsFix = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString(); + GwApi::BoatValue *pdop=new GwApi::BoatValue(F("PDOP")); + if(String(gpsFix) == "GPS Fix" && pdop->valid == true && int(pdop->value) <= 50){ + setPortPin(OBP_FLASH_LED, true); + } + if(String(gpsFix) == "GPS Fix" && pdop->valid == true && int(pdop->value) > 50){ + setPortPin(OBP_FLASH_LED, false); + } +*/ + // Check the keyboard message int keyboardMessage=0; while (xQueueReceive(allParameters.queue,&keyboardMessage,0)){ LOG_DEBUG(GwLog::LOG,"new key from keyboard %d",keyboardMessage); @@ -428,7 +454,7 @@ void OBP60Task(GwApi *api){ api->getBoatDataValues(boatValues.numValues,boatValues.allBoatValues); api->getStatus(commonData.status); - //handle the pag + //handle the page if (pages[pageNumber].description && pages[pageNumber].description->header){ //build some header and footer using commonData