diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 72501d0..af27212 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -263,6 +263,7 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa if(commonData.status.usbRx != usbRxOld || commonData.status.usbTx != usbTxOld){ getdisplay().print("USB "); } + String acttime = formatValue(time, commonData).svalue; if(commonData.config->getBool(commonData.config->useGPS) == true && date->valid == true){ getdisplay().print("GPS"); } @@ -393,27 +394,25 @@ void batteryGraphic(uint x, uint y, float percent, int pcolor, int bcolor){ // Solar graphic with fill level void solarGraphic(uint x, uint y, int pcolor, int bcolor){ - // Show battery + // Show solar modul int xb = x; // X position int yb = y; // Y position int t = 4; // Line thickness - int percent = 75; - // Battery corpus 100x80 with fill level + int percent = 0; + // Solar corpus 100x80 int level = int((100.0 - percent) * (80-(2*t)) / 100.0); getdisplay().fillRect(xb, yb, 100, 80, pcolor); if(percent < 99){ getdisplay().fillRect(xb+t, yb+t, 100-(2*t), level, bcolor); } - // Plus pol 20x15 - int xp = xb + 20; - int yp = yb - 15 + t; - getdisplay().fillRect(xp, yp, 20, 15, pcolor); - getdisplay().fillRect(xp+t, yp+t, 20-(2*t), 15-(2*t), bcolor); - // Minus pol 20x15 - int xm = xb + 60; - int ym = yb -15 + t; - getdisplay().fillRect(xm, ym, 20, 15, pcolor); - getdisplay().fillRect(xm+t, ym+t, 20-(2*t), 15-(2*t), bcolor); + // Draw horizontel lines + getdisplay().fillRect(xb, yb+28-t, 100, t, pcolor); + getdisplay().fillRect(xb, yb+54-t, 100, t, pcolor); + // Draw vertical lines + getdisplay().fillRect(xb+19+t, yb, t, 80, pcolor); + getdisplay().fillRect(xb+38+2*t, yb, t, 80, pcolor); + getdisplay().fillRect(xb+57+3*t, yb, t, 80, pcolor); + } // Generator graphic with fill level @@ -422,24 +421,15 @@ void generatorGraphic(uint x, uint y, int pcolor, int bcolor){ int xb = x; // X position int yb = y; // Y position int t = 4; // Line thickness - int percent = 35; - - // Battery corpus 100x80 with fill level - int level = int((100.0 - percent) * (80-(2*t)) / 100.0); - getdisplay().fillRect(xb, yb, 100, 80, pcolor); - if(percent < 99){ - getdisplay().fillRect(xb+t, yb+t, 100-(2*t), level, bcolor); - } - // Plus pol 20x15 - int xp = xb + 20; - int yp = yb - 15 + t; - getdisplay().fillRect(xp, yp, 20, 15, pcolor); - getdisplay().fillRect(xp+t, yp+t, 20-(2*t), 15-(2*t), bcolor); - // Minus pol 20x15 - int xm = xb + 60; - int ym = yb -15 + t; - getdisplay().fillRect(xm, ym, 20, 15, pcolor); - getdisplay().fillRect(xm+t, ym+t, 20-(2*t), 15-(2*t), bcolor); + + // Generator corpus with radius 45 + getdisplay().fillCircle(xb, yb, 45, pcolor); + getdisplay().fillCircle(xb, yb, 41, bcolor); + // Insert G + getdisplay().setTextColor(pcolor); + getdisplay().setFont(&Ubuntu_Bold32pt7b); + getdisplay().setCursor(xb-22, yb+20); + getdisplay().print("G"); } #endif \ No newline at end of file diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index a58b95b..6e73c55 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -63,6 +63,6 @@ SunData calcSunsetSunrise(GwApi *api, double time, double date, double latitude, void batteryGraphic(uint x, uint y, float percent, int pcolor, int bcolor); // Battery graphic with fill level void solarGraphic(uint x, uint y, int pcolor, int bcolor); // Solar graphic with fill level -void gerenratorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic with fill level +void generatorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic with fill level #endif \ No newline at end of file diff --git a/lib/obp60task/OBPSensorTask.cpp b/lib/obp60task/OBPSensorTask.cpp index d807136..f8b5d94 100644 --- a/lib/obp60task/OBPSensorTask.cpp +++ b/lib/obp60task/OBPSensorTask.cpp @@ -94,6 +94,10 @@ void sensorTask(void *param){ ds18b20.begin(); DeviceAddress tempDeviceAddress; numberOfDevices = ds18b20.getDeviceCount(); + // Limit for 8 sensors + if(numberOfDevices > 8){ + numberOfDevices = 8; + } if (numberOfDevices < 1) { oneWire_ready = false; api->getLogger()->logDebug(GwLog::ERROR,"Modul DS18B20 not found, check wiring"); @@ -384,7 +388,7 @@ void sensorTask(void *param){ if(millis() > starttime13 + 1000 && String(oneWireOn) == "DS18B20" && oneWire_ready == true){ starttime13 = millis(); float tempC; - ds18b20.requestTemperatures(); // Collect all temperature values + ds18b20.requestTemperatures(); // Collect all temperature values (max.8) for(int i=0;isendN2kMessage(N2kMsg); api->getLogger()->logDebug(GwLog::LOG,"DS18B20-%1d Temp: %.1f",i,tempC); @@ -420,6 +425,12 @@ void sensorTask(void *param){ } double sysTime = (hour * 3600) + (minute * 60) + second; if(!isnan(daysAt1970) && !isnan(sysTime)){ + sensors.rtcYear = year; // Save values in SensorData + sensors.rtcMonth = month; + sensors.rtcDay = day; + sensors.rtcHour = hour; + sensors.rtcMinute = minute; + sensors.rtcSecond = second; // api->getLogger()->logDebug(GwLog::LOG,"RTC time: %04d/%02d/%02d %02d:%02d:%02d",year, month, day, hour, minute, second); // api->getLogger()->logDebug(GwLog::LOG,"Send PGN126992: %10d %10d",daysAt1970, (uint16_t)sysTime); SetN2kPGN126992(N2kMsg,0,daysAt1970,sysTime,N2ktimes_LocalCrystalClock); diff --git a/lib/obp60task/PageGenerator.cpp b/lib/obp60task/PageGenerator.cpp index 596614b..a12c741 100644 --- a/lib/obp60task/PageGenerator.cpp +++ b/lib/obp60task/PageGenerator.cpp @@ -8,20 +8,12 @@ class PageGenerator : public Page { bool init = false; // Marker for init done bool keylock = false; // Keylock -int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s, 3=300s public: PageGenerator(CommonData &common){ common.logger->logDebug(GwLog::LOG,"Show PageGenerator"); } virtual int handleKey(int key){ - // Change average - if(key == 1){ - average ++; - average = average % 4; // Modulo 4 - return 0; // Commit the key - } - // Code for keylock if(key == 11){ keylock = !keylock; // Toggle keylock @@ -42,30 +34,34 @@ public: String flashLED = config->getString(config->flashLED); String batVoltage = config->getString(config->batteryVoltage); int genPower = config->getInt(config->genPower); - String batType = config->getString(config->batteryType); String backlightMode = config->getString(config->backlight); String powerSensor = config->getString(config->usePowSensor3); - double value1 = 0; // Battery voltage - double value2 = 0; // Battery current - double value3 = 0; // Battery power consumption + double value1 = 0; // Solar voltage + double value2 = 0; // Solar current + double value3 = 0; // Solar output power double valueTrend = 0; // Average over 10 values - int genPercentage = 0; + int genPercentage = 0; // Power generator load // Get voltage value String name1 = "VGen"; - // Read values - value1 = commonData.data.batteryVoltage; // Live data - value2 = commonData.data.batteryCurrent; - value3 = commonData.data.batteryPower; + // Get raw value for trend indicator + if(powerSensor != "off"){ + value1 = commonData.data.generatorVoltage; // Use voltage from external sensor + } + else{ + value1 = commonData.data.batteryVoltage; // Use internal voltage sensor + } + value2 = commonData.data.generatorCurrent; + value3 = commonData.data.generatorPower; genPercentage = value3 * 100 / (double)genPower; // Load value - bool valid1 = true; - // Limits for battery level if(genPercentage < 0) genPercentage = 0; if(genPercentage > 99) genPercentage = 99; + bool valid1 = true; + // Optical warning by limit violation if(String(flashLED) == "Limit Violation"){ // Over voltage @@ -84,8 +80,7 @@ public: } // Logging voltage value - if (value1 == NULL) return; - LOG_DEBUG(GwLog::LOG,"Drawing at PageGenerator, Type:%s %s:=%f", batType, name1, value1); + LOG_DEBUG(GwLog::LOG,"Drawing at PageGenerator, Type:%iW %s:=%f", genPower, name1, value1); // Draw page //*********************************************************** @@ -111,13 +106,10 @@ public: getdisplay().setTextColor(textcolor); getdisplay().setFont(&Ubuntu_Bold20pt7b); getdisplay().setCursor(10, 65); - getdisplay().print("Bat."); - - // Show batery type - getdisplay().setTextColor(textcolor); + getdisplay().print("Power"); getdisplay().setFont(&Ubuntu_Bold8pt7b); - getdisplay().setCursor(90, 65); - getdisplay().print(batType); + getdisplay().setCursor(12, 82); + getdisplay().print("Generator"); // Show voltage type getdisplay().setTextColor(textcolor); @@ -137,7 +129,7 @@ public: if(genPower <= 999) getdisplay().print(genPower, 0); if(genPower > 999) getdisplay().print(float(genPower/1000.0), 1); getdisplay().setFont(&Ubuntu_Bold16pt7b); - if(genPower <= 999) getdisplay().print("w"); + if(genPower <= 999) getdisplay().print("W"); if(genPower > 999) getdisplay().print("kW"); // Show info @@ -145,40 +137,21 @@ public: getdisplay().setCursor(10, 235); getdisplay().print("Installed"); getdisplay().setCursor(10, 255); - getdisplay().print("Battery Type"); + getdisplay().print("Power Modul"); - // Show battery with fill level - batteryGraphic(150, 45, genPercentage, pixelcolor, bgcolor); + // Show generator + generatorGraphic(200, 95, pixelcolor, bgcolor); - // Show average settings - getdisplay().setTextColor(textcolor); - getdisplay().setFont(&Ubuntu_Bold8pt7b); - getdisplay().setCursor(150, 145); - switch (average) { - case 0: - getdisplay().print("Avg: 1s"); - break; - case 1: - getdisplay().print("Avg: 10s"); - break; - case 2: - getdisplay().print("Avg: 60s"); - break; - case 3: - getdisplay().print("Avg: 300s"); - break; - default: - getdisplay().print("Avg: 1s"); - break; - } - - // Show fill level in percent + // Show load level in percent getdisplay().setTextColor(textcolor); getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); getdisplay().setCursor(150, 200); getdisplay().print(genPercentage); getdisplay().setFont(&Ubuntu_Bold16pt7b); getdisplay().print("%"); + getdisplay().setFont(&Ubuntu_Bold8pt7b); + getdisplay().setCursor(150, 235); + getdisplay().print("Load"); // Show sensor type info String i2cAddr = ""; @@ -187,10 +160,11 @@ public: if(powerSensor == "off") getdisplay().print("Internal"); if(powerSensor == "INA219"){ getdisplay().print("INA219"); + i2cAddr = " (0x" + String(INA219_I2C_ADDR3, HEX) + ")"; } if(powerSensor == "INA226"){ getdisplay().print("INA226"); - i2cAddr = " (0x" + String(INA226_I2C_ADDR1, HEX) + ")"; + i2cAddr = " (0x" + String(INA226_I2C_ADDR3, HEX) + ")"; } getdisplay().print(i2cAddr); getdisplay().setCursor(270, 80); @@ -255,8 +229,6 @@ public: getdisplay().setTextColor(textcolor); getdisplay().setFont(&Ubuntu_Bold8pt7b); if(keylock == false){ - getdisplay().setCursor(10, 290); - getdisplay().print("[AVG]"); getdisplay().setCursor(130, 290); getdisplay().print("[ <<<< " + String(commonData.data.actpage) + "/" + String(commonData.data.maxpage) + " >>>> ]"); if(String(backlightMode) == "Control by Key"){ // Key for illumination diff --git a/lib/obp60task/PageSolar.cpp b/lib/obp60task/PageSolar.cpp index f3c9084..007bae5 100644 --- a/lib/obp60task/PageSolar.cpp +++ b/lib/obp60task/PageSolar.cpp @@ -8,28 +8,12 @@ class PageSolar : public Page { bool init = false; // Marker for init done bool keylock = false; // Keylock -int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s, 3=300s -bool trend = true; // Trend indicator [0|1], 0=off, 1=on -double raw = 0; public: PageSolar(CommonData &common){ common.logger->logDebug(GwLog::LOG,"Show PageSolar"); } virtual int handleKey(int key){ - // Change average - if(key == 1){ - average ++; - average = average % 4; // Modulo 4 - return 0; // Commit the key - } - - // Trend indicator - if(key == 5){ - trend = !trend; - return 0; // Commit the key - } - // Code for keylock if(key == 11){ keylock = !keylock; // Toggle keylock @@ -50,7 +34,6 @@ public: String flashLED = config->getString(config->flashLED); String batVoltage = config->getString(config->batteryVoltage); int solPower = config->getInt(config->solarPower); - String batType = config->getString(config->batteryType); String backlightMode = config->getString(config->backlight); String powerSensor = config->getString(config->usePowSensor2); @@ -153,7 +136,7 @@ public: getdisplay().setCursor(10, 255); getdisplay().print("Solar Modul"); - // Show battery with fill level + // Show solar panel solarGraphic(150, 45, pixelcolor, bgcolor); // Show load level in percent @@ -271,7 +254,7 @@ static Page *createPage(CommonData &common){ * and will will provide the names of the fixed values we need */ PageDescription registerPageSolar( - "Solar", // Name of page + "Solar", // Name of page createPage, // Action 0, // Number of bus values depends on selection in Web configuration {}, // Names of bus values undepends on selection in Web configuration (refer GwBoatData.h) diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 54deb1f..e4ff852 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -36,14 +36,15 @@ typedef struct{ double airTemperature = 0; double airHumidity = 0; double airPressure = 0; - double onewireTemp1 = 0; - double onewireTemp2 = 0; - double onewireTemp3 = 0; - double onewireTemp4 = 0; - double onewireTemp5 = 0; - double onewireTemp6 = 0; + double onewireTemp[8] = {0,0,0,0,0,0,0,0}; double rotationAngle = 0; // Rotation angle in radiant - bool validRotAngle = false; // Valid flag magnet present for potation sensor + bool validRotAngle = false; // Valid flag magnet present for rotation sensor + int rtcYear = 0; // UTC time + int rtcMonth = 0; + int rtcDay = 0; + int rtcHour = 0; + int rtcMinute = 0; + int rtcSecond = 0; int sunsetHour = 0; int sunsetMinute = 0; int sunriseHour = 0;