From 8c035c4ba18ba9e612ead5a94a8277d513620776 Mon Sep 17 00:00:00 2001 From: wellenvogel Date: Wed, 5 Mar 2025 20:48:29 +0100 Subject: [PATCH] #100: allow to set custom_config, custom_js, custom_css --- extra_script.py | 10 ++++++---- lib/exampletask/Readme.md | 18 ++++++++++++------ lib/exampletask/platformio.ini | 7 ++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/extra_script.py b/extra_script.py index 941909b..218782f 100644 --- a/extra_script.py +++ b/extra_script.py @@ -465,7 +465,9 @@ def getOption(env,name,toArray=True): if toArray: if opt is None: return [] - return opt.split(',') + if isinstance(opt,list): + return opt + return opt.split("\n" if "\n" in opt else ",") return opt except: pass @@ -488,9 +490,9 @@ def prebuild(env): if ldf_mode == 'off': print("##ldf off - own dependency handling") handleDeps(env) - extraConfigs=getOption(env,'extra_config',toArray=True) - extraJs=getOption(env,'extra_js',toArray=True) - extraCss=getOption(env,'extra_css',toArray=True) + extraConfigs=getOption(env,'custom_config',toArray=True) + extraJs=getOption(env,'custom_js',toArray=True) + extraCss=getOption(env,'custom_css',toArray=True) userTaskDirs=getUserTaskDirs() mergedConfig=os.path.join(outPath(),os.path.basename(CFG_FILE)) diff --git a/lib/exampletask/Readme.md b/lib/exampletask/Readme.md index 4c51d92..f8aea49 100644 --- a/lib/exampletask/Readme.md +++ b/lib/exampletask/Readme.md @@ -14,7 +14,7 @@ Files * [platformio.ini](platformio.ini)
This file is completely optional. You only need this if you want to - extend the base configuration - we add a dummy library here and define one additional build environment (board) + extend the base configuration - we add a dummy library here and define additional build environments (boards) * [GwExampleTask.h](GwExampleTask.h) the name of this include must match the name of the directory (ignoring case) with a "gw" in front. This file includes our special hardware definitions and registers our task at the core.
This registration can be done statically using [DECLARE_USERTASK](https://github.com/wellenvogel/esp32-nmea2000/blob/9b955d135d74937a60f2926e8bfb9395585ff8cd/lib/api/GwApi.h#L202) in the header file.
As an alternative we just only register an [initialization function](https://github.com/wellenvogel/esp32-nmea2000/blob/9b955d135d74937a60f2926e8bfb9395585ff8cd/lib/exampletask/GwExampleTask.h#L19) using DECLARE_INITFUNCTION and later on register the task function itself via the [API](https://github.com/wellenvogel/esp32-nmea2000/blob/9b955d135d74937a60f2926e8bfb9395585ff8cd/lib/exampletask/GwExampleTask.cpp#L32).
@@ -28,11 +28,13 @@ Files * [GwExampleTaks.cpp](GwExampleTask.cpp) includes the implementation of our task. This tasks runs in an own thread - see the comments in the code. We can have as many cpp (and header files) as we need to structure our code. - * [config.json](config.json)
+ * [config.json](exampleConfig.json)
This file allows to add some config definitions that are needed for our task. For the possible options have a look at the global [config.json](../../web/config.json). Be careful not to overwrite config defitions from the global file. A good practice wood be to prefix the names of definitions with parts of the library name. Always put them in a separate category so that they do not interfere with the system ones. - The defined config items can later be accessed in the code (see the example in [GwExampleTask.cpp](GwExampleTask.cpp)). + The defined config items can later be accessed in the code (see the example in [GwExampleTask.cpp](GwExampleTask.cpp)).
+ + Starting from Version 202503xx you should normally not use this file name any more as those configs would be added for all build environments. Instead define a parameter _custom_config_ in your [platformio.ini](platformio.ini) for the environments you would like to add some configurations for. This parameter accepts a list of file names (relative to the project root, separated by ,). - * [index.js](index.js)
+ * [index.js](example.js)
You can add javascript code that will contribute to the UI of the system. The WebUI provides a small API that allows you to "hook" into some functions to include your own parts of the UI. This includes adding new tabs, modifying/replacing the data display items, modifying the status display or accessing the config items. For the API refer to [../../web/index.js](../../web/index.js#L2001). To start interacting just register for some events like api.EVENTS.init. You can check the capabilities you have defined to see if your task is active. @@ -46,10 +48,14 @@ Files tools/testServer.py nnn http://x.x.x.x/api ``` with nnn being the local port and x.x.x.x the address of a running system. Open `http://localhost:nnn` in your browser.
- After a change just start the compilation and reload the page. + After a change just start the compilation and reload the page.
+ + Starting from Version 202503xx you should normally not use this file name any more as those js code would be added for all build environments. Instead define a parameter _custom_js_ in your [platformio.ini](platformio.ini) for the environments you would like to add the js code for. This parameter accepts a list of file names (relative to the project root, separated by ,). This will also allow you to skip the check for capabilities in your code. * [index.css](index.css)
- You can add own css to influence the styling of the display. + You can add own css to influence the styling of the display.
+ + Starting from Version 202503xx you should normally not use this file name any more as those styles would be added for all build environments. Instead define a parameter _custom_css_ in your [platformio.ini](platformio.ini) for the environments you would like to add some styles for. This parameter accepts a list of file names (relative to the project root, separated by , or as multi line entry) Interfaces diff --git a/lib/exampletask/platformio.ini b/lib/exampletask/platformio.ini index d63dda8..348b36c 100644 --- a/lib/exampletask/platformio.ini +++ b/lib/exampletask/platformio.ini @@ -10,8 +10,9 @@ lib_deps = build_flags= -D BOARD_TEST ${env.build_flags} -extra_config=lib/exampletask/exampleConfig.json, -extra_js=lib/exampletask/example.js -extra_css=lib/exampletask/example.css +custom_config= + lib/exampletask/exampleConfig.json +custom_js=lib/exampletask/example.js +custom_css=lib/exampletask/example.css upload_port = /dev/esp32 upload_protocol = esptool \ No newline at end of file