From 4aefc992125b8fa9295e1f5a1ecd70395775d99c Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Tue, 8 Jul 2025 19:41:18 +0200 Subject: [PATCH 1/6] Add home location to system page --- lib/obp60task/OBP60Formater.cpp | 12 ++++++++++++ lib/obp60task/PageSystem.cpp | 26 ++++++++++++++++++++------ lib/obp60task/Pagedata.h | 2 ++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/obp60task/OBP60Formater.cpp b/lib/obp60task/OBP60Formater.cpp index 6ac51a8..3fb5cff 100644 --- a/lib/obp60task/OBP60Formater.cpp +++ b/lib/obp60task/OBP60Formater.cpp @@ -37,6 +37,18 @@ String formatTime(char fmttype, uint8_t hour, uint8_t minute, uint8_t second) { return String(buffer); } +String formatLatitude(double lat) { + float degree = abs(int(lat)); + float minute = abs((lat - int(lat)) * 60); + return String(degree, 0) + "\x90 " + String(minute, 4) + "' " + ((lat > 0) ? "N" : "S"); +} + +String formatLongitude(double lon) { + float degree = abs(int(lon)); + float minute = abs((lon - int(lon)) * 60); + return String(degree, 0) + "\x90 " + String(minute, 4) + "' " + ((lon > 0) ? "E" : "W"); +} + FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ GwLog *logger = commondata.logger; FormatedData result; diff --git a/lib/obp60task/PageSystem.cpp b/lib/obp60task/PageSystem.cpp index 519bee1..7e58d15 100644 --- a/lib/obp60task/PageSystem.cpp +++ b/lib/obp60task/PageSystem.cpp @@ -43,6 +43,8 @@ String batt_sensor; String solar_sensor; String gen_sensor; String rot_sensor; +double homelat; +double homelon; char mode = 'N'; // (N)ormal, (S)ettings, (D)evice list, (C)ard @@ -69,6 +71,8 @@ public: solar_sensor = common.config->getString(common.config->usePowSensor2); gen_sensor = common.config->getString(common.config->usePowSensor3); rot_sensor = common.config->getString(common.config->useRotSensor); + homelat = common.config->getString(common.config->homeLAT).toDouble(); + homelon = common.config->getString(common.config->homeLON).toDouble(); } virtual void setupKeys(){ @@ -295,34 +299,44 @@ public: // left column getdisplay().setCursor(x0, y0); getdisplay().print("Simulation:"); - getdisplay().setCursor(140, y0); + getdisplay().setCursor(120, y0); getdisplay().print(simulation ? "on" : "off"); getdisplay().setCursor(x0, y0 + 16); getdisplay().print("Environment:"); - getdisplay().setCursor(140, y0 + 16); + getdisplay().setCursor(120, y0 + 16); getdisplay().print(env_module); getdisplay().setCursor(x0, y0 + 32); getdisplay().print("Buzzer:"); - getdisplay().setCursor(140, y0 + 32); + getdisplay().setCursor(120, y0 + 32); getdisplay().print(buzzer_mode); getdisplay().setCursor(x0, y0 + 64); getdisplay().print("GPS:"); - getdisplay().setCursor(140, y0 + 64); + getdisplay().setCursor(120, y0 + 64); getdisplay().print(gps_module); getdisplay().setCursor(x0, y0 + 80); getdisplay().print("RTC:"); - getdisplay().setCursor(140, y0 + 80); + getdisplay().setCursor(120, y0 + 80); getdisplay().print(rtc_module); getdisplay().setCursor(x0, y0 + 96); getdisplay().print("Wifi:"); - getdisplay().setCursor(140, y0 + 96); + getdisplay().setCursor(120, y0 + 96); getdisplay().print(commonData->status.wifiApOn ? "on" : "off"); + // Home location + getdisplay().setCursor(x0, y0 + 128); + getdisplay().print("Home Lat.:"); + getdisplay().setCursor(120, y0 + 128); + getdisplay().print(formatLatitude(homelat)); + getdisplay().setCursor(x0, y0 + 144); + getdisplay().print("Home Lon.:"); + getdisplay().setCursor(120, y0 + 144); + getdisplay().print(formatLongitude(homelon)); + // right column getdisplay().setCursor(202, y0); getdisplay().print("Batt. sensor:"); diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 65bdc67..7387b28 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -168,6 +168,8 @@ class PageStruct{ // Standard format functions without overhead String formatDate(String fmttype, uint16_t year, uint8_t month, uint8_t day); String formatTime(char fmttype, uint8_t hour, uint8_t minute, uint8_t second); +String formatLatitude(double lat); +String formatLongitude(double lon); // Structure for formatted boat values typedef struct{ From 8e34fa936d4c5071eba6c82a8a6ed75005f7ca0e Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Wed, 9 Jul 2025 16:13:32 +0200 Subject: [PATCH 2/6] Add display library version info to page system --- extra_script.py.new | 26 +++++++++++++++----------- lib/obp60task/PageSystem.cpp | 9 ++++++--- lib/obp60task/extra_task.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 lib/obp60task/extra_task.py diff --git a/extra_script.py.new b/extra_script.py.new index 31ae608..ae08e44 100644 --- a/extra_script.py.new +++ b/extra_script.py.new @@ -520,19 +520,23 @@ prebuild(env) board="PLATFORM_BOARD_%s"%env["BOARD"].replace("-","_").upper() print("Board=#%s#"%board) print("BuildFlags=%s"%(" ".join(env["BUILD_FLAGS"]))) - -epdtype = "unknown" -pcbvers = "unknown" -for x in env["BUILD_FLAGS"]: - if x.startswith("-D HARDWARE_"): - pcbvers = x.split('_')[1] - if x.startswith("-D DISPLAY_"): - epdtype = x.split('_')[1] - env.Append( LINKFLAGS=[ "-u", "custom_app_desc" ], - CPPDEFINES=[(board,"1"), ("BOARD", env["BOARD"]), ("EPDTYPE", epdtype), - ("PCBVERS", pcbvers)] + CPPDEFINES=[(board,"1")] ) #script does not run on clean yet - maybe in the future env.AddPostAction("clean",cleangenerated) + +#look for extra task scripts and include them here +for taskdir in userTaskDirs: + script = os.path.join(taskdir, "extra_task.py") + if os.path.isfile(script): + taskname = os.path.basename(os.path.normpath(taskdir)) + print("#extra task script for '{}'".format(taskname)) + with open(script) as fh: + try: + code = compile(fh.read(), task, 'exec') + except SyntaxError: + print("#ERROR: script does not compile") + continue + exec(code) diff --git a/lib/obp60task/PageSystem.cpp b/lib/obp60task/PageSystem.cpp index 7e58d15..417c1b0 100644 --- a/lib/obp60task/PageSystem.cpp +++ b/lib/obp60task/PageSystem.cpp @@ -17,6 +17,7 @@ #define BOARDINFO STRINGIZE(BOARD) #define PCBINFO STRINGIZE(PCBVERS) #define DISPLAYINFO STRINGIZE(EPDTYPE) +#define GXEPD2INFO STRINGIZE(GXEPD2VERS) /* * Special system page, called directly with fast key sequence 5,4 @@ -207,19 +208,21 @@ public: getdisplay().setCursor(8, 95); getdisplay().print("Firmware version: "); - getdisplay().setCursor(160, 95); + getdisplay().setCursor(150, 95); getdisplay().print(VERSINFO); getdisplay().setCursor(8, 113); getdisplay().print("Board version: "); - getdisplay().setCursor(160, 113); + getdisplay().setCursor(150, 113); getdisplay().print(BOARDINFO); getdisplay().print(String(" HW ") + String(PCBINFO)); getdisplay().setCursor(8, 131); getdisplay().print("Display version: "); - getdisplay().setCursor(160, 131); + getdisplay().setCursor(150, 131); getdisplay().print(DISPLAYINFO); + getdisplay().print("; GxEPD2 v"); + getdisplay().print(GXEPD2INFO); getdisplay().setCursor(8, 265); #ifdef BOARD_OBP60S3 diff --git a/lib/obp60task/extra_task.py b/lib/obp60task/extra_task.py new file mode 100644 index 0000000..28e9980 --- /dev/null +++ b/lib/obp60task/extra_task.py @@ -0,0 +1,30 @@ +# PlatformIO extra script for obp60task + +epdtype = "unknown" +pcbvers = "unknown" +for x in env["BUILD_FLAGS"]: + if x.startswith("-D HARDWARE_"): + pcbvers = x.split('_')[1] + if x.startswith("-D DISPLAY_"): + epdtype = x.split('_')[1] + +propfilename = os.path.join(env["PROJECT_LIBDEPS_DIR"], env["PIOENV"], "GxEPD2/library.properties") +properties = {} +with open(propfilename, 'r') as file: + for line in file: + match = re.match(r'^([^=]+)=(.*)$', line) + if match: + key = match.group(1).strip() + value = match.group(2).strip() + properties[key] = value + +gxepd2vers = "unknown" +try: + if properties["name"] == "GxEPD2": + gxepd2vers = properties["version"] +except: + pass + +env["CPPDEFINES"].extend([("BOARD", env["BOARD"]), ("EPDTYPE", epdtype), ("PCBVERS", pcbvers), ("GXEPD2VERS", gxepd2vers)]) + +print("added hardware info to CPPDEFINES") From 7ca0a4d09a7beb1e85551a3018a62ba489a9b587 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Wed, 9 Jul 2025 16:23:11 +0200 Subject: [PATCH 3/6] Fix variable name in extra_script.py.new --- extra_script.py.new | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra_script.py.new b/extra_script.py.new index ae08e44..dd9a90b 100644 --- a/extra_script.py.new +++ b/extra_script.py.new @@ -535,7 +535,7 @@ for taskdir in userTaskDirs: print("#extra task script for '{}'".format(taskname)) with open(script) as fh: try: - code = compile(fh.read(), task, 'exec') + code = compile(fh.read(), taskname, 'exec') except SyntaxError: print("#ERROR: script does not compile") continue From 7f954e702d35fd3bb12a2bf85cddda4f011206f3 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Fri, 11 Jul 2025 18:37:12 +0200 Subject: [PATCH 4/6] Add debugging info --- lib/obp60task/debugging.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lib/obp60task/debugging.txt diff --git a/lib/obp60task/debugging.txt b/lib/obp60task/debugging.txt new file mode 100644 index 0000000..c0a22e0 --- /dev/null +++ b/lib/obp60task/debugging.txt @@ -0,0 +1,6 @@ +Debugging tool +############## + +log.txt = text file with error messages from terminal console + +tools/decoder.py -p ESP32S3 -t ~/.platformio/packages/toolchain-xtensa-esp32s3/ -e .pio/build/obp60_s3/firmware.elf log.txt \ No newline at end of file From 71946248e2cffa0a7da8911d3573cc999117836e Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Mon, 14 Jul 2025 14:14:50 +0200 Subject: [PATCH 5/6] Fix voltage sensor for OBP40 --- lib/obp60task/OBPSensorTask.cpp | 12 ++++++++---- lib/obp60task/PageVoltage.cpp | 1 - lib/obp60task/debugging.txt | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 lib/obp60task/debugging.txt diff --git a/lib/obp60task/OBPSensorTask.cpp b/lib/obp60task/OBPSensorTask.cpp index 311da1c..31c754c 100644 --- a/lib/obp60task/OBPSensorTask.cpp +++ b/lib/obp60task/OBPSensorTask.cpp @@ -498,14 +498,18 @@ void sensorTask(void *param){ // Send supply voltage value all 1s if(millis() > starttime5 + 1000 && String(powsensor1) == "off"){ starttime5 = millis(); - float rawVoltage = 0; - #if defined(BOARD_OBP40S3) && defined(VOLTAGE_SENSOR) + float rawVoltage = 0; // Default value + #ifdef BOARD_OBP40S3 + sensors.batteryVoltage = 0; // If no sensor then zero voltage + #endif + #if defined(BOARD_OBP40S3) && defined(VOLTAGE_SENSOR) rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40 + sensors.batteryVoltage = rawVoltage * vslope + voffset; // Calibration #endif #ifdef BOARD_OBP60S3 - rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60 + rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60 + sensors.batteryVoltage = rawVoltage * vslope + voffset; // Calibration #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 diff --git a/lib/obp60task/PageVoltage.cpp b/lib/obp60task/PageVoltage.cpp index 2aab416..cfd784e 100644 --- a/lib/obp60task/PageVoltage.cpp +++ b/lib/obp60task/PageVoltage.cpp @@ -187,7 +187,6 @@ public: } // Logging voltage value - if (raw == 0) return; LOG_DEBUG(GwLog::LOG,"Drawing at PageVoltage, Type:%s %s:=%f", batType, name1.c_str(), raw); // Draw page diff --git a/lib/obp60task/debugging.txt b/lib/obp60task/debugging.txt new file mode 100644 index 0000000..c0a22e0 --- /dev/null +++ b/lib/obp60task/debugging.txt @@ -0,0 +1,6 @@ +Debugging tool +############## + +log.txt = text file with error messages from terminal console + +tools/decoder.py -p ESP32S3 -t ~/.platformio/packages/toolchain-xtensa-esp32s3/ -e .pio/build/obp60_s3/firmware.elf log.txt \ No newline at end of file From 85dee2a622f43bf207d3a64d63a1095e9cec5060 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Mon, 14 Jul 2025 14:27:33 +0200 Subject: [PATCH 6/6] Fix page refresh if using keypad --- lib/obp60task/obp60task.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 5043b64..482d929 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -711,7 +711,7 @@ void OBP60Task(GwApi *api){ } // #9 or #10 Refresh display after a new page after 4s waiting time and if refresh is disabled - if(refreshmode == true && (keyboardMessage == 9 || keyboardMessage == 10)){ + if(refreshmode == true && (keyboardMessage == 9 || keyboardMessage == 10 || keyboardMessage == 4 || keyboardMessage == 3)){ starttime4 = millis(); starttime2 = millis(); // Reset the timer for full display update delayedDisplayUpdate = true;