Skip to content

Commit

Permalink
New generator page
Browse files Browse the repository at this point in the history
  • Loading branch information
norbert-walter committed Apr 26, 2024
1 parent 972d7f3 commit d2a17b7
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 116 deletions.
52 changes: 21 additions & 31 deletions lib/obp60task/OBP60Extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/obp60task/OBP60Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion lib/obp60task/OBPSensorTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -384,14 +388,15 @@ 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;i<numberOfDevices; i++){
if(ds18b20.getAddress(tempDeviceAddress, i)){
// Read temperature value in Celsius
tempC = ds18b20.getTempC(tempDeviceAddress);
}
// Send to NMEA200 bus for each sensor with instance number
if(!isnan(tempC)){
sensors.onewireTemp[i] = tempC; // Save values in SensorData
SetN2kPGN130316(N2kMsg, 0, i, N2kts_OutsideTemperature, CToKelvin(tempC), N2kDoubleNA);
api->sendN2kMessage(N2kMsg);
api->getLogger()->logDebug(GwLog::LOG,"DS18B20-%1d Temp: %.1f",i,tempC);
Expand Down Expand Up @@ -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);
Expand Down
86 changes: 29 additions & 57 deletions lib/obp60task/PageGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,30 +34,34 @@ int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s
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
Expand All @@ -84,8 +80,7 @@ int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s
}

// 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
//***********************************************************
Expand All @@ -111,13 +106,10 @@ int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s
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);
Expand All @@ -137,48 +129,29 @@ int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s
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
getdisplay().setFont(&Ubuntu_Bold8pt7b);
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 = "";
Expand All @@ -187,10 +160,11 @@ int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s
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);
Expand Down Expand Up @@ -255,8 +229,6 @@ int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s
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
Expand Down
21 changes: 2 additions & 19 deletions lib/obp60task/PageSolar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,7 +34,6 @@ double raw = 0;
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);

Expand Down Expand Up @@ -153,7 +136,7 @@ double raw = 0;
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
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions lib/obp60task/Pagedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d2a17b7

Please sign in to comment.