This commit is contained in:
norbert-walter 2022-04-18 17:22:24 +02:00
parent 9a20e589da
commit 662dd5e0e2
5 changed files with 270 additions and 24 deletions

View File

@ -415,8 +415,8 @@ void sensorTask(void *param){
if(String(powsensor1) == "INA226" && INA226_1_ready == true){ if(String(powsensor1) == "INA226" && INA226_1_ready == true){
double voltage = ina226_1.getBusVoltage(); double voltage = ina226_1.getBusVoltage();
// Limiter for voltage average building // Limiter for voltage average building
if(voltage < -30){ if(voltage < 0){
voltage = -30; voltage = 0;
} }
if(voltage > 30){ if(voltage > 30){
voltage = 30; voltage = 30;

View File

@ -9,7 +9,6 @@ class PageBattery2 : public Page
bool init = false; // Marker for init done bool init = false; // Marker for init done
bool keylock = false; // Keylock bool keylock = false; // Keylock
int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s, 3=300s 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; double raw = 0;
public: public:
@ -24,12 +23,6 @@ public:
return 0; // Commit the key return 0; // Commit the key
} }
// Trend indicator
if(key == 5){
trend = !trend;
return 0; // Commit the key
}
// Code for keylock // Code for keylock
if(key == 11){ if(key == 11){
keylock = !keylock; // Toggle keylock keylock = !keylock; // Toggle keylock
@ -79,9 +72,6 @@ public:
valueTrend = commonData.data.batteryVoltage10; valueTrend = commonData.data.batteryVoltage10;
} }
// Get raw value for trend indicator
raw = commonData.data.batteryVoltage; // Live data
// Switch average values // Switch average values
switch (average) { switch (average) {
case 0: case 0:
@ -281,11 +271,18 @@ public:
display.print("h"); display.print("h");
// Show sensor type info // Show sensor type info
String i2cAddr = "";
display.setFont(&Ubuntu_Bold8pt7b); display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(270, 60); display.setCursor(270, 60);
if(powerSensor == "off") display.print("Internal"); if(powerSensor == "off") display.print("Internal");
if(powerSensor == "INA219") display.print("INA219"); if(powerSensor == "INA219"){
if(powerSensor == "INA226") display.print("INA226"); display.print("INA219");
}
if(powerSensor == "INA226"){
display.print("INA226");
i2cAddr = " (0x" + String(INA226_I2C_ADDR1, HEX) + ")";
}
display.print(i2cAddr);
display.setCursor(270, 80); display.setCursor(270, 80);
display.print("Sensor Modul"); display.print("Sensor Modul");

247
lib/obp60task/PageSolar.cpp Normal file
View File

@ -0,0 +1,247 @@
#ifdef BOARD_NODEMCU32S_OBP60
#include "Pagedata.h"
#include "OBP60Extensions.h"
class PageSolar : public Page
{
bool init = false; // Marker for init done
bool keylock = false; // Keylock
int solPercentage = 0; // Solar power level
public:
PageSolar(CommonData &common){
common.logger->logDebug(GwLog::LOG,"Show PageSolar");
}
virtual int handleKey(int key){
// Code for keylock
if(key == 11){
keylock = !keylock; // Toggle keylock
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);
String batVoltage = config->getString(config->batteryVoltage);
int solarMaxPower = config->getInt(config->solarPower);
String backlightMode = config->getString(config->backlight);
String powerSensor = config->getString(config->usePowSensor2);
double value1 = 0; // Solar voltage
double value2 = 0; // Solar current
double value3 = 0; // Solar power consumption
// Get values
value1 = commonData.data.batteryVoltage; // Live data
value2 = commonData.data.batteryCurrent;
value3 = commonData.data.batteryPower;
solPercentage = value3 / solarMaxPower * 100; // Power level calculation
if(solPercentage < 0){ // Limiting values
solPercentage = 0;
}
if(solPercentage > 99){
solPercentage = 99;
}
bool valid1 = true;
// Optical warning by limit violation (unused)
if(String(flashLED) == "Limit Violation"){
setBlinkingLED(false);
setPortPin(OBP_FLASH_LED, false);
}
// Logging voltage value
if (value1 == NULL) return;
LOG_DEBUG(GwLog::LOG,"Drawing at PageSolar, V:%f C:%f P:%f", value1, value2, value3);
// 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;
}
// Clear display in obp60task.cpp in main loop
// Show name
display.setTextColor(textcolor);
display.setFont(&Ubuntu_Bold20pt7b);
display.setCursor(10, 65);
display.print("Solar");
// Show voltage type
display.setTextColor(textcolor);
display.setFont(&DSEG7Classic_BoldItalic20pt7b);
display.setCursor(10, 140);
int bvoltage = 0;
if(String(batVoltage) == "12V") bvoltage = 12;
else bvoltage = 24;
display.print(bvoltage);
display.setFont(&Ubuntu_Bold16pt7b);
display.print("V");
// Show solar power level
display.setTextColor(textcolor);
display.setFont(&DSEG7Classic_BoldItalic20pt7b);
display.setCursor(10, 200);
if(solarMaxPower <= 999) display.print(solarMaxPower, 0);
if(solarMaxPower > 999) display.print(float(solarMaxPower/1000.0), 1);
display.setFont(&Ubuntu_Bold16pt7b);
if(solarMaxPower <= 999) display.print("W");
if(solarMaxPower > 999) display.print("kw");
// Show info
display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(10, 235);
display.print("Installed");
display.setCursor(10, 255);
display.print("Solar Type");
// Show battery with fill level
batteryGraphic(150, 45, solPercentage, pixelcolor, bgcolor);
// Show average settings
display.setTextColor(textcolor);
display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(150, 145);
display.print("Avg: 1s");
// Show power level in percent
display.setTextColor(textcolor);
display.setFont(&DSEG7Classic_BoldItalic20pt7b);
display.setCursor(150, 200);
display.print(solPercentage);
display.setFont(&Ubuntu_Bold16pt7b);
display.print("%");
// Show sensor type info
String i2cAddr = "";
display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(270, 60);
if(powerSensor == "off") display.print("Internal");
if(powerSensor == "INA219"){
display.print("INA219");
}
if(powerSensor == "INA226"){
display.print("INA226");
i2cAddr = " (0x" + String(INA226_I2C_ADDR2, HEX) + ")";
}
display.print(i2cAddr);
display.setCursor(270, 80);
display.print("Sensor Modul");
// Reading bus data or using simulation data
display.setTextColor(textcolor);
display.setFont(&DSEG7Classic_BoldItalic20pt7b);
display.setCursor(260, 140);
if(simulation == true){
if(batVoltage == "12V"){
value1 = 12.0;
}
if(batVoltage == "24V"){
value1 = 24.0;
}
value1 += float(random(0, 5)) / 10; // Simulation data
display.print(value1,1);
}
else{
// Check for valid real data, display also if hold values activated
if(valid1 == true || holdvalues == true){
// Resolution switching
if(value1 <= 9.9) display.print(value1, 2);
if(value1 > 9.9 && value1 <= 99.9)display.print(value1, 1);
if(value1 > 99.9) display.print(value1, 0);
}
else{
display.print("---"); // Missing bus data
}
}
display.setFont(&Ubuntu_Bold16pt7b);
display.print("V");
// Show actual current in A
display.setTextColor(textcolor);
display.setFont(&DSEG7Classic_BoldItalic20pt7b);
display.setCursor(260, 200);
if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){
if(value2 <= 9.9) display.print(value2, 2);
if(value2 > 9.9 && value2 <= 99.9)display.print(value2, 1);
if(value2 > 99.9) display.print(value2, 0);
}
else display.print("---");
display.setFont(&Ubuntu_Bold16pt7b);
display.print("A");
// Show actual consumption in W
display.setTextColor(textcolor);
display.setFont(&DSEG7Classic_BoldItalic20pt7b);
display.setCursor(260, 260);
if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){
if(value3 <= 9.9) display.print(value3, 2);
if(value3 > 9.9 && value3 <= 99.9)display.print(value3, 1);
if(value3 > 99.9) display.print(value3, 0);
}
else display.print("---");
display.setFont(&Ubuntu_Bold16pt7b);
display.print("W");
// Key Layout
display.setTextColor(textcolor);
display.setFont(&Ubuntu_Bold8pt7b);
if(keylock == false){
display.setCursor(130, 290);
display.print("[ <<<< " + String(commonData.data.actpage) + "/" + String(commonData.data.maxpage) + " >>>> ]");
if(String(backlightMode) == "Control by Key"){ // Key for illumination
display.setCursor(343, 290);
display.print("[ILUM]");
}
}
else{
display.setCursor(130, 290);
display.print(" [ Keylock active ]");
}
// Update display
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast)
};
};
static Page *createPage(CommonData &common){
return new PageSolar(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 registerPageSolar(
"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)
true // Show display header on/off
);
#endif

View File

@ -726,7 +726,7 @@
"type": "list", "type": "list",
"default": "Voltage", "default": "Voltage",
"description": "Type of page for page 1", "description": "Type of page for page 1",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 1", "category": "OBP60 Page 1",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -786,7 +786,7 @@
"type": "list", "type": "list",
"default": "ApparentWind", "default": "ApparentWind",
"description": "Type of page for page 2", "description": "Type of page for page 2",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 2", "category": "OBP60 Page 2",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -847,7 +847,7 @@
"type": "list", "type": "list",
"default": "OneValue", "default": "OneValue",
"description": "Type of page for page 3", "description": "Type of page for page 3",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 3", "category": "OBP60 Page 3",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -908,7 +908,7 @@
"type": "list", "type": "list",
"default": "OneValue", "default": "OneValue",
"description": "Type of page for page 4", "description": "Type of page for page 4",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 4", "category": "OBP60 Page 4",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -969,7 +969,7 @@
"type": "list", "type": "list",
"default": "OneValue", "default": "OneValue",
"description": "Type of page for page 5", "description": "Type of page for page 5",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 5", "category": "OBP60 Page 5",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -1030,7 +1030,7 @@
"type": "list", "type": "list",
"default": "OneValue", "default": "OneValue",
"description": "Type of page for page 6", "description": "Type of page for page 6",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 6", "category": "OBP60 Page 6",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -1091,7 +1091,7 @@
"type": "list", "type": "list",
"default": "OneValue", "default": "OneValue",
"description": "Type of page for page 7", "description": "Type of page for page 7",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 7", "category": "OBP60 Page 7",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -1152,7 +1152,7 @@
"type": "list", "type": "list",
"default": "OneValue", "default": "OneValue",
"description": "Type of page for page 8", "description": "Type of page for page 8",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 8", "category": "OBP60 Page 8",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -1213,7 +1213,7 @@
"type": "list", "type": "list",
"default": "OneValue", "default": "OneValue",
"description": "Type of page for page 9", "description": "Type of page for page 9",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 9", "category": "OBP60 Page 9",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -1274,7 +1274,7 @@
"type": "list", "type": "list",
"default": "OneValue", "default": "OneValue",
"description": "Type of page for page 10", "description": "Type of page for page 10",
"list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch"], "list":["OneValue","TwoValues","ThreeValues","FourValues","FourValues2","ApparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition","Battery","Battery2","RollPitch","Solar"],
"category": "OBP60 Page 10", "category": "OBP60 Page 10",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"

View File

@ -212,6 +212,8 @@ void registerAllPages(PageList &list){
list.add(&registerPageBattery2); list.add(&registerPageBattery2);
extern PageDescription registerPageRollPitch; extern PageDescription registerPageRollPitch;
list.add(&registerPageRollPitch); list.add(&registerPageRollPitch);
extern PageDescription registerPageSolar;
list.add(&registerPageSolar);
} }
// OBP60 Task // OBP60 Task