mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-02-06 12:43:07 +01:00
Merge branch 'norbert-walter:master' into simulation
This commit is contained in:
@@ -141,12 +141,12 @@ void deepSleep(CommonData &common){
|
||||
getdisplay().print("Sleep Mode");
|
||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||
getdisplay().setCursor(65, 175);
|
||||
getdisplay().print("For wakeup press key and wait 5s");
|
||||
getdisplay().print("To wake up press key and wait 5s");
|
||||
getdisplay().nextPage(); // Update display contents
|
||||
getdisplay().powerOff(); // Display power off
|
||||
setPortPin(OBP_POWER_50, false); // Power off ePaper display
|
||||
// Stop system
|
||||
esp_deep_sleep_start(); // Deep Sleep with weakup via touch pin
|
||||
esp_deep_sleep_start(); // Deep Sleep with weakup via touch pin
|
||||
}
|
||||
#endif
|
||||
#ifdef BOARD_OBP40S3
|
||||
@@ -166,7 +166,7 @@ void deepSleep(CommonData &common){
|
||||
getdisplay().print("Sleep Mode");
|
||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||
getdisplay().setCursor(65, 175);
|
||||
getdisplay().print("For wakeup press wheel and wait 5s");
|
||||
getdisplay().print("To wake up press wheel and wait 5s");
|
||||
getdisplay().nextPage(); // Partial update
|
||||
getdisplay().powerOff(); // Display power off
|
||||
setPortPin(OBP_POWER_EPD, false); // Power off ePaper display
|
||||
@@ -341,13 +341,9 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa
|
||||
static unsigned long tcpClTxOld = 0;
|
||||
static unsigned long n2kRxOld = 0;
|
||||
static unsigned long n2kTxOld = 0;
|
||||
int textcolor = GxEPD_BLACK;
|
||||
|
||||
if(commonData.config->getBool(commonData.config->statusLine) == true){
|
||||
|
||||
// Header separator line (optional)
|
||||
// getdisplay().drawLine(0, 19, 399, 19, commonData.fgcolor);
|
||||
|
||||
// Show status info
|
||||
getdisplay().setTextColor(commonData.fgcolor);
|
||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||
@@ -392,13 +388,37 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa
|
||||
getdisplay().drawXBitmap(166, 1, swipe_bits, swipe_width, swipe_height, commonData.fgcolor);
|
||||
}
|
||||
#endif
|
||||
#ifdef LIPO_ACCU_1200
|
||||
if (commonData.data.BatteryChargeStatus == 1) {
|
||||
getdisplay().drawXBitmap(170, 1, battery_loading_bits, battery_width, battery_height, commonData.fgcolor);
|
||||
} else {
|
||||
#ifdef VOLTAGE_SENSOR
|
||||
if (commonData.data.batteryLevelLiPo < 10) {
|
||||
getdisplay().drawXBitmap(170, 1, battery_0_bits, battery_width, battery_height, commonData.fgcolor);
|
||||
} else if (commonData.data.batteryLevelLiPo < 25) {
|
||||
getdisplay().drawXBitmap(170, 1, battery_25_bits, battery_width, battery_height, commonData.fgcolor);
|
||||
} else if (commonData.data.batteryLevelLiPo < 50) {
|
||||
getdisplay().drawXBitmap(170, 1, battery_50_bits, battery_width, battery_height, commonData.fgcolor);
|
||||
} else if (commonData.data.batteryLevelLiPo < 75) {
|
||||
getdisplay().drawXBitmap(170, 1, battery_75_bits, battery_width, battery_height, commonData.fgcolor);
|
||||
} else {
|
||||
getdisplay().drawXBitmap(170, 1, battery_100_bits, battery_width, battery_height, commonData.fgcolor);
|
||||
}
|
||||
#endif // VOLTAGE_SENSOR
|
||||
}
|
||||
#endif // LIPO_ACCU_1200
|
||||
|
||||
// Heartbeat as dot
|
||||
getdisplay().setTextColor(commonData.fgcolor);
|
||||
getdisplay().setFont(&Ubuntu_Bold32pt7b);
|
||||
getdisplay().setCursor(205, 14);
|
||||
getdisplay().print(heartbeat ? "." : " ");
|
||||
heartbeat = !heartbeat;
|
||||
// Heartbeat as page number
|
||||
if (heartbeat) {
|
||||
getdisplay().setTextColor(commonData.bgcolor);
|
||||
getdisplay().fillRect(201, 0, 23, 19, commonData.fgcolor);
|
||||
} else {
|
||||
getdisplay().setTextColor(commonData.fgcolor);
|
||||
getdisplay().drawRect(201, 0, 23, 19, commonData.fgcolor);
|
||||
}
|
||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||
drawTextCenter(211, 9, String(commonData.data.actpage));
|
||||
heartbeat = !heartbeat;
|
||||
|
||||
// Date and time
|
||||
getdisplay().setTextColor(commonData.fgcolor);
|
||||
@@ -442,17 +462,16 @@ void displayFooter(CommonData &commonData) {
|
||||
// horizontal elements
|
||||
const uint16_t top = 280;
|
||||
const uint16_t bottom = 299;
|
||||
// horizontal stub lines
|
||||
getdisplay().drawLine(commonData.keydata[0].x, top, commonData.keydata[0].x+10, top, commonData.fgcolor);
|
||||
getdisplay().drawLine(commonData.keydata[1].x-10, top, commonData.keydata[1].x+10, top, commonData.fgcolor);
|
||||
getdisplay().drawLine(commonData.keydata[2].x-10, top, commonData.keydata[2].x+10, top, commonData.fgcolor);
|
||||
getdisplay().drawLine(commonData.keydata[4].x-10, top, commonData.keydata[4].x+10, top, commonData.fgcolor);
|
||||
getdisplay().drawLine(commonData.keydata[5].x-10, top, commonData.keydata[5].x+10, top, commonData.fgcolor);
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
getdisplay().drawLine(commonData.keydata[i].x-10, top, commonData.keydata[i].x+10, top, commonData.fgcolor);
|
||||
}
|
||||
getdisplay().drawLine(commonData.keydata[5].x + commonData.keydata[5].w - 10, top, commonData.keydata[5].x + commonData.keydata[5].w + 1, top, commonData.fgcolor);
|
||||
// vertical key separators
|
||||
getdisplay().drawLine(commonData.keydata[0].x + commonData.keydata[0].w, top, commonData.keydata[0].x + commonData.keydata[0].w, bottom, commonData.fgcolor);
|
||||
getdisplay().drawLine(commonData.keydata[1].x + commonData.keydata[1].w, top, commonData.keydata[1].x + commonData.keydata[1].w, bottom, commonData.fgcolor);
|
||||
getdisplay().drawLine(commonData.keydata[3].x + commonData.keydata[3].w, top, commonData.keydata[3].x + commonData.keydata[3].w, bottom, commonData.fgcolor);
|
||||
getdisplay().drawLine(commonData.keydata[4].x + commonData.keydata[4].w, top, commonData.keydata[4].x + commonData.keydata[4].w, bottom, commonData.fgcolor);
|
||||
for (int i = 0; i <= 4; i++) {
|
||||
getdisplay().drawLine(commonData.keydata[i].x + commonData.keydata[i].w, top, commonData.keydata[i].x + commonData.keydata[i].w, bottom, commonData.fgcolor);
|
||||
}
|
||||
for (int i = 0; i < 6; i++) {
|
||||
uint16_t x, y;
|
||||
if (commonData.keydata[i].label.length() > 0) {
|
||||
@@ -476,9 +495,6 @@ void displayFooter(CommonData &commonData) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Current page number in a small box
|
||||
getdisplay().drawRect(190, 280, 23, 19, commonData.fgcolor);
|
||||
drawTextCenter(200, 289, String(commonData.data.actpage));
|
||||
} else {
|
||||
getdisplay().setCursor(65, 295);
|
||||
getdisplay().print("Press 1 and 6 fast to unlock keys");
|
||||
|
||||
@@ -100,8 +100,8 @@ void displayFooter(CommonData &commonData);
|
||||
SunData calcSunsetSunrise(GwApi *api, double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise
|
||||
|
||||
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 generatorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic with fill level
|
||||
void solarGraphic(uint x, uint y, int pcolor, int bcolor); // Solar graphic
|
||||
void generatorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic
|
||||
void startLedTask(GwApi *api);
|
||||
|
||||
void doImageRequest(GwApi *api, int *pageno, const PageStruct pages[MAX_PAGE_NUMBER], AsyncWebServerRequest *request);
|
||||
@@ -160,6 +160,46 @@ static std::map<String, unsigned char *> iconmap = {
|
||||
{"AP", ap_bits}
|
||||
};
|
||||
|
||||
// Battery
|
||||
#define battery_width 24
|
||||
#define battery_height 16
|
||||
|
||||
static unsigned char battery_0_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0xff, 0xff, 0x1f,
|
||||
0x03, 0x00, 0x18, 0x03, 0x00, 0x78, 0x03, 0x00, 0xf8, 0x03, 0x00, 0xd8,
|
||||
0x03, 0x00, 0xd8, 0x03, 0x00, 0xd8, 0x03, 0x00, 0xf8, 0x03, 0x00, 0x78,
|
||||
0x03, 0x00, 0x18, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char battery_25_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0xff, 0xff, 0x1f,
|
||||
0x03, 0x00, 0x18, 0x3b, 0x00, 0x78, 0x3b, 0x00, 0xf8, 0x3b, 0x00, 0xd8,
|
||||
0x3b, 0x00, 0xd8, 0x3b, 0x00, 0xd8, 0x3b, 0x00, 0xf8, 0x3b, 0x00, 0x78,
|
||||
0x03, 0x00, 0x18, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char battery_50_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0xff, 0xff, 0x1f,
|
||||
0x03, 0x00, 0x18, 0xbb, 0x03, 0x78, 0xbb, 0x03, 0xf8, 0xbb, 0x03, 0xd8,
|
||||
0xbb, 0x03, 0xd8, 0xbb, 0x03, 0xd8, 0xbb, 0x03, 0xf8, 0xbb, 0x03, 0x78,
|
||||
0x03, 0x00, 0x18, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char battery_75_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0xff, 0xff, 0x1f,
|
||||
0x03, 0x00, 0x18, 0xbb, 0x3b, 0x78, 0xbb, 0x3b, 0xf8, 0xbb, 0x3b, 0xd8,
|
||||
0xbb, 0x3b, 0xd8, 0xbb, 0x3b, 0xd8, 0xbb, 0x3b, 0xf8, 0xbb, 0x3b, 0x78,
|
||||
0x03, 0x00, 0x18, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char battery_100_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0xff, 0xff, 0x1f,
|
||||
0x03, 0x00, 0x18, 0xbb, 0xbb, 0x7b, 0xbb, 0xbb, 0xfb, 0xbb, 0xbb, 0xdb,
|
||||
0xbb, 0xbb, 0xdb, 0xbb, 0xbb, 0xdb, 0xbb, 0xbb, 0xfb, 0xbb, 0xbb, 0x7b,
|
||||
0x03, 0x00, 0x18, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char battery_loading_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xfe, 0xe4, 0x0f, 0xff, 0xec, 0x1f,
|
||||
0x03, 0x08, 0x18, 0x03, 0x18, 0x78, 0x03, 0x30, 0xf8, 0x83, 0x3f, 0xd8,
|
||||
0x03, 0x7f, 0xd8, 0x03, 0x03, 0xd8, 0x03, 0x06, 0xf8, 0x03, 0x04, 0x78,
|
||||
0x03, 0x0c, 0x18, 0xff, 0xcb, 0x1f, 0xfe, 0xd3, 0x0f, 0x00, 0x10, 0x00 };
|
||||
|
||||
// Other symbols
|
||||
#define swipe_width 24
|
||||
#define swipe_height 16
|
||||
|
||||
@@ -277,8 +277,8 @@ void initKeys(CommonData &commonData) {
|
||||
starttime = millis(); // Start key pressed
|
||||
keycodeold = keycode;
|
||||
}
|
||||
// If key pressed longer than 200ms
|
||||
if(millis() > starttime + 200 && keycode == keycodeold) {
|
||||
// If key pressed longer than 100ms
|
||||
if(millis() > starttime + 100 && keycode == keycodeold) {
|
||||
if (use_syspage and keycode == 3) {
|
||||
keystatus = 12;
|
||||
} else {
|
||||
|
||||
@@ -88,8 +88,16 @@ void sensorTask(void *param){
|
||||
double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
|
||||
double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
|
||||
if(String(powsensor1) == "off"){
|
||||
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20
|
||||
sensors.batteryVoltage = sensors.batteryVoltage * vslope + voffset; // Calibration
|
||||
#ifdef VOLTAGE_SENSOR
|
||||
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
|
||||
#else
|
||||
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
|
||||
#endif
|
||||
sensors.batteryVoltage = rawVoltage * vslope + voffset; // Calibration
|
||||
#ifdef LIPO_ACCU_1200
|
||||
sensors.BatteryChargeStatus = 0; // Set to discharging
|
||||
sensors.batteryLevelLiPo = 0; // Level 0...100%
|
||||
#endif
|
||||
sensors.batteryCurrent = 0;
|
||||
sensors.batteryPower = 0;
|
||||
// Fill average arrays with start values
|
||||
@@ -459,19 +467,61 @@ void sensorTask(void *param){
|
||||
// Send supply voltage value all 1s
|
||||
if(millis() > starttime5 + 1000 && String(powsensor1) == "off"){
|
||||
starttime5 = millis();
|
||||
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20
|
||||
sensors.batteryVoltage = sensors.batteryVoltage * vslope + voffset; // Calibration
|
||||
#ifdef VOLTAGE_SENSOR
|
||||
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
|
||||
#else
|
||||
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
|
||||
#endif
|
||||
sensors.batteryVoltage = rawVoltage * vslope + voffset; // Calibration
|
||||
// Save new data in average array
|
||||
batV.reading(int(sensors.batteryVoltage * 100));
|
||||
// Calculate the average values for different time lines from integer values
|
||||
sensors.batteryVoltage10 = batV.getAvg(10) / 100.0;
|
||||
sensors.batteryVoltage60 = batV.getAvg(60) / 100.0;
|
||||
sensors.batteryVoltage300 = batV.getAvg(300) / 100.0;
|
||||
#if defined LIPO_ACCU_1200 && defined VOLTAGE_SENSOR
|
||||
// Polynomfit for LiPo capacity calculation for 3,7V LiPo accus, 0...100%
|
||||
sensors.batteryLevelLiPo = sensors.batteryVoltage60 * 203.8312 -738.1635;
|
||||
// Limiter
|
||||
if(sensors.batteryLevelLiPo > 100){
|
||||
sensors.batteryLevelLiPo = 100;
|
||||
}
|
||||
if(sensors.batteryLevelLiPo < 0){
|
||||
sensors.batteryLevelLiPo = 0;
|
||||
}
|
||||
// Charging detection
|
||||
float deltaV = sensors.batteryVoltage - sensors.batteryVoltage10;
|
||||
// Higher limits for lower voltages
|
||||
if(sensors.batteryVoltage10 < 4.0){
|
||||
if(deltaV > 0.045 && deltaV < 4.15){
|
||||
sensors.BatteryChargeStatus = 1; // Charging active
|
||||
}
|
||||
if(deltaV < -0.04 || deltaV >= 4.15){ // Charging stops by grater than 4,15V
|
||||
sensors.BatteryChargeStatus = 0; // Discharging
|
||||
}
|
||||
}
|
||||
// Lower limits for higher voltages
|
||||
else{
|
||||
if(deltaV > 0.03 && deltaV < 4.15){
|
||||
sensors.BatteryChargeStatus = 1; // Charging active
|
||||
}
|
||||
if(deltaV < -0.03 || deltaV >= 4.15){ // Charging stops by grater than 4,15V
|
||||
sensors.BatteryChargeStatus = 0; // Discharging
|
||||
}
|
||||
}
|
||||
// Send to NMEA200 bus as instance 10
|
||||
if(!isnan(sensors.batteryVoltage)){
|
||||
SetN2kDCBatStatus(N2kMsg, 10, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 0);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
}
|
||||
#endif
|
||||
#ifdef BOARD_OBP60S3
|
||||
// Send to NMEA200 bus
|
||||
if(!isnan(sensors.batteryVoltage)){
|
||||
SetN2kDCBatStatus(N2kMsg, 0, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 1);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Send data from environment sensor all 2s
|
||||
|
||||
@@ -205,6 +205,18 @@ public:
|
||||
getdisplay().setCursor(20, 100);
|
||||
getdisplay().print(name1); // Value name
|
||||
|
||||
#if defined BOARD_OBP40S3 && defined LIPO_ACCU_1200 && defined VOLTAGE_SENSOR
|
||||
// Show charge status
|
||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||
getdisplay().setCursor(185, 100);
|
||||
if(commonData->data.BatteryChargeStatus == true){
|
||||
getdisplay().print("Charge");
|
||||
}
|
||||
else{
|
||||
getdisplay().print("Discharge");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Show unit
|
||||
getdisplay().setFont(&Ubuntu_Bold20pt7b);
|
||||
getdisplay().setCursor(270, 100);
|
||||
@@ -213,7 +225,12 @@ public:
|
||||
// Show battery type
|
||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||
getdisplay().setCursor(295, 100);
|
||||
#ifdef BOARD_OBP60S3
|
||||
getdisplay().print(batType);
|
||||
#endif
|
||||
#if defined BOARD_OBP40S3 && defined LIPO_ACCU_1200 && defined VOLTAGE_SENSOR
|
||||
getdisplay().print("LiPo");
|
||||
#endif
|
||||
|
||||
// Show average settings
|
||||
printAvg(average, 320, 84, true);
|
||||
|
||||
@@ -31,6 +31,8 @@ typedef struct{
|
||||
double batteryVoltage300 = 0; // Sliding average over 300 values
|
||||
double batteryCurrent300 = 0;
|
||||
double batteryPower300 = 0;
|
||||
double batteryLevelLiPo = 0; // Battery level for OBP40 LiPo accu
|
||||
int BatteryChargeStatus = 0; // LiPo charge status: 0 = discharge, 1 = loading activ
|
||||
double solarVoltage = 0;
|
||||
double solarCurrent = 0;
|
||||
double solarPower = 0;
|
||||
@@ -93,6 +95,7 @@ typedef struct{
|
||||
uint16_t fgcolor;
|
||||
uint16_t bgcolor;
|
||||
bool keylock = false;
|
||||
String powermode;
|
||||
} CommonData;
|
||||
|
||||
//a base class that all pages must inherit from
|
||||
@@ -110,7 +113,7 @@ class Page{
|
||||
commonData->keydata[2].label = "#LEFT";
|
||||
commonData->keydata[3].label = "#RIGHT";
|
||||
commonData->keydata[4].label = "";
|
||||
if (commonData->backlight.mode == KEY) {
|
||||
if ((commonData->backlight.mode == KEY) && !(commonData->powermode == "Min Power")) {
|
||||
commonData->keydata[5].label = "ILUM";
|
||||
} else {
|
||||
commonData->keydata[5].label = "";
|
||||
|
||||
@@ -609,10 +609,10 @@
|
||||
"label": "Undervoltage",
|
||||
"type": "boolean",
|
||||
"default": "false",
|
||||
"description": "Switch off device if voltage drops below 9V [on|off]",
|
||||
"description": "Switch off device if LiPo voltage drops below 3.65V [on|off]",
|
||||
"category": "OBP40 Hardware",
|
||||
"capabilities": {
|
||||
"obp40": "false"
|
||||
"obp40":"true"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -78,7 +78,7 @@ void OBP60Init(GwApi *api){
|
||||
}
|
||||
|
||||
#ifdef BOARD_OBP40S3
|
||||
//String sdcard = config->getConfigItem(config->useSDCard, true)->asString();
|
||||
// String sdcard = config->getConfigItem(config->useSDCard, true)->asString();
|
||||
String sdcard = "on";
|
||||
if (sdcard == "on") {
|
||||
SPIClass SD_SPI = SPIClass(HSPI);
|
||||
@@ -310,12 +310,39 @@ void registerAllPages(PageList &list){
|
||||
// Undervoltage detection for shutdown display
|
||||
void underVoltageDetection(GwApi *api, CommonData &common){
|
||||
// Read settings
|
||||
float vslope = uint(api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asFloat());
|
||||
float voffset = uint(api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asFloat());
|
||||
double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
|
||||
double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
|
||||
// Read supply voltage
|
||||
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin
|
||||
actVoltage = actVoltage * vslope + voffset;
|
||||
if(actVoltage < MIN_VOLTAGE){
|
||||
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
|
||||
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
|
||||
float minVoltage = 3.65; // Absolut minimum volatge for 3,7V LiPo accu
|
||||
#else
|
||||
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
|
||||
float minVoltage = MIN_VOLTAGE;
|
||||
#endif
|
||||
double calVoltage = actVoltage * vslope + voffset; // Calibration
|
||||
if(calVoltage < minVoltage){
|
||||
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
|
||||
// Switch off all power lines
|
||||
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
|
||||
setFlashLED(false); // Flash LED Off
|
||||
buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms
|
||||
// Shutdown EInk display
|
||||
getdisplay().setFullWindow(); // Set full Refresh
|
||||
//getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
|
||||
getdisplay().fillScreen(common.bgcolor);// Clear screen
|
||||
getdisplay().setTextColor(common.fgcolor);
|
||||
getdisplay().setFont(&Ubuntu_Bold20pt7b);
|
||||
getdisplay().setCursor(65, 150);
|
||||
getdisplay().print("Undervoltage");
|
||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||
getdisplay().setCursor(65, 175);
|
||||
getdisplay().print("Charge battery and restart system");
|
||||
getdisplay().nextPage(); // Partial update
|
||||
getdisplay().powerOff(); // Display power off
|
||||
setPortPin(OBP_POWER_EPD, false); // Power off ePaper display
|
||||
setPortPin(OBP_POWER_SD, false); // Power off SD card
|
||||
#else
|
||||
// Switch off all power lines
|
||||
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
|
||||
setFlashLED(false); // Flash LED Off
|
||||
@@ -323,13 +350,17 @@ void underVoltageDetection(GwApi *api, CommonData &common){
|
||||
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
|
||||
// Shutdown EInk display
|
||||
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
|
||||
getdisplay().fillScreen(common.bgcolor); // Clear screen
|
||||
getdisplay().fillScreen(common.bgcolor);// Clear screen
|
||||
getdisplay().setTextColor(common.fgcolor);
|
||||
getdisplay().setFont(&Ubuntu_Bold20pt7b);
|
||||
getdisplay().setCursor(65, 150);
|
||||
getdisplay().print("Undervoltage");
|
||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||
getdisplay().setCursor(65, 175);
|
||||
getdisplay().print("To wake up repower system");
|
||||
getdisplay().nextPage(); // Partial update
|
||||
getdisplay().powerOff(); // Display power off
|
||||
#endif
|
||||
// Stop system
|
||||
while(true){
|
||||
esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart).
|
||||
@@ -382,7 +413,8 @@ void OBP60Task(GwApi *api){
|
||||
String fastrefresh = api->getConfig()->getConfigItem(api->getConfig()->fastRefresh,true)->asString();
|
||||
uint fullrefreshtime = uint(api->getConfig()->getConfigItem(api->getConfig()->fullRefreshTime,true)->asInt());
|
||||
#ifdef BOARD_OBP40S3
|
||||
bool syspage_enabled = config->getBool(config->systemPage);
|
||||
// bool syspage_enabled = config->getBool(config->systemPage);
|
||||
bool syspage_enabled = true;
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_GDEY042T81
|
||||
@@ -523,6 +555,7 @@ void OBP60Task(GwApi *api){
|
||||
commonData.backlight.mode = backlightMapping(config->getConfigItem(config->backlight,true)->asString());
|
||||
commonData.backlight.color = colorMapping(config->getConfigItem(config->blColor,true)->asString());
|
||||
commonData.backlight.brightness = 2.55 * uint(config->getConfigItem(config->blBrightness,true)->asInt());
|
||||
commonData.powermode = api->getConfig()->getConfigItem(api->getConfig()->powerMode,true)->asString();
|
||||
|
||||
bool uvoltage = api->getConfig()->getConfigItem(api->getConfig()->underVoltage,true)->asBoolean();
|
||||
String cpuspeed = api->getConfig()->getConfigItem(api->getConfig()->cpuSpeed,true)->asString();
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
#if you want a pio run to only build
|
||||
#your special environments you can set this here
|
||||
#by uncommenting the next line
|
||||
default_envs = obp60_s3
|
||||
|
||||
default_envs =
|
||||
obp60_s3
|
||||
obp40_s3
|
||||
|
||||
[env:obp60_s3]
|
||||
platform = espressif32@6.8.1
|
||||
@@ -91,6 +94,8 @@ build_flags=
|
||||
-D DISABLE_DIAGNOSTIC_OUTPUT #Disable diagnostic output for GxEPD2 lib
|
||||
-D BOARD_OBP40S3 #Board OBP40 V1.0 with ESP32S3 SKU:DIE07300S (CrowPanel 4.2)
|
||||
-D DISPLAY_GDEY042T81 #new E-Ink display from Waveshare, R10 2.2 ohm
|
||||
-D LIPO_ACCU_1200 #Hardware extension, LiPo accu 3,7V 1200mAh
|
||||
-D VOLTAGE_SENSOR #Hardware extension, LiPo voltage sensor with two resistors
|
||||
${env.build_flags}
|
||||
upload_port = /dev/ttyUSB0 #OBP40 download via external USB/Serail converter
|
||||
upload_protocol = esptool #firmware upload via USB OTG seriell, by first upload need to set the ESP32-S3 in the upload mode with shortcut GND to Pin27
|
||||
|
||||
Reference in New Issue
Block a user