From 8e34fa936d4c5071eba6c82a8a6ed75005f7ca0e Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Wed, 9 Jul 2025 16:13:32 +0200 Subject: [PATCH] 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")