From 027ffa983fd1c44042ce53c73a6794e8741f2f71 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Feb 2021 03:05:00 +0100 Subject: [PATCH 001/236] Update tests --- test/test_colors.tavern.yaml | 8 +- test/test_label.tavern.yaml | 166 ++++++++++++++++---------------- test/test_mqtt.tavern.yaml | 38 ++++---- test/test_obj.tavern.yaml | 58 +++++------ test/test_value_str.tavern.yaml | 6 +- 5 files changed, 133 insertions(+), 143 deletions(-) diff --git a/test/test_colors.tavern.yaml b/test/test_colors.tavern.yaml index 569dff13..9aefdd4d 100644 --- a/test/test_colors.tavern.yaml +++ b/test/test_colors.tavern.yaml @@ -81,7 +81,7 @@ stages: mqtt_response: topic: hasp/{plate}/state/page payload: "1" - timeout: 5 + timeout: 1 delay_after: 0 - name: Set bg_color @@ -125,7 +125,7 @@ stages: r: "{r}" g: "{g}" b: "{b}" - timeout: 5 + timeout: 1 - name: Reset mqtt_publish: @@ -144,7 +144,7 @@ stages: r: "{r}" g: "{g}" b: "{b}" - timeout: 5 + timeout: 1 - name: Reset mqtt_publish: @@ -163,4 +163,4 @@ stages: r: "{r}" g: "{g}" b: "{b}" - timeout: 5 + timeout: 1 diff --git a/test/test_label.tavern.yaml b/test/test_label.tavern.yaml index 48a4ce44..fa995d2b 100644 --- a/test/test_label.tavern.yaml +++ b/test/test_label.tavern.yaml @@ -22,7 +22,7 @@ stages: mqtt_response: topic: hasp/{plate}/state/page payload: "1" - timeout: 5 + timeout: 1 delay_after: 0.1 - name: Clear page @@ -42,305 +42,305 @@ stages: - name: Set x mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].x=50" + payload: "p1b1.x=50" delay_after: 0.1 - name: Get x mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].x" + payload: "p1b1.x" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - x: "50" - timeout: 5 + x: 50 + timeout: 1 - name: Set x mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].x=25" + payload: "p1b1.x=25" - name: Get x mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].x" + payload: "p1b1.x" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - x: "25" - timeout: 5 + x: 25 + timeout: 1 - name: Set y mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].y=50" + payload: "p1b1.y=50" delay_after: 0.1 - name: Get y mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].y" + payload: "p1b1.y" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - y: "50" - timeout: 5 + y: 50 + timeout: 1 - name: Set y mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].y=25" + payload: "p1b1.y=25" delay_after: 0.1 - name: Get y mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].y" + payload: "p1b1.y" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - y: "25" - timeout: 5 + y: 25 + timeout: 1 - name: Set w mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].w=50" + payload: "p1b1.w=50" delay_after: 0.1 - name: Get w mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].w" + payload: "p1b1.w" mqtt_response: topic: hasp/{plate}/state/p1b1 json: w: !anything - timeout: 5 + timeout: 1 - name: Set w mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].w=25" + payload: "p1b1.w=25" - name: Get w mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].w" + payload: "p1b1.w" mqtt_response: topic: hasp/{plate}/state/p1b1 json: w: !anything - timeout: 5 + timeout: 1 - name: Set h mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].h=50" + payload: "p1b1.h=50" delay_after: 0.1 - name: Get h mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].h" + payload: "p1b1.h" mqtt_response: topic: hasp/{plate}/state/p1b1 json: h: !anything - timeout: 5 + timeout: 1 - name: Set h mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].h=25" + payload: "p1b1.h=25" delay_after: 0.1 - name: Get h mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].h" + payload: "p1b1.h" mqtt_response: topic: hasp/{plate}/state/p1b1 json: h: !anything - timeout: 5 + timeout: 1 - name: Set mode mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].mode=crop" + payload: "p1b1.mode=crop" delay_after: 0.1 - name: Get mode mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].mode" + payload: "p1b1.mode" - name: Set w mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].w=50" + payload: "p1b1.w=50" delay_after: 0.1 - name: Get w mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].w" + payload: "p1b1.w" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - w: "50" - timeout: 5 + w: 50 + timeout: 1 - name: Set w mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].w=25" + payload: "p1b1.w=25" - name: Get w mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].w" + payload: "p1b1.w" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - w: "25" - timeout: 5 + w: 25 + timeout: 1 - name: Set h mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].h=50" + payload: "p1b1.h=50" delay_after: 0.1 - name: Get h mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].h" + payload: "p1b1.h" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - h: "50" - timeout: 5 + h: 50 + timeout: 1 - name: Set h mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].h=45" + payload: "p1b1.h=45" delay_after: 0.1 - name: Get h mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].h" + payload: "p1b1.h" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - h: "45" - timeout: 5 + h: 45 + timeout: 1 - name: Set enabled mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].enabled=0" + payload: "p1b1.enabled=0" delay_after: 0.1 - name: Get enabled mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].enabled" + payload: "p1b1.enabled" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - enabled: "0" - timeout: 5 + enabled: 0 + timeout: 1 - name: Set enabled mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].enabled=1" + payload: "p1b1.enabled=1" delay_after: 0.1 - name: Get enabled mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].enabled" + payload: "p1b1.enabled" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - enabled: "1" - timeout: 5 + enabled: 1 + timeout: 1 - name: Set hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden=1" + payload: "p1b1.hidden=1" delay_after: 0.1 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden" + payload: "p1b1.hidden" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - hidden: "1" - timeout: 5 + hidden: 1 + timeout: 1 - name: Get vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis" + payload: "p1b1.vis" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - vis: "0" - timeout: 5 + vis: 0 + timeout: 1 - name: Set hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden=0" + payload: "p1b1.hidden=0" delay_after: 0.1 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden" + payload: "p1b1.hidden" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - hidden: "0" - timeout: 5 + hidden: 0 + timeout: 1 - name: Get vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis" + payload: "p1b1.vis" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - vis: "1" - timeout: 5 + vis: 1 + timeout: 1 - name: Set vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis=0" + payload: "p1b1.vis=0" delay_after: 0.1 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden" + payload: "p1b1.hidden" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - hidden: "1" - timeout: 5 + hidden: 1 + timeout: 1 - name: Get vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis" + payload: "p1b1.vis" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - vis: "0" - timeout: 5 + vis: 0 + timeout: 1 - name: Set vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis=1" + payload: "p1b1.vis=1" delay_after: 0.1 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden" + payload: "p1b1.hidden" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - hidden: "0" - timeout: 5 + hidden: 0 + timeout: 1 - name: Get vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis" + payload: "p1b1.vis" mqtt_response: topic: hasp/{plate}/state/p1b1 json: - vis: "1" - timeout: 5 + vis: 1 + timeout: 1 diff --git a/test/test_mqtt.tavern.yaml b/test/test_mqtt.tavern.yaml index 18c220af..2e103523 100644 --- a/test/test_mqtt.tavern.yaml +++ b/test/test_mqtt.tavern.yaml @@ -23,8 +23,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/page payload: "1" - timeout: 5 - delay_after: 1 + timeout: 1 + delay_after: 0 - name: step 2 - Page test mqtt_publish: topic: hasp/{plate}/command @@ -32,8 +32,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/page payload: "2" - timeout: 5 - delay_after: 1 + timeout: 1 + delay_after: 0 - name: step 3 - Page test mqtt_publish: topic: hasp/{plate}/command @@ -41,26 +41,26 @@ stages: mqtt_response: topic: hasp/{plate}/state/page payload: "3" - timeout: 5 - delay_after: 1 + timeout: 1 + delay_after: 0 - name: step 4 - Page test mqtt_publish: topic: hasp/{plate}/command/json - payload: "[\"page=0\"]" + payload: "[\"page=1\"]" mqtt_response: topic: hasp/{plate}/state/page - payload: "0" - timeout: 3 - delay_after: 1 + payload: "1" + timeout: 1 + delay_after: 0 - name: step 5 - Page test mqtt_publish: topic: hasp/{plate}/command/json payload: "[\"page 300\"]" mqtt_response: topic: hasp/{plate}/state/page - payload: "0" - timeout: 3 - delay_after: 1 + payload: "1" + timeout: 1 + delay_after: 0 --- test_name: Reboot Command @@ -75,7 +75,7 @@ paho-mqtt: connect: host: "{host}" port: !int "{port:d}" - timeout: 3 + timeout: 1 stages: - name: Test reboot command @@ -86,7 +86,7 @@ stages: topic: hasp/{plate}/LWT payload: "offline" timeout: 20 - delay_after: 1 + delay_after: 0 --- test_name: Idle States @@ -112,7 +112,7 @@ stages: topic: hasp/{plate}/state/idle payload: "LONG" timeout: 190 - delay_after: 1 + delay_after: 0 - name: Test idle mqtt_publish: @@ -122,7 +122,7 @@ stages: topic: hasp/{plate}/state/idle payload: "SHORT" timeout: 70 - delay_after: 1 + delay_after: 0 - name: Test idle mqtt_publish: @@ -131,5 +131,5 @@ stages: mqtt_response: topic: hasp/{plate}/state/idle payload: "OFF" - timeout: 3 - delay_after: 1 + timeout: 1 + delay_after: 0 diff --git a/test/test_obj.tavern.yaml b/test/test_obj.tavern.yaml index 032621a3..6738952c 100644 --- a/test/test_obj.tavern.yaml +++ b/test/test_obj.tavern.yaml @@ -35,17 +35,7 @@ marks: vals: - 10 - 12 - - 20 - - 22 - - 30 - - 31 - - 32 - - 33 - - 40 - - 41 - - 50 - - 51 - - 91 + stages: - name: Page 1 @@ -55,7 +45,7 @@ stages: mqtt_response: topic: hasp/{plate}/state/page payload: "1" - timeout: 5 + timeout: 1 delay_after: 0 - name: Clear page @@ -79,8 +69,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - x: "{x}" - timeout: 5 + x: !int "{x:d}" + timeout: 1 - name: Test y mqtt_publish: @@ -89,8 +79,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - y: "{y}" - timeout: 5 + y: !int "{y:d}" + timeout: 1 - name: Test w mqtt_publish: @@ -99,8 +89,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - w: "{w}" - timeout: 5 + w: !int "{w:d}" + timeout: 1 - name: Test h mqtt_publish: @@ -110,8 +100,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - h: "{h}" - timeout: 5 + h: !int "{h:d}" + timeout: 1 - name: Test enabled mqtt_publish: @@ -121,8 +111,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - enabled: "{hidden}" - timeout: 5 + enabled: !int "{hidden:d}" + timeout: 1 - name: Set vis mqtt_publish: @@ -136,8 +126,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - hidden: "{hidden_inv}" - timeout: 5 + hidden: !int "{hidden_inv:d}" + timeout: 1 - name: Get vis mqtt_publish: topic: hasp/{plate}/command @@ -145,8 +135,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - vis: "{hidden}" - timeout: 5 + vis: !int "{hidden:d}" + timeout: 1 - name: Set hidden mqtt_publish: @@ -160,8 +150,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - hidden: "{hidden}" - timeout: 5 + hidden: !int "{hidden:d}" + timeout: 1 - name: Get vis mqtt_publish: @@ -170,8 +160,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - vis: "{hidden_inv}" - timeout: 5 + vis: !int "{hidden_inv:d}" + timeout: 1 - name: Test opacity mqtt_publish: @@ -180,8 +170,8 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - opacity: "{opacity}" - timeout: 5 + opacity: !int "{opacity:d}" + timeout: 1 - name: Test radius mqtt_publish: @@ -190,5 +180,5 @@ stages: mqtt_response: topic: hasp/{plate}/state/p1b1 json: - radius: "{radius}" - timeout: 5 + radius: !int "{radius:d}" + timeout: 1 diff --git a/test/test_value_str.tavern.yaml b/test/test_value_str.tavern.yaml index a0cc6a4f..6b4fa323 100644 --- a/test/test_value_str.tavern.yaml +++ b/test/test_value_str.tavern.yaml @@ -81,14 +81,14 @@ stages: mqtt_response: topic: hasp/{plate}/state/page payload: "1" - timeout: 5 + timeout: 1 delay_after: 0 - name: Set value_str mqtt_publish: topic: "hasp/{plate}/command/p[1].b[1].value_str" payload: "{str1}{str2}" - delay_after: 0.2 + delay_after: 0.05 - name: Get value_str mqtt_publish: topic: hasp/{plate}/command @@ -97,4 +97,4 @@ stages: topic: hasp/{plate}/state/p1b1 json: value_str: "{str1}{str2}" - timeout: 5 + timeout: 1 From a70eb1fd5fd4dfafd2f04b03a8b2ff9504bebdc7 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Feb 2021 03:09:17 +0100 Subject: [PATCH 002/236] Add Windows client --- hal/sdl2/app_hal.c | 75 +++ hal/sdl2/app_hal.h | 17 + hal/stm32f407_btt/app_hal.c | 50 ++ hal/stm32f407_btt/app_hal.h | 17 + hal/stm32f407_btt/tft.c | 65 +++ hal/stm32f407_btt/tft.h | 37 ++ hal/stm32f429_disco/app_hal.c | 123 +++++ hal/stm32f429_disco/app_hal.h | 17 + hal/stm32f429_disco/tft.c | 236 +++++++++ hal/stm32f429_disco/tft.h | 37 ++ hal/stm32f429_disco/touchpad.c | 144 ++++++ hal/stm32f429_disco/touchpad.h | 32 ++ include/VersionInfo.h | 7 + include/hasp_conf.h | 73 ++- include/hasp_macro.h | 57 ++- include/lv_conf_v7.h | 14 +- platformio.ini | 135 +++++- src/{main.cpp => main_arduino.cpp} | 23 +- src/main_windows.cpp | 120 +++++ src/{svc => mqtt}/hasp_mqtt.h | 8 +- src/{svc/hasp_mqtt.cpp => mqtt/hasp_mqtt.old} | 2 +- src/{svc => mqtt}/hasp_mqtt_ha.cpp | 3 +- src/{svc => mqtt}/hasp_mqtt_ha.h | 0 src/mqtt/hasp_mqtt_paho.cpp | 423 ++++++++++++++++ src/mqtt/hasp_mqtt_pubsubclient.cpp | 455 ++++++++++++++++++ tools/sdl2_build_extra.py | 33 ++ 26 files changed, 2155 insertions(+), 48 deletions(-) create mode 100644 hal/sdl2/app_hal.c create mode 100644 hal/sdl2/app_hal.h create mode 100644 hal/stm32f407_btt/app_hal.c create mode 100644 hal/stm32f407_btt/app_hal.h create mode 100644 hal/stm32f407_btt/tft.c create mode 100644 hal/stm32f407_btt/tft.h create mode 100644 hal/stm32f429_disco/app_hal.c create mode 100644 hal/stm32f429_disco/app_hal.h create mode 100644 hal/stm32f429_disco/tft.c create mode 100644 hal/stm32f429_disco/tft.h create mode 100644 hal/stm32f429_disco/touchpad.c create mode 100644 hal/stm32f429_disco/touchpad.h create mode 100644 include/VersionInfo.h rename src/{main.cpp => main_arduino.cpp} (92%) create mode 100644 src/main_windows.cpp rename src/{svc => mqtt}/hasp_mqtt.h (84%) rename src/{svc/hasp_mqtt.cpp => mqtt/hasp_mqtt.old} (99%) rename src/{svc => mqtt}/hasp_mqtt_ha.cpp (99%) rename src/{svc => mqtt}/hasp_mqtt_ha.h (100%) create mode 100644 src/mqtt/hasp_mqtt_paho.cpp create mode 100644 src/mqtt/hasp_mqtt_pubsubclient.cpp create mode 100644 tools/sdl2_build_extra.py diff --git a/hal/sdl2/app_hal.c b/hal/sdl2/app_hal.c new file mode 100644 index 00000000..326c8282 --- /dev/null +++ b/hal/sdl2/app_hal.c @@ -0,0 +1,75 @@ +#include +#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/ +#include +#include "display/monitor.h" +#include "indev/mouse.h" +#include "indev/mousewheel.h" +#include "indev/keyboard.h" + + +/** + * A task to measure the elapsed time for LittlevGL + * @param data unused + * @return never return + */ +static int tick_thread(void * data) +{ + (void)data; + + while(1) { + SDL_Delay(5); /*Sleep for 5 millisecond*/ + lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/ + } + + return 0; +} + + +void hal_setup(void) +{ + // Workaround for sdl2 `-m32` crash + // https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7 + #ifndef WIN32 + setenv("DBUS_FATAL_WARNINGS", "0", 1); + #endif + + /* Add a display + * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ + monitor_init(); + /* Tick init. + * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed + * Create an SDL thread to do this*/ + SDL_CreateThread(tick_thread, "tick", NULL); + + lv_init(); + static lv_disp_buf_t disp_buf; + static lv_color_t buf[LV_HOR_RES_MAX * 10]; /*Declare a buffer for 10 lines*/ + lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/ + + lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); /*Basic initialization*/ + disp_drv.flush_cb = monitor_flush; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/ + disp_drv.buffer = &disp_buf; + //disp_drv.disp_fill = monitor_fill; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ + //disp_drv.disp_map = monitor_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ + lv_disp_drv_register(&disp_drv); + + /* Add the mouse as input device + * Use the 'mouse' driver which reads the PC's mouse*/ + mouse_init(); + lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); /*Basic initialization*/ + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read_cb = mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/ + lv_indev_drv_register(&indev_drv); + + +} + +void hal_loop(void) +{ + /*while(1)*/ { + SDL_Delay(5); + lv_task_handler(); + } +} diff --git a/hal/sdl2/app_hal.h b/hal/sdl2/app_hal.h new file mode 100644 index 00000000..58a5b9df --- /dev/null +++ b/hal/sdl2/app_hal.h @@ -0,0 +1,17 @@ +#ifndef DRIVER_H +#define DRIVER_H + +#ifdef __cplusplus +extern "C" { +#endif + + +void hal_setup(void); +void hal_loop(void); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*DRIVER_H*/ diff --git a/hal/stm32f407_btt/app_hal.c b/hal/stm32f407_btt/app_hal.c new file mode 100644 index 00000000..639a3b04 --- /dev/null +++ b/hal/stm32f407_btt/app_hal.c @@ -0,0 +1,50 @@ + +#include "Arduino.h" + +#include "stm32f4xx.h" +//#include "stm32f429i_discovery.h" +#include "tft.h" +//#include "touchpad.h" + +#ifdef USE_RTOS_SYSTICK +#include +#endif + +void hal_setup(void) +{ + pinMode(PD12, OUTPUT); + digitalWrite(PD12, HIGH); + + // HAL_Init(); + + // /* Configure the system clock to 180 MHz */ + // SystemClock_Config(); + + // /* Start up indication */ + // BSP_LED_Init(LED3); + // for (uint8_t i = 0; i < 8; i++) { BSP_LED_Toggle(LED3); delay(50); } + + tft_init(); + //touchpad_init(); +} + +// void SysTick_Handler(void) +// { +// HAL_IncTick(); +// HAL_SYSTICK_IRQHandler(); + +// lv_tick_inc(1); + +// #ifdef USE_RTOS_SYSTICK +// osSystickHandler(); +// #endif +// } + +void hal_loop(void) +{ + //while (1) + { + delay(5); + lv_task_handler(); + } +} diff --git a/hal/stm32f407_btt/app_hal.h b/hal/stm32f407_btt/app_hal.h new file mode 100644 index 00000000..58a5b9df --- /dev/null +++ b/hal/stm32f407_btt/app_hal.h @@ -0,0 +1,17 @@ +#ifndef DRIVER_H +#define DRIVER_H + +#ifdef __cplusplus +extern "C" { +#endif + + +void hal_setup(void); +void hal_loop(void); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*DRIVER_H*/ diff --git a/hal/stm32f407_btt/tft.c b/hal/stm32f407_btt/tft.c new file mode 100644 index 00000000..76ab6061 --- /dev/null +++ b/hal/stm32f407_btt/tft.c @@ -0,0 +1,65 @@ +/** + * @file disp.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include + +#include "tft.h" +#include "stm32f4xx.h" +#include "fsmc_ssd1963.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static lv_disp_drv_t disp_drv; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ +/** + * Initialize your display here + */ +void tft_init(void) +{ + static lv_color_t disp_buf1[TFT_HOR_RES * 40]; + static lv_disp_buf_t buf; + lv_disp_buf_init(&buf, disp_buf1, NULL, TFT_HOR_RES * 40); + + lv_disp_drv_init(&disp_drv); + fsmc_ssd1963_init(0, false); + + disp_drv.buffer = &buf; + disp_drv.flush_cb = fsmc_ssd1963_flush; + disp_drv.hor_res = TFT_HOR_RES; + disp_drv.ver_res = TFT_VER_RES; +#if TFT_USE_GPU != 0 + DMA2D_Config(); + disp_drv.gpu_blend_cb = gpu_mem_blend; + disp_drv.gpu_fill_cb = gpu_mem_fill; +#endif + lv_disp_drv_register(&disp_drv); +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/hal/stm32f407_btt/tft.h b/hal/stm32f407_btt/tft.h new file mode 100644 index 00000000..fc54bb03 --- /dev/null +++ b/hal/stm32f407_btt/tft.h @@ -0,0 +1,37 @@ +/** + * @file disp.h + * + */ + +#ifndef DISP_H +#define DISP_H + +/********************* + * INCLUDES + *********************/ +#include +#include "lvgl.h" + +/********************* + * DEFINES + *********************/ +#define TFT_HOR_RES TFT_WIDTH +#define TFT_VER_RES TFT_HEIGHT + +#define TFT_EXT_FB 1 /*Frame buffer is located into an external SDRAM*/ +#define TFT_USE_GPU 0 /*Enable hardware accelerator*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void tft_init(void); + +/********************** + * MACROS + **********************/ + +#endif diff --git a/hal/stm32f429_disco/app_hal.c b/hal/stm32f429_disco/app_hal.c new file mode 100644 index 00000000..c7aa120f --- /dev/null +++ b/hal/stm32f429_disco/app_hal.c @@ -0,0 +1,123 @@ + +#include "stm32f4xx.h" +#include "stm32f429i_discovery.h" +#include "tft.h" +#include "touchpad.h" + +#ifdef USE_RTOS_SYSTICK +#include +#endif + + +/** + * @brief System Clock Configuration + * The system Clock is configured as follow : + * System Clock source = PLL (HSE) + * SYSCLK(Hz) = 180000000 + * HCLK(Hz) = 180000000 + * AHB Prescaler = 1 + * APB1 Prescaler = 4 + * APB2 Prescaler = 2 + * HSE Frequency(Hz) = 8000000 + * PLL_M = 8 + * PLL_N = 360 + * PLL_P = 2 + * PLL_Q = 7 + * VDD(V) = 3.3 + * Main regulator output voltage = Scale1 mode + * Flash Latency(WS) = 5 + * The LTDC Clock is configured as follow : + * PLLSAIN = 192 + * PLLSAIR = 4 + * PLLSAIDivR = 8 + * @param None + * @retval None + */ +static void SystemClock_Config(void) +{ + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; + + /* Enable Power Control clock */ + __HAL_RCC_PWR_CLK_ENABLE(); + + /* The voltage scaling allows optimizing the power consumption when the device is + clocked below the maximum system frequency, to update the voltage scaling value + regarding system frequency refer to product datasheet. */ + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + + /*##-1- System Clock Configuration #########################################*/ + /* Enable HSE Oscillator and activate PLL with HSE as source */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 8; + RCC_OscInitStruct.PLL.PLLN = 360; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 7; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + /* Activate the Over-Drive mode */ + HAL_PWREx_EnableOverDrive(); + + /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 + clocks dividers */ + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); + + /*##-2- LTDC Clock Configuration ###########################################*/ + /* LCD clock configuration */ + /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 MHz */ + /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 MHz */ + /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 MHz */ + /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 MHz */ + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; + PeriphClkInitStruct.PLLSAI.PLLSAIN = 192; + PeriphClkInitStruct.PLLSAI.PLLSAIR = 4; + PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8; + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); +} + + +void hal_setup(void) +{ + HAL_Init(); + + /* Configure the system clock to 180 MHz */ + SystemClock_Config(); + + /* Start up indication */ + BSP_LED_Init(LED3); + for (uint8_t i = 0; i < 8; i++) { BSP_LED_Toggle(LED3); HAL_Delay(50); } + + tft_init(); + touchpad_init(); +} + + +void SysTick_Handler(void) +{ + HAL_IncTick(); + HAL_SYSTICK_IRQHandler(); + + lv_tick_inc(1); + +#ifdef USE_RTOS_SYSTICK + osSystickHandler(); +#endif +} + + +void hal_loop(void) +{ + while(1) { + HAL_Delay(5); + lv_task_handler(); + } +} diff --git a/hal/stm32f429_disco/app_hal.h b/hal/stm32f429_disco/app_hal.h new file mode 100644 index 00000000..58a5b9df --- /dev/null +++ b/hal/stm32f429_disco/app_hal.h @@ -0,0 +1,17 @@ +#ifndef DRIVER_H +#define DRIVER_H + +#ifdef __cplusplus +extern "C" { +#endif + + +void hal_setup(void); +void hal_loop(void); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*DRIVER_H*/ diff --git a/hal/stm32f429_disco/tft.c b/hal/stm32f429_disco/tft.c new file mode 100644 index 00000000..d6a463c2 --- /dev/null +++ b/hal/stm32f429_disco/tft.c @@ -0,0 +1,236 @@ +/** + * @file disp.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include + +#include "tft.h" +#include "stm32f4xx.h" +#include "stm32f429i_discovery_lcd.h" +#include "ili9341.h" + +/********************* + * DEFINES + *********************/ + +#define SDRAM_BANK_ADDR ((uint32_t)0xD0000000) + +#define DMA_STREAM DMA2_Stream0 +#define DMA_CHANNEL DMA_CHANNEL_0 +#define DMA_STREAM_IRQ DMA2_Stream0_IRQn +#define DMA_STREAM_IRQHANDLER DMA2_Stream0_IRQHandler + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +static void tft_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p); + +/********************** + * STATIC VARIABLES + **********************/ +extern LTDC_HandleTypeDef LtdcHandler; + +#if TFT_USE_GPU != 0 +static DMA2D_HandleTypeDef Dma2dHandle; +#endif + +#if TFT_EXT_FB != 0 +static __IO uint16_t *my_fb = (__IO uint16_t *)(SDRAM_BANK_ADDR); +#else +static uint16_t my_fb[TFT_HOR_RES * TFT_VER_RES]; +#endif + +/*DMA to flush to frame buffer*/ +static void DMA_Config(void); +static void DMA_TransferComplete(DMA_HandleTypeDef *han); +static void DMA_TransferError(DMA_HandleTypeDef *han); + +DMA_HandleTypeDef DmaHandle; +static lv_disp_drv_t disp_drv; +static int32_t x1_flush; +static int32_t y1_flush; +static int32_t x2_flush; +static int32_t y2_fill; +static int32_t y_fill_act; +static const lv_color_t *buf_to_flush; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ +/** + * Initialize your display here + */ +void tft_init(void) +{ + static lv_color_t disp_buf1[TFT_HOR_RES * 40]; + static lv_disp_buf_t buf; + lv_disp_buf_init(&buf, disp_buf1, NULL, TFT_HOR_RES * 40); + + lv_disp_drv_init(&disp_drv); + + BSP_LCD_Init(); + BSP_LCD_LayerDefaultInit(0, (uint32_t)my_fb); + HAL_LTDC_SetPixelFormat(&LtdcHandler, LTDC_PIXEL_FORMAT_RGB565, 0); + DMA_Config(); + disp_drv.buffer = &buf; + disp_drv.flush_cb = tft_flush; + disp_drv.hor_res = TFT_HOR_RES; + disp_drv.ver_res = TFT_VER_RES; +#if TFT_USE_GPU != 0 + DMA2D_Config(); + disp_drv.gpu_blend_cb = gpu_mem_blend; + disp_drv.gpu_fill_cb = gpu_mem_fill; +#endif + lv_disp_drv_register(&disp_drv); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Flush a color buffer + * @param x1 left coordinate of the rectangle + * @param x2 right coordinate of the rectangle + * @param y1 top coordinate of the rectangle + * @param y2 bottom coordinate of the rectangle + * @param color_p pointer to an array of colors + */ +static void tft_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p) +{ + /*Return if the area is out the screen*/ + if (area->x2 < 0) + return; + if (area->y2 < 0) + return; + if (area->x1 > TFT_HOR_RES - 1) + return; + if (area->y1 > TFT_VER_RES - 1) + return; + + /*Truncate the area to the screen*/ + int32_t act_x1 = area->x1 < 0 ? 0 : area->x1; + int32_t act_y1 = area->y1 < 0 ? 0 : area->y1; + int32_t act_x2 = area->x2 > TFT_HOR_RES - 1 ? TFT_HOR_RES - 1 : area->x2; + int32_t act_y2 = area->y2 > TFT_VER_RES - 1 ? TFT_VER_RES - 1 : area->y2; + + x1_flush = act_x1; + y1_flush = act_y1; + x2_flush = act_x2; + y2_fill = act_y2; + y_fill_act = act_y1; + buf_to_flush = color_p; + + /*##-7- Start the DMA transfer using the interrupt mode #*/ + /* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */ + /* Enable All the DMA interrupts */ + HAL_StatusTypeDef err; + err = HAL_DMA_Start_IT(&DmaHandle, (uint32_t)buf_to_flush, (uint32_t)&my_fb[y_fill_act * TFT_HOR_RES + x1_flush], + (x2_flush - x1_flush + 1)); + if (err != HAL_OK) + { + while (1) + ; /*Halt on error*/ + } +} + +static void DMA_Config(void) +{ + /*## -1- Enable DMA2 clock #################################################*/ + __HAL_RCC_DMA2_CLK_ENABLE(); + + /*##-2- Select the DMA functional Parameters ###############################*/ + DmaHandle.Init.Channel = DMA_CHANNEL; /* DMA_CHANNEL_0 */ + DmaHandle.Init.Direction = DMA_MEMORY_TO_MEMORY; /* M2M transfer mode */ + DmaHandle.Init.PeriphInc = DMA_PINC_ENABLE; /* Peripheral increment mode Enable */ + DmaHandle.Init.MemInc = DMA_MINC_ENABLE; /* Memory increment mode Enable */ + DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; /* Peripheral data alignment : 16bit */ + DmaHandle.Init.MemDataAlignment = DMA_PDATAALIGN_HALFWORD; /* memory data alignment : 16bit */ + DmaHandle.Init.Mode = DMA_NORMAL; /* Normal DMA mode */ + DmaHandle.Init.Priority = DMA_PRIORITY_HIGH; /* priority level : high */ + DmaHandle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; /* FIFO mode enabled */ + DmaHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_1QUARTERFULL; /* FIFO threshold: 1/4 full */ + DmaHandle.Init.MemBurst = DMA_MBURST_SINGLE; /* Memory burst */ + DmaHandle.Init.PeriphBurst = DMA_PBURST_SINGLE; /* Peripheral burst */ + + /*##-3- Select the DMA instance to be used for the transfer : DMA2_Stream0 #*/ + DmaHandle.Instance = DMA_STREAM; + + /*##-4- Initialize the DMA stream ##########################################*/ + if (HAL_DMA_Init(&DmaHandle) != HAL_OK) + { + while (1) + ; + } + + /*##-5- Select Callbacks functions called after Transfer complete and Transfer error */ + HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_CPLT_CB_ID, DMA_TransferComplete); + HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_ERROR_CB_ID, DMA_TransferError); + + /*##-6- Configure NVIC for DMA transfer complete/error interrupts ##########*/ + HAL_NVIC_SetPriority(DMA_STREAM_IRQ, 0, 0); + HAL_NVIC_EnableIRQ(DMA_STREAM_IRQ); +} + +/** + * @brief DMA conversion complete callback + * @note This function is executed when the transfer complete interrupt + * is generated + * @retval None + */ +static void DMA_TransferComplete(DMA_HandleTypeDef *han) +{ + y_fill_act++; + + if (y_fill_act > y2_fill) + { + lv_disp_flush_ready(&disp_drv); + } + else + { + buf_to_flush += x2_flush - x1_flush + 1; + /*##-7- Start the DMA transfer using the interrupt mode ####################*/ + /* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */ + /* Enable All the DMA interrupts */ + if (HAL_DMA_Start_IT(han, (uint32_t)buf_to_flush, (uint32_t)&my_fb[y_fill_act * TFT_HOR_RES + x1_flush], + (x2_flush - x1_flush + 1)) != HAL_OK) + { + while (1) + ; /*Halt on error*/ + } + } +} + +/** + * @brief DMA conversion error callback + * @note This function is executed when the transfer error interrupt + * is generated during DMA transfer + * @retval None + */ +static void DMA_TransferError(DMA_HandleTypeDef *han) +{ +} + +/** + * @brief This function handles DMA Stream interrupt request. + * @param None + * @retval None + */ +void DMA_STREAM_IRQHANDLER(void) +{ + /* Check the interrupt and clear flag */ + HAL_DMA_IRQHandler(&DmaHandle); +} \ No newline at end of file diff --git a/hal/stm32f429_disco/tft.h b/hal/stm32f429_disco/tft.h new file mode 100644 index 00000000..e9bbdfbb --- /dev/null +++ b/hal/stm32f429_disco/tft.h @@ -0,0 +1,37 @@ +/** + * @file disp.h + * + */ + +#ifndef DISP_H +#define DISP_H + +/********************* + * INCLUDES + *********************/ +#include +#include "lvgl.h" + +/********************* + * DEFINES + *********************/ +#define TFT_HOR_RES 240 +#define TFT_VER_RES 320 + +#define TFT_EXT_FB 1 /*Frame buffer is located into an external SDRAM*/ +#define TFT_USE_GPU 0 /*Enable hardware accelerator*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void tft_init(void); + +/********************** + * MACROS + **********************/ + +#endif diff --git a/hal/stm32f429_disco/touchpad.c b/hal/stm32f429_disco/touchpad.c new file mode 100644 index 00000000..cba8bd77 --- /dev/null +++ b/hal/stm32f429_disco/touchpad.c @@ -0,0 +1,144 @@ +/** + * @file indev.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "tft.h" +#include "lvgl.h" + +#include "stm32f4xx.h" +#include "stm32f429i_discovery.h" +#include "stmpe811.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool touchpad_read(lv_indev_drv_t * drv, lv_indev_data_t *data); +static bool touchpad_get_xy(int16_t *x, int16_t *y); + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize your input devices here + */ +void touchpad_init(void) +{ + stmpe811_Init(TS_I2C_ADDRESS); + stmpe811_TS_Start(TS_I2C_ADDRESS); + + lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); + indev_drv.read_cb = touchpad_read; + indev_drv.type = LV_INDEV_TYPE_POINTER; + lv_indev_drv_register(&indev_drv); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Read an input device + * @param indev_id id of the input device to read + * @param x put the x coordinate here + * @param y put the y coordinate here + * @return true: the device is pressed, false: released + */ +static bool touchpad_read(lv_indev_drv_t * drv, lv_indev_data_t *data) +{ + static int16_t last_x = 0; + static int16_t last_y = 0; + + bool detected; + int16_t x; + int16_t y; + detected = touchpad_get_xy(&x, &y); + if(detected) { + data->point.x = x; + data->point.y = y; + last_x = data->point.x; + last_y = data->point.y; + + data->state = LV_INDEV_STATE_PR; + } else { + data->point.x = last_x; + data->point.y = last_y; + data->state = LV_INDEV_STATE_REL; + } + + return false; +} + + +static bool touchpad_get_xy(int16_t *x, int16_t *y) +{ + static int32_t _x = 0, _y = 0; + int16_t xDiff, yDiff, xr, yr, x_raw, y_raw;; + + bool detected; + detected = stmpe811_TS_DetectTouch(TS_I2C_ADDRESS); + + if(!detected) return false; + + + stmpe811_TS_GetXY(TS_I2C_ADDRESS, &x_raw, &y_raw); + + /* Y value first correction */ + y_raw -= 360; + + /* Y value second correction */ + yr = y_raw / 11; + + /* Return y_raw position value */ + if(yr <= 0) yr = 0; + else if (yr > TFT_VER_RES) yr = TFT_VER_RES - 1; + + y_raw = yr; + + /* X value first correction */ + if(x_raw <= 3000) x_raw = 3870 - x_raw; + else x_raw = 3800 - x_raw; + + /* X value second correction */ + xr = x_raw / 15; + + /* Return X position value */ + if(xr <= 0) xr = 0; + else if (xr > TFT_HOR_RES) xr = TFT_HOR_RES - 1; + + x_raw = xr; + xDiff = x_raw > _x? (x_raw - _x): (_x - x_raw); + yDiff = y_raw > _y? (y_raw - _y): (_y - y_raw); + + if (xDiff + yDiff > 5) { + _x = x_raw; + _y = y_raw; + } + + /* Update the X and Y position */ + *x = _x; + *y = _y; + + return true; +} diff --git a/hal/stm32f429_disco/touchpad.h b/hal/stm32f429_disco/touchpad.h new file mode 100644 index 00000000..bfd61c2d --- /dev/null +++ b/hal/stm32f429_disco/touchpad.h @@ -0,0 +1,32 @@ +/** + * @file indev.h + * + */ + +#ifndef INDEV_H +#define INDEV_H + +/********************* + * INCLUDES + *********************/ +#include +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void touchpad_init(void); + +/********************** + * MACROS + **********************/ + +#endif diff --git a/include/VersionInfo.h b/include/VersionInfo.h new file mode 100644 index 00000000..5b91bf3a --- /dev/null +++ b/include/VersionInfo.h @@ -0,0 +1,7 @@ +#ifndef VERSIONINFO_H +#define VERSIONINFO_H + +#define BUILD_TIMESTAMP "@BUILD_TIMESTAMP@" +#define CLIENT_VERSION "@CLIENT_VERSION@" + +#endif /* VERSIONINFO_H */ diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 2ac6c842..c0e2f847 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -1,6 +1,9 @@ #ifndef HASP_CONF_H #define HASP_CONF_H +// language specific defines +#include "lang/lang.h" + #define HASP_USE_APP 1 #ifndef HASP_USE_DEBUG @@ -101,7 +104,12 @@ #define HASP_OBJECT_NOTATION "p%ub%u" /* Includes */ -#include +#ifdef WINDOWS + #include "winsock2.h" + #include "Windows.h" +#else + #include "Arduino.h" +#endif #if HASP_USE_SPIFFS > 0 // #if defined(ARDUINO_ARCH_ESP32) @@ -132,7 +140,7 @@ #endif #if HASP_USE_WIFI > 0 - #include "net/hasp_wifi.h" + #include "sys/net/hasp_wifi.h" #if defined(STM32F4xx) #include "WiFiSpi.h" @@ -173,11 +181,18 @@ static WiFiSpiClass WiFi; #endif #if HASP_USE_MQTT > 0 - #include "svc/hasp_mqtt.h" + #include "mqtt/hasp_mqtt.h" + + #ifdef WINDOWS + #define USE_PAHO + #else + #define USE_PUBSUBCLIENT + #endif + #endif #if HASP_USE_GPIO > 0 - #include "hasp_gpio.h" + #include "sys/gpio/hasp_gpio.h" #endif #if HASP_USE_HTTP > 0 @@ -215,4 +230,54 @@ static WiFiSpiClass WiFi; #define PGM_P const char * #endif +#ifndef __FlashStringHelper + #define __FlashStringHelper char +#endif + +#ifndef FPSTR + #define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) +#endif + +#ifndef PGM_P + #define PGM_P const char * +#endif + +#ifndef F + #define F(x) (x) +#endif + +#ifndef PSTR + #define PSTR(x) x +#endif + +#ifndef PROGMEM + #define PROGMEM +#endif + +#ifdef WINDOWS + #include + #include + #include + #include + + #define snprintf_P snprintf + #define memcpy_P memcpy + #define strcasecmp_P strcmp // TODO: should be strcasecmp + #define strcmp_P strcmp + #define strstr_P strstr + #define halRestartMcu() + #define delay Sleep + #define millis SDL_GetTicks + + #define DEC 10 + #define HEX 16 + #define BIN 2 + + #define guiGetDim() 255 + #define guiSetDim(x) + #define guiGetBacklight() 1 + #define guiSetBacklight(x) + #define guiCalibrate() +#endif + #endif // HASP_CONF_H \ No newline at end of file diff --git a/include/hasp_macro.h b/include/hasp_macro.h index 0e7c636a..a129cbe0 100644 --- a/include/hasp_macro.h +++ b/include/hasp_macro.h @@ -1,65 +1,72 @@ #ifndef HASP_MACRO_H #define HASP_MACRO_H -#if HASP_LOG_LEVEL > LOG_LEVEL_FATAL - #define LOG_FATAL(...) \ - Log.fatal(__VA_ARGS__); \ - while(true) { \ - } +#ifdef WINDOWS +#define LOG_OUTPUT(x, ...) printf(__VA_ARGS__) #else - #define LOG_FATAL(...) \ - do { \ - } while(0) +#define LOG_OUTPUT(...) Log.output(...) + +#if HASP_LOG_LEVEL > LOG_LEVEL_FATAL +#define LOG_FATAL(...) \ + Log.fatal(__VA_ARGS__); \ + while (true) \ + { \ + } +#else +#define LOG_FATAL(...) \ + do \ + { \ + } while (0) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_ALERT - #define LOG_ALERT(...) Log.alert(__VA_ARGS__) +#define LOG_ALERT(...) Log.alert(__VA_ARGS__) #else - #define LOG_ALERT(...) +#define LOG_ALERT(...) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_CRITICAL - #define LOG_CRITICAL(...) Log.critical(__VA_ARGS__) +#define LOG_CRITICAL(...) Log.critical(__VA_ARGS__) #else - #define LOG_CRITICAL(...) +#define LOG_CRITICAL(...) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_ERROR - #define LOG_ERROR(...) Log.error(__VA_ARGS__) +#define LOG_ERROR(...) Log.error(__VA_ARGS__) #else - #define LOG_ERROR(...) +#define LOG_ERROR(...) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_WARNING - #define LOG_WARNING(...) Log.warning(__VA_ARGS__) +#define LOG_WARNING(...) Log.warning(__VA_ARGS__) #else - #define LOG_WARNING(...) +#define LOG_WARNING(...) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_INFO - #define LOG_INFO(...) Log.notice(__VA_ARGS__) +#define LOG_INFO(...) Log.notice(__VA_ARGS__) #else - #define LOG_INFO(...) +#define LOG_INFO(...) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_TRACE - #define LOG_TRACE(...) Log.trace(__VA_ARGS__) +#define LOG_TRACE(...) Log.trace(__VA_ARGS__) #else - #define LOG_TRACE(...) +#define LOG_TRACE(...) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_VERBOSE - #define LOG_VERBOSE(...) Log.verbose(__VA_ARGS__) +#define LOG_VERBOSE(...) Log.verbose(__VA_ARGS__) #else - #define LOG_VERBOSE(...) +#define LOG_VERBOSE(...) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_DEBUG - #define LOG_DEBUG(...) Log.debug(__VA_ARGS__) +#define LOG_DEBUG(...) Log.debug(__VA_ARGS__) #else - #define LOG_DEBUG(...) +#define LOG_DEBUG(...) #endif -#define LOG_OUTPUT(...) Log.output(...) +#endif #endif \ No newline at end of file diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index abb7c91e..be0aa63e 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -26,6 +26,8 @@ /* Maximal horizontal and vertical resolution to support by the library.*/ #define LV_HOR_RES_MAX (TFT_WIDTH) #define LV_VER_RES_MAX (TFT_HEIGHT) +#define LV_HOR_RES (TFT_WIDTH) +#define LV_VER_RES (TFT_HEIGHT) /* Color depth: * - 1: 1 byte per pixel @@ -181,7 +183,7 @@ typedef void* lv_group_user_data_t; typedef void* lv_fs_drv_user_data_t; /*File system interface*/ -#define LV_USE_FS_IF 1 +#define LV_USE_FS_IF 0 #if LV_USE_FS_IF # define LV_FS_IF_FATFS '\0' #if defined(ARDUINO_ARCH_ESP32) // || defined(ARDUINO_ARCH_ESP8266) @@ -251,12 +253,18 @@ typedef void* lv_img_decoder_user_data_t; /* 1: use a custom tick source. * It removes the need to manually update the tick with `lv_tick_inc`) */ +#ifdef ARDUINO + #define LV_TICK_CUSTOM 1 #if LV_TICK_CUSTOM == 1 #define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the sys time function*/ #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/ #endif /*LV_TICK_CUSTOM*/ +#else +#define LV_TICK_CUSTOM 0 +#endif + typedef void* lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ typedef void* lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/ @@ -280,7 +288,7 @@ typedef void* lv_indev_drv_user_data_t; /*Type of user data in the in /* 1: Print the log with 'printf'; * 0: user need to register a callback with `lv_log_register_print_cb`*/ -# define LV_LOG_PRINTF 0 +# define LV_LOG_PRINTF 1 #endif /*LV_USE_LOG*/ /*================= @@ -431,7 +439,7 @@ typedef void* lv_font_user_data_t; /*Always enable at least on theme*/ #define LV_USE_THEME_MATERIAL 1 /*A fast and impressive theme*/ -#define LV_THEME_DEFAULT_INIT lv_theme_hasp_init // We init the theme ourselves +#define LV_THEME_DEFAULT_INIT lv_theme_material_init // lv_theme_hasp_init // We init the theme ourselves #define LV_THEME_DEFAULT_COLOR_PRIMARY LV_COLOR_RED #define LV_THEME_DEFAULT_COLOR_SECONDARY LV_COLOR_BLUE #define LV_THEME_DEFAULT_FLAG 0 //LV_THEME_MATERIAL_FLAG_NONE diff --git a/platformio.ini b/platformio.ini index 7b671f8f..4dc6ca5c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,7 +34,6 @@ extra_default_envs = ; Common environment settings ;*************************************************** [env] -framework = arduino upload_speed = 921600 monitor_speed = 115200 @@ -49,21 +48,20 @@ build_flags = -D LV_CONF_INCLUDE_SIMPLE ; for lvgl -D LV_LVGL_H_INCLUDE_SIMPLE ; for lv_drivers -D LV_COMP_CONF_INCLUDE_SIMPLE ; for components - ; -- littlevgl build options ------------------------------ + ; -- ESP build options ------------------------------------ -D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files ; -- ArduinoJson build options ---------------------------- -D ARDUINOJSON_DECODE_UNICODE=1 ; for utf-8 symbols - -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments + ;-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments ; -- StreamUtils build options ---------------------------- -D STREAMUTILS_ENABLE_EEPROM=1 ; for STM32, it also supports EEPROM ; -- Hasp build options ---------------------------- -D HASP_VER_MAJ=0 - -D HASP_VER_MIN=3 - -D HASP_VER_REV=3 + -D HASP_VER_MIN=4 + -D HASP_VER_REV=0 -D HASP_LOG_LEVEL=9 - -D HASP_USE_CONFIG=1 ; Native application, not library ${override.build_flags} ; -- Shared library dependencies in all environments @@ -93,6 +91,7 @@ extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py ; -- Platform specific build flags [esp32] +framework = arduino build_flags = ${env.build_flags} -D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer @@ -108,6 +107,7 @@ build_flags = ;-D HASP_USE_SPIFFS=1 -D HASP_USE_LITTLEFS=1 ;-D HASP_USE_EEPROM=1 + -D HASP_USE_CONFIG=1 ; Native application, not library ; -- LittleFS build options ------------------------ -D CONFIG_LITTLEFS_FOR_IDF_3_2 @@ -146,6 +146,7 @@ hspi = -D TFT_SCLK=14 [esp8266] +framework = arduino build_flags= -D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer -D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages @@ -163,6 +164,7 @@ build_flags= -D HASP_USE_LITTLEFS=1 -D HASP_USE_EEPROM=1 -D HASP_USE_ETHERNET=0 + -D HASP_USE_CONFIG=1 ; Native application, not library lib_ignore = ESP32 BLE Arduino @@ -174,6 +176,7 @@ lib_ignore = lib_deps = [stm32f4] +framework = arduino build_flags= -I include/stm32f4 -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages @@ -187,6 +190,7 @@ build_flags= -D HASP_USE_SYSLOG=0 ; Needs UDP -D HASP_USE_SPIFFS=0 -D HASP_USE_LITTLEFS=0 + -D HASP_USE_CONFIG=1 ; Native application, not library lib_deps = ; sstaub/Ticker @ ^3.2.0 @@ -219,3 +223,122 @@ lib_deps = ; ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/master.zip ; lv_drivers@^6.0.2 ;src_filter = +<*> +<../drivers/sdl2> + +[env:emulator_64bits] +platform = native@^1.1.3 +extra_scripts = tools/sdl2_build_extra.py +build_flags = + ${env.build_flags} + ; ----- Monitor + -D TFT_WIDTH=800 + -D TFT_HEIGHT=480 + ; SDL drivers options + ;-D LV_LVGL_H_INCLUDE_SIMPLE + ;-D LV_DRV_NO_CONF + -D USE_MONITOR + -D MONITOR_ZOOM=1 ; 2 + -D USE_MOUSE + -D USE_MOUSEWHEEL + -D USE_KEYBOARD + ; ----- ArduinoJson + -D ARDUINOJSON_DECODE_UNICODE=1 + -D HASP_NUM_PAGES=4 + -D HASP_USE_SPIFFS=0 + -D HASP_USE_LITTLEFS=0 + -D HASP_USE_EEPROM=0 + -D HASP_USE_GPIO=0 + -D HASP_USE_CONFIG=0 ; Standalone application, as library + -D HASP_USE_DEBUG=1 + -D HASP_USE_MQTT=1 + -D MQTT_MAX_PACKET_SIZE=2048 + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO + ;-D LV_LOG_PRINTF=1 + ; Add recursive dirs for hal headers search + !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" + -mconsole + -lSDL2 + -D PAHO_MQTT_STATIC + -D _WIN64 + -D WINDOWS ; We add this for code branching in hasp + -D WIN32_LEAN_AND_MEAN + -DPAHO_WITH_SSL=FALSE + -DPAHO_BUILD_DOCUMENTATION=FALSE + -DPAHO_BUILD_SAMPLES=FALSE + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_VERBOSE_MAKEFILE=TRUE + ;-D NO_PERSISTENCE + -I.pio/libdeps/emulator_64bits/paho/src + -I.pio/libdeps/emulator_64bits/ArduinoJson/src + -I lib/ArduinoJson/src + -I lib/lv_fs_if + -l"ws2_32" + -lrpcrt4 + -lcrypt32 + -lmingw32 + -lSDL2main + -lSDL2 + -mwindows + -lm + -ldinput8 + -ldxguid + -ldxerr8 + -luser32 + -lgdi32 + -lwinmm + -limm32 + -lole32 + -loleaut32 + -lshell32 + -lversion + -luuid + -lsetupapi + -lhid + ;-v + + +lib_deps = + ${env.lib_deps} + lv_drivers@~7.9.0 + ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip + https://github.com/eclipse/paho.mqtt.c.git + bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + +lib_ignore = paho + +src_filter = + +<*> + -<*.h> + +<../hal/sdl2> + +<../.pio/libdeps/emulator_64bits/paho/src/*.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> + -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> + - + - + - + -<../.pio/libdeps/emulator_64bits/lv_fs_if/lv_fs_pc.c> + -<../.pio/libdeps/emulator_64bits/ArduinoLog/ArduinoLog.cpp> + - + - + - + - + - + - + - + - + - + - + - + + + + + + + - + + + - + - + -<../lib/lv_fs_if> + -<../lib/lv_fs_if/lv_fs_if.cpp> + -<../lib/lv_fs_if/lv_fs_if.h> + -<../lib/lv_fs_if/lv_fs_spiffs.cpp> + -<../lib/lv_fs_if/lv_fs_spiffs.h> + +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> diff --git a/src/main.cpp b/src/main_arduino.cpp similarity index 92% rename from src/main.cpp rename to src/main_arduino.cpp index 818f0919..b8eb8087 100644 --- a/src/main.cpp +++ b/src/main_arduino.cpp @@ -1,18 +1,26 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ +#ifdef ARDUINO + #include #include "hasp_conf.h" // load first -#include "hasp_debug.h" -#include "hasp_config.h" -#include "hasp_gui.h" +#if HASP_USE_CONFIG > 0 + #include "hasp_debug.h" +#endif + +#if HASP_USE_CONFIG > 0 + #include "hasp_config.h" + #include "hasp_gui.h" +#endif + #include "hasp_oobe.h" #include "hasp/hasp_dispatch.h" #include "hasp/hasp.h" -#include "net/hasp_network.h" +#include "sys/net/hasp_network.h" #include "dev/device.h" @@ -49,6 +57,7 @@ void setup() dispatchSetup(); guiSetup(); debugSetup(); // Init the console + #if HASP_USE_GPIO > 0 gpioSetup(); #endif @@ -137,7 +146,7 @@ void loop() /* Timer Loop */ if(millis() - mainLastLoopTime >= 1000) { /* Runs Every Second */ - haspEverySecond(); + haspEverySecond(); // sleep timer debugEverySecond(); // statusupdate #if HASP_USE_OTA > 0 @@ -177,4 +186,6 @@ void loop() #else delay(6); #endif -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/main_windows.cpp b/src/main_windows.cpp new file mode 100644 index 00000000..b3b021cd --- /dev/null +++ b/src/main_windows.cpp @@ -0,0 +1,120 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifdef WINDOWS + + #include "lvgl.h" + #include "app_hal.h" + + #include "hasp_conf.h" + #include "hasp_debug.h" + + #include "hasp/hasp_dispatch.h" + #include "hasp/hasp.h" + + #include "dev/device.h" + #include "app_hal.h" + +bool isConnected; +uint8_t mainLoopCounter = 0; +unsigned long mainLastLoopTime = 0; + +void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, + const char * descr) +{ + printf("%s %d\n", file, line); +} + +void setup() +{ + printf("%s %d\n", __FILE__, __LINE__); + fflush(stdout); + lv_init(); + lv_log_register_print_cb(debugLvglLogEvent); + + printf("%s %d\n", __FILE__, __LINE__); + fflush(stdout); + hal_setup(); + + printf("%s %d\n", __FILE__, __LINE__); + haspDevice.pre_setup(); + + printf("%s %d\n", __FILE__, __LINE__); + dispatchSetup(); + // debugSetup(); // Init the console + + #if HASP_USE_MQTT > 0 + printf("%s %d\n", __FILE__, __LINE__); + mqttSetup(); // Load Hostname before starting WiFi + #endif + + printf("%s %d\n", __FILE__, __LINE__); + haspSetup(); + mainLastLoopTime = millis() - 1000; // reset loop counter + delay(250); + + mqttStart(); +} + +void loop() +{ + haspLoop(); + + // debugLoop(); // Console + haspDevice.loop(); + + /* Timer Loop */ + if(millis() - mainLastLoopTime >= 1000) { + /* Runs Every Second */ + haspEverySecond(); // sleep timer + + #if HASP_USE_OTA > 0 + otaEverySecond(); // progressbar + #endif + + /* Runs Every 5 Seconds */ + if(mainLoopCounter == 0 || mainLoopCounter == 5) { + + haspDevice.loop_5s(); + } + + /* Reset loop counter every 10 seconds */ + if(mainLoopCounter >= 9) { + mainLoopCounter = 0; + } else { + mainLoopCounter++; + } + mainLastLoopTime += 1000; + } + + delay(6); +} + + #ifdef WINDOWS +int main(int argv, char ** args) +{ + printf("%s %d\n", __FILE__, __LINE__); + fflush(stdout); + setup(); + std::cout << "HSetup OK\n"; + + while(1) { + SDL_Delay(5); + lv_task_handler(); + fflush(stdout); + } + std::cout << "Hloop OK\n"; + + return 0; +} + + #else +void loop() +{ + delay(5); + lv_task_handler(); +} + + #endif + +#endif \ No newline at end of file diff --git a/src/svc/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h similarity index 84% rename from src/svc/hasp_mqtt.h rename to src/mqtt/hasp_mqtt.h index c1343a3c..6d3dcbde 100644 --- a/src/svc/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -4,7 +4,11 @@ #ifndef HASP_MQTT_H #define HASP_MQTT_H -#include "ArduinoJson.h" +#include + +#include "hasp_conf.h" + +#define __FlashStringHelper char void mqttSetup(); void mqttLoop(); @@ -22,6 +26,6 @@ bool mqttGetConfig(const JsonObject & settings); bool mqttSetConfig(const JsonObject & settings); #endif -String mqttGetNodename(void); +//String mqttGetNodename(void); #endif \ No newline at end of file diff --git a/src/svc/hasp_mqtt.cpp b/src/mqtt/hasp_mqtt.old similarity index 99% rename from src/svc/hasp_mqtt.cpp rename to src/mqtt/hasp_mqtt.old index 044e68a0..0c67bc24 100644 --- a/src/svc/hasp_mqtt.cpp +++ b/src/mqtt/hasp_mqtt.old @@ -35,7 +35,7 @@ EthernetClient mqttNetworkClient; #endif #include "hasp_hal.h" - #include "hasp_debug.h" + #include "log/hasp_debug.h" #include "hasp_config.h" #include "../hasp/hasp_dispatch.h" diff --git a/src/svc/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp similarity index 99% rename from src/svc/hasp_mqtt_ha.cpp rename to src/mqtt/hasp_mqtt_ha.cpp index 90069126..a5e1bfe7 100644 --- a/src/svc/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -3,7 +3,8 @@ #include "ArduinoJson.h" #include "hasp_conf.h" -#if HASP_USE_MQTT > 0 + +#if 0 && HASP_USE_MQTT > 0 #include "PubSubClient.h" diff --git a/src/svc/hasp_mqtt_ha.h b/src/mqtt/hasp_mqtt_ha.h similarity index 100% rename from src/svc/hasp_mqtt_ha.h rename to src/mqtt/hasp_mqtt_ha.h diff --git a/src/mqtt/hasp_mqtt_paho.cpp b/src/mqtt/hasp_mqtt_paho.cpp new file mode 100644 index 00000000..07ebb2b5 --- /dev/null +++ b/src/mqtt/hasp_mqtt_paho.cpp @@ -0,0 +1,423 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#include + +#include "hasp_conf.h" + +#if HASP_USE_MQTT > 0 + #ifdef USE_PAHO + + /******************************************************************************* + * Copyright (c) 2012, 2020 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * https://www.eclipse.org/legal/epl-2.0/ + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial contribution + *******************************************************************************/ + + #include + #include + #include + #include + #include + + #include "MQTTAsync.h" + + #include "hasp_mqtt.h" // functions to implement here + + #include "hasp/hasp_dispatch.h" // for dispatch_topic_payload + #include "hasp_debug.h" // for logging + + #if !defined(_WIN32) + #include + #else + #include + #endif + + #if defined(_WRS_KERNEL) + #include + #endif + + #define ADDRESS "10.4.0.5:1883" + #define CLIENTID "ExampleClientSub" + #define TOPIC "hasp/plate35/" + #define QOS 1 + #define TIMEOUT 10000L + +const char * mqttNodeTopic = TOPIC; +const char * mqttGroupTopic = TOPIC; +// char mqttNodeTopic[24]; +// char mqttGroupTopic[24]; +bool mqttEnabled = false; +bool mqttHAautodiscover = true; + + //////////////////////////////////////////////////////////////////////////////////////////////////// + // These defaults may be overwritten with values saved by the web interface + #ifndef MQTT_HOST + #define MQTT_HOST ""; + #endif + + #ifndef MQTT_PORT + #define MQTT_PORT 1883; + #endif + + #ifndef MQTT_USER + #define MQTT_USER ""; + #endif + + #ifndef MQTT_PASSW + #define MQTT_PASSW ""; + #endif + #ifndef MQTT_NODENAME + #define MQTT_NODENAME ""; + #endif + #ifndef MQTT_GROUPNAME + #define MQTT_GROUPNAME ""; + #endif + + #ifndef MQTT_PREFIX + #define MQTT_PREFIX "hasp" + #endif + + #define LWT_TOPIC "LWT" + +char mqttServer[16] = MQTT_HOST; +char mqttUser[23] = MQTT_USER; +char mqttPassword[32] = MQTT_PASSW; +char mqttNodeName[16] = MQTT_NODENAME; +char mqttGroupName[16] = MQTT_GROUPNAME; +uint16_t mqttPort = MQTT_PORT; + +MQTTAsync mqtt_client; + +int disc_finished = 0; +int subscribed = 0; +int connected = 0; + +static bool mqttPublish(const char * topic, const char * payload, size_t len, bool retain = false); + +/* ===== Paho event callbacks ===== */ + +void connlost(void * context, char * cause) +{ + MQTTAsync client = (MQTTAsync)context; + MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer; + int rc; + connected = 0; + + printf("\nConnection lost\n"); + if(cause) printf(" cause: %s\n", cause); + + printf("Reconnecting\n"); + conn_opts.keepAliveInterval = 20; + conn_opts.cleansession = 1; + if((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS) { + printf("Failed to start connect, return code %d\n", rc); + } +} + +// Receive incoming messages +static void mqtt_message_cb(char * topic, char * payload, unsigned int length) +{ // Handle incoming commands from MQTT + if(length + 1 >= MQTT_MAX_PACKET_SIZE) { + LOG_ERROR(TAG_MQTT_RCV, F("Payload too long (%d bytes)"), length); + return; + } else { + payload[length] = '\0'; + } + + LOG_TRACE(TAG_MQTT_RCV, F("%s = %s"), topic, (char *)payload); + + if(topic == strstr(topic, mqttNodeTopic)) { // startsWith mqttNodeTopic + + // Node topic + topic += strlen(mqttNodeTopic); // shorten topic + + } else if(topic == strstr(topic, mqttGroupTopic)) { // startsWith mqttGroupTopic + + // Group topic + topic += strlen(mqttGroupTopic); // shorten topic + dispatch_topic_payload(topic, (const char *)payload); + return; + + } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic + if(mqttHAautodiscover && !strcasecmp_P((char *)payload, PSTR("online"))) { + // dispatch_current_state(); + // mqtt_ha_register_auto_discovery(); + } + return; + + } else { + // Other topic + LOG_ERROR(TAG_MQTT, F(D_MQTT_INVALID_TOPIC)); + return; + } + + // catch a dangling LWT from a previous connection if it appears + if(!strcmp_P(topic, PSTR(LWT_TOPIC))) { // endsWith LWT + if(!strcasecmp_P((char *)payload, PSTR("offline"))) { + { + char msg[8]; + char tmp_topic[strlen(mqttNodeTopic) + 8]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" LWT_TOPIC), mqttNodeTopic); + snprintf_P(msg, sizeof(msg), PSTR("online")); + + // /*bool res =*/mqttClient.publish(tmp_topic, msg, true); + mqttPublish(tmp_topic, msg, true); + } + + } else { + // LOG_TRACE(TAG_MQTT, F("ignoring LWT = online")); + } + } else { + dispatch_topic_payload(topic, (const char *)payload); + } +} + +int msgarrvd(void * context, char * topicName, int topicLen, MQTTAsync_message * message) +{ + printf("MQT RCV >> "); + printf("%s => %.*s (%d)\n", topicName, message->payloadlen, (char *)message->payload, message->payloadlen); + + char msg[message->payloadlen + 1]; + memcpy(msg, (char *)message->payload, message->payloadlen); + msg[message->payloadlen] = '\0'; + + mqtt_message_cb(topicName, (char *)message->payload, message->payloadlen); + + MQTTAsync_freeMessage(&message); + MQTTAsync_free(topicName); + return 1; +} + +void onDisconnectFailure(void * context, MQTTAsync_failureData * response) +{ + printf("Disconnect failed, rc %d\n", response->code); + disc_finished = 1; +} + +void onDisconnect(void * context, MQTTAsync_successData * response) +{ + printf("Successful disconnection\n"); + disc_finished = 1; + connected = 0; +} + +void onSubscribe(void * context, MQTTAsync_successData * response) +{ + printf("Subscribe succeeded %d\n", response->token); + subscribed = 1; +} + +void onSubscribeFailure(void * context, MQTTAsync_failureData * response) +{ + printf("Subscribe failed, rc %d\n", response->code); +} + +void onConnectFailure(void * context, MQTTAsync_failureData * response) +{ + connected = 0; + printf("Connect failed, rc %d\n", response->code); +} + +void mqtt_subscribe(void * context, const char * topic) +{ + MQTTAsync client = (MQTTAsync)context; + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + int rc; + + printf("Subscribing to topic %s\nfor client %s using QoS%d\n\n", topic, CLIENTID, QOS); + opts.onSuccess = onSubscribe; + opts.onFailure = onSubscribeFailure; + opts.context = client; + if((rc = MQTTAsync_subscribe(client, topic, QOS, &opts)) != MQTTASYNC_SUCCESS) { + printf("Failed to start subscribe, return code %d\n", rc); + } +} + +void onConnect(void * context, MQTTAsync_successData * response) +{ + MQTTAsync client = (MQTTAsync)context; + connected = 1; + + printf("Successful connection\n"); + + mqtt_subscribe(context, TOPIC "command/#"); + mqtt_subscribe(context, TOPIC "command"); + mqtt_subscribe(context, TOPIC "light"); + mqtt_subscribe(context, TOPIC "dim"); + + mqtt_send_object_state(0, 0, "connected"); + std::cout << std::endl; +} + +void onSendFailure(void * context, MQTTAsync_failureData * response) +{ + MQTTAsync client = (MQTTAsync)context; + MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; + int rc; + + printf("Message send failed token %d error code %d\n", response->token, response->code); + opts.onSuccess = onDisconnect; + opts.onFailure = onDisconnectFailure; + opts.context = client; + if((rc = MQTTAsync_disconnect(client, &opts)) != MQTTASYNC_SUCCESS) { + printf("Failed to start disconnect, return code %d\n", rc); + exit(EXIT_FAILURE); + } +} + +void onSend(void * context, MQTTAsync_successData * response) +{ + MQTTAsync client = (MQTTAsync)context; + MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; + int rc; + + printf("Message with token value %d delivery confirmed\n", response->token); + // opts.onSuccess = onDisconnect; + // opts.onFailure = onDisconnectFailure; + // opts.context = client; + // if ((rc = MQTTAsync_disconnect(client, &opts)) != MQTTASYNC_SUCCESS) + // { + // printf("Failed to start disconnect, return code %d\n", rc); + // exit(EXIT_FAILURE); + // } +} + +/* ===== Local HASP MQTT functions ===== */ + +static bool mqttPublish(const char * topic, const char * payload, size_t len, bool retain) +{ + if(mqttIsConnected()) { + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + MQTTAsync_message pubmsg = MQTTAsync_message_initializer; + int rc; + + opts.onSuccess = onSend; + opts.onFailure = onSendFailure; + opts.context = mqtt_client; + pubmsg.payload = (char *)payload; + pubmsg.payloadlen = (int)strlen(payload); + pubmsg.qos = QOS; + pubmsg.retained = 0; + if((rc = MQTTAsync_sendMessage(mqtt_client, topic, &pubmsg, &opts)) != MQTTASYNC_SUCCESS) { + LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " %s => %s"), topic, payload); + } else { + LOG_TRACE(TAG_MQTT_PUB, F("%s => %s"), topic, payload); + return true; + } + } else { + LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_CONNECTED)); + } + return false; +} + +/* ===== Public HASP MQTT functions ===== */ + +bool mqttIsConnected() +{ + return connected == 1; +} + +void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload) +{ + char tmp_topic[strlen(mqttNodeTopic) + 20]; + printf(("%sstate/%s\n"), mqttNodeTopic, subtopic); + snprintf_P(tmp_topic, sizeof(tmp_topic), ("%sstate/%s"), mqttNodeTopic, subtopic); + mqttPublish(tmp_topic, payload, false); +} + +void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload) +{ + char tmp_topic[strlen(mqttNodeTopic) + 20]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/p%ub%u"), mqttNodeTopic, pageid, btnid); + mqttPublish(tmp_topic, payload, false); +} + +void mqttStart() +{ + MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer; + int rc; + int ch; + + if((rc = MQTTAsync_create(&mqtt_client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_NONE, NULL)) != + MQTTASYNC_SUCCESS) { + printf("Failed to create client, return code %d\n", rc); + rc = EXIT_FAILURE; + return; + } + + if((rc = MQTTAsync_setCallbacks(mqtt_client, mqtt_client, connlost, msgarrvd, NULL)) != MQTTASYNC_SUCCESS) { + printf("Failed to set callbacks, return code %d\n", rc); + rc = EXIT_FAILURE; + return; + } + + conn_opts.keepAliveInterval = 20; + conn_opts.cleansession = 1; + conn_opts.onSuccess = onConnect; + conn_opts.onFailure = onConnectFailure; + conn_opts.context = mqtt_client; + if((rc = MQTTAsync_connect(mqtt_client, &conn_opts)) != MQTTASYNC_SUCCESS) { + printf("Failed to start connect, return code %d\n", rc); + rc = EXIT_FAILURE; + // goto destroy_exit; + } else { + } + + // while (!subscribed && !finished) + // #if defined(_WIN32) + // Sleep(100); + // #else + // usleep(10000L); + // #endif + + // if (finished) + // goto exit; +} + +void mqttStop() +{ + int rc; + MQTTAsync_disconnectOptions disc_opts = MQTTAsync_disconnectOptions_initializer; + disc_opts.onSuccess = onDisconnect; + disc_opts.onFailure = onDisconnectFailure; + if((rc = MQTTAsync_disconnect(mqtt_client, &disc_opts)) != MQTTASYNC_SUCCESS) { + printf("Failed to start disconnect, return code %d\n", rc); + rc = EXIT_FAILURE; + // goto destroy_exit; + } + // while (!disc_finished) + // { + // #if defined(_WIN32) + // Sleep(100); + // #else + // usleep(10000L); + // #endif + // } + + // destroy_exit: + // MQTTAsync_destroy(&client); + // exit: + // return rc; +} + +void mqttSetup(){}; + +void mqttLoop(){}; + +void mqttEvery5Seconds(bool wifiIsConnected){}; + + // String mqttGetNodename(void){return "palte35"}; + + #endif // USE_PAHO +#endif // USE_MQTT \ No newline at end of file diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp new file mode 100644 index 00000000..70701959 --- /dev/null +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -0,0 +1,455 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#include "hasp_conf.h" + +#if HASP_USE_MQTT > 0 + #ifdef USE_PUBSUBCLIENT + + #include "PubSubClient.h" + + #include "hasp/hasp.h" + #include "hasp_mqtt.h" + #include "hasp_mqtt_ha.h" + + #if defined(ARDUINO_ARCH_ESP32) + #include +WiFiClient mqttNetworkClient; + #elif defined(ARDUINO_ARCH_ESP8266) + #include + #include + #include +WiFiClient mqttNetworkClient; + #else + #if defined(STM32F4xx) && HASP_USE_WIFI > 0 +// #include +WiFiSpiClient mqttNetworkClient; + #else + #if defined(W5500_MOSI) && defined(W5500_MISO) && defined(W5500_SCLK) + #define W5500_LAN + #include + #else + #include + #endif + +EthernetClient mqttNetworkClient; + #endif + #endif + + #include "hasp_hal.h" + #include "log/hasp_debug.h" + #include "hasp_config.h" + + #include "../hasp/hasp_dispatch.h" + + #ifdef USE_CONFIG_OVERRIDE + #include "user_config_override.h" + #endif + +char mqttNodeTopic[24]; +char mqttGroupTopic[24]; +bool mqttEnabled = false; +bool mqttHAautodiscover = true; + + //////////////////////////////////////////////////////////////////////////////////////////////////// + // These defaults may be overwritten with values saved by the web interface + #ifndef MQTT_HOST + #define MQTT_HOST ""; + #endif + + #ifndef MQTT_PORT + #define MQTT_PORT 1883; + #endif + + #ifndef MQTT_USER + #define MQTT_USER ""; + #endif + + #ifndef MQTT_PASSW + #define MQTT_PASSW ""; + #endif + #ifndef MQTT_NODENAME + #define MQTT_NODENAME ""; + #endif + #ifndef MQTT_GROUPNAME + #define MQTT_GROUPNAME ""; + #endif + + #ifndef MQTT_PREFIX + #define MQTT_PREFIX "hasp" + #endif + + #define LWT_TOPIC "LWT" + +char mqttServer[16] = MQTT_HOST; +char mqttUser[23] = MQTT_USER; +char mqttPassword[32] = MQTT_PASSW; +char mqttNodeName[16] = MQTT_NODENAME; +char mqttGroupName[16] = MQTT_GROUPNAME; +uint16_t mqttPort = MQTT_PORT; +PubSubClient mqttClient(mqttNetworkClient); + +static bool mqttPublish(const char * topic, const char * payload, size_t len, bool retain = false) +{ + if(mqttIsConnected()) { + if(mqttClient.beginPublish(topic, len, retain)) { + mqttClient.write((uint8_t *)payload, len); + mqttClient.endPublish(); + + LOG_TRACE(TAG_MQTT_PUB, F("%s => %s"), topic, payload); + return true; + } else { + LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " %s => %s"), topic, payload); + } + } else { + LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_CONNECTED)); + } + return false; +} + +static bool mqttPublish(const char * topic, const char * payload, bool retain = false) +{ + return mqttPublish(topic, payload, strlen(payload), retain); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Send changed values OUT + +bool mqttIsConnected() +{ + return mqttEnabled && mqttClient.connected(); +} + +void mqtt_send_lwt(bool online) +{ + char tmp_payload[8]; + char tmp_topic[strlen(mqttNodeTopic) + 4]; + strncpy(tmp_topic, mqttNodeTopic, sizeof(tmp_topic)); + strncat_P(tmp_topic, PSTR(LWT_TOPIC), sizeof(tmp_topic)); + // snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" LWT_TOPIC), mqttNodeTopic); + + size_t len = snprintf_P(tmp_payload, sizeof(tmp_payload), online ? PSTR("online") : PSTR("offline")); + bool res = mqttPublish(tmp_topic, tmp_payload, len, true); +} + +void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload) +{ + char tmp_topic[strlen(mqttNodeTopic) + 16]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/" HASP_OBJECT_NOTATION), mqttNodeTopic, pageid, btnid); + mqttPublish(tmp_topic, payload); +} + +void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload) +{ + char tmp_topic[strlen(mqttNodeTopic) + 20]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/%s"), mqttNodeTopic, subtopic); + mqttPublish(tmp_topic, payload); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Receive incoming messages +static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) +{ // Handle incoming commands from MQTT + if(length + 1 >= mqttClient.getBufferSize()) { + LOG_ERROR(TAG_MQTT_RCV, F("Payload too long (%d bytes)"), length); + return; + } else { + payload[length] = '\0'; + } + + LOG_TRACE(TAG_MQTT_RCV, F("%s = %s"), topic, (char *)payload); + + if(topic == strstr(topic, mqttNodeTopic)) { // startsWith mqttNodeTopic + + // Node topic + topic += strlen(mqttNodeTopic); // shorten topic + + } else if(topic == strstr(topic, mqttGroupTopic)) { // startsWith mqttGroupTopic + + // Group topic + topic += strlen(mqttGroupTopic); // shorten topic + dispatch_topic_payload(topic, (const char *)payload); + return; + + } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic + if(mqttHAautodiscover && !strcasecmp_P((char *)payload, PSTR("online"))) { + dispatch_current_state(); + mqtt_ha_register_auto_discovery(); + } + return; + + } else { + // Other topic + LOG_ERROR(TAG_MQTT, F(D_MQTT_INVALID_TOPIC)); + return; + } + + // catch a dangling LWT from a previous connection if it appears + if(!strcmp_P(topic, PSTR(LWT_TOPIC))) { // endsWith LWT + if(!strcasecmp_P((char *)payload, PSTR("offline"))) { + { + char msg[8]; + char tmp_topic[strlen(mqttNodeTopic) + 8]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" LWT_TOPIC), mqttNodeTopic); + snprintf_P(msg, sizeof(msg), PSTR("online")); + + // /*bool res =*/mqttClient.publish(tmp_topic, msg, true); + mqttPublish(tmp_topic, msg, true); + } + + } else { + // LOG_TRACE(TAG_MQTT, F("ignoring LWT = online")); + } + } else { + dispatch_topic_payload(topic, (const char *)payload); + } +} + +static void mqttSubscribeTo(const __FlashStringHelper * format, const char * data) +{ + char tmp_topic[strlen_P((PGM_P)format) + 2 + strlen(data)]; + snprintf_P(tmp_topic, sizeof(tmp_topic), (PGM_P)format, data); + if(mqttClient.subscribe(tmp_topic)) { + LOG_VERBOSE(TAG_MQTT, F(D_BULLET D_MQTT_SUBSCRIBED), tmp_topic); + } else { + LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_SUBSCRIBED), tmp_topic); + } +} + +void mqttStart() +{ + char buffer[64]; + char mqttClientId[64]; + char lastWillPayload[8]; + static uint8_t mqttReconnectCount = 0; + // bool mqttFirstConnect = true; + + mqttClient.setServer(mqttServer, 1883); + // mqttClient.setSocketTimeout(10); //in seconds + + /* Construct unique Client ID*/ + { + String mac = halGetMacAddress(3, ""); + mac.toLowerCase(); + memset(mqttClientId, 0, sizeof(mqttClientId)); + snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR(D_MQTT_DEFAULT_NAME), mac.c_str()); + LOG_INFO(TAG_MQTT, mqttClientId); + } + + // Attempt to connect and set LWT and Clean Session + snprintf_P(buffer, sizeof(buffer), PSTR("%s" LWT_TOPIC), mqttNodeTopic); // lastWillTopic + snprintf_P(lastWillPayload, sizeof(lastWillPayload), PSTR("offline")); // lastWillPayload + + haspProgressMsg(F(D_MQTT_CONNECTING)); + haspProgressVal(mqttReconnectCount * 5); + if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, true, lastWillPayload, true)) { + // Retry until we give up and restart after connectTimeout seconds + mqttReconnectCount++; + + switch(mqttClient.state()) { + case MQTT_CONNECTION_TIMEOUT: + LOG_WARNING(TAG_MQTT, F("Connection timeout")); + break; + case MQTT_CONNECTION_LOST: + LOG_WARNING(TAG_MQTT, F("Connection lost")); + break; + case MQTT_CONNECT_FAILED: + LOG_WARNING(TAG_MQTT, F("Connection failed")); + break; + case MQTT_DISCONNECTED: + snprintf_P(buffer, sizeof(buffer), PSTR(D_MQTT_DISCONNECTED)); + break; + case MQTT_CONNECTED: + break; + case MQTT_CONNECT_BAD_PROTOCOL: + LOG_WARNING(TAG_MQTT, F("MQTT version not suported")); + break; + case MQTT_CONNECT_BAD_CLIENT_ID: + LOG_WARNING(TAG_MQTT, F("Client ID rejected")); + break; + case MQTT_CONNECT_UNAVAILABLE: + LOG_WARNING(TAG_MQTT, F("Server unavailable")); + break; + case MQTT_CONNECT_BAD_CREDENTIALS: + LOG_WARNING(TAG_MQTT, F("Bad credentials")); + break; + case MQTT_CONNECT_UNAUTHORIZED: + LOG_WARNING(TAG_MQTT, F("Unauthorized")); + break; + default: + LOG_WARNING(TAG_MQTT, F("Unknown failure")); + } + + if(mqttReconnectCount > 20) { + LOG_ERROR(TAG_MQTT, F("Retry count exceeded, rebooting...")); + dispatch_reboot(false); + } + return; + } + + LOG_INFO(TAG_MQTT, F(D_MQTT_CONNECTED), mqttServer, mqttClientId); + + // Subscribe to our incoming topics + const __FlashStringHelper * F_topic; + F_topic = F("%scommand/#"); + mqttSubscribeTo(F_topic, mqttGroupTopic); + mqttSubscribeTo(F_topic, mqttNodeTopic); + F_topic = F("%sconfig/#"); + mqttSubscribeTo(F_topic, mqttGroupTopic); + mqttSubscribeTo(F_topic, mqttNodeTopic); + mqttSubscribeTo(F("%slight/#"), mqttNodeTopic); + mqttSubscribeTo(F("%sbrightness/#"), mqttNodeTopic); + // mqttSubscribeTo(F("%s"LWT_TOPIC), mqttNodeTopic); + mqttSubscribeTo(F("hass/status"), mqttClientId); + + /* Home Assistant auto-configuration */ + if(mqttHAautodiscover) mqttSubscribeTo(F("homeassistant/status"), mqttClientId); + + // Force any subscribed clients to toggle offline/online when we first connect to + // make sure we get a full panel refresh at power on. Sending offline, + // "online" will be sent by the mqttStatusTopic subscription action. + mqtt_send_lwt(true); + + // mqttFirstConnect = false; + mqttReconnectCount = 0; + + haspReconnect(); + haspProgressVal(255); + + dispatch_current_state(); +} + +void mqttSetup() +{ + mqttEnabled = strlen(mqttServer) > 0 && mqttPort > 0; + if(mqttEnabled) { + mqttClient.setServer(mqttServer, mqttPort); + mqttClient.setCallback(mqtt_message_cb); + // if(!mqttClient.setBufferSize(1024)) { + // LOG_ERROR(TAG_MQTT, F("Buffer allocation failed")); + // } else { + LOG_INFO(TAG_MQTT, F(D_MQTT_STARTED), mqttClient.getBufferSize()); + // } + } else { + LOG_WARNING(TAG_MQTT, F(D_MQTT_NOT_CONFIGURED)); + } +} + +void mqttLoop(void) +{ + if(mqttEnabled) mqttClient.loop(); +} + +void mqttEvery5Seconds(bool networkIsConnected) +{ + if(mqttEnabled && networkIsConnected && !mqttClient.connected()) { + LOG_TRACE(TAG_MQTT, F(D_MQTT_RECONNECTING)); + mqttStart(); + } +} + +String mqttGetNodename() +{ + return mqttNodeName; +} + +void mqttStop() +{ + if(mqttEnabled && mqttClient.connected()) { + LOG_TRACE(TAG_MQTT, F(D_MQTT_DISCONNECTING)); + mqtt_send_lwt(false); + mqttClient.disconnect(); + LOG_INFO(TAG_MQTT, F(D_MQTT_DISCONNECTED)); + } +} + + #if HASP_USE_CONFIG > 0 +bool mqttGetConfig(const JsonObject & settings) +{ + bool changed = false; + + if(strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)].as().c_str()) != 0) changed = true; + settings[FPSTR(FP_CONFIG_NAME)] = mqttNodeName; + + if(strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)].as().c_str()) != 0) changed = true; + settings[FPSTR(FP_CONFIG_GROUP)] = mqttGroupName; + + if(strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)].as().c_str()) != 0) changed = true; + settings[FPSTR(FP_CONFIG_HOST)] = mqttServer; + + if(mqttPort != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true; + settings[FPSTR(FP_CONFIG_PORT)] = mqttPort; + + if(strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true; + settings[FPSTR(FP_CONFIG_USER)] = mqttUser; + + if(strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true; + settings[FPSTR(FP_CONFIG_PASS)] = mqttPassword; + + if(changed) configOutput(settings, TAG_MQTT); + return changed; +} + +/** Set MQTT Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ +bool mqttSetConfig(const JsonObject & settings) +{ + configOutput(settings, TAG_MQTT); + bool changed = false; + + changed |= configSet(mqttPort, settings[FPSTR(FP_CONFIG_PORT)], F("mqttPort")); + + if(!settings[FPSTR(FP_CONFIG_NAME)].isNull()) { + changed |= strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)]) != 0; + strncpy(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)], sizeof(mqttNodeName)); + } + // Prefill node name + if(strlen(mqttNodeName) == 0) { + String mac = halGetMacAddress(3, ""); + mac.toLowerCase(); + snprintf_P(mqttNodeName, sizeof(mqttNodeName), PSTR(D_MQTT_DEFAULT_NAME), mac.c_str()); + changed = true; + } + + if(!settings[FPSTR(FP_CONFIG_GROUP)].isNull()) { + changed |= strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)]) != 0; + strncpy(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)], sizeof(mqttGroupName)); + } + + if(strlen(mqttGroupName) == 0) { + strcpy_P(mqttGroupName, PSTR("plates")); + changed = true; + } + + if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) { + changed |= strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)]) != 0; + strncpy(mqttServer, settings[FPSTR(FP_CONFIG_HOST)], sizeof(mqttServer)); + } + + if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) { + changed |= strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)]) != 0; + strncpy(mqttUser, settings[FPSTR(FP_CONFIG_USER)], sizeof(mqttUser)); + } + + if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() && + settings[FPSTR(FP_CONFIG_PASS)].as() != String(FPSTR(D_PASSWORD_MASK))) { + changed |= strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)]) != 0; + strncpy(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)], sizeof(mqttPassword)); + } + + snprintf_P(mqttNodeTopic, sizeof(mqttNodeTopic), PSTR(MQTT_PREFIX "/%s/"), mqttNodeName); + snprintf_P(mqttGroupTopic, sizeof(mqttGroupTopic), PSTR(MQTT_PREFIX "/%s/"), mqttGroupName); + + return changed; +} + #endif // HASP_USE_CONFIG + + #endif // PUBSUBCLIENT + +#endif // HASP_USE_MQTT diff --git a/tools/sdl2_build_extra.py b/tools/sdl2_build_extra.py new file mode 100644 index 00000000..34ec79ce --- /dev/null +++ b/tools/sdl2_build_extra.py @@ -0,0 +1,33 @@ +Import("env", "projenv") + +for e in [ env, projenv ]: + # If compiler uses `-m32`, propagate it to linker. + # Add via script, because `-Wl,-m32` does not work. + if "-m32" in e['CCFLAGS']: + e.Append(LINKFLAGS = ["-m32"]) + +env.Append( + LINKFLAGS=[ + "-static", + "-static-libgcc", + "-static-libstdc++" + ] +) + +# Override unused "upload" to execute compiled binary +from SCons.Script import AlwaysBuild +AlwaysBuild(env.Alias("build", "$BUILD_DIR/${PROGNAME}", "$BUILD_DIR/${PROGNAME}")) + +# Add custom target to explorer +env.AddTarget( + name = "execute", + dependencies = "$BUILD_DIR\${PROGNAME}.exe", + actions = "$BUILD_DIR\${PROGNAME}.exe", +# actions = 'cmd.exe /C "start cmd.exe /C $BUILD_DIR\${PROGNAME}.exe"', + title = "Execute", + description = "Build and execute", + group="General" +) + +#print('=====================================') +#print(env.Dump()) From 1c707cfe5b67fa2a40f947177a1e89112c216b54 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Feb 2021 04:22:13 +0100 Subject: [PATCH 003/236] Add win32 environment --- platformio.ini | 119 ------------------------- platformio_override-template.ini | 1 + user_setups/win32/emulator_64bits].ini | 117 ++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 119 deletions(-) create mode 100644 user_setups/win32/emulator_64bits].ini diff --git a/platformio.ini b/platformio.ini index 4dc6ca5c..602d9c17 100644 --- a/platformio.ini +++ b/platformio.ini @@ -223,122 +223,3 @@ lib_deps = ; ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/master.zip ; lv_drivers@^6.0.2 ;src_filter = +<*> +<../drivers/sdl2> - -[env:emulator_64bits] -platform = native@^1.1.3 -extra_scripts = tools/sdl2_build_extra.py -build_flags = - ${env.build_flags} - ; ----- Monitor - -D TFT_WIDTH=800 - -D TFT_HEIGHT=480 - ; SDL drivers options - ;-D LV_LVGL_H_INCLUDE_SIMPLE - ;-D LV_DRV_NO_CONF - -D USE_MONITOR - -D MONITOR_ZOOM=1 ; 2 - -D USE_MOUSE - -D USE_MOUSEWHEEL - -D USE_KEYBOARD - ; ----- ArduinoJson - -D ARDUINOJSON_DECODE_UNICODE=1 - -D HASP_NUM_PAGES=4 - -D HASP_USE_SPIFFS=0 - -D HASP_USE_LITTLEFS=0 - -D HASP_USE_EEPROM=0 - -D HASP_USE_GPIO=0 - -D HASP_USE_CONFIG=0 ; Standalone application, as library - -D HASP_USE_DEBUG=1 - -D HASP_USE_MQTT=1 - -D MQTT_MAX_PACKET_SIZE=2048 - ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO - ;-D LV_LOG_PRINTF=1 - ; Add recursive dirs for hal headers search - !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" - -mconsole - -lSDL2 - -D PAHO_MQTT_STATIC - -D _WIN64 - -D WINDOWS ; We add this for code branching in hasp - -D WIN32_LEAN_AND_MEAN - -DPAHO_WITH_SSL=FALSE - -DPAHO_BUILD_DOCUMENTATION=FALSE - -DPAHO_BUILD_SAMPLES=FALSE - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_VERBOSE_MAKEFILE=TRUE - ;-D NO_PERSISTENCE - -I.pio/libdeps/emulator_64bits/paho/src - -I.pio/libdeps/emulator_64bits/ArduinoJson/src - -I lib/ArduinoJson/src - -I lib/lv_fs_if - -l"ws2_32" - -lrpcrt4 - -lcrypt32 - -lmingw32 - -lSDL2main - -lSDL2 - -mwindows - -lm - -ldinput8 - -ldxguid - -ldxerr8 - -luser32 - -lgdi32 - -lwinmm - -limm32 - -lole32 - -loleaut32 - -lshell32 - -lversion - -luuid - -lsetupapi - -lhid - ;-v - - -lib_deps = - ${env.lib_deps} - lv_drivers@~7.9.0 - ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip - https://github.com/eclipse/paho.mqtt.c.git - bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser - -lib_ignore = paho - -src_filter = - +<*> - -<*.h> - +<../hal/sdl2> - +<../.pio/libdeps/emulator_64bits/paho/src/*.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> - -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> - - - - - - - -<../.pio/libdeps/emulator_64bits/lv_fs_if/lv_fs_pc.c> - -<../.pio/libdeps/emulator_64bits/ArduinoLog/ArduinoLog.cpp> - - - - - - - - - - - - - - - - - - - - - - - + - + - + - - - + - - - - - -<../lib/lv_fs_if> - -<../lib/lv_fs_if/lv_fs_if.cpp> - -<../lib/lv_fs_if/lv_fs_if.h> - -<../lib/lv_fs_if/lv_fs_spiffs.cpp> - -<../lib/lv_fs_if/lv_fs_spiffs.h> - +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> diff --git a/platformio_override-template.ini b/platformio_override-template.ini index 46731383..ab5374e8 100644 --- a/platformio_override-template.ini +++ b/platformio_override-template.ini @@ -9,6 +9,7 @@ extra_configs = ; user_setups/esp32/*.ini ; user_setups/esp8266/*.ini ; user_setups/stm32f4xx/*.ini + ; user_setups/win32/*.ini [override] ; -- Hasp config options -------------------------------------- diff --git a/user_setups/win32/emulator_64bits].ini b/user_setups/win32/emulator_64bits].ini new file mode 100644 index 00000000..94dff354 --- /dev/null +++ b/user_setups/win32/emulator_64bits].ini @@ -0,0 +1,117 @@ +[env:emulator_64bits] +platform = native@^1.1.3 +extra_scripts = tools/sdl2_build_extra.py +build_flags = + ${env.build_flags} + ; ----- Monitor + -D TFT_WIDTH=800 + -D TFT_HEIGHT=480 + ; SDL drivers options + ;-D LV_LVGL_H_INCLUDE_SIMPLE + ;-D LV_DRV_NO_CONF + -D USE_MONITOR + -D MONITOR_ZOOM=1 ; 2 + -D USE_MOUSE + -D USE_MOUSEWHEEL + -D USE_KEYBOARD + ; ----- ArduinoJson + -D ARDUINOJSON_DECODE_UNICODE=1 + -D HASP_NUM_PAGES=4 + -D HASP_USE_SPIFFS=0 + -D HASP_USE_LITTLEFS=0 + -D HASP_USE_EEPROM=0 + -D HASP_USE_GPIO=0 + -D HASP_USE_CONFIG=0 ; Standalone application, as library + -D HASP_USE_DEBUG=1 + -D HASP_USE_MQTT=1 + -D MQTT_MAX_PACKET_SIZE=2048 + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO + ;-D LV_LOG_PRINTF=1 + ; Add recursive dirs for hal headers search + !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" + -mconsole + -lSDL2 + -D PAHO_MQTT_STATIC + -D _WIN64 + -D WINDOWS ; We add this for code branching in hasp + -D WIN32_LEAN_AND_MEAN + -DPAHO_WITH_SSL=FALSE + -DPAHO_BUILD_DOCUMENTATION=FALSE + -DPAHO_BUILD_SAMPLES=FALSE + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_VERBOSE_MAKEFILE=TRUE + ;-D NO_PERSISTENCE + -I.pio/libdeps/emulator_64bits/paho/src + -I.pio/libdeps/emulator_64bits/ArduinoJson/src + -I lib/ArduinoJson/src + -I lib/lv_fs_if + ; ----- Statically linked libraries -------------------- + -l"ws2_32" + -lrpcrt4 + -lcrypt32 + -lmingw32 + -lSDL2main + -lSDL2 + -mwindows + -lm + -ldinput8 + ;-ldxguid + ;-ldxerr8 + ;-luser32 + ;-lgdi32 + -lwinmm + -limm32 + -lole32 + -loleaut32 + ;-lshell32 + -lversion + ;-luuid + -lsetupapi + ;-lhid + +lib_deps = + ${env.lib_deps} + lv_drivers@~7.9.0 + ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip + https://github.com/eclipse/paho.mqtt.c.git + bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + +lib_ignore = paho + +src_filter = + +<*> + -<*.h> + +<../hal/sdl2> + +<../.pio/libdeps/emulator_64bits/paho/src/*.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> + -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> + - + - + - + -<../.pio/libdeps/emulator_64bits/lv_fs_if/lv_fs_pc.c> + -<../.pio/libdeps/emulator_64bits/ArduinoLog/ArduinoLog.cpp> + - + - + - + - + - + - + - + - + - + - + - + + + + + + + - + + + - + - + -<../lib/lv_fs_if> + -<../lib/lv_fs_if/lv_fs_if.cpp> + -<../lib/lv_fs_if/lv_fs_if.h> + -<../lib/lv_fs_if/lv_fs_spiffs.cpp> + -<../lib/lv_fs_if/lv_fs_spiffs.h> + +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> From b6a17935383f8b93daf00d526c2ceca441d3a95a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Feb 2021 04:26:30 +0100 Subject: [PATCH 004/236] Add win32 environment --- src/lang/lang.h | 1 + src/sys/net/hasp_wifi.h | 23 +++++ user_setups/win32/emulator_64bits.ini | 117 ++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 src/sys/net/hasp_wifi.h create mode 100644 user_setups/win32/emulator_64bits.ini diff --git a/src/lang/lang.h b/src/lang/lang.h index 81633d7f..4a5428b9 100644 --- a/src/lang/lang.h +++ b/src/lang/lang.h @@ -3,6 +3,7 @@ #include "en_US.h" +// language independent defines #define D_PASSWORD_MASK "********" #define D_BULLET " * " #define D_MANUFACTURER "hasp-lvgl" diff --git a/src/sys/net/hasp_wifi.h b/src/sys/net/hasp_wifi.h new file mode 100644 index 00000000..5364150f --- /dev/null +++ b/src/sys/net/hasp_wifi.h @@ -0,0 +1,23 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_WIFI_H +#define HASP_WIFI_H + +#include "ArduinoJson.h" + +void wifiSetup(); +bool wifiShowAP(); +bool wifiShowAP(char * ssid, char * pass); +bool wifiEvery5Seconds(void); +void wifiStop(void); + +bool wifiValidateSsid(const char * ssid, const char * pass); +void wifi_get_statusupdate(char * buffer, size_t len); + +#if HASP_USE_CONFIG > 0 +bool wifiGetConfig(const JsonObject & settings); +bool wifiSetConfig(const JsonObject & settings); +#endif + +#endif \ No newline at end of file diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/emulator_64bits.ini new file mode 100644 index 00000000..94dff354 --- /dev/null +++ b/user_setups/win32/emulator_64bits.ini @@ -0,0 +1,117 @@ +[env:emulator_64bits] +platform = native@^1.1.3 +extra_scripts = tools/sdl2_build_extra.py +build_flags = + ${env.build_flags} + ; ----- Monitor + -D TFT_WIDTH=800 + -D TFT_HEIGHT=480 + ; SDL drivers options + ;-D LV_LVGL_H_INCLUDE_SIMPLE + ;-D LV_DRV_NO_CONF + -D USE_MONITOR + -D MONITOR_ZOOM=1 ; 2 + -D USE_MOUSE + -D USE_MOUSEWHEEL + -D USE_KEYBOARD + ; ----- ArduinoJson + -D ARDUINOJSON_DECODE_UNICODE=1 + -D HASP_NUM_PAGES=4 + -D HASP_USE_SPIFFS=0 + -D HASP_USE_LITTLEFS=0 + -D HASP_USE_EEPROM=0 + -D HASP_USE_GPIO=0 + -D HASP_USE_CONFIG=0 ; Standalone application, as library + -D HASP_USE_DEBUG=1 + -D HASP_USE_MQTT=1 + -D MQTT_MAX_PACKET_SIZE=2048 + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO + ;-D LV_LOG_PRINTF=1 + ; Add recursive dirs for hal headers search + !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" + -mconsole + -lSDL2 + -D PAHO_MQTT_STATIC + -D _WIN64 + -D WINDOWS ; We add this for code branching in hasp + -D WIN32_LEAN_AND_MEAN + -DPAHO_WITH_SSL=FALSE + -DPAHO_BUILD_DOCUMENTATION=FALSE + -DPAHO_BUILD_SAMPLES=FALSE + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_VERBOSE_MAKEFILE=TRUE + ;-D NO_PERSISTENCE + -I.pio/libdeps/emulator_64bits/paho/src + -I.pio/libdeps/emulator_64bits/ArduinoJson/src + -I lib/ArduinoJson/src + -I lib/lv_fs_if + ; ----- Statically linked libraries -------------------- + -l"ws2_32" + -lrpcrt4 + -lcrypt32 + -lmingw32 + -lSDL2main + -lSDL2 + -mwindows + -lm + -ldinput8 + ;-ldxguid + ;-ldxerr8 + ;-luser32 + ;-lgdi32 + -lwinmm + -limm32 + -lole32 + -loleaut32 + ;-lshell32 + -lversion + ;-luuid + -lsetupapi + ;-lhid + +lib_deps = + ${env.lib_deps} + lv_drivers@~7.9.0 + ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip + https://github.com/eclipse/paho.mqtt.c.git + bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + +lib_ignore = paho + +src_filter = + +<*> + -<*.h> + +<../hal/sdl2> + +<../.pio/libdeps/emulator_64bits/paho/src/*.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> + -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> + - + - + - + -<../.pio/libdeps/emulator_64bits/lv_fs_if/lv_fs_pc.c> + -<../.pio/libdeps/emulator_64bits/ArduinoLog/ArduinoLog.cpp> + - + - + - + - + - + - + - + - + - + - + - + + + + + + + - + + + - + - + -<../lib/lv_fs_if> + -<../lib/lv_fs_if/lv_fs_if.cpp> + -<../lib/lv_fs_if/lv_fs_if.h> + -<../lib/lv_fs_if/lv_fs_spiffs.cpp> + -<../lib/lv_fs_if/lv_fs_spiffs.h> + +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> From e9c75fe3c3fa5b4666eb542a6e8b07f53abc652c Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Feb 2021 04:27:02 +0100 Subject: [PATCH 005/236] Add win32 environment --- user_setups/win32/emulator_64bits].ini | 117 ------------------------- 1 file changed, 117 deletions(-) delete mode 100644 user_setups/win32/emulator_64bits].ini diff --git a/user_setups/win32/emulator_64bits].ini b/user_setups/win32/emulator_64bits].ini deleted file mode 100644 index 94dff354..00000000 --- a/user_setups/win32/emulator_64bits].ini +++ /dev/null @@ -1,117 +0,0 @@ -[env:emulator_64bits] -platform = native@^1.1.3 -extra_scripts = tools/sdl2_build_extra.py -build_flags = - ${env.build_flags} - ; ----- Monitor - -D TFT_WIDTH=800 - -D TFT_HEIGHT=480 - ; SDL drivers options - ;-D LV_LVGL_H_INCLUDE_SIMPLE - ;-D LV_DRV_NO_CONF - -D USE_MONITOR - -D MONITOR_ZOOM=1 ; 2 - -D USE_MOUSE - -D USE_MOUSEWHEEL - -D USE_KEYBOARD - ; ----- ArduinoJson - -D ARDUINOJSON_DECODE_UNICODE=1 - -D HASP_NUM_PAGES=4 - -D HASP_USE_SPIFFS=0 - -D HASP_USE_LITTLEFS=0 - -D HASP_USE_EEPROM=0 - -D HASP_USE_GPIO=0 - -D HASP_USE_CONFIG=0 ; Standalone application, as library - -D HASP_USE_DEBUG=1 - -D HASP_USE_MQTT=1 - -D MQTT_MAX_PACKET_SIZE=2048 - ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO - ;-D LV_LOG_PRINTF=1 - ; Add recursive dirs for hal headers search - !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" - -mconsole - -lSDL2 - -D PAHO_MQTT_STATIC - -D _WIN64 - -D WINDOWS ; We add this for code branching in hasp - -D WIN32_LEAN_AND_MEAN - -DPAHO_WITH_SSL=FALSE - -DPAHO_BUILD_DOCUMENTATION=FALSE - -DPAHO_BUILD_SAMPLES=FALSE - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_VERBOSE_MAKEFILE=TRUE - ;-D NO_PERSISTENCE - -I.pio/libdeps/emulator_64bits/paho/src - -I.pio/libdeps/emulator_64bits/ArduinoJson/src - -I lib/ArduinoJson/src - -I lib/lv_fs_if - ; ----- Statically linked libraries -------------------- - -l"ws2_32" - -lrpcrt4 - -lcrypt32 - -lmingw32 - -lSDL2main - -lSDL2 - -mwindows - -lm - -ldinput8 - ;-ldxguid - ;-ldxerr8 - ;-luser32 - ;-lgdi32 - -lwinmm - -limm32 - -lole32 - -loleaut32 - ;-lshell32 - -lversion - ;-luuid - -lsetupapi - ;-lhid - -lib_deps = - ${env.lib_deps} - lv_drivers@~7.9.0 - ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip - https://github.com/eclipse/paho.mqtt.c.git - bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser - -lib_ignore = paho - -src_filter = - +<*> - -<*.h> - +<../hal/sdl2> - +<../.pio/libdeps/emulator_64bits/paho/src/*.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> - -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> - - - - - - - -<../.pio/libdeps/emulator_64bits/lv_fs_if/lv_fs_pc.c> - -<../.pio/libdeps/emulator_64bits/ArduinoLog/ArduinoLog.cpp> - - - - - - - - - - - - - - - - - - - - - - - + - + - + - - - + - - - - - -<../lib/lv_fs_if> - -<../lib/lv_fs_if/lv_fs_if.cpp> - -<../lib/lv_fs_if/lv_fs_if.h> - -<../lib/lv_fs_if/lv_fs_spiffs.cpp> - -<../lib/lv_fs_if/lv_fs_spiffs.h> - +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> From 8723e655a91bc86ddfecb7f553b5f0d94a9a5d39 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:10:55 +0100 Subject: [PATCH 006/236] Enable spinner --- include/lv_conf_v7.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index be0aa63e..0e7024f5 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -645,7 +645,7 @@ typedef struct { #endif /*Preload (dependencies: lv_arc, lv_anim)*/ -#define LV_USE_SPINNER 0 +#define LV_USE_SPINNER 1 #if LV_USE_SPINNER != 0 # define LV_SPINNER_DEF_ARC_LENGTH 60 /*[deg]*/ # define LV_SPINNER_DEF_SPIN_TIME 1000 /*[ms]*/ From e3dfee55c10fad808ce7de0b31dce0c18b0871cb Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:11:33 +0100 Subject: [PATCH 007/236] Tweak Windows environment --- user_setups/win32/emulator_64bits.ini | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/emulator_64bits.ini index 94dff354..9742840d 100644 --- a/user_setups/win32/emulator_64bits.ini +++ b/user_setups/win32/emulator_64bits.ini @@ -4,11 +4,12 @@ extra_scripts = tools/sdl2_build_extra.py build_flags = ${env.build_flags} ; ----- Monitor - -D TFT_WIDTH=800 - -D TFT_HEIGHT=480 + -D TFT_WIDTH=240 + -D TFT_HEIGHT=320 ; SDL drivers options ;-D LV_LVGL_H_INCLUDE_SIMPLE ;-D LV_DRV_NO_CONF + -D LV_MEM_SIZE=262144U ; 256kB lvgl memory -D USE_MONITOR -D MONITOR_ZOOM=1 ; 2 -D USE_MOUSE @@ -16,7 +17,7 @@ build_flags = -D USE_KEYBOARD ; ----- ArduinoJson -D ARDUINOJSON_DECODE_UNICODE=1 - -D HASP_NUM_PAGES=4 + -D HASP_NUM_PAGES=12 -D HASP_USE_SPIFFS=0 -D HASP_USE_LITTLEFS=0 -D HASP_USE_EEPROM=0 @@ -28,14 +29,11 @@ build_flags = ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO ;-D LV_LOG_PRINTF=1 ; Add recursive dirs for hal headers search - !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" - -mconsole - -lSDL2 - -D PAHO_MQTT_STATIC -D _WIN64 - -D WINDOWS ; We add this for code branching in hasp - -D WIN32_LEAN_AND_MEAN - -DPAHO_WITH_SSL=FALSE + -D WINDOWS ; We add this ourselves for code branching in hasp + -D WIN32_LEAN_AND_MEAN ; exclude a bunch of Windows header files from windows.h + -D PAHO_MQTT_STATIC + -DPAHO_WITH_SSL=TRUE -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_SAMPLES=FALSE -DCMAKE_BUILD_TYPE=Release @@ -45,8 +43,10 @@ build_flags = -I.pio/libdeps/emulator_64bits/ArduinoJson/src -I lib/ArduinoJson/src -I lib/lv_fs_if + !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" + -mconsole ; ----- Statically linked libraries -------------------- - -l"ws2_32" + -l"ws2_32" ;windsock2 -lrpcrt4 -lcrypt32 -lmingw32 @@ -109,7 +109,7 @@ src_filter = + - - - -<../lib/lv_fs_if> + -<../lib/lv_fs_if/> -<../lib/lv_fs_if/lv_fs_if.cpp> -<../lib/lv_fs_if/lv_fs_if.h> -<../lib/lv_fs_if/lv_fs_spiffs.cpp> From 1e1afeaa69a4f5d0dc100d7f4dd40ea9a1015d7d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:12:34 +0100 Subject: [PATCH 008/236] Update tests --- test/test_colors.tavern.yaml | 24 ++++---- test/test_obj.tavern.yaml | 99 ++++++++++++++++++++++----------- test/test_value_str.tavern.yaml | 10 ++++ 3 files changed, 87 insertions(+), 46 deletions(-) diff --git a/test/test_colors.tavern.yaml b/test/test_colors.tavern.yaml index 9aefdd4d..dd8a7d35 100644 --- a/test/test_colors.tavern.yaml +++ b/test/test_colors.tavern.yaml @@ -103,9 +103,9 @@ stages: obj: "{obj}" id: 1 txt: "{color}" - x: "{r}" - y: "{g}" - w: "{b}" + r: !int "{r:d}" + g: !int "{g:d}" + b: !int "{b:d}" delay_after: 0.1 - name: Set bg_color @@ -122,9 +122,9 @@ stages: topic: hasp/{plate}/state/p1b1 json: text_color: "{hex}" - r: "{r}" - g: "{g}" - b: "{b}" + r: !int "{r:d}" + g: !int "{g:d}" + b: !int "{b:d}" timeout: 1 - name: Reset @@ -141,9 +141,9 @@ stages: topic: hasp/{plate}/state/p1b1 json: text_color: "{hex}" - r: "{r}" - g: "{g}" - b: "{b}" + r: !int "{r:d}" + g: !int "{g:d}" + b: !int "{b:d}" timeout: 1 - name: Reset @@ -160,7 +160,7 @@ stages: topic: hasp/{plate}/state/p1b1 json: text_color: "{hex}" - r: "{r}" - g: "{g}" - b: "{b}" + r: !int "{r:d}" + g: !int "{g:d}" + b: !int "{b:d}" timeout: 1 diff --git a/test/test_obj.tavern.yaml b/test/test_obj.tavern.yaml index 6738952c..5d2aba82 100644 --- a/test/test_obj.tavern.yaml +++ b/test/test_obj.tavern.yaml @@ -15,6 +15,24 @@ paho-mqtt: timeout: 3 marks: + - parametrize: + key: obj + vals: + - btnmatrix + - gauge + - btn + - label + - slider + #- cb + - sw + - bar + - arc + - led + - obj + - lmeter + - dropdown + - roller + - spinner - parametrize: key: - hidden @@ -25,17 +43,13 @@ marks: - h - radius - opacity + - str1 + - str2 vals: - - [1, 0, 120, 121, 122, 123, 0, 255] - - [0, 1, 80, 81, 82, 83, 32535, 192] - - [1, 0, -10, -10, 256, 257, 1, 64] - - [0, 1, 1024, 1025, 1026, 1027, 5, 0] - - parametrize: - key: objid - vals: - - 10 - - 12 - + - [1, 0, 120, 121, 122, 123, 0, 255, "I'm sorry.", "louie"] + - [1, 0, -10, -10, 256, 257, 1, 64, "louie", " The cat stretched."] + - [0, 1, 1024, 1025, 1026, 1027, 5, 0, "The pipe began to rust while new.", ""] + - [0, 1, 80, 81, 82, 83, 32535, 192, "" ," Oak is strong and also gives shade."] stages: - name: Page 1 @@ -52,40 +66,42 @@ stages: mqtt_publish: topic: hasp/{plate}/command/clearpage payload: "" - delay_after: 0 + delay_after: 0.2 - name: Create object mqtt_publish: topic: hasp/{plate}/command/jsonl json: - objid: "{objid}" + obj: "{obj}" id: 1 + x: 128 + y: 128 delay_after: 0 - - name: Test x - mqtt_publish: - topic: hasp/{plate}/command/json - payload: '["p[1].b[1].x={x}","p[1].b[1].x"]' - mqtt_response: - topic: hasp/{plate}/state/p1b1 - json: - x: !int "{x:d}" - timeout: 1 - - name: Test y mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].y={y}","p[1].b[1].y"]' + payload: '["p1b1.y={y}","p1b1.y"]' mqtt_response: topic: hasp/{plate}/state/p1b1 json: y: !int "{y:d}" timeout: 1 + - name: Test x + mqtt_publish: + topic: hasp/{plate}/command/json + payload: '["p1b1.x={x}","p1b1.x"]' + mqtt_response: + topic: hasp/{plate}/state/p1b1 + json: + x: !int "{x:d}" + timeout: 1 + - name: Test w mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].w={w}","p[1].b[1].w"]' + payload: '["p1b1.w={w}","p1b1.w"]' mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -95,7 +111,7 @@ stages: - name: Test h mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].h={h}","p[1].b[1].h"]' + payload: '["p1b1.h={h}","p1b1.h"]' delay_after: 0 mqtt_response: topic: hasp/{plate}/state/p1b1 @@ -106,7 +122,7 @@ stages: - name: Test enabled mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].enabled={hidden}","p[1].b[1].enabled"]' + payload: '["p1b1.enabled={hidden}","p1b1.enabled"]' delay_after: 0 mqtt_response: topic: hasp/{plate}/state/p1b1 @@ -117,12 +133,12 @@ stages: - name: Set vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis={hidden}" + payload: "p1b1.vis={hidden}" delay_after: 0 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden" + payload: "p1b1.hidden" mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -131,7 +147,7 @@ stages: - name: Get vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis" + payload: "p1b1.vis" mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -141,12 +157,12 @@ stages: - name: Set hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden={hidden}" + payload: "p1b1.hidden={hidden}" delay_after: 0 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].hidden" + payload: "p1b1.hidden" mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -156,7 +172,7 @@ stages: - name: Get vis mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].vis" + payload: "p1b1.vis" mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -166,7 +182,7 @@ stages: - name: Test opacity mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].opacity={opacity}","p[1].b[1].opacity"]' + payload: '["p1b1.opacity={opacity}","p1b1.opacity"]' mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -176,9 +192,24 @@ stages: - name: Test radius mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].radius={radius}","p[1].b[1].radius"]' + payload: '["p1b1.radius={radius}","p1b1.radius"]' mqtt_response: topic: hasp/{plate}/state/p1b1 json: radius: !int "{radius:d}" timeout: 1 + + - name: Set value_str + mqtt_publish: + topic: "hasp/{plate}/command/p1b1.value_str" + payload: "{str1}{str2}" + delay_after: 0.05 + - name: Get value_str + mqtt_publish: + topic: hasp/{plate}/command + payload: "p1b1.value_str" + mqtt_response: + topic: hasp/{plate}/state/p1b1 + json: + value_str: "{str1}{str2}" + timeout: 1 diff --git a/test/test_value_str.tavern.yaml b/test/test_value_str.tavern.yaml index 6b4fa323..e3448654 100644 --- a/test/test_value_str.tavern.yaml +++ b/test/test_value_str.tavern.yaml @@ -84,6 +84,16 @@ stages: timeout: 1 delay_after: 0 + - name: Create object + mqtt_publish: + topic: hasp/{plate}/command/jsonl + json: + objid: "{objid}" + id: 1 + x: 128 + y: 128 + delay_after: 0 + - name: Set value_str mqtt_publish: topic: "hasp/{plate}/command/p[1].b[1].value_str" From 929e507dc402f1c47584f93b0360157489e03fc3 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 01:35:19 +0100 Subject: [PATCH 009/236] Update tests --- test/test_obj.tavern.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/test_obj.tavern.yaml b/test/test_obj.tavern.yaml index 5d2aba82..9fe6ae5a 100644 --- a/test/test_obj.tavern.yaml +++ b/test/test_obj.tavern.yaml @@ -19,20 +19,24 @@ marks: key: obj vals: - btnmatrix + - cpicker + - table + - tabview + - chart - gauge - btn - label - slider - #- cb - - sw + - checkbox + - switch - bar - arc - led - obj - lmeter - dropdown - - roller - spinner + - roller - parametrize: key: - hidden From bfe1877a9136456d13e90579f1abedbebd664be7 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 14:13:07 +0100 Subject: [PATCH 010/236] Add class wrapper --- src/hasp/hasp_parser.cpp | 90 +++++++++++++++++++++++++++++++++++++ src/hasp/hasp_parser.h | 84 ++++++++++++++++++++++++++++++++++ src/hasp/hasp_utilities.cpp | 23 +++++++--- src/hasp/hasp_utilities.h | 16 +++++-- 4 files changed, 203 insertions(+), 10 deletions(-) create mode 100644 src/hasp/hasp_parser.cpp create mode 100644 src/hasp/hasp_parser.h diff --git a/src/hasp/hasp_parser.cpp b/src/hasp/hasp_parser.cpp new file mode 100644 index 00000000..af46a4ec --- /dev/null +++ b/src/hasp/hasp_parser.cpp @@ -0,0 +1,90 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#include + +#ifdef ARDUINO +#include "pgmspace.h" +#endif + +#include "lvgl.h" +#include "hasp_conf.h" + +#include "hasp_parser.h" +#include "hasp_utilities.h" + +bool Parser::haspPayloadToColor(const char * payload, lv_color32_t & color) +{ + /* HEX format #rrggbb or #rgb */ + if(*payload == '#') { + if(strlen(payload) >= 8) return false; + + char * pEnd; + long color_int = strtol(payload + 1, &pEnd, HEX); + + if(pEnd - payload == 7) { // #rrbbgg + color.ch.red = color_int >> 16 & 0xff; + color.ch.green = color_int >> 8 & 0xff; + color.ch.blue = color_int & 0xff; + + } else if(pEnd - payload == 4) { // #rgb + color.ch.red = color_int >> 8 & 0xf; + color.ch.green = color_int >> 4 & 0xf; + color.ch.blue = color_int & 0xf; + + color.ch.red += color.ch.red * HEX; + color.ch.green += color.ch.green * HEX; + color.ch.blue += color.ch.blue * HEX; + + } else { + return false; /* Invalid hex length */ + } + + return true; /* Color found */ + } + + /* 16-bit RGB565 Color Scheme*/ + if(Utilities::is_only_digits(payload)) { + uint16_t c = atoi(payload); + + /* Initial colors */ + uint8_t R5 = ((c >> 11) & 0b11111); + uint8_t G6 = ((c >> 5) & 0b111111); + uint8_t B5 = (c & 0b11111); + + /* Remapped colors */ + color.ch.red = (R5 * 527 + 23) >> 6; + color.ch.green = (G6 * 259 + 33) >> 6; + color.ch.blue = (B5 * 527 + 23) >> 6; + + return true; /* Color found */ + } + + /* Named colors */ + size_t numColors = sizeof(haspNamedColors) / sizeof(haspNamedColors[0]); + uint16_t sdbm = Utilities::get_sdbm(payload); + +#ifdef ARDUINO + for(size_t i = 0; i < numColors; i++) { + if(sdbm == (uint16_t)pgm_read_word_near(&(haspNamedColors[i].hash))) { + color.ch.red = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].r)); + color.ch.green = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].g)); + color.ch.blue = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].b)); + + return true; /* Color found */ + } + } +#else + for(size_t i = 0; i < numColors; i++) { + if(sdbm == haspNamedColors[i].hash) { + color.ch.red = haspNamedColors[i].r; + color.ch.green = haspNamedColors[i].g; + color.ch.blue = haspNamedColors[i].b; + + return true; /* Color found */ + } + } +#endif + + return false; /* Color not found */ +} \ No newline at end of file diff --git a/src/hasp/hasp_parser.h b/src/hasp/hasp_parser.h new file mode 100644 index 00000000..2ffc058c --- /dev/null +++ b/src/hasp/hasp_parser.h @@ -0,0 +1,84 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_PARSER_H +#define HASP_PARSER_H + +#include "lvgl.h" +#include "hasp_conf.h" + +class Parser { + + public: + static bool haspPayloadToColor(const char * payload, lv_color32_t & color); +}; + +/* Named COLOR attributes */ +#define ATTR_RED 177 +#define ATTR_TAN 7873 +#define ATTR_AQUA 3452 +#define ATTR_BLUE 37050 +#define ATTR_CYAN 9763 +#define ATTR_GOLD 53440 +#define ATTR_GRAY 64675 +#define ATTR_GREY 64927 +#define ATTR_LIME 34741 +#define ATTR_NAVY 44918 +#define ATTR_PERU 36344 +#define ATTR_PINK 51958 +#define ATTR_PLUM 64308 +#define ATTR_SNOW 35587 +#define ATTR_TEAL 52412 +#define ATTR_AZURE 44239 +#define ATTR_BEIGE 12132 +#define ATTR_BLACK 26527 +#define ATTR_BLUSH 41376 +#define ATTR_BROWN 10774 +#define ATTR_CORAL 16369 +#define ATTR_GREEN 26019 +#define ATTR_IVORY 1257 +#define ATTR_KHAKI 32162 +#define ATTR_LINEN 30074 +#define ATTR_OLIVE 47963 +#define ATTR_WHEAT 11591 +#define ATTR_WHITE 28649 +#define ATTR_BISQUE 60533 +#define ATTR_INDIGO 46482 +#define ATTR_MAROON 12528 +#define ATTR_ORANGE 21582 +#define ATTR_ORCHID 39235 +#define ATTR_PURPLE 53116 +#define ATTR_SALMON 29934 +#define ATTR_SIENNA 50930 +#define ATTR_SILVER 62989 +#define ATTR_TOMATO 8234 +#define ATTR_VIOLET 61695 +#define ATTR_YELLOW 10484 +#define ATTR_FUCHSIA 5463 +#define ATTR_MAGENTA 49385 + +struct hasp_color_t +{ + uint16_t hash; + uint8_t r, g, b; +}; + +/* Named COLOR lookup table */ +const hasp_color_t haspNamedColors[] PROGMEM = { + {ATTR_RED, 0xFF, 0x00, 0x00}, {ATTR_TAN, 0xD2, 0xB4, 0x8C}, {ATTR_AQUA, 0x00, 0xFF, 0xFF}, + {ATTR_BLUE, 0x00, 0x00, 0xFF}, {ATTR_CYAN, 0x00, 0xFF, 0xFF}, {ATTR_GOLD, 0xFF, 0xD7, 0x00}, + {ATTR_GRAY, 0x80, 0x80, 0x80}, {ATTR_GREY, 0x80, 0x80, 0x80}, {ATTR_LIME, 0x00, 0xFF, 0x00}, + {ATTR_NAVY, 0x00, 0x00, 0x80}, {ATTR_PERU, 0xCD, 0x85, 0x3F}, {ATTR_PINK, 0xFF, 0xC0, 0xCB}, + {ATTR_PLUM, 0xDD, 0xA0, 0xDD}, {ATTR_SNOW, 0xFF, 0xFA, 0xFA}, {ATTR_TEAL, 0x00, 0x80, 0x80}, + {ATTR_AZURE, 0xF0, 0xFF, 0xFF}, {ATTR_BEIGE, 0xF5, 0xF5, 0xDC}, {ATTR_BLACK, 0x00, 0x00, 0x00}, + {ATTR_BLUSH, 0xB0, 0x00, 0x00}, {ATTR_BROWN, 0xA5, 0x2A, 0x2A}, {ATTR_CORAL, 0xFF, 0x7F, 0x50}, + {ATTR_GREEN, 0x00, 0x80, 0x00}, {ATTR_IVORY, 0xFF, 0xFF, 0xF0}, {ATTR_KHAKI, 0xF0, 0xE6, 0x8C}, + {ATTR_LINEN, 0xFA, 0xF0, 0xE6}, {ATTR_OLIVE, 0x80, 0x80, 0x00}, {ATTR_WHEAT, 0xF5, 0xDE, 0xB3}, + {ATTR_WHITE, 0xFF, 0xFF, 0xFF}, {ATTR_BISQUE, 0xFF, 0xE4, 0xC4}, {ATTR_INDIGO, 0x4B, 0x00, 0x82}, + {ATTR_MAROON, 0x80, 0x00, 0x00}, {ATTR_ORANGE, 0xFF, 0xA5, 0x00}, {ATTR_ORCHID, 0xDA, 0x70, 0xD6}, + {ATTR_PURPLE, 0x80, 0x00, 0x80}, {ATTR_SALMON, 0xFA, 0x80, 0x72}, {ATTR_SIENNA, 0xA0, 0x52, 0x2D}, + {ATTR_SILVER, 0xC0, 0xC0, 0xC0}, {ATTR_TOMATO, 0xFF, 0x63, 0x47}, {ATTR_VIOLET, 0xEE, 0x82, 0xEE}, + {ATTR_YELLOW, 0xFF, 0xFF, 0x00}, {ATTR_FUCHSIA, 0xFF, 0x00, 0xFF}, {ATTR_MAGENTA, 0xFF, 0x00, 0xFF}, +}; + +#endif \ No newline at end of file diff --git a/src/hasp/hasp_utilities.cpp b/src/hasp/hasp_utilities.cpp index 75ab5cd8..d99e6dca 100644 --- a/src/hasp/hasp_utilities.cpp +++ b/src/hasp/hasp_utilities.cpp @@ -1,11 +1,16 @@ #include -#include "Arduino.h" +#ifdef ARDUINO + #include "Arduino.h" +#endif + +#include "hasp_conf.h" + #include "hasp_utilities.h" /* 16-bit hashing function http://www.cse.yorku.ca/~oz/hash.html */ /* all possible attributes are hashed and checked if they are unique */ -uint16_t hasp_util_get_sdbm(const char * str) +uint16_t Utilities::get_sdbm(const char * str) { uint16_t hash = 0; char c; @@ -18,13 +23,13 @@ uint16_t hasp_util_get_sdbm(const char * str) return hash; } -bool hasp_util_is_true(const char * s) +bool Utilities::is_true(const char * s) { return (!strcasecmp_P(s, PSTR("true")) || !strcasecmp_P(s, PSTR("on")) || !strcasecmp_P(s, PSTR("yes")) || !strcmp_P(s, PSTR("1"))); } -bool hasp_util_is_only_digits(const char * s) +bool Utilities::is_only_digits(const char * s) { size_t digits = 0; while(*(s + digits) != '\0' && isdigit(*(s + digits))) { @@ -33,7 +38,7 @@ bool hasp_util_is_only_digits(const char * s) return strlen(s) == digits; } -int hasp_util_format_bytes(size_t filesize, char * buf, size_t len) +int Utilities::format_bytes(size_t filesize, char * buf, size_t len) { if(filesize < 1024) return snprintf_P(buf, len, PSTR("%d B"), filesize); @@ -47,4 +52,10 @@ int hasp_util_format_bytes(size_t filesize, char * buf, size_t len) } return snprintf_P(buf, len, PSTR("%d.%d %ciB"), filesize / 10, filesize % 10, labels[unit]); -} \ No newline at end of file +} + +#ifndef ARDUINO +long map(long x, long in_min, long in_max, long out_min, long out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} +#endif \ No newline at end of file diff --git a/src/hasp/hasp_utilities.h b/src/hasp/hasp_utilities.h index eb164cd5..066d89e0 100644 --- a/src/hasp/hasp_utilities.h +++ b/src/hasp/hasp_utilities.h @@ -4,9 +4,17 @@ #ifndef HASP_UTILITIES_H #define HASP_UTILITIES_H -uint16_t hasp_util_get_sdbm(const char * str); -bool hasp_util_is_true(const char * s); -bool hasp_util_is_only_digits(const char * s); -int hasp_util_format_bytes(size_t filesize, char * buf, size_t len); +class Utilities { + + public: + static uint16_t get_sdbm(const char * str); + static bool is_true(const char * s); + static bool is_only_digits(const char * s); + static int format_bytes(size_t filesize, char * buf, size_t len); +}; + +#ifndef ARDUINO +long map(long x, long in_min, long in_max, long out_min, long out_max); +#endif #endif \ No newline at end of file From 760de1b09296b9a83518a5fa1b8a23fd780b8d3b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 14:14:05 +0100 Subject: [PATCH 011/236] Move user_config_override.h --- {src => include}/user_config_override-template.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src => include}/user_config_override-template.h (100%) diff --git a/src/user_config_override-template.h b/include/user_config_override-template.h similarity index 100% rename from src/user_config_override-template.h rename to include/user_config_override-template.h From 5ffbd18d8b015b3b0952ae31d485c1667121f338 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:02:49 +0100 Subject: [PATCH 012/236] Xplatform changes --- lib/ArduinoLog/ArduinoLog.cpp | 58 ++++++++++++++++++--------------- lib/lv_fs_if/lv_fs_spiffs.cpp | 4 +++ lib/lv_lib_zifont/lv_zifont.cpp | 5 +++ src/main_arduino.cpp | 3 +- src/main_windows.cpp | 1 + src/mouse_cursor_icon.c | 1 - 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/lib/ArduinoLog/ArduinoLog.cpp b/lib/ArduinoLog/ArduinoLog.cpp index d3174f52..af50c24f 100644 --- a/lib/ArduinoLog/ArduinoLog.cpp +++ b/lib/ArduinoLog/ArduinoLog.cpp @@ -29,85 +29,87 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "ArduinoLog.h" +#ifdef ARDUINO + + #include "ArduinoLog.h" void Logging::begin(int level, bool showLevel) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING setLevel(0, level); setLevel(1, level); setLevel(2, level); setShowLevel(0, showLevel); -#endif + #endif } void Logging::registerOutput(uint8_t slot, Print * logOutput, int level, bool showLevel) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING if(slot >= 3) return; setLevel(slot, level); setShowLevel(slot, showLevel); _logOutput[slot] = logOutput; -#endif + #endif } void Logging::unregisterOutput(uint8_t slot) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING if(slot >= 3) return; _logOutput[slot] = NULL; -#endif + #endif } void Logging::setLevel(uint8_t slot, int level) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING _level[slot] = constrain(level, LOG_LEVEL_SILENT, LOG_LEVEL_OUTPUT); -#endif + #endif } int Logging::getLevel(uint8_t slot) const { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING return _level[slot]; -#else + #else return 0; -#endif + #endif } void Logging::setShowLevel(uint8_t slot, bool showLevel) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING _showLevel[slot] = showLevel; -#endif + #endif } bool Logging::getShowLevel(uint8_t slot) const { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING return _showLevel[slot]; -#else + #else return false; -#endif + #endif } void Logging::setPrefix(printfunction f) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING _prefix = f; -#endif + #endif } void Logging::setSuffix(printfunction f) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING _suffix = f; -#endif + #endif } void Logging::print(Print * logOutput, const __FlashStringHelper * format, va_list args) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING PGM_P p = reinterpret_cast(format); char c = pgm_read_byte(p++); for(; c != 0; c = pgm_read_byte(p++)) { @@ -118,12 +120,12 @@ void Logging::print(Print * logOutput, const __FlashStringHelper * format, va_li logOutput->print(c); } } -#endif + #endif } void Logging::print(Print * logOutput, const char * format, va_list args) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING for(; *format != 0; ++format) { if(*format == '%') { ++format; @@ -132,12 +134,12 @@ void Logging::print(Print * logOutput, const char * format, va_list args) logOutput->print(*format); } } -#endif + #endif } void Logging::printFormat(Print * logOutput, const char format, va_list * args) { -#ifndef DISABLE_LOGGING + #ifndef DISABLE_LOGGING if(format == '%') { logOutput->print(format); } else if(format == 's') { @@ -179,7 +181,9 @@ void Logging::printFormat(Print * logOutput, const char format, va_list * args) logOutput->print(F("false")); } } -#endif + #endif } Logging Log = Logging(); + +#endif // ARDUINO \ No newline at end of file diff --git a/lib/lv_fs_if/lv_fs_spiffs.cpp b/lib/lv_fs_if/lv_fs_spiffs.cpp index e4fe5e82..c8e8fb95 100644 --- a/lib/lv_fs_if/lv_fs_spiffs.cpp +++ b/lib/lv_fs_if/lv_fs_spiffs.cpp @@ -6,6 +6,8 @@ /********************* * INCLUDES *********************/ +#ifdef ARDUINO + #include #include "lv_fs_if.h" #include "lv_fs_spiffs.h" @@ -504,3 +506,5 @@ static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p) #endif /*LV_USE_FS_IF*/ #endif /*LV_FS_IF_SPIFFS*/ + +#endif /*ARDUINO*/ \ No newline at end of file diff --git a/lib/lv_lib_zifont/lv_zifont.cpp b/lib/lv_lib_zifont/lv_zifont.cpp index 90e586b1..25bfe0b4 100644 --- a/lib/lv_lib_zifont/lv_zifont.cpp +++ b/lib/lv_lib_zifont/lv_zifont.cpp @@ -1,6 +1,9 @@ /********************* * INCLUDES *********************/ + +#ifndef WINDOWS + #include #include @@ -557,6 +560,8 @@ static inline void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, u } } +#endif + /* void printPixel(uint8_t pixel) { diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index b8eb8087..2a68517f 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -1,9 +1,10 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#ifdef ARDUINO +#ifndef WINDOWS #include +#include "lvgl.h" #include "hasp_conf.h" // load first #if HASP_USE_CONFIG > 0 diff --git a/src/main_windows.cpp b/src/main_windows.cpp index b3b021cd..56710613 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -98,6 +98,7 @@ int main(int argv, char ** args) setup(); std::cout << "HSetup OK\n"; + while(1) { SDL_Delay(5); lv_task_handler(); diff --git a/src/mouse_cursor_icon.c b/src/mouse_cursor_icon.c index 14c089a4..1c3a93a8 100644 --- a/src/mouse_cursor_icon.c +++ b/src/mouse_cursor_icon.c @@ -1,4 +1,3 @@ -#include "Arduino.h" #include "lvgl.h" #if 1 From b992779c3693f16e033f655e6f0a454396d46c88 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:03:19 +0100 Subject: [PATCH 013/236] Move user_config_override.h --- .gitignore | 3 +++ platformio_override-template.ini | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 24f89b84..756b6d8b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,11 +6,14 @@ .pio data/* src/user_setups/active/* +include/user_config_override.h src/user_config_override.h +user_config_override.h platformio_override.ini user_setups/active/* build_output/* build_output/firmware/*.bin +build_output/firmware/*.exe ## Test result files *.xml diff --git a/platformio_override-template.ini b/platformio_override-template.ini index ab5374e8..cd14bc2a 100644 --- a/platformio_override-template.ini +++ b/platformio_override-template.ini @@ -14,7 +14,7 @@ extra_configs = [override] ; -- Hasp config options -------------------------------------- build_flags = -; -- Uncomment the next line to use the file src/user_config_override.h settings +; -- Uncomment the next line to use the file include/user_config_override.h settings ; -DUSE_CONFIG_OVERRIDE ;region -- Default Build Environments : Used when Build All --- From ea78d5598076e2a0a858196ad2329964e0d9eb44 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:04:46 +0100 Subject: [PATCH 014/236] Cahnges to arduino environment --- platformio.ini | 13 +++++++++++-- user_setups/esp32/lolin-d32-pro_ili9341.ini | 10 ++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/platformio.ini b/platformio.ini index 602d9c17..f1528970 100644 --- a/platformio.ini +++ b/platformio.ini @@ -74,8 +74,8 @@ lib_deps = git+https://github.com/fvanroie/ConsoleInput.git ;git+https://github.com/andrethomas/TasmotaSlave.git ;git+https://github.com/fvanroie/lv_components.git - git+https://github.com/lvgl/lvgl.git - ;lvgl/lvgl @ ^7.7.2 ; from PIO library + ;git+https://github.com/lvgl/lvgl.git + lvgl/lvgl @^7.10.1 ; from PIO library ;bodmer/TFT_eSPI @ 2.3.4 ; Tft SPI drivers EXACT version 2.3.5 has compile error git+https://github.com/Bodmer/TFT_eSPI.git ; ------ Unused / Test libraries @@ -92,6 +92,15 @@ extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py ; -- Platform specific build flags [esp32] framework = arduino +platform = espressif32 +board = lolin_d32_pro +;upload_port = COM6 ; To change the port, use platform_override.ini +;monitor_port = COM6 ; To change the port, use platform_override.ini +monitor_filters = esp32_exception_decoder +board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv +check_tool = cppcheck +check_flags = --enable=all + build_flags = ${env.build_flags} -D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer diff --git a/user_setups/esp32/lolin-d32-pro_ili9341.ini b/user_setups/esp32/lolin-d32-pro_ili9341.ini index c2d22b36..dae78b4a 100644 --- a/user_setups/esp32/lolin-d32-pro_ili9341.ini +++ b/user_setups/esp32/lolin-d32-pro_ili9341.ini @@ -8,14 +8,7 @@ ; !! This board already defines TFT_CS, TFT_DC and TFT_RST !! [env:lolind32pro-lolintft24] -platform = espressif32 -board = lolin_d32_pro -;upload_port = COM6 ; To change the port, use platform_override.ini -;monitor_port = COM6 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv -check_tool = cppcheck -check_flags = --enable=all +extends = esp32 build_flags = ${env.build_flags} @@ -25,6 +18,7 @@ build_flags = ;region -- TFT_eSPI build options ------------------------ ${lcd.lolin24} ${esp32.vspi} ; Use VSPI hardware SPI bus + -D USE_TFT_ESPI ; The board already defines the macros for the TFT connector: ;-D TFT_DC=27 ; Defined by board, don't redefine !! ;-D TFT_CS=14 ; Defined by board, don't redefine !! From 9229280502d6040d06aaef943aa940afaa4c3da3 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:07:25 +0100 Subject: [PATCH 015/236] Move files around --- src/drv/hasp_drv_display.cpp | 2 + src/drv/hasp_drv_display.h | 2 + src/drv/{ => touch}/hasp_drv_ft5206.cpp | 0 src/drv/{ => touch}/hasp_drv_ft5206.h | 2 +- src/drv/{ => touch}/hasp_drv_ft6336u.cpp | 0 src/drv/{ => touch}/hasp_drv_ft6336u.h | 2 +- src/drv/{ => touch}/hasp_drv_gt911.cpp | 0 src/drv/{ => touch}/hasp_drv_gt911.h | 2 +- src/drv/{ => touch}/hasp_drv_xpt2046.cpp | 0 src/drv/{ => touch}/hasp_drv_xpt2046.h | 0 src/hasp_hal.cpp | 445 ---------------------- src/hasp_hal.h | 21 - src/net/hasp_wifi.h | 23 -- src/svc/hasp_http.cpp | 20 +- src/svc/hasp_telnet.cpp | 2 +- src/{ => sys/gpio}/hasp_gpio.cpp | 0 src/{ => sys/gpio}/hasp_gpio.h | 0 src/{ => sys}/net/hasp_ethernet_esp32.cpp | 2 +- src/{ => sys}/net/hasp_ethernet_esp32.h | 0 src/{ => sys}/net/hasp_ethernet_stm32.cpp | 2 +- src/{ => sys}/net/hasp_ethernet_stm32.h | 0 src/{ => sys}/net/hasp_network.cpp | 6 +- src/{ => sys}/net/hasp_network.h | 0 src/{ => sys}/net/hasp_wifi.cpp | 0 24 files changed, 23 insertions(+), 508 deletions(-) rename src/drv/{ => touch}/hasp_drv_ft5206.cpp (100%) rename src/drv/{ => touch}/hasp_drv_ft5206.h (87%) rename src/drv/{ => touch}/hasp_drv_ft6336u.cpp (100%) rename src/drv/{ => touch}/hasp_drv_ft6336u.h (86%) rename src/drv/{ => touch}/hasp_drv_gt911.cpp (100%) rename src/drv/{ => touch}/hasp_drv_gt911.h (87%) rename src/drv/{ => touch}/hasp_drv_xpt2046.cpp (100%) rename src/drv/{ => touch}/hasp_drv_xpt2046.h (100%) delete mode 100644 src/hasp_hal.cpp delete mode 100644 src/hasp_hal.h delete mode 100644 src/net/hasp_wifi.h rename src/{ => sys/gpio}/hasp_gpio.cpp (100%) rename src/{ => sys/gpio}/hasp_gpio.h (100%) rename src/{ => sys}/net/hasp_ethernet_esp32.cpp (98%) rename src/{ => sys}/net/hasp_ethernet_esp32.h (100%) rename src/{ => sys}/net/hasp_ethernet_stm32.cpp (99%) rename src/{ => sys}/net/hasp_ethernet_stm32.h (100%) rename src/{ => sys}/net/hasp_network.cpp (95%) rename src/{ => sys}/net/hasp_network.h (100%) rename src/{ => sys}/net/hasp_wifi.cpp (100%) diff --git a/src/drv/hasp_drv_display.cpp b/src/drv/hasp_drv_display.cpp index ad80fdf8..54d96c6c 100644 --- a/src/drv/hasp_drv_display.cpp +++ b/src/drv/hasp_drv_display.cpp @@ -1,4 +1,6 @@ #include "hasp_drv_display.h" +#include "tft_espi_drv.h" +//#include "fsmc_ili9341.h" void drv_display_init(lv_disp_drv_t * disp_drv, uint8_t rotation, bool invert_display) { diff --git a/src/drv/hasp_drv_display.h b/src/drv/hasp_drv_display.h index 477cb762..75a26c63 100644 --- a/src/drv/hasp_drv_display.h +++ b/src/drv/hasp_drv_display.h @@ -4,6 +4,8 @@ #ifndef HASP_DRV_DISPLAY_H #define HASP_DRV_DISPLAY_H +#include "lvgl.h" + // Select Display Driver #if defined(USE_FSMC) #include "fsmc_ili9341.h" diff --git a/src/drv/hasp_drv_ft5206.cpp b/src/drv/touch/hasp_drv_ft5206.cpp similarity index 100% rename from src/drv/hasp_drv_ft5206.cpp rename to src/drv/touch/hasp_drv_ft5206.cpp diff --git a/src/drv/hasp_drv_ft5206.h b/src/drv/touch/hasp_drv_ft5206.h similarity index 87% rename from src/drv/hasp_drv_ft5206.h rename to src/drv/touch/hasp_drv_ft5206.h index e53c1c07..88c6eb3f 100644 --- a/src/drv/hasp_drv_ft5206.h +++ b/src/drv/touch/hasp_drv_ft5206.h @@ -8,7 +8,7 @@ #define FT5206_address 0x38 - #include "hasp_debug.h" // for TAG_DRVR + #include "log/hasp_debug.h" // for TAG_DRVR bool FT5206_getXY(int16_t * touchX, int16_t * touchY, bool debug); void FT5206_init(); diff --git a/src/drv/hasp_drv_ft6336u.cpp b/src/drv/touch/hasp_drv_ft6336u.cpp similarity index 100% rename from src/drv/hasp_drv_ft6336u.cpp rename to src/drv/touch/hasp_drv_ft6336u.cpp diff --git a/src/drv/hasp_drv_ft6336u.h b/src/drv/touch/hasp_drv_ft6336u.h similarity index 86% rename from src/drv/hasp_drv_ft6336u.h rename to src/drv/touch/hasp_drv_ft6336u.h index f8e0e1e3..ac1dd47a 100644 --- a/src/drv/hasp_drv_ft6336u.h +++ b/src/drv/touch/hasp_drv_ft6336u.h @@ -6,7 +6,7 @@ #if TOUCH_DRIVER == 6336 - #include "hasp_debug.h" // for TAG_DRVR + #include "log/hasp_debug.h" // for TAG_DRVR bool FT6336U_getXY(int16_t * touchX, int16_t * touchY, bool debug); void FT6336U_init(); diff --git a/src/drv/hasp_drv_gt911.cpp b/src/drv/touch/hasp_drv_gt911.cpp similarity index 100% rename from src/drv/hasp_drv_gt911.cpp rename to src/drv/touch/hasp_drv_gt911.cpp diff --git a/src/drv/hasp_drv_gt911.h b/src/drv/touch/hasp_drv_gt911.h similarity index 87% rename from src/drv/hasp_drv_gt911.h rename to src/drv/touch/hasp_drv_gt911.h index d72627a0..ec36b69b 100644 --- a/src/drv/hasp_drv_gt911.h +++ b/src/drv/touch/hasp_drv_gt911.h @@ -6,7 +6,7 @@ #if TOUCH_DRIVER == 911 - #include "hasp_debug.h" // for TAG_DRVR + #include "log/hasp_debug.h" // for TAG_DRVR bool GT911_getXY(int16_t * touchX, int16_t * touchY, bool debug); void GT911_init(); diff --git a/src/drv/hasp_drv_xpt2046.cpp b/src/drv/touch/hasp_drv_xpt2046.cpp similarity index 100% rename from src/drv/hasp_drv_xpt2046.cpp rename to src/drv/touch/hasp_drv_xpt2046.cpp diff --git a/src/drv/hasp_drv_xpt2046.h b/src/drv/touch/hasp_drv_xpt2046.h similarity index 100% rename from src/drv/hasp_drv_xpt2046.h rename to src/drv/touch/hasp_drv_xpt2046.h diff --git a/src/hasp_hal.cpp b/src/hasp_hal.cpp deleted file mode 100644 index aa0323d0..00000000 --- a/src/hasp_hal.cpp +++ /dev/null @@ -1,445 +0,0 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie - For full license information read the LICENSE file in the project folder */ - -#include "hasp_hal.h" -#include "hasp_conf.h" - -#if defined(ESP8266) - #include - #include -#endif - -#if defined(ESP32) - #include - #include - #include "esp_system.h" -#endif - -#if defined(ARDUINO_ARCH_ESP32) - #include // needed to get the ResetInfo - -// Compatibility function for ESP8266 getRestInfo -String esp32ResetReason(uint8_t cpuid) -{ - if(cpuid > 1) { - return F("Invalid CPU id"); - } - RESET_REASON reason = rtc_get_reset_reason(cpuid); - - String resetReason((char *)0); - resetReason.reserve(128); - - resetReason += F("CPU"); - resetReason += cpuid; - resetReason += F(": "); - - switch(reason) { - case 1: - resetReason += F("POWERON"); - break; /**<1, Vbat power on reset*/ - case 3: - resetReason += F("SW"); - break; /**<3, Software reset digital core*/ - case 4: - resetReason += F("OWDT"); - break; /**<4, Legacy watch dog reset digital core*/ - case 5: - resetReason += F("DEEPSLEEP"); - break; /**<5, Deep Sleep reset digital core*/ - case 6: - resetReason += F("SDIO"); - break; /**<6, Reset by SLC module, reset digital core*/ - case 7: - resetReason += F("TG0WDT_SYS"); - break; /**<7, Timer Group0 Watch dog reset digital core*/ - case 8: - resetReason += F("TG1WDT_SYS"); - break; /**<8, Timer Group1 Watch dog reset digital core*/ - case 9: - resetReason += F("RTCWDT_SYS"); - break; /**<9, RTC Watch dog Reset digital core*/ - case 10: - resetReason += F("INTRUSION"); - break; /**<10, Instrusion tested to reset CPU*/ - case 11: - resetReason += F("TGWDT_CPU"); - break; /**<11, Time Group reset CPU*/ - case 12: - resetReason += F("SW_CPU"); - break; /**<12, Software reset CPU*/ - case 13: - resetReason += F("RTCWDT_CPU"); - break; /**<13, RTC Watch dog Reset CPU*/ - case 14: - resetReason += F("EXT_CPU"); - break; /**<14, for APP CPU, reseted by PRO CPU*/ - case 15: - resetReason += F("RTCWDT_BROWN_OUT"); - break; /**<15, Reset when the vdd voltage is not stable*/ - case 16: - resetReason += F("RTCWDT_RTC"); - break; /**<16, RTC Watch dog reset digital core and rtc module*/ - default: - resetReason += F("NO_MEAN"); - return resetReason; - } - resetReason += F("_RESET"); - return resetReason; -} -#endif - -void halRestartMcu(void) -{ -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - ESP.restart(); -#else - NVIC_SystemReset(); -#endif - for(;;) { - } // halt -} - -String halGetResetInfo() -{ -#if defined(ARDUINO_ARCH_ESP32) - String resetReason((char *)0); - resetReason.reserve(128); - - resetReason += String(esp32ResetReason(0)); - resetReason += F(" / "); - resetReason += String(esp32ResetReason(1)); - return resetReason; -#elif defined(ARDUINO_ARCH_ESP8266) - return ESP.getResetInfo(); -#else - return ""; -#endif -} - -String halGetCoreVersion() -{ -#if defined(ARDUINO_ARCH_ESP32) - return String(ESP.getSdkVersion()); -#elif defined(ARDUINO_ARCH_ESP8266) - return String(ESP.getCoreVersion()); -#else - return String(STM32_CORE_VERSION_MAJOR) + "." + STM32_CORE_VERSION_MINOR + "." + STM32_CORE_VERSION_PATCH; -#endif -} - -String halGetChipModel() -{ - String model((char *)0); - model.reserve(128); - -#if defined(STM32F4xx) - model = F("STM32"); -#endif - -#if defined(STM32F4xx) - model = F("STM32F4xx"); - -#elif defined(ARDUINO_ARCH_ESP8266) - model = F("ESP8266"); - -#elif defined(ARDUINO_ARCH_ESP32) - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); - - model = chip_info.cores; - model += F("core "); - switch(chip_info.model) { - case CHIP_ESP32: - model += F("ESP32"); - break; - #ifdef CHIP_ESP32S2 - case CHIP_ESP32S2: - model += F("ESP32-S2"); - break; - #endif - default: - model = F("Unknown ESP32"); - } - model += F(" rev"); - model += chip_info.revision; - -#else - model = F("Unknown"); -#endif - - return model; -} - -/*******************************/ -/* Memory Management Functions */ - -#if defined(STM32F4xx) - #include // for mallinfo() - #include // for sbrk() - -int freeHighMemory() -{ - char top; - #ifdef __arm__ - return &top - reinterpret_cast(sbrk(0)); - #elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151) - return &top - __brkval; - #else // __arm__ - return __brkval ? &top - __brkval : &top - __malloc_heap_start; - #endif // __arm__ -} -#endif - -/* -extern char *fake_heap_end; // current heap start -extern char *fake_heap_start; // current heap end - -char* getHeapStart() { - return fake_heap_start; -} - -char* getHeapEnd() { - return (char*)sbrk(0); -} - -char* getHeapLimit() { - return fake_heap_end; -} - -int getMemUsed() { // returns the amount of used memory in bytes - struct mallinfo mi = mallinfo(); - return mi.uordblks; -} - -int getMemFree() { // returns the amount of free memory in bytes - struct mallinfo mi = mallinfo(); - return mi.fordblks + freeHighMemory(); -} */ - -size_t halGetMaxFreeBlock() -{ -#if defined(ARDUINO_ARCH_ESP32) - return ESP.getMaxAllocHeap(); -#elif defined(ARDUINO_ARCH_ESP8266) - return ESP.getMaxFreeBlockSize(); -#else - return freeHighMemory(); -#endif -} - -size_t halGetFreeHeap(void) -{ -#if defined(ARDUINO_ARCH_ESP32) - return ESP.getFreeHeap(); -#elif defined(ARDUINO_ARCH_ESP8266) - return ESP.getFreeHeap(); -#else - struct mallinfo chuncks = mallinfo(); - - // fordblks - // This is the total size of memory occupied by free (not in use) chunks. - - return chuncks.fordblks + freeHighMemory(); -#endif -} - -uint8_t halGetHeapFragmentation() -{ -#if defined(ARDUINO_ARCH_ESP32) - return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)ESP.getFreeHeap()); -#elif defined(ARDUINO_ARCH_ESP8266) - return ESP.getHeapFragmentation(); -#else - return (int8_t)(100.00f - (float)freeHighMemory() * 100.00f / (float)halGetFreeHeap()); -#endif -} - -String halGetMacAddress(int start, const char * seperator) -{ - byte mac[6]; - -#if defined(STM32F4xx) - uint8_t * mac_p = nullptr; - #if HASP_USE_ETHERNET > 0 - #if USE_BUILTIN_ETHERNET > 0 - mac_p = Ethernet.MACAddress(); - for(int i = 0; i < 6; i++) mac[i] = *(mac_p + i); - #else - Ethernet.macAddress(mac); - #endif - #endif -#else - WiFi.macAddress(mac); -#endif - - String cMac((char *)0); - cMac.reserve(32); - - for(int i = start; i < 6; ++i) { - if(mac[i] < 0x10) cMac += "0"; - cMac += String(mac[i], HEX); - if(i < 5) cMac += seperator; - } - cMac.toUpperCase(); - return cMac; -} - -uint16_t halGetCpuFreqMHz() -{ -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32) - return ESP.getCpuFreqMHz(); -#else - return (F_CPU / 1000 / 1000); -#endif -} - - - -String halDisplayDriverName() -{ -#if defined(ILI9341_DRIVER) - return F("ILI9341"); -#elif defined(ST7735_DRIVER) - return F("ST7735"); -#elif defined(ILI9163_DRIVER) - return F("ILI9163"); -#elif defined(S6D02A1_DRIVER) - return F("S6D02A1"); -#elif defined(ST7796_DRIVER) - return F("ST7796"); -#elif defined(ILI9486_DRIVER) - return F("ILI9486"); -#elif defined(ILI9481_DRIVER) - return F("ILI9481"); -#elif defined(ILI9488_DRIVER) - return F("ILI9488"); -#elif defined(HX8357D_DRIVER) - return F("HX8357D"); -#elif defined(EPD_DRIVER) - return F("EPD"); -#elif defined(ST7789_DRIVER) - return F("ST7789"); -#elif defined(R61581_DRIVER) - return F("R61581"); -#elif defined(ST7789_2_DRIVER) - return F("ST7789_2"); -#elif defined(RM68140_DRIVER) - return F("RM68140"); -#endif - return F("Unknown"); -} - -String halGpioName(uint8_t gpio) -{ -#if defined(STM32F4xx) - String ioName; - uint16_t name = digitalPin[gpio]; - uint8_t num = name % 16; - switch(name / 16) { - case PortName::PortA: - ioName = F("PA"); - break; - case PortName::PortB: - ioName = F("PB"); - break; - #if defined GPIOC_BASE - case PortName::PortC: - ioName = F("PC"); - break; - #endif - #if defined GPIOD_BASE - case PortName::PortD: - ioName = F("PD"); - break; - #endif - #if defined GPIOE_BASE - case PortName::PortE: - ioName = F("PE"); - break; - #endif - #if defined GPIOF_BASE - case PortName::PortF: - ioName = F("PF"); - break; - #endif - #if defined GPIOG_BASE - case PortName::PortG: - ioName = F("PG"); - break; - #endif - #if defined GPIOH_BASE - case PortName::PortH: - ioName = F("PH"); - break; - #endif - #if defined GPIOI_BASE - case PortName::PortI: - ioName = F("PI"); - break; - #endif - #if defined GPIOJ_BASE - case PortName::PortJ: - ioName = F("PJ"); - break; - #endif - #if defined GPIOK_BASE - case PortName::PortK: - ioName = F("PK"); - break; - #endif - #if defined GPIOZ_BASE - case PortName::PortZ: - ioName = F("PZ"); - break; - #endif - default: - ioName = F("P?"); - } - ioName += num; - ioName += F(" (io"); - ioName += gpio; - ioName += F(")"); - return ioName; -#endif - -// For ESP32 pin labels on boards use the GPIO number -#ifdef ARDUINO_ARCH_ESP32 - return /*String(F("gpio")) +*/ String(gpio); -#endif - -#ifdef ARDUINO_ARCH_ESP8266 - // For ESP8266 the pin labels are not the same as the GPIO number - // These are for the NodeMCU pin definitions: - // GPIO Dxx - switch(gpio) { - case 16: - return F("D0"); - case 5: - return F("D1"); - case 4: - return F("D2"); - case 0: - return F("D3"); - case 2: - return F("D4"); - case 14: - return F("D5"); - case 12: - return F("D6"); - case 13: - return F("D7"); - case 15: - return F("D8"); - case 3: - return F("TX"); - case 1: - return F("RX"); - // case 9: - // return F("D11"); - // case 10: - // return F("D12"); - default: - return F("D?"); // Invalid pin - } -#endif -} \ No newline at end of file diff --git a/src/hasp_hal.h b/src/hasp_hal.h deleted file mode 100644 index 5c735bab..00000000 --- a/src/hasp_hal.h +++ /dev/null @@ -1,21 +0,0 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie - For full license information read the LICENSE file in the project folder */ - -#ifndef HASP_HAL_H -#define HASP_HAL_H - -#include - -void halRestartMcu(void); -uint8_t halGetHeapFragmentation(void); -String halGetResetInfo(void); -size_t halGetMaxFreeBlock(void); -size_t halGetFreeHeap(void); -String halGetCoreVersion(void); -String halGetChipModel(); -String halGetMacAddress(int start, const char * seperator); -uint16_t halGetCpuFreqMHz(void); -String halDisplayDriverName(void); -String halGpioName(uint8_t gpio); - -#endif \ No newline at end of file diff --git a/src/net/hasp_wifi.h b/src/net/hasp_wifi.h deleted file mode 100644 index 5364150f..00000000 --- a/src/net/hasp_wifi.h +++ /dev/null @@ -1,23 +0,0 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie - For full license information read the LICENSE file in the project folder */ - -#ifndef HASP_WIFI_H -#define HASP_WIFI_H - -#include "ArduinoJson.h" - -void wifiSetup(); -bool wifiShowAP(); -bool wifiShowAP(char * ssid, char * pass); -bool wifiEvery5Seconds(void); -void wifiStop(void); - -bool wifiValidateSsid(const char * ssid, const char * pass); -void wifi_get_statusupdate(char * buffer, size_t len); - -#if HASP_USE_CONFIG > 0 -bool wifiGetConfig(const JsonObject & settings); -bool wifiSetConfig(const JsonObject & settings); -#endif - -#endif \ No newline at end of file diff --git a/src/svc/hasp_http.cpp b/src/svc/hasp_http.cpp index 1fea82a0..194805ef 100644 --- a/src/svc/hasp_http.cpp +++ b/src/svc/hasp_http.cpp @@ -13,7 +13,7 @@ #include "hasp_conf.h" #include "hasp_gui.h" -#include "hasp_hal.h" +#include "hal/hasp_hal.h" #include "hasp_debug.h" #include "hasp_config.h" @@ -527,7 +527,7 @@ void webHandleInfo() httpMessage += F("s"); httpMessage += F("
Free Memory: "); - hasp_util_format_bytes(halGetFreeHeap(), size_buf, sizeof(size_buf)); + Utilities::format_bytes(halGetFreeHeap(), size_buf, sizeof(size_buf)); httpMessage += size_buf; httpMessage += F("
Memory Fragmentation: "); httpMessage += String(halGetHeapFragmentation()); @@ -535,10 +535,10 @@ void webHandleInfo() #if ARDUINO_ARCH_ESP32 if(psramFound()) { httpMessage += F("
Free PSRam: "); - hasp_util_format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf)); + Utilities::format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf)); httpMessage += size_buf; httpMessage += F("
PSRam Size: "); - hasp_util_format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf)); + Utilities::format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf)); httpMessage += size_buf; } #endif @@ -547,10 +547,10 @@ void webHandleInfo() lv_mem_monitor_t mem_mon; lv_mem_monitor(&mem_mon); httpMessage += F("

LVGL Memory: "); - hasp_util_format_bytes(mem_mon.total_size, size_buf, sizeof(size_buf)); + Utilities::format_bytes(mem_mon.total_size, size_buf, sizeof(size_buf)); httpMessage += size_buf; httpMessage += F("
LVGL Free: "); - hasp_util_format_bytes(mem_mon.free_size, size_buf, sizeof(size_buf)); + Utilities::format_bytes(mem_mon.free_size, size_buf, sizeof(size_buf)); httpMessage += size_buf; httpMessage += F("
LVGL Fragmentation: "); httpMessage += mem_mon.frag_pct; @@ -653,15 +653,15 @@ void webHandleInfo() #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) httpMessage += F("
Flash Chip Size: "); - hasp_util_format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf)); + Utilities::format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf)); httpMessage += size_buf; httpMessage += F("
Program Size: "); - hasp_util_format_bytes(ESP.getSketchSize(), size_buf, sizeof(size_buf)); + Utilities::format_bytes(ESP.getSketchSize(), size_buf, sizeof(size_buf)); httpMessage += size_buf; httpMessage += F("
Free Program Space: "); - hasp_util_format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf)); + Utilities::format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf)); httpMessage += size_buf; #endif @@ -1834,7 +1834,7 @@ void webHandleSaveConfig() { if(!httpIsAuthenticated(F("saveConfig"))) return; - configWriteConfig(); + configWrite(); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/svc/hasp_telnet.cpp b/src/svc/hasp_telnet.cpp index 8b9689d3..6caff6ec 100644 --- a/src/svc/hasp_telnet.cpp +++ b/src/svc/hasp_telnet.cpp @@ -7,7 +7,7 @@ #include "ArduinoJson.h" #include "ConsoleInput.h" - #include "hasp_debug.h" + #include "log/hasp_debug.h" #include "hasp_config.h" #include "hasp_telnet.h" diff --git a/src/hasp_gpio.cpp b/src/sys/gpio/hasp_gpio.cpp similarity index 100% rename from src/hasp_gpio.cpp rename to src/sys/gpio/hasp_gpio.cpp diff --git a/src/hasp_gpio.h b/src/sys/gpio/hasp_gpio.h similarity index 100% rename from src/hasp_gpio.h rename to src/sys/gpio/hasp_gpio.h diff --git a/src/net/hasp_ethernet_esp32.cpp b/src/sys/net/hasp_ethernet_esp32.cpp similarity index 98% rename from src/net/hasp_ethernet_esp32.cpp rename to src/sys/net/hasp_ethernet_esp32.cpp index b32ba958..8d073cb6 100644 --- a/src/net/hasp_ethernet_esp32.cpp +++ b/src/sys/net/hasp_ethernet_esp32.cpp @@ -3,7 +3,7 @@ #include "hasp_conf.h" -#include "hasp_hal.h" +#include "hal/hasp_hal.h" #include "hasp_debug.h" #include "hasp_network.h" diff --git a/src/net/hasp_ethernet_esp32.h b/src/sys/net/hasp_ethernet_esp32.h similarity index 100% rename from src/net/hasp_ethernet_esp32.h rename to src/sys/net/hasp_ethernet_esp32.h diff --git a/src/net/hasp_ethernet_stm32.cpp b/src/sys/net/hasp_ethernet_stm32.cpp similarity index 99% rename from src/net/hasp_ethernet_stm32.cpp rename to src/sys/net/hasp_ethernet_stm32.cpp index 46935132..32bdebe7 100644 --- a/src/net/hasp_ethernet_stm32.cpp +++ b/src/sys/net/hasp_ethernet_stm32.cpp @@ -4,7 +4,7 @@ #include "hasp_conf.h" #include "hasp_debug.h" -#include "hasp_hal.h" +#include "hal/hasp_hal.h" #if HASP_USE_ETHERNET > 0 && defined(STM32F4xx) diff --git a/src/net/hasp_ethernet_stm32.h b/src/sys/net/hasp_ethernet_stm32.h similarity index 100% rename from src/net/hasp_ethernet_stm32.h rename to src/sys/net/hasp_ethernet_stm32.h diff --git a/src/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp similarity index 95% rename from src/net/hasp_network.cpp rename to src/sys/net/hasp_network.cpp index 31ab26d2..b51d0778 100644 --- a/src/net/hasp_network.cpp +++ b/src/sys/net/hasp_network.cpp @@ -9,12 +9,12 @@ #include "ArduinoLog.h" #include "hasp_conf.h" -#include "hasp_hal.h" +#include "hal/hasp_hal.h" #include "hasp_debug.h" #include "hasp_network.h" -#include "../hasp/hasp.h" -#include "../svc/hasp_mdns.h" +#include "../../hasp/hasp.h" +#include "../../svc/hasp_mdns.h" #if HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0 void networkStart(void) diff --git a/src/net/hasp_network.h b/src/sys/net/hasp_network.h similarity index 100% rename from src/net/hasp_network.h rename to src/sys/net/hasp_network.h diff --git a/src/net/hasp_wifi.cpp b/src/sys/net/hasp_wifi.cpp similarity index 100% rename from src/net/hasp_wifi.cpp rename to src/sys/net/hasp_wifi.cpp From 17e88dcd35d958616a2922fc30b384f8d82562bd Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:07:56 +0100 Subject: [PATCH 016/236] Move files around --- src/dev/device.h | 5 ++--- src/dev/{ => lanbon-l8}/lanbonl8.cpp | 3 ++- src/dev/{ => lanbon-l8}/lanbonl8.h | 2 +- src/dev/{ => m5stackcore2}/m5stackcore2.cpp | 2 +- src/dev/{ => m5stackcore2}/m5stackcore2.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename src/dev/{ => lanbon-l8}/lanbonl8.cpp (97%) rename src/dev/{ => lanbon-l8}/lanbonl8.h (95%) rename src/dev/{ => m5stackcore2}/m5stackcore2.cpp (97%) rename src/dev/{ => m5stackcore2}/m5stackcore2.h (95%) diff --git a/src/dev/device.h b/src/dev/device.h index 98250540..f1f053f5 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -22,13 +22,12 @@ class BaseDevice { using dev::BaseDevice; -#include "lanbonl8.h" -#include "m5stackcore2.h" - #if defined(LANBONL8) #warning Lanbon L8 + #include "lanbonl8.h" #elif defined(M5STACK) #warning M5 Stack + #include "m5stackcore2.h" #else extern dev::BaseDevice haspDevice; #endif diff --git a/src/dev/lanbonl8.cpp b/src/dev/lanbon-l8/lanbonl8.cpp similarity index 97% rename from src/dev/lanbonl8.cpp rename to src/dev/lanbon-l8/lanbonl8.cpp index 71f92851..9fdccb7e 100644 --- a/src/dev/lanbonl8.cpp +++ b/src/dev/lanbon-l8/lanbonl8.cpp @@ -1,7 +1,8 @@ -#include "Arduino.h" #include "lanbonl8.h" #if defined(LANBONL8) + #include "Arduino.h" + #include "../device.h" #include "driver/adc.h" #include "esp_adc_cal.h" diff --git a/src/dev/lanbonl8.h b/src/dev/lanbon-l8/lanbonl8.h similarity index 95% rename from src/dev/lanbonl8.h rename to src/dev/lanbon-l8/lanbonl8.h index 445a2204..9155109e 100644 --- a/src/dev/lanbonl8.h +++ b/src/dev/lanbon-l8/lanbonl8.h @@ -4,7 +4,7 @@ #ifndef HASP_DEVICE_LANBONL8_H #define HASP_DEVICE_LANBONL8_H -#include "device.h" +#include "../device.h" #if defined(LANBONL8) diff --git a/src/dev/m5stackcore2.cpp b/src/dev/m5stackcore2/m5stackcore2.cpp similarity index 97% rename from src/dev/m5stackcore2.cpp rename to src/dev/m5stackcore2/m5stackcore2.cpp index d208931d..c3354aa2 100644 --- a/src/dev/m5stackcore2.cpp +++ b/src/dev/m5stackcore2/m5stackcore2.cpp @@ -1,8 +1,8 @@ -#include "device.h" #include "m5stackcore2.h" #if defined(M5STACK) #include "AXP192.h" // Power Mgmt + #include "../device.h" // AXP192 Axp; namespace dev { diff --git a/src/dev/m5stackcore2.h b/src/dev/m5stackcore2/m5stackcore2.h similarity index 95% rename from src/dev/m5stackcore2.h rename to src/dev/m5stackcore2/m5stackcore2.h index 39539fff..fa51231d 100644 --- a/src/dev/m5stackcore2.h +++ b/src/dev/m5stackcore2/m5stackcore2.h @@ -6,7 +6,7 @@ #if defined(M5STACK) - #include "device.h" + #include "../device.h" namespace dev { From 0d53ff02a7d81f3c42bbe2cfe87d5872d23f2d37 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:08:25 +0100 Subject: [PATCH 017/236] Seperate mqtt stacks --- src/mqtt/hasp_mqtt.h | 8 +++++-- src/mqtt/hasp_mqtt_ha.cpp | 36 +++++++++++++++-------------- src/mqtt/hasp_mqtt_paho.cpp | 30 +++++++++++++----------- src/mqtt/hasp_mqtt_pubsubclient.cpp | 4 ++-- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/mqtt/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h index 6d3dcbde..322c7b88 100644 --- a/src/mqtt/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -8,7 +8,9 @@ #include "hasp_conf.h" -#define __FlashStringHelper char +#ifdef WINDOWS + #define __FlashStringHelper char +#endif void mqttSetup(); void mqttLoop(); @@ -26,6 +28,8 @@ bool mqttGetConfig(const JsonObject & settings); bool mqttSetConfig(const JsonObject & settings); #endif -//String mqttGetNodename(void); +#ifndef WINDOWS +String mqttGetNodename(void); +#endif #endif \ No newline at end of file diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index a5e1bfe7..1bab42f0 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -4,19 +4,20 @@ #include "ArduinoJson.h" #include "hasp_conf.h" -#if 0 && HASP_USE_MQTT > 0 +#ifndef WINDOWS + #if HASP_USE_MQTT > 0 - #include "PubSubClient.h" + #include "PubSubClient.h" - #include "hasp/hasp.h" - #include "hasp/hasp_dispatch.h" - #include "hasp_hal.h" - #include "hasp_mqtt.h" - #include "hasp_mqtt_ha.h" + #include "hasp/hasp.h" + #include "hasp/hasp_dispatch.h" + #include "hal/hasp_hal.h" + #include "hasp_mqtt.h" + #include "hasp_mqtt_ha.h" - #define RETAINED true - #define HASP_MAC_ADDRESS halGetMacAddress(0, "").c_str() - #define HASP_MAC_ADDRESS_STR halGetMacAddress(0, "") + #define RETAINED true + #define HASP_MAC_ADDRESS halGetMacAddress(0, "").c_str() + #define HASP_MAC_ADDRESS_STR halGetMacAddress(0, "") extern PubSubClient mqttClient; extern char mqttNodeName[16]; @@ -27,10 +28,10 @@ extern bool mqttHAautodiscover; char discovery_prefix[] = "homeassistant"; -const char FP_MQTT_HA_DEVICE[] PROGMEM = "device"; -const char FP_MQTT_HA_IDENTIFIERS[] PROGMEM = "ids"; -const char FP_MQTT_HA_NAME[] PROGMEM = "name"; -const char FP_MQTT_HA_MODEL[] PROGMEM = "mdl"; +const char FP_MQTT_HA_DEVICE[] PROGMEM = "device"; +const char FP_MQTT_HA_IDENTIFIERS[] PROGMEM = "ids"; +const char FP_MQTT_HA_NAME[] PROGMEM = "name"; +const char FP_MQTT_HA_MODEL[] PROGMEM = "mdl"; const char FP_MQTT_HA_MANUFACTURER[] PROGMEM = "mf"; void mqtt_ha_send_json(char * topic, JsonDocument & doc) @@ -53,9 +54,9 @@ void mqtt_ha_add_device_ids(JsonDocument & doc) haspGetVersion(buffer, sizeof(buffer)); device[F("sw")] = buffer; - device[FPSTR(FP_MQTT_HA_NAME)] = mqttNodeName; - device[FPSTR(FP_MQTT_HA_MODEL)] = F(PIOENV); - device[FPSTR(FP_MQTT_HA_MANUFACTURER)] = F(D_MANUFACTURER); + device[FPSTR(FP_MQTT_HA_NAME)] = mqttNodeName; + device[FPSTR(FP_MQTT_HA_MODEL)] = F(PIOENV); + device[FPSTR(FP_MQTT_HA_MANUFACTURER)] = F(D_MANUFACTURER); doc[F("~")] = mqttNodeTopic; } @@ -251,6 +252,7 @@ void mqtt_ha_register_auto_discovery() mqtt_ha_register_idle(); mqtt_ha_register_connectivity(); } + #endif #endif /* diff --git a/src/mqtt/hasp_mqtt_paho.cpp b/src/mqtt/hasp_mqtt_paho.cpp index 07ebb2b5..a0c017f8 100644 --- a/src/mqtt/hasp_mqtt_paho.cpp +++ b/src/mqtt/hasp_mqtt_paho.cpp @@ -109,20 +109,11 @@ static bool mqttPublish(const char * topic, const char * payload, size_t len, bo void connlost(void * context, char * cause) { - MQTTAsync client = (MQTTAsync)context; - MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer; - int rc; - connected = 0; - printf("\nConnection lost\n"); if(cause) printf(" cause: %s\n", cause); printf("Reconnecting\n"); - conn_opts.keepAliveInterval = 20; - conn_opts.cleansession = 1; - if((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS) { - printf("Failed to start connect, return code %d\n", rc); - } + mqttStart(); } // Receive incoming messages @@ -185,8 +176,8 @@ static void mqtt_message_cb(char * topic, char * payload, unsigned int length) int msgarrvd(void * context, char * topicName, int topicLen, MQTTAsync_message * message) { - printf("MQT RCV >> "); - printf("%s => %.*s (%d)\n", topicName, message->payloadlen, (char *)message->payload, message->payloadlen); + // printf("MQT RCV >> "); + // printf("%s => %.*s (%d)\n", topicName, message->payloadlen, (char *)message->payload, message->payloadlen); char msg[message->payloadlen + 1]; memcpy(msg, (char *)message->payload, message->payloadlen); @@ -256,6 +247,8 @@ void onConnect(void * context, MQTTAsync_successData * response) mqtt_subscribe(context, TOPIC "light"); mqtt_subscribe(context, TOPIC "dim"); + mqttPublish(TOPIC LWT_TOPIC, "online", false); + mqtt_send_object_state(0, 0, "connected"); std::cout << std::endl; } @@ -272,7 +265,7 @@ void onSendFailure(void * context, MQTTAsync_failureData * response) opts.context = client; if((rc = MQTTAsync_disconnect(client, &opts)) != MQTTASYNC_SUCCESS) { printf("Failed to start disconnect, return code %d\n", rc); - exit(EXIT_FAILURE); + //exit(EXIT_FAILURE); } } @@ -282,7 +275,8 @@ void onSend(void * context, MQTTAsync_successData * response) MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; int rc; - printf("Message with token value %d delivery confirmed\n", response->token); + // printf("Message with token value %d delivery confirmed\n", response->token); + // opts.onSuccess = onDisconnect; // opts.onFailure = onDisconnectFailure; // opts.context = client; @@ -346,6 +340,7 @@ void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload) void mqttStart() { MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer; + MQTTAsync_willOptions will_opts = MQTTAsync_willOptions_initializer; int rc; int ch; @@ -362,11 +357,18 @@ void mqttStart() return; } + conn_opts.will = &will_opts; + conn_opts.will->message = "offline"; + conn_opts.will->qos = 1; + conn_opts.will->retained = 0; + conn_opts.will->topicName = "hasp/plate35/LWT"; + conn_opts.keepAliveInterval = 20; conn_opts.cleansession = 1; conn_opts.onSuccess = onConnect; conn_opts.onFailure = onConnectFailure; conn_opts.context = mqtt_client; + if((rc = MQTTAsync_connect(mqtt_client, &conn_opts)) != MQTTASYNC_SUCCESS) { printf("Failed to start connect, return code %d\n", rc); rc = EXIT_FAILURE; diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index 70701959..0bcfa252 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -36,8 +36,8 @@ EthernetClient mqttNetworkClient; #endif #endif - #include "hasp_hal.h" - #include "log/hasp_debug.h" + #include "hal/hasp_hal.h" + #include "hasp_debug.h" #include "hasp_config.h" #include "../hasp/hasp_dispatch.h" From 8d3fec7da9d0b27cab43c50cdd35c5e3727271b9 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:08:52 +0100 Subject: [PATCH 018/236] Move files around --- src/hal/hasp_hal.cpp | 445 +++++++++++++++++++++++++++++++++++++++++++ src/hal/hasp_hal.h | 21 ++ 2 files changed, 466 insertions(+) create mode 100644 src/hal/hasp_hal.cpp create mode 100644 src/hal/hasp_hal.h diff --git a/src/hal/hasp_hal.cpp b/src/hal/hasp_hal.cpp new file mode 100644 index 00000000..aa0323d0 --- /dev/null +++ b/src/hal/hasp_hal.cpp @@ -0,0 +1,445 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#include "hasp_hal.h" +#include "hasp_conf.h" + +#if defined(ESP8266) + #include + #include +#endif + +#if defined(ESP32) + #include + #include + #include "esp_system.h" +#endif + +#if defined(ARDUINO_ARCH_ESP32) + #include // needed to get the ResetInfo + +// Compatibility function for ESP8266 getRestInfo +String esp32ResetReason(uint8_t cpuid) +{ + if(cpuid > 1) { + return F("Invalid CPU id"); + } + RESET_REASON reason = rtc_get_reset_reason(cpuid); + + String resetReason((char *)0); + resetReason.reserve(128); + + resetReason += F("CPU"); + resetReason += cpuid; + resetReason += F(": "); + + switch(reason) { + case 1: + resetReason += F("POWERON"); + break; /**<1, Vbat power on reset*/ + case 3: + resetReason += F("SW"); + break; /**<3, Software reset digital core*/ + case 4: + resetReason += F("OWDT"); + break; /**<4, Legacy watch dog reset digital core*/ + case 5: + resetReason += F("DEEPSLEEP"); + break; /**<5, Deep Sleep reset digital core*/ + case 6: + resetReason += F("SDIO"); + break; /**<6, Reset by SLC module, reset digital core*/ + case 7: + resetReason += F("TG0WDT_SYS"); + break; /**<7, Timer Group0 Watch dog reset digital core*/ + case 8: + resetReason += F("TG1WDT_SYS"); + break; /**<8, Timer Group1 Watch dog reset digital core*/ + case 9: + resetReason += F("RTCWDT_SYS"); + break; /**<9, RTC Watch dog Reset digital core*/ + case 10: + resetReason += F("INTRUSION"); + break; /**<10, Instrusion tested to reset CPU*/ + case 11: + resetReason += F("TGWDT_CPU"); + break; /**<11, Time Group reset CPU*/ + case 12: + resetReason += F("SW_CPU"); + break; /**<12, Software reset CPU*/ + case 13: + resetReason += F("RTCWDT_CPU"); + break; /**<13, RTC Watch dog Reset CPU*/ + case 14: + resetReason += F("EXT_CPU"); + break; /**<14, for APP CPU, reseted by PRO CPU*/ + case 15: + resetReason += F("RTCWDT_BROWN_OUT"); + break; /**<15, Reset when the vdd voltage is not stable*/ + case 16: + resetReason += F("RTCWDT_RTC"); + break; /**<16, RTC Watch dog reset digital core and rtc module*/ + default: + resetReason += F("NO_MEAN"); + return resetReason; + } + resetReason += F("_RESET"); + return resetReason; +} +#endif + +void halRestartMcu(void) +{ +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + ESP.restart(); +#else + NVIC_SystemReset(); +#endif + for(;;) { + } // halt +} + +String halGetResetInfo() +{ +#if defined(ARDUINO_ARCH_ESP32) + String resetReason((char *)0); + resetReason.reserve(128); + + resetReason += String(esp32ResetReason(0)); + resetReason += F(" / "); + resetReason += String(esp32ResetReason(1)); + return resetReason; +#elif defined(ARDUINO_ARCH_ESP8266) + return ESP.getResetInfo(); +#else + return ""; +#endif +} + +String halGetCoreVersion() +{ +#if defined(ARDUINO_ARCH_ESP32) + return String(ESP.getSdkVersion()); +#elif defined(ARDUINO_ARCH_ESP8266) + return String(ESP.getCoreVersion()); +#else + return String(STM32_CORE_VERSION_MAJOR) + "." + STM32_CORE_VERSION_MINOR + "." + STM32_CORE_VERSION_PATCH; +#endif +} + +String halGetChipModel() +{ + String model((char *)0); + model.reserve(128); + +#if defined(STM32F4xx) + model = F("STM32"); +#endif + +#if defined(STM32F4xx) + model = F("STM32F4xx"); + +#elif defined(ARDUINO_ARCH_ESP8266) + model = F("ESP8266"); + +#elif defined(ARDUINO_ARCH_ESP32) + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); + + model = chip_info.cores; + model += F("core "); + switch(chip_info.model) { + case CHIP_ESP32: + model += F("ESP32"); + break; + #ifdef CHIP_ESP32S2 + case CHIP_ESP32S2: + model += F("ESP32-S2"); + break; + #endif + default: + model = F("Unknown ESP32"); + } + model += F(" rev"); + model += chip_info.revision; + +#else + model = F("Unknown"); +#endif + + return model; +} + +/*******************************/ +/* Memory Management Functions */ + +#if defined(STM32F4xx) + #include // for mallinfo() + #include // for sbrk() + +int freeHighMemory() +{ + char top; + #ifdef __arm__ + return &top - reinterpret_cast(sbrk(0)); + #elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151) + return &top - __brkval; + #else // __arm__ + return __brkval ? &top - __brkval : &top - __malloc_heap_start; + #endif // __arm__ +} +#endif + +/* +extern char *fake_heap_end; // current heap start +extern char *fake_heap_start; // current heap end + +char* getHeapStart() { + return fake_heap_start; +} + +char* getHeapEnd() { + return (char*)sbrk(0); +} + +char* getHeapLimit() { + return fake_heap_end; +} + +int getMemUsed() { // returns the amount of used memory in bytes + struct mallinfo mi = mallinfo(); + return mi.uordblks; +} + +int getMemFree() { // returns the amount of free memory in bytes + struct mallinfo mi = mallinfo(); + return mi.fordblks + freeHighMemory(); +} */ + +size_t halGetMaxFreeBlock() +{ +#if defined(ARDUINO_ARCH_ESP32) + return ESP.getMaxAllocHeap(); +#elif defined(ARDUINO_ARCH_ESP8266) + return ESP.getMaxFreeBlockSize(); +#else + return freeHighMemory(); +#endif +} + +size_t halGetFreeHeap(void) +{ +#if defined(ARDUINO_ARCH_ESP32) + return ESP.getFreeHeap(); +#elif defined(ARDUINO_ARCH_ESP8266) + return ESP.getFreeHeap(); +#else + struct mallinfo chuncks = mallinfo(); + + // fordblks + // This is the total size of memory occupied by free (not in use) chunks. + + return chuncks.fordblks + freeHighMemory(); +#endif +} + +uint8_t halGetHeapFragmentation() +{ +#if defined(ARDUINO_ARCH_ESP32) + return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)ESP.getFreeHeap()); +#elif defined(ARDUINO_ARCH_ESP8266) + return ESP.getHeapFragmentation(); +#else + return (int8_t)(100.00f - (float)freeHighMemory() * 100.00f / (float)halGetFreeHeap()); +#endif +} + +String halGetMacAddress(int start, const char * seperator) +{ + byte mac[6]; + +#if defined(STM32F4xx) + uint8_t * mac_p = nullptr; + #if HASP_USE_ETHERNET > 0 + #if USE_BUILTIN_ETHERNET > 0 + mac_p = Ethernet.MACAddress(); + for(int i = 0; i < 6; i++) mac[i] = *(mac_p + i); + #else + Ethernet.macAddress(mac); + #endif + #endif +#else + WiFi.macAddress(mac); +#endif + + String cMac((char *)0); + cMac.reserve(32); + + for(int i = start; i < 6; ++i) { + if(mac[i] < 0x10) cMac += "0"; + cMac += String(mac[i], HEX); + if(i < 5) cMac += seperator; + } + cMac.toUpperCase(); + return cMac; +} + +uint16_t halGetCpuFreqMHz() +{ +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32) + return ESP.getCpuFreqMHz(); +#else + return (F_CPU / 1000 / 1000); +#endif +} + + + +String halDisplayDriverName() +{ +#if defined(ILI9341_DRIVER) + return F("ILI9341"); +#elif defined(ST7735_DRIVER) + return F("ST7735"); +#elif defined(ILI9163_DRIVER) + return F("ILI9163"); +#elif defined(S6D02A1_DRIVER) + return F("S6D02A1"); +#elif defined(ST7796_DRIVER) + return F("ST7796"); +#elif defined(ILI9486_DRIVER) + return F("ILI9486"); +#elif defined(ILI9481_DRIVER) + return F("ILI9481"); +#elif defined(ILI9488_DRIVER) + return F("ILI9488"); +#elif defined(HX8357D_DRIVER) + return F("HX8357D"); +#elif defined(EPD_DRIVER) + return F("EPD"); +#elif defined(ST7789_DRIVER) + return F("ST7789"); +#elif defined(R61581_DRIVER) + return F("R61581"); +#elif defined(ST7789_2_DRIVER) + return F("ST7789_2"); +#elif defined(RM68140_DRIVER) + return F("RM68140"); +#endif + return F("Unknown"); +} + +String halGpioName(uint8_t gpio) +{ +#if defined(STM32F4xx) + String ioName; + uint16_t name = digitalPin[gpio]; + uint8_t num = name % 16; + switch(name / 16) { + case PortName::PortA: + ioName = F("PA"); + break; + case PortName::PortB: + ioName = F("PB"); + break; + #if defined GPIOC_BASE + case PortName::PortC: + ioName = F("PC"); + break; + #endif + #if defined GPIOD_BASE + case PortName::PortD: + ioName = F("PD"); + break; + #endif + #if defined GPIOE_BASE + case PortName::PortE: + ioName = F("PE"); + break; + #endif + #if defined GPIOF_BASE + case PortName::PortF: + ioName = F("PF"); + break; + #endif + #if defined GPIOG_BASE + case PortName::PortG: + ioName = F("PG"); + break; + #endif + #if defined GPIOH_BASE + case PortName::PortH: + ioName = F("PH"); + break; + #endif + #if defined GPIOI_BASE + case PortName::PortI: + ioName = F("PI"); + break; + #endif + #if defined GPIOJ_BASE + case PortName::PortJ: + ioName = F("PJ"); + break; + #endif + #if defined GPIOK_BASE + case PortName::PortK: + ioName = F("PK"); + break; + #endif + #if defined GPIOZ_BASE + case PortName::PortZ: + ioName = F("PZ"); + break; + #endif + default: + ioName = F("P?"); + } + ioName += num; + ioName += F(" (io"); + ioName += gpio; + ioName += F(")"); + return ioName; +#endif + +// For ESP32 pin labels on boards use the GPIO number +#ifdef ARDUINO_ARCH_ESP32 + return /*String(F("gpio")) +*/ String(gpio); +#endif + +#ifdef ARDUINO_ARCH_ESP8266 + // For ESP8266 the pin labels are not the same as the GPIO number + // These are for the NodeMCU pin definitions: + // GPIO Dxx + switch(gpio) { + case 16: + return F("D0"); + case 5: + return F("D1"); + case 4: + return F("D2"); + case 0: + return F("D3"); + case 2: + return F("D4"); + case 14: + return F("D5"); + case 12: + return F("D6"); + case 13: + return F("D7"); + case 15: + return F("D8"); + case 3: + return F("TX"); + case 1: + return F("RX"); + // case 9: + // return F("D11"); + // case 10: + // return F("D12"); + default: + return F("D?"); // Invalid pin + } +#endif +} \ No newline at end of file diff --git a/src/hal/hasp_hal.h b/src/hal/hasp_hal.h new file mode 100644 index 00000000..5c735bab --- /dev/null +++ b/src/hal/hasp_hal.h @@ -0,0 +1,21 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_HAL_H +#define HASP_HAL_H + +#include + +void halRestartMcu(void); +uint8_t halGetHeapFragmentation(void); +String halGetResetInfo(void); +size_t halGetMaxFreeBlock(void); +size_t halGetFreeHeap(void); +String halGetCoreVersion(void); +String halGetChipModel(); +String halGetMacAddress(int start, const char * seperator); +uint16_t halGetCpuFreqMHz(void); +String halDisplayDriverName(void); +String halGpioName(uint8_t gpio); + +#endif \ No newline at end of file From ea6a8cd532914b880e8ee95df976145c120b7b2c Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:09:50 +0100 Subject: [PATCH 019/236] Xplatform changes --- src/hasp/hasp_attribute.cpp | 186 ++++++++++++++---------------------- 1 file changed, 74 insertions(+), 112 deletions(-) diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 43e6fe6c..a5f6bab7 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1,17 +1,21 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ +#ifdef ARDUINO + #include "ArduinoLog.h" +#endif + #include "lvgl.h" #if LVGL_VERSION_MAJOR != 7 #include "../lv_components.h" #endif -#include "ArduinoLog.h" #include "hasp.h" #include "hasp_object.h" #include "hasp_dispatch.h" #include "hasp_attribute.h" #include "hasp_utilities.h" +#include "hasp_parser.h" LV_FONT_DECLARE(unscii_8_icon); extern lv_font_t * haspFonts[8]; @@ -342,14 +346,16 @@ static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload) size_t tot_len = sizeof(char *) * (arr.size() + 1); const char ** map_data_str = (const char **)lv_mem_alloc(tot_len); if(map_data_str == NULL) { - return LOG_ERROR(TAG_ATTR, F("Out of memory while creating button map")); + LOG_ERROR(TAG_ATTR, F("Out of memory while creating button map")); + return; } memset(map_data_str, 0, tot_len); // Create buffer tot_len = 0; for(JsonVariant btn : arr) { - tot_len += btn.as().length() + 1; + // tot_len += btn.as().length() + 1; + tot_len += strlen(btn.as()) + 1; } tot_len++; // trailing '\0' LOG_VERBOSE(TAG_ATTR, F("Array Size = %d, Map Length = %d"), arr.size(), tot_len); @@ -357,7 +363,8 @@ static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload) char * buffer_addr = (char *)lv_mem_alloc(tot_len); if(buffer_addr == NULL) { lv_mem_free(map_data_str); - return LOG_ERROR(TAG_ATTR, F("Out of memory while creating button map")); + LOG_ERROR(TAG_ATTR, F("Out of memory while creating button map")); + return; } memset(buffer_addr, 0, tot_len); // Important, last index needs to be 0 => empty string "" @@ -370,11 +377,15 @@ static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload) size_t pos = 0; LOG_VERBOSE(TAG_ATTR, F("%s %d lbl addr: %x"), __FILE__, __LINE__, buffer_addr); for(JsonVariant btn : arr) { - size_t len = btn.as().length() + 1; - LOG_VERBOSE(TAG_ATTR, F(D_BULLET "Adding button: %s (%d bytes) %x"), btn.as().c_str(), len, + // size_t len = btn.as().length() + 1; + size_t len = strlen(btn.as()) + 1; + LOG_VERBOSE(TAG_ATTR, F(D_BULLET "Adding button: %s (%d bytes) %x"), btn.as(), len, buffer_addr + pos); - memccpy(buffer_addr + pos, btn.as().c_str(), 0, len); // Copy the label text into the buffer - map_data_str[index++] = buffer_addr + pos; // save pointer to the label in the array + // LOG_VERBOSE(TAG_ATTR, F(D_BULLET "Adding button: %s (%d bytes) %x"), btn.as().c_str(), len, + // buffer_addr + pos); + memccpy(buffer_addr + pos, btn.as(), 0, len); // Copy the label text into the buffer + // memccpy(buffer_addr + pos, btn.as().c_str(), 0, len); // Copy the label text into the buffer + map_data_str[index++] = buffer_addr + pos; // save pointer to the label in the array pos += len; } map_data_str[index] = buffer_addr + pos; // save pointer to the last \0 byte @@ -414,7 +425,8 @@ static void line_set_points(lv_obj_t * obj, const char * payload) size_t tot_len = sizeof(lv_point_t *) * (arr.size()); lv_point_t * point_arr = (lv_point_t *)lv_mem_alloc(tot_len); if(point_arr == NULL) { - return LOG_ERROR(TAG_ATTR, F("Out of memory while creating line points")); + LOG_ERROR(TAG_ATTR, F("Out of memory while creating line points")); + return; } memset(point_arr, 0, tot_len); @@ -442,74 +454,6 @@ static inline lv_color_t haspLogColor(lv_color_t color) return color; } -// OK -bool haspPayloadToColor(const char * payload, lv_color32_t & color) -{ - /* HEX format #rrggbb or #rgb */ - if(*payload == '#') { - if(strlen(payload) >= 8) return false; - - char * pEnd; - long color_int = strtol(payload + 1, &pEnd, HEX); - uint8_t R8; - uint8_t G8; - uint8_t B8; - - if(pEnd - payload == 7) { // #rrbbgg - color.ch.red = color_int >> 16 & 0xff; - color.ch.green = color_int >> 8 & 0xff; - color.ch.blue = color_int & 0xff; - - } else if(pEnd - payload == 4) { // #rgb - color.ch.red = color_int >> 8 & 0xf; - color.ch.green = color_int >> 4 & 0xf; - color.ch.blue = color_int & 0xf; - - color.ch.red += color.ch.red * HEX; - color.ch.green += color.ch.green * HEX; - color.ch.blue += color.ch.blue * HEX; - - } else { - return false; /* Invalid hex length */ - } - - return true; /* Color found */ - } - - /* 16-bit RGB565 Color Scheme*/ - if(hasp_util_is_only_digits(payload)) { - uint16_t c = atoi(payload); - - /* Initial colors */ - uint8_t R5 = ((c >> 11) & 0b11111); - uint8_t G6 = ((c >> 5) & 0b111111); - uint8_t B5 = (c & 0b11111); - - /* Remapped colors */ - color.ch.red = (R5 * 527 + 23) >> 6; - color.ch.green = (G6 * 259 + 33) >> 6; - color.ch.blue = (B5 * 527 + 23) >> 6; - - return true; /* Color found */ - } - - /* Named colors */ - size_t numColors = sizeof(haspNamedColors) / sizeof(haspNamedColors[0]); - uint16_t sdbm = hasp_util_get_sdbm(payload); - - for(size_t i = 0; i < numColors; i++) { - if(sdbm == (uint16_t)pgm_read_word_near(&(haspNamedColors[i].hash))) { - color.ch.red = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].r)); - color.ch.green = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].g)); - color.ch.blue = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].b)); - - return true; /* Color found */ - } - } - - return false; /* Color not found */ -} - static lv_font_t * haspPayloadToFont(const char * payload) { uint8_t var = atoi(payload); @@ -524,7 +468,7 @@ static lv_font_t * haspPayloadToFont(const char * payload) case 8: return &unscii_8_icon; -#if ESP32 +#ifndef ARDUINO_ARCH_ESP8266 #ifdef LV_FONT_CUSTOM_12 case 12: @@ -590,7 +534,8 @@ static void hasp_process_label_long_mode(lv_obj_t * obj, const char * payload, b } else if(!strcasecmp_P(payload, PSTR("crop"))) { mode = LV_LABEL_LONG_CROP; } else { - return LOG_WARNING(TAG_ATTR, F("Invalid long mode")); + LOG_WARNING(TAG_ATTR, F("Invalid long mode")); + return; } lv_label_set_long_mode(obj, mode); } else { @@ -785,7 +730,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t // test_prop(attr_hash); hasp_attribute_get_part_state(obj, attr_p, attr, part, state); - attr_hash = hasp_util_get_sdbm(attr); // attribute name without the index number + attr_hash = Utilities::get_sdbm(attr); // attribute name without the index number /* ***** WARNING **************************************************** * when using hasp_out use attr_p for the original attribute name @@ -836,7 +781,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_BG_COLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c) && part != 64) + if(Parser::haspPayloadToColor(payload, c) && part != 64) lv_obj_set_style_local_bg_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { hasp_out_color(obj, attr, lv_obj_get_style_bg_color(obj, part)); @@ -846,7 +791,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_BG_GRAD_COLOR: if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_bg_grad_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { @@ -857,6 +802,16 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_BG_OPA: return attribute_bg_opa(obj, part, state, update, attr_p, (lv_opa_t)var); + /* Margin attributes */ + case ATTR_MARGIN_TOP: + return attribute_margin_top(obj, part, state, update, attr_p, (lv_style_int_t)var); + case ATTR_MARGIN_BOTTOM: + return attribute_margin_bottom(obj, part, state, update, attr_p, (lv_style_int_t)var); + case ATTR_MARGIN_LEFT: + return attribute_margin_left(obj, part, state, update, attr_p, (lv_style_int_t)var); + case ATTR_MARGIN_RIGHT: + return attribute_margin_right(obj, part, state, update, attr_p, (lv_style_int_t)var); + /* Padding attributes */ case ATTR_PAD_TOP: return attribute_pad_top(obj, part, state, update, attr_p, (lv_style_int_t)var); @@ -883,7 +838,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_TEXT_COLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_text_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { hasp_out_color(obj, attr, lv_obj_get_style_text_color(obj, part)); @@ -893,7 +848,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_TEXT_SEL_COLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_text_sel_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { @@ -910,7 +865,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t if(check_obj_type(obj, LV_HASP_ROLLER)) lv_roller_set_visible_row_count(obj, count); lv_obj_set_style_local_text_font(obj, part, state, font); // again, for roller - if(check_obj_type(obj, LV_HASP_DDLIST)) { // issue #43 + if(check_obj_type(obj, LV_HASP_DROPDOWN)) { // issue #43 lv_obj_set_style_local_text_font(obj, LV_DROPDOWN_PART_MAIN, state, font); lv_obj_set_style_local_text_font(obj, LV_DROPDOWN_PART_LIST, state, font); lv_obj_set_style_local_text_font(obj, LV_DROPDOWN_PART_SELECTED, state, font); @@ -928,13 +883,13 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_BORDER_SIDE: return attribute_border_side(obj, part, state, update, attr_p, (lv_border_side_t)var); case ATTR_BORDER_POST: - return attribute_border_post(obj, part, state, update, attr_p, hasp_util_is_true(payload)); + return attribute_border_post(obj, part, state, update, attr_p, Utilities::is_true(payload)); case ATTR_BORDER_OPA: return attribute_border_opa(obj, part, state, update, attr_p, (lv_opa_t)var); case ATTR_BORDER_COLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_border_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { @@ -953,7 +908,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_OUTLINE_COLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_outline_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { @@ -977,7 +932,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_SHADOW_COLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_shadow_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { @@ -995,13 +950,13 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_LINE_DASH_GAP: return attribute_line_dash_gap(obj, part, state, update, attr_p, (lv_style_int_t)var); case ATTR_LINE_ROUNDED: - return attribute_line_rounded(obj, part, state, update, attr_p, hasp_util_is_true(payload)); + return attribute_line_rounded(obj, part, state, update, attr_p, Utilities::is_true(payload)); case ATTR_LINE_OPA: return attribute_line_opa(obj, part, state, update, attr_p, (lv_opa_t)var); case ATTR_LINE_COLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_line_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { hasp_out_color(obj, attr, lv_obj_get_style_line_color(obj, part)); @@ -1051,7 +1006,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_VALUE_COLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_value_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { @@ -1064,13 +1019,14 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t if(font) { return lv_obj_set_style_local_value_font(obj, part, state, font); } else { - return LOG_WARNING(TAG_ATTR, F("Unknown Font ID %s"), attr_p); + LOG_WARNING(TAG_ATTR, F("Unknown Font ID %s"), attr_p); + return; } } /* Pattern attributes */ case ATTR_PATTERN_REPEAT: - return attribute_pattern_repeat(obj, part, state, update, attr_p, hasp_util_is_true(payload)); + return attribute_pattern_repeat(obj, part, state, update, attr_p, Utilities::is_true(payload)); case ATTR_PATTERN_OPA: return attribute_pattern_opa(obj, part, state, update, attr_p, (lv_opa_t)var); case ATTR_PATTERN_RECOLOR_OPA: @@ -1081,7 +1037,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t case ATTR_PATTERN_RECOLOR: { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_obj_set_style_local_pattern_recolor(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { @@ -1099,7 +1055,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t /* Transition attributes */ // Todo } - LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_UNKNOWN), attr_p); + LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_UNKNOWN " (%d)"), attr_p, attr_hash); } static void hasp_process_arc_attribute(lv_obj_t * obj, const char * attr_p, uint16_t attr_hash, const char * payload, @@ -1121,7 +1077,7 @@ static void hasp_process_arc_attribute(lv_obj_t * obj, const char * attr_p, uint case ATTR_ADJUSTABLE: if(update) { - bool toggle = hasp_util_is_true(payload); + bool toggle = Utilities::is_true(payload); lv_arc_set_adjustable(obj, toggle); lv_obj_set_event_cb(obj, toggle ? slider_event_handler : generic_event_handler); } else { @@ -1259,7 +1215,7 @@ static void hasp_process_obj_attribute_txt(lv_obj_t * obj, const char * attr, co if(check_obj_type(obj, LV_HASP_CHECKBOX)) { return update ? lv_checkbox_set_text(obj, payload) : hasp_out_str(obj, attr, lv_checkbox_get_text(obj)); } - if(check_obj_type(obj, LV_HASP_DDLIST)) { + if(check_obj_type(obj, LV_HASP_DROPDOWN)) { char buffer[128]; lv_dropdown_get_selected_str(obj, buffer, sizeof(buffer)); return hasp_out_str(obj, attr, buffer); @@ -1297,14 +1253,14 @@ bool hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, const cha return false; // not checkable } } else if(check_obj_type(obj, LV_HASP_CHECKBOX)) { - update ? lv_checkbox_set_checked(obj, hasp_util_is_true(payload)) + update ? lv_checkbox_set_checked(obj, Utilities::is_true(payload)) : hasp_out_int(obj, attr, lv_checkbox_is_checked(obj)); } else if(check_obj_type(obj, LV_HASP_SWITCH)) { if(update) - hasp_util_is_true(payload) ? lv_switch_on(obj, LV_ANIM_ON) : lv_switch_off(obj, LV_ANIM_ON); + Utilities::is_true(payload) ? lv_switch_on(obj, LV_ANIM_ON) : lv_switch_off(obj, LV_ANIM_ON); else hasp_out_int(obj, attr, lv_switch_get_state(obj)); - } else if(check_obj_type(obj, LV_HASP_DDLIST)) { + } else if(check_obj_type(obj, LV_HASP_DROPDOWN)) { lv_dropdown_set_selected(obj, (uint16_t)intval); } else if(check_obj_type(obj, LV_HASP_LMETER)) { update ? lv_linemeter_set_value(obj, intval) : hasp_out_int(obj, attr, lv_linemeter_get_value(obj)); @@ -1402,13 +1358,16 @@ static void hasp_process_obj_attribute_range(lv_obj_t * obj, const char * attr, void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char * payload, bool update) { // unsigned long start = millis(); - if(!obj) return LOG_WARNING(TAG_ATTR, F(D_OBJECT_UNKNOWN)); + if(!obj) { + LOG_WARNING(TAG_ATTR, F(D_OBJECT_UNKNOWN)); + return; + } int16_t val = atoi(payload); char * attr = (char *)attr_p; if(*attr == '.') attr++; // strip leading '.' - uint16_t attr_hash = hasp_util_get_sdbm(attr); + uint16_t attr_hash = Utilities::get_sdbm(attr); // LOG_VERBOSE(TAG_ATTR,"%s => %d", attr, attr_hash); /* 16-bit Hash Lookup Table */ @@ -1466,12 +1425,12 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char break; // attribute_found case ATTR_VIS: - update ? lv_obj_set_hidden(obj, !hasp_util_is_true(payload)) + update ? lv_obj_set_hidden(obj, !Utilities::is_true(payload)) : hasp_out_int(obj, attr, !lv_obj_get_hidden(obj)); break; // attribute_found case ATTR_HIDDEN: - update ? lv_obj_set_hidden(obj, hasp_util_is_true(payload)) + update ? lv_obj_set_hidden(obj, Utilities::is_true(payload)) : hasp_out_int(obj, attr, lv_obj_get_hidden(obj)); break; // attribute_found @@ -1484,7 +1443,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char if(check_obj_type(obj, LV_HASP_CPICKER)) { if(update) { lv_color32_t c; - if(haspPayloadToColor(payload, c)) + if(Parser::haspPayloadToColor(payload, c)) lv_cpicker_set_color(obj, lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); } else { hasp_out_color(obj, attr, lv_cpicker_get_color(obj)); @@ -1512,7 +1471,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char break; // attribute_found case ATTR_ENABLED: - update ? lv_obj_set_click(obj, hasp_util_is_true(payload)) : hasp_out_int(obj, attr, lv_obj_get_click(obj)); + update ? lv_obj_set_click(obj, Utilities::is_true(payload)) : hasp_out_int(obj, attr, lv_obj_get_click(obj)); break; // attribute_found case ATTR_SRC: @@ -1596,7 +1555,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char case ATTR_TOGGLE: if(check_obj_type(obj, LV_HASP_BUTTON)) { if(update) { - bool toggle = hasp_util_is_true(payload); + bool toggle = Utilities::is_true(payload); lv_btn_set_checkable(obj, toggle); lv_obj_set_event_cb(obj, toggle ? toggle_event_handler : generic_event_handler); } else { @@ -1608,7 +1567,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char break; // attribute_found case ATTR_OPTIONS: - if(check_obj_type(obj, LV_HASP_DDLIST)) { + if(check_obj_type(obj, LV_HASP_DROPDOWN)) { if(update) { lv_dropdown_set_options(obj, payload); } else { @@ -1673,21 +1632,24 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char case ATTR_DELETE: if(!lv_obj_get_parent(obj)) { - return LOG_ERROR(TAG_ATTR, F(D_ATTRIBUTE_PAGE_METHOD_INVALID), attr_p); + LOG_ERROR(TAG_ATTR, F(D_ATTRIBUTE_PAGE_METHOD_INVALID), attr_p); + return; } lv_obj_del_async(obj); break; // attribute_found case ATTR_TO_FRONT: if(!lv_obj_get_parent(obj)) { - return LOG_ERROR(TAG_ATTR, F(D_ATTRIBUTE_PAGE_METHOD_INVALID), attr_p); + LOG_ERROR(TAG_ATTR, F(D_ATTRIBUTE_PAGE_METHOD_INVALID), attr_p); + return; } lv_obj_move_foreground(obj); break; // attribute_found case ATTR_TO_BACK: if(!lv_obj_get_parent(obj)) { - return LOG_ERROR(TAG_ATTR, F(D_ATTRIBUTE_PAGE_METHOD_INVALID), attr_p); + LOG_ERROR(TAG_ATTR, F(D_ATTRIBUTE_PAGE_METHOD_INVALID), attr_p); + return; } lv_obj_move_background(obj); break; // attribute_found From c1ec46d708125e4f8227f31b4aedd76d861c6eef Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:10:01 +0100 Subject: [PATCH 020/236] Add parser and margin attributes --- src/hasp/hasp_attribute.h | 80 +++++---------------------------------- 1 file changed, 10 insertions(+), 70 deletions(-) diff --git a/src/hasp/hasp_attribute.h b/src/hasp/hasp_attribute.h index c7381fc4..7273cd21 100644 --- a/src/hasp/hasp_attribute.h +++ b/src/hasp/hasp_attribute.h @@ -27,8 +27,6 @@ void line_clear_points(lv_obj_t * obj); void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char * payload, bool update); bool hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, const char * payload, bool update); -bool haspPayloadToColor(const char * payload, lv_color32_t & color); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -57,6 +55,10 @@ _HASP_ATTRIBUTE(SIZE, size, lv_style_int_t) _HASP_ATTRIBUTE(TRANSFORM_WIDTH, transform_width, lv_style_int_t) _HASP_ATTRIBUTE(TRANSFORM_HEIGHT, transform_height, lv_style_int_t) _HASP_ATTRIBUTE(OPA_SCALE, opa_scale, lv_opa_t) +_HASP_ATTRIBUTE(MARGIN_TOP, margin_top, lv_style_int_t) +_HASP_ATTRIBUTE(MARGIN_BOTTOM, margin_bottom, lv_style_int_t) +_HASP_ATTRIBUTE(MARGIN_LEFT, margin_left, lv_style_int_t) +_HASP_ATTRIBUTE(MARGIN_RIGHT, margin_right, lv_style_int_t) _HASP_ATTRIBUTE(PAD_TOP, pad_top, lv_style_int_t) _HASP_ATTRIBUTE(PAD_BOTTOM, pad_bottom, lv_style_int_t) _HASP_ATTRIBUTE(PAD_LEFT, pad_left, lv_style_int_t) @@ -162,6 +164,12 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t) #define ATTR_BG_BLEND_MODE 31147 #define ATTR_BG_GRAD_COLOR 44140 +/* Margin Attributes */ +#define ATTR_MARGIN_TOP 7812 +#define ATTR_MARGIN_LEFT 24440 +#define ATTR_MARGIN_BOTTOM 37692 +#define ATTR_MARGIN_RIGHT 2187 + /* Padding Attributes */ #define ATTR_PAD_TOP 59081 #define ATTR_PAD_LEFT 43123 @@ -307,72 +315,4 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t) #define ATTR_GROUPID 48986 #define ATTR_OBJID 41010 -/* Named COLOR attributes */ -#define ATTR_RED 177 -#define ATTR_TAN 7873 -#define ATTR_AQUA 3452 -#define ATTR_BLUE 37050 -#define ATTR_CYAN 9763 -#define ATTR_GOLD 53440 -#define ATTR_GRAY 64675 -#define ATTR_GREY 64927 -#define ATTR_LIME 34741 -#define ATTR_NAVY 44918 -#define ATTR_PERU 36344 -#define ATTR_PINK 51958 -#define ATTR_PLUM 64308 -#define ATTR_SNOW 35587 -#define ATTR_TEAL 52412 -#define ATTR_AZURE 44239 -#define ATTR_BEIGE 12132 -#define ATTR_BLACK 26527 -#define ATTR_BLUSH 41376 -#define ATTR_BROWN 10774 -#define ATTR_CORAL 16369 -#define ATTR_GREEN 26019 -#define ATTR_IVORY 1257 -#define ATTR_KHAKI 32162 -#define ATTR_LINEN 30074 -#define ATTR_OLIVE 47963 -#define ATTR_WHEAT 11591 -#define ATTR_WHITE 28649 -#define ATTR_BISQUE 60533 -#define ATTR_INDIGO 46482 -#define ATTR_MAROON 12528 -#define ATTR_ORANGE 21582 -#define ATTR_ORCHID 39235 -#define ATTR_PURPLE 53116 -#define ATTR_SALMON 29934 -#define ATTR_SIENNA 50930 -#define ATTR_SILVER 62989 -#define ATTR_TOMATO 8234 -#define ATTR_VIOLET 61695 -#define ATTR_YELLOW 10484 -#define ATTR_FUCHSIA 5463 -#define ATTR_MAGENTA 49385 - -struct hasp_color_t -{ - uint16_t hash; - uint8_t r, g, b; -}; - -/* Named COLOR lookup table */ -const hasp_color_t haspNamedColors[] PROGMEM = { - {ATTR_RED, 0xFF, 0x00, 0x00}, {ATTR_TAN, 0xD2, 0xB4, 0x8C}, {ATTR_AQUA, 0x00, 0xFF, 0xFF}, - {ATTR_BLUE, 0x00, 0x00, 0xFF}, {ATTR_CYAN, 0x00, 0xFF, 0xFF}, {ATTR_GOLD, 0xFF, 0xD7, 0x00}, - {ATTR_GRAY, 0x80, 0x80, 0x80}, {ATTR_GREY, 0x80, 0x80, 0x80}, {ATTR_LIME, 0x00, 0xFF, 0x00}, - {ATTR_NAVY, 0x00, 0x00, 0x80}, {ATTR_PERU, 0xCD, 0x85, 0x3F}, {ATTR_PINK, 0xFF, 0xC0, 0xCB}, - {ATTR_PLUM, 0xDD, 0xA0, 0xDD}, {ATTR_SNOW, 0xFF, 0xFA, 0xFA}, {ATTR_TEAL, 0x00, 0x80, 0x80}, - {ATTR_AZURE, 0xF0, 0xFF, 0xFF}, {ATTR_BEIGE, 0xF5, 0xF5, 0xDC}, {ATTR_BLACK, 0x00, 0x00, 0x00}, - {ATTR_BLUSH, 0xB0, 0x00, 0x00}, {ATTR_BROWN, 0xA5, 0x2A, 0x2A}, {ATTR_CORAL, 0xFF, 0x7F, 0x50}, - {ATTR_GREEN, 0x00, 0x80, 0x00}, {ATTR_IVORY, 0xFF, 0xFF, 0xF0}, {ATTR_KHAKI, 0xF0, 0xE6, 0x8C}, - {ATTR_LINEN, 0xFA, 0xF0, 0xE6}, {ATTR_OLIVE, 0x80, 0x80, 0x00}, {ATTR_WHEAT, 0xF5, 0xDE, 0xB3}, - {ATTR_WHITE, 0xFF, 0xFF, 0xFF}, {ATTR_BISQUE, 0xFF, 0xE4, 0xC4}, {ATTR_INDIGO, 0x4B, 0x00, 0x82}, - {ATTR_MAROON, 0x80, 0x00, 0x00}, {ATTR_ORANGE, 0xFF, 0xA5, 0x00}, {ATTR_ORCHID, 0xDA, 0x70, 0xD6}, - {ATTR_PURPLE, 0x80, 0x00, 0x80}, {ATTR_SALMON, 0xFA, 0x80, 0x72}, {ATTR_SIENNA, 0xA0, 0x52, 0x2D}, - {ATTR_SILVER, 0xC0, 0xC0, 0xC0}, {ATTR_TOMATO, 0xFF, 0x63, 0x47}, {ATTR_VIOLET, 0xEE, 0x82, 0xEE}, - {ATTR_YELLOW, 0xFF, 0xFF, 0x00}, {ATTR_FUCHSIA, 0xFF, 0x00, 0xFF}, {ATTR_MAGENTA, 0xFF, 0x00, 0xFF}, -}; - #endif From 63ccab10fa041616e205984b02bf4fc6dc314ee2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:11:22 +0100 Subject: [PATCH 021/236] Xplatform changes and fix some object types --- src/hasp/hasp_object.cpp | 79 +++++++++++++++++++++++++++------------- src/hasp/hasp_object.h | 30 +++++++-------- 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 82a25a0d..9b300088 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -13,7 +13,9 @@ * ******************************************************************************************** */ -#include "ArduinoLog.h" +#ifdef ARDUINO + #include "ArduinoLog.h" +#endif #include "lvgl.h" #if LVGL_VERSION_MAJOR != 7 @@ -25,6 +27,7 @@ #include "hasp_dispatch.h" #include "hasp_attribute.h" #include "hasp_utilities.h" +#include "hasp_parser.h" const char ** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map // static unsigned long last_change_event = 0; @@ -102,11 +105,11 @@ bool hasp_find_id_from_obj(lv_obj_t * obj, uint8_t * pageid, uint8_t * objid) // return (strcmp_P(lvobjtype, PSTR("label")) == 0); // case LV_HASP_CHECKBOX: // return (strcmp_P(lvobjtype, PSTR("checkbox")) == 0); // || (strcmp_P(lvobjtype, PSTR("lv_cb")) == 0); -// case LV_HASP_DDLIST: +// case LV_HASP_DROPDOWN: // return (strcmp_P(lvobjtype, PSTR("dropdown")) == 0); // || (strcmp_P(lvobjtype, PSTR("lv_ddlist")) == 0); // case LV_HASP_CPICKER: // return (strcmp_P(lvobjtype, PSTR("cpicker")) == 0); -// case LV_HASP_PRELOADER: +// case LV_HASP_SPINNER: // return (strcmp_P(lvobjtype, PSTR("spinner")) == 0); // || (strcmp_P(lvobjtype, PSTR("lv_preload")) == 0); // case LV_HASP_SLIDER: // return (strcmp_P(lvobjtype, PSTR("slider")) == 0); @@ -412,7 +415,7 @@ static void selector_event_handler(lv_obj_t * obj, lv_event_t event) hasp_update_sleep_state(); // wakeup? switch(obj->user_data.objid) { - case LV_HASP_DDLIST: + case LV_HASP_DROPDOWN: val = lv_dropdown_get_selected(obj); max = lv_dropdown_get_option_cnt(obj) - 1; lv_dropdown_get_selected_str(obj, buffer, sizeof(buffer)); @@ -596,6 +599,35 @@ void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, co // ##################### Object Creator ######################################################## +int hasp_parse_json_attributes(lv_obj_t * obj, const JsonObject & doc) +{ + int i = 0; +#ifdef WINDOWS + // String v((char *)0); + // v.reserve(64); + std::string v; + + for(JsonPair keyValue : doc) { + LOG_VERBOSE(TAG_HASP, F(" * %s => %s"), keyValue.key().c_str(), keyValue.value().as().c_str()); + v = keyValue.value().as(); + hasp_process_obj_attribute(obj, keyValue.key().c_str(), keyValue.value().as().c_str(), true); + i++; + } +#else + String v((char *)0); + v.reserve(64); + + for(JsonPair keyValue : doc) { + LOG_VERBOSE(TAG_HASP, F(" * %s => %s"), keyValue.key().c_str(), keyValue.value().as().c_str()); + v = keyValue.value().as(); + hasp_process_obj_attribute(obj, keyValue.key().c_str(), keyValue.value().as().c_str(), true); + i++; + } +#endif + LOG_VERBOSE(TAG_HASP, F("%d attributes processed"), i); + return i; +} + /** * Create a new object according to the json config * @param config Json representation for this object @@ -608,7 +640,8 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) uint8_t pageid = config[FPSTR(FP_PAGE)].isNull() ? saved_page_id : config[FPSTR(FP_PAGE)].as(); lv_obj_t * parent_obj = get_page_obj(pageid); if(!parent_obj) { - return LOG_WARNING(TAG_HASP, F(D_OBJECT_PAGE_UNKNOWN), pageid); + LOG_WARNING(TAG_HASP, F(D_OBJECT_PAGE_UNKNOWN), pageid); + return; } else { saved_page_id = pageid; /* save the current pageid */ } @@ -618,8 +651,8 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) uint8_t parentid = config[FPSTR(FP_PARENTID)].as(); parent_obj = hasp_find_obj_from_parent_id(parent_obj, parentid); if(!parent_obj) { - return LOG_WARNING(TAG_HASP, F("Parent ID " HASP_OBJECT_NOTATION " not found, skipping..."), pageid, - parentid); + LOG_WARNING(TAG_HASP, F("Parent ID " HASP_OBJECT_NOTATION " not found, skipping..."), pageid, parentid); + return; } else { LOG_VERBOSE(TAG_HASP, F("Parent ID " HASP_OBJECT_NOTATION " found"), pageid, parentid); } @@ -640,7 +673,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) if(config[FPSTR(FP_OBJ)].isNull()) { return; // comments } else { - sdbm = hasp_util_get_sdbm(config[FPSTR(FP_OBJ)].as().c_str()); + sdbm = Utilities::get_sdbm(config[FPSTR(FP_OBJ)].as()); } } else { sdbm = config[FPSTR(FP_OBJID)].as(); @@ -687,7 +720,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) break; case LV_HASP_CHECKBOX: - case HASP_OBJ_CB: + case HASP_OBJ_CHECKBOX: obj = lv_checkbox_create(parent_obj, NULL); if(obj) { lv_obj_set_event_cb(obj, toggle_event_handler); @@ -839,11 +872,11 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) } break; -#if LV_USE_PRELOAD != 0 - case LV_HASP_PRELOADER: +#if LV_USE_SPINNER != 0 + case LV_HASP_SPINNER: case HASP_OBJ_SPINNER: obj = lv_spinner_create(parent_obj, NULL); - if(obj) obj->user_data.objid = LV_HASP_PRELOADER; + if(obj) obj->user_data.objid = LV_HASP_SPINNER; break; #endif @@ -922,7 +955,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) break; /* ----- List Object ------- */ - case LV_HASP_DDLIST: + case LV_HASP_DROPDOWN: case HASP_OBJ_DROPDOWN: obj = lv_dropdown_create(parent_obj, NULL); if(obj) { @@ -931,7 +964,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) lv_obj_set_top(obj, true); // lv_obj_align(obj, NULL, LV_ALIGN_IN_TOP_MID, 0, 20); lv_obj_set_event_cb(obj, selector_event_handler); - obj->user_data.objid = LV_HASP_DDLIST; + obj->user_data.objid = LV_HASP_DROPDOWN; } break; @@ -953,7 +986,8 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) /* No object was actually created */ if(!obj) { - return LOG_ERROR(TAG_HASP, F(D_OBJECT_CREATE_FAILED), id); + LOG_ERROR(TAG_HASP, F(D_OBJECT_CREATE_FAILED), id); + return; } // Prevent losing press when the press is slid out of the objects. @@ -968,7 +1002,8 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) /** testing start **/ uint8_t temp; if(!hasp_find_id_from_obj(obj, &pageid, &temp)) { - return LOG_ERROR(TAG_HASP, F(D_OBJECT_LOST)); + LOG_ERROR(TAG_HASP, F(D_OBJECT_LOST)); + return; } /** verbose reporting **/ @@ -979,7 +1014,8 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) /* test double-check */ lv_obj_t * test = hasp_find_obj_from_parent_id(get_page_obj(pageid), (uint8_t)temp); if(test != obj) { - return LOG_ERROR(TAG_HASP, F(D_OBJECT_MISMATCH)); + LOG_ERROR(TAG_HASP, F(D_OBJECT_MISMATCH)); + return; } } @@ -990,14 +1026,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) config.remove(FPSTR(FP_OBJID)); // TODO: obsolete objid config.remove(FPSTR(FP_PARENTID)); - String v((char *)0); - v.reserve(64); - - for(JsonPair keyValue : config) { - v = keyValue.value().as(); - hasp_process_obj_attribute(obj, keyValue.key().c_str(), v.c_str(), true); - // LOG_VERBOSE(TAG_HASP,F(" * %s => %s"), keyValue.key().c_str(), v.c_str()); - } + hasp_parse_json_attributes(obj, config); } void hasp_object_delete(lv_obj_t * obj) diff --git a/src/hasp/hasp_object.h b/src/hasp/hasp_object.h index 9ef17688..012e4782 100644 --- a/src/hasp/hasp_object.h +++ b/src/hasp/hasp_object.h @@ -7,12 +7,12 @@ #include #include "lvgl.h" -const char FP_PAGE[] PROGMEM = "page"; -const char FP_ID[] PROGMEM = "id"; -const char FP_OBJ[] PROGMEM = "obj"; -const char FP_OBJID[] PROGMEM = "objid"; +const char FP_PAGE[] PROGMEM = "page"; +const char FP_ID[] PROGMEM = "id"; +const char FP_OBJ[] PROGMEM = "obj"; +const char FP_OBJID[] PROGMEM = "objid"; const char FP_PARENTID[] PROGMEM = "parentid"; -const char FP_GROUPID[] PROGMEM = "groupid"; +const char FP_GROUPID[] PROGMEM = "groupid"; enum lv_hasp_obj_type_t { /* Controls */ @@ -28,7 +28,7 @@ enum lv_hasp_obj_type_t { LV_HASP_CPICKER = 20, /* Selectors */ - LV_HASP_DDLIST = 50, + LV_HASP_DROPDOWN = 50, LV_HASP_ROLLER = 51, LV_HASP_LIST = 52, // placeholder LV_HASP_TABLE = 53, @@ -44,14 +44,14 @@ enum lv_hasp_obj_type_t { LV_HASP_PAGE = 79, // Obsolete in v8 /* Visualizers */ - LV_HASP_LABEL = 12, // 30 - LV_HASP_GAUGE = 31, - LV_HASP_BAR = 32, - LV_HASP_LMETER = 33, - LV_HASP_LED = 41, // 34 - LV_HASP_ARC = 22, // 35 - LV_HASP_PRELOADER = 21, // 36 - LV_HASP_CHART = 37, + LV_HASP_LABEL = 12, // 30 + LV_HASP_GAUGE = 31, + LV_HASP_BAR = 32, + LV_HASP_LMETER = 33, + LV_HASP_LED = 41, // 34 + LV_HASP_ARC = 22, // 35 + LV_HASP_SPINNER = 21, // 36 + LV_HASP_CHART = 37, /* Graphics */ LV_HASP_LINE = 60, @@ -85,7 +85,7 @@ void wakeup_event_handler(lv_obj_t * obj, lv_event_t event); #define HASP_OBJ_BAR 1971 #define HASP_OBJ_BTN 3164 #define HASP_OBJ_CPICKER 3313 -#define HASP_OBJ_CB 6335 +#define HASP_OBJ_CHECKBOX 1923 #define HASP_OBJ_SPINNER 7097 #define HASP_OBJ_MSGBOX 7498 #define HASP_OBJ_TABLE 12078 From 367458469b832d2cf0adfcebae850b06486b2f28 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:12:38 +0100 Subject: [PATCH 022/236] Xplatform changes --- include/hasp_conf.h | 46 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/include/hasp_conf.h b/include/hasp_conf.h index c0e2f847..215c673d 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -222,36 +222,34 @@ static WiFiSpiClass WiFi; #include "svc/hasp_slave.h" #endif -#ifndef FPSTR - #define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) -#endif +#ifdef WINDOWS + #ifndef FPSTR + #define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) + #endif -#ifndef PGM_P - #define PGM_P const char * -#endif + #ifndef __FlashStringHelper + #define __FlashStringHelper char + #endif -#ifndef __FlashStringHelper - #define __FlashStringHelper char -#endif + #ifndef FPSTR + #define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) + #endif -#ifndef FPSTR - #define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) -#endif + #ifndef PGM_P + #define PGM_P const char * + #endif -#ifndef PGM_P - #define PGM_P const char * -#endif + #ifndef F + #define F(x) (x) + #endif -#ifndef F - #define F(x) (x) -#endif + #ifndef PSTR + #define PSTR(x) x + #endif -#ifndef PSTR - #define PSTR(x) x -#endif - -#ifndef PROGMEM - #define PROGMEM + #ifndef PROGMEM + #define PROGMEM + #endif #endif #ifdef WINDOWS From 19a1ce5eb03d13038b076dc8a8fcea765275cc4c Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:16:38 +0100 Subject: [PATCH 023/236] Xplatform changes and add settings struct --- src/hasp/hasp_dispatch.cpp | 153 ++++++++++++++++++++++++------------- src/hasp/hasp_dispatch.h | 12 ++- src/hasp_gui.cpp | 117 +++++++++++++++------------- src/hasp_gui.h | 11 ++- 4 files changed, 186 insertions(+), 107 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index e308d5f6..22927d7c 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -1,47 +1,59 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#include "ArduinoLog.h" +#include + +//#include "ArduinoLog.h" #include "hasp_conf.h" #include "hasp_dispatch.h" #include "hasp_object.h" #include "hasp.h" #include "hasp_utilities.h" +#include "hasp_parser.h" #include "hasp_attribute.h" +//#include "hasp_gui.h" + #if HASP_USE_DEBUG > 0 - #include "StringStream.h" - #include "CharStream.h" + #include "../hasp_debug.h" - #include "hasp_debug.h" - #include "hasp_gui.h" - #include "hasp_oobe.h" - #include "hasp_gpio.h" - #include "hasp_hal.h" + #if WINDOWS + #include + #include + #include + #include "../mqtt/hasp_mqtt.h" + #else + #include "StringStream.h" + #include "CharStream.h" - #include "svc/hasp_ota.h" - #include "svc/hasp_mqtt.h" - #include "net/hasp_network.h" // for network_get_status() -#else - #include - #include + #include "hasp_oobe.h" + #include "hasp_gui.h" // for screenshot + #include "sys/gpio/hasp_gpio.h" + #include "hal/hasp_hal.h" + + #include "svc/hasp_ota.h" + #include "mqtt/hasp_mqtt.h" + #include "sys/net/hasp_network.h" // for network_get_status() + #endif #endif #if HASP_USE_CONFIG > 0 #include "hasp_config.h" #endif -extern unsigned long debugLastMillis; // UpdateStatus timer extern uint8_t hasp_sleep_state; +dispatch_conf_t dispatch_setings = {.teleperiod = 300}; + +uint32_t dispatchLastMillis; uint8_t nCommands = 0; haspCommand_t commands[17]; struct moodlight_t { - byte power; - byte r, g, b; + uint8_t power; + uint8_t r, g, b; }; moodlight_t moodlight; @@ -599,7 +611,9 @@ void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t * { if(groupid > 0) { LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d"), groupid, value); +#if USE_GPIO gpio_set_normalized_group_value(groupid, value); +#endif // object_set_group_state(groupid, value, obj); } } @@ -627,11 +641,11 @@ void dispatch_parse_json(const char *, const char * payload) } else if(json.is()) { // handle json as an array of commands JsonArray arr = json.as(); - guiStop(); + // guiStop(); for(JsonVariant command : arr) { - dispatch_text_line(command.as().c_str()); + dispatch_text_line(command.as()); } - guiStart(); + // guiStart(); } else if(json.is()) { // handle json as a jsonl uint8_t savedPage = haspGetPage(); hasp_new_object(json.as(), savedPage); @@ -642,15 +656,15 @@ void dispatch_parse_json(const char *, const char * payload) } else if(json.is()) { // handle json as a single command dispatch_text_line(json.as()); - } else if(json.is()) { // handle json as a single command - dispatch_text_line(json.as().c_str()); + // } else if(json.is()) { // handle json as a single command + // dispatch_text_line(json.as().c_str()); } else { LOG_WARNING(TAG_MSGR, F(D_DISPATCH_COMMAND_NOT_FOUND), payload); } } -#if HASP_USE_CONFIG > 0 +#ifdef ARDUINO void dispatch_parse_jsonl(Stream & stream) #else void dispatch_parse_jsonl(std::istringstream & stream) @@ -660,7 +674,10 @@ void dispatch_parse_jsonl(std::istringstream & stream) size_t line = 1; DynamicJsonDocument jsonl(MQTT_MAX_PACKET_SIZE / 2 + 128); // max ~256 characters per line DeserializationError jsonError = deserializeJson(jsonl, stream); + +#ifdef ARDUINO stream.setTimeout(25); +#endif // guiStop(); while(jsonError == DeserializationError::Ok) { @@ -703,7 +720,7 @@ void dispatch_output_current_page() void dispatch_page(const char *, const char * page) { if(strlen(page) > 0) { - if(hasp_util_is_only_digits(page)) { + if(Utilities::is_only_digits(page)) { uint8_t pageid = atoi(page); haspSetPage(pageid); } else { @@ -781,7 +798,7 @@ void dispatch_moodlight(const char * topic, const char * payload) dispatch_json_error(TAG_MSGR, jsonError); } else { - if(!json[F("power")].isNull()) moodlight.power = hasp_util_is_true(json[F("power")].as().c_str()); + if(!json[F("power")].isNull()) moodlight.power = Utilities::is_true(json[F("power")].as()); if(!json[F("r")].isNull()) moodlight.r = json[F("r")].as(); if(!json[F("g")].isNull()) moodlight.r = json[F("g")].as(); @@ -789,17 +806,19 @@ void dispatch_moodlight(const char * topic, const char * payload) if(!json[F("color")].isNull()) { lv_color32_t color; - if(haspPayloadToColor(json[F("color")].as().c_str(), color)) { + if(Parser::haspPayloadToColor(json[F("color")].as(), color)) { moodlight.r = color.ch.red; moodlight.g = color.ch.green; moodlight.b = color.ch.blue; } } +#ifdef USE_GPIO if(moodlight.power) gpio_set_moodlight(moodlight.r, moodlight.g, moodlight.b); else gpio_set_moodlight(0, 0, 0); +#endif } } @@ -814,7 +833,7 @@ void dispatch_moodlight(const char * topic, const char * payload) void dispatch_backlight(const char *, const char * payload) { // Set the current state - if(strlen(payload) != 0) guiSetBacklight(hasp_util_is_true(payload)); + if(strlen(payload) != 0) guiSetBacklight(Utilities::is_true(payload)); // Return the current state char buffer[4]; @@ -834,9 +853,9 @@ void dispatch_web_update(const char *, const char * espOtaUrl) void dispatch_reboot(bool saveConfig) { #if HASP_USE_CONFIG > 0 - if(saveConfig) configWriteConfig(); + if(saveConfig) configWrite(); #endif -#if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 && defined(ARDUINO) mqttStop(); // Stop the MQTT Client first #endif #if HASP_USE_CONFIG > 0 @@ -847,7 +866,13 @@ void dispatch_reboot(bool saveConfig) #endif LOG_VERBOSE(TAG_MSGR, F("-------------------------------------")); LOG_TRACE(TAG_MSGR, F(D_DISPATCH_REBOOT)); + +#if WINDOWS + fflush(stdout); +#else Serial.flush(); +#endif + halRestartMcu(); } @@ -869,33 +894,34 @@ void dispatch_output_statusupdate(const char *, const char *) { char buffer[128]; - haspGetVersion(buffer, sizeof(buffer)); - snprintf_P(data, sizeof(data), - PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), - mqttGetNodename().c_str(), buffer, long(millis() / 1000)); + /* haspGetVersion(buffer, sizeof(buffer)); + snprintf_P(data, sizeof(data), + PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), + mqttGetNodename().c_str(), buffer, long(millis() / 1000)); - #if HASP_USE_WIFI > 0 - network_get_statusupdate(buffer, sizeof(buffer)); - strcat(data, buffer); - #endif - snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","), - halGetFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str()); - strcat(data, buffer); - snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), - haspGetPage(), (HASP_NUM_PAGES)); - strcat(data, buffer); + #if HASP_USE_WIFI > 0 + network_get_statusupdate(buffer, sizeof(buffer)); + strcat(data, buffer); + #endif + snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","), + halGetFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str()); + strcat(data, buffer); + snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), + haspGetPage(), (HASP_NUM_PAGES)); + strcat(data, buffer); - #if defined(ARDUINO_ARCH_ESP8266) - snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000); - strcat(data, buffer); - #endif + #if defined(ARDUINO_ARCH_ESP8266) + snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000); + strcat(data, buffer); + #endif - snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), - halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); - strcat(data, buffer); + snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), + halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); + strcat(data, buffer); + */ } mqtt_send_state(F("statusupdate"), data); - debugLastMillis = millis(); + dispatchLastMillis = millis(); /* if(updateEspAvailable) { mqttStatusPayload += F("\"updateEspAvailable\":true,"); @@ -976,3 +1002,28 @@ void dispatchLoop() { // Not used } + +#if 1 || ARDUINO +void everySecond() +{ + if(dispatch_setings.teleperiod > 0 && (millis() - dispatchLastMillis) >= dispatch_setings.teleperiod * 1000) { + dispatchLastMillis = millis(); + dispatch_output_statusupdate(NULL, NULL); + } +} +#else + #include +std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); +void everySecond() +{ + if(dispatch_setings.teleperiod > 0) { + std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); + std::chrono::seconds elapsed = std::chrono::duration_cast(end - begin); + + if(elapsed.count() >= dispatch_setings.teleperiod) { + std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); + dispatch_output_statusupdate(NULL, NULL); + } + } +} +#endif \ No newline at end of file diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index b8a4c1b9..017d825a 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -7,6 +7,10 @@ #include "ArduinoJson.h" #include "lvgl.h" +struct dispatch_conf_t { + uint16_t teleperiod; +}; + enum hasp_event_t { // even = released, odd = pressed HASP_EVENT_OFF = 0, HASP_EVENT_ON = 1, @@ -30,7 +34,13 @@ void dispatchStop(void); /* ===== Special Event Processors ===== */ void dispatch_topic_payload(const char * topic, const char * payload); void dispatch_text_line(const char * cmnd); -void dispatch_parse_jsonl(Stream & stream); + +#ifdef ARDUINO +void dispatch_parse_jsonl(Stream &stream); +#else +void dispatch_parse_jsonl(std::istringstream &stream); +#endif + void dispatch_clear_page(const char * page); void dispatch_json_error(uint8_t tag, DeserializationError & jsonError); diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 6fd4af36..bbc1780b 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -51,14 +51,21 @@ File pFileOut; // static void IRAM_ATTR lv_tick_handler(void); -static bool guiShowPointer = false; -static bool guiBacklightIsOn = true; -static int8_t guiDimLevel = -1; -static int8_t guiBacklightPin = TFT_BCKL; -static uint8_t guiTickPeriod = 20; -static uint8_t guiRotation = TFT_ROTATION; -static uint8_t guiInvertDisplay = INVERT_COLORS; -static uint16_t calData[5] = {0, 65535, 0, 65535, 0}; +// static bool guiShowPointer = false; +// static int8_t guiBacklightPin = TFT_BCKL; +// static uint8_t guiTickPeriod = 20; +// static uint8_t guiRotation = TFT_ROTATION; +// static uint8_t guiInvertDisplay = INVERT_COLORS; +// static uint16_t calData[5] = {0, 65535, 0, 65535, 0}; + +gui_conf_t gui_settings = {.show_pointer = false, + .backlight_pin =TFT_BCKL, + .rotation = TFT_ROTATION, + .invert_display = INVERT_COLORS, + .cal_data = {0, 65535, 0, 65535, 0}}; + +static int8_t guiDimLevel = 100; +bool guiBacklightIsOn; // #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) // static Ticker tick; /* timer for interrupt handler */ @@ -197,7 +204,7 @@ boolean Touch_getXY(uint16_t * x, uint16_t * y, boolean showTouch) bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE); if(pressed) { - switch(guiRotation) { + switch(gui_settings.rotation) { case 0: // portrait *x = map(p.x, coords[0], coords[1], 0, tft.width()); *y = map(p.y, coords[2], coords[3], 0, tft.height()); @@ -225,11 +232,11 @@ void guiCalibrate() { #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 #ifdef TOUCH_CS - tft_espi_calibrate(calData); + tft_espi_calibrate(gui_settings.cal_data); #endif for(int i = 0; i < 5; i++) { - Serial.print(calData[i]); + Serial.print(gui_settings.cal_data[i]); if(i < 4) Serial.print(", "); } @@ -308,17 +315,17 @@ void guiSetup() #endif /* Setup Backlight Control Pin */ - if(guiBacklightPin >= 0) { - LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), guiBacklightPin); + if(gui_settings.backlight_pin >= 0) { + LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), gui_settings.backlight_pin); #if defined(ARDUINO_ARCH_ESP32) ledcSetup(BACKLIGHT_CHANNEL, 20000, 12); - ledcAttachPin(guiBacklightPin, BACKLIGHT_CHANNEL); + ledcAttachPin(gui_settings.backlight_pin, BACKLIGHT_CHANNEL); #elif defined(ARDUINO_ARCH_ESP8266) - pinMode(guiBacklightPin, OUTPUT); + pinMode(gui_settings.backlight_pin, OUTPUT); #endif } - LOG_VERBOSE(TAG_GUI, F("Rotation : %d"), guiRotation); + LOG_VERBOSE(TAG_GUI, F("Rotation : %d"), gui_settings.rotation); LOG_VERBOSE(TAG_LVGL, F("Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH, PSTR(LVGL_VERSION_INFO)); @@ -336,10 +343,12 @@ void guiSetup() /* Initialize the display driver */ lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); - drv_display_init(&disp_drv, guiRotation, guiInvertDisplay); // Set display driver callback & rotation + drv_display_init(&disp_drv, gui_settings.rotation, + gui_settings.invert_display); // Set display driver callback & rotation disp_drv.buffer = &disp_buf; - if(guiRotation == 0 || guiRotation == 2 || guiRotation == 4 || guiRotation == 6) { + if(gui_settings.rotation == 0 || gui_settings.rotation == 2 || gui_settings.rotation == 4 || + gui_settings.rotation == 6) { /* 1/3=Landscape or 0/2=Portrait orientation */ // Normal width & height disp_drv.hor_res = TFT_WIDTH; @@ -376,7 +385,7 @@ void guiSetup() mouse_indev->driver.type = LV_INDEV_TYPE_POINTER; /*Set a cursor for the mouse*/ - if(guiShowPointer) { + if(gui_settings.show_pointer) { // lv_obj_t * label = lv_label_create(lv_layer_sys(), NULL); // lv_label_set_text(label, "<"); // lv_indev_set_cursor(mouse_indev, label); // connect the object to the driver @@ -398,7 +407,7 @@ void guiSetup() #endif lv_indev_set_cursor(mouse_indev, cursor); /*Connect the image object to the driver*/ } - drv_touch_init(guiRotation); // Touch driver + drv_touch_init(gui_settings.rotation); // Touch driver // guiStart(); // Ticker } @@ -448,14 +457,14 @@ void guiSetBacklight(bool lighton) { guiBacklightIsOn = lighton; -if(!lighton) hasp_enable_wakeup_touch(); + if(!lighton) hasp_enable_wakeup_touch(); - if(guiBacklightPin >= 0) { + if(gui_settings.backlight_pin >= 0) { #if defined(ARDUINO_ARCH_ESP32) ledcWrite(BACKLIGHT_CHANNEL, lighton ? map(guiDimLevel, 0, 100, 0, 4095) : 0); // ledChannel and value #else - analogWrite(guiBacklightPin, lighton ? map(guiDimLevel, 0, 100, 0, 1023) : 0); + analogWrite(gui_settings.backlight_pin, lighton ? map(guiDimLevel, 0, 100, 0, 1023) : 0); #endif } else { @@ -465,7 +474,7 @@ if(!lighton) hasp_enable_wakeup_touch(); void guiSetDim(int8_t level) { - if(guiBacklightPin >= 0) { + if(gui_settings.backlight_pin >= 0) { guiDimLevel = level >= 0 ? level : 0; guiDimLevel = guiDimLevel <= 100 ? guiDimLevel : 100; @@ -473,7 +482,7 @@ void guiSetDim(int8_t level) #if defined(ARDUINO_ARCH_ESP32) ledcWrite(BACKLIGHT_CHANNEL, map(guiDimLevel, 0, 100, 0, 4095)); // ledChannel and value #else - analogWrite(guiBacklightPin, map(guiDimLevel, 0, 100, 0, 1023)); + analogWrite(gui_settings.backlight_pin, map(guiDimLevel, 0, 100, 0, 1023)); #endif } @@ -496,8 +505,8 @@ bool guiGetConfig(const JsonObject & settings) uint16_t guiSleepTime2; hasp_get_sleep_time(guiSleepTime1, guiSleepTime2); - if(guiTickPeriod != settings[FPSTR(FP_GUI_TICKPERIOD)].as()) changed = true; - settings[FPSTR(FP_GUI_TICKPERIOD)] = guiTickPeriod; + // if(guiTickPeriod != settings[FPSTR(FP_GUI_TICKPERIOD)].as()) changed = true; + // settings[FPSTR(FP_GUI_TICKPERIOD)] = guiTickPeriod; if(guiSleepTime1 != settings[FPSTR(FP_GUI_IDLEPERIOD1)].as()) changed = true; settings[FPSTR(FP_GUI_IDLEPERIOD1)] = guiSleepTime1; @@ -505,31 +514,31 @@ bool guiGetConfig(const JsonObject & settings) if(guiSleepTime2 != settings[FPSTR(FP_GUI_IDLEPERIOD2)].as()) changed = true; settings[FPSTR(FP_GUI_IDLEPERIOD2)] = guiSleepTime2; - if(guiBacklightPin != settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as()) changed = true; - settings[FPSTR(FP_GUI_BACKLIGHTPIN)] = guiBacklightPin; + if(gui_settings.backlight_pin != settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as()) changed = true; + settings[FPSTR(FP_GUI_BACKLIGHTPIN)] = gui_settings.backlight_pin; - if(guiRotation != settings[FPSTR(FP_GUI_ROTATION)].as()) changed = true; - settings[FPSTR(FP_GUI_ROTATION)] = guiRotation; + if(gui_settings.rotation != settings[FPSTR(FP_GUI_ROTATION)].as()) changed = true; + settings[FPSTR(FP_GUI_ROTATION)] = gui_settings.rotation; - if(guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as()) changed = true; - settings[FPSTR(FP_GUI_POINTER)] = guiShowPointer; + if(gui_settings.show_pointer != settings[FPSTR(FP_GUI_POINTER)].as()) changed = true; + settings[FPSTR(FP_GUI_POINTER)] = gui_settings.show_pointer; - if(guiInvertDisplay != settings[FPSTR(FP_GUI_INVERT)].as()) changed = true; - settings[FPSTR(FP_GUI_INVERT)] = guiInvertDisplay; + if(gui_settings.invert_display != settings[FPSTR(FP_GUI_INVERT)].as()) changed = true; + settings[FPSTR(FP_GUI_INVERT)] = gui_settings.invert_display; /* Check CalData array has changed */ JsonArray array = settings[FPSTR(FP_GUI_CALIBRATION)].as(); uint8_t i = 0; for(JsonVariant v : array) { - LOG_VERBOSE(TAG_GUI, F("GUI CONF: %d: %d <=> %d"), i, calData[i], v.as()); + LOG_VERBOSE(TAG_GUI, F("GUI CONF: %d: %d <=> %d"), i, gui_settings.cal_data[i], v.as()); if(i < 5) { - if(calData[i] != v.as()) changed = true; - v.set(calData[i]); + if(gui_settings.cal_data[i] != v.as()) changed = true; + v.set(gui_settings.cal_data[i]); } else { changed = true; #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) - tft_espi_set_touch(calData); + tft_espi_set_touch(gui_settings.cal_data); #endif } i++; @@ -539,12 +548,12 @@ bool guiGetConfig(const JsonObject & settings) if(i != 5) { array = settings[FPSTR(FP_GUI_CALIBRATION)].to(); // Clear JsonArray for(int i = 0; i < 5; i++) { - array.add(calData[i]); + array.add(gui_settings.cal_data[i]); } changed = true; #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) - tft_espi_set_touch(calData); + tft_espi_set_touch(gui_settings.cal_data); #endif } @@ -569,22 +578,22 @@ bool guiSetConfig(const JsonObject & settings) hasp_get_sleep_time(guiSleepTime1, guiSleepTime2); - changed |= configSet(guiTickPeriod, settings[FPSTR(FP_GUI_TICKPERIOD)], F("guiTickPeriod")); - changed |= configSet(guiBacklightPin, settings[FPSTR(FP_GUI_BACKLIGHTPIN)], F("guiBacklightPin")); + // changed |= configSet(guiTickPeriod, settings[FPSTR(FP_GUI_TICKPERIOD)], F("guiTickPeriod")); + changed |= configSet(gui_settings.backlight_pin, settings[FPSTR(FP_GUI_BACKLIGHTPIN)], F("guiBacklightPin")); changed |= configSet(guiSleepTime1, settings[FPSTR(FP_GUI_IDLEPERIOD1)], F("guiSleepTime1")); changed |= configSet(guiSleepTime2, settings[FPSTR(FP_GUI_IDLEPERIOD2)], F("guiSleepTime2")); - changed |= configSet(guiRotation, settings[FPSTR(FP_GUI_ROTATION)], F("guiRotation")); - changed |= configSet(guiInvertDisplay, settings[FPSTR(FP_GUI_INVERT)], F("guiInvertDisplay")); + changed |= configSet(gui_settings.rotation, settings[FPSTR(FP_GUI_ROTATION)], F("gui_settings.rotation")); + changed |= configSet(gui_settings.invert_display, settings[FPSTR(FP_GUI_INVERT)], F("guiInvertDisplay")); hasp_set_sleep_time(guiSleepTime1, guiSleepTime2); if(!settings[FPSTR(FP_GUI_POINTER)].isNull()) { - if(guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as()) { + if(gui_settings.show_pointer != settings[FPSTR(FP_GUI_POINTER)].as()) { LOG_VERBOSE(TAG_GUI, F("guiShowPointer set")); } - changed |= guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as(); + changed |= gui_settings.show_pointer != settings[FPSTR(FP_GUI_POINTER)].as(); - guiShowPointer = settings[FPSTR(FP_GUI_POINTER)].as(); + gui_settings.show_pointer = settings[FPSTR(FP_GUI_POINTER)].as(); } if(!settings[FPSTR(FP_GUI_CALIBRATION)].isNull()) { @@ -594,15 +603,15 @@ bool guiSetConfig(const JsonObject & settings) JsonArray array = settings[FPSTR(FP_GUI_CALIBRATION)].as(); for(JsonVariant v : array) { if(i < 5) { - if(calData[i] != v.as()) status = true; - calData[i] = v.as(); + if(gui_settings.cal_data[i] != v.as()) status = true; + gui_settings.cal_data[i] = v.as(); } i++; } - if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) { - LOG_VERBOSE(TAG_GUI, F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3], - calData[4]); + if(gui_settings.cal_data[0] != 0 || gui_settings.cal_data[1] != 65535 || gui_settings.cal_data[2] != 0 || gui_settings.cal_data[3] != 65535) { + LOG_VERBOSE(TAG_GUI, F("calData set [%u, %u, %u, %u, %u]"), gui_settings.cal_data[0], gui_settings.cal_data[1], gui_settings.cal_data[2], gui_settings.cal_data[3], + gui_settings.cal_data[4]); oobeSetAutoCalibrate(false); } else { LOG_TRACE(TAG_GUI, F("First Touch Calibration enabled")); @@ -610,7 +619,7 @@ bool guiSetConfig(const JsonObject & settings) } #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) - if(status) tft_espi_set_touch(calData); + if(status) tft_espi_set_touch(gui_settings.cal_data); #endif changed |= status; } diff --git a/src/hasp_gui.h b/src/hasp_gui.h index 8db8e1f7..170c1e8c 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -7,6 +7,15 @@ #include "ArduinoJson.h" #include "lvgl.h" +struct gui_conf_t +{ + bool show_pointer; + int8_t backlight_pin; + uint8_t rotation; + uint8_t invert_display; + uint16_t cal_data[5]; +}; + /* ===== Default Event Processors ===== */ void guiSetup(); void guiLoop(void); @@ -21,7 +30,7 @@ void guiTakeScreenshot(); // webclient /* ===== Getter and Setter Functions ===== */ void guiSetDim(int8_t level); -int8_t guiGetDim(void); +int8_t guiGetDim(); void guiSetBacklight(bool lighton); bool guiGetBacklight(); From 874456b458333ba110d2a73dd862902b803859d2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:17:07 +0100 Subject: [PATCH 024/236] Xplatfotm changes --- src/hasp_eeprom.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/hasp_eeprom.cpp b/src/hasp_eeprom.cpp index 7faa5527..80a1a27d 100644 --- a/src/hasp_eeprom.cpp +++ b/src/hasp_eeprom.cpp @@ -1,21 +1,29 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#include -#include "EEPROM.h" +#include "hasp_conf.h" // load first + +#if HASP_USE_EEPROM > 0 + + #ifdef ARDUINO + #include "Arduino.h" + #endif + + #include "EEPROM.h" void eepromSetup() { -#if defined(STM32Fxx) + #if defined(STM32Fxx) eeprom_buffer_fill(); - char buffer[] = "{\"objid\":10,\"id\":1,\"page\":0,\"x\":10,\"y\":45,\"w\":220,\"h\":55,\"toggle\":\"TRUE\",\"txt\":\"Toggle Me\"}"; + char buffer[] = "{\"objid\":10,\"id\":1,\"page\":0,\"x\":10,\"y\":45,\"w\":220,\"h\":55,\"toggle\":\"TRUE\"," + "\"txt\":\"Toggle Me\"}"; uint size = strlen(buffer); uint16_t i; - for(i = 0; i < size; i++) eeprom_buffered_write_byte(i+4096, buffer[i]); - eeprom_buffered_write_byte(i+4096, 0); - // eeprom_buffer_flush(); -#endif + for(i = 0; i < size; i++) eeprom_buffered_write_byte(i + 4096, buffer[i]); + eeprom_buffered_write_byte(i + 4096, 0); + // eeprom_buffer_flush(); + #endif // ESP8266 // Don't start at boot, only at write // EEPROM.begin(1024); @@ -23,4 +31,6 @@ void eepromSetup() } void eepromLoop() -{} \ No newline at end of file +{} + +#endif \ No newline at end of file From 52eef3f657c6496d708654b98cbfe4c9d9155bf6 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:18:19 +0100 Subject: [PATCH 025/236] Xplatform changes --- src/hasp/hasp.cpp | 23 ++++++++++++++++------- src/hasp/hasp.h | 12 ++++++++++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 50008358..2adc0dad 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -1,10 +1,12 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#include "hasp_conf.h" +#ifdef ARDUINO + #include "ArduinoLog.h" +#endif #include "ArduinoJson.h" -#include "ArduinoLog.h" +#include "hasp_conf.h" #if HASP_USE_EEPROM > 0 #include "StreamUtils.h" // For EEPromStream @@ -15,10 +17,13 @@ #include "hasp_conf.h" #if HASP_USE_DEBUG > 0 + #include "../hasp_debug.h" +#endif + +#if HASP_USE_CONFIG > 0 #include "lv_fs_if.h" - #include "hasp_debug.h" - #include "hasp_config.h" #include "hasp_gui.h" + #include "hasp_config.h" //#include "hasp_filesystem.h" included in hasp_conf.h #endif @@ -29,7 +34,9 @@ #include "hasp.h" #include "lv_theme_hasp.h" -#include "EEPROM.h" +#if HASP_USE_EEPROM > 0 + #include "EEPROM.h" +#endif //#if LV_USE_HASP @@ -129,7 +136,7 @@ bool hasp_update_sleep_state() void hasp_enable_wakeup_touch() { - LOG_VERBOSE(TAG_HASP,F("Wakeup touch enabled")); + LOG_VERBOSE(TAG_HASP, F("Wakeup touch enabled")); lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); // enable first touch lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), wakeup_event_handler); } @@ -289,11 +296,13 @@ void haspProgressMsg(const char * msg) } */ } +#ifdef ARDUINO // Sets the value string of the global progress bar -void haspProgressMsg(const __FlashStringHelper * msg) +void haspProgressMsg(const __FlashStringHelper *msg) { haspProgressMsg(String(msg).c_str()); } +#endif /*Add a custom apply callback*/ static void custom_font_apply_cb(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index edc5512b..0b0b260f 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -4,16 +4,22 @@ #ifndef HASP_H #define HASP_H -#define NORMALIZE(a, b, c) map(a, b, c, 0, 0xFFFFU) +#ifdef ARDUINO +#include "Arduino.h" +#endif -#include #include "lvgl.h" #include "hasp_conf.h" +#include "hasp_conf.h" +#include "hasp_utilities.h" + #if HASP_USE_DEBUG > 0 #include "../hasp_debug.h" #endif +#define NORMALIZE(a, b, c) map(a, b, c, 0, 0xFFFFU) + #ifdef __cplusplus extern "C" { #endif @@ -87,6 +93,8 @@ void hasp_enable_wakeup_touch(); #endif void haspProgressMsg(const char * msg); +#ifdef ARDUINO void haspProgressMsg(const __FlashStringHelper * msg); +#endif #endif /*HASP_H*/ From 2148ee77778b53c58ded13b4f69931b2c106f6e7 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:24:00 +0100 Subject: [PATCH 026/236] Xplatform changes --- src/hasp_config.h | 17 ++++---- src/hasp_debug.h | 88 +++++++++++++++++++++++++++++++++-------- src/hasp_filesystem.cpp | 55 ++++++++++++++------------ 3 files changed, 110 insertions(+), 50 deletions(-) diff --git a/src/hasp_config.h b/src/hasp_config.h index 31ea0df3..76cd5448 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -18,7 +18,7 @@ void configStart(void); void configStop(void); /* ===== Special Event Processors ===== */ -void configWriteConfig(void); +void configWrite(void); void configOutput(const JsonObject & settings, uint8_t tag = TAG_CONF); bool configClearEeprom(void); @@ -62,16 +62,15 @@ const char FP_GPIO_CONFIG[] PROGMEM = "config"; const char FP_HASP_CONFIG_FILE[] PROGMEM = "/config.json"; -const char FP_WIFI[] PROGMEM = "wifi"; -const char FP_MQTT[] PROGMEM = "mqtt"; -const char FP_HTTP[] PROGMEM = "http"; -const char FP_GPIO[] PROGMEM = "gpio"; -const char FP_MDNS[] PROGMEM = "mdns"; -const char FP_HASP[] PROGMEM = "hasp"; -const char FP_GUI[] PROGMEM = "gui"; +const char FP_WIFI[] PROGMEM = "wifi"; +const char FP_MQTT[] PROGMEM = "mqtt"; +const char FP_HTTP[] PROGMEM = "http"; +const char FP_GPIO[] PROGMEM = "gpio"; +const char FP_MDNS[] PROGMEM = "mdns"; +const char FP_HASP[] PROGMEM = "hasp"; +const char FP_GUI[] PROGMEM = "gui"; const char FP_DEBUG[] PROGMEM = "debug"; - #endif #endif // HASP_USE_CONFIG \ No newline at end of file diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 0c182a04..3cc1794a 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -5,12 +5,14 @@ #define HASP_DEBUG_H #include "ArduinoJson.h" -#include "ArduinoLog.h" #include "hasp_macro.h" #include "lvgl.h" #include "lang/lang.h" +#ifndef WINDOWS +#include "ArduinoLog.h" + /* ===== Default Event Processors ===== */ void debugPreSetup(JsonObject settings); void debugSetup(); @@ -20,30 +22,84 @@ void debugStart(void); void debugStop(void); /* ===== Special Event Processors ===== */ -void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, - const char * descr); -void debugPrintHaspHeader(Print * output); +void debugLvglLogEvent(lv_log_level_t level, const char *file, uint32_t line, const char *funcname, + const char *descr); +void debugPrintHaspHeader(Print *output); void debugStartSyslog(void); void debugStopSyslog(void); // void syslogSend(uint8_t log, const char * debugText); +#else +#include + +#define LOG_FATAL(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_ERROR(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_WARNING(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_NOTICE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_TRACE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_VERBOSE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_DEBUG(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_INFO(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) + +/* json keys used in the configfile */ +// const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage"; +// const char FP_CONFIG_STARTDIM[] PROGMEM = "startdim"; +// const char FP_CONFIG_THEME[] PROGMEM = "theme"; +// const char FP_CONFIG_HUE[] PROGMEM = "hue"; +// const char FP_CONFIG_ZIFONT[] PROGMEM = "font"; +// const char FP_CONFIG_PAGES[] PROGMEM = "pages"; +// const char FP_CONFIG_ENABLE[] PROGMEM = "enable"; +// const char FP_CONFIG_HOST[] PROGMEM = "host"; +// const char FP_CONFIG_PORT[] PROGMEM = "port"; +// const char FP_CONFIG_NAME[] PROGMEM = "name"; +// const char FP_CONFIG_USER[] PROGMEM = "user"; +// const char FP_CONFIG_PASS[] PROGMEM = "pass"; +// const char FP_CONFIG_SSID[] PROGMEM = "ssid"; +// const char FP_CONFIG_GROUP[] PROGMEM = "group"; +// const char FP_CONFIG_BAUD[] PROGMEM = "baud"; +// const char FP_CONFIG_LOG[] PROGMEM = "log"; +// const char FP_CONFIG_PROTOCOL[] PROGMEM = "proto"; +// const char FP_GUI_ROTATION[] PROGMEM = "rotate"; +// const char FP_GUI_INVERT[] PROGMEM = "invert"; +// const char FP_GUI_TICKPERIOD[] PROGMEM = "tick"; +// const char FP_GUI_IDLEPERIOD1[] PROGMEM = "idle1"; +// const char FP_GUI_IDLEPERIOD2[] PROGMEM = "idle2"; +// const char FP_GUI_CALIBRATION[] PROGMEM = "calibration"; +// const char FP_GUI_BACKLIGHTPIN[] PROGMEM = "bckl"; +// const char FP_GUI_POINTER[] PROGMEM = "cursor"; +// const char FP_DEBUG_TELEPERIOD[] PROGMEM = "tele"; +// const char FP_GPIO_CONFIG[] PROGMEM = "config"; + +// const char FP_HASP_CONFIG_FILE[] PROGMEM = "/config.json"; + +// const char FP_WIFI[] PROGMEM = "wifi"; +// const char FP_MQTT[] PROGMEM = "mqtt"; +// const char FP_HTTP[] PROGMEM = "http"; +// const char FP_GPIO[] PROGMEM = "gpio"; +// const char FP_MDNS[] PROGMEM = "mdns"; +// const char FP_HASP[] PROGMEM = "hasp"; +// const char FP_GUI[] PROGMEM = "gui"; +// const char FP_DEBUG[] PROGMEM = "debug"; + +#endif /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 -bool debugGetConfig(const JsonObject & settings); -bool debugSetConfig(const JsonObject & settings); +bool debugGetConfig(const JsonObject &settings); +bool debugSetConfig(const JsonObject &settings); #endif // void debugPrintPrefix(int level, Print * _logOutput); // void debugPrintSuffix(int level, Print * _logOutput); // void debugSendOuput(const char * buffer); -enum { +enum +{ TAG_MAIN = 0, TAG_HASP = 1, TAG_ATTR = 2, TAG_MSGR = 3, TAG_OOBE = 4, - TAG_HAL = 5, + TAG_HAL = 5, TAG_DRVR = 6, TAG_DEBG = 10, @@ -52,8 +108,8 @@ enum { TAG_TASM = 13, TAG_CONF = 20, - TAG_GUI = 21, - TAG_TFT = 22, + TAG_GUI = 21, + TAG_TFT = 22, TAG_EPRM = 30, TAG_FILE = 31, @@ -61,12 +117,12 @@ enum { TAG_FWUP = 50, - TAG_ETH = 60, - TAG_WIFI = 61, - TAG_HTTP = 62, - TAG_OTA = 63, - TAG_MDNS = 64, - TAG_MQTT = 65, + TAG_ETH = 60, + TAG_WIFI = 61, + TAG_HTTP = 62, + TAG_OTA = 63, + TAG_MDNS = 64, + TAG_MQTT = 65, TAG_MQTT_PUB = 66, TAG_MQTT_RCV = 67, diff --git a/src/hasp_filesystem.cpp b/src/hasp_filesystem.cpp index a4544532..c8d915f8 100644 --- a/src/hasp_filesystem.cpp +++ b/src/hasp_filesystem.cpp @@ -1,21 +1,24 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#include -#include "ArduinoJson.h" -#include "ArduinoLog.h" +#include "hasp_conf.h" // include first -#include "hasp_conf.h" -#include "hasp_debug.h" -#include "hasp_filesystem.h" +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + + #include + #include "ArduinoJson.h" + #include "ArduinoLog.h" + + #include "hasp_debug.h" + #include "hasp_filesystem.h" void filesystemInfo() { // Get all information of your SPIFFS -#if 0 + #if 0 FSInfo fs_info; SPIFFS.info(fs_info); - Serial.println("File sistem info."); + Serial.println("File system info."); Serial.print("Total space: "); Serial.print(fs_info.totalBytes); @@ -61,61 +64,63 @@ void filesystemInfo() Serial.print("Max path lenght: "); // Serial.println(SPIFFS.maxPathLength()); -#endif + #endif } void filesystemList() { -#if HASP_USE_SPIFFS > 0 -#if defined(ARDUINO_ARCH_ESP8266) + #if HASP_USE_SPIFFS > 0 + #if defined(ARDUINO_ARCH_ESP8266) if(!SPIFFS.begin()) { -#else + #else if(!SPIFFS.begin(true)) { -#endif + #endif LOG_ERROR(TAG_FILE, F("Flash file system not mouted.")); } else { LOG_VERBOSE(TAG_FILE, F("Listing files on the internal flash:")); -#if defined(ARDUINO_ARCH_ESP32) + #if defined(ARDUINO_ARCH_ESP32) File root = SPIFFS.open("/"); File file = root.openNextFile(); while(file) { LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), file.name(), (uint32_t)file.size()); file = root.openNextFile(); } -#endif -#if defined(ARDUINO_ARCH_ESP8266) + #endif + #if defined(ARDUINO_ARCH_ESP8266) Dir dir = SPIFFS.openDir("/"); while(dir.next()) { LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize()); } -#endif + #endif } -#endif + #endif } bool filesystemSetup(void) { // no SPIFFS settings, as settings depend on SPIFFS // no Logging, because it depends on the configuration file - + // Logging is defered until debugging has started // FS success or failure is printed at that time ! -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 -#if defined(ARDUINO_ARCH_ESP8266) + #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + #if defined(ARDUINO_ARCH_ESP8266) if(!HASP_FS.begin()) { -#else + #else if(!HASP_FS.begin(true)) { -#endif + #endif // LOG_ERROR(TAG_FILE, F("SPI flash init failed. Unable to mount FS.")); return false; } else { // LOG_INFO(TAG_FILE, F("SPI Flash FS mounted")); return true; } -#endif + #endif return false; -} \ No newline at end of file +} + +#endif \ No newline at end of file From e7d1fdef859c095fe0a7c8b39b9c143e66d42ed9 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:25:05 +0100 Subject: [PATCH 027/236] Move files around --- src/hasp_oobe.cpp | 2 +- src/{ => log}/hasp_debug.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{ => log}/hasp_debug.cpp (99%) diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index 0b14ecb9..e1424ff1 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -13,7 +13,7 @@ #include "hasp_gui.h" #include "hasp_config.h" - #include "net/hasp_wifi.h" + #include "sys/net/hasp_wifi.h" #include "hasp/hasp_dispatch.h" #include "hasp/hasp_object.h" diff --git a/src/hasp_debug.cpp b/src/log/hasp_debug.cpp similarity index 99% rename from src/hasp_debug.cpp rename to src/log/hasp_debug.cpp index 9b556153..1aece68b 100644 --- a/src/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -29,7 +29,7 @@ #include "hasp_conf.h" -#include "hasp_hal.h" +#include "hal/hasp_hal.h" #include "hasp_debug.h" #include "hasp_config.h" From d04d3b41406deae516b7736f7bcd067bd4260e64 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:26:08 +0100 Subject: [PATCH 028/236] Move files around --- lib/lv_drv_tft_espi/tft_espi_drv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lv_drv_tft_espi/tft_espi_drv.cpp b/lib/lv_drv_tft_espi/tft_espi_drv.cpp index 2b51d462..5f05b867 100644 --- a/lib/lv_drv_tft_espi/tft_espi_drv.cpp +++ b/lib/lv_drv_tft_espi/tft_espi_drv.cpp @@ -6,7 +6,7 @@ /********************* * INCLUDES *********************/ -#include "../../src/hasp_hal.h" // for halGpioName() +#include "../../src/hal/hasp_hal.h" // for halGpioName() #include "tft_espi_drv.h" #include "ArduinoLog.h" #include "hasp_macro.h" From a19d82f06c8ea08d0629179037b051483cd4a3cc Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:26:50 +0100 Subject: [PATCH 029/236] Use settings structs --- src/hasp_config.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 0c040cb9..540d995f 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -19,11 +19,18 @@ //#include "hasp_eeprom.h" #include "hasp/hasp.h" + #include "hasp/hasp_dispatch.h" #if HASP_USE_EEPROM > 0 #include "EEPROM.h" #endif +extern uint16_t dispatchTelePeriod; +extern uint32_t dispatchLastMillis; + +extern gui_conf_t gui_settings; +extern dispatch_conf_t dispatch_settings; + void confDebugSet(const __FlashStringHelper * fstr_name) { /*char buffer[128]; @@ -86,7 +93,7 @@ void configStartDebug(bool setupdebug, String & configFile) #endif } -void configGetConfig(JsonDocument & settings, bool setupdebug = false) +void configRead(JsonDocument & settings, bool setupdebug = false) { String configFile((char *)0); configFile.reserve(32); @@ -116,8 +123,8 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false) // show settings in log String output; serializeJson(settings, output); - String passmask = F(D_PASSWORD_MASK); - const __FlashStringHelper * pass = F("pass"); + String passmask = F(D_PASSWORD_MASK); + const __FlashStringHelper * pass = F("pass"); output.replace(settings[FPSTR(FP_HTTP)][pass].as(), passmask); output.replace(settings[FPSTR(FP_MQTT)][pass].as(), passmask); output.replace(settings[FPSTR(FP_WIFI)][pass].as(), passmask); @@ -177,7 +184,7 @@ void configBackupToEeprom() #endif } */ -void configWriteConfig() +void configWrite() { String configFile((char *)0); configFile.reserve(32); @@ -190,7 +197,7 @@ void configWriteConfig() /* Read Config File */ DynamicJsonDocument doc(8 * 256); LOG_TRACE(TAG_CONF, F(D_FILE_LOADING), configFile.c_str()); - configGetConfig(doc, false); + configRead(doc, false); LOG_INFO(TAG_CONF, F(D_FILE_LOADED), configFile.c_str()); // Make sure we have a valid JsonObject to start from @@ -367,7 +374,7 @@ void configSetup() return; } #endif - configGetConfig(settings, true); + configRead(settings, true); } //#if HASP_USE_SPIFFS > 0 From 941c8c90d7b66b4924ab400d8d7ce5ce89cc6238 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 18:31:02 +0100 Subject: [PATCH 030/236] Update lv_drv_conf --- .clang-format | 2 +- include/lv_drv_conf.h | 90 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 20 deletions(-) diff --git a/.clang-format b/.clang-format index f6605270..d801df39 100644 --- a/.clang-format +++ b/.clang-format @@ -60,7 +60,7 @@ IncludeIsMainRegex: '$' IndentCaseLabels: true IndentWidth: 4 IndentWrappedFunctionNames: false -IndentPPDirectives: BeforeHash +# IndentPPDirectives: BeforeHash JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true diff --git a/include/lv_drv_conf.h b/include/lv_drv_conf.h index ea6a588c..cb5bd603 100644 --- a/include/lv_drv_conf.h +++ b/include/lv_drv_conf.h @@ -1,6 +1,10 @@ /** * @file lv_drv_conf.h - * + * Configuration file for v7.9.1 + */ + +/* + * COPY THIS FILE AS lv_drv_conf.h */ #if 1 /*Set it to "1" to enable the content*/ @@ -13,9 +17,15 @@ /********************* * DELAY INTERFACE *********************/ +#ifdef ARDUINO #define LV_DRV_DELAY_INCLUDE /*Dummy include by default*/ #define LV_DRV_DELAY_US(us) delayMicroseconds(ud) /*Delay the given number of microseconds*/ #define LV_DRV_DELAY_MS(ms) delay(ms) /*Delay the given number of milliseconds*/ +#else +#define LV_DRV_DELAY_INCLUDE /*Dummy include by default*/ +#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/ +#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/ +#endif /********************* * DISPLAY INTERFACE @@ -93,7 +103,9 @@ #define MONITOR_VER_RES LV_VER_RES /* Scale window by this factor (useful when simulating small screens) */ +#ifndef MONITOR_ZOOM #define MONITOR_ZOOM 1 +#endif /* Used to test true double buffering with only address changing. * Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */ @@ -102,9 +114,6 @@ /*Eclipse: Visual Studio: */ #define MONITOR_SDL_INCLUDE_PATH -/*Different rendering might be used if running in a Virtual machine*/ -#define MONITOR_VIRTUAL_MACHINE 0 - /*Open two windows to test multi display support*/ #define MONITOR_DUAL 0 #endif @@ -116,12 +125,18 @@ #define USE_WINDOWS 0 #endif -#define USE_WINDOWS 0 #if USE_WINDOWS #define WINDOW_HOR_RES 480 #define WINDOW_VER_RES 320 #endif +/*---------------------------------------- + * GTK drivers (monitor, mouse, keyboard + *---------------------------------------*/ +#ifndef USE_GTK +#define USE_GTK 0 +#endif + /*---------------- * SSD1963 *--------------*/ @@ -181,6 +196,17 @@ /*No settings*/ #endif /*USE_ST7565*/ +/*------------------------------ + * GC9A01 (color, low res.) + *-----------------------------*/ +#ifndef USE_GC9A01 +#define USE_GC9A01 0 +#endif + +#if USE_GC9A01 +/*No settings*/ +#endif /*USE_GC9A01*/ + /*------------------------------------------ * UC1610 (4 gray 160*[104|128]) * (EA DOGXL160 160x104 tested) @@ -218,6 +244,20 @@ b) /*((uint8_t) __REV(__RBIT(b)))*/ /*Architecture / compiler dependent byte bits order reverse*/ #endif /*USE_SHARP_MIP*/ +/*------------------------------------------------- + * ILI9341 240X320 TFT LCD + *------------------------------------------------*/ +#ifndef USE_ILI9341 +#define USE_ILI9341 0 +#endif + +#if USE_ILI9341 +#define ILI9341_HOR_RES LV_HOR_RES +#define ILI9341_VER_RES LV_VER_RES +#define ILI9341_GAMMA 1 +#define ILI9341_TEARING 0 +#endif /*USE_ILI9341*/ + /*----------------------------------------- * Linux frame buffer device (/dev/fbx) *-----------------------------------------*/ @@ -240,6 +280,18 @@ #define FBDEV_PATH "/dev/fb0" #endif +/*----------------------------------------- + * DRM/KMS device (/dev/dri/cardX) + *-----------------------------------------*/ +#ifndef USE_DRM +#define USE_DRM 0 +#endif + +#if USE_DRM +#define DRM_CARD "/dev/dri/card0" +#define DRM_CONNECTOR_ID -1 /* -1 for the first connected one */ +#endif + /********************* * INPUT DEVICES *********************/ @@ -330,25 +382,25 @@ #define USE_EVDEV 0 #endif -#if USE_EVDEV -#define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test \ - them*/ -#define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/ +#ifndef USE_BSD_EVDEV +#define USE_BSD_EVDEV 0 +#endif -#define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */ -#if EVDEV_SCALE -#define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */ -#define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */ -#endif /*EVDEV_SCALE*/ +#if USE_EVDEV || USE_BSD_EVDEV +#define EVDEV_NAME \ + "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test \ + them*/ +#define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/ #define EVDEV_CALIBRATE \ 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/ + #if EVDEV_CALIBRATE -#define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/ -#define EVDEV_HOR_MAX 200 -#define EVDEV_VER_MIN 200 -#define EVDEV_VER_MAX 3800 -#endif /*EVDEV_SCALE*/ +#define EVDEV_HOR_MIN 0 /*to invert axis swap EVDEV_XXX_MIN by EVDEV_XXX_MAX*/ +#define EVDEV_HOR_MAX 4096 /*"evtest" Linux tool can help to get the correct calibraion values>*/ +#define EVDEV_VER_MIN 0 +#define EVDEV_VER_MAX 4096 +#endif /*EVDEV_CALIBRATE*/ #endif /*USE_EVDEV*/ /*------------------------------- From 3d95275c830df2e095f2dadaf5770959a67cac38 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 03:25:50 +0100 Subject: [PATCH 031/236] Reorganize environments --- user_setups/esp32/d1-mini-esp32_ili9341.ini | 8 +------- .../esp32/d132-unoshield_ili9486_parallel.ini | 6 +----- user_setups/esp32/esp32-dev_ili9488.ini | 13 +------------ user_setups/esp32/esp32-dev_ili9488_parallel.ini | 10 +--------- user_setups/esp32/esp32cam_st7796.ini | 14 +------------- user_setups/esp32/lanbon_l8.ini | 8 +------- user_setups/esp32/lolin-d32-pro_ili9341.ini | 1 + user_setups/esp32/m5stack_core2.ini | 8 +------- user_setups/esp32/nodemcu-32s_st7796.ini | 8 +------- user_setups/esp32/ttgo-esp32-lilygo-pi.ini | 11 +---------- user_setups/esp32/ttgo-esp32-poe_ili9341.ini | 11 +---------- user_setups/esp32/wt32-sc01.ini | 8 +------- user_setups/esp8266/d1-mini-esp8266_ili9341.ini | 10 ++-------- user_setups/esp8266/esp8266_st7735.ini | 9 ++------- user_setups/win32/emulator_64bits.ini | 4 ++-- 15 files changed, 18 insertions(+), 111 deletions(-) diff --git a/user_setups/esp32/d1-mini-esp32_ili9341.ini b/user_setups/esp32/d1-mini-esp32_ili9341.ini index 68ed7003..a3a04a8a 100644 --- a/user_setups/esp32/d1-mini-esp32_ili9341.ini +++ b/user_setups/esp32/d1-mini-esp32_ili9341.ini @@ -6,14 +6,8 @@ ;***************************************************; [env:d1-mini-esp32_ili9341] -platform = espressif32 -platform_packages = framework-arduinoespressif32 -framework = arduino +extends = esp32 board = wemos_d1_mini32 -;upload_port = COM5 ; To change the port, use platform_override.ini -;monitor_port = COM5 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32/d132-unoshield_ili9486_parallel.ini b/user_setups/esp32/d132-unoshield_ili9486_parallel.ini index 8c188f00..b1c84d76 100644 --- a/user_setups/esp32/d132-unoshield_ili9486_parallel.ini +++ b/user_setups/esp32/d132-unoshield_ili9486_parallel.ini @@ -5,12 +5,8 @@ ;***************************************************; [env:d132-unoshield] -platform = espressif32 +extends = esp32 board = esp32dev -upload_port = COM4 ; To change the port, use platform_override.ini -monitor_port = COM4 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32/esp32-dev_ili9488.ini b/user_setups/esp32/esp32-dev_ili9488.ini index 2b529cc8..5747e110 100644 --- a/user_setups/esp32/esp32-dev_ili9488.ini +++ b/user_setups/esp32/esp32-dev_ili9488.ini @@ -5,19 +5,8 @@ ;***************************************************; [env:esp32dev-ili9488] -platform = espressif32 @ ^2.0.0 +extends = esp32 board = esp32dev -upload_port = COM2 ; To change the port, use platform_override.ini -monitor_port = COM2 ; To change the port, use platform_override.ini -; upload_protocol = espota ; Use ArduinoOTA after flashing over serial -; upload_port = 10.4.0.171 ; IP of the ESP -; upload_flags = -; --port=3232 -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv - -debug_tool = esp-prog -debug_init_break = tbreak setup build_flags = ${env.build_flags} diff --git a/user_setups/esp32/esp32-dev_ili9488_parallel.ini b/user_setups/esp32/esp32-dev_ili9488_parallel.ini index d6f73632..995ba4a5 100644 --- a/user_setups/esp32/esp32-dev_ili9488_parallel.ini +++ b/user_setups/esp32/esp32-dev_ili9488_parallel.ini @@ -6,16 +6,8 @@ ;***************************************************; [env:esp32dev-mrb3511] -platform = espressif32 @ ^2.0.0 +extends = esp32 board = esp32dev -upload_port = COM1 ; To change the port, use platform_override.ini -monitor_port = COM1 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv -check_tool = cppcheck -check_flags = --enable=all -debug_tool = esp-prog -debug_init_break = tbreak setup build_flags = ${env.build_flags} diff --git a/user_setups/esp32/esp32cam_st7796.ini b/user_setups/esp32/esp32cam_st7796.ini index 88d4e79d..fd51c356 100644 --- a/user_setups/esp32/esp32cam_st7796.ini +++ b/user_setups/esp32/esp32cam_st7796.ini @@ -6,20 +6,8 @@ ;***************************************************; [env:esp32cam-st7796] -platform = espressif32 @ ^2.0.0 +extends = esp32 board = esp32cam -; upload_port = COM18 ; To change the port, use platform_override.ini -; monitor_port = COM18 ; To change the port, use platform_override.ini -; upload_protocol = espota ; Use ArduinoOTA after flashing over serial -; upload_port = x.x.x.x; IP of the ESP -; upload_flags = -; --port=3232 - -debug_tool = esp-prog -debug_init_break = tbreak setup -;board_build.partitions = min_spiffs.csv -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv ;ESP32 CAM PINS build_flags = diff --git a/user_setups/esp32/lanbon_l8.ini b/user_setups/esp32/lanbon_l8.ini index 2843205e..4328cc6e 100644 --- a/user_setups/esp32/lanbon_l8.ini +++ b/user_setups/esp32/lanbon_l8.ini @@ -6,14 +6,8 @@ ;***************************************************; [env:lanbon_l8] -platform = espressif32 -platform_packages = framework-arduinoespressif32 -framework = arduino +extends = esp32 board = esp32dev -;upload_port = COM5 ; To change the port, use platform_override.ini -;monitor_port = COM5 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32/lolin-d32-pro_ili9341.ini b/user_setups/esp32/lolin-d32-pro_ili9341.ini index dae78b4a..47a82dc2 100644 --- a/user_setups/esp32/lolin-d32-pro_ili9341.ini +++ b/user_setups/esp32/lolin-d32-pro_ili9341.ini @@ -9,6 +9,7 @@ [env:lolind32pro-lolintft24] extends = esp32 +board = lolin_d32_pro build_flags = ${env.build_flags} diff --git a/user_setups/esp32/m5stack_core2.ini b/user_setups/esp32/m5stack_core2.ini index 6ea889e0..bd2dbb04 100644 --- a/user_setups/esp32/m5stack_core2.ini +++ b/user_setups/esp32/m5stack_core2.ini @@ -6,14 +6,8 @@ ;***************************************************; [env:m5stack-core2] -platform = espressif32 -platform_packages = framework-arduinoespressif32 -framework = arduino +extends = esp32 board = esp32dev -;upload_port = COM5 ; To change the port, use platform_override.ini -;monitor_port = COM5 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32/nodemcu-32s_st7796.ini b/user_setups/esp32/nodemcu-32s_st7796.ini index 919b9ee4..5fd72ab2 100644 --- a/user_setups/esp32/nodemcu-32s_st7796.ini +++ b/user_setups/esp32/nodemcu-32s_st7796.ini @@ -6,14 +6,8 @@ ;***************************************************; [env:nodemcu32s-raspi] -platform = espressif32 @ ^2.0.0 +extends = esp32 board = nodemcu-32s -;upload_port = COM9 ; To change the port, use platform_override.ini -;monitor_port = COM9 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv -debug_tool = esp-prog -debug_init_break = tbreak setup build_flags = ${env.build_flags} diff --git a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini index 215a51ee..2d687549 100644 --- a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini +++ b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini @@ -6,17 +6,8 @@ ;***************************************************; [env:ttgo-esp32-lilygo-pi] -platform = espressif32 +extends = esp32 board = esp32dev -;upload_protocol = espota ; Use ArduinoOTA after flashing over serial -;upload_port = 10.4.70.37 ; 10.4.0.198 ; IP of the ESP -;upload_flags = -; --port=3232 - -;upload_port = COM9 ; To change the port, use platform_override.ini -;monitor_port = COM9 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32/ttgo-esp32-poe_ili9341.ini b/user_setups/esp32/ttgo-esp32-poe_ili9341.ini index cab11a22..0031aae4 100644 --- a/user_setups/esp32/ttgo-esp32-poe_ili9341.ini +++ b/user_setups/esp32/ttgo-esp32-poe_ili9341.ini @@ -7,17 +7,8 @@ ;***************************************************; [env:ttgo_esp32_poe-lolintft24] -platform = espressif32 @ ^2.0.0 +extends = esp32 board = esp32dev -;upload_protocol = espota ; Use ArduinoOTA after flashing over serial -;upload_port = 10.4.70.37 ; 10.4.0.198 ; IP of the ESP -;upload_flags = -; --port=3232 - -;upload_port = COM9 ; To change the port, use platform_override.ini -;monitor_port = COM9 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32/wt32-sc01.ini b/user_setups/esp32/wt32-sc01.ini index 5076645f..e63852ff 100644 --- a/user_setups/esp32/wt32-sc01.ini +++ b/user_setups/esp32/wt32-sc01.ini @@ -6,14 +6,8 @@ ;***************************************************; [env:wt32-sc01] -platform = espressif32 -platform_packages = framework-arduinoespressif32 -framework = arduino +extends = esp32 board = esp32dev -;upload_port = COM5 ; To change the port, use platform_override.ini -;monitor_port = COM5 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp8266/d1-mini-esp8266_ili9341.ini b/user_setups/esp8266/d1-mini-esp8266_ili9341.ini index c9998782..6eb7ac8a 100644 --- a/user_setups/esp8266/d1-mini-esp8266_ili9341.ini +++ b/user_setups/esp8266/d1-mini-esp8266_ili9341.ini @@ -6,15 +6,9 @@ ;***************************************************; [env:d1-mini-esp8266_ili9341] -platform = espressif8266@^2.6.2 +extends = esp8266 board = d1_mini -;upload_port = COM7 ; To change the port, use platform_override.ini -;monitor_port = COM7 ; To change the port, use platform_override.ini -monitor_filters = esp8266_exception_decoder -board_build.f_flash = 40000000L -board_build.flash_mode = dout -board_build.ldscript = eagle.flash.4m2m.ld ; 2Mb Spiffs -board_build.f_cpu = 160000000L ; set frequency to 160MHz + build_flags = ${env.build_flags} ${esp8266.build_flags} diff --git a/user_setups/esp8266/esp8266_st7735.ini b/user_setups/esp8266/esp8266_st7735.ini index d1637bcc..374292b6 100644 --- a/user_setups/esp8266/esp8266_st7735.ini +++ b/user_setups/esp8266/esp8266_st7735.ini @@ -5,14 +5,9 @@ ;***************************************************; [env:esp12e-st7735] -platform = espressif8266@^2.6.2 +extends = esp8266 board = esp12e -upload_port = COM8 ; To change the port, use platform_override.ini -monitor_port = COM8 ; To change the port, use platform_override.ini -board_build.f_flash = 40000000L -board_build.flash_mode = dout -board_build.ldscript = eagle.flash.4m2m.ld ; 2Mb Spiffs -board_build.f_cpu = 160000000L ; set frequency to 160MHz + build_flags = ${env.build_flags} ${esp8266.build_flags} diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/emulator_64bits.ini index 9742840d..43480cbd 100644 --- a/user_setups/win32/emulator_64bits.ini +++ b/user_setups/win32/emulator_64bits.ini @@ -11,7 +11,7 @@ build_flags = ;-D LV_DRV_NO_CONF -D LV_MEM_SIZE=262144U ; 256kB lvgl memory -D USE_MONITOR - -D MONITOR_ZOOM=1 ; 2 + -D MONITOR_ZOOM=1 ; can be fractional like 1.5 or 2 -D USE_MOUSE -D USE_MOUSEWHEEL -D USE_KEYBOARD @@ -71,7 +71,7 @@ build_flags = lib_deps = ${env.lib_deps} - lv_drivers@~7.9.0 + ;lv_drivers@~7.9.0 ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip https://github.com/eclipse/paho.mqtt.c.git bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser From 8156e8ca33b793d0f571a90d9ff5890e8aa7de55 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 03:26:17 +0100 Subject: [PATCH 032/236] Add Out of Memory --- src/lang/en_US.h | 2 ++ src/lang/nl_NL.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/lang/en_US.h b/src/lang/en_US.h index f03b9f45..e5747b38 100644 --- a/src/lang/en_US.h +++ b/src/lang/en_US.h @@ -5,6 +5,8 @@ #define D_PASSWORD "Password:" #define D_SSID "Ssid:" +#define D_ERROR_OUT_OF_MEMORY "Out of memory" + #define D_CONFIG_NOT_CHANGED "Settings did not change" #define D_CONFIG_CHANGED "Settings changed" #define D_CONFIG_LOADED "Settings loaded" diff --git a/src/lang/nl_NL.h b/src/lang/nl_NL.h index 84528bc9..6a5022fc 100644 --- a/src/lang/nl_NL.h +++ b/src/lang/nl_NL.h @@ -5,6 +5,8 @@ #define D_PASSWORD "Wachtwoord:" #define D_SSID "Ssid:" +#define D_ERROR_OUT_OF_MEMORY "Geen geheugen bechikbaar" + #define D_CONFIG_NOT_CHANGED "Instellingen ongewijzigd" #define D_CONFIG_CHANGED "Instellingen gewijzigd" #define D_CONFIG_LOADED "Instellingen geladen" From 5692bb8b9009a68701ce6563e1e70348a19089ea Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 03:39:56 +0100 Subject: [PATCH 033/236] Extended device classes for ESP32 and ESP8266 --- src/dev/device.cpp | 6 +- src/dev/device.h | 41 +++++++-- src/dev/esp32/esp32.cpp | 84 +++++++++++++++++ src/dev/esp32/esp32.h | 51 ++++++++++ src/dev/{lanbon-l8 => esp32}/lanbonl8.cpp | 29 +++--- src/dev/{lanbon-l8 => esp32}/lanbonl8.h | 13 +-- .../{m5stackcore2 => esp32}/m5stackcore2.cpp | 13 +-- .../{m5stackcore2 => esp32}/m5stackcore2.h | 7 +- src/dev/esp8266/esp8266.cpp | 66 +++++++++++++ src/dev/esp8266/esp8266.h | 45 +++++++++ src/hal/hasp_hal.cpp | 80 ++++++++-------- src/hasp/hasp.cpp | 27 +++--- src/hasp/hasp_dispatch.cpp | 92 ++++++++++--------- 13 files changed, 403 insertions(+), 151 deletions(-) create mode 100644 src/dev/esp32/esp32.cpp create mode 100644 src/dev/esp32/esp32.h rename src/dev/{lanbon-l8 => esp32}/lanbonl8.cpp (79%) rename src/dev/{lanbon-l8 => esp32}/lanbonl8.h (63%) rename src/dev/{m5stackcore2 => esp32}/m5stackcore2.cpp (83%) rename src/dev/{m5stackcore2 => esp32}/m5stackcore2.h (71%) create mode 100644 src/dev/esp8266/esp8266.cpp create mode 100644 src/dev/esp8266/esp8266.h diff --git a/src/dev/device.cpp b/src/dev/device.cpp index 99e49f86..ce356046 100644 --- a/src/dev/device.cpp +++ b/src/dev/device.cpp @@ -1,9 +1,9 @@ #include "device.h" #if defined(LANBONL8) - #warning Lanbon L8 +#warning Lanbon L8 #elif defined(M5STACK) - #warning M5 Stack +#warning M5 Stack #else -dev::BaseDevice haspDevice; +#warning Generic Device #endif \ No newline at end of file diff --git a/src/dev/device.h b/src/dev/device.h index f1f053f5..6350dea6 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -4,10 +4,19 @@ #ifndef HASP_DEVICE_H #define HASP_DEVICE_H +#ifdef ARDUINO +#include "Arduino.h" +#endif + namespace dev { class BaseDevice { public: + bool has_battery = false; + bool has_backligth_control = true; + + virtual void reboot() + {} virtual void pre_setup() {} virtual void post_setup() @@ -16,19 +25,37 @@ class BaseDevice { {} virtual void loop_5s() {} + virtual void set_backlight_pin(uint8_t pin) + {} + virtual void set_backlight_level(uint8_t level) + {} + virtual uint8_t get_backlight_level() + { + return -1; + } + virtual void set_backlight_power(bool power) + {} + virtual bool get_backlight_power() + { + return true; + } }; } // namespace dev +#if defined(ESP32) +#warning Building for ESP32 Devices +#include "dev/esp32/esp32.h" +#elif defined(ESP8266) +#warning Building for ESP8266 Devices +#include "dev/esp8266/esp8266.h" +#elif defined(STM32F4) +#warning Building for STM32F4xx Devices +#include "dev/stm32f4.h" +#else +#warning Building for Generic Devices using dev::BaseDevice; -#if defined(LANBONL8) - #warning Lanbon L8 - #include "lanbonl8.h" -#elif defined(M5STACK) - #warning M5 Stack - #include "m5stackcore2.h" -#else extern dev::BaseDevice haspDevice; #endif #endif \ No newline at end of file diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp new file mode 100644 index 00000000..b317aafa --- /dev/null +++ b/src/dev/esp32/esp32.cpp @@ -0,0 +1,84 @@ +#if defined(ESP32) + +#include "Arduino.h" +#include +#include "esp_system.h" + +#include "dev/device.h" +#include "dev/esp32/esp32.h" + +#include "driver/adc.h" +#include "esp_adc_cal.h" + +#include "hasp_conf.h" +#include "hasp_debug.h" + +#define BACKLIGHT_CHANNEL 0 + +namespace dev { + +void Esp32Device::reboot() +{ + ESP.restart(); +} + +void Esp32Device::set_backlight_pin(uint8_t pin) +{ + Esp32Device::backlight_pin = pin; + /* Setup Backlight Control Pin */ + if(pin >= 0) { + LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); + + ledcSetup(BACKLIGHT_CHANNEL, 20000, 12); + ledcAttachPin(pin, BACKLIGHT_CHANNEL); + + update_backlight(); + } +} + +void Esp32Device::set_backlight_level(uint8_t level) +{ + backlight_level = level >= 0 ? level : 0; + backlight_level = backlight_level <= 100 ? backlight_level : 100; + + update_backlight(); +} + +uint8_t Esp32Device::get_backlight_level() +{ + return backlight_level; +} + +void Esp32Device::set_backlight_power(bool power) +{ + backlight_power = power; + update_backlight(); +} + +bool Esp32Device::get_backlight_power() +{ + return backlight_power != 0; +} + +void Esp32Device::update_backlight() +{ + if(backlight_pin == -1) return; + + if(backlight_power) { // The backlight is ON + ledcWrite(BACKLIGHT_CHANNEL, map(backlight_level, 0, 100, 0, 4095)); // ledChannel and value + } +} + +} // namespace dev + +#if defined(LANBONL8) +#warning Building for Lanbon L8 +#include "dev/esp32/lanbonl8.h" +#elif defined(M5STACK) +#warning Building for M5Stack core2 +#include "dev/esp32/m5stackcore2.h" +#else +dev::Esp32Device haspDevice; +#endif + +#endif // ESP32 \ No newline at end of file diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h new file mode 100644 index 00000000..3c9bd449 --- /dev/null +++ b/src/dev/esp32/esp32.h @@ -0,0 +1,51 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_DEVICE_ESP32_H +#define HASP_DEVICE_ESP32_H + +#include "dev/device.h" + +#if defined(ESP32) + +namespace dev { + +class Esp32Device : public BaseDevice { + + public: + void reboot() override; + + void set_backlight_pin(uint8_t pin) override; + + void set_backlight_level(uint8_t val) override; + + uint8_t get_backlight_level() override; + + void set_backlight_power(bool power) override; + + bool get_backlight_power() override; + + private: + uint8_t backlight_pin; + uint8_t backlight_level; + uint8_t backlight_power; + + void update_backlight(); +}; + +} // namespace dev + +using dev::Esp32Device; + +#if defined(LANBONL8) +#warning Building for Lanbon L8 +#include "dev/esp32/lanbonl8.h" +#elif defined(M5STACK) +#warning Building for M5Stack core2 +#include "dev/esp32/m5stackcore2.h" +#else +extern dev::Esp32Device haspDevice; +#endif +#endif // ESP32 + +#endif // HASP_DEVICE_ESP32_H \ No newline at end of file diff --git a/src/dev/lanbon-l8/lanbonl8.cpp b/src/dev/esp32/lanbonl8.cpp similarity index 79% rename from src/dev/lanbon-l8/lanbonl8.cpp rename to src/dev/esp32/lanbonl8.cpp index 9fdccb7e..4e09d88f 100644 --- a/src/dev/lanbon-l8/lanbonl8.cpp +++ b/src/dev/esp32/lanbonl8.cpp @@ -1,13 +1,19 @@ #include "lanbonl8.h" #if defined(LANBONL8) - #include "Arduino.h" - #include "../device.h" - #include "driver/adc.h" - #include "esp_adc_cal.h" +#include "Arduino.h" +#include "dev/esp32/esp32.h" - #define REF_VOLTAGE 1100 +#include "driver/adc.h" +#include "esp_adc_cal.h" + +#include "hasp_conf.h" +#include "hasp_debug.h" + +#define BACKLIGHT_CHANNEL 0 + +#define REF_VOLTAGE 1100 esp_adc_cal_characteristics_t * adc_chars = new esp_adc_cal_characteristics_t; // adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t)); @@ -55,19 +61,6 @@ void LanbonL8::pre_setup() print_char_val_type(val_type); } -void LanbonL8::post_setup() -{} - -void LanbonL8::loop() -{} - -void LanbonL8::loop_5s() -{ - double voltage = esp_adc_cal_raw_to_voltage(analogRead(39), adc_chars); - Serial.print(adc1_get_raw(ADC1_CHANNEL_3)); - Serial.print(" - "); - Serial.println(voltage); -} } // namespace dev dev::LanbonL8 haspDevice; diff --git a/src/dev/lanbon-l8/lanbonl8.h b/src/dev/esp32/lanbonl8.h similarity index 63% rename from src/dev/lanbon-l8/lanbonl8.h rename to src/dev/esp32/lanbonl8.h index 9155109e..0c1ffc53 100644 --- a/src/dev/lanbon-l8/lanbonl8.h +++ b/src/dev/esp32/lanbonl8.h @@ -4,22 +4,17 @@ #ifndef HASP_DEVICE_LANBONL8_H #define HASP_DEVICE_LANBONL8_H -#include "../device.h" +#include "dev/esp32/esp32.h" #if defined(LANBONL8) namespace dev { -class LanbonL8 : public BaseDevice { +class LanbonL8 : public Esp32Device { public: - void pre_setup() override; - - void post_setup() override; - - void loop() override; - - void loop_5s() override; + void pre_setup(); }; + } // namespace dev extern dev::LanbonL8 haspDevice; diff --git a/src/dev/m5stackcore2/m5stackcore2.cpp b/src/dev/esp32/m5stackcore2.cpp similarity index 83% rename from src/dev/m5stackcore2/m5stackcore2.cpp rename to src/dev/esp32/m5stackcore2.cpp index c3354aa2..0ebf315f 100644 --- a/src/dev/m5stackcore2/m5stackcore2.cpp +++ b/src/dev/esp32/m5stackcore2.cpp @@ -1,8 +1,9 @@ #include "m5stackcore2.h" #if defined(M5STACK) - #include "AXP192.h" // Power Mgmt - #include "../device.h" + +#include "AXP192.h" // Power Mgmt +#include "dev/esp32/esp32.h" // AXP192 Axp; namespace dev { @@ -39,14 +40,6 @@ void M5StackCore2::pre_setup(void) Axp.SetLed(1); } -void M5StackCore2::post_setup(void) -{} - -void M5StackCore2::loop(void) -{} - -void M5StackCore2::loop_5s(void) -{} } // namespace dev dev::M5StackCore2 haspDevice; diff --git a/src/dev/m5stackcore2/m5stackcore2.h b/src/dev/esp32/m5stackcore2.h similarity index 71% rename from src/dev/m5stackcore2/m5stackcore2.h rename to src/dev/esp32/m5stackcore2.h index fa51231d..8060530a 100644 --- a/src/dev/m5stackcore2/m5stackcore2.h +++ b/src/dev/esp32/m5stackcore2.h @@ -6,16 +6,13 @@ #if defined(M5STACK) - #include "../device.h" +#include "dev/esp32/esp32.h" namespace dev { -class M5StackCore2 : public BaseDevice { +class M5StackCore2 : public Esp32Device { public: void pre_setup() override; - void post_setup() override; - void loop() override; - void loop_5s() override; }; } // namespace dev diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp new file mode 100644 index 00000000..029139eb --- /dev/null +++ b/src/dev/esp8266/esp8266.cpp @@ -0,0 +1,66 @@ +#if defined(ESP8266) + +#include "Arduino.h" +#include + +#include "dev/esp8266/esp8266.h" + +#include "hasp_conf.h" +#include "hasp_debug.h" + +#define BACKLIGHT_CHANNEL 0 + +namespace dev { + +void Esp8266Device::reboot() +{ + ESP.restart(); +} + +void Esp8266Device::set_backlight_pin(uint8_t pin) +{ + Esp8266Device::backlight_pin = pin; + /* Setup Backlight Control Pin */ + if(pin >= 0) { + LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); + pinMode(backlight_pin, OUTPUT); + update_backlight(); + } +} + +void Esp8266Device::set_backlight_level(uint8_t level) +{ + backlight_level = level >= 0 ? level : 0; + backlight_level = backlight_level <= 100 ? backlight_level : 100; + + update_backlight(); +} + +uint8_t Esp8266Device::get_backlight_level() +{ + return backlight_level; +} + +void Esp8266Device::set_backlight_power(bool power) +{ + backlight_power = power; + update_backlight(); +} + +bool Esp8266Device::get_backlight_power() +{ + return backlight_power != 0; +} + +void Esp8266Device::update_backlight() +{ + if(backlight_pin == -1) return; + + analogWrite(backlight_pin, backlight_power ? map(backlight_level, 0, 100, 0, 1023) : 0); +} + +} // namespace dev + +dev::Esp8266Device haspDevice; + +#endif // ESP8266 \ No newline at end of file diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h new file mode 100644 index 00000000..e90b486a --- /dev/null +++ b/src/dev/esp8266/esp8266.h @@ -0,0 +1,45 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_DEVICE_ESP8266_H +#define HASP_DEVICE_ESP8266_H + +#include "hasp_conf.h" +#include "dev/device.h" + +#if defined(ESP8266) + +namespace dev { + +class Esp8266Device : public BaseDevice { + + public: + void reboot() override; + + void set_backlight_pin(uint8_t pin) override; + + void set_backlight_level(uint8_t val) override; + + uint8_t get_backlight_level() override; + + void set_backlight_power(bool power) override; + + bool get_backlight_power() override; + + private: + uint8_t backlight_pin; + uint8_t backlight_level; + uint8_t backlight_power; + + void update_backlight(); +}; + +} // namespace dev + +using dev::Esp8266Device; + +extern dev::Esp8266Device haspDevice; + +#endif // ESP8266 + +#endif // HASP_DEVICE_ESP8266_H \ No newline at end of file diff --git a/src/hal/hasp_hal.cpp b/src/hal/hasp_hal.cpp index aa0323d0..f2bea6a0 100644 --- a/src/hal/hasp_hal.cpp +++ b/src/hal/hasp_hal.cpp @@ -5,18 +5,18 @@ #include "hasp_conf.h" #if defined(ESP8266) - #include - #include +#include +#include #endif #if defined(ESP32) - #include - #include - #include "esp_system.h" +#include +#include +#include "esp_system.h" #endif #if defined(ARDUINO_ARCH_ESP32) - #include // needed to get the ResetInfo +#include // needed to get the ResetInfo // Compatibility function for ESP8266 getRestInfo String esp32ResetReason(uint8_t cpuid) @@ -152,11 +152,11 @@ String halGetChipModel() case CHIP_ESP32: model += F("ESP32"); break; - #ifdef CHIP_ESP32S2 +#ifdef CHIP_ESP32S2 case CHIP_ESP32S2: model += F("ESP32-S2"); break; - #endif +#endif default: model = F("Unknown ESP32"); } @@ -174,19 +174,19 @@ String halGetChipModel() /* Memory Management Functions */ #if defined(STM32F4xx) - #include // for mallinfo() - #include // for sbrk() +#include // for mallinfo() +#include // for sbrk() int freeHighMemory() { char top; - #ifdef __arm__ +#ifdef __arm__ return &top - reinterpret_cast(sbrk(0)); - #elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151) +#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151) return &top - __brkval; - #else // __arm__ +#else // __arm__ return __brkval ? &top - __brkval : &top - __malloc_heap_start; - #endif // __arm__ +#endif // __arm__ } #endif @@ -260,14 +260,14 @@ String halGetMacAddress(int start, const char * seperator) #if defined(STM32F4xx) uint8_t * mac_p = nullptr; - #if HASP_USE_ETHERNET > 0 - #if USE_BUILTIN_ETHERNET > 0 +#if HASP_USE_ETHERNET > 0 +#if USE_BUILTIN_ETHERNET > 0 mac_p = Ethernet.MACAddress(); for(int i = 0; i < 6; i++) mac[i] = *(mac_p + i); - #else +#else Ethernet.macAddress(mac); - #endif - #endif +#endif +#endif #else WiFi.macAddress(mac); #endif @@ -293,8 +293,6 @@ uint16_t halGetCpuFreqMHz() #endif } - - String halDisplayDriverName() { #if defined(ILI9341_DRIVER) @@ -342,56 +340,56 @@ String halGpioName(uint8_t gpio) case PortName::PortB: ioName = F("PB"); break; - #if defined GPIOC_BASE +#if defined GPIOC_BASE case PortName::PortC: ioName = F("PC"); break; - #endif - #if defined GPIOD_BASE +#endif +#if defined GPIOD_BASE case PortName::PortD: ioName = F("PD"); break; - #endif - #if defined GPIOE_BASE +#endif +#if defined GPIOE_BASE case PortName::PortE: ioName = F("PE"); break; - #endif - #if defined GPIOF_BASE +#endif +#if defined GPIOF_BASE case PortName::PortF: ioName = F("PF"); break; - #endif - #if defined GPIOG_BASE +#endif +#if defined GPIOG_BASE case PortName::PortG: ioName = F("PG"); break; - #endif - #if defined GPIOH_BASE +#endif +#if defined GPIOH_BASE case PortName::PortH: ioName = F("PH"); break; - #endif - #if defined GPIOI_BASE +#endif +#if defined GPIOI_BASE case PortName::PortI: ioName = F("PI"); break; - #endif - #if defined GPIOJ_BASE +#endif +#if defined GPIOJ_BASE case PortName::PortJ: ioName = F("PJ"); break; - #endif - #if defined GPIOK_BASE +#endif +#if defined GPIOK_BASE case PortName::PortK: ioName = F("PK"); break; - #endif - #if defined GPIOZ_BASE +#endif +#if defined GPIOZ_BASE case PortName::PortZ: ioName = F("PZ"); break; - #endif +#endif default: ioName = F("P?"); } diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 2adc0dad..ee971af3 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -2,14 +2,14 @@ For full license information read the LICENSE file in the project folder */ #ifdef ARDUINO - #include "ArduinoLog.h" +#include "ArduinoLog.h" #endif #include "ArduinoJson.h" #include "hasp_conf.h" #if HASP_USE_EEPROM > 0 - #include "StreamUtils.h" // For EEPromStream +#include "StreamUtils.h" // For EEPromStream #endif #include "lvgl.h" @@ -17,13 +17,13 @@ #include "hasp_conf.h" #if HASP_USE_DEBUG > 0 - #include "../hasp_debug.h" +#include "../hasp_debug.h" #endif #if HASP_USE_CONFIG > 0 - #include "lv_fs_if.h" - #include "hasp_gui.h" - #include "hasp_config.h" +#include "lv_fs_if.h" +#include "hasp_gui.h" +#include "hasp_config.h" //#include "hasp_filesystem.h" included in hasp_conf.h #endif @@ -32,10 +32,11 @@ #include "hasp_attribute.h" #include "hasp.h" +#include "dev/device.h" #include "lv_theme_hasp.h" #if HASP_USE_EEPROM > 0 - #include "EEPROM.h" +#include "EEPROM.h" #endif //#if LV_USE_HASP @@ -298,7 +299,7 @@ void haspProgressMsg(const char * msg) #ifdef ARDUINO // Sets the value string of the global progress bar -void haspProgressMsg(const __FlashStringHelper *msg) +void haspProgressMsg(const __FlashStringHelper * msg) { haspProgressMsg(String(msg).c_str()); } @@ -322,7 +323,7 @@ static void custom_font_apply_cb(lv_theme_t * th, lv_obj_t * obj, lv_theme_style */ void haspSetup(void) { - guiSetDim(haspStartDim); + haspDevice.set_backlight_level(haspStartDim); /******* File System Test ********************************************************************/ // lv_fs_file_t f; @@ -355,7 +356,7 @@ void haspSetup(void) /* ********** Font Initializations ********** */ #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) lv_zifont_init(); if(lv_zifont_font_init(&haspFonts[1], haspZiFontPath, 32) != 0) { @@ -364,7 +365,7 @@ void haspSetup(void) } else { // defaultFont = haspFonts[0]; } - #endif +#endif #endif // haspFonts[0] = lv_font_load("E:/font_1.fnt"); @@ -589,12 +590,12 @@ void haspLoadPage(const char * pagesfile) LOG_INFO(TAG_HASP, F("File %s loaded"), pagesfile); #else - #if HASP_USE_EEPROM > 0 +#if HASP_USE_EEPROM > 0 LOG_TRACE(TAG_HASP, F("Loading jsonl from EEPROM...")); EepromStream eepromStream(4096, 1024); dispatch_parse_jsonl(eepromStream); LOG_INFO(TAG_HASP, F("Loaded jsonl from EEPROM")); - #endif +#endif #endif } diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 22927d7c..2931e518 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -13,33 +13,35 @@ #include "hasp_parser.h" #include "hasp_attribute.h" +#include "dev/device.h" + //#include "hasp_gui.h" #if HASP_USE_DEBUG > 0 - #include "../hasp_debug.h" +#include "../hasp_debug.h" - #if WINDOWS - #include - #include - #include - #include "../mqtt/hasp_mqtt.h" - #else - #include "StringStream.h" - #include "CharStream.h" +#if WINDOWS +#include +#include +#include +#include "../mqtt/hasp_mqtt.h" +#else +#include "StringStream.h" +#include "CharStream.h" - #include "hasp_oobe.h" - #include "hasp_gui.h" // for screenshot - #include "sys/gpio/hasp_gpio.h" - #include "hal/hasp_hal.h" +#include "hasp_oobe.h" +#include "hasp_gui.h" // for screenshot +#include "sys/gpio/hasp_gpio.h" +#include "hal/hasp_hal.h" - #include "svc/hasp_ota.h" - #include "mqtt/hasp_mqtt.h" - #include "sys/net/hasp_network.h" // for network_get_status() - #endif +#include "svc/hasp_ota.h" +#include "mqtt/hasp_mqtt.h" +#include "sys/net/hasp_network.h" // for network_get_status() +#endif #endif #if HASP_USE_CONFIG > 0 - #include "hasp_config.h" +#include "hasp_config.h" #endif extern uint8_t hasp_sleep_state; @@ -227,14 +229,14 @@ void dispatch_command(const char * topic, const char * payload) #if HASP_USE_CONFIG > 0 - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 } else if(!strcmp_P(topic, FP_CONFIG_SSID) || !strcmp_P(topic, FP_CONFIG_PASS)) { StaticJsonDocument<64> settings; settings[topic] = payload; wifiSetConfig(settings.as()); - #endif // HASP_USE_WIFI +#endif // HASP_USE_WIFI - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 } else if(!strcmp_P(topic, PSTR("mqtthost")) || !strcmp_P(topic, PSTR("mqttport")) || !strcmp_P(topic, PSTR("mqttport")) || !strcmp_P(topic, PSTR("mqttuser")) || !strcmp_P(topic, PSTR("hostname"))) { @@ -245,7 +247,7 @@ void dispatch_command(const char * topic, const char * payload) StaticJsonDocument<64> settings; settings[topic + 4] = payload; mqttSetConfig(settings.as()); - #endif // HASP_USE_MQTT +#endif // HASP_USE_MQTT #endif // HASP_USE_CONFIG @@ -425,42 +427,42 @@ static void dispatch_config(const char * topic, const char * payload) haspGetConfig(settings); } - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 else if(strcasecmp_P(topic, PSTR("wifi")) == 0) { if(update) wifiSetConfig(settings); else wifiGetConfig(settings); } - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 else if(strcasecmp_P(topic, PSTR("mqtt")) == 0) { if(update) mqttSetConfig(settings); else mqttGetConfig(settings); } - #endif - #if HASP_USE_TELNET > 0 - // else if(strcasecmp_P(topic, PSTR("telnet")) == 0) - // telnetGetConfig(settings[F("telnet")]); - #endif - #if HASP_USE_MDNS > 0 +#endif +#if HASP_USE_TELNET > 0 + // else if(strcasecmp_P(topic, PSTR("telnet")) == 0) + // telnetGetConfig(settings[F("telnet")]); +#endif +#if HASP_USE_MDNS > 0 else if(strcasecmp_P(topic, PSTR("mdns")) == 0) { if(update) mdnsSetConfig(settings); else mdnsGetConfig(settings); } - #endif - #if HASP_USE_HTTP > 0 +#endif +#if HASP_USE_HTTP > 0 else if(strcasecmp_P(topic, PSTR("http")) == 0) { if(update) httpSetConfig(settings); else httpGetConfig(settings); } - #endif - #endif +#endif +#endif // Send output if(!update) { @@ -532,9 +534,9 @@ void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid) dispatch_get_event_name(eventid, event, sizeof(event)); snprintf_P(payload, sizeof(payload), PSTR("{\"pin\":%d,\"group\":%d,\"event\":\"%s\"}"), pin, group, event); - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 mqtt_send_state(F("input"), payload); - #endif +#endif // update outputstates // dispatch_group_onoff(group, dispatch_get_event_state(eventid), NULL); @@ -572,12 +574,12 @@ static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, cons #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) LOG_TRACE(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload); #else - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 mqtt_send_state(subtopic, payload); - #endif - #if HASP_USE_TASMOTA_SLAVE > 0 +#endif +#if HASP_USE_TASMOTA_SLAVE > 0 slave_send_state(subtopic, payload); - #endif +#endif #endif } @@ -774,10 +776,10 @@ void dispatch_clear_page(const char *, const char * page) void dispatch_dim(const char *, const char * level) { // Set the current state - if(strlen(level) != 0) guiSetDim(atoi(level)); + if(strlen(level) != 0) haspDevice.set_backlight_level(atoi(level)); char payload[5]; - itoa(guiGetDim(), payload, DEC); + itoa(haspDevice.get_backlight_level(), payload, DEC); dispatch_state_msg(F("dim"), payload); } @@ -833,11 +835,11 @@ void dispatch_moodlight(const char * topic, const char * payload) void dispatch_backlight(const char *, const char * payload) { // Set the current state - if(strlen(payload) != 0) guiSetBacklight(Utilities::is_true(payload)); + if(strlen(payload) != 0) haspDevice.set_backlight_power(Utilities::is_true(payload)); // Return the current state char buffer[4]; - memcpy_P(buffer, guiGetBacklight() ? PSTR("ON") : PSTR("OFF"), sizeof(buffer)); + memcpy_P(buffer, haspDevice.get_backlight_power() ? PSTR("ON") : PSTR("OFF"), sizeof(buffer)); dispatch_state_msg(F("light"), buffer); } @@ -1012,7 +1014,7 @@ void everySecond() } } #else - #include +#include std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); void everySecond() { From 0c927a67d78a8df938d65636e65c1b3623ba1233 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 03:40:47 +0100 Subject: [PATCH 034/236] Use device and code clean-up --- src/hasp_gui.cpp | 320 ++++++++++++++-------------------------------- src/hasp_gui.h | 8 +- src/hasp_oobe.cpp | 67 +++++----- 3 files changed, 131 insertions(+), 264 deletions(-) diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index bbc1780b..f96e874f 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -28,7 +28,7 @@ //#include "Ticker.h" #if HASP_USE_PNGDECODE > 0 - #include "png_decoder.h" +#include "png_decoder.h" #endif #define BACKLIGHT_CHANNEL 0 // pwm channel 0-15 @@ -40,26 +40,19 @@ File pFileOut; #define LVGL_TICK_PERIOD 20 #ifndef TFT_BCKL - #define TFT_BCKL -1 // No Backlight Control +#define TFT_BCKL -1 // No Backlight Control #endif #ifndef TFT_ROTATION - #define TFT_ROTATION 0 +#define TFT_ROTATION 0 #endif #ifndef INVERT_COLORS - #define INVERT_COLORS 0 +#define INVERT_COLORS 0 #endif // static void IRAM_ATTR lv_tick_handler(void); -// static bool guiShowPointer = false; -// static int8_t guiBacklightPin = TFT_BCKL; -// static uint8_t guiTickPeriod = 20; -// static uint8_t guiRotation = TFT_ROTATION; -// static uint8_t guiInvertDisplay = INVERT_COLORS; -// static uint16_t calData[5] = {0, 65535, 0, 65535, 0}; - -gui_conf_t gui_settings = {.show_pointer = false, - .backlight_pin =TFT_BCKL, +gui_conf_t gui_settings = {.show_pointer = false, + .backlight_pin = TFT_BCKL, .rotation = TFT_ROTATION, .invert_display = INVERT_COLORS, .cal_data = {0, 65535, 0, 65535, 0}}; @@ -81,159 +74,12 @@ bool guiBacklightIsOn; // lv_tick_inc(LVGL_TICK_PERIOD); // } -/* Reading input device (simulated encoder here) */ -/*bool read_encoder(lv_indev_drv_t * indev, lv_indev_data_t * data) -{ - static int32_t last_diff = 0; - int32_t diff = 0; // Dummy - no movement - int btn_state = LV_INDEV_STATE_REL; // Dummy - no press - - data->enc_diff = diff - last_diff; - data->state = btn_state; - last_diff = diff; - return false; -}*/ - -// #define _RAWERR 20 // Deadband error allowed in successive position samples -// uint8_t validTouch(uint16_t * x, uint16_t * y, uint16_t threshold) -// { -// uint16_t x_tmp, y_tmp, x_tmp2, y_tmp2; - -// // Wait until pressure stops increasing to debounce pressure -// uint16_t z1 = 1; -// uint16_t z2 = 0; -// while(z1 > z2) { -// z2 = z1; -// z1 = tft.getTouchRawZ(); -// delay(1); -// } - -// // Serial.print("Z = ");Serial.println(z1); - -// if(z1 <= threshold) return false; - -// tft.getTouchRaw(&x_tmp, &y_tmp); - -// // Serial.print("Sample 1 x,y = "); Serial.print(x_tmp);Serial.print(",");Serial.print(y_tmp); -// // Serial.print(", Z = ");Serial.println(z1); - -// delay(1); // Small delay to the next sample -// if(tft.getTouchRawZ() <= threshold) return false; - -// delay(2); // Small delay to the next sample -// tft.getTouchRaw(&x_tmp2, &y_tmp2); - -// // Serial.print("Sample 2 x,y = "); Serial.print(x_tmp2);Serial.print(",");Serial.println(y_tmp2); -// // Serial.print("Sample difference = ");Serial.print(abs(x_tmp - -// // x_tmp2));Serial.print(",");Serial.println(abs(y_tmp - y_tmp2)); - -// if(abs(x_tmp - x_tmp2) > _RAWERR) return false; -// if(abs(y_tmp - y_tmp2) > _RAWERR) return false; - -// *x = x_tmp; -// *y = y_tmp; - -// return true; -// } - -// bool gui_touchpad_read_raw(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) -// { -// #ifdef TOUCH_CS -// uint16_t touchX, touchY; - -// bool touched = validTouch(&touchX, &touchY, 600u / 2); -// if(!touched) return false; - -// // if(touchCounter < 255) { -// // touchCounter++; - -// // // Store the raw touches -// // if(touchCounter >= 8) { -// // touchPoints[touchCorner].x /= touchCounter; -// // touchPoints[touchCorner].y /= touchCounter; -// // touchCounter = 255; -// // } else { -// // touchPoints[touchCorner].x += touchX; -// // touchPoints[touchCorner].y += touchY; -// // } -// // } - -// if(sleep_state > 0) hasp_update_sleep_state(); // update Idle - -// /*Save the state and save the pressed coordinate*/ -// // lv_disp_t * disp = lv_disp_get_default(); -// data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; -// data->point.x = touchX; // 20 + (disp->driver.hor_res - 40) * (touchCorner % 2); -// data->point.y = touchY; // 20 + (disp->driver.ver_res - 40) * (touchCorner / 2); - -// LOG_VERBOSE(TAG_GUI,F("Calibrate touch %u / %u"), touchX, touchY); - -// #endif - -// return false; /*Return `false` because we are not buffering and no more data to read*/ -// } - -#if TOUCH_DRIVER == 0xADC // Analog Digital Touch Conroller - #include "Touchscreen.h" // For Uno Shield or ADC based resistive touchscreens - -boolean Touch_getXY(uint16_t * x, uint16_t * y, boolean showTouch) -{ - static const int coords[] = {3800, 500, 300, 3800}; // portrait - left, right, top, bottom - static const int XP = 27, XM = 15, YP = 4, YM = 14; // default ESP32 Uno touchscreen pins - static TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); - TSPoint p = ts.getPoint(); - int z1 = analogRead(aXM); - int z2 = analogRead(aYP); - Serial.print(p.x); - Serial.print(" - "); - Serial.print(p.y); - Serial.print(" - "); - Serial.print(p.z); - Serial.print(" - "); - Serial.print(z1); - Serial.print(" - "); - Serial.println(z2); - - pinMode(aYP, OUTPUT); // restore shared pins - pinMode(aXM, OUTPUT); - digitalWrite(aYP, HIGH); // because TFT control pins - digitalWrite(aXM, HIGH); - // adjust pressure sensitivity - note works 'backwards' - #define MINPRESSURE 200 - #define MAXPRESSURE 1000 - bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE); - if(pressed) { - - switch(gui_settings.rotation) { - case 0: // portrait - *x = map(p.x, coords[0], coords[1], 0, tft.width()); - *y = map(p.y, coords[2], coords[3], 0, tft.height()); - break; - case 1: // landscape - *x = map(p.y, coords[1], coords[0], 0, tft.width()); - *y = map(p.x, coords[2], coords[3], 0, tft.height()); - break; - case 2: // portrait inverted - *x = map(p.x, coords[1], coords[0], 0, tft.width()); - *y = map(p.y, coords[3], coords[2], 0, tft.height()); - break; - case 3: // landscape inverted - *x = map(p.y, coords[0], coords[1], 0, tft.width()); - *y = map(p.x, coords[3], coords[2], 0, tft.height()); - break; - } - // if(showTouch) tft.fillCircle(*x, *y, 2, YELLOW); - } - return pressed; -} -#endif - void guiCalibrate() { #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 - #ifdef TOUCH_CS +#ifdef TOUCH_CS tft_espi_calibrate(gui_settings.cal_data); - #endif +#endif for(int i = 0; i < 5; i++) { Serial.print(gui_settings.cal_data[i]); @@ -247,19 +93,23 @@ void guiCalibrate() void guiSetup() { - /* Initialize the Virtual Device Buffers */ -#if defined(ARDUINO_ARCH_ESP32) - /* allocate on iram (or psram ?) */ + // Register logger to capture lvgl_init output + LOG_TRACE(TAG_LVGL, F(D_SERVICE_STARTING)); +#if LV_USE_LOG != 0 + lv_log_register_print_cb(debugLvglLogEvent); +#endif - #ifdef USE_DMA_TO_TFT - static lv_disp_buf_t disp_buf; + /* Create the Virtual Device Buffers */ +#if defined(ARDUINO_ARCH_ESP32) + +#ifdef USE_DMA_TO_TFT static lv_color_t *guiVdbBuffer1, *guiVdbBuffer2 = NULL; // DMA: len must be less than 32767 size_t guiVDBsize = 15 * 1024u; // 30 KBytes guiVdbBuffer1 = (lv_color_t *)heap_caps_calloc(guiVDBsize, sizeof(lv_color_t), MALLOC_CAP_DMA); - // guiVdbBuffer2 = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * guiVDBsize, MALLOC_CAP_DMA); - // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize); - #else + // guiVdbBuffer2 = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * guiVDBsize, MALLOC_CAP_DMA); + // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize); +#else static lv_color_t * guiVdbBuffer1; size_t guiVDBsize = 16 * 1024u; // 32 KBytes @@ -269,10 +119,11 @@ void guiSetup() guiVdbBuffer1 = (lv_color_t *)calloc(guiVDBsize, sizeof(lv_color_t)); } - #endif +#endif // static lv_color_t * guiVdbBuffer2 = (lv_color_t *)malloc(sizeof(lv_color_t) * guiVDBsize); // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize); + #elif defined(ARDUINO_ARCH_ESP8266) /* allocate on heap */ // static lv_color_t guiVdbBuffer1[2 * 512u]; // 4 KBytes @@ -282,6 +133,19 @@ void guiSetup() static lv_color_t * guiVdbBuffer1; size_t guiVDBsize = 2 * 512u; // 4 KBytes * 2 guiVdbBuffer1 = (lv_color_t *)malloc(sizeof(lv_color_t) * guiVDBsize); + +#elif defined(WINDOWS) + static lv_color_t buf[LV_HOR_RES_MAX * 10]; /*Declare a buffer for 10 lines*/ + lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/ + + lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); /*Basic initialization*/ + disp_drv.flush_cb = monitor_flush; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/ + disp_drv.buffer = &disp_buf; + // disp_drv.disp_fill = monitor_fill; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ + // disp_drv.disp_map = monitor_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ + lv_disp_drv_register(&disp_drv); + #else static lv_color_t guiVdbBuffer1[16 * 512u]; // 16 KBytes // static lv_color_t guiVdbBuffer2[16 * 512u]; // 16 KBytes @@ -289,15 +153,38 @@ void guiSetup() // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize); #endif - if(!guiVdbBuffer1) { - LOG_ERROR(TAG_GUI, F("Gram out of memory")); + /* Initialize lvgl */ + static lv_disp_buf_t disp_buf; + if(guiVdbBuffer1 && guiVDBsize > 0) { + lv_init(); + lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize); + } else { + LOG_FATAL(TAG_GUI, F(D_ERROR_OUT_OF_MEMORY)); } - static lv_disp_buf_t disp_buf; - lv_init(); - lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize); + /* Initialize the display driver */ + lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); + disp_drv.buffer = &disp_buf; - /* Initialize Filesystems */ + drv_display_init(&disp_drv, gui_settings.rotation, + gui_settings.invert_display); // Set display driver callback & rotation + disp_drv.hor_res = TFT_WIDTH; + disp_drv.ver_res = TFT_HEIGHT; + lv_disp_t * display = lv_disp_drv_register(&disp_drv); + + switch(gui_settings.rotation) { + case 1: + case 3: + case 5: + case 7: + lv_disp_set_rotation(display, LV_DISP_ROT_90); + break; + default: + lv_disp_set_rotation(display, LV_DISP_ROT_NONE); + } + + /* Initialize Filesystems */ #if LV_USE_FS_IF != 0 _lv_fs_init(); // lvgl File System lv_fs_if_init(); // auxilary file system drivers @@ -335,47 +222,6 @@ void guiSetup() #endif LOG_VERBOSE(TAG_LVGL, F("VFB size : %d"), (size_t)sizeof(lv_color_t) * guiVDBsize); -#if LV_USE_LOG != 0 - LOG_TRACE(TAG_LVGL, F("Registering lvgl logging handler")); - lv_log_register_print_cb(debugLvglLogEvent); -#endif - - /* Initialize the display driver */ - lv_disp_drv_t disp_drv; - lv_disp_drv_init(&disp_drv); - drv_display_init(&disp_drv, gui_settings.rotation, - gui_settings.invert_display); // Set display driver callback & rotation - disp_drv.buffer = &disp_buf; - - if(gui_settings.rotation == 0 || gui_settings.rotation == 2 || gui_settings.rotation == 4 || - gui_settings.rotation == 6) { - /* 1/3=Landscape or 0/2=Portrait orientation */ - // Normal width & height - disp_drv.hor_res = TFT_WIDTH; - disp_drv.ver_res = TFT_HEIGHT; - } else { - // Swapped width & height - disp_drv.hor_res = TFT_HEIGHT; - disp_drv.ver_res = TFT_WIDTH; - } - lv_disp_drv_register(&disp_drv); - - /* Initialize Global progress bar*/ - lv_obj_t * bar = lv_bar_create(lv_layer_sys(), NULL); - lv_obj_set_hidden(bar, true); - lv_bar_set_range(bar, 0, 100); - lv_bar_set_value(bar, 10, LV_ANIM_OFF); - lv_obj_set_size(bar, 200, 15); - lv_obj_align(bar, lv_layer_sys(), LV_ALIGN_CENTER, 0, -10); - lv_obj_user_data_t udata = (lv_obj_user_data_t){10, 0, 10}; - lv_obj_set_user_data(bar, udata); - lv_obj_set_style_local_value_color(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_obj_set_style_local_value_align(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_ALIGN_CENTER); - lv_obj_set_style_local_value_ofs_y(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_value_font(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_FONT_DEFAULT); - lv_obj_set_style_local_bg_color(lv_layer_sys(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); - lv_obj_set_style_local_bg_opa(lv_layer_sys(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0); - /* Initialize the touch pad */ lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); @@ -409,6 +255,22 @@ void guiSetup() } drv_touch_init(gui_settings.rotation); // Touch driver + /* Initialize Global progress bar*/ + lv_obj_user_data_t udata = (lv_obj_user_data_t){10, 0, 10}; + lv_obj_t * bar = lv_bar_create(lv_layer_sys(), NULL); + lv_obj_set_user_data(bar, udata); + lv_obj_set_hidden(bar, true); + lv_bar_set_range(bar, 0, 100); + lv_bar_set_value(bar, 10, LV_ANIM_OFF); + lv_obj_set_size(bar, 200, 15); + lv_obj_align(bar, lv_layer_sys(), LV_ALIGN_CENTER, 0, -10); + lv_obj_set_style_local_value_color(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_value_align(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_ALIGN_CENTER); + lv_obj_set_style_local_value_ofs_y(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, 20); + lv_obj_set_style_local_value_font(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_FONT_DEFAULT); + lv_obj_set_style_local_bg_color(lv_layer_sys(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_bg_opa(lv_layer_sys(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0); + // guiStart(); // Ticker } @@ -448,6 +310,7 @@ void guiStop() } //////////////////////////////////////////////////////////////////////////////////////////////////// +/* bool guiGetBacklight() { return guiBacklightIsOn; @@ -495,6 +358,7 @@ int8_t guiGetDim() { return guiDimLevel; } +*/ //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_CONFIG > 0 @@ -537,9 +401,9 @@ bool guiGetConfig(const JsonObject & settings) } else { changed = true; - #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) +#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) tft_espi_set_touch(gui_settings.cal_data); - #endif +#endif } i++; } @@ -552,9 +416,9 @@ bool guiGetConfig(const JsonObject & settings) } changed = true; - #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) +#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) tft_espi_set_touch(gui_settings.cal_data); - #endif +#endif } if(changed) configOutput(settings, TAG_GUI); @@ -578,7 +442,7 @@ bool guiSetConfig(const JsonObject & settings) hasp_get_sleep_time(guiSleepTime1, guiSleepTime2); - // changed |= configSet(guiTickPeriod, settings[FPSTR(FP_GUI_TICKPERIOD)], F("guiTickPeriod")); + // changed |= configSet(guiTickPeriod, settings[FPSTR(FP_GUI_TICKPERIOD)], F("guiTickPeriod")); changed |= configSet(gui_settings.backlight_pin, settings[FPSTR(FP_GUI_BACKLIGHTPIN)], F("guiBacklightPin")); changed |= configSet(guiSleepTime1, settings[FPSTR(FP_GUI_IDLEPERIOD1)], F("guiSleepTime1")); changed |= configSet(guiSleepTime2, settings[FPSTR(FP_GUI_IDLEPERIOD2)], F("guiSleepTime2")); @@ -609,8 +473,10 @@ bool guiSetConfig(const JsonObject & settings) i++; } - if(gui_settings.cal_data[0] != 0 || gui_settings.cal_data[1] != 65535 || gui_settings.cal_data[2] != 0 || gui_settings.cal_data[3] != 65535) { - LOG_VERBOSE(TAG_GUI, F("calData set [%u, %u, %u, %u, %u]"), gui_settings.cal_data[0], gui_settings.cal_data[1], gui_settings.cal_data[2], gui_settings.cal_data[3], + if(gui_settings.cal_data[0] != 0 || gui_settings.cal_data[1] != 65535 || gui_settings.cal_data[2] != 0 || + gui_settings.cal_data[3] != 65535) { + LOG_VERBOSE(TAG_GUI, F("calData set [%u, %u, %u, %u, %u]"), gui_settings.cal_data[0], + gui_settings.cal_data[1], gui_settings.cal_data[2], gui_settings.cal_data[3], gui_settings.cal_data[4]); oobeSetAutoCalibrate(false); } else { @@ -618,9 +484,9 @@ bool guiSetConfig(const JsonObject & settings) oobeSetAutoCalibrate(true); } - #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) +#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS) if(status) tft_espi_set_touch(gui_settings.cal_data); - #endif +#endif changed |= status; } diff --git a/src/hasp_gui.h b/src/hasp_gui.h index 170c1e8c..bc2f29de 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -29,10 +29,10 @@ void guiTakeScreenshot(const char * pFileName); // to file void guiTakeScreenshot(); // webclient /* ===== Getter and Setter Functions ===== */ -void guiSetDim(int8_t level); -int8_t guiGetDim(); -void guiSetBacklight(bool lighton); -bool guiGetBacklight(); +// void guiSetDim(int8_t level); +// int8_t guiGetDim(); +// void guiSetBacklight(bool lighton); +// bool guiGetBacklight(); /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index e1424ff1..b3748dea 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -3,27 +3,28 @@ #if HASP_USE_CONFIG > 0 - #include "hasp_conf.h" +#include "hasp_conf.h" - #include "lvgl.h" - #if LVGL_VERSION_MAJOR != 7 - #include "../lv_components.h" - #endif +#include "lvgl.h" +#if LVGL_VERSION_MAJOR != 7 +#include "../lv_components.h" +#endif - #include "hasp_gui.h" - #include "hasp_config.h" +#include "hasp_gui.h" +#include "hasp_config.h" - #include "sys/net/hasp_wifi.h" - #include "hasp/hasp_dispatch.h" - #include "hasp/hasp_object.h" +#include "sys/net/hasp_wifi.h" +#include "hasp/hasp_dispatch.h" +#include "hasp/hasp_object.h" +#include "dev/device.h" static bool oobeAutoCalibrate = true; - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 - #if HASP_USE_QRCODE > 0 - #include "lv_qrcode.h" - #endif +#if HASP_USE_QRCODE > 0 +#include "lv_qrcode.h" +#endif static lv_obj_t * oobepage[2]; static lv_obj_t * oobekb; @@ -125,10 +126,10 @@ static void oobeSetupQR(const char * ssid, const char * pass) char buffer[128]; lv_obj_t * container = lv_cont_create(oobepage[0], NULL); lv_obj_set_pos(container, 5, 5); - // lv_obj_set_style_local_bg_opa(container, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); - // lv_obj_set_style_local_border_opa(container, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); + // lv_obj_set_style_local_bg_opa(container, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); + // lv_obj_set_style_local_border_opa(container, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); - #if HASP_USE_QRCODE > 0 +#if HASP_USE_QRCODE > 0 snprintf_P(buffer, sizeof(buffer), PSTR("WIFI:S:%s;T:WPA;P:%s;;"), ssid, pass); lv_obj_t * qr = lv_qrcode_create(oobepage[0], 120, LV_COLOR_BLACK, LV_COLOR_WHITE); @@ -148,10 +149,10 @@ static void oobeSetupQR(const char * ssid, const char * pass) lv_obj_align(qrlabel, qr, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); } - #else +#else lv_obj_set_size(container, disp->driver.hor_res, disp->driver.ver_res); - #endif +#endif lv_obj_t * aplabel = lv_label_create(container, NULL); snprintf_P(buffer, sizeof(buffer), PSTR(D_OOBE_MSG)); @@ -257,12 +258,12 @@ static void oobeSetupSsid(void) lv_label_set_text(oneline_label, buffer); lv_obj_align(oneline_label, oneline_ta, labelpos, 0, 0); - /* Create a keyboard and make it fill the width of the above text areas */ - #if LVGL_VERSION_MAJOR == 8 +/* Create a keyboard and make it fill the width of the above text areas */ +#if LVGL_VERSION_MAJOR == 8 oobekb = lv_keyboard_create(oobepage[1]); - #else +#else oobekb = lv_keyboard_create(oobepage[1], NULL); - #endif +#endif lv_obj_set_style_local_pad_inner(oobekb, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 0); lv_obj_set_style_local_border_width(oobekb, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 0); @@ -289,7 +290,7 @@ static void oobe_calibrate_cb(lv_obj_t * ta, lv_event_t event) { if(event == LV_EVENT_CLICKED) { if(oobeAutoCalibrate) { - guiSetDim(100); + haspDevice.set_backlight_level(100); guiCalibrate(); oobeAutoCalibrate = false; lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); @@ -300,7 +301,7 @@ static void oobe_calibrate_cb(lv_obj_t * ta, lv_event_t event) } } } - #endif // HASP_USE_WIFI +#endif // HASP_USE_WIFI void oobeSetAutoCalibrate(bool cal) { @@ -309,15 +310,15 @@ void oobeSetAutoCalibrate(bool cal) bool oobeSetup() { - #if HASP_USE_ETHERNET > 0 +#if HASP_USE_ETHERNET > 0 if(eth_connected) return false; - #endif - #if HASP_USE_WIFI > 0 +#endif +#if HASP_USE_WIFI > 0 char ssid[32]; char pass[32]; if(wifiShowAP(ssid, pass)) { - guiSetDim(100); + haspDevice.set_backlight_level(100); oobeSetupQR(ssid, pass); oobeSetupSsid(); @@ -334,18 +335,18 @@ bool oobeSetup() } else { return false; } - #endif +#endif return false; } // Thist is used for testing only !! void oobeFakeSetup(const char *, const char *) { - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 char ssid[32] = "HASP-ABCDEF"; char pass[32] = "haspadmin"; - guiSetDim(100); + haspDevice.set_backlight_level(100); oobeSetupQR(ssid, pass); oobeSetupSsid(); oobeSetPage(0); @@ -359,6 +360,6 @@ void oobeFakeSetup(const char *, const char *) } else { LOG_INFO(TAG_OOBE, F(D_OOBE_CALIBRATED)); } - #endif +#endif } #endif // HASP_USE_CONFIG \ No newline at end of file From 79467a8846f58381123475b7675438245374aff5 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 03:41:08 +0100 Subject: [PATCH 035/236] Minor tweaks --- src/main_arduino.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 2a68517f..89b492c6 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -8,12 +8,12 @@ #include "hasp_conf.h" // load first #if HASP_USE_CONFIG > 0 - #include "hasp_debug.h" +#include "hasp_debug.h" #endif #if HASP_USE_CONFIG > 0 - #include "hasp_config.h" - #include "hasp_gui.h" +#include "hasp_config.h" +#include "hasp_gui.h" #endif #include "hasp_oobe.h" @@ -31,6 +31,8 @@ unsigned long mainLastLoopTime = 0; void setup() { + // hal_setup(); + haspDevice.pre_setup(); /**************************** From b4a901ef9acc32e481075c912368c264b24298e9 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 03:41:37 +0100 Subject: [PATCH 036/236] Update driver path --- src/drv/hasp_drv_touch.cpp | 30 +++++++++++++++--------------- src/drv/touch/hasp_drv_ft5206.h | 4 ++-- src/drv/touch/hasp_drv_ft6336u.h | 2 +- src/drv/touch/hasp_drv_gt911.h | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/drv/hasp_drv_touch.cpp b/src/drv/hasp_drv_touch.cpp index bb311480..28bafd31 100644 --- a/src/drv/hasp_drv_touch.cpp +++ b/src/drv/hasp_drv_touch.cpp @@ -3,23 +3,23 @@ #include "lvgl.h" #if TOUCH_DRIVER == 2046 - #if defined(USE_FSMC) - #else - #include "tft_espi_drv.h" - #endif +#if defined(USE_FSMC) +#else +#include "tft_espi_drv.h" +#endif #elif TOUCH_DRIVER == 2046 - #include "indev/XPT2046.h" +#include "indev/XPT2046.h" #elif TOUCH_DRIVER == 0x2046B - #include "hasp_drv_xpt2046.h" +#include "drv/touch/hasp_drv_xpt2046.h" #elif TOUCH_DRIVER == 911 - #include "hasp_drv_gt911.h" +#include "drv/touch/hasp_drv_gt911.h" #elif TOUCH_DRIVER == 0xADC - #include "hasp_drv_ft6336u.h" +#include "drv/touch/hasp_drv_ft6336u.h" #elif TOUCH_DRIVER == 5206 - #include "hasp_drv_ft5206.h" +#include "drv/touch/hasp_drv_ft5206.h" #elif TOUCH_DRIVER == 6336 - #include "hasp_drv_ft6336u.h" +#include "drv/touch/hasp_drv_ft6336u.h" #else //#include "tp_i2c.h" //#include "ft6x36.h" @@ -34,12 +34,12 @@ void drv_touch_init(uint8_t rotation) drv_touch_rotation = rotation; #if TOUCH_DRIVER == 2046 // XPT2046 Resistive touch panel driver - #if defined(USE_FSMC) +#if defined(USE_FSMC) xpt2046_init(rotation); - #else - // The display driver takes care of all initializations - // tft_espi_init(rotation); - #endif +#else + // The display driver takes care of all initializations + // tft_espi_init(rotation); +#endif #elif TOUCH_DRIVER == 911 GT911_init(); diff --git a/src/drv/touch/hasp_drv_ft5206.h b/src/drv/touch/hasp_drv_ft5206.h index 88c6eb3f..9f1d9786 100644 --- a/src/drv/touch/hasp_drv_ft5206.h +++ b/src/drv/touch/hasp_drv_ft5206.h @@ -6,9 +6,9 @@ #if TOUCH_DRIVER == 5206 - #define FT5206_address 0x38 +#define FT5206_address 0x38 - #include "log/hasp_debug.h" // for TAG_DRVR +#include "hasp_debug.h" // for TAG_DRVR bool FT5206_getXY(int16_t * touchX, int16_t * touchY, bool debug); void FT5206_init(); diff --git a/src/drv/touch/hasp_drv_ft6336u.h b/src/drv/touch/hasp_drv_ft6336u.h index ac1dd47a..652ca87b 100644 --- a/src/drv/touch/hasp_drv_ft6336u.h +++ b/src/drv/touch/hasp_drv_ft6336u.h @@ -6,7 +6,7 @@ #if TOUCH_DRIVER == 6336 - #include "log/hasp_debug.h" // for TAG_DRVR +#include "hasp_debug.h" // for TAG_DRVR bool FT6336U_getXY(int16_t * touchX, int16_t * touchY, bool debug); void FT6336U_init(); diff --git a/src/drv/touch/hasp_drv_gt911.h b/src/drv/touch/hasp_drv_gt911.h index ec36b69b..761ae081 100644 --- a/src/drv/touch/hasp_drv_gt911.h +++ b/src/drv/touch/hasp_drv_gt911.h @@ -6,7 +6,7 @@ #if TOUCH_DRIVER == 911 - #include "log/hasp_debug.h" // for TAG_DRVR +#include "hasp_debug.h" // for TAG_DRVR bool GT911_getXY(int16_t * touchX, int16_t * touchY, bool debug); void GT911_init(); From a7e6def45774ed22678d82bdd088319e21a95aaf Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 03:41:56 +0100 Subject: [PATCH 037/236] Re-organize environments --- platformio.ini | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index f1528970..a2d5a969 100644 --- a/platformio.ini +++ b/platformio.ini @@ -74,8 +74,8 @@ lib_deps = git+https://github.com/fvanroie/ConsoleInput.git ;git+https://github.com/andrethomas/TasmotaSlave.git ;git+https://github.com/fvanroie/lv_components.git - ;git+https://github.com/lvgl/lvgl.git - lvgl/lvgl @^7.10.1 ; from PIO library + git+https://github.com/lvgl/lvgl.git + ;lvgl/lvgl @^7.11.0 ; from PIO library ;bodmer/TFT_eSPI @ 2.3.4 ; Tft SPI drivers EXACT version 2.3.5 has compile error git+https://github.com/Bodmer/TFT_eSPI.git ; ------ Unused / Test libraries @@ -93,13 +93,16 @@ extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py [esp32] framework = arduino platform = espressif32 -board = lolin_d32_pro -;upload_port = COM6 ; To change the port, use platform_override.ini -;monitor_port = COM6 ; To change the port, use platform_override.ini -monitor_filters = esp32_exception_decoder board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv + +; ----- crash reporter +monitor_filters = esp32_exception_decoder + +; ----- debugger check_tool = cppcheck check_flags = --enable=all +debug_tool = esp-prog +debug_init_break = tbreak setup build_flags = ${env.build_flags} @@ -156,6 +159,16 @@ hspi = [esp8266] framework = arduino +platform = espressif8266 + +board_build.f_flash = 40000000L +board_build.flash_mode = dout +board_build.ldscript = eagle.flash.4m2m.ld ; 2Mb Spiffs +board_build.f_cpu = 160000000L ; set frequency to 160MHz + +; ----- crash reporter +monitor_filters = esp8266_exception_decoder + build_flags= -D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer -D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages From 09c9e7f066ecc49a0d0a20ccbc8ea09b2eff5283 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 05:16:25 +0100 Subject: [PATCH 038/236] Add memory functions to device class --- lib/lv_drv_tft_espi/tft_espi_drv.cpp | 57 ++--- src/dev/device.h | 14 +- src/dev/esp32/esp32.cpp | 29 ++- src/dev/esp32/esp32.h | 14 +- src/dev/esp32/lanbonl8.h | 2 +- src/dev/esp32/m5stackcore2.h | 2 +- src/dev/esp8266/esp8266.cpp | 22 +- src/dev/esp8266/esp8266.h | 8 + src/hal/hasp_hal.h | 10 +- src/hasp/hasp_dispatch.cpp | 3 +- src/log/hasp_debug.cpp | 63 ++--- src/svc/hasp_http.cpp | 361 ++++++++++++++------------- 12 files changed, 329 insertions(+), 256 deletions(-) diff --git a/lib/lv_drv_tft_espi/tft_espi_drv.cpp b/lib/lv_drv_tft_espi/tft_espi_drv.cpp index 5f05b867..ebc4136b 100644 --- a/lib/lv_drv_tft_espi/tft_espi_drv.cpp +++ b/lib/lv_drv_tft_espi/tft_espi_drv.cpp @@ -7,23 +7,24 @@ * INCLUDES *********************/ #include "../../src/hal/hasp_hal.h" // for halGpioName() +#include "../../src/dev/device.h" #include "tft_espi_drv.h" #include "ArduinoLog.h" #include "hasp_macro.h" #if USE_TFT_ESPI != 0 - #include - #include "TFT_eSPI.h" +#include +#include "TFT_eSPI.h" - #include LV_DRV_DISP_INCLUDE - #include LV_DRV_DELAY_INCLUDE - #include "bootscreen.h" // Sketch tab header for xbm images +#include LV_DRV_DISP_INCLUDE +#include LV_DRV_DELAY_INCLUDE +#include "bootscreen.h" // Sketch tab header for xbm images - /********************* - * DEFINES - *********************/ - #define TAG_TFT 22 +/********************* + * DEFINES + *********************/ +#define TAG_TFT 22 /********************** * TYPEDEFS @@ -54,11 +55,11 @@ static TFT_eSPI tft; */ void tft_espi_init(uint8_t rotation, bool invert_display) { - #ifdef USE_DMA_TO_TFT +#ifdef USE_DMA_TO_TFT // DMA - should work with STM32F2xx/F4xx/F7xx processors // NOTE: >>>>>> DMA IS FOR SPI DISPLAYS ONLY <<<<<< tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767) - #endif +#endif /* TFT init */ tft.begin(); @@ -77,11 +78,11 @@ void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * c /* Update TFT */ tft.startWrite(); /* Start new TFT transaction */ tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */ - #ifdef USE_DMA_TO_TFT +#ifdef USE_DMA_TO_TFT tft.pushPixelsDMA((uint16_t *)color_p, len); /* Write words at once */ - #else +#else tft.pushPixels((uint16_t *)color_p, len); /* Write words at once */ - #endif +#endif tft.endWrite(); /* terminate TFT transaction */ /* Tell lvgl that flushing is done */ @@ -98,7 +99,7 @@ void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * c // tft_espi_flush(x1, y1, x2, y2, color_p); // } - #if defined(TOUCH_CS) +#if defined(TOUCH_CS) void tft_espi_calibrate(uint16_t * calData) { @@ -125,15 +126,15 @@ bool tft_espi_get_touch(int16_t * touchX, int16_t * touchY, uint16_t threshold) { return tft.getTouch((uint16_t *)touchX, (uint16_t *)touchY, threshold); } - #endif +#endif /********************** * STATIC FUNCTIONS **********************/ - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) ADC_MODE(ADC_VCC); // tftShowConfig measures the voltage on the pin - #endif +#endif static void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset) { @@ -160,21 +161,21 @@ static void tftShowConfig(TFT_eSPI & tft) tft.getSetup(tftSetup); LOG_VERBOSE(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str()); - #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) LOG_VERBOSE(TAG_TFT, F("Processor : ESP%x"), tftSetup.esp); - #else +#else LOG_VERBOSE(TAG_TFT, F("Processor : STM%x"), tftSetup.esp); - #endif - LOG_VERBOSE(TAG_TFT, F("CPU freq. : %i MHz"), halGetCpuFreqMHz()); +#endif + LOG_VERBOSE(TAG_TFT, F("CPU freq. : %i MHz"), haspDevice.get_cpu_frequency()); - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) LOG_VERBOSE(TAG_TFT, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined - #endif +#endif LOG_VERBOSE(TAG_TFT, F("Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); LOG_VERBOSE(TAG_TFT, F("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel")); - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) LOG_VERBOSE(TAG_TFT, F("SPI overlap: %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No")); - #endif +#endif if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch { @@ -201,7 +202,7 @@ static void tftShowConfig(TFT_eSPI & tft) tftPinInfo(F("MISO"), tftSetup.pin_tft_miso); tftPinInfo(F("SCLK"), tftSetup.pin_tft_clk); - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) if(tftSetup.overlap == true) { LOG_VERBOSE(TAG_TFT, F("Overlap selected, following pins MUST be used:")); @@ -212,7 +213,7 @@ static void tftShowConfig(TFT_eSPI & tft) LOG_VERBOSE(TAG_TFT, F("TFT_DC and TFT_RST pins can be tftSetup defined")); } - #endif +#endif tftPinInfo(F("TFT_CS"), tftSetup.pin_tft_cs); tftPinInfo(F("TFT_DC"), tftSetup.pin_tft_dc); diff --git a/src/dev/device.h b/src/dev/device.h index 6350dea6..1fa36ea4 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -39,19 +39,27 @@ class BaseDevice { { return true; } + virtual size_t get_free_max_block() + {} + virtual size_t get_free_heap() + {} + virtual uint8_t get_heap_fragmentation() + {} + virtual uint16_t get_cpu_frequency() + {} }; } // namespace dev #if defined(ESP32) #warning Building for ESP32 Devices -#include "dev/esp32/esp32.h" +#include "esp32/esp32.h" #elif defined(ESP8266) #warning Building for ESP8266 Devices -#include "dev/esp8266/esp8266.h" +#include "esp8266/esp8266.h" #elif defined(STM32F4) #warning Building for STM32F4xx Devices -#include "dev/stm32f4.h" +#include "stm32f4/stm32f4.h" #else #warning Building for Generic Devices using dev::BaseDevice; diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index b317aafa..d4f6a9ef 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -4,8 +4,8 @@ #include #include "esp_system.h" -#include "dev/device.h" -#include "dev/esp32/esp32.h" +#include "../device.h" +#include "esp32.h" #include "driver/adc.h" #include "esp_adc_cal.h" @@ -69,6 +69,31 @@ void Esp32Device::update_backlight() } } +size_t Esp32Device::get_free_max_block() +{ + return ESP.getMaxAllocHeap(); +} + +size_t Esp32Device::get_free_heap() +{ + return ESP.getFreeHeap(); +} + +uint8_t Esp32Device::get_heap_fragmentation() +{ + uint32_t free = ESP.getFreeHeap(); + if(free) { + return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)free); + } else { + return 100; // no free memory + } +} + +uint16_t Esp32Device::get_cpu_frequency() +{ + return ESP.getCpuFreqMHz(); +} + } // namespace dev #if defined(LANBONL8) diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 3c9bd449..7c950867 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -4,7 +4,7 @@ #ifndef HASP_DEVICE_ESP32_H #define HASP_DEVICE_ESP32_H -#include "dev/device.h" +#include "../device.h" #if defined(ESP32) @@ -25,6 +25,14 @@ class Esp32Device : public BaseDevice { bool get_backlight_power() override; + size_t get_free_max_block() override; + + size_t get_free_heap() override; + + uint8_t get_heap_fragmentation() override; + + uint16_t get_cpu_frequency() override; + private: uint8_t backlight_pin; uint8_t backlight_level; @@ -39,10 +47,10 @@ using dev::Esp32Device; #if defined(LANBONL8) #warning Building for Lanbon L8 -#include "dev/esp32/lanbonl8.h" +#include "lanbonl8.h" #elif defined(M5STACK) #warning Building for M5Stack core2 -#include "dev/esp32/m5stackcore2.h" +#include "m5stackcore2.h" #else extern dev::Esp32Device haspDevice; #endif diff --git a/src/dev/esp32/lanbonl8.h b/src/dev/esp32/lanbonl8.h index 0c1ffc53..8cf07a5f 100644 --- a/src/dev/esp32/lanbonl8.h +++ b/src/dev/esp32/lanbonl8.h @@ -4,7 +4,7 @@ #ifndef HASP_DEVICE_LANBONL8_H #define HASP_DEVICE_LANBONL8_H -#include "dev/esp32/esp32.h" +#include "esp32.h" #if defined(LANBONL8) diff --git a/src/dev/esp32/m5stackcore2.h b/src/dev/esp32/m5stackcore2.h index 8060530a..12187b5d 100644 --- a/src/dev/esp32/m5stackcore2.h +++ b/src/dev/esp32/m5stackcore2.h @@ -6,7 +6,7 @@ #if defined(M5STACK) -#include "dev/esp32/esp32.h" +#include "esp32.h" namespace dev { diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index 029139eb..95aa5795 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -3,7 +3,7 @@ #include "Arduino.h" #include -#include "dev/esp8266/esp8266.h" +#include "esp8266.h" #include "hasp_conf.h" #include "hasp_debug.h" @@ -59,6 +59,26 @@ void Esp8266Device::update_backlight() analogWrite(backlight_pin, backlight_power ? map(backlight_level, 0, 100, 0, 1023) : 0); } +size_t Esp8266Device::get_free_max_block() +{ + return ESP.getMaxFreeBlockSize(); +} + +size_t Esp8266Device::get_free_heap(void) +{ + return ESP.getFreeHeap(); +} + +uint8_t Esp8266Device::get_heap_fragmentation() +{ + return ESP.getHeapFragmentation(); +} + +uint16_t Esp8266Device::get_cpu_frequency() +{ + return ESP.getCpuFreqMHz(); +} + } // namespace dev dev::Esp8266Device haspDevice; diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index e90b486a..29a57ef3 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -26,6 +26,14 @@ class Esp8266Device : public BaseDevice { bool get_backlight_power() override; + size_t get_free_max_block() override; + + size_t get_free_heap() override; + + uint8_t get_heap_fragmentation() override; + + uint16_t get_cpu_frequency() override; + private: uint8_t backlight_pin; uint8_t backlight_level; diff --git a/src/hal/hasp_hal.h b/src/hal/hasp_hal.h index 5c735bab..0ccd03df 100644 --- a/src/hal/hasp_hal.h +++ b/src/hal/hasp_hal.h @@ -6,15 +6,15 @@ #include -void halRestartMcu(void); -uint8_t halGetHeapFragmentation(void); +// void halRestartMcu(void); String halGetResetInfo(void); -size_t halGetMaxFreeBlock(void); -size_t halGetFreeHeap(void); +// uint8_t halGetHeapFragmentation(void); +// size_t halGetMaxFreeBlock(void); +// size_t halGetFreeHeap(void); String halGetCoreVersion(void); String halGetChipModel(); String halGetMacAddress(int start, const char * seperator); -uint16_t halGetCpuFreqMHz(void); +// uint16_t halGetCpuFreqMHz(void); String halDisplayDriverName(void); String halGpioName(uint8_t gpio); diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 2931e518..77fd108a 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -875,7 +875,8 @@ void dispatch_reboot(bool saveConfig) Serial.flush(); #endif - halRestartMcu(); + // halRestartMcu(); + haspDevice.reboot(); } void dispatch_current_state() diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index 1aece68b..a7183f3a 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -19,15 +19,16 @@ //#include "time.h" #if defined(ARDUINO_ARCH_ESP8266) - #include // sntp_servermode_dhcp() - #include - #include +#include // sntp_servermode_dhcp() +#include +#include #elif defined(ARDUINO_ARCH_ESP32) - #include - #include +#include +#include #endif #include "hasp_conf.h" +#include "dev/device.h" #include "hal/hasp_hal.h" #include "hasp_debug.h" @@ -37,27 +38,27 @@ #include "hasp/hasp.h" #ifdef USE_CONFIG_OVERRIDE - #include "user_config_override.h" +#include "user_config_override.h" #endif #ifndef SERIAL_SPEED - #define SERIAL_SPEED 115200 +#define SERIAL_SPEED 115200 #endif #if HASP_USE_SYSLOG > 0 - #include +#include - #ifndef SYSLOG_SERVER - #define SYSLOG_SERVER "" - #endif +#ifndef SYSLOG_SERVER +#define SYSLOG_SERVER "" +#endif - #ifndef SYSLOG_PORT - #define SYSLOG_PORT 514 - #endif +#ifndef SYSLOG_PORT +#define SYSLOG_PORT 514 +#endif - #ifndef APP_NAME - #define APP_NAME "HASP" - #endif +#ifndef APP_NAME +#define APP_NAME "HASP" +#endif // variables for debug stream writer // static String debugOutput((char *)0); @@ -72,7 +73,7 @@ uint8_t debugSyslogProtocol = 0; // A UDP instance to let us send and receive packets over UDP WiFiUDP * syslogClient; - #define SYSLOG_PROTO_IETF 0 +#define SYSLOG_PROTO_IETF 0 // Create a new syslog instance with LOG_KERN facility // Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN); @@ -207,7 +208,7 @@ bool debugGetConfig(const JsonObject & settings) if(debugTelePeriod != settings[FPSTR(FP_DEBUG_TELEPERIOD)].as()) changed = true; settings[FPSTR(FP_DEBUG_TELEPERIOD)] = debugTelePeriod; - #if HASP_USE_SYSLOG > 0 +#if HASP_USE_SYSLOG > 0 if(strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)].as().c_str()) != 0) changed = true; settings[FPSTR(FP_CONFIG_HOST)] = debugSyslogHost; @@ -219,7 +220,7 @@ bool debugGetConfig(const JsonObject & settings) if(debugSyslogFacility != settings[FPSTR(FP_CONFIG_LOG)].as()) changed = true; settings[FPSTR(FP_CONFIG_LOG)] = debugSyslogFacility; - #endif +#endif if(changed) configOutput(settings, TAG_DEBG); return changed; @@ -244,8 +245,8 @@ bool debugSetConfig(const JsonObject & settings) /* Teleperiod Settings*/ changed |= configSet(debugTelePeriod, settings[FPSTR(FP_DEBUG_TELEPERIOD)], F("debugTelePeriod")); - /* Syslog Settings*/ - #if HASP_USE_SYSLOG > 0 +/* Syslog Settings*/ +#if HASP_USE_SYSLOG > 0 if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) { changed |= strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)]) != 0; strncpy(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)], sizeof(debugSyslogHost)); @@ -253,7 +254,7 @@ bool debugSetConfig(const JsonObject & settings) changed |= configSet(debugSyslogPort, settings[FPSTR(FP_CONFIG_PORT)], F("debugSyslogPort")); changed |= configSet(debugSyslogProtocol, settings[FPSTR(FP_CONFIG_PROTOCOL)], F("debugSyslogProtocol")); changed |= configSet(debugSyslogFacility, settings[FPSTR(FP_CONFIG_LOG)], F("debugSyslogFacility")); - #endif +#endif return changed; } @@ -369,9 +370,9 @@ static void debugPrintTimestamp(int level, Print * _logOutput) static void debugPrintHaspMemory(int level, Print * _logOutput) { - size_t maxfree = halGetMaxFreeBlock(); - uint32_t totalfree = halGetFreeHeap(); - uint8_t frag = halGetHeapFragmentation(); + size_t maxfree = haspDevice.get_free_max_block(); + size_t totalfree = haspDevice.get_free_heap(); + uint8_t frag = haspDevice.get_heap_fragmentation(); /* Print HASP Memory Info */ if(debugAnsiCodes) { @@ -411,7 +412,7 @@ static void debugPrintPriority(int level, Print * _logOutput) // } switch(level) { - case LOG_LEVEL_FATAL...LOG_LEVEL_ERROR: + case LOG_LEVEL_FATAL ... LOG_LEVEL_ERROR: debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); break; case LOG_LEVEL_WARNING: @@ -572,9 +573,9 @@ void debugPrintPrefix(uint8_t tag, int level, Print * _logOutput) } debugPrintHaspMemory(level, _logOutput); - #if LV_MEM_CUSTOM == 0 +#if LV_MEM_CUSTOM == 0 debugPrintLvglMemory(level, _logOutput); - #endif +#endif } return; } @@ -637,10 +638,10 @@ void debugPreSetup(JsonObject settings) if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */ #if defined(STM32F4xx) - #ifndef STM32_SERIAL1 // Define what Serial port to use for log output +#ifndef STM32_SERIAL1 // Define what Serial port to use for log output Serial.setRx(PA3); // User Serial2 Serial.setTx(PA2); - #endif +#endif #endif Serial.begin(baudrate); /* prepare for possible serial debug */ delay(10); diff --git a/src/svc/hasp_http.cpp b/src/svc/hasp_http.cpp index 194805ef..f4751797 100644 --- a/src/svc/hasp_http.cpp +++ b/src/svc/hasp_http.cpp @@ -7,10 +7,11 @@ #include "lvgl.h" #if defined(ARDUINO_ARCH_ESP32) - #include "Update.h" +#include "Update.h" #endif #include "hasp_conf.h" +#include "dev/device.h" #include "hasp_gui.h" #include "hal/hasp_hal.h" @@ -23,9 +24,9 @@ #if HASP_USE_HTTP > 0 - #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) File fsUploadFile; - #endif +#endif //////////////////////////////////////////////////////////////////////////////////////////////////// bool webServerStarted = false; @@ -36,31 +37,31 @@ bool webServerStarted = false; // char httpPassword[32] = ""; hasp_http_config_t http_config; - #define HTTP_PAGE_SIZE (6 * 256) +#define HTTP_PAGE_SIZE (6 * 256) - #if defined(STM32F4xx) && HASP_USE_ETHERNET > 0 - #include +#if defined(STM32F4xx) && HASP_USE_ETHERNET > 0 +#include EthernetWebServer webServer(80); - #endif +#endif - #if defined(STM32F4xx) && HASP_USE_WIFI > 0 - #include +#if defined(STM32F4xx) && HASP_USE_WIFI > 0 +#include // #include EthernetWebServer webServer(80); - #endif +#endif - #if defined(ARDUINO_ARCH_ESP8266) - #include "StringStream.h" - #include - #include +#if defined(ARDUINO_ARCH_ESP8266) +#include "StringStream.h" +#include +#include ESP8266WebServer webServer(80); - #endif +#endif - #if defined(ARDUINO_ARCH_ESP32) - #include - #include +#if defined(ARDUINO_ARCH_ESP32) +#include +#include WebServer webServer(80); - #endif // ESP32 +#endif // ESP32 HTTPUpload * upload; @@ -112,12 +113,11 @@ const char HTTP_FOOTER[] PROGMEM = " by Francis Van Roie"; // // Default link to compiled Nextion firmware images // String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft"; - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 extern char mqttNodeName[16]; - #else +#else char mqttNodeName[3] = "na"; - #endif - +#endif //////////////////////////////////////////////////////////////////////////////////////////////////// String getOption(int value, String label, bool selected) @@ -185,13 +185,13 @@ bool httpIsAuthenticated(const __FlashStringHelper * fstr_page) } } - #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) LOG_TRACE(TAG_HTTP, F("Sending %S page to client connected from: %s"), fstr_page, - webServer.client().remoteIP().toString().c_str()); - #else - // LOG_INFO(TAG_HTTP,F("Sending %s page to client connected from: %s"), page, - // String(webServer.client().remoteIP()).c_str()); - #endif + webServer.client().remoteIP().toString().c_str()); +#else + // LOG_INFO(TAG_HTTP,F("Sending %s page to client connected from: %s"), page, + // String(webServer.client().remoteIP()).c_str()); +#endif return true; } @@ -201,15 +201,15 @@ void webSendFooter() char buffer[16]; haspGetVersion(buffer, sizeof(buffer)); - #if defined(STM32F4xx) +#if defined(STM32F4xx) webServer.sendContent(HTTP_END); webServer.sendContent(buffer); webServer.sendContent(HTTP_FOOTER); - #else +#else webServer.sendContent_P(HTTP_END); webServer.sendContent(buffer); webServer.sendContent_P(HTTP_FOOTER); - #endif +#endif } void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false) @@ -235,29 +235,29 @@ void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false) } webServer.setContentLength(contentLength + httpdatalength); - #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122 - #else +#else webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122 - #endif +#endif snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename); webServer.sendContent(buffer); // 17-2+len } - #if defined(STM32F4xx) +#if defined(STM32F4xx) webServer.sendContent(HTTP_SCRIPT); // 131 webServer.sendContent(HTTP_STYLE); // 487 // webServer.sendContent(HASP_STYLE); // 145 if(gohome) webServer.sendContent(HTTP_META_GO_BACK); // 47 webServer.sendContent(HTTP_HEADER_END); // 80 - #else +#else webServer.sendContent_P(HTTP_SCRIPT); // 131 webServer.sendContent_P(HTTP_STYLE); // 487 // webServer.sendContent_P(HASP_STYLE); // 145 if(gohome) webServer.sendContent_P(HTTP_META_GO_BACK); // 47 webServer.sendContent_P(HTTP_HEADER_END); // 80 - #endif +#endif } void saveConfig() @@ -272,10 +272,10 @@ void saveConfig() if(save == String(PSTR("hasp"))) { haspSetConfig(settings.as()); - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 } else if(save == String(PSTR("mqtt"))) { mqttSetConfig(settings.as()); - #endif +#endif } else if(save == String(PSTR("gui"))) { settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cur")); @@ -291,10 +291,10 @@ void saveConfig() // Password might have changed if(!httpIsAuthenticated(F("config"))) return; - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 } else if(save == String(PSTR("wifi"))) { wifiSetConfig(settings.as()); - #endif +#endif } } } @@ -326,13 +326,13 @@ void webHandleRoot() httpMessage += F("

"); - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 if(HASP_FS.exists(F("/edit.htm.gz"))) { httpMessage += F("

"); } - #endif +#endif httpMessage += F("

"); @@ -455,15 +455,15 @@ void webHandleAbout() F("

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, " "dhylands, Josha blemasle, mfalkvidd"); httpMessage += FPSTR(MIT_LICENSE); - #if HASP_USE_SYSLOG > 0 - // Replaced with WiFiUDP client - // httpMessage += F("

Syslog

Copyright© 2016 Martin Sloup"); - // httpMessage += FPSTR(MIT_LICENSE); - #endif - #if HASP_USE_QRCODE > 0 +#if HASP_USE_SYSLOG > 0 + // Replaced with WiFiUDP client + // httpMessage += F("

Syslog

Copyright© 2016 Martin Sloup"); + // httpMessage += FPSTR(MIT_LICENSE); +#endif +#if HASP_USE_QRCODE > 0 httpMessage += F("

QR Code generator

Copyright© Project Nayuki"); httpMessage += FPSTR(MIT_LICENSE); - #endif +#endif httpMessage += F("

AceButton

Copyright© 2018 Brian T. Park"); httpMessage += FPSTR(MIT_LICENSE); @@ -527,12 +527,12 @@ void webHandleInfo() httpMessage += F("s"); httpMessage += F("
Free Memory: "); - Utilities::format_bytes(halGetFreeHeap(), size_buf, sizeof(size_buf)); + Utilities::format_bytes(haspDevice.get_free_heap(), size_buf, sizeof(size_buf)); httpMessage += size_buf; httpMessage += F("
Memory Fragmentation: "); - httpMessage += String(halGetHeapFragmentation()); + httpMessage += String(haspDevice.get_heap_fragmentation()); - #if ARDUINO_ARCH_ESP32 +#if ARDUINO_ARCH_ESP32 if(psramFound()) { httpMessage += F("
Free PSRam: "); Utilities::format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf)); @@ -541,7 +541,7 @@ void webHandleInfo() Utilities::format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf)); httpMessage += size_buf; } - #endif +#endif /* LVGL Stats */ lv_mem_monitor_t mem_mon; @@ -562,7 +562,7 @@ void webHandleInfo() httpMessage += String(haspGetPage()); /* Wifi Stats */ - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 httpMessage += F("

SSID: "); httpMessage += String(WiFi.SSID()); httpMessage += F("
Signal Strength: "); @@ -582,7 +582,7 @@ void webHandleInfo() } else { httpMessage += F("Very Bad)"); } - #if defined(STM32F4xx) +#if defined(STM32F4xx) byte mac[6]; WiFi.macAddress(mac); char macAddress[16]; @@ -594,7 +594,7 @@ void webHandleInfo() httpMessage += String(WiFi.gatewayIP()); httpMessage += F("
MAC Address: "); httpMessage += String(macAddress); - #else +#else httpMessage += F("
IP Address: "); httpMessage += String(WiFi.localIP().toString()); httpMessage += F("
Gateway: "); @@ -603,10 +603,10 @@ void webHandleInfo() httpMessage += String(WiFi.dnsIP().toString()); httpMessage += F("
MAC Address: "); httpMessage += String(WiFi.macAddress()); - #endif - #endif - #if HASP_USE_ETHERNET > 0 - #if defined(ARDUINO_ARCH_ESP32) +#endif +#endif +#if HASP_USE_ETHERNET > 0 +#if defined(ARDUINO_ARCH_ESP32) httpMessage += F("

Ethernet: "); httpMessage += String(ETH.linkSpeed()); httpMessage += F(" Mbps"); @@ -621,10 +621,10 @@ void webHandleInfo() httpMessage += String(ETH.dnsIP().toString()); httpMessage += F("
MAC Address: "); httpMessage += String(ETH.macAddress()); - #endif - #endif - /* Mqtt Stats */ - #if HASP_USE_MQTT > 0 +#endif +#endif +/* Mqtt Stats */ +#if HASP_USE_MQTT > 0 httpMessage += F("

MQTT Status: "); if(mqttIsConnected()) { // Check MQTT connection httpMessage += F("Connected"); @@ -642,16 +642,16 @@ void webHandleInfo() httpMessage += mqttClientId; } - #endif // MQTT +#endif // MQTT /* ESP Stats */ httpMessage += F("

MCU Model: "); httpMessage += halGetChipModel(); httpMessage += F("
CPU Frequency: "); - httpMessage += String(halGetCpuFreqMHz()); + httpMessage += String(haspDevice.get_cpu_frequency()); httpMessage += F("MHz"); - #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) httpMessage += F("
Flash Chip Size: "); Utilities::format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf)); httpMessage += size_buf; @@ -663,14 +663,14 @@ void webHandleInfo() httpMessage += F("
Free Program Space: "); Utilities::format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf)); httpMessage += size_buf; - #endif +#endif //#if defined(ARDUINO_ARCH_ESP32) // httpMessage += F("
ESP SDK version: "); // httpMessage += String(ESP.getSdkVersion()); //#else httpMessage += F("
Core version: "); - httpMessage += String(halGetCoreVersion()); + httpMessage += halGetCoreVersion(); //#endif httpMessage += F("
Last Reset: "); httpMessage += halGetResetInfo(); @@ -768,20 +768,20 @@ void webUploadProgress() haspProgressVal(t); } - #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) static inline void webUpdatePrintError() { - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) String output((char *)0); output.reserve(128); StringStream stream((String &)output); Update.printError(stream); // ESP8266 only has printError() LOG_ERROR(TAG_HTTP, output.c_str()); haspProgressMsg(output.c_str()); - #elif defined(ARDUINO_ARCH_ESP32) +#elif defined(ARDUINO_ARCH_ESP32) LOG_ERROR(TAG_HTTP, Update.errorString()); // ESP32 has errorString() haspProgressMsg(Update.errorString()); - #endif +#endif } void webUpdateReboot() @@ -839,9 +839,9 @@ void webHandleFirmwareUpload() } } } - #endif +#endif - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 bool handleFileRead(String path) { if(!httpIsAuthenticated(F("fileread"))) return false; @@ -973,7 +973,7 @@ void handleFileList() LOG_TRACE(TAG_HTTP, F("handleFileList: %s"), path.c_str()); path.clear(); - #if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) File root = HASP_FS.open("/", FILE_READ); File file = root.openNextFile(); String output = "["; @@ -998,7 +998,7 @@ void handleFileList() } output += "]"; webServer.send(200, PSTR("text/json"), output); - #elif defined(ARDUINO_ARCH_ESP8266) +#elif defined(ARDUINO_ARCH_ESP8266) Dir dir = HASP_FS.openDir(path); String output = "["; while(dir.next()) { @@ -1020,24 +1020,24 @@ void handleFileList() } output += "]"; webServer.send(200, PSTR("text/json"), output); - #endif +#endif } - #endif +#endif - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if HASP_USE_CONFIG > 0 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_CONFIG > 0 void webHandleConfig() { // http://plate01/config if(!httpIsAuthenticated(F("config"))) return; saveConfig(); - // Reboot after saving wifi config in AP mode - #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) +// Reboot after saving wifi config in AP mode +#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) if(WiFi.getMode() != WIFI_STA) { httpHandleReboot(); } - #endif +#endif { String httpMessage((char *)0); @@ -1046,15 +1046,15 @@ void webHandleConfig() httpMessage += httpGetNodename(); httpMessage += F("


"); - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 httpMessage += F("

"); - #endif +#endif - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 httpMessage += F("

"); - #endif +#endif httpMessage += F("

"); @@ -1062,14 +1062,14 @@ void webHandleConfig() httpMessage += F("

"); - // httpMessage += - // F("

"); + // httpMessage += + // F("

"); - #if HASP_USE_GPIO > 0 +#if HASP_USE_GPIO > 0 httpMessage += F("

"); - #endif +#endif httpMessage += F("

"); @@ -1087,8 +1087,8 @@ void webHandleConfig() webSendFooter(); } - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if HASP_USE_MQTT > 0 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_MQTT > 0 void webHandleMqttConfig() { // http://plate01/config/mqtt if(!httpIsAuthenticated(F("config/mqtt"))) return; @@ -1129,7 +1129,8 @@ void webHandleMqttConfig() F("'>

"); add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += PSTR("

"); webSendPage(httpGetNodename(), httpMessage.length(), false); @@ -1138,7 +1139,7 @@ void webHandleMqttConfig() // httpMessage.clear(); webSendFooter(); } - #endif +#endif //////////////////////////////////////////////////////////////////////////////////////////////////// void webHandleGuiConfig() @@ -1190,7 +1191,7 @@ void webHandleGuiConfig() int8_t bcklpin = settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as(); httpMessage += F("

Backlight Control

"); add_button(httpMessage, F(D_HTTP_SAVE_SETTINGS), F("name='save' value='gui'")); close_form(httpMessage); - // httpMessage += - // F("

"); + // httpMessage += + // F("

"); - #if TOUCH_DRIVER == 2046 && defined(TOUCH_CS) +#if TOUCH_DRIVER == 2046 && defined(TOUCH_CS) add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='action' value='calibrate'")); - // httpMessage += PSTR("

"); - #endif +// httpMessage += PSTR("

"); +#endif add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); @@ -1235,8 +1236,8 @@ void webHandleGuiConfig() if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); } - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if HASP_USE_WIFI > 0 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_WIFI > 0 void webHandleWifiConfig() { // http://plate01/config/wifi if(!httpIsAuthenticated(F("config/wifi"))) return; @@ -1262,28 +1263,28 @@ void webHandleWifiConfig() httpMessage += F("'>

"); - #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) +#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) if(WiFi.getMode() == WIFI_STA) { add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); // httpMessage += PSTR("

"); } - #endif +#endif webSendPage(httpGetNodename(), httpMessage.length(), false); webServer.sendContent(httpMessage); - #if defined(STM32F4xx) +#if defined(STM32F4xx) httpMessage = ""; - #else +#else httpMessage.clear(); - #endif +#endif webSendFooter(); } - #endif +#endif - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if HASP_USE_HTTP > 0 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_HTTP > 0 void webHandleHttpConfig() { // http://plate01/config/http if(!httpIsAuthenticated(F("config/http"))) return; @@ -1340,10 +1341,10 @@ void webHandleHttpConfig() // httpMessage.clear(); webSendFooter(); } - #endif +#endif - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) void webHandleGpioConfig() { // http://plate01/config/gpio if(!httpIsAuthenticated(F("config/gpio"))) return; @@ -1571,7 +1572,7 @@ void webHandleGpioOptions() if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check } - #endif // HASP_USE_GPIO +#endif // HASP_USE_GPIO //////////////////////////////////////////////////////////////////////////////////////////////////// void webHandleDebugConfig() @@ -1604,7 +1605,7 @@ void webHandleDebugConfig() httpMessage += settings[FPSTR(FP_DEBUG_TELEPERIOD)].as(); httpMessage += F("'>

"); - #if HASP_USE_SYSLOG > 0 +#if HASP_USE_SYSLOG > 0 httpMessage += F("Syslog Hostame (optional)() == 1) httpMessage += F(" checked"); httpMessage += F(">BSD (RFC 3164)"); - #endif +#endif httpMessage += F("

"); @@ -1664,24 +1665,24 @@ void webHandleHaspConfig() httpMessage += F("

UI Theme (required)
"); httpMessage += F("Hue

"); httpMessage += F("

Default Font

"); httpMessage += F("

Startup Layout (optional) 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 if(handleFileRead(webServer.uri())) return; - #endif +#endif - #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) LOG_TRACE(TAG_HTTP, F("Sending 404 to client connected from: %s"), - webServer.client().remoteIP().toString().c_str()); - #else + webServer.client().remoteIP().toString().c_str()); +#else // LOG_TRACE(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); - #endif +#endif String httpMessage((char *)0); httpMessage.reserve(HTTP_PAGE_SIZE); @@ -1828,8 +1829,8 @@ void httpHandleEspFirmware() // espStartOta(webServer.arg("espFirmware")); } - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if HASP_USE_CONFIG > 0 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_CONFIG > 0 void webHandleSaveConfig() { if(!httpIsAuthenticated(F("saveConfig"))) return; @@ -1888,30 +1889,30 @@ void httpHandleResetConfig() dispatch_reboot(false); // Do not save the current config } } - #endif // HASP_USE_CONFIG +#endif // HASP_USE_CONFIG void httpStart() { webServer.begin(); webServerStarted = true; - #if HASP_USE_WIFI > 0 - #if defined(STM32F4xx) +#if HASP_USE_WIFI > 0 +#if defined(STM32F4xx) IPAddress ip; ip = WiFi.localIP(); LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); - #else +#else LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"), - (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); - #endif - #else + (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); +#endif +#else IPAddress ip; - #if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) ip = ETH.localIP(); - #else +#else ip = Ethernet.localIP(); - #endif +#endif LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); - #endif +#endif } void httpStop() @@ -1935,19 +1936,19 @@ void httpSetup() webServer.on(F("/about"), webHandleAbout); webServer.onNotFound(httpHandleNotFound); - #if HASP_USE_WIFI > 0 - #if !defined(STM32F4xx) +#if HASP_USE_WIFI > 0 +#if !defined(STM32F4xx) - #if HASP_USE_CONFIG > 0 +#if HASP_USE_CONFIG > 0 if(WiFi.getMode() != WIFI_STA) { LOG_TRACE(TAG_HTTP, F("Wifi access point")); webServer.on(F("/"), webHandleWifiConfig); return; } - #endif - #endif - #endif +#endif +#endif +#endif webServer.on(F("/page/"), []() { String pageid = webServer.arg(F("page")); @@ -1955,7 +1956,7 @@ void httpSetup() haspSetPage(pageid.toInt()); }); - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 webServer.on(F("/list"), HTTP_GET, handleFileList); // load editor webServer.on(F("/edit"), HTTP_GET, []() { @@ -1976,7 +1977,7 @@ void httpSetup() LOG_VERBOSE(TAG_HTTP, F("Headers: %d"), webServer.headers()); }, handleFileUpload); - #endif +#endif webServer.on(F("/"), webHandleRoot); webServer.on(F("/info"), webHandleInfo); @@ -1984,27 +1985,27 @@ void httpSetup() webServer.on(F("/firmware"), webHandleFirmware); webServer.on(F("/reboot"), httpHandleReboot); - #if HASP_USE_CONFIG > 0 +#if HASP_USE_CONFIG > 0 webServer.on(F("/config/hasp"), webHandleHaspConfig); webServer.on(F("/config/http"), webHandleHttpConfig); webServer.on(F("/config/gui"), webHandleGuiConfig); webServer.on(F("/config/debug"), webHandleDebugConfig); - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 webServer.on(F("/config/mqtt"), webHandleMqttConfig); - #endif - #if HASP_USE_WIFI > 0 +#endif +#if HASP_USE_WIFI > 0 webServer.on(F("/config/wifi"), webHandleWifiConfig); - #endif - #if HASP_USE_GPIO > 0 +#endif +#if HASP_USE_GPIO > 0 webServer.on(F("/config/gpio"), webHandleGpioConfig); webServer.on(F("/config/gpio/options"), webHandleGpioOptions); - #endif +#endif webServer.on(F("/saveConfig"), webHandleSaveConfig); webServer.on(F("/resetConfig"), httpHandleResetConfig); webServer.on(F("/config"), webHandleConfig); - #endif // HASP_USE_CONFIG +#endif // HASP_USE_CONFIG - #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) webServer.on( F("/update"), HTTP_POST, []() { @@ -2013,7 +2014,7 @@ void httpSetup() }, webHandleFirmwareUpload); webServer.on(F("/espfirmware"), httpHandleEspFirmware); - #endif +#endif LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED)); // webStart(); Wait for network connection @@ -2027,9 +2028,9 @@ void httpReconnect() if(webServerStarted) { httpStop(); } else - #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) +#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA) - #endif +#endif { httpStart(); } @@ -2048,7 +2049,7 @@ void httpEvery5Seconds() } //////////////////////////////////////////////////////////////////////////////////////////////////// - #if HASP_USE_CONFIG > 0 +#if HASP_USE_CONFIG > 0 bool httpGetConfig(const JsonObject & settings) { bool changed = false; @@ -2095,7 +2096,7 @@ bool httpSetConfig(const JsonObject & settings) return changed; } - #endif // HASP_USE_CONFIG +#endif // HASP_USE_CONFIG size_t httpClientWrite(const uint8_t * buf, size_t size) { From 830a2ef4152499a7ef5b61d95f6fefb5f5b4512e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 05:17:29 +0100 Subject: [PATCH 039/236] Move files to src --- {lib/lv_drv_tft_espi => src/drv}/tft_espi_drv.cpp | 7 +++++-- {lib/lv_drv_tft_espi => src/drv}/tft_espi_drv.h | 0 2 files changed, 5 insertions(+), 2 deletions(-) rename {lib/lv_drv_tft_espi => src/drv}/tft_espi_drv.cpp (98%) rename {lib/lv_drv_tft_espi => src/drv}/tft_espi_drv.h (100%) diff --git a/lib/lv_drv_tft_espi/tft_espi_drv.cpp b/src/drv/tft_espi_drv.cpp similarity index 98% rename from lib/lv_drv_tft_espi/tft_espi_drv.cpp rename to src/drv/tft_espi_drv.cpp index ebc4136b..2b090569 100644 --- a/lib/lv_drv_tft_espi/tft_espi_drv.cpp +++ b/src/drv/tft_espi_drv.cpp @@ -6,8 +6,11 @@ /********************* * INCLUDES *********************/ -#include "../../src/hal/hasp_hal.h" // for halGpioName() -#include "../../src/dev/device.h" +#include "hasp_conf.h" + +#include "hal/hasp_hal.h" // for halGpioName() +#include "dev/device.h" + #include "tft_espi_drv.h" #include "ArduinoLog.h" #include "hasp_macro.h" diff --git a/lib/lv_drv_tft_espi/tft_espi_drv.h b/src/drv/tft_espi_drv.h similarity index 100% rename from lib/lv_drv_tft_espi/tft_espi_drv.h rename to src/drv/tft_espi_drv.h From 28bf02642de1af2d4e96527d0370f1b34bd12f61 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 05:41:04 +0100 Subject: [PATCH 040/236] Enable ARDUINOJSON_ENABLE_PROGMEM --- platformio.ini | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index a2d5a969..ce3e8871 100644 --- a/platformio.ini +++ b/platformio.ini @@ -52,7 +52,6 @@ build_flags = -D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files ; -- ArduinoJson build options ---------------------------- -D ARDUINOJSON_DECODE_UNICODE=1 ; for utf-8 symbols - ;-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments ; -- StreamUtils build options ---------------------------- -D STREAMUTILS_ENABLE_EEPROM=1 ; for STM32, it also supports EEPROM @@ -112,6 +111,8 @@ build_flags = -D NO_GLOBAL_HTTPUPDATE ; dont instantiate httpUpdate ; -- lvgl build options ----------------------------- -D LV_MEM_SIZE=61440U ; 60kB lvgl memory +; -- ArduinoJson build options ---------------------------- + -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments ; -- tft_espi build options ------------------------ ;-D USE_DMA_TO_TFT ; -- hasp-lvgl build options ------------------------ @@ -180,6 +181,8 @@ build_flags= -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY ; -- lvgl build options ----------------------------- -D LV_MEM_SIZE=12288U ; 12kB lvgl memory +; -- ArduinoJson build options ---------------------------- + -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments ; -- hasp-lvgl build options ------------------------ ;-D HASP_USE_TELNET=1 ;-D HASP_USE_SPIFFS=1 From a43787c3f9d795564cbed3376dfdaaaed23b7e0d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 05:41:25 +0100 Subject: [PATCH 041/236] Code cleanup --- src/hasp_gui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index f96e874f..c15cf745 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -57,8 +57,8 @@ gui_conf_t gui_settings = {.show_pointer = false, .invert_display = INVERT_COLORS, .cal_data = {0, 65535, 0, 65535, 0}}; -static int8_t guiDimLevel = 100; -bool guiBacklightIsOn; +// static int8_t guiDimLevel = 100; +// bool guiBacklightIsOn; // #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) // static Ticker tick; /* timer for interrupt handler */ From 0b2b3fe7a855f41a3748205f88b8b5cea0ec5ef7 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:40:10 +0100 Subject: [PATCH 042/236] Update environments with TasmotaClient --- user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini | 2 +- user_setups/stm32f4xx/stm32f407-black_ili9341.ini | 2 +- user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini | 2 +- user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini | 2 +- user_setups/win32/emulator_64bits.ini | 2 -- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini b/user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini index eb720d23..0534321f 100644 --- a/user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini +++ b/user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini @@ -50,7 +50,7 @@ build_flags = -D STM32_SERIAL1 ; Set this option to use Serial1 as default sersial port, leave out if using Serial2 ;region -- Hasp build options ---------------------------- - -D HASP_USE_TASMOTA_SLAVE=0 + -D HASP_USE_TASMOTA_CLIENT=0 -D HASP_OUTPUT_PIN=PA1 ; User LED D2 on DevEBox board -D HASP_INPUT_PIN=PA0 ; User Button K1 on DevEBox board -D HASP_USE_WIFI=0 diff --git a/user_setups/stm32f4xx/stm32f407-black_ili9341.ini b/user_setups/stm32f4xx/stm32f407-black_ili9341.ini index 57ed09f7..2b3d9388 100644 --- a/user_setups/stm32f4xx/stm32f407-black_ili9341.ini +++ b/user_setups/stm32f4xx/stm32f407-black_ili9341.ini @@ -32,7 +32,7 @@ build_flags = ;region -- Hasp build options ---------------------------- -D HASP_OUTPUT_PIN=PE0 ; User LED D2 on DevEBox board -D HASP_INPUT_PIN=PD15 ; User Button K1 on DevEBox board - -D HASP_USE_TASMOTA_SLAVE=1 + -D HASP_USE_TASMOTA_CLIENT=1 -D HASP_USE_OTA=0 -D HASP_USE_ETHERNET=1 ;endregion diff --git a/user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini b/user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini index c855aebb..b019108b 100644 --- a/user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini +++ b/user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini @@ -44,7 +44,7 @@ build_flags = -D HASP_USE_SPIFFS=0 -D HASP_USE_EEPROM=1 -D HASP_USE_GPIO=0 - -D HASP_USE_TASMOTA_SLAVE=0 + -D HASP_USE_TASMOTA_CLIENT=0 -D HASP_USE_OTA=0 -D HASP_USE_ETHERNET=0 ;endregion diff --git a/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini b/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini index 2a5e7950..4005c4a8 100644 --- a/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini +++ b/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini @@ -52,7 +52,7 @@ build_flags = -D HASP_USE_SPIFFS=0 -D HASP_USE_EEPROM=1 -D HASP_USE_GPIO=1 - -D HASP_USE_TASMOTA_SLAVE=0 + -D HASP_USE_TASMOTA_CLIENT=0 -D HASP_USE_OTA=0 -D HASP_OUTPUT_PIN=PA1 ; User LED D2 on DevEBox board -D HASP_INPUT_PIN=PA0 ; User Button K1 on DevEBox board diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/emulator_64bits.ini index 43480cbd..0d86e0e2 100644 --- a/user_setups/win32/emulator_64bits.ini +++ b/user_setups/win32/emulator_64bits.ini @@ -100,8 +100,6 @@ src_filter = - - - - - - - + + + From 215c2645b3d08150440fc2c54dc5b0b9d05d478b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:41:18 +0100 Subject: [PATCH 043/236] Move network services into system --- src/sys/net/hasp_network.cpp | 81 +++++++++++++++++++++---------- src/{ => sys}/svc/hasp_http.cpp | 0 src/{ => sys}/svc/hasp_http.h | 0 src/{ => sys}/svc/hasp_mdns.cpp | 0 src/{ => sys}/svc/hasp_mdns.h | 0 src/{ => sys}/svc/hasp_ota.cpp | 66 ++++++++++++------------- src/{ => sys}/svc/hasp_ota.h | 0 src/{ => sys}/svc/hasp_slave.cpp | 6 +-- src/{ => sys}/svc/hasp_slave.h | 9 ++-- src/{ => sys}/svc/hasp_telnet.cpp | 0 src/{ => sys}/svc/hasp_telnet.h | 0 11 files changed, 96 insertions(+), 66 deletions(-) rename src/{ => sys}/svc/hasp_http.cpp (100%) rename src/{ => sys}/svc/hasp_http.h (100%) rename src/{ => sys}/svc/hasp_mdns.cpp (100%) rename src/{ => sys}/svc/hasp_mdns.h (100%) rename src/{ => sys}/svc/hasp_ota.cpp (89%) rename src/{ => sys}/svc/hasp_ota.h (100%) rename src/{ => sys}/svc/hasp_slave.cpp (97%) rename src/{ => sys}/svc/hasp_slave.h (79%) rename src/{ => sys}/svc/hasp_telnet.cpp (100%) rename src/{ => sys}/svc/hasp_telnet.h (100%) diff --git a/src/sys/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp index b51d0778..02f299ad 100644 --- a/src/sys/net/hasp_network.cpp +++ b/src/sys/net/hasp_network.cpp @@ -13,8 +13,8 @@ #include "hasp_debug.h" #include "hasp_network.h" -#include "../../hasp/hasp.h" -#include "../../svc/hasp_mdns.h" +#include "hasp/hasp.h" +#include "sys/svc/hasp_mdns.h" #if HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0 void networkStart(void) @@ -41,60 +41,91 @@ void networkStop(void) void networkSetup() { - #if HASP_USE_ETHERNET > 0 +#if HASP_USE_ETHERNET > 0 ethernetSetup(); - #endif +#endif - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 wifiSetup(); - #endif +#endif } void networkLoop(void) { - #if HASP_USE_ETHERNET > 0 +#if HASP_USE_ETHERNET > 0 ethernetLoop(); - #endif +#endif - #if HASP_USE_WIFI > 0 - // wifiLoop(); - #endif +#if HASP_USE_WIFI > 0 + // wifiLoop(); +#endif + +#if HASP_USE_TASMOTA_CLIENT > 0 + tasmotaclientLoop(); +#endif // HASP_USE_TASMOTA_CLIENT + +#if HASP_USE_HTTP > 0 + httpLoop(); +#endif // HTTP + +#if HASP_USE_GPIO > 0 + gpioLoop(); +#endif // GPIO + +#if HASP_USE_OTA > 0 + otaLoop(); +#endif // OTA + +#if HASP_USE_MDNS > 0 + mdnsLoop(); +#endif // MDNS + +#if HASP_USE_TELNET > 0 + telnetLoop(); // Console +#endif // TELNET } bool networkEvery5Seconds(void) { - #if HASP_USE_ETHERNET > 0 +#if HASP_USE_ETHERNET > 0 return ethernetEvery5Seconds(); - #endif +#endif - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 return wifiEvery5Seconds(); - #endif +#endif return false; } bool networkEverySecond(void) { - #if HASP_USE_ETHERNET > 0 - // return ethernetEverySecond(); - #endif + bool connected = false; + +#if HASP_USE_ETHERNET > 0 + connected |= ethernetEverySecond(); +#endif + +#if HASP_USE_WIFI > 0 + // connected |= wifiEverySecond(); +#endif + +#if HASP_USE_OTA > 0 + otaEverySecond(); // progressbar +#endif - #if HASP_USE_WIFI > 0 - // return wifiEverySecond(); - #endif return true; } void network_get_statusupdate(char * buffer, size_t len) { - #if HASP_USE_ETHERNET > 0 +#if HASP_USE_ETHERNET > 0 ethernet_get_statusupdate(buffer, len); - #endif +#endif - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 wifi_get_statusupdate(buffer, len); - #endif +#endif } #endif \ No newline at end of file diff --git a/src/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp similarity index 100% rename from src/svc/hasp_http.cpp rename to src/sys/svc/hasp_http.cpp diff --git a/src/svc/hasp_http.h b/src/sys/svc/hasp_http.h similarity index 100% rename from src/svc/hasp_http.h rename to src/sys/svc/hasp_http.h diff --git a/src/svc/hasp_mdns.cpp b/src/sys/svc/hasp_mdns.cpp similarity index 100% rename from src/svc/hasp_mdns.cpp rename to src/sys/svc/hasp_mdns.cpp diff --git a/src/svc/hasp_mdns.h b/src/sys/svc/hasp_mdns.h similarity index 100% rename from src/svc/hasp_mdns.h rename to src/sys/svc/hasp_mdns.h diff --git a/src/svc/hasp_ota.cpp b/src/sys/svc/hasp_ota.cpp similarity index 89% rename from src/svc/hasp_ota.cpp rename to src/sys/svc/hasp_ota.cpp index 6dc60d84..17392160 100644 --- a/src/svc/hasp_ota.cpp +++ b/src/sys/svc/hasp_ota.cpp @@ -3,25 +3,25 @@ #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - #include "hasp_conf.h" +#include "hasp_conf.h" - #include "hasp_debug.h" - #include "hasp_ota.h" +#include "hasp_debug.h" +#include "hasp_ota.h" - #include "../hasp/hasp_dispatch.h" - #include "../hasp/hasp.h" +#include "../../hasp/hasp_dispatch.h" +#include "../../hasp/hasp.h" - #if defined(ARDUINO_ARCH_ESP8266) - #include - #include - #include - #else - #include - #include - #include - #endif +#if defined(ARDUINO_ARCH_ESP8266) +#include +#include +#include +#else +#include +#include +#include +#endif - #include +#include static WiFiClient otaClient; std::string otaUrl = "http://ota.netwize.be"; @@ -141,27 +141,27 @@ void otaSetup(void) // delay(5000); }); - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 ArduinoOTA.setHostname(String(mqttGetNodename()).c_str()); - #else +#else ArduinoOTA.setHostname(String(mqttGetNodename()).c_str()); - #endif +#endif // ArduinoOTA.setPassword(configPassword); ArduinoOTA.setPort(otaPort); - #if ESP32 - #if HASP_USE_MDNS > 0 +#if ESP32 +#if HASP_USE_MDNS > 0 ArduinoOTA.setMdnsEnabled(true); - #else +#else ArduinoOTA.setMdnsEnabled(false); - #endif - // ArduinoOTA.setTimeout(1000); - #endif +#endif + // ArduinoOTA.setTimeout(1000); +#endif ArduinoOTA.setRebootOnSuccess(false); // We do that ourselves - #ifdef OTA_PASSWORD +#ifdef OTA_PASSWORD ArduinoOTA.setPassword(OTA_PASSWORD); - #endif +#endif ArduinoOTA.begin(); LOG_INFO(TAG_OTA, F(D_SERVICE_STARTED)); @@ -182,19 +182,19 @@ void otaEverySecond(void) void otaHttpUpdate(const char * espOtaUrl) { // Update ESP firmware from HTTP - #if HASP_USE_MDNS > 0 +#if HASP_USE_MDNS > 0 mdnsStop(); // Keep mDNS responder from breaking things - #endif +#endif - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) // ESPhttpUpdate.onStart(update_started); // ESPhttpUpdate.onEnd(update_finished); // ESPhttpUpdate.onProgress(update_progress); // ESPhttpUpdate.onError(update_error); ESP8266HTTPUpdate httpUpdate; - #else +#else HTTPUpdate httpUpdate; - #endif +#endif httpUpdate.rebootOnUpdate(false); // We do that ourselves t_httpUpdate_return returnCode = httpUpdate.update(otaClient, espOtaUrl); @@ -214,9 +214,9 @@ void otaHttpUpdate(const char * espOtaUrl) dispatch_reboot(true); } - #if HASP_USE_MDNS > 0 +#if HASP_USE_MDNS > 0 mdnsStart(); - #endif // HASP_USE_MDNS +#endif // HASP_USE_MDNS } #endif // ARDUINO_ARCH_ESP8266 || ARDUINO_ARCH_ESP32 \ No newline at end of file diff --git a/src/svc/hasp_ota.h b/src/sys/svc/hasp_ota.h similarity index 100% rename from src/svc/hasp_ota.h rename to src/sys/svc/hasp_ota.h diff --git a/src/svc/hasp_slave.cpp b/src/sys/svc/hasp_slave.cpp similarity index 97% rename from src/svc/hasp_slave.cpp rename to src/sys/svc/hasp_slave.cpp index dc287ae9..840269b2 100644 --- a/src/svc/hasp_slave.cpp +++ b/src/sys/svc/hasp_slave.cpp @@ -2,7 +2,7 @@ For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" -#if HASP_USE_TASMOTA_SLAVE > 0 +#if HASP_USE_TASMOTA_CLIENT > 0 #include "hasp_slave.h" #include "ArduinoJson.h" @@ -52,7 +52,7 @@ void slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * at slave.ExecuteCommand((char *)cBuffer); // Log after char buffers are cleared LOG_TRACE(TAG_TASM, F("TAS PUB: %sstate/json = {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, - attribute, data); + attribute, data); } void slave_send_input(uint8_t id, const char * payload) @@ -145,7 +145,7 @@ void TASMO_EVERY_SECOND(void) void slaveSetup() { - Serial2.begin(HASP_SLAVE_SPEED); + Serial2.begin(HASP_TASMOTACLIENT_SPEED); // slave.attach_FUNC_EVERY_SECOND(TASMO_EVERY_SECOND); slave.attach_FUNC_JSON(TASMO_TELE_JSON); slave.attach_FUNC_COMMAND_SEND(TASMO_DATA_RECEIVE); diff --git a/src/svc/hasp_slave.h b/src/sys/svc/hasp_slave.h similarity index 79% rename from src/svc/hasp_slave.h rename to src/sys/svc/hasp_slave.h index a97e132d..9271732a 100644 --- a/src/svc/hasp_slave.h +++ b/src/sys/svc/hasp_slave.h @@ -1,15 +1,15 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#ifndef HASP_SLAVE_H -#define HASP_SLAVE_H +#ifndef HASP_TASMOTACLIENT_H +#define HASP_TASMOTACLIENT_H #include "ArduinoJson.h" -#define HASP_SLAVE_SPEED 57600 +#define HASP_TASMOTACLIENT_SPEED 57600 void TASMO_EVERY_SECOND(void); -void TASMO_DATA_RECEIVE(char *data); +void TASMO_DATA_RECEIVE(char * data); void slave_send_state(const __FlashStringHelper * subtopic, const char * payload); void slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data); void slave_send_input(uint8_t id, const char * payload); @@ -18,5 +18,4 @@ void slave_send_statusupdate(); void slaveSetup(); void slaveLoop(void); - #endif \ No newline at end of file diff --git a/src/svc/hasp_telnet.cpp b/src/sys/svc/hasp_telnet.cpp similarity index 100% rename from src/svc/hasp_telnet.cpp rename to src/sys/svc/hasp_telnet.cpp diff --git a/src/svc/hasp_telnet.h b/src/sys/svc/hasp_telnet.h similarity index 100% rename from src/svc/hasp_telnet.h rename to src/sys/svc/hasp_telnet.h From 7009c10c97f283f44a85daad5ba9d7e21e0bbe0a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:41:54 +0100 Subject: [PATCH 044/236] Rename pre-setup to init --- src/dev/device.h | 2 +- src/dev/esp32/lanbonl8.cpp | 2 +- src/dev/esp32/lanbonl8.h | 2 +- src/dev/esp32/m5stackcore2.cpp | 2 +- src/dev/esp32/m5stackcore2.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dev/device.h b/src/dev/device.h index 1fa36ea4..a56bcf4d 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -17,7 +17,7 @@ class BaseDevice { virtual void reboot() {} - virtual void pre_setup() + virtual void init() {} virtual void post_setup() {} diff --git a/src/dev/esp32/lanbonl8.cpp b/src/dev/esp32/lanbonl8.cpp index 4e09d88f..05a3cc8e 100644 --- a/src/dev/esp32/lanbonl8.cpp +++ b/src/dev/esp32/lanbonl8.cpp @@ -48,7 +48,7 @@ static void print_char_val_type(esp_adc_cal_value_t val_type) } } -void LanbonL8::pre_setup() +void LanbonL8::init() { // Check if Two Point or Vref are burned into eFuse check_efuse(); diff --git a/src/dev/esp32/lanbonl8.h b/src/dev/esp32/lanbonl8.h index 8cf07a5f..6bc4a747 100644 --- a/src/dev/esp32/lanbonl8.h +++ b/src/dev/esp32/lanbonl8.h @@ -12,7 +12,7 @@ namespace dev { class LanbonL8 : public Esp32Device { public: - void pre_setup(); + void init(); }; } // namespace dev diff --git a/src/dev/esp32/m5stackcore2.cpp b/src/dev/esp32/m5stackcore2.cpp index 0ebf315f..e0eed7d0 100644 --- a/src/dev/esp32/m5stackcore2.cpp +++ b/src/dev/esp32/m5stackcore2.cpp @@ -8,7 +8,7 @@ // AXP192 Axp; namespace dev { -void M5StackCore2::pre_setup(void) +void M5StackCore2::init(void) { AXP192 Axp; Wire.begin(TOUCH_SDA, TOUCH_SCL); diff --git a/src/dev/esp32/m5stackcore2.h b/src/dev/esp32/m5stackcore2.h index 12187b5d..b41f4a6e 100644 --- a/src/dev/esp32/m5stackcore2.h +++ b/src/dev/esp32/m5stackcore2.h @@ -12,7 +12,7 @@ namespace dev { class M5StackCore2 : public Esp32Device { public: - void pre_setup() override; + void init() override; }; } // namespace dev From 1c6ea7c38f8a21103b136aa92bdad086424381ba Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:43:50 +0100 Subject: [PATCH 045/236] Fix memcpy overrun and TasmotaClient rename --- src/hasp/hasp_dispatch.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 77fd108a..51b4363f 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -19,6 +19,7 @@ #if HASP_USE_DEBUG > 0 #include "../hasp_debug.h" +#include "hasp_gui.h" // for screenshot #if WINDOWS #include @@ -30,11 +31,10 @@ #include "CharStream.h" #include "hasp_oobe.h" -#include "hasp_gui.h" // for screenshot #include "sys/gpio/hasp_gpio.h" #include "hal/hasp_hal.h" -#include "svc/hasp_ota.h" +#include "sys/svc/hasp_ota.h" #include "mqtt/hasp_mqtt.h" #include "sys/net/hasp_network.h" // for network_get_status() #endif @@ -329,13 +329,13 @@ void dispatch_output_idle_state(uint8_t state) char payload[6]; switch(state) { case HASP_SLEEP_LONG: - memcpy_P(payload, PSTR("LONG"), sizeof(payload)); + memcpy_P(payload, PSTR("LONG"), 5); break; case HASP_SLEEP_SHORT: - memcpy_P(payload, PSTR("SHORT"), sizeof(payload)); + memcpy_P(payload, PSTR("SHORT"), 6); break; default: - memcpy_P(payload, PSTR("OFF"), sizeof(payload)); + memcpy_P(payload, PSTR("OFF"), 4); } dispatch_state_msg(F("idle"), payload); } @@ -571,13 +571,13 @@ void dispatch_object_value_changed(lv_obj_t * obj, int16_t state) /********************************************** Output States ******************************************/ static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, const char * payload) { -#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) +#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_CLIENT) LOG_TRACE(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload); #else #if HASP_USE_MQTT > 0 mqtt_send_state(subtopic, payload); #endif -#if HASP_USE_TASMOTA_SLAVE > 0 +#if HASP_USE_TASMOTA_CLIENT > 0 slave_send_state(subtopic, payload); #endif #endif @@ -895,9 +895,10 @@ void dispatch_output_statusupdate(const char *, const char *) char data[3 * 128]; { + /* char buffer[128]; - /* haspGetVersion(buffer, sizeof(buffer)); + haspGetVersion(buffer, sizeof(buffer)); snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), mqttGetNodename().c_str(), buffer, long(millis() / 1000)); From 4a993392fdb1d3413899e4fc47c128d2507b9cb2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:55:58 +0100 Subject: [PATCH 046/236] Add Xplatform --- src/hasp_gui.cpp | 52 +++++++++++++++++++++++++++++------------------- src/hasp_gui.h | 12 +++++------ 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index c15cf745..02470bdf 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -23,6 +23,11 @@ #include "hasp/hasp_dispatch.h" #include "hasp/hasp.h" +#ifdef WINDOWS +#include "display/monitor.h" +#include "indev/mouse.h" +#endif + //#include "tpcal.h" //#include "Ticker.h" @@ -74,7 +79,7 @@ gui_conf_t gui_settings = {.show_pointer = false, // lv_tick_inc(LVGL_TICK_PERIOD); // } -void guiCalibrate() +void guiCalibrate(void) { #if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 #ifdef TOUCH_CS @@ -91,11 +96,11 @@ void guiCalibrate() #endif } -void guiSetup() +void guiSetup(void) { // Register logger to capture lvgl_init output LOG_TRACE(TAG_LVGL, F(D_SERVICE_STARTING)); -#if LV_USE_LOG != 0 +#if LV_USE_LOG != 0 && defined(ARDUINO) lv_log_register_print_cb(debugLvglLogEvent); #endif @@ -105,13 +110,13 @@ void guiSetup() #ifdef USE_DMA_TO_TFT static lv_color_t *guiVdbBuffer1, *guiVdbBuffer2 = NULL; // DMA: len must be less than 32767 - size_t guiVDBsize = 15 * 1024u; // 30 KBytes - guiVdbBuffer1 = (lv_color_t *)heap_caps_calloc(guiVDBsize, sizeof(lv_color_t), MALLOC_CAP_DMA); + const size_t guiVDBsize = 15 * 1024u; // 30 KBytes + guiVdbBuffer1 = (lv_color_t *)heap_caps_calloc(guiVDBsize, sizeof(lv_color_t), MALLOC_CAP_DMA); // guiVdbBuffer2 = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * guiVDBsize, MALLOC_CAP_DMA); // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize); #else static lv_color_t * guiVdbBuffer1; - size_t guiVDBsize = 16 * 1024u; // 32 KBytes + const size_t guiVDBsize = 16 * 1024u; // 32 KBytes if(0 && psramFound()) { guiVdbBuffer1 = (lv_color_t *)ps_calloc(guiVDBsize, sizeof(lv_color_t)); // too slow for VDB @@ -131,20 +136,12 @@ void guiSetup() // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize); static lv_color_t * guiVdbBuffer1; - size_t guiVDBsize = 2 * 512u; // 4 KBytes * 2 - guiVdbBuffer1 = (lv_color_t *)malloc(sizeof(lv_color_t) * guiVDBsize); + const size_t guiVDBsize = 2 * 512u; // 4 KBytes * 2 + guiVdbBuffer1 = (lv_color_t *)malloc(sizeof(lv_color_t) * guiVDBsize); #elif defined(WINDOWS) - static lv_color_t buf[LV_HOR_RES_MAX * 10]; /*Declare a buffer for 10 lines*/ - lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/ - - lv_disp_drv_t disp_drv; - lv_disp_drv_init(&disp_drv); /*Basic initialization*/ - disp_drv.flush_cb = monitor_flush; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/ - disp_drv.buffer = &disp_buf; - // disp_drv.disp_fill = monitor_fill; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ - // disp_drv.disp_map = monitor_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ - lv_disp_drv_register(&disp_drv); + const size_t guiVDBsize = LV_HOR_RES_MAX * 10; + static lv_color_t guiVdbBuffer1[guiVDBsize]; /*Declare a buffer for 10 lines*/ #else static lv_color_t guiVdbBuffer1[16 * 512u]; // 16 KBytes @@ -167,8 +164,12 @@ void guiSetup() lv_disp_drv_init(&disp_drv); disp_drv.buffer = &disp_buf; +#if defined(WINDOWS) + disp_drv.flush_cb = monitor_flush; +#else drv_display_init(&disp_drv, gui_settings.rotation, gui_settings.invert_display); // Set display driver callback & rotation +#endif disp_drv.hor_res = TFT_WIDTH; disp_drv.ver_res = TFT_HEIGHT; lv_disp_t * display = lv_disp_drv_register(&disp_drv); @@ -225,8 +226,12 @@ void guiSetup() /* Initialize the touch pad */ lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read_cb = drv_touch_read; + indev_drv.type = LV_INDEV_TYPE_POINTER; +#if defined(WINDOWS) + indev_drv.read_cb = mouse_read; +#else + indev_drv.read_cb = drv_touch_read; +#endif lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv); mouse_indev->driver.type = LV_INDEV_TYPE_POINTER; @@ -253,7 +258,10 @@ void guiSetup() #endif lv_indev_set_cursor(mouse_indev, cursor); /*Connect the image object to the driver*/ } + +#if !defined(WINDOWS) drv_touch_init(gui_settings.rotation); // Touch driver +#endif /* Initialize Global progress bar*/ lv_obj_user_data_t udata = (lv_obj_user_data_t){10, 0, 10}; @@ -281,7 +289,9 @@ void guiLoop(void) #endif lv_task_handler(); // process animations - drv_touch_loop(); // update touch +#if !defined(WINDOWS) + drv_touch_loop(); // update touch +#endif } void guiEverySecond(void) diff --git a/src/hasp_gui.h b/src/hasp_gui.h index bc2f29de..ccaccf76 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -17,16 +17,16 @@ struct gui_conf_t }; /* ===== Default Event Processors ===== */ -void guiSetup(); +void guiSetup(void); void guiLoop(void); void guiEverySecond(void); void guiStart(void); void guiStop(void); /* ===== Special Event Processors ===== */ -void guiCalibrate(); -void guiTakeScreenshot(const char * pFileName); // to file -void guiTakeScreenshot(); // webclient +void guiCalibrate(void); +void guiTakeScreenshot(const char* pFileName); // to file +void guiTakeScreenshot(void); // webclient /* ===== Getter and Setter Functions ===== */ // void guiSetDim(int8_t level); @@ -36,8 +36,8 @@ void guiTakeScreenshot(); // webclient /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 -bool guiGetConfig(const JsonObject & settings); -bool guiSetConfig(const JsonObject & settings); +bool guiGetConfig(const JsonObject& settings); +bool guiSetConfig(const JsonObject& settings); #endif #endif \ No newline at end of file From 046ecb0b7a70da6ca27f8b13df82d73f28e59831 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:12:56 +0100 Subject: [PATCH 047/236] Post latest updates --- .clang-format | 69 +++++---- include/hasp_conf.h | 274 +++++++++++++++++------------------ src/hasp/hasp_dispatch.cpp | 138 +++++++++--------- src/main_arduino copy.cpp | 194 +++++++++++++++++++++++++ src/main_arduino.cpp | 35 +---- src/main_windows.cpp | 69 ++++----- src/sys/net/hasp_network.cpp | 2 +- 7 files changed, 469 insertions(+), 312 deletions(-) create mode 100644 src/main_arduino copy.cpp diff --git a/.clang-format b/.clang-format index d801df39..03091be4 100644 --- a/.clang-format +++ b/.clang-format @@ -1,12 +1,12 @@ --- -Language: Cpp +Language: Cpp # BasedOnStyle: LLVM AccessModifierOffset: -2 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: false AlignEscapedNewlinesLeft: false -AlignOperands: true +AlignOperands: true AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: false @@ -21,51 +21,51 @@ AlwaysBreakTemplateDeclarations: false BinPackArguments: true BinPackParameters: true BreakBeforeBraces: Custom -BraceWrapping: - AfterClass: false +BraceWrapping: + AfterClass: false AfterControlStatement: false - AfterEnum: false - AfterFunction: true - AfterNamespace: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false AfterObjCDeclaration: false - AfterStruct: true - AfterUnion: true - BeforeCatch: false - BeforeElse: false - IndentBraces: false + AfterStruct: true + AfterUnion: true + BeforeCatch: false + BeforeElse: false + IndentBraces: false SplitEmptyFunction: false BreakBeforeBinaryOperators: None BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ IWYU pragma:' +ColumnLimit: 120 +CommentPragmas: "^ IWYU pragma:" ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DerivePointerAlignment: false -DisableFormat: false +DisableFormat: false ExperimentalAutoDetectBinPacking: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 -IncludeIsMainRegex: '$' +ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: ".*" + Priority: 1 +IncludeIsMainRegex: "$" IndentCaseLabels: true -IndentWidth: 4 +IndentWidth: 4 IndentWrappedFunctionNames: false # IndentPPDirectives: BeforeHash JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' +MacroBlockBegin: "" +MacroBlockEnd: "" MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBlockIndentWidth: 2 @@ -77,21 +77,20 @@ PenaltyBreakFirstLessLess: 120 PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Middle -ReflowComments: true -SortIncludes: false +PointerAlignment: Left +ReflowComments: true +SortIncludes: false SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeParens: Never SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 -SpacesInAngles: false +SpacesInAngles: false SpacesInContainerLiterals: false SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 4 -UseTab: Never -... +Standard: Cpp11 +TabWidth: 4 +UseTab: Never diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 215c673d..577c3d78 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -7,86 +7,86 @@ #define HASP_USE_APP 1 #ifndef HASP_USE_DEBUG - #define HASP_USE_DEBUG 1 +#define HASP_USE_DEBUG 1 #endif /* Network Services */ #ifndef HASP_USE_ETHERNET - #define HASP_USE_ETHERNET 0 +#define HASP_USE_ETHERNET 0 #endif #ifndef HASP_USE_WIFI - #define HASP_USE_WIFI (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_WIFI > 0) +#define HASP_USE_WIFI (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_WIFI > 0) #endif #define HASP_HAS_NETWORK \ (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0) #ifndef HASP_USE_OTA - #define HASP_USE_OTA (HASP_HAS_NETWORK) +#define HASP_USE_OTA (HASP_HAS_NETWORK) #endif #ifndef HASP_USE_MQTT - #define HASP_USE_MQTT (HASP_HAS_NETWORK) +#define HASP_USE_MQTT (HASP_HAS_NETWORK) #endif #ifndef HASP_USE_HTTP - #define HASP_USE_HTTP (HASP_HAS_NETWORK) +#define HASP_USE_HTTP (HASP_HAS_NETWORK) #endif #ifndef HASP_USE_MDNS - #define HASP_USE_MDNS (HASP_HAS_NETWORK) +#define HASP_USE_MDNS (HASP_HAS_NETWORK) #endif #ifndef HASP_USE_SYSLOG - #define HASP_USE_SYSLOG (HASP_HAS_NETWORK) +#define HASP_USE_SYSLOG (HASP_HAS_NETWORK) #endif #ifndef HASP_USE_TELNET - #define HASP_USE_TELNET 0 +#define HASP_USE_TELNET 0 #endif /* Filesystem */ #define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0) #ifndef HASP_USE_SPIFFS - #ifndef HASP_USE_LITTLEFS - #define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM) - #else - #define HASP_USE_SPIFFS (HASP_USE_LITTLEFS <= 0) - #endif +#ifndef HASP_USE_LITTLEFS +#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM) +#else +#define HASP_USE_SPIFFS (HASP_USE_LITTLEFS <= 0) +#endif #endif #ifndef HASP_USE_LITTLEFS - #define HASP_USE_LITTLEFS (HASP_USE_SPIFFS <= 0) +#define HASP_USE_LITTLEFS (HASP_USE_SPIFFS <= 0) #endif #ifndef HASP_USE_EEPROM - #define HASP_USE_EEPROM 1 +#define HASP_USE_EEPROM 1 #endif #ifndef HASP_USE_SDCARD - #define HASP_USE_SDCARD 0 +#define HASP_USE_SDCARD 0 #endif #ifndef HASP_USE_GPIO - #define HASP_USE_GPIO 1 +#define HASP_USE_GPIO 1 #endif #ifndef HASP_USE_QRCODE - #define HASP_USE_QRCODE 1 +#define HASP_USE_QRCODE 1 #endif #ifndef HASP_USE_PNGDECODE - #define HASP_USE_PNGDECODE 0 +#define HASP_USE_PNGDECODE 0 #endif #ifndef HASP_NUM_GPIO_CONFIG - #define HASP_NUM_GPIO_CONFIG 8 +#define HASP_NUM_GPIO_CONFIG 8 #endif #ifndef HASP_NUM_INPUTS - #define HASP_NUM_INPUTS 4 // Number of ACE Buttons +#define HASP_NUM_INPUTS 4 // Number of ACE Buttons #endif // #ifndef HASP_NUM_OUTPUTS @@ -94,188 +94,188 @@ // #endif #ifndef HASP_NUM_PAGES - #if defined(ARDUINO_ARCH_ESP8266) - #define HASP_NUM_PAGES 4 - #else - #define HASP_NUM_PAGES 12 - #endif +#if defined(ARDUINO_ARCH_ESP8266) +#define HASP_NUM_PAGES 4 +#else +#define HASP_NUM_PAGES 12 +#endif #endif #define HASP_OBJECT_NOTATION "p%ub%u" /* Includes */ #ifdef WINDOWS - #include "winsock2.h" - #include "Windows.h" +#include "winsock2.h" +#include "Windows.h" #else - #include "Arduino.h" +#include "Arduino.h" #endif #if HASP_USE_SPIFFS > 0 - // #if defined(ARDUINO_ARCH_ESP32) - // #include "SPIFFS.h" - // #endif - // #include // Include the SPIFFS library - #include "hasp_filesystem.h" +// #if defined(ARDUINO_ARCH_ESP32) +// #include "SPIFFS.h" +// #endif +// #include // Include the SPIFFS library +#include "hasp_filesystem.h" #endif #if HASP_USE_LITTLEFS > 0 - // #if defined(ARDUINO_ARCH_ESP32) - // #include "LITTLEFS.h" - // #elif defined(ARDUINO_ARCH_ESP8266) - // #include // Include the FS library - // #include - // #endif - #include "hasp_filesystem.h" +// #if defined(ARDUINO_ARCH_ESP32) +// #include "LITTLEFS.h" +// #elif defined(ARDUINO_ARCH_ESP8266) +// #include // Include the FS library +// #include +// #endif +#include "hasp_filesystem.h" #endif #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - #include "lv_zifont.h" - #endif +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +#include "lv_zifont.h" +#endif #endif #if HASP_USE_EEPROM > 0 - #include "hasp_eeprom.h" +#include "hasp_eeprom.h" #endif #if HASP_USE_WIFI > 0 - #include "sys/net/hasp_wifi.h" +#include "sys/net/hasp_wifi.h" - #if defined(STM32F4xx) - #include "WiFiSpi.h" +#if defined(STM32F4xx) +#include "WiFiSpi.h" static WiFiSpiClass WiFi; - #endif +#endif #endif // HASP_USE_WIFI #if HASP_USE_ETHERNET > 0 - #if defined(ARDUINO_ARCH_ESP32) - #include +#if defined(ARDUINO_ARCH_ESP32) +#include - #define ETH_ADDR 0 - #define ETH_POWER_PIN -1 - #define ETH_MDC_PIN 23 - #define ETH_MDIO_PIN 18 - #define NRST 5 - #define ETH_TYPE ETH_PHY_LAN8720 - #define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT +#define ETH_ADDR 0 +#define ETH_POWER_PIN -1 +#define ETH_MDC_PIN 23 +#define ETH_MDIO_PIN 18 +#define NRST 5 +#define ETH_TYPE ETH_PHY_LAN8720 +#define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT - #include "net/hasp_ethernet_esp32.h" - #warning Using ESP32 Ethernet LAN8720 +#include "net/hasp_ethernet_esp32.h" +#warning Using ESP32 Ethernet LAN8720 - #else - #if USE_BUILTIN_ETHERNET > 0 - #include - #include - #warning Use built-in STM32 Ethernet - #elif USE_UIP_ETHERNET - #include - #include - #warning Use ENC28J60 Ethernet shield - #else - #include "Ethernet.h" - #warning Use W5x00 Ethernet shield - #endif - #include "net/hasp_ethernet_stm32.h" - #endif +#else +#if USE_BUILTIN_ETHERNET > 0 +#include +#include +#warning Use built-in STM32 Ethernet +#elif USE_UIP_ETHERNET +#include +#include +#warning Use ENC28J60 Ethernet shield +#else +#include "Ethernet.h" +#warning Use W5x00 Ethernet shield +#endif +#include "net/hasp_ethernet_stm32.h" +#endif #endif #if HASP_USE_MQTT > 0 - #include "mqtt/hasp_mqtt.h" +#include "mqtt/hasp_mqtt.h" - #ifdef WINDOWS - #define USE_PAHO - #else - #define USE_PUBSUBCLIENT - #endif +#ifdef WINDOWS +#define USE_PAHO +#else +#define USE_PUBSUBCLIENT +#endif #endif #if HASP_USE_GPIO > 0 - #include "sys/gpio/hasp_gpio.h" +#include "sys/gpio/hasp_gpio.h" #endif #if HASP_USE_HTTP > 0 - #include "svc/hasp_http.h" +#include "sys/svc/hasp_http.h" #endif #if HASP_USE_TELNET > 0 - #include "svc/hasp_telnet.h" +#include "sys/svc/hasp_telnet.h" #endif #if HASP_USE_MDNS > 0 - #include "svc/hasp_mdns.h" +#include "sys/svc/hasp_mdns.h" #endif #if HASP_USE_OTA > 0 - #include "svc/hasp_ota.h" - #ifndef HASP_OTA_PORT - #if defined(ARDUINO_ARCH_ESP32) - #define HASP_OTA_PORT 3232 - #elif defined(ARDUINO_ARCH_ESP8266) - #define HASP_OTA_PORT 8266 - #endif - #endif +#include "sys/svc/hasp_ota.h" +#ifndef HASP_OTA_PORT +#if defined(ARDUINO_ARCH_ESP32) +#define HASP_OTA_PORT 3232 +#elif defined(ARDUINO_ARCH_ESP8266) +#define HASP_OTA_PORT 8266 +#endif +#endif #endif -#if HASP_USE_TASMOTA_SLAVE > 0 - #include "svc/hasp_slave.h" +#if HASP_USE_TASMOTA_CLIENT > 0 +#include "sys/svc/hasp_slave.h" #endif #ifdef WINDOWS - #ifndef FPSTR - #define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) - #endif +#ifndef FPSTR +#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) +#endif - #ifndef __FlashStringHelper - #define __FlashStringHelper char - #endif +#ifndef __FlashStringHelper +#define __FlashStringHelper char +#endif - #ifndef FPSTR - #define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) - #endif +#ifndef FPSTR +#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) +#endif - #ifndef PGM_P - #define PGM_P const char * - #endif +#ifndef PGM_P +#define PGM_P const char* +#endif - #ifndef F - #define F(x) (x) - #endif +#ifndef F +#define F(x) (x) +#endif - #ifndef PSTR - #define PSTR(x) x - #endif +#ifndef PSTR +#define PSTR(x) x +#endif - #ifndef PROGMEM - #define PROGMEM - #endif +#ifndef PROGMEM +#define PROGMEM +#endif #endif #ifdef WINDOWS - #include - #include - #include - #include +#include +#include +#include +#include - #define snprintf_P snprintf - #define memcpy_P memcpy - #define strcasecmp_P strcmp // TODO: should be strcasecmp - #define strcmp_P strcmp - #define strstr_P strstr - #define halRestartMcu() - #define delay Sleep - #define millis SDL_GetTicks +#define snprintf_P snprintf +#define memcpy_P memcpy +#define strcasecmp_P strcmp // TODO: should be strcasecmp +#define strcmp_P strcmp +#define strstr_P strstr +#define halRestartMcu() +#define delay Sleep +#define millis SDL_GetTicks - #define DEC 10 - #define HEX 16 - #define BIN 2 +#define DEC 10 +#define HEX 16 +#define BIN 2 - #define guiGetDim() 255 - #define guiSetDim(x) - #define guiGetBacklight() 1 - #define guiSetBacklight(x) - #define guiCalibrate() +#define guiGetDim() 255 +#define guiSetDim(x) +#define guiGetBacklight() 1 +#define guiSetBacklight(x) +//#define guiCalibrate() #endif #endif // HASP_CONF_H \ No newline at end of file diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 51b4363f..c146c26b 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -59,11 +59,11 @@ struct moodlight_t }; moodlight_t moodlight; -static void dispatch_config(const char * topic, const char * payload); +static void dispatch_config(const char* topic, const char* payload); // void dispatch_group_value(uint8_t groupid, int16_t state, lv_obj_t * obj); -static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, const char * payload); +static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const char* payload); -void dispatch_screenshot(const char *, const char * filename) +void dispatch_screenshot(const char*, const char* filename) { #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 @@ -99,16 +99,16 @@ bool dispatch_factory_reset() return formated && erased; } -void dispatch_json_error(uint8_t tag, DeserializationError & jsonError) +void dispatch_json_error(uint8_t tag, DeserializationError& jsonError) { LOG_ERROR(tag, F(D_JSON_FAILED " %s"), jsonError.c_str()); } // p[x].b[y].attr=value -static inline bool dispatch_parse_button_attribute(const char * topic_p, const char * payload) +static inline bool dispatch_parse_button_attribute(const char* topic_p, const char* payload) { long num; - char * pEnd; + char* pEnd; uint8_t pageid, objid; if(*topic_p != 'p' && *topic_p != 'P') return false; // obligated p @@ -202,7 +202,7 @@ static inline bool dispatch_parse_button_attribute(const char * topic_p, const c } // objectattribute=value -void dispatch_command(const char * topic, const char * payload) +void dispatch_command(const char* topic, const char* payload) { /* ================================= Standard payload commands ======================================= */ @@ -260,34 +260,34 @@ void dispatch_command(const char * topic, const char * payload) } // Strip command/config prefix from the topic and process the payload -void dispatch_topic_payload(const char * topic, const char * payload) +void dispatch_topic_payload(const char* topic, const char* payload) { // LOG_VERBOSE(TAG_MSGR,F("TOPIC: short topic: %s"), topic); if(!strcmp_P(topic, PSTR("command"))) { - dispatch_text_line((char *)payload); + dispatch_text_line((char*)payload); return; } if(topic == strstr_P(topic, PSTR("command/"))) { // startsWith command/ topic += 8u; - dispatch_command(topic, (char *)payload); + dispatch_command(topic, (char*)payload); return; } #if HASP_USE_CONFIG > 0 if(topic == strstr_P(topic, PSTR("config/"))) { // startsWith command/ topic += 7u; - dispatch_config(topic, (char *)payload); + dispatch_config(topic, (char*)payload); return; } #endif - dispatch_command(topic, (char *)payload); // dispatch as is + dispatch_command(topic, (char*)payload); // dispatch as is } // Parse one line of text and execute the command -void dispatch_text_line(const char * cmnd) +void dispatch_text_line(const char* cmnd) { size_t pos1 = std::string(cmnd).find("="); size_t pos2 = std::string(cmnd).find(" "); @@ -350,7 +350,7 @@ void dispatch_output_group_state(uint8_t groupid, uint16_t state) dispatch_state_msg(F("output"), payload); } -void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) +void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char* attribute, const char* data) { if(!attribute || !data) return; @@ -360,7 +360,7 @@ void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * mqtt_send_object_state(pageid, btnid, payload); } -void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val) +void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char* attribute, int32_t val) { if(!attribute) return; @@ -370,7 +370,7 @@ void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * mqtt_send_object_state(pageid, btnid, payload); } -void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char * attribute, uint8_t r, uint8_t g, +void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char* attribute, uint8_t r, uint8_t g, uint8_t b) { if(!attribute) return; @@ -384,7 +384,7 @@ void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char #if HASP_USE_CONFIG > 0 // Get or Set a part of the config.json file -static void dispatch_config(const char * topic, const char * payload) +static void dispatch_config(const char* topic, const char* payload) { DynamicJsonDocument doc(128 * 2); char buffer[128 * 2]; @@ -494,7 +494,7 @@ bool dispatch_get_event_state(uint8_t eventid) } // Map events to their description string -void dispatch_get_event_name(uint8_t eventid, char * buffer, size_t size) +void dispatch_get_event_name(uint8_t eventid, char* buffer, size_t size) { switch(eventid) { case HASP_EVENT_ON: @@ -543,7 +543,7 @@ void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid) } #endif -void dispatch_object_event(lv_obj_t * obj, uint8_t eventid) +void dispatch_object_event(lv_obj_t* obj, uint8_t eventid) { char topic[8]; char payload[8]; @@ -559,7 +559,7 @@ void dispatch_object_event(lv_obj_t * obj, uint8_t eventid) // dispatch_group_onoff(obj->user_data.groupid, dispatch_get_event_state(eventid), obj); } -void dispatch_object_value_changed(lv_obj_t * obj, int16_t state) +void dispatch_object_value_changed(lv_obj_t* obj, int16_t state) { char topic[4]; @@ -569,7 +569,7 @@ void dispatch_object_value_changed(lv_obj_t * obj, int16_t state) } /********************************************** Output States ******************************************/ -static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, const char * payload) +static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const char* payload) { #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_CLIENT) LOG_TRACE(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload); @@ -609,7 +609,7 @@ static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, cons // // dispatch_output_group_state(groupid, payload); // } -void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t * obj) +void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t* obj) { if(groupid > 0) { LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d"), groupid, value); @@ -622,7 +622,7 @@ void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t * /********************************************** Native Commands ****************************************/ -void dispatch_parse_json(const char *, const char * payload) +void dispatch_parse_json(const char*, const char* payload) { // Parse an incoming JSON array into individual commands /* if(strPayload.endsWith(",]")) { // Trailing null array elements are an artifact of older Home Assistant automations @@ -645,18 +645,18 @@ void dispatch_parse_json(const char *, const char * payload) JsonArray arr = json.as(); // guiStop(); for(JsonVariant command : arr) { - dispatch_text_line(command.as()); + dispatch_text_line(command.as()); } // guiStart(); } else if(json.is()) { // handle json as a jsonl uint8_t savedPage = haspGetPage(); hasp_new_object(json.as(), savedPage); - } else if(json.is()) { // handle json as a single command - dispatch_text_line(json.as()); + } else if(json.is()) { // handle json as a single command + dispatch_text_line(json.as()); - } else if(json.is()) { // handle json as a single command - dispatch_text_line(json.as()); + } else if(json.is()) { // handle json as a single command + dispatch_text_line(json.as()); // } else if(json.is()) { // handle json as a single command // dispatch_text_line(json.as().c_str()); @@ -667,9 +667,9 @@ void dispatch_parse_json(const char *, const char * payload) } #ifdef ARDUINO -void dispatch_parse_jsonl(Stream & stream) +void dispatch_parse_jsonl(Stream& stream) #else -void dispatch_parse_jsonl(std::istringstream & stream) +void dispatch_parse_jsonl(std::istringstream& stream) #endif { uint8_t savedPage = haspGetPage(); @@ -698,14 +698,14 @@ void dispatch_parse_jsonl(std::istringstream & stream) } } -void dispatch_parse_jsonl(const char *, const char * payload) +void dispatch_parse_jsonl(const char*, const char* payload) { #if HASP_USE_CONFIG > 0 - CharStream stream((char *)payload); + CharStream stream((char*)payload); // stream.setTimeout(10); dispatch_parse_jsonl(stream); #else - std::istringstream stream((char *)payload); + std::istringstream stream((char*)payload); dispatch_parse_jsonl(stream); #endif } @@ -719,7 +719,7 @@ void dispatch_output_current_page() } // Get or Set a page -void dispatch_page(const char *, const char * page) +void dispatch_page(const char*, const char* page) { if(strlen(page) > 0) { if(Utilities::is_only_digits(page)) { @@ -766,14 +766,14 @@ void dispatch_page_prev() } // Clears a page id or the current page if empty -void dispatch_clear_page(const char *, const char * page) +void dispatch_clear_page(const char*, const char* page) { uint8_t pageid = haspGetPage(); if(strlen(page) > 0) pageid = atoi(page); haspClearPage(pageid); } -void dispatch_dim(const char *, const char * level) +void dispatch_dim(const char*, const char* level) { // Set the current state if(strlen(level) != 0) haspDevice.set_backlight_level(atoi(level)); @@ -783,7 +783,7 @@ void dispatch_dim(const char *, const char * level) dispatch_state_msg(F("dim"), payload); } -void dispatch_moodlight(const char * topic, const char * payload) +void dispatch_moodlight(const char* topic, const char* payload) { // Set the current state if(strlen(payload) != 0) { @@ -800,7 +800,7 @@ void dispatch_moodlight(const char * topic, const char * payload) dispatch_json_error(TAG_MSGR, jsonError); } else { - if(!json[F("power")].isNull()) moodlight.power = Utilities::is_true(json[F("power")].as()); + if(!json[F("power")].isNull()) moodlight.power = Utilities::is_true(json[F("power")].as()); if(!json[F("r")].isNull()) moodlight.r = json[F("r")].as(); if(!json[F("g")].isNull()) moodlight.r = json[F("g")].as(); @@ -808,7 +808,7 @@ void dispatch_moodlight(const char * topic, const char * payload) if(!json[F("color")].isNull()) { lv_color32_t color; - if(Parser::haspPayloadToColor(json[F("color")].as(), color)) { + if(Parser::haspPayloadToColor(json[F("color")].as(), color)) { moodlight.r = color.ch.red; moodlight.g = color.ch.green; moodlight.b = color.ch.blue; @@ -832,7 +832,7 @@ void dispatch_moodlight(const char * topic, const char * payload) dispatch_state_msg(F("moodlight"), buffer); } -void dispatch_backlight(const char *, const char * payload) +void dispatch_backlight(const char*, const char* payload) { // Set the current state if(strlen(payload) != 0) haspDevice.set_backlight_power(Utilities::is_true(payload)); @@ -843,7 +843,7 @@ void dispatch_backlight(const char *, const char * payload) dispatch_state_msg(F("light"), buffer); } -void dispatch_web_update(const char *, const char * espOtaUrl) +void dispatch_web_update(const char*, const char* espOtaUrl) { #if HASP_USE_OTA > 0 LOG_TRACE(TAG_MSGR, F(D_OTA_CHECK_UPDATE), espOtaUrl); @@ -889,40 +889,38 @@ void dispatch_current_state() /******************************************* Command Wrapper Functions *********************************/ // Periodically publish a JSON string indicating system status -void dispatch_output_statusupdate(const char *, const char *) +void dispatch_output_statusupdate(const char*, const char*) { #if HASP_USE_MQTT > 0 char data[3 * 128]; { - /* char buffer[128]; - haspGetVersion(buffer, sizeof(buffer)); - snprintf_P(data, sizeof(data), - PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), - mqttGetNodename().c_str(), buffer, long(millis() / 1000)); + haspGetVersion(buffer, sizeof(buffer)); + snprintf_P(data, sizeof(data), + PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), + mqttGetNodename().c_str(), buffer, long(millis() / 1000)); - #if HASP_USE_WIFI > 0 - network_get_statusupdate(buffer, sizeof(buffer)); - strcat(data, buffer); - #endif - snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","), - halGetFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str()); - strcat(data, buffer); - snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), - haspGetPage(), (HASP_NUM_PAGES)); - strcat(data, buffer); +#if HASP_USE_WIFI > 0 + network_get_statusupdate(buffer, sizeof(buffer)); + strcat(data, buffer); +#endif + snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","), + haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), halGetCoreVersion().c_str()); + strcat(data, buffer); + snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), + haspGetPage(), (HASP_NUM_PAGES)); + strcat(data, buffer); - #if defined(ARDUINO_ARCH_ESP8266) - snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000); - strcat(data, buffer); - #endif +#if defined(ARDUINO_ARCH_ESP8266) + snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000); + strcat(data, buffer); +#endif - snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), - halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); - strcat(data, buffer); - */ + snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), + halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); + strcat(data, buffer); } mqtt_send_state(F("statusupdate"), data); dispatchLastMillis = millis(); @@ -937,22 +935,22 @@ void dispatch_output_statusupdate(const char *, const char *) #endif } -void dispatch_calibrate(const char * topic = NULL, const char * payload = NULL) +void dispatch_calibrate(const char* topic = NULL, const char* payload = NULL) { guiCalibrate(); } -void dispatch_wakeup(const char *, const char *) +void dispatch_wakeup(const char*, const char*) { lv_disp_trig_activity(NULL); } -void dispatch_reboot(const char *, const char *) +void dispatch_reboot(const char*, const char*) { dispatch_reboot(true); } -void dispatch_factory_reset(const char *, const char *) +void dispatch_factory_reset(const char*, const char*) { dispatch_factory_reset(); delay(500); @@ -961,7 +959,7 @@ void dispatch_factory_reset(const char *, const char *) /******************************************* Commands builder *******************************************/ -static void dispatch_add_command(const char * p_cmdstr, void (*func)(const char *, const char *)) +static void dispatch_add_command(const char* p_cmdstr, void (*func)(const char*, const char*)) { if(nCommands >= sizeof(commands) / sizeof(haspCommand_t)) { LOG_FATAL(TAG_MSGR, F("CMD_OVERFLOW %d"), nCommands); diff --git a/src/main_arduino copy.cpp b/src/main_arduino copy.cpp new file mode 100644 index 00000000..6d14b297 --- /dev/null +++ b/src/main_arduino copy.cpp @@ -0,0 +1,194 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#if 0 && ARDUINO + +#include +#include "lvgl.h" +#include "hasp_conf.h" // load first + +#if HASP_USE_CONFIG > 0 +#include "hasp_debug.h" +#endif + +#if HASP_USE_CONFIG > 0 +#include "hasp_config.h" +#include "hasp_gui.h" +#endif + +#include "hasp_oobe.h" + +#include "hasp/hasp_dispatch.h" +#include "hasp/hasp.h" + +#include "sys/net/hasp_network.h" + +#include "dev/device.h" + +bool isConnected; +uint8_t mainLoopCounter = 0; +unsigned long mainLastLoopTime = 0; + +void setup() +{ + hal_setup(); + + haspDevice.init(); + + /**************************** + * Storage initializations + ***************************/ +#if HASP_USE_EEPROM > 0 + eepromSetup(); // Don't start at boot, only at write +#endif + + // #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + // filesystemSetup(); // FS mount is done in configSetup() + // #endif + + // #if HASP_USE_SDCARD > 0 + // sdcardSetup(); + // #endif + + /**************************** + * Read & Apply User Configuration + ***************************/ +#if HASP_USE_CONFIG > 0 + configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart() +#endif + + dispatchSetup(); + guiSetup(); + debugSetup(); // Init the console + +#if HASP_USE_GPIO > 0 + gpioSetup(); +#endif + + /**************************** + * Apply User Configuration + ***************************/ + +#if HASP_USE_MQTT > 0 + mqttSetup(); // Load Hostname before starting WiFi +#endif + +#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0 + networkSetup(); +#endif + +#if HASP_USE_CONFIG > 0 + if(!oobeSetup()) +#endif + { + haspSetup(); + } + +#if HASP_USE_MDNS > 0 + mdnsSetup(); +#endif + +#if HASP_USE_OTA > 0 + otaSetup(); +#endif + +#if HASP_USE_HTTP > 0 + httpSetup(); +#endif + +#if HASP_USE_TELNET > 0 + telnetSetup(); +#endif + +#if HASP_USE_TASMOTA_CLIENT > 0 + slaveSetup(); +#endif + + mainLastLoopTime = millis() - 1000; // reset loop counter + delay(250); + guiStart(); +} + +void loop() +{ + networkLoop(); + guiLoop(); + haspLoop(); + +#if HASP_USE_MQTT > 0 + mqttLoop(); +#endif // MQTT + +#if HASP_USE_TASMOTA_CLIENT > 0 + slaveLoop(); +#endif // TASMOTASLAVE + +#if HASP_USE_HTTP > 0 + httpLoop(); +#endif // HTTP + +#if HASP_USE_GPIO > 0 + gpioLoop(); +#endif // GPIO + +#if HASP_USE_OTA > 0 + otaLoop(); +#endif // OTA + +#if HASP_USE_MDNS > 0 + mdnsLoop(); +#endif // MDNS + +#if HASP_USE_TELNET > 0 + telnetLoop(); // Console +#endif // TELNET + + debugLoop(); // Console + haspDevice.loop(); + + /* Timer Loop */ + if(millis() - mainLastLoopTime >= 1000) { + /* Runs Every Second */ + haspEverySecond(); // sleep timer + debugEverySecond(); // statusupdate + +#if HASP_USE_OTA > 0 + otaEverySecond(); // progressbar +#endif + + /* Runs Every 5 Seconds */ + if(mainLoopCounter == 0 || mainLoopCounter == 5) { + isConnected = networkEvery5Seconds(); // Check connection + +#if HASP_USE_HTTP > 0 + // httpEvery5Seconds(); +#endif + +#if HASP_USE_MQTT > 0 + mqttEvery5Seconds(isConnected); +#endif + +#if HASP_USE_GPIO > 0 + // gpioEvery5Seconds(); +#endif + + haspDevice.loop_5s(); + } + + /* Reset loop counter every 10 seconds */ + if(mainLoopCounter >= 9) { + mainLoopCounter = 0; + } else { + mainLoopCounter++; + } + mainLastLoopTime += 1000; + } + +#ifdef ARDUINO_ARCH_ESP8266 + delay(2); +#else + delay(6); +#endif +} + +#endif \ No newline at end of file diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 89b492c6..65272907 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -33,7 +33,7 @@ void setup() { // hal_setup(); - haspDevice.pre_setup(); + haspDevice.init(); /**************************** * Storage initializations @@ -100,7 +100,7 @@ void setup() telnetSetup(); #endif -#if HASP_USE_TASMOTA_SLAVE > 0 +#if HASP_USE_TASMOTA_CLINET > 0 slaveSetup(); #endif @@ -111,51 +111,24 @@ void setup() void loop() { - networkLoop(); guiLoop(); haspLoop(); + networkLoop(); #if HASP_USE_MQTT > 0 mqttLoop(); #endif // MQTT -#if HASP_USE_TASMOTA_SLAVE > 0 - slaveLoop(); -#endif // TASMOTASLAVE - -#if HASP_USE_HTTP > 0 - httpLoop(); -#endif // HTTP - -#if HASP_USE_GPIO > 0 - gpioLoop(); -#endif // GPIO - -#if HASP_USE_OTA > 0 - otaLoop(); -#endif // OTA - -#if HASP_USE_MDNS > 0 - mdnsLoop(); -#endif // MDNS - -#if HASP_USE_TELNET > 0 - telnetLoop(); // Console -#endif // TELNET - debugLoop(); // Console haspDevice.loop(); /* Timer Loop */ if(millis() - mainLastLoopTime >= 1000) { + /* Runs Every Second */ haspEverySecond(); // sleep timer debugEverySecond(); // statusupdate -#if HASP_USE_OTA > 0 - otaEverySecond(); // progressbar -#endif - /* Runs Every 5 Seconds */ if(mainLoopCounter == 0 || mainLoopCounter == 5) { isConnected = networkEvery5Seconds(); // Check connection diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 56710613..c2e113ab 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -3,19 +3,22 @@ #ifdef WINDOWS - #include "lvgl.h" - #include "app_hal.h" +#include "hasp_conf.h" - #include "hasp_conf.h" - #include "hasp_debug.h" +#include "lvgl.h" +#include "app_hal.h" - #include "hasp/hasp_dispatch.h" - #include "hasp/hasp.h" +#include "hasp_debug.h" +#include "hasp_gui.h" - #include "dev/device.h" - #include "app_hal.h" +#include "hasp/hasp_dispatch.h" +#include "hasp/hasp.h" + +#include "dev/device.h" bool isConnected; +bool isRunning = 1; + uint8_t mainLoopCounter = 0; unsigned long mainLastLoopTime = 0; @@ -27,26 +30,26 @@ void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, c void setup() { - printf("%s %d\n", __FILE__, __LINE__); - fflush(stdout); + // Load Settings + + // Init debug log + // debug_init(); + + // Initialize lvgl environment lv_init(); lv_log_register_print_cb(debugLvglLogEvent); - printf("%s %d\n", __FILE__, __LINE__); - fflush(stdout); + haspDevice.init(); hal_setup(); + guiSetup(); - printf("%s %d\n", __FILE__, __LINE__); - haspDevice.pre_setup(); - - printf("%s %d\n", __FILE__, __LINE__); dispatchSetup(); // debugSetup(); // Init the console - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 printf("%s %d\n", __FILE__, __LINE__); mqttSetup(); // Load Hostname before starting WiFi - #endif +#endif printf("%s %d\n", __FILE__, __LINE__); haspSetup(); @@ -62,15 +65,16 @@ void loop() // debugLoop(); // Console haspDevice.loop(); + guiLoop(); /* Timer Loop */ if(millis() - mainLastLoopTime >= 1000) { /* Runs Every Second */ haspEverySecond(); // sleep timer - #if HASP_USE_OTA > 0 +#if HASP_USE_OTA > 0 otaEverySecond(); // progressbar - #endif +#endif /* Runs Every 5 Seconds */ if(mainLoopCounter == 0 || mainLoopCounter == 5) { @@ -90,32 +94,21 @@ void loop() delay(6); } - #ifdef WINDOWS +#ifdef WINDOWS int main(int argv, char ** args) { - printf("%s %d\n", __FILE__, __LINE__); - fflush(stdout); + // printf("%s %d\n", __FILE__, __LINE__); + // fflush(stdout); setup(); - std::cout << "HSetup OK\n"; - - while(1) { - SDL_Delay(5); - lv_task_handler(); - fflush(stdout); + while(isRunning) { + loop(); + // std::cout << "HSetup OK\n"; } - std::cout << "Hloop OK\n"; return 0; } - #else -void loop() -{ - delay(5); - lv_task_handler(); -} - - #endif +#endif #endif \ No newline at end of file diff --git a/src/sys/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp index 02f299ad..467b6330 100644 --- a/src/sys/net/hasp_network.cpp +++ b/src/sys/net/hasp_network.cpp @@ -117,7 +117,7 @@ bool networkEverySecond(void) return true; } -void network_get_statusupdate(char * buffer, size_t len) +void network_get_statusupdate(char* buffer, size_t len) { #if HASP_USE_ETHERNET > 0 ethernet_get_statusupdate(buffer, len); From b7366336cc2ae4795c38ff4fe528e33649c9420e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Feb 2021 23:18:03 +0100 Subject: [PATCH 048/236] Fix build errors --- src/sys/svc/hasp_telnet.cpp | 111 ++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/src/sys/svc/hasp_telnet.cpp b/src/sys/svc/hasp_telnet.cpp index 6caff6ec..50697059 100644 --- a/src/sys/svc/hasp_telnet.cpp +++ b/src/sys/svc/hasp_telnet.cpp @@ -2,41 +2,44 @@ For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" + #if HASP_USE_TELNET > 0 - #include "ArduinoJson.h" - #include "ConsoleInput.h" +#include "ArduinoJson.h" +#include "ConsoleInput.h" - #include "log/hasp_debug.h" - #include "hasp_config.h" - #include "hasp_telnet.h" +#include "hasp_debug.h" +#include "hasp_config.h" +#include "hasp_telnet.h" +#include "hasp_http.h" - #include "../hasp/hasp_dispatch.h" +#include "../../hasp/hasp_dispatch.h" - #if defined(ARDUINO_ARCH_ESP32) - #include +#if defined(ARDUINO_ARCH_ESP32) +#include WiFiClient telnetClient; -static WiFiServer * telnetServer; - #elif defined(ARDUINO_ARCH_ESP8266) - #include +static WiFiServer* telnetServer; +#elif defined(ARDUINO_ARCH_ESP8266) +#include WiFiClient telnetClient; -static WiFiServer * telnetServer; - #else +static WiFiServer* telnetServer; +#else //#include EthernetClient telnetClient; static EthernetServer telnetServer(23); - #endif +#endif - #if HASP_USE_HTTP > 0 -extern char httpUser[32]; -extern char httpPassword[32]; - #endif +#if HASP_USE_HTTP > 0 +// extern char http_config.user[32]; +// extern char http_config.password[32]; +extern hasp_http_config_t http_config; +#endif uint8_t telnetLoginState = TELNET_UNAUTHENTICATED; uint16_t telnetPort = 23; uint8_t telnetEnabled = true; // Enable telnet debug output uint8_t telnetLoginAttempt = 0; // Initial attempt -ConsoleInput * telnetConsole; +ConsoleInput* telnetConsole; void telnetClientDisconnect() { @@ -83,34 +86,34 @@ void telnetAcceptClient() // telnetClient.print((char)0xFD); // telnetClient.print((char)0x1B); - #if HASP_USE_HTTP > 0 - if(strlen(httpUser) != 0 || strlen(httpPassword) != 0) { - telnetClient.println(F("\r\n" D_TELNET_USERNAME " ")); +#if HASP_USE_HTTP > 0 + if(strlen(http_config.user) != 0 || strlen(http_config.password) != 0) { + telnetClient.println(F("\r\n" D_USERNAME " ")); telnetLoginState = TELNET_UNAUTHENTICATED; } else - #endif +#endif { telnetClientLogon(); } telnetLoginAttempt = 0; // Initial attempt } - #if 0 +#if 0 static inline void telnetProcessLine() { telnetInputBuffer[telnetInputIndex] = 0; // null terminate our char array switch(telnetLoginState) { case TELNET_UNAUTHENTICATED: { - telnetClient.printf(PSTR(D_TELNET_PASSWORD" %c%c%c"), 0xFF, 0xFB, 0x01); // Hide characters - #if HASP_USE_HTTP > 0 - telnetLoginState = strcmp(telnetInputBuffer, httpUser) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK; + telnetClient.printf(PSTR(D_PASSWORD" %c%c%c"), 0xFF, 0xFB, 0x01); // Hide characters +#if HASP_USE_HTTP > 0 + telnetLoginState = strcmp(telnetInputBuffer, http_config.user) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK; break; } case TELNET_USERNAME_OK: case TELNET_USERNAME_NOK: { telnetClient.printf(PSTR("%c%c%c\n"), 0xFF, 0xFC, 0x01); // Show characters - if(telnetLoginState == TELNET_USERNAME_OK && strcmp(telnetInputBuffer, httpPassword) == 0) { + if(telnetLoginState == TELNET_USERNAME_OK && strcmp(telnetInputBuffer, http_config.password) == 0) { telnetClientLogon(); } else { telnetLoginState = TELNET_UNAUTHENTICATED; @@ -120,12 +123,12 @@ static inline void telnetProcessLine() if(telnetLoginAttempt >= 3) { telnetClientDisconnect(); } else { - telnetClient.print(F(D_TELNET_USERNAME" ")); + telnetClient.print(F(D_USERNAME" ")); } } - #else +#else telnetClientLogon(); - #endif +#endif break; } default: @@ -179,24 +182,24 @@ static inline void telnetProcessCharacter(char ch) //} } - #endif +#endif -static inline void telnetProcessLine(const char * input) +static inline void telnetProcessLine(const char* input) { switch(telnetLoginState) { case TELNET_UNAUTHENTICATED: { char buffer[20]; - snprintf_P(buffer, sizeof(buffer), PSTR(D_TELNET_PASSWORD " %c%c%c\n"), 0xFF, 0xFB, + snprintf_P(buffer, sizeof(buffer), PSTR(D_PASSWORD " %c%c%c\n"), 0xFF, 0xFB, 0x01); // Hide characters telnetClient.print(buffer); - #if HASP_USE_HTTP > 0 - telnetLoginState = strcmp(input, httpUser) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK; +#if HASP_USE_HTTP > 0 + telnetLoginState = strcmp(input, http_config.user) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK; break; } case TELNET_USERNAME_OK: case TELNET_USERNAME_NOK: { telnetClient.printf(PSTR("%c%c%c\n"), 0xFF, 0xFC, 0x01); // Show characters - if(telnetLoginState == TELNET_USERNAME_OK && strcmp(input, httpPassword) == 0) { + if(telnetLoginState == TELNET_USERNAME_OK && strcmp(input, http_config.password) == 0) { telnetClientLogon(); } else { telnetLoginState = TELNET_UNAUTHENTICATED; @@ -206,19 +209,19 @@ static inline void telnetProcessLine(const char * input) if(telnetLoginAttempt >= 3) { telnetClientDisconnect(); } else { - telnetClient.print(F(D_TELNET_USERNAME " ")); + telnetClient.print(F(D_USERNAME " ")); } } - #else +#else telnetClientLogon(); - #endif +#endif break; } default: if(strcasecmp_P(input, PSTR("exit")) == 0) { telnetClientDisconnect(); } else if(strcasecmp_P(input, PSTR("logoff")) == 0) { - telnetClient.println(F("\r\n" D_TELNET_USERNAME " ")); + telnetClient.println(F("\r\n" D_USERNAME " ")); telnetLoginState = TELNET_UNAUTHENTICATED; } else { dispatch_text_line(input); @@ -231,15 +234,15 @@ void telnetSetup() // telnetSetConfig(settings); if(telnetEnabled) { // Setup telnet server for remote debug output - #if defined(STM32F4xx) +#if defined(STM32F4xx) // if(!telnetServer) telnetServer = new EthernetServer(telnetPort); // if(telnetServer) { telnetServer->begin(); LOG_INFO(TAG_TELN, F(D_TELNET_STARTED)); - // } else { - // LOG_ERROR(TAG_TELN,F("Failed to start telnet server")); - //} - #else + // } else { + // LOG_ERROR(TAG_TELN,F("Failed to start telnet server")); + //} +#else if(!telnetServer) telnetServer = new WiFiServer(telnetPort); if(telnetServer) { telnetServer->setNoDelay(true); @@ -254,7 +257,7 @@ void telnetSetup() } LOG_ERROR(TAG_TELN, F(D_TELNET_FAILED)); - #endif +#endif } } @@ -262,7 +265,7 @@ void telnetLoop() { // Basic telnet client handling code from: https://gist.github.com/tablatronix/4793677ca748f5f584c95ec4a2b10303 - #if defined(STM32F4xx) +#if defined(STM32F4xx) Ethernet.schedule(); // if(telnetServer) { // client is connected @@ -289,7 +292,7 @@ void telnetLoop() } } } - #else +#else if(telnetServer && telnetServer->hasClient()) { // a new client has connected if(!telnetClient.connected()) { // nobody is already connected telnetAcceptClient(); // allow the new client @@ -312,11 +315,11 @@ void telnetLoop() } } } - #endif +#endif } - #if HASP_USE_CONFIG > 0 -bool telnetGetConfig(const JsonObject & settings) +#if HASP_USE_CONFIG > 0 +bool telnetGetConfig(const JsonObject& settings) { bool changed = false; @@ -338,7 +341,7 @@ bool telnetGetConfig(const JsonObject & settings) * * @param[in] settings JsonObject with the config settings. **/ -bool telnetSetConfig(const JsonObject & settings) +bool telnetSetConfig(const JsonObject& settings) { configOutput(settings, TAG_TELN); bool changed = false; @@ -348,6 +351,6 @@ bool telnetSetConfig(const JsonObject & settings) return changed; } - #endif // HASP_USE_CONFIG +#endif // HASP_USE_CONFIG #endif \ No newline at end of file From 7857ea03ed19898bc3d914239682e188656b70a2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 18 Feb 2021 19:06:46 +0100 Subject: [PATCH 049/236] Changes to haspDevice class --- src/dev/device.h | 23 ++- src/dev/esp32/esp32.cpp | 30 ++-- src/dev/esp32/esp32.h | 16 +-- src/dev/esp32/lanbonl8.cpp | 3 +- src/dev/esp32/lanbonl8.h | 1 + src/dev/esp32/m5stackcore2.cpp | 1 + src/dev/esp8266/esp8266.h | 1 - src/dev/win32/hasp_win32.cpp | 86 ++++++++++++ src/dev/win32/hasp_win32.h | 52 +++++++ src/drv/tft_espi_drv.cpp | 24 ++-- src/hasp/hasp.cpp | 63 ++++----- src/hasp/hasp.h | 46 +++--- src/hasp/hasp_dispatch.cpp | 27 +++- src/hasp/hasp_dispatch.h | 41 +++--- src/hasp/hasp_object.cpp | 102 +++++++------- src/hasp/hasp_utilities.cpp | 51 ++++++- src/hasp/hasp_utilities.h | 11 +- src/hasp_gui.cpp | 80 +++++------ src/mqtt/hasp_mqtt.h | 16 +-- src/mqtt/hasp_mqtt_paho.cpp | 192 +++++++++++++------------- src/mqtt/hasp_mqtt_pubsubclient.cpp | 150 ++++++++++---------- src/sys/net/hasp_ethernet_esp32.cpp | 9 +- src/sys/net/hasp_wifi.cpp | 25 ++-- src/sys/svc/hasp_mdns.cpp | 42 +++--- src/sys/svc/hasp_ota.cpp | 12 +- user_setups/win32/emulator_64bits.ini | 17 +-- 26 files changed, 669 insertions(+), 452 deletions(-) create mode 100644 src/dev/win32/hasp_win32.cpp create mode 100644 src/dev/win32/hasp_win32.h diff --git a/src/dev/device.h b/src/dev/device.h index a56bcf4d..bb68fd42 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -8,6 +8,11 @@ #include "Arduino.h" #endif +#ifdef WINDOWS +#include +#include "Windows.h" +#endif + namespace dev { class BaseDevice { @@ -17,6 +22,19 @@ class BaseDevice { virtual void reboot() {} + virtual const char* get_hostname() + { + return ""; + } + virtual const char* get_core_version() + { + return ""; + } + virtual const char* get_display_driver() + { + return ""; + } + virtual void init() {} virtual void post_setup() @@ -60,10 +78,13 @@ class BaseDevice { #elif defined(STM32F4) #warning Building for STM32F4xx Devices #include "stm32f4/stm32f4.h" +#elif defined(WINDOWS) +#warning Building for Win32 Devices +#include "win32/hasp_win32.h" #else #warning Building for Generic Devices using dev::BaseDevice; - extern dev::BaseDevice haspDevice; #endif + #endif \ No newline at end of file diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index d4f6a9ef..2dbdd88d 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -12,6 +12,7 @@ #include "hasp_conf.h" #include "hasp_debug.h" +#include "hasp/hasp_utilities.h" #define BACKLIGHT_CHANNEL 0 @@ -22,17 +23,31 @@ void Esp32Device::reboot() ESP.restart(); } +const char* Esp32Device::get_hostname() +{ + return hostname.c_str(); +} +const char* Esp32Device::get_core_version() +{ + return ESP.getSdkVersion(); +} +const char* Esp32Device::get_display_driver() +{ + return Utilities::tft_driver_name().c_str(); +} + void Esp32Device::set_backlight_pin(uint8_t pin) { Esp32Device::backlight_pin = pin; - /* Setup Backlight Control Pin */ - if(pin >= 0) { - LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); + /* Setup Backlight Control Pin */ + if(pin != (uint8_t)-1) { + LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); ledcSetup(BACKLIGHT_CHANNEL, 20000, 12); ledcAttachPin(pin, BACKLIGHT_CHANNEL); - update_backlight(); + } else { + LOG_VERBOSE(TAG_GUI, F("Backlight : Pin not set")); } } @@ -62,11 +77,10 @@ bool Esp32Device::get_backlight_power() void Esp32Device::update_backlight() { - if(backlight_pin == -1) return; + if(backlight_pin == (uint8_t)-1) return; - if(backlight_power) { // The backlight is ON - ledcWrite(BACKLIGHT_CHANNEL, map(backlight_level, 0, 100, 0, 4095)); // ledChannel and value - } + uint32_t duty = backlight_power ? map(backlight_level, 0, 100, 0, 4095) : 0; + ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value } size_t Esp32Device::get_free_max_block() diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 7c950867..db5605ab 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -15,25 +15,24 @@ class Esp32Device : public BaseDevice { public: void reboot() override; + const char* get_hostname(); + const char* get_core_version(); + const char* get_display_driver(); + void set_backlight_pin(uint8_t pin) override; - void set_backlight_level(uint8_t val) override; - uint8_t get_backlight_level() override; - void set_backlight_power(bool power) override; - bool get_backlight_power() override; size_t get_free_max_block() override; - size_t get_free_heap() override; - uint8_t get_heap_fragmentation() override; - uint16_t get_cpu_frequency() override; private: + std::string hostname; + uint8_t backlight_pin; uint8_t backlight_level; uint8_t backlight_power; @@ -43,8 +42,6 @@ class Esp32Device : public BaseDevice { } // namespace dev -using dev::Esp32Device; - #if defined(LANBONL8) #warning Building for Lanbon L8 #include "lanbonl8.h" @@ -52,6 +49,7 @@ using dev::Esp32Device; #warning Building for M5Stack core2 #include "m5stackcore2.h" #else +using dev::Esp32Device; extern dev::Esp32Device haspDevice; #endif #endif // ESP32 diff --git a/src/dev/esp32/lanbonl8.cpp b/src/dev/esp32/lanbonl8.cpp index 05a3cc8e..e72c21c5 100644 --- a/src/dev/esp32/lanbonl8.cpp +++ b/src/dev/esp32/lanbonl8.cpp @@ -14,7 +14,7 @@ #define BACKLIGHT_CHANNEL 0 #define REF_VOLTAGE 1100 -esp_adc_cal_characteristics_t * adc_chars = +esp_adc_cal_characteristics_t* adc_chars = new esp_adc_cal_characteristics_t; // adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t)); namespace dev { @@ -64,4 +64,5 @@ void LanbonL8::init() } // namespace dev dev::LanbonL8 haspDevice; + #endif diff --git a/src/dev/esp32/lanbonl8.h b/src/dev/esp32/lanbonl8.h index 6bc4a747..3ec1fa93 100644 --- a/src/dev/esp32/lanbonl8.h +++ b/src/dev/esp32/lanbonl8.h @@ -17,6 +17,7 @@ class LanbonL8 : public Esp32Device { } // namespace dev +using dev::LanbonL8; extern dev::LanbonL8 haspDevice; #endif diff --git a/src/dev/esp32/m5stackcore2.cpp b/src/dev/esp32/m5stackcore2.cpp index e0eed7d0..e86bb404 100644 --- a/src/dev/esp32/m5stackcore2.cpp +++ b/src/dev/esp32/m5stackcore2.cpp @@ -43,4 +43,5 @@ void M5StackCore2::init(void) } // namespace dev dev::M5StackCore2 haspDevice; + #endif diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 29a57ef3..c96641fc 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -45,7 +45,6 @@ class Esp8266Device : public BaseDevice { } // namespace dev using dev::Esp8266Device; - extern dev::Esp8266Device haspDevice; #endif // ESP8266 diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp new file mode 100644 index 00000000..9447de8b --- /dev/null +++ b/src/dev/win32/hasp_win32.cpp @@ -0,0 +1,86 @@ +#if defined(WINDOWS) + +#include +#include "Windows.h" + +#include "hasp_win32.h" + +#include "hasp_conf.h" +#include "hasp_debug.h" + +namespace dev { + +void Win32Device::reboot() +{} + +const char* Win32Device::get_hostname() +{ + return "winhasp"; +} +const char* Win32Device::get_core_version() +{ + return "win32"; +} +const char* Win32Device::get_display_driver() +{ + return "test"; +} + +void Win32Device::set_backlight_pin(uint8_t pin) +{ + Win32Device::backlight_pin = pin; +} + +void Win32Device::set_backlight_level(uint8_t level) +{ + backlight_level = level >= 0 ? level : 0; + backlight_level = backlight_level <= 100 ? backlight_level : 100; + update_backlight(); +} + +uint8_t Win32Device::get_backlight_level() +{ + return backlight_level; +} + +void Win32Device::set_backlight_power(bool power) +{ + backlight_power = power; + update_backlight(); +} + +bool Win32Device::get_backlight_power() +{ + return backlight_power != 0; +} + +void Win32Device::update_backlight() +{ + if(backlight_pin == -1) return; +} + +size_t Win32Device::get_free_max_block() +{ + return 0; +} + +size_t Win32Device::get_free_heap(void) +{ + return 0; +} + +uint8_t Win32Device::get_heap_fragmentation() +{ + return 0; +} + +uint16_t Win32Device::get_cpu_frequency() +{ + return 0; +} + +} // namespace dev + +dev::Win32Device haspDevice; + +#endif // WINDOWS \ No newline at end of file diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h new file mode 100644 index 00000000..2d739e9a --- /dev/null +++ b/src/dev/win32/hasp_win32.h @@ -0,0 +1,52 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_DEVICE_WINDOWS_H +#define HASP_DEVICE_WINDOWS_H + +#include +#include "Windows.h" + +#include "hasp_conf.h" +#include "../device.h" + +#if defined(WINDOWS) + +namespace dev { + +class Win32Device : public BaseDevice { + + public: + void reboot() override; + + const char* get_hostname() override; + const char* get_core_version() override; + const char* get_display_driver() override; + + void set_backlight_pin(uint8_t pin); + void set_backlight_level(uint8_t val); + uint8_t get_backlight_level(); + void set_backlight_power(bool power); + bool get_backlight_power(); + + size_t get_free_max_block(); + size_t get_free_heap(); + uint8_t get_heap_fragmentation(); + uint16_t get_cpu_frequency(); + + private: + uint8_t backlight_pin; + uint8_t backlight_level; + uint8_t backlight_power; + + void update_backlight(); +}; + +} // namespace dev + +using dev::Win32Device; +extern dev::Win32Device haspDevice; + +#endif // WINDOWS + +#endif // HASP_DEVICE_WINDOWS_H \ No newline at end of file diff --git a/src/drv/tft_espi_drv.cpp b/src/drv/tft_espi_drv.cpp index 2b090569..dc924ba0 100644 --- a/src/drv/tft_espi_drv.cpp +++ b/src/drv/tft_espi_drv.cpp @@ -36,8 +36,8 @@ /********************** * STATIC PROTOTYPES **********************/ -static void tftShowConfig(TFT_eSPI & tft); -static inline void tftShowLogo(TFT_eSPI & tft); +static void tftShowConfig(TFT_eSPI& tft); +static inline void tftShowLogo(TFT_eSPI& tft); /********************** * STATIC VARIABLES @@ -74,7 +74,7 @@ void tft_espi_init(uint8_t rotation, bool invert_display) tftShowConfig(tft); } -void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) +void tft_espi_flush(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) { size_t len = lv_area_get_size(area); @@ -82,9 +82,9 @@ void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * c tft.startWrite(); /* Start new TFT transaction */ tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */ #ifdef USE_DMA_TO_TFT - tft.pushPixelsDMA((uint16_t *)color_p, len); /* Write words at once */ + tft.pushPixelsDMA((uint16_t*)color_p, len); /* Write words at once */ #else - tft.pushPixels((uint16_t *)color_p, len); /* Write words at once */ + tft.pushPixels((uint16_t*)color_p, len); /* Write words at once */ #endif tft.endWrite(); /* terminate TFT transaction */ @@ -104,7 +104,7 @@ void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * c #if defined(TOUCH_CS) -void tft_espi_calibrate(uint16_t * calData) +void tft_espi_calibrate(uint16_t* calData) { tft.fillScreen(TFT_BLACK); tft.setCursor(20, 0); @@ -120,14 +120,14 @@ void tft_espi_calibrate(uint16_t * calData) tft.setTouch(calData); } -void tft_espi_set_touch(uint16_t * calData) +void tft_espi_set_touch(uint16_t* calData) { tft.setTouch(calData); } -bool tft_espi_get_touch(int16_t * touchX, int16_t * touchY, uint16_t threshold) +bool tft_espi_get_touch(int16_t* touchX, int16_t* touchY, uint16_t threshold) { - return tft.getTouch((uint16_t *)touchX, (uint16_t *)touchY, threshold); + return tft.getTouch((uint16_t*)touchX, (uint16_t*)touchY, threshold); } #endif @@ -149,7 +149,7 @@ static void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset) } } -static void tftPinInfo(const __FlashStringHelper * pinfunction, int8_t pin) +static void tftPinInfo(const __FlashStringHelper* pinfunction, int8_t pin) { if(pin != -1) { char buffer[64]; @@ -158,7 +158,7 @@ static void tftPinInfo(const __FlashStringHelper * pinfunction, int8_t pin) } } -static void tftShowConfig(TFT_eSPI & tft) +static void tftShowConfig(TFT_eSPI& tft) { setup_t tftSetup; tft.getSetup(tftSetup); @@ -246,7 +246,7 @@ static void tftShowConfig(TFT_eSPI & tft) } } -static inline void tftShowLogo(TFT_eSPI & tft) +static inline void tftShowLogo(TFT_eSPI& tft) { tft.fillScreen(TFT_DARKCYAN); int x = (tft.width() - logoWidth) / 2; diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index ee971af3..319852b2 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -8,13 +8,14 @@ #include "ArduinoJson.h" #include "hasp_conf.h" +#include "dev/device.h" + #if HASP_USE_EEPROM > 0 #include "StreamUtils.h" // For EEPromStream #endif #include "lvgl.h" #include "lv_conf.h" -#include "hasp_conf.h" #if HASP_USE_DEBUG > 0 #include "../hasp_debug.h" @@ -32,7 +33,6 @@ #include "hasp_attribute.h" #include "hasp.h" -#include "dev/device.h" #include "lv_theme_hasp.h" #if HASP_USE_EEPROM > 0 @@ -73,7 +73,7 @@ LV_IMG_DECLARE(img_bubble_pattern) /********************** * GLOBAL FUNCTIONS **********************/ -void haspLoadPage(const char * pages); +void haspLoadPage(const char* pages); //////////////////////////////////////////////////////////////////////////////////////////////////// uint8_t hasp_sleep_state = HASP_SLEEP_OFF; // Used in hasp_drv_touch.cpp @@ -88,18 +88,18 @@ char haspPagesPath[32] = "/pages.jsonl"; char haspZiFontPath[32]; lv_style_t style_mbox_bg; /*Black bg. style with opacity*/ -lv_obj_t * kb; +lv_obj_t* kb; // lv_font_t * defaultFont; -lv_obj_t * pages[HASP_NUM_PAGES]; -static lv_font_t * haspFonts[4] = {nullptr, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, - LV_THEME_DEFAULT_FONT_TITLE}; -uint8_t current_page = 1; +lv_obj_t* pages[HASP_NUM_PAGES]; +static lv_font_t* haspFonts[4] = {nullptr, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, + LV_THEME_DEFAULT_FONT_TITLE}; +uint8_t current_page = 1; /** * Get Font ID */ -lv_font_t * hasp_get_font(uint8_t fontid) +lv_font_t* hasp_get_font(uint8_t fontid) { if(fontid >= 4) { return nullptr; @@ -145,7 +145,7 @@ void hasp_enable_wakeup_touch() /** * Return the sleep times */ -void hasp_get_sleep_time(uint16_t & short_time, uint16_t & long_time) +void hasp_get_sleep_time(uint16_t& short_time, uint16_t& long_time) { short_time = sleepTimeShort; long_time = sleepTimeLong; @@ -163,16 +163,17 @@ void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time) /** * Checks if we went to sleep, wake up is handled in the event handlers */ -// void haspEverySecond() -// { -// hasp_update_sleep_state(); -// } +void haspEverySecond() +{ + hasp_update_sleep_state(); + dispatchEverySecond(); +} //////////////////////////////////////////////////////////////////////////////////////////////////// /** * Get Page Object by PageID */ -lv_obj_t * get_page_obj(uint8_t pageid) +lv_obj_t* get_page_obj(uint8_t pageid) { if(pageid == 0) return lv_layer_top(); // 254 if(pageid == 255) return lv_layer_sys(); @@ -180,9 +181,9 @@ lv_obj_t * get_page_obj(uint8_t pageid) return pages[pageid - PAGE_START_INDEX]; } -bool get_page_id(lv_obj_t * obj, uint8_t * pageid) +bool get_page_id(lv_obj_t* obj, uint8_t* pageid) { - lv_obj_t * page = lv_obj_get_screen(obj); + lv_obj_t* page = lv_obj_get_screen(obj); if(!page) return false; @@ -248,8 +249,8 @@ void haspReconnect() // Shows/hides the the global progress bar and updates the value void haspProgressVal(uint8_t val) { - lv_obj_t * layer = lv_disp_get_layer_sys(NULL); - lv_obj_t * bar = hasp_find_obj_from_parent_id(get_page_obj(255), (uint8_t)10); + lv_obj_t* layer = lv_disp_get_layer_sys(NULL); + lv_obj_t* bar = hasp_find_obj_from_parent_id(get_page_obj(255), (uint8_t)10); if(layer && bar) { if(val == 255) { if(!lv_obj_get_hidden(bar)) { @@ -276,9 +277,9 @@ void haspProgressVal(uint8_t val) } // Sets the value string of the global progress bar -void haspProgressMsg(const char * msg) +void haspProgressMsg(const char* msg) { - lv_obj_t * bar = hasp_find_obj_from_parent_id(get_page_obj(255), (uint8_t)10); + lv_obj_t* bar = hasp_find_obj_from_parent_id(get_page_obj(255), (uint8_t)10); if(bar) { char value_str[10]; @@ -299,16 +300,16 @@ void haspProgressMsg(const char * msg) #ifdef ARDUINO // Sets the value string of the global progress bar -void haspProgressMsg(const __FlashStringHelper * msg) +void haspProgressMsg(const __FlashStringHelper* msg) { haspProgressMsg(String(msg).c_str()); } #endif /*Add a custom apply callback*/ -static void custom_font_apply_cb(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) +static void custom_font_apply_cb(lv_theme_t* th, lv_obj_t* obj, lv_theme_style_t name) { - lv_style_list_t * list; + lv_style_list_t* list; switch(name) { case LV_THEME_BTN: @@ -377,7 +378,7 @@ void haspSetup(void) if(haspThemeId == 9) haspThemeId = 5; // update old material id if(haspThemeId < 0 || haspThemeId > 5) haspThemeId = 1; // check bounds - lv_theme_t * th = NULL; + lv_theme_t* th = NULL; #if(LV_USE_THEME_HASP == 1) lv_theme_hasp_flag_t hasp_flags = LV_THEME_HASP_FLAG_LIGHT; #endif @@ -530,14 +531,14 @@ void hasp_background(uint16_t pageid, uint16_t imageid) /////////////////////////////////////////////////////////////////////////////////////////////////////////// -void haspGetVersion(char * version, size_t len) +void haspGetVersion(char* version, size_t len) { snprintf_P(version, len, PSTR("%u.%u.%u"), HASP_VER_MAJ, HASP_VER_MIN, HASP_VER_REV); } void haspClearPage(uint16_t pageid) { - lv_obj_t * page = get_page_obj(pageid); + lv_obj_t* page = get_page_obj(pageid); if(!page || (pageid > HASP_NUM_PAGES)) { LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_PAGE), pageid); } else if(page == lv_layer_sys() /*|| page == lv_layer_top()*/) { @@ -555,7 +556,7 @@ uint8_t haspGetPage() void haspSetPage(uint8_t pageid) { - lv_obj_t * page = get_page_obj(pageid); + lv_obj_t* page = get_page_obj(pageid); if(!page || pageid == 0 || pageid > HASP_NUM_PAGES) { LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_PAGE), pageid); } else { @@ -566,7 +567,7 @@ void haspSetPage(uint8_t pageid) } } -void haspLoadPage(const char * pagesfile) +void haspLoadPage(const char* pagesfile) { #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 if(pagesfile[0] == '\0') return; @@ -602,7 +603,7 @@ void haspLoadPage(const char * pagesfile) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_CONFIG > 0 -bool haspGetConfig(const JsonObject & settings) +bool haspGetConfig(const JsonObject& settings) { bool changed = false; @@ -636,7 +637,7 @@ bool haspGetConfig(const JsonObject & settings) * * @param[in] settings JsonObject with the config settings. **/ -bool haspSetConfig(const JsonObject & settings) +bool haspSetConfig(const JsonObject& settings) { configOutput(settings, TAG_HASP); bool changed = false; diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index 0b0b260f..d7bc4eaa 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -15,7 +15,8 @@ #include "hasp_utilities.h" #if HASP_USE_DEBUG > 0 - #include "../hasp_debug.h" +#include "../hasp_debug.h" +#include "dev/device.h" #endif #define NORMALIZE(a, b, c) map(a, b, c, 0, 0xFFFFU) @@ -30,12 +31,12 @@ extern "C" { #if HASP_USE_APP > 0 - /********************* - * DEFINES - *********************/ - #define HASP_SLEEP_OFF 0 - #define HASP_SLEEP_SHORT 1 - #define HASP_SLEEP_LONG 2 +/********************* + * DEFINES + *********************/ +#define HASP_SLEEP_OFF 0 +#define HASP_SLEEP_SHORT 1 +#define HASP_SLEEP_LONG 2 /********************** * TYPEDEFS @@ -50,41 +51,40 @@ extern "C" { */ void haspSetup(void); void haspLoop(void); -// void haspEverySecond(void); // See MACROS +void haspEverySecond(void); void haspReconnect(void); void haspDisconnect(void); -lv_obj_t * get_page_obj(uint8_t pageid); -bool get_page_id(lv_obj_t * obj, uint8_t * pageid); +lv_obj_t* get_page_obj(uint8_t pageid); +bool get_page_id(lv_obj_t* obj, uint8_t* pageid); void haspSetPage(uint8_t id); uint8_t haspGetPage(); void haspClearPage(uint16_t pageid); -void haspGetVersion(char * version, size_t len); +void haspGetVersion(char* version, size_t len); // void haspBackground(uint16_t pageid, uint16_t imageid); // void haspNewObject(const JsonObject & config, uint8_t & saved_page_id); void haspProgressVal(uint8_t val); - #if HASP_USE_CONFIG > 0 -bool haspGetConfig(const JsonObject & settings); -bool haspSetConfig(const JsonObject & settings); - #endif +#if HASP_USE_CONFIG > 0 +bool haspGetConfig(const JsonObject& settings); +bool haspSetConfig(const JsonObject& settings); +#endif -lv_font_t * hasp_get_font(uint8_t fontid); +lv_font_t* hasp_get_font(uint8_t fontid); bool hasp_update_sleep_state(); -void hasp_get_sleep_time(uint16_t & short_time, uint16_t & long_time); +void hasp_get_sleep_time(uint16_t& short_time, uint16_t& long_time); void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time); void hasp_enable_wakeup_touch(); - /********************** - * MACROS - **********************/ - #define haspEverySecond hasp_update_sleep_state +/********************** + * MACROS + **********************/ #endif /*HASP_USE_APP*/ @@ -92,9 +92,9 @@ void hasp_enable_wakeup_touch(); } /* extern "C" */ #endif -void haspProgressMsg(const char * msg); +void haspProgressMsg(const char* msg); #ifdef ARDUINO -void haspProgressMsg(const __FlashStringHelper * msg); +void haspProgressMsg(const __FlashStringHelper* msg); #endif #endif /*HASP_H*/ diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index c146c26b..3ca31c20 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -46,7 +46,7 @@ extern uint8_t hasp_sleep_state; -dispatch_conf_t dispatch_setings = {.teleperiod = 300}; +dispatch_conf_t dispatch_setings = {.teleperiod = 10}; uint32_t dispatchLastMillis; uint8_t nCommands = 0; @@ -897,18 +897,32 @@ void dispatch_output_statusupdate(const char*, const char*) { char buffer[128]; + printf("%s %d\n", __FILE__, __LINE__); + fflush(stdout); + haspGetVersion(buffer, sizeof(buffer)); snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), - mqttGetNodename().c_str(), buffer, long(millis() / 1000)); + haspDevice.get_hostname(), buffer, long(millis() / 1000)); + + printf("%s %d\n", __FILE__, __LINE__); + fflush(stdout); #if HASP_USE_WIFI > 0 network_get_statusupdate(buffer, sizeof(buffer)); strcat(data, buffer); #endif + + printf("%s %d\n", __FILE__, __LINE__); + fflush(stdout); + snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","), - haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), halGetCoreVersion().c_str()); + haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), haspDevice.get_core_version()); strcat(data, buffer); + + printf("%s %d\n", __FILE__, __LINE__); + fflush(stdout); + snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), haspGetPage(), (HASP_NUM_PAGES)); strcat(data, buffer); @@ -918,8 +932,11 @@ void dispatch_output_statusupdate(const char*, const char*) strcat(data, buffer); #endif + printf("%s %d\n", __FILE__, __LINE__); + fflush(stdout); + snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), - halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); + haspDevice.get_display_driver(), (TFT_WIDTH), (TFT_HEIGHT)); strcat(data, buffer); } mqtt_send_state(F("statusupdate"), data); @@ -1006,7 +1023,7 @@ void dispatchLoop() } #if 1 || ARDUINO -void everySecond() +void dispatchEverySecond() { if(dispatch_setings.teleperiod > 0 && (millis() - dispatchLastMillis) >= dispatch_setings.teleperiod * 1000) { dispatchLastMillis = millis(); diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 017d825a..254c1d0d 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -7,7 +7,8 @@ #include "ArduinoJson.h" #include "lvgl.h" -struct dispatch_conf_t { +struct dispatch_conf_t +{ uint16_t teleperiod; }; @@ -32,43 +33,43 @@ void dispatchStart(void); void dispatchStop(void); /* ===== Special Event Processors ===== */ -void dispatch_topic_payload(const char * topic, const char * payload); -void dispatch_text_line(const char * cmnd); +void dispatch_topic_payload(const char* topic, const char* payload); +void dispatch_text_line(const char* cmnd); #ifdef ARDUINO -void dispatch_parse_jsonl(Stream &stream); +void dispatch_parse_jsonl(Stream& stream); #else -void dispatch_parse_jsonl(std::istringstream &stream); +void dispatch_parse_jsonl(std::istringstream& stream); #endif -void dispatch_clear_page(const char * page); -void dispatch_json_error(uint8_t tag, DeserializationError & jsonError); +void dispatch_clear_page(const char* page); +void dispatch_json_error(uint8_t tag, DeserializationError& jsonError); // void dispatchPage(uint8_t page); void dispatch_page_next(); void dispatch_page_prev(); -void dispatch_dim(const char * level); -void dispatch_backlight(const char * payload); +void dispatch_dim(const char* level); +void dispatch_backlight(const char* payload); -void dispatch_web_update(const char * espOtaUrl); +void dispatch_web_update(const char* espOtaUrl); void dispatch_reboot(bool saveConfig); void dispatch_output_idle_state(uint8_t state); -void dispatch_output_statusupdate(const char *, const char *); +void dispatch_output_statusupdate(const char*, const char*); void dispatch_current_state(); void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid); -void dispatch_object_event(lv_obj_t * obj, uint8_t eventid); +void dispatch_object_event(lv_obj_t* obj, uint8_t eventid); bool dispatch_get_event_state(uint8_t eventid); -void dispatch_get_event_name(uint8_t eventid, char * buffer, size_t size); -void dispatch_object_value_changed(lv_obj_t * obj, int16_t state); +void dispatch_get_event_name(uint8_t eventid, char* buffer, size_t size); +void dispatch_object_value_changed(lv_obj_t* obj, int16_t state); -void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t * obj); +void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t* obj); -void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data); -void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val); -void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char * attribute, uint8_t r, uint8_t g, +void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char* attribute, const char* data); +void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char* attribute, int32_t val); +void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char* attribute, uint8_t r, uint8_t g, uint8_t b); /* ===== Getter and Setter Functions ===== */ @@ -78,8 +79,8 @@ void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char /* ===== Structs and Constants ===== */ struct haspCommand_t { - void (*func)(const char *, const char *); - const char * p_cmdstr; + void (*func)(const char*, const char*); + const char* p_cmdstr; }; #endif \ No newline at end of file diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 9b300088..68312705 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -14,12 +14,12 @@ ******************************************************************************************** */ #ifdef ARDUINO - #include "ArduinoLog.h" +#include "ArduinoLog.h" #endif #include "lvgl.h" #if LVGL_VERSION_MAJOR != 7 - #include "../lv_components.h" +#include "../lv_components.h" #endif #include "hasp.h" @@ -29,31 +29,31 @@ #include "hasp_utilities.h" #include "hasp_parser.h" -const char ** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map +const char** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map // static unsigned long last_change_event = 0; static bool last_press_was_short = false; // Avoid SHORT + UP double events // ##################### Object Finders ######################################################## -lv_obj_t * hasp_find_obj_from_parent_id(lv_obj_t * parent, uint8_t objid) +lv_obj_t* hasp_find_obj_from_parent_id(lv_obj_t* parent, uint8_t objid) { if(objid == 0 || parent == nullptr) return parent; - lv_obj_t * child; + lv_obj_t* child; child = lv_obj_get_child(parent, NULL); while(child) { /* child found, return it */ if(objid == child->user_data.id) return child; /* check grandchildren */ - lv_obj_t * grandchild = hasp_find_obj_from_parent_id(child, objid); + lv_obj_t* grandchild = hasp_find_obj_from_parent_id(child, objid); if(grandchild) return grandchild; /* grandchild found, return it */ /* check tabs */ if(check_obj_type(child, LV_HASP_TABVIEW)) { uint16_t tabcount = lv_tabview_get_tab_count(child); for(uint16_t i = 0; i < tabcount; i++) { - lv_obj_t * tab = lv_tabview_get_tab(child, i); + lv_obj_t* tab = lv_tabview_get_tab(child, i); LOG_VERBOSE(TAG_HASP, "Found tab %i", i); if(tab->user_data.objid && objid == tab->user_data.objid) return tab; /* tab found, return it */ @@ -74,7 +74,7 @@ lv_obj_t * hasp_find_obj_from_parent_id(lv_obj_t * parent, uint8_t objid) // return hasp_find_obj_from_parent_id(get_page_obj(pageid), objid); // } -bool hasp_find_id_from_obj(lv_obj_t * obj, uint8_t * pageid, uint8_t * objid) +bool hasp_find_id_from_obj(lv_obj_t* obj, uint8_t* pageid, uint8_t* objid) { if(!get_page_id(obj, pageid)) return false; if(!(obj->user_data.id > 0)) return false; @@ -164,29 +164,29 @@ bool hasp_find_id_from_obj(lv_obj_t * obj, uint8_t * pageid, uint8_t * objid) * @return true or false wether the types match * @note */ -bool check_obj_type(lv_obj_t * obj, lv_hasp_obj_type_t haspobjtype) +bool check_obj_type(lv_obj_t* obj, lv_hasp_obj_type_t haspobjtype) { #if 1 return obj->user_data.objid == (uint8_t)haspobjtype; #else lv_obj_type_t list; lv_obj_get_type(obj, &list); - const char * objtype = list.type[0]; + const char* objtype = list.type[0]; return check_obj_type(objtype, haspobjtype); #endif } -void hasp_object_tree(lv_obj_t * parent, uint8_t pageid, uint16_t level) +void hasp_object_tree(lv_obj_t* parent, uint8_t pageid, uint16_t level) { if(parent == nullptr) return; /* Output parent info */ lv_obj_type_t list; lv_obj_get_type(parent, &list); - const char * objtype = list.type[0]; + const char* objtype = list.type[0]; LOG_VERBOSE(TAG_HASP, F("[%d] " HASP_OBJECT_NOTATION " %s"), level, pageid, parent->user_data.id, objtype); - lv_obj_t * child; + lv_obj_t* child; child = lv_obj_get_child(parent, NULL); while(child) { /* child found, process it */ @@ -201,7 +201,7 @@ void hasp_object_tree(lv_obj_t * parent, uint8_t pageid, uint16_t level) #if 1 uint16_t tabcount = lv_tabview_get_tab_count(parent); for(uint16_t i = 0; i < tabcount; i++) { - lv_obj_t * tab = lv_tabview_get_tab(parent, i); + lv_obj_t* tab = lv_tabview_get_tab(parent, i); LOG_VERBOSE(TAG_HASP, "Found tab %i", i); if(tab->user_data.objid) hasp_object_tree(tab, pageid, level + 1); } @@ -211,7 +211,7 @@ void hasp_object_tree(lv_obj_t * parent, uint8_t pageid, uint16_t level) // ##################### Value Dispatchers ######################################################## -void hasp_send_obj_attribute_str(lv_obj_t * obj, const char * attribute, const char * data) +void hasp_send_obj_attribute_str(lv_obj_t* obj, const char* attribute, const char* data) { uint8_t pageid; uint8_t objid; @@ -221,7 +221,7 @@ void hasp_send_obj_attribute_str(lv_obj_t * obj, const char * attribute, const c } } -void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t val) +void hasp_send_obj_attribute_int(lv_obj_t* obj, const char* attribute, int32_t val) { uint8_t pageid; uint8_t objid; @@ -231,7 +231,7 @@ void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t } } -void hasp_send_obj_attribute_color(lv_obj_t * obj, const char * attribute, lv_color_t color) +void hasp_send_obj_attribute_color(lv_obj_t* obj, const char* attribute, lv_color_t color) { uint8_t pageid; uint8_t objid; @@ -279,7 +279,7 @@ void hasp_send_obj_attribute_color(lv_obj_t * obj, const char * attribute, lv_co * @param obj pointer to a button object * @param event type of event that occured */ -void generic_event_handler(lv_obj_t * obj, lv_event_t event) +void generic_event_handler(lv_obj_t* obj, lv_event_t event) { uint8_t eventid; @@ -348,7 +348,7 @@ void generic_event_handler(lv_obj_t * obj, lv_event_t event) * @param obj pointer to a button matrix * @param event type of event that occured */ -void wakeup_event_handler(lv_obj_t * obj, lv_event_t event) +void wakeup_event_handler(lv_obj_t* obj, lv_event_t event) { if(obj == lv_disp_get_layer_sys(NULL)) { hasp_update_sleep_state(); // wakeup? @@ -365,7 +365,7 @@ void wakeup_event_handler(lv_obj_t * obj, lv_event_t event) * @param obj pointer to a switch object * @param event type of event that occured */ -void toggle_event_handler(lv_obj_t * obj, lv_event_t event) +void toggle_event_handler(lv_obj_t* obj, lv_event_t event) { if(event == LV_EVENT_VALUE_CHANGED) { char property[4]; @@ -405,7 +405,7 @@ void toggle_event_handler(lv_obj_t * obj, lv_event_t event) * @param obj pointer to a dropdown list or roller * @param event type of event that occured */ -static void selector_event_handler(lv_obj_t * obj, lv_event_t event) +static void selector_event_handler(lv_obj_t* obj, lv_event_t event) { if(event == LV_EVENT_VALUE_CHANGED) { char buffer[128]; @@ -428,8 +428,8 @@ static void selector_event_handler(lv_obj_t * obj, lv_event_t event) break; case LV_HASP_BTNMATRIX: { - val = lv_btnmatrix_get_active_btn(obj); - const char * txt = lv_btnmatrix_get_btn_text(obj, val); + val = lv_btnmatrix_get_active_btn(obj); + const char* txt = lv_btnmatrix_get_btn_text(obj, val); strncpy(buffer, txt, sizeof(buffer)); break; } @@ -439,7 +439,7 @@ static void selector_event_handler(lv_obj_t * obj, lv_event_t event) uint16_t col; if(lv_table_get_pressed_cell(obj, &row, &col) != LV_RES_OK) return; // outside any cell - const char * txt = lv_table_get_cell_value(obj, row, col); + const char* txt = lv_table_get_cell_value(obj, row, col); strncpy(buffer, txt, sizeof(buffer)); snprintf_P(property, sizeof(property), PSTR("row\":%d,\"col\":%d,\"txt"), row, col); @@ -467,7 +467,7 @@ static void selector_event_handler(lv_obj_t * obj, lv_event_t event) * @param obj pointer to a slider * @param event type of event that occured */ -void slider_event_handler(lv_obj_t * obj, lv_event_t event) +void slider_event_handler(lv_obj_t* obj, lv_event_t event) { if(event == LV_EVENT_VALUE_CHANGED) { /* bool is_dragged; @@ -512,7 +512,7 @@ void slider_event_handler(lv_obj_t * obj, lv_event_t event) * @param obj pointer to a color picker * @param event type of event that occured */ -static void cpicker_event_handler(lv_obj_t * obj, lv_event_t event) +static void cpicker_event_handler(lv_obj_t* obj, lv_event_t event) { char color[6]; snprintf_P(color, sizeof(color), PSTR("color")); @@ -529,7 +529,7 @@ static void cpicker_event_handler(lv_obj_t * obj, lv_event_t event) // ##################### State Changers ######################################################## // TODO make this a recursive function that goes over all objects only ONCE -void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t * src_obj) +void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t* src_obj) { if(groupid == 0) return; bool state = dispatch_get_event_state(eventid); @@ -537,7 +537,7 @@ void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t * src_obj for(uint8_t page = 0; page < HASP_NUM_PAGES; page++) { uint8_t startid = 1; for(uint8_t objid = startid; objid < 20; objid++) { - lv_obj_t * obj = hasp_find_obj_from_parent_id(get_page_obj(page), objid); + lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(page), objid); if(obj && obj != src_obj && obj->user_data.groupid == groupid) { // skip source object, if set lv_obj_set_state(obj, state ? LV_STATE_PRESSED | LV_STATE_CHECKED : LV_STATE_DEFAULT); } @@ -545,11 +545,11 @@ void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t * src_obj } } -void object_set_group_value(lv_obj_t * parent, uint8_t groupid, const char * payload) +void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* payload) { if(groupid == 0 || parent == nullptr) return; - lv_obj_t * child; + lv_obj_t* child; child = lv_obj_get_child(parent, NULL); while(child) { /* child found, update it */ @@ -563,7 +563,7 @@ void object_set_group_value(lv_obj_t * parent, uint8_t groupid, const char * pay //#if LVGL_VERSION_MAJOR == 7 uint16_t tabcount = lv_tabview_get_tab_count(child); for(uint16_t i = 0; i < tabcount; i++) { - lv_obj_t * tab = lv_tabview_get_tab(child, i); + lv_obj_t* tab = lv_tabview_get_tab(child, i); LOG_VERBOSE(TAG_HASP, F("Found tab %i"), i); if(tab->user_data.groupid && groupid == tab->user_data.groupid) hasp_process_obj_attribute_val(tab, NULL, payload, true); /* tab found, update it */ @@ -588,9 +588,9 @@ void object_set_group_value(uint8_t groupid, int16_t state) //////////////////////////////////////////////////////////////////////////////////////////////////// // Used in the dispatcher & hasp_new_object -void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, const char * payload) +void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload) { - if(lv_obj_t * obj = hasp_find_obj_from_parent_id(get_page_obj(pageid), objid)) { + if(lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(pageid), objid)) { hasp_process_obj_attribute(obj, attr, payload, strlen(payload) > 0); } else { LOG_WARNING(TAG_HASP, F(D_OBJECT_UNKNOWN " " HASP_OBJECT_NOTATION), pageid, objid); @@ -599,7 +599,7 @@ void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, co // ##################### Object Creator ######################################################## -int hasp_parse_json_attributes(lv_obj_t * obj, const JsonObject & doc) +int hasp_parse_json_attributes(lv_obj_t* obj, const JsonObject& doc) { int i = 0; #ifdef WINDOWS @@ -608,17 +608,17 @@ int hasp_parse_json_attributes(lv_obj_t * obj, const JsonObject & doc) std::string v; for(JsonPair keyValue : doc) { - LOG_VERBOSE(TAG_HASP, F(" * %s => %s"), keyValue.key().c_str(), keyValue.value().as().c_str()); + LOG_VERBOSE(TAG_HASP, F(D_BULLET "%s=%s"), keyValue.key().c_str(), keyValue.value().as().c_str()); v = keyValue.value().as(); hasp_process_obj_attribute(obj, keyValue.key().c_str(), keyValue.value().as().c_str(), true); i++; } #else - String v((char *)0); + String v((char*)0); v.reserve(64); for(JsonPair keyValue : doc) { - LOG_VERBOSE(TAG_HASP, F(" * %s => %s"), keyValue.key().c_str(), keyValue.value().as().c_str()); + LOG_DEBUG(TAG_HASP, F(D_BULLET "%s=%s"), keyValue.key().c_str(), keyValue.value().as().c_str()); v = keyValue.value().as(); hasp_process_obj_attribute(obj, keyValue.key().c_str(), keyValue.value().as().c_str(), true); i++; @@ -634,11 +634,11 @@ int hasp_parse_json_attributes(lv_obj_t * obj, const JsonObject & doc) * @param saved_page_id the pageid to use when no pageid is specified in the Json, updated when it is specified so * following objects in the file can share the pageid */ -void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) +void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) { /* Page selection: page is the default parent_obj */ - uint8_t pageid = config[FPSTR(FP_PAGE)].isNull() ? saved_page_id : config[FPSTR(FP_PAGE)].as(); - lv_obj_t * parent_obj = get_page_obj(pageid); + uint8_t pageid = config[FPSTR(FP_PAGE)].isNull() ? saved_page_id : config[FPSTR(FP_PAGE)].as(); + lv_obj_t* parent_obj = get_page_obj(pageid); if(!parent_obj) { LOG_WARNING(TAG_HASP, F(D_OBJECT_PAGE_UNKNOWN), pageid); return; @@ -663,7 +663,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) uint8_t groupid = config[FPSTR(FP_GROUPID)].as(); /* Define Objects*/ - lv_obj_t * obj = hasp_find_obj_from_parent_id(parent_obj, id); + lv_obj_t* obj = hasp_find_obj_from_parent_id(parent_obj, id); if(!obj) { /* Create the object first */ @@ -673,7 +673,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) if(config[FPSTR(FP_OBJ)].isNull()) { return; // comments } else { - sdbm = Utilities::get_sdbm(config[FPSTR(FP_OBJ)].as()); + sdbm = Utilities::get_sdbm(config[FPSTR(FP_OBJ)].as()); } } else { sdbm = config[FPSTR(FP_OBJID)].as(); @@ -688,9 +688,9 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) lv_btnmatrix_set_recolor(obj, true); lv_obj_set_event_cb(obj, selector_event_handler); - lv_btnmatrix_ext_t * ext = (lv_btnmatrix_ext_t *)lv_obj_get_ext_attr(obj); - btnmatrix_default_map = ext->map_p; // store the static pointer to the default lvgl btnmap - obj->user_data.objid = LV_HASP_BTNMATRIX; + lv_btnmatrix_ext_t* ext = (lv_btnmatrix_ext_t*)lv_obj_get_ext_attr(obj); + btnmatrix_default_map = ext->map_p; // store the static pointer to the default lvgl btnmap + obj->user_data.objid = LV_HASP_BTNMATRIX; } break; @@ -707,7 +707,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) case HASP_OBJ_BTN: obj = lv_btn_create(parent_obj, NULL); if(obj) { - lv_obj_t * lbl = lv_label_create(obj, NULL); + lv_obj_t* lbl = lv_label_create(obj, NULL); if(lbl) { lv_label_set_text(lbl, ""); lv_label_set_recolor(lbl, true); @@ -814,7 +814,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) obj = lv_tabview_create(parent_obj, LV_DIR_TOP, 100); // No event handler for tabs if(obj) { - lv_obj_t * tab; + lv_obj_t* tab; tab = lv_tabview_add_tab(obj, "tab 1"); // lv_obj_set_user_data(tab, id + 1); tab = lv_tabview_add_tab(obj, "tab 2"); @@ -849,7 +849,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) obj = lv_tabview_create(parent_obj, NULL); // No event handler for tabs if(obj) { - lv_obj_t * tab; + lv_obj_t* tab; tab = lv_tabview_add_tab(obj, "tab 1"); // lv_obj_set_user_data(tab, id + 1); tab = lv_tabview_add_tab(obj, "tab 2"); @@ -934,7 +934,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) lv_chart_add_series(obj, LV_COLOR_GREEN); lv_chart_add_series(obj, LV_COLOR_BLUE); - lv_chart_series_t * ser = my_chart_get_series(obj, 2); + lv_chart_series_t* ser = my_chart_get_series(obj, 2); lv_chart_set_next(obj, ser, 10); lv_chart_set_next(obj, ser, 20); lv_chart_set_next(obj, ser, 30); @@ -1012,7 +1012,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) LOG_VERBOSE(TAG_HASP, F(D_BULLET HASP_OBJECT_NOTATION " = %s"), pageid, temp, list.type[0]); /* test double-check */ - lv_obj_t * test = hasp_find_obj_from_parent_id(get_page_obj(pageid), (uint8_t)temp); + lv_obj_t* test = hasp_find_obj_from_parent_id(get_page_obj(pageid), (uint8_t)temp); if(test != obj) { LOG_ERROR(TAG_HASP, F(D_OBJECT_MISMATCH)); return; @@ -1029,7 +1029,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id) hasp_parse_json_attributes(obj, config); } -void hasp_object_delete(lv_obj_t * obj) +void hasp_object_delete(lv_obj_t* obj) { switch(obj->user_data.objid) { case LV_HASP_LINE: diff --git a/src/hasp/hasp_utilities.cpp b/src/hasp/hasp_utilities.cpp index d99e6dca..fd39dc09 100644 --- a/src/hasp/hasp_utilities.cpp +++ b/src/hasp/hasp_utilities.cpp @@ -1,7 +1,8 @@ #include +#include #ifdef ARDUINO - #include "Arduino.h" +#include "Arduino.h" #endif #include "hasp_conf.h" @@ -10,7 +11,7 @@ /* 16-bit hashing function http://www.cse.yorku.ca/~oz/hash.html */ /* all possible attributes are hashed and checked if they are unique */ -uint16_t Utilities::get_sdbm(const char * str) +uint16_t Utilities::get_sdbm(const char* str) { uint16_t hash = 0; char c; @@ -23,13 +24,13 @@ uint16_t Utilities::get_sdbm(const char * str) return hash; } -bool Utilities::is_true(const char * s) +bool Utilities::is_true(const char* s) { return (!strcasecmp_P(s, PSTR("true")) || !strcasecmp_P(s, PSTR("on")) || !strcasecmp_P(s, PSTR("yes")) || !strcmp_P(s, PSTR("1"))); } -bool Utilities::is_only_digits(const char * s) +bool Utilities::is_only_digits(const char* s) { size_t digits = 0; while(*(s + digits) != '\0' && isdigit(*(s + digits))) { @@ -38,7 +39,7 @@ bool Utilities::is_only_digits(const char * s) return strlen(s) == digits; } -int Utilities::format_bytes(size_t filesize, char * buf, size_t len) +int Utilities::format_bytes(size_t filesize, char* buf, size_t len) { if(filesize < 1024) return snprintf_P(buf, len, PSTR("%d B"), filesize); @@ -54,8 +55,44 @@ int Utilities::format_bytes(size_t filesize, char * buf, size_t len) return snprintf_P(buf, len, PSTR("%d.%d %ciB"), filesize / 10, filesize % 10, labels[unit]); } +std::string Utilities::tft_driver_name() +{ +#if defined(ILI9341_DRIVER) + return "ILI9341"; +#elif defined(ST7735_DRIVER) + return "ST7735"; +#elif defined(ILI9163_DRIVER) + return "ILI9163"; +#elif defined(S6D02A1_DRIVER) + return "S6D02A1"; +#elif defined(ST7796_DRIVER) + return "ST7796"; +#elif defined(ILI9486_DRIVER) + return "ILI9486"; +#elif defined(ILI9481_DRIVER) + return "ILI9481"; +#elif defined(ILI9488_DRIVER) + return "ILI9488"; +#elif defined(HX8357D_DRIVER) + return "HX8357D"; +#elif defined(EPD_DRIVER) + return "EPD"; +#elif defined(ST7789_DRIVER) + return "ST7789"; +#elif defined(R61581_DRIVER) + return "R61581"; +#elif defined(ST7789_2_DRIVER) + return "ST7789_2"; +#elif defined(RM68140_DRIVER) + return "RM68140"; +#else + return "Other"; +#endif +} + #ifndef ARDUINO -long map(long x, long in_min, long in_max, long out_min, long out_max) { - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +long map(long x, long in_min, long in_max, long out_min, long out_max) +{ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } #endif \ No newline at end of file diff --git a/src/hasp/hasp_utilities.h b/src/hasp/hasp_utilities.h index 066d89e0..e44a86ca 100644 --- a/src/hasp/hasp_utilities.h +++ b/src/hasp/hasp_utilities.h @@ -4,13 +4,16 @@ #ifndef HASP_UTILITIES_H #define HASP_UTILITIES_H +#include + class Utilities { public: - static uint16_t get_sdbm(const char * str); - static bool is_true(const char * s); - static bool is_only_digits(const char * s); - static int format_bytes(size_t filesize, char * buf, size_t len); + static uint16_t get_sdbm(const char* str); + static bool is_true(const char* s); + static bool is_only_digits(const char* s); + static int format_bytes(size_t filesize, char* buf, size_t len); + static std::string tft_driver_name(); }; #ifndef ARDUINO diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 02470bdf..9b3cc7ff 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -12,6 +12,7 @@ #include "lv_fs_if.h" // Device Drivers +#include "dev/device.h" #include "drv/hasp_drv_display.h" #include "drv/hasp_drv_touch.h" @@ -111,17 +112,17 @@ void guiSetup(void) static lv_color_t *guiVdbBuffer1, *guiVdbBuffer2 = NULL; // DMA: len must be less than 32767 const size_t guiVDBsize = 15 * 1024u; // 30 KBytes - guiVdbBuffer1 = (lv_color_t *)heap_caps_calloc(guiVDBsize, sizeof(lv_color_t), MALLOC_CAP_DMA); + guiVdbBuffer1 = (lv_color_t*)heap_caps_calloc(guiVDBsize, sizeof(lv_color_t), MALLOC_CAP_DMA); // guiVdbBuffer2 = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * guiVDBsize, MALLOC_CAP_DMA); // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize); #else - static lv_color_t * guiVdbBuffer1; + static lv_color_t* guiVdbBuffer1; const size_t guiVDBsize = 16 * 1024u; // 32 KBytes if(0 && psramFound()) { - guiVdbBuffer1 = (lv_color_t *)ps_calloc(guiVDBsize, sizeof(lv_color_t)); // too slow for VDB + guiVdbBuffer1 = (lv_color_t*)ps_calloc(guiVDBsize, sizeof(lv_color_t)); // too slow for VDB } else { - guiVdbBuffer1 = (lv_color_t *)calloc(guiVDBsize, sizeof(lv_color_t)); + guiVdbBuffer1 = (lv_color_t*)calloc(guiVDBsize, sizeof(lv_color_t)); } #endif @@ -135,9 +136,9 @@ void guiSetup(void) // size_t guiVDBsize = sizeof(guiVdbBuffer1) / sizeof(guiVdbBuffer1[0]); // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize); - static lv_color_t * guiVdbBuffer1; + static lv_color_t* guiVdbBuffer1; const size_t guiVDBsize = 2 * 512u; // 4 KBytes * 2 - guiVdbBuffer1 = (lv_color_t *)malloc(sizeof(lv_color_t) * guiVDBsize); + guiVdbBuffer1 = (lv_color_t*)malloc(sizeof(lv_color_t) * guiVDBsize); #elif defined(WINDOWS) const size_t guiVDBsize = LV_HOR_RES_MAX * 10; @@ -170,9 +171,9 @@ void guiSetup(void) drv_display_init(&disp_drv, gui_settings.rotation, gui_settings.invert_display); // Set display driver callback & rotation #endif - disp_drv.hor_res = TFT_WIDTH; - disp_drv.ver_res = TFT_HEIGHT; - lv_disp_t * display = lv_disp_drv_register(&disp_drv); + disp_drv.hor_res = TFT_WIDTH; + disp_drv.ver_res = TFT_HEIGHT; + lv_disp_t* display = lv_disp_drv_register(&disp_drv); switch(gui_settings.rotation) { case 1: @@ -203,16 +204,17 @@ void guiSetup(void) #endif /* Setup Backlight Control Pin */ - if(gui_settings.backlight_pin >= 0) { - LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), gui_settings.backlight_pin); + haspDevice.set_backlight_pin(gui_settings.backlight_pin); + // if(gui_settings.backlight_pin >= 0) { + // LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), gui_settings.backlight_pin); -#if defined(ARDUINO_ARCH_ESP32) - ledcSetup(BACKLIGHT_CHANNEL, 20000, 12); - ledcAttachPin(gui_settings.backlight_pin, BACKLIGHT_CHANNEL); -#elif defined(ARDUINO_ARCH_ESP8266) - pinMode(gui_settings.backlight_pin, OUTPUT); -#endif - } + // #if defined(ARDUINO_ARCH_ESP32) + // ledcSetup(BACKLIGHT_CHANNEL, 20000, 12); + // ledcAttachPin(gui_settings.backlight_pin, BACKLIGHT_CHANNEL); + // #elif defined(ARDUINO_ARCH_ESP8266) + // pinMode(gui_settings.backlight_pin, OUTPUT); + // #endif + // } LOG_VERBOSE(TAG_GUI, F("Rotation : %d"), gui_settings.rotation); LOG_VERBOSE(TAG_LVGL, F("Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH, @@ -232,7 +234,7 @@ void guiSetup(void) #else indev_drv.read_cb = drv_touch_read; #endif - lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv); + lv_indev_t* mouse_indev = lv_indev_drv_register(&indev_drv); mouse_indev->driver.type = LV_INDEV_TYPE_POINTER; /*Set a cursor for the mouse*/ @@ -242,8 +244,8 @@ void guiSetup(void) // lv_indev_set_cursor(mouse_indev, label); // connect the object to the driver LOG_TRACE(TAG_GUI, F("Initialize Cursor")); - lv_obj_t * cursor; - lv_obj_t * mouse_layer = lv_disp_get_layer_sys(NULL); // default display + lv_obj_t* cursor; + lv_obj_t* mouse_layer = lv_disp_get_layer_sys(NULL); // default display #if defined(ARDUINO_ARCH_ESP32) LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/ @@ -265,7 +267,7 @@ void guiSetup(void) /* Initialize Global progress bar*/ lv_obj_user_data_t udata = (lv_obj_user_data_t){10, 0, 10}; - lv_obj_t * bar = lv_bar_create(lv_layer_sys(), NULL); + lv_obj_t* bar = lv_bar_create(lv_layer_sys(), NULL); lv_obj_set_user_data(bar, udata); lv_obj_set_hidden(bar, true); lv_bar_set_range(bar, 0, 100); @@ -372,7 +374,7 @@ int8_t guiGetDim() //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_CONFIG > 0 -bool guiGetConfig(const JsonObject & settings) +bool guiGetConfig(const JsonObject& settings) { bool changed = false; uint16_t guiSleepTime1; @@ -443,7 +445,7 @@ bool guiGetConfig(const JsonObject & settings) * * @param[in] settings JsonObject with the config settings. **/ -bool guiSetConfig(const JsonObject & settings) +bool guiSetConfig(const JsonObject& settings) { configOutput(settings, TAG_GUI); bool changed = false; @@ -507,7 +509,7 @@ bool guiSetConfig(const JsonObject & settings) /* **************************** SCREENSHOTS ************************************** */ #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 || HASP_USE_HTTP > 0 -static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data) +static void guiSetBmpHeader(uint8_t* buffer_p, int32_t data) { *buffer_p++ = data & 0xFF; *buffer_p++ = (data >> 8) & 0xFF; @@ -522,13 +524,13 @@ static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data) * @note: send header before refreshing the whole screen * **/ -static void gui_get_bitmap_header(uint8_t * buffer, size_t bufsize) +static void gui_get_bitmap_header(uint8_t* buffer, size_t bufsize) { memset(buffer, 0, bufsize); - lv_disp_t * disp = lv_disp_get_default(); - buffer[0] = 0x42; // B - buffer[1] = 0x4D; // M + lv_disp_t* disp = lv_disp_get_default(); + buffer[0] = 0x42; // B + buffer[1] = 0x4D; // M buffer[10 + 0] = 122; // full header size buffer[14 + 0] = 122 - 14; // dib header size @@ -538,7 +540,7 @@ static void gui_get_bitmap_header(uint8_t * buffer, size_t bufsize) // The refresh draws the active screen only, so we need the dimensions of the active screen // This could in be diferent from the display driver width/height if the screen has been resized - lv_obj_t * scr = lv_disp_get_scr_act(NULL); + lv_obj_t* scr = lv_disp_get_scr_act(NULL); // file size guiSetBmpHeader(&buffer[2], 122 + disp->driver.hor_res * disp->driver.ver_res * buffer[28] / 8); @@ -579,11 +581,11 @@ void gui_flush_not_complete() #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 /* Flush VDB bytes to a file */ -static void gui_screenshot_to_file(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) +static void gui_screenshot_to_file(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) { size_t len = (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1); /* Number of pixels */ len *= sizeof(lv_color_t); /* Number of bytes */ - size_t res = pFileOut.write((uint8_t *)color_p, len); + size_t res = pFileOut.write((uint8_t*)color_p, len); if(res != len) gui_flush_not_complete(); drv_display_flush_cb(disp, area, color_p); // indirect callback to flush screenshot data to the screen } @@ -597,7 +599,7 @@ static void gui_screenshot_to_file(lv_disp_drv_t * disp, const lv_area_t * area, * @param[in] pFileName Output binary file name. * **/ -void guiTakeScreenshot(const char * pFileName) +void guiTakeScreenshot(const char* pFileName) { uint8_t buffer[128]; gui_get_bitmap_header(buffer, sizeof(buffer)); @@ -610,8 +612,8 @@ void guiTakeScreenshot(const char * pFileName) LOG_VERBOSE(TAG_GUI, F("Bitmap header written")); /* Refresh screen to screenshot callback */ - lv_disp_t * disp = lv_disp_get_default(); - void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); + lv_disp_t* disp = lv_disp_get_default(); + void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t* area, lv_color_t* color_p); flush_cb = disp->driver.flush_cb; /* store callback */ disp->driver.flush_cb = gui_screenshot_to_file; @@ -634,11 +636,11 @@ void guiTakeScreenshot(const char * pFileName) #if HASP_USE_HTTP > 0 /* Flush VDB bytes to a webclient */ -static void gui_screenshot_to_http(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) +static void gui_screenshot_to_http(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) { size_t len = (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1); /* Number of pixels */ len *= sizeof(lv_color_t); /* Number of bytes */ - size_t res = httpClientWrite((uint8_t *)color_p, len); + size_t res = httpClientWrite((uint8_t*)color_p, len); if(res != len) gui_flush_not_complete(); drv_display_flush_cb(disp, area, color_p); } @@ -659,8 +661,8 @@ void guiTakeScreenshot() LOG_VERBOSE(TAG_GUI, F("Bitmap header sent")); /* Refresh screen to screenshot callback */ - lv_disp_t * disp = lv_disp_get_default(); - void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); + lv_disp_t* disp = lv_disp_get_default(); + void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t* area, lv_color_t* color_p); flush_cb = disp->driver.flush_cb; /* store callback */ disp->driver.flush_cb = gui_screenshot_to_http; lv_obj_invalidate(lv_scr_act()); diff --git a/src/mqtt/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h index 322c7b88..16c1abcd 100644 --- a/src/mqtt/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -9,7 +9,7 @@ #include "hasp_conf.h" #ifdef WINDOWS - #define __FlashStringHelper char +#define __FlashStringHelper char #endif void mqttSetup(); @@ -18,18 +18,18 @@ void mqttEvery5Seconds(bool wifiIsConnected); void mqttStart(); void mqttStop(); -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload); -void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload); +void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload); +void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload); bool mqttIsConnected(); #if HASP_USE_CONFIG > 0 -bool mqttGetConfig(const JsonObject & settings); -bool mqttSetConfig(const JsonObject & settings); +bool mqttGetConfig(const JsonObject& settings); +bool mqttSetConfig(const JsonObject& settings); #endif -#ifndef WINDOWS -String mqttGetNodename(void); -#endif +// #ifndef WINDOWS +// String mqttGetNodename(void); +// #endif #endif \ No newline at end of file diff --git a/src/mqtt/hasp_mqtt_paho.cpp b/src/mqtt/hasp_mqtt_paho.cpp index a0c017f8..d33fa022 100644 --- a/src/mqtt/hasp_mqtt_paho.cpp +++ b/src/mqtt/hasp_mqtt_paho.cpp @@ -6,94 +6,94 @@ #include "hasp_conf.h" #if HASP_USE_MQTT > 0 - #ifdef USE_PAHO +#ifdef USE_PAHO - /******************************************************************************* - * Copyright (c) 2012, 2020 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v2.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * https://www.eclipse.org/legal/epl-2.0/ - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Ian Craggs - initial contribution - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2012, 2020 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * https://www.eclipse.org/legal/epl-2.0/ + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial contribution + *******************************************************************************/ - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include - #include "MQTTAsync.h" +#include "MQTTAsync.h" - #include "hasp_mqtt.h" // functions to implement here +#include "hasp_mqtt.h" // functions to implement here - #include "hasp/hasp_dispatch.h" // for dispatch_topic_payload - #include "hasp_debug.h" // for logging +#include "hasp/hasp_dispatch.h" // for dispatch_topic_payload +#include "hasp_debug.h" // for logging - #if !defined(_WIN32) - #include - #else - #include - #endif +#if !defined(_WIN32) +#include +#else +#include +#endif - #if defined(_WRS_KERNEL) - #include - #endif +#if defined(_WRS_KERNEL) +#include +#endif - #define ADDRESS "10.4.0.5:1883" - #define CLIENTID "ExampleClientSub" - #define TOPIC "hasp/plate35/" - #define QOS 1 - #define TIMEOUT 10000L +#define ADDRESS "10.4.0.5:1883" +#define CLIENTID "ExampleClientSub" +#define TOPIC "hasp/plate35/" +#define QOS 1 +#define TIMEOUT 10000L -const char * mqttNodeTopic = TOPIC; -const char * mqttGroupTopic = TOPIC; +const char* mqttNodeTopic = TOPIC; +const char* mqttGroupTopic = TOPIC; // char mqttNodeTopic[24]; // char mqttGroupTopic[24]; bool mqttEnabled = false; bool mqttHAautodiscover = true; - //////////////////////////////////////////////////////////////////////////////////////////////////// - // These defaults may be overwritten with values saved by the web interface - #ifndef MQTT_HOST - #define MQTT_HOST ""; - #endif +//////////////////////////////////////////////////////////////////////////////////////////////////// +// These defaults may be overwritten with values saved by the web interface +#ifndef MQTT_HOST +#define MQTT_HOST ""; +#endif - #ifndef MQTT_PORT - #define MQTT_PORT 1883; - #endif +#ifndef MQTT_PORT +#define MQTT_PORT 1883; +#endif - #ifndef MQTT_USER - #define MQTT_USER ""; - #endif +#ifndef MQTT_USER +#define MQTT_USER ""; +#endif - #ifndef MQTT_PASSW - #define MQTT_PASSW ""; - #endif - #ifndef MQTT_NODENAME - #define MQTT_NODENAME ""; - #endif - #ifndef MQTT_GROUPNAME - #define MQTT_GROUPNAME ""; - #endif +#ifndef MQTT_PASSW +#define MQTT_PASSW ""; +#endif +#ifndef MQTT_NODENAME +#define MQTT_NODENAME ""; +#endif +#ifndef MQTT_GROUPNAME +#define MQTT_GROUPNAME ""; +#endif - #ifndef MQTT_PREFIX - #define MQTT_PREFIX "hasp" - #endif +#ifndef MQTT_PREFIX +#define MQTT_PREFIX "hasp" +#endif - #define LWT_TOPIC "LWT" +#define LWT_TOPIC "LWT" -char mqttServer[16] = MQTT_HOST; -char mqttUser[23] = MQTT_USER; -char mqttPassword[32] = MQTT_PASSW; -char mqttNodeName[16] = MQTT_NODENAME; +char mqttServer[16] = MQTT_HOST; +char mqttUser[23] = MQTT_USER; +char mqttPassword[32] = MQTT_PASSW; +// char mqttNodeName[16] = MQTT_NODENAME; char mqttGroupName[16] = MQTT_GROUPNAME; uint16_t mqttPort = MQTT_PORT; @@ -103,11 +103,11 @@ int disc_finished = 0; int subscribed = 0; int connected = 0; -static bool mqttPublish(const char * topic, const char * payload, size_t len, bool retain = false); +static bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain = false); /* ===== Paho event callbacks ===== */ -void connlost(void * context, char * cause) +void connlost(void* context, char* cause) { printf("\nConnection lost\n"); if(cause) printf(" cause: %s\n", cause); @@ -117,7 +117,7 @@ void connlost(void * context, char * cause) } // Receive incoming messages -static void mqtt_message_cb(char * topic, char * payload, unsigned int length) +static void mqtt_message_cb(char* topic, char* payload, unsigned int length) { // Handle incoming commands from MQTT if(length + 1 >= MQTT_MAX_PACKET_SIZE) { LOG_ERROR(TAG_MQTT_RCV, F("Payload too long (%d bytes)"), length); @@ -126,7 +126,7 @@ static void mqtt_message_cb(char * topic, char * payload, unsigned int length) payload[length] = '\0'; } - LOG_TRACE(TAG_MQTT_RCV, F("%s = %s"), topic, (char *)payload); + LOG_TRACE(TAG_MQTT_RCV, F("%s = %s"), topic, (char*)payload); if(topic == strstr(topic, mqttNodeTopic)) { // startsWith mqttNodeTopic @@ -137,11 +137,11 @@ static void mqtt_message_cb(char * topic, char * payload, unsigned int length) // Group topic topic += strlen(mqttGroupTopic); // shorten topic - dispatch_topic_payload(topic, (const char *)payload); + dispatch_topic_payload(topic, (const char*)payload); return; } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic - if(mqttHAautodiscover && !strcasecmp_P((char *)payload, PSTR("online"))) { + if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { // dispatch_current_state(); // mqtt_ha_register_auto_discovery(); } @@ -155,7 +155,7 @@ static void mqtt_message_cb(char * topic, char * payload, unsigned int length) // catch a dangling LWT from a previous connection if it appears if(!strcmp_P(topic, PSTR(LWT_TOPIC))) { // endsWith LWT - if(!strcasecmp_P((char *)payload, PSTR("offline"))) { + if(!strcasecmp_P((char*)payload, PSTR("offline"))) { { char msg[8]; char tmp_topic[strlen(mqttNodeTopic) + 8]; @@ -170,57 +170,57 @@ static void mqtt_message_cb(char * topic, char * payload, unsigned int length) // LOG_TRACE(TAG_MQTT, F("ignoring LWT = online")); } } else { - dispatch_topic_payload(topic, (const char *)payload); + dispatch_topic_payload(topic, (const char*)payload); } } -int msgarrvd(void * context, char * topicName, int topicLen, MQTTAsync_message * message) +int msgarrvd(void* context, char* topicName, int topicLen, MQTTAsync_message* message) { // printf("MQT RCV >> "); // printf("%s => %.*s (%d)\n", topicName, message->payloadlen, (char *)message->payload, message->payloadlen); char msg[message->payloadlen + 1]; - memcpy(msg, (char *)message->payload, message->payloadlen); + memcpy(msg, (char*)message->payload, message->payloadlen); msg[message->payloadlen] = '\0'; - mqtt_message_cb(topicName, (char *)message->payload, message->payloadlen); + mqtt_message_cb(topicName, (char*)message->payload, message->payloadlen); MQTTAsync_freeMessage(&message); MQTTAsync_free(topicName); return 1; } -void onDisconnectFailure(void * context, MQTTAsync_failureData * response) +void onDisconnectFailure(void* context, MQTTAsync_failureData* response) { printf("Disconnect failed, rc %d\n", response->code); disc_finished = 1; } -void onDisconnect(void * context, MQTTAsync_successData * response) +void onDisconnect(void* context, MQTTAsync_successData* response) { printf("Successful disconnection\n"); disc_finished = 1; connected = 0; } -void onSubscribe(void * context, MQTTAsync_successData * response) +void onSubscribe(void* context, MQTTAsync_successData* response) { printf("Subscribe succeeded %d\n", response->token); subscribed = 1; } -void onSubscribeFailure(void * context, MQTTAsync_failureData * response) +void onSubscribeFailure(void* context, MQTTAsync_failureData* response) { printf("Subscribe failed, rc %d\n", response->code); } -void onConnectFailure(void * context, MQTTAsync_failureData * response) +void onConnectFailure(void* context, MQTTAsync_failureData* response) { connected = 0; printf("Connect failed, rc %d\n", response->code); } -void mqtt_subscribe(void * context, const char * topic) +void mqtt_subscribe(void* context, const char* topic) { MQTTAsync client = (MQTTAsync)context; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; @@ -235,7 +235,7 @@ void mqtt_subscribe(void * context, const char * topic) } } -void onConnect(void * context, MQTTAsync_successData * response) +void onConnect(void* context, MQTTAsync_successData* response) { MQTTAsync client = (MQTTAsync)context; connected = 1; @@ -253,7 +253,7 @@ void onConnect(void * context, MQTTAsync_successData * response) std::cout << std::endl; } -void onSendFailure(void * context, MQTTAsync_failureData * response) +void onSendFailure(void* context, MQTTAsync_failureData* response) { MQTTAsync client = (MQTTAsync)context; MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; @@ -265,11 +265,11 @@ void onSendFailure(void * context, MQTTAsync_failureData * response) opts.context = client; if((rc = MQTTAsync_disconnect(client, &opts)) != MQTTASYNC_SUCCESS) { printf("Failed to start disconnect, return code %d\n", rc); - //exit(EXIT_FAILURE); + // exit(EXIT_FAILURE); } } -void onSend(void * context, MQTTAsync_successData * response) +void onSend(void* context, MQTTAsync_successData* response) { MQTTAsync client = (MQTTAsync)context; MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; @@ -289,7 +289,7 @@ void onSend(void * context, MQTTAsync_successData * response) /* ===== Local HASP MQTT functions ===== */ -static bool mqttPublish(const char * topic, const char * payload, size_t len, bool retain) +static bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain) { if(mqttIsConnected()) { MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; @@ -299,7 +299,7 @@ static bool mqttPublish(const char * topic, const char * payload, size_t len, bo opts.onSuccess = onSend; opts.onFailure = onSendFailure; opts.context = mqtt_client; - pubmsg.payload = (char *)payload; + pubmsg.payload = (char*)payload; pubmsg.payloadlen = (int)strlen(payload); pubmsg.qos = QOS; pubmsg.retained = 0; @@ -322,7 +322,7 @@ bool mqttIsConnected() return connected == 1; } -void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload) +void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; printf(("%sstate/%s\n"), mqttNodeTopic, subtopic); @@ -330,7 +330,7 @@ void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload) mqttPublish(tmp_topic, payload, false); } -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload) +void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/p%ub%u"), mqttNodeTopic, pageid, btnid); @@ -419,7 +419,5 @@ void mqttLoop(){}; void mqttEvery5Seconds(bool wifiIsConnected){}; - // String mqttGetNodename(void){return "palte35"}; - - #endif // USE_PAHO -#endif // USE_MQTT \ No newline at end of file +#endif // USE_PAHO +#endif // USE_MQTT \ No newline at end of file diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index 0bcfa252..f8fbde27 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -4,82 +4,82 @@ #include "hasp_conf.h" #if HASP_USE_MQTT > 0 - #ifdef USE_PUBSUBCLIENT +#ifdef USE_PUBSUBCLIENT - #include "PubSubClient.h" +#include "PubSubClient.h" - #include "hasp/hasp.h" - #include "hasp_mqtt.h" - #include "hasp_mqtt_ha.h" +#include "hasp/hasp.h" +#include "hasp_mqtt.h" +#include "hasp_mqtt_ha.h" - #if defined(ARDUINO_ARCH_ESP32) - #include +#if defined(ARDUINO_ARCH_ESP32) +#include WiFiClient mqttNetworkClient; - #elif defined(ARDUINO_ARCH_ESP8266) - #include - #include - #include +#elif defined(ARDUINO_ARCH_ESP8266) +#include +#include +#include WiFiClient mqttNetworkClient; - #else - #if defined(STM32F4xx) && HASP_USE_WIFI > 0 +#else +#if defined(STM32F4xx) && HASP_USE_WIFI > 0 // #include WiFiSpiClient mqttNetworkClient; - #else - #if defined(W5500_MOSI) && defined(W5500_MISO) && defined(W5500_SCLK) - #define W5500_LAN - #include - #else - #include - #endif +#else +#if defined(W5500_MOSI) && defined(W5500_MISO) && defined(W5500_SCLK) +#define W5500_LAN +#include +#else +#include +#endif EthernetClient mqttNetworkClient; - #endif - #endif +#endif +#endif - #include "hal/hasp_hal.h" - #include "hasp_debug.h" - #include "hasp_config.h" +#include "hal/hasp_hal.h" +#include "hasp_debug.h" +#include "hasp_config.h" - #include "../hasp/hasp_dispatch.h" +#include "../hasp/hasp_dispatch.h" - #ifdef USE_CONFIG_OVERRIDE - #include "user_config_override.h" - #endif +#ifdef USE_CONFIG_OVERRIDE +#include "user_config_override.h" +#endif char mqttNodeTopic[24]; char mqttGroupTopic[24]; bool mqttEnabled = false; bool mqttHAautodiscover = true; - //////////////////////////////////////////////////////////////////////////////////////////////////// - // These defaults may be overwritten with values saved by the web interface - #ifndef MQTT_HOST - #define MQTT_HOST ""; - #endif +//////////////////////////////////////////////////////////////////////////////////////////////////// +// These defaults may be overwritten with values saved by the web interface +#ifndef MQTT_HOST +#define MQTT_HOST ""; +#endif - #ifndef MQTT_PORT - #define MQTT_PORT 1883; - #endif +#ifndef MQTT_PORT +#define MQTT_PORT 1883; +#endif - #ifndef MQTT_USER - #define MQTT_USER ""; - #endif +#ifndef MQTT_USER +#define MQTT_USER ""; +#endif - #ifndef MQTT_PASSW - #define MQTT_PASSW ""; - #endif - #ifndef MQTT_NODENAME - #define MQTT_NODENAME ""; - #endif - #ifndef MQTT_GROUPNAME - #define MQTT_GROUPNAME ""; - #endif +#ifndef MQTT_PASSW +#define MQTT_PASSW ""; +#endif +#ifndef MQTT_NODENAME +#define MQTT_NODENAME ""; +#endif +#ifndef MQTT_GROUPNAME +#define MQTT_GROUPNAME ""; +#endif - #ifndef MQTT_PREFIX - #define MQTT_PREFIX "hasp" - #endif +#ifndef MQTT_PREFIX +#define MQTT_PREFIX "hasp" +#endif - #define LWT_TOPIC "LWT" +#define LWT_TOPIC "LWT" char mqttServer[16] = MQTT_HOST; char mqttUser[23] = MQTT_USER; @@ -89,11 +89,11 @@ char mqttGroupName[16] = MQTT_GROUPNAME; uint16_t mqttPort = MQTT_PORT; PubSubClient mqttClient(mqttNetworkClient); -static bool mqttPublish(const char * topic, const char * payload, size_t len, bool retain = false) +static bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain = false) { if(mqttIsConnected()) { if(mqttClient.beginPublish(topic, len, retain)) { - mqttClient.write((uint8_t *)payload, len); + mqttClient.write((uint8_t*)payload, len); mqttClient.endPublish(); LOG_TRACE(TAG_MQTT_PUB, F("%s => %s"), topic, payload); @@ -107,7 +107,7 @@ static bool mqttPublish(const char * topic, const char * payload, size_t len, bo return false; } -static bool mqttPublish(const char * topic, const char * payload, bool retain = false) +static bool mqttPublish(const char* topic, const char* payload, bool retain = false) { return mqttPublish(topic, payload, strlen(payload), retain); } @@ -132,14 +132,14 @@ void mqtt_send_lwt(bool online) bool res = mqttPublish(tmp_topic, tmp_payload, len, true); } -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload) +void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 16]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/" HASP_OBJECT_NOTATION), mqttNodeTopic, pageid, btnid); mqttPublish(tmp_topic, payload); } -void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload) +void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/%s"), mqttNodeTopic, subtopic); @@ -148,7 +148,7 @@ void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload) //////////////////////////////////////////////////////////////////////////////////////////////////// // Receive incoming messages -static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) +static void mqtt_message_cb(char* topic, byte* payload, unsigned int length) { // Handle incoming commands from MQTT if(length + 1 >= mqttClient.getBufferSize()) { LOG_ERROR(TAG_MQTT_RCV, F("Payload too long (%d bytes)"), length); @@ -157,7 +157,7 @@ static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) payload[length] = '\0'; } - LOG_TRACE(TAG_MQTT_RCV, F("%s = %s"), topic, (char *)payload); + LOG_TRACE(TAG_MQTT_RCV, F("%s = %s"), topic, (char*)payload); if(topic == strstr(topic, mqttNodeTopic)) { // startsWith mqttNodeTopic @@ -168,11 +168,11 @@ static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) // Group topic topic += strlen(mqttGroupTopic); // shorten topic - dispatch_topic_payload(topic, (const char *)payload); + dispatch_topic_payload(topic, (const char*)payload); return; } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic - if(mqttHAautodiscover && !strcasecmp_P((char *)payload, PSTR("online"))) { + if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { dispatch_current_state(); mqtt_ha_register_auto_discovery(); } @@ -186,7 +186,7 @@ static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) // catch a dangling LWT from a previous connection if it appears if(!strcmp_P(topic, PSTR(LWT_TOPIC))) { // endsWith LWT - if(!strcasecmp_P((char *)payload, PSTR("offline"))) { + if(!strcasecmp_P((char*)payload, PSTR("offline"))) { { char msg[8]; char tmp_topic[strlen(mqttNodeTopic) + 8]; @@ -201,11 +201,11 @@ static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) // LOG_TRACE(TAG_MQTT, F("ignoring LWT = online")); } } else { - dispatch_topic_payload(topic, (const char *)payload); + dispatch_topic_payload(topic, (const char*)payload); } } -static void mqttSubscribeTo(const __FlashStringHelper * format, const char * data) +static void mqttSubscribeTo(const __FlashStringHelper* format, const char* data) { char tmp_topic[strlen_P((PGM_P)format) + 2 + strlen(data)]; snprintf_P(tmp_topic, sizeof(tmp_topic), (PGM_P)format, data); @@ -290,7 +290,7 @@ void mqttStart() LOG_INFO(TAG_MQTT, F(D_MQTT_CONNECTED), mqttServer, mqttClientId); // Subscribe to our incoming topics - const __FlashStringHelper * F_topic; + const __FlashStringHelper* F_topic; F_topic = F("%scommand/#"); mqttSubscribeTo(F_topic, mqttGroupTopic); mqttSubscribeTo(F_topic, mqttNodeTopic); @@ -348,10 +348,10 @@ void mqttEvery5Seconds(bool networkIsConnected) } } -String mqttGetNodename() -{ - return mqttNodeName; -} +// String mqttGetNodename() +// { +// return mqttNodeName; +// } void mqttStop() { @@ -363,8 +363,8 @@ void mqttStop() } } - #if HASP_USE_CONFIG > 0 -bool mqttGetConfig(const JsonObject & settings) +#if HASP_USE_CONFIG > 0 +bool mqttGetConfig(const JsonObject& settings) { bool changed = false; @@ -398,7 +398,7 @@ bool mqttGetConfig(const JsonObject & settings) * * @param[in] settings JsonObject with the config settings. **/ -bool mqttSetConfig(const JsonObject & settings) +bool mqttSetConfig(const JsonObject& settings) { configOutput(settings, TAG_MQTT); bool changed = false; @@ -448,8 +448,8 @@ bool mqttSetConfig(const JsonObject & settings) return changed; } - #endif // HASP_USE_CONFIG +#endif // HASP_USE_CONFIG - #endif // PUBSUBCLIENT +#endif // PUBSUBCLIENT #endif // HASP_USE_MQTT diff --git a/src/sys/net/hasp_ethernet_esp32.cpp b/src/sys/net/hasp_ethernet_esp32.cpp index 8d073cb6..270c44ba 100644 --- a/src/sys/net/hasp_ethernet_esp32.cpp +++ b/src/sys/net/hasp_ethernet_esp32.cpp @@ -1,7 +1,6 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ - #include "hasp_conf.h" #include "hal/hasp_hal.h" #include "hasp_debug.h" @@ -17,7 +16,7 @@ void EthernetEvent(WiFiEvent_t event) case SYSTEM_EVENT_ETH_START: LOG_TRACE(TAG_ETH, F(D_SERVICE_STARTED)); // set eth hostname here - ETH.setHostname(mqttGetNodename().c_str()); + ETH.setHostname(haspDevice.get_hostname()); break; case SYSTEM_EVENT_ETH_CONNECTED: LOG_TRACE(TAG_ETH, F(D_SERVICE_CONNECTED)); @@ -63,10 +62,10 @@ bool ethernetEvery5Seconds() return eth_connected; } -void ethernet_get_statusupdate(char * buffer, size_t len) +void ethernet_get_statusupdate(char* buffer, size_t len) { - snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":\"%d Mbps\",\"ip\":\"%s\","), eth_connected ? F("ON") : F("OFF"), ETH.linkSpeed(), - ETH.localIP().toString().c_str()); + snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":\"%d Mbps\",\"ip\":\"%s\","), + eth_connected ? F("ON") : F("OFF"), ETH.linkSpeed(), ETH.localIP().toString().c_str()); } #endif \ No newline at end of file diff --git a/src/sys/net/hasp_wifi.cpp b/src/sys/net/hasp_wifi.cpp index b2b95d68..24380503 100644 --- a/src/sys/net/hasp_wifi.cpp +++ b/src/sys/net/hasp_wifi.cpp @@ -65,11 +65,12 @@ static void wifiConnected(IPAddress ipaddress) LOG_TRACE(TAG_WIFI, F(D_NETWORK_IP_ADDRESS_RECEIVED), ipaddress.toString().c_str()); #endif - LOG_VERBOSE(TAG_WIFI, F("Connected = %s"), WiFi.status() == WL_CONNECTED ? PSTR(D_NETWORK_ONLINE) : PSTR(D_NETWORK_OFFLINE)); + LOG_VERBOSE(TAG_WIFI, F("Connected = %s"), + WiFi.status() == WL_CONNECTED ? PSTR(D_NETWORK_ONLINE) : PSTR(D_NETWORK_OFFLINE)); networkStart(); } -static void wifiDisconnected(const char * ssid, uint8_t reason) +static void wifiDisconnected(const char* ssid, uint8_t reason) { wifiReconnectCounter++; @@ -270,7 +271,7 @@ static void wifiDisconnected(const char * ssid, uint8_t reason) LOG_WARNING(TAG_WIFI, F("Disconnected from %s (Reason: %s [%d])"), ssid, buffer, reason); } -static void wifiSsidConnected(const char * ssid) +static void wifiSsidConnected(const char* ssid) { LOG_TRACE(TAG_WIFI, F("Connected to SSID %s. Requesting IP..."), ssid); wifiReconnectCounter = 0; @@ -281,13 +282,13 @@ static void wifi_callback(system_event_id_t event, system_event_info_t info) { switch(event) { case SYSTEM_EVENT_STA_CONNECTED: - wifiSsidConnected((const char *)info.connected.ssid); + wifiSsidConnected((const char*)info.connected.ssid); break; case SYSTEM_EVENT_STA_GOT_IP: wifiConnected(IPAddress(info.got_ip.ip_info.ip.addr)); break; case SYSTEM_EVENT_STA_DISCONNECTED: - wifiDisconnected((const char *)info.disconnected.ssid, info.disconnected.reason); + wifiDisconnected((const char*)info.disconnected.ssid, info.disconnected.reason); // NTP.stop(); // NTP sync can be disabled to avoid sync errors break; default: @@ -325,7 +326,7 @@ bool wifiShowAP() return true; } -bool wifiShowAP(char * ssid, char * pass) +bool wifiShowAP(char* ssid, char* pass) { if(strlen(wifiSsid) != 0) return false; @@ -353,10 +354,10 @@ static void wifiReconnect(void) { WiFi.disconnect(true); #if defined(ARDUINO_ARCH_ESP8266) - WiFi.hostname(mqttGetNodename().c_str()); + WiFi.hostname(haspDevice.get_hostname()); #elif defined(ARDUINO_ARCH_ESP32) WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); - WiFi.setHostname(mqttGetNodename().c_str()); + WiFi.setHostname(haspDevice.get_hostname()); #endif WiFi.begin(wifiSsid, wifiPassword); } @@ -451,7 +452,7 @@ bool wifiEvery5Seconds() } } -bool wifiValidateSsid(const char * ssid, const char * pass) +bool wifiValidateSsid(const char* ssid, const char* pass) { uint8_t attempt = 0; WiFi.begin(ssid, pass); @@ -493,7 +494,7 @@ void wifiStop() LOG_WARNING(TAG_WIFI, F(D_SERVICE_STOPPED)); } -void wifi_get_statusupdate(char * buffer, size_t len) +void wifi_get_statusupdate(char* buffer, size_t len) { #if defined(STM32F4xx) IPAddress ip; @@ -510,7 +511,7 @@ void wifi_get_statusupdate(char * buffer, size_t len) /* ============ Confiuration =============================================================== */ #if HASP_USE_CONFIG > 0 -bool wifiGetConfig(const JsonObject & settings) +bool wifiGetConfig(const JsonObject& settings) { bool changed = false; @@ -532,7 +533,7 @@ bool wifiGetConfig(const JsonObject & settings) * * @param[in] settings JsonObject with the config settings. **/ -bool wifiSetConfig(const JsonObject & settings) +bool wifiSetConfig(const JsonObject& settings) { configOutput(settings, TAG_WIFI); bool changed = false; diff --git a/src/sys/svc/hasp_mdns.cpp b/src/sys/svc/hasp_mdns.cpp index 8f06c2f4..1c6c127e 100644 --- a/src/sys/svc/hasp_mdns.cpp +++ b/src/sys/svc/hasp_mdns.cpp @@ -4,16 +4,16 @@ #include "hasp_conf.h" #if HASP_USE_MDNS > 0 - #if defined(ARDUINO_ARCH_ESP32) - #include - #elif defined(ARDUINO_ARCH_ESP8266) - #include - // MDNSResponder::hMDNSService hMDNSService; - #endif +#if defined(ARDUINO_ARCH_ESP32) +#include +#elif defined(ARDUINO_ARCH_ESP8266) +#include +// MDNSResponder::hMDNSService hMDNSService; +#endif - #include "hasp/hasp.h" - #include "hasp_config.h" - #include "hasp_debug.h" +#include "hasp/hasp.h" +#include "hasp_config.h" +#include "hasp_debug.h" // uint8_t mdnsEnabled = true; hasp_mdns_config_t mdns_config; @@ -33,12 +33,6 @@ void mdnsStart() LOG_TRACE(TAG_MDNS, F(D_SERVICE_STARTING)); - #if HASP_USE_MQTT > 0 - String hasp2Node = mqttGetNodename(); - #else - String hasp2Node = "unknown"; - #endif - // Setup mDNS service discovery if enabled /* uint8_t attempt = 0; @@ -55,7 +49,7 @@ void mdnsStart() LOG_VERBOSE(TAG_MDNS, F("Trying hostname %s"), hasp2Node.c_str()); };*/ - if(MDNS.begin(hasp2Node.c_str())) { + if(MDNS.begin(haspDevice.get_hostname())) { char value[32]; char service[12]; char key[12]; @@ -86,23 +80,23 @@ void mdnsStart() void mdnsLoop(void) { - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) if(mdns_config.enable) { MDNS.update(); } - #endif +#endif } void mdnsStop() { return; - #if HASP_USE_MDNS > 0 +#if HASP_USE_MDNS > 0 MDNS.end(); - #endif +#endif } - #if HASP_USE_CONFIG > 0 -bool mdnsGetConfig(const JsonObject & settings) +#if HASP_USE_CONFIG > 0 +bool mdnsGetConfig(const JsonObject& settings) { bool changed = false; @@ -118,7 +112,7 @@ bool mdnsGetConfig(const JsonObject & settings) * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. * @param[in] settings JsonObject with the config settings. **/ -bool mdnsSetConfig(const JsonObject & settings) +bool mdnsSetConfig(const JsonObject& settings) { configOutput(settings, TAG_MDNS); bool changed = false; @@ -127,6 +121,6 @@ bool mdnsSetConfig(const JsonObject & settings) return changed; } - #endif // HASP_USE_CONFIG +#endif // HASP_USE_CONFIG #endif // HASP_USE_MDNS diff --git a/src/sys/svc/hasp_ota.cpp b/src/sys/svc/hasp_ota.cpp index 17392160..ba643b60 100644 --- a/src/sys/svc/hasp_ota.cpp +++ b/src/sys/svc/hasp_ota.cpp @@ -141,12 +141,8 @@ void otaSetup(void) // delay(5000); }); -#if HASP_USE_MQTT > 0 - ArduinoOTA.setHostname(String(mqttGetNodename()).c_str()); -#else - ArduinoOTA.setHostname(String(mqttGetNodename()).c_str()); -#endif - // ArduinoOTA.setPassword(configPassword); + ArduinoOTA.setHostname(haspDevice.get_hostname()); + // ArduinoOTA.setPassword(configPassword); // See OTA_PASSWORD ArduinoOTA.setPort(otaPort); #if ESP32 @@ -160,7 +156,7 @@ void otaSetup(void) ArduinoOTA.setRebootOnSuccess(false); // We do that ourselves #ifdef OTA_PASSWORD - ArduinoOTA.setPassword(OTA_PASSWORD); + ArduinoOTA.setPassword(OTA_PASSWORD); // TODO #endif ArduinoOTA.begin(); @@ -180,7 +176,7 @@ void otaEverySecond(void) if(otaPrecentageComplete >= 0) otaProgress(); } -void otaHttpUpdate(const char * espOtaUrl) +void otaHttpUpdate(const char* espOtaUrl) { // Update ESP firmware from HTTP #if HASP_USE_MDNS > 0 mdnsStop(); // Keep mDNS responder from breaking things diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/emulator_64bits.ini index 0d86e0e2..2c24a6e8 100644 --- a/user_setups/win32/emulator_64bits.ini +++ b/user_setups/win32/emulator_64bits.ini @@ -76,7 +76,11 @@ lib_deps = https://github.com/eclipse/paho.mqtt.c.git bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser -lib_ignore = paho +lib_ignore = + paho + AXP192 + ArduinoLog + lv_fs_if src_filter = +<*> @@ -89,14 +93,12 @@ src_filter = - - - - -<../.pio/libdeps/emulator_64bits/lv_fs_if/lv_fs_pc.c> - -<../.pio/libdeps/emulator_64bits/ArduinoLog/ArduinoLog.cpp> - - - - - - - + + - - - @@ -105,11 +107,4 @@ src_filter = + - + - - - - - -<../lib/lv_fs_if/> - -<../lib/lv_fs_if/lv_fs_if.cpp> - -<../lib/lv_fs_if/lv_fs_if.h> - -<../lib/lv_fs_if/lv_fs_spiffs.cpp> - -<../lib/lv_fs_if/lv_fs_spiffs.h> +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> From 06cba2ea8ed84ba94c4858ed736b34ae9bc1c783 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 18 Feb 2021 19:17:00 +0100 Subject: [PATCH 050/236] Use haspDevice for hostname --- src/log/hasp_debug.cpp | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index a7183f3a..c36ba4f5 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -65,14 +65,14 @@ // static StringStream debugStream((String &)debugOutput); // extern char mqttNodeName[16]; -const char * syslogAppName = APP_NAME; +const char* syslogAppName = APP_NAME; char debugSyslogHost[32] = SYSLOG_SERVER; uint16_t debugSyslogPort = SYSLOG_PORT; uint8_t debugSyslogFacility = 0; uint8_t debugSyslogProtocol = 0; // A UDP instance to let us send and receive packets over UDP -WiFiUDP * syslogClient; +WiFiUDP* syslogClient; #define SYSLOG_PROTO_IETF 0 // Create a new syslog instance with LOG_KERN facility @@ -109,7 +109,7 @@ unsigned long debugLastMillis = 0; uint16_t debugTelePeriod = 300; // Send the HASP header and version to the output device specified -void debugPrintHaspHeader(Print * output) +void debugPrintHaspHeader(Print* output) { if(debugAnsiCodes) output->print(TERM_COLOR_YELLOW); output->println(); @@ -198,7 +198,7 @@ void debugStop() } #if HASP_USE_CONFIG > 0 -bool debugGetConfig(const JsonObject & settings) +bool debugGetConfig(const JsonObject& settings) { bool changed = false; @@ -234,7 +234,7 @@ bool debugGetConfig(const JsonObject & settings) * * @param[in] settings JsonObject with the config settings. **/ -bool debugSetConfig(const JsonObject & settings) +bool debugSetConfig(const JsonObject& settings) { configOutput(settings, TAG_DEBG); bool changed = false; @@ -260,7 +260,7 @@ bool debugSetConfig(const JsonObject & settings) } #endif // HASP_USE_CONFIG -inline void debugSendAnsiCode(const __FlashStringHelper * code, Print * _logOutput) +inline void debugSendAnsiCode(const __FlashStringHelper* code, Print* _logOutput) { if(debugAnsiCodes) _logOutput->print(code); } @@ -329,11 +329,11 @@ void debugGetHistoryLine(size_t num) } */ -static void debugPrintTimestamp(int level, Print * _logOutput) +static void debugPrintTimestamp(int level, Print* _logOutput) { /* Print Current Time */ struct timeval tval; - struct tm * timeinfo; + struct tm* timeinfo; int rslt; rslt = gettimeofday(&tval, NULL); @@ -368,7 +368,7 @@ static void debugPrintTimestamp(int level, Print * _logOutput) } } -static void debugPrintHaspMemory(int level, Print * _logOutput) +static void debugPrintHaspMemory(int level, Print* _logOutput) { size_t maxfree = haspDevice.get_free_max_block(); size_t totalfree = haspDevice.get_free_heap(); @@ -387,7 +387,7 @@ static void debugPrintHaspMemory(int level, Print * _logOutput) } #if LV_MEM_CUSTOM == 0 -static void debugPrintLvglMemory(int level, Print * _logOutput) +static void debugPrintLvglMemory(int level, Print* _logOutput) { lv_mem_monitor_t mem_mon; lv_mem_monitor(&mem_mon); @@ -406,7 +406,7 @@ static void debugPrintLvglMemory(int level, Print * _logOutput) } #endif -static void debugPrintPriority(int level, Print * _logOutput) +static void debugPrintPriority(int level, Print* _logOutput) { // if(_logOutput == &syslogClient) { // } @@ -436,7 +436,7 @@ static void debugPrintPriority(int level, Print * _logOutput) } } -static void debugPrintTag(uint8_t tag, Print * _logOutput) +static void debugPrintTag(uint8_t tag, Print* _logOutput) { switch(tag) { case TAG_MAIN: @@ -544,7 +544,7 @@ static void debugPrintTag(uint8_t tag, Print * _logOutput) } } -void debugPrintPrefix(uint8_t tag, int level, Print * _logOutput) +void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput) { #if HASP_USE_SYSLOG > 0 @@ -562,7 +562,7 @@ void debugPrintPrefix(uint8_t tag, int level, Print * _logOutput) syslogClient->print(F("1 - ")); } - syslogClient->print(mqttGetNodename()); + syslogClient->print(haspDevice.get_hostname()); syslogClient->print(F(" ")); debugPrintTag(tag, _logOutput); @@ -602,7 +602,7 @@ void debugPrintPrefix(uint8_t tag, int level, Print * _logOutput) _logOutput->print(F(": ")); } -void debugPrintSuffix(uint8_t tag, int level, Print * _logOutput) +void debugPrintSuffix(uint8_t tag, int level, Print* _logOutput) { #if HASP_USE_SYSLOG > 0 if(_logOutput == syslogClient && syslogClient) { @@ -658,8 +658,7 @@ void debugPreSetup(JsonObject settings) } #if LV_USE_LOG != 0 -void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, - const char * descr) +void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr) { /* used for duplicate detection */ static uint32_t lastDbgLine; @@ -713,7 +712,7 @@ void printLocalTime() { char buffer[128]; time_t rawtime; - struct tm * timeinfo; + struct tm* timeinfo; // if(!time(nullptr)) return; @@ -732,8 +731,8 @@ void printLocalTime() // LwIP v2 is able to list more details about the currently configured SNTP servers for(int i = 0; i < SNTP_MAX_SERVERS; i++) { - IPAddress sntp = *sntp_getserver(i); - const char * name = sntp_getservername(i); + IPAddress sntp = *sntp_getserver(i); + const char* name = sntp_getservername(i); if(sntp.isSet()) { Serial.printf("sntp%d: ", i); if(name) { From e8850d99fe442aadc0a92a3e16c2852cf9ac825e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 18 Feb 2021 22:17:29 +0100 Subject: [PATCH 051/236] Add set_hostname to device class --- src/dev/device.h | 2 + src/dev/esp32/esp32.cpp | 22 ++-- src/dev/esp32/esp32.h | 16 ++- src/dev/esp8266/esp8266.cpp | 25 +++-- src/dev/esp8266/esp8266.h | 28 +++-- src/dev/win32/hasp_win32.cpp | 22 ++-- src/dev/win32/hasp_win32.h | 24 +++- src/hasp/hasp_dispatch.cpp | 2 +- src/mqtt/hasp_mqtt_ha.cpp | 63 ++++++----- src/mqtt/hasp_mqtt_pubsubclient.cpp | 23 ++-- src/sys/svc/hasp_http.cpp | 166 ++++++++++++++-------------- 11 files changed, 225 insertions(+), 168 deletions(-) diff --git a/src/dev/device.h b/src/dev/device.h index bb68fd42..ac2524a3 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -26,6 +26,8 @@ class BaseDevice { { return ""; } + virtual void set_hostname(const char*) + {} virtual const char* get_core_version() { return ""; diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index 2dbdd88d..36129a85 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -25,7 +25,11 @@ void Esp32Device::reboot() const char* Esp32Device::get_hostname() { - return hostname.c_str(); + return _hostname.c_str(); +} +void Esp32Device::set_hostname(const char* hostname) +{ + _hostname = hostname; } const char* Esp32Device::get_core_version() { @@ -38,7 +42,7 @@ const char* Esp32Device::get_display_driver() void Esp32Device::set_backlight_pin(uint8_t pin) { - Esp32Device::backlight_pin = pin; + Esp32Device::_backlight_pin = pin; /* Setup Backlight Control Pin */ if(pin != (uint8_t)-1) { @@ -53,33 +57,33 @@ void Esp32Device::set_backlight_pin(uint8_t pin) void Esp32Device::set_backlight_level(uint8_t level) { - backlight_level = level >= 0 ? level : 0; - backlight_level = backlight_level <= 100 ? backlight_level : 100; + _backlight_level = level >= 0 ? level : 0; + _backlight_level = _backlight_level <= 100 ? _backlight_level : 100; update_backlight(); } uint8_t Esp32Device::get_backlight_level() { - return backlight_level; + return _backlight_level; } void Esp32Device::set_backlight_power(bool power) { - backlight_power = power; + _backlight_power = power; update_backlight(); } bool Esp32Device::get_backlight_power() { - return backlight_power != 0; + return _backlight_power != 0; } void Esp32Device::update_backlight() { - if(backlight_pin == (uint8_t)-1) return; + if(_backlight_pin == (uint8_t)-1) return; - uint32_t duty = backlight_power ? map(backlight_level, 0, 100, 0, 4095) : 0; + uint32_t duty = _backlight_power ? map(_backlight_level, 0, 100, 0, 4095) : 0; ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value } diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index db5605ab..d7627047 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -13,9 +13,17 @@ namespace dev { class Esp32Device : public BaseDevice { public: + Esp32Device() + { + _hostname = "plate"; + _backlight_pin = TFT_BCKL; + _backlight_power = 1; + _backlight_level = 100; + } void reboot() override; const char* get_hostname(); + void set_hostname(const char*); const char* get_core_version(); const char* get_display_driver(); @@ -31,11 +39,11 @@ class Esp32Device : public BaseDevice { uint16_t get_cpu_frequency() override; private: - std::string hostname; + std::string _hostname; - uint8_t backlight_pin; - uint8_t backlight_level; - uint8_t backlight_power; + uint8_t _backlight_pin; + uint8_t _backlight_level; + uint8_t _backlight_power; void update_backlight(); }; diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index 95aa5795..95a9c08a 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -17,9 +17,18 @@ void Esp8266Device::reboot() ESP.restart(); } +const char* Esp8266Device::get_hostname() +{ + return _hostname.c_str(); +} +void Esp8266Device::set_hostname(const char* hostname) +{ + _hostname = hostname; +} + void Esp8266Device::set_backlight_pin(uint8_t pin) { - Esp8266Device::backlight_pin = pin; + _backlight_pin = pin; /* Setup Backlight Control Pin */ if(pin >= 0) { LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); @@ -30,33 +39,33 @@ void Esp8266Device::set_backlight_pin(uint8_t pin) void Esp8266Device::set_backlight_level(uint8_t level) { - backlight_level = level >= 0 ? level : 0; - backlight_level = backlight_level <= 100 ? backlight_level : 100; + _backlight_level = level >= 0 ? level : 0; + _backlight_level = _backlight_level <= 100 ? backlight_level : 100; update_backlight(); } uint8_t Esp8266Device::get_backlight_level() { - return backlight_level; + return _backlight_level; } void Esp8266Device::set_backlight_power(bool power) { - backlight_power = power; + _backlight_power = power; update_backlight(); } bool Esp8266Device::get_backlight_power() { - return backlight_power != 0; + return _backlight_power != 0; } void Esp8266Device::update_backlight() { - if(backlight_pin == -1) return; + if(_backlight_pin == -1) return; - analogWrite(backlight_pin, backlight_power ? map(backlight_level, 0, 100, 0, 1023) : 0); + analogWrite(backlight_pin, _backlight_power ? map(_backlight_level, 0, 100, 0, 1023) : 0); } size_t Esp8266Device::get_free_max_block() diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index c96641fc..4ef5421c 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -14,30 +14,38 @@ namespace dev { class Esp8266Device : public BaseDevice { public: + Esp8266Device() + { + hostname = "plate"; + backlight_pin = TFT_BCKL; + backlight_power = 1; + backlight_level = 100; + } + void reboot() override; + const char* get_hostname(); + void set_hostname(const char*); + const char* get_core_version(); + const char* get_display_driver(); + void set_backlight_pin(uint8_t pin) override; - void set_backlight_level(uint8_t val) override; - uint8_t get_backlight_level() override; - void set_backlight_power(bool power) override; - bool get_backlight_power() override; size_t get_free_max_block() override; - size_t get_free_heap() override; - uint8_t get_heap_fragmentation() override; - uint16_t get_cpu_frequency() override; private: - uint8_t backlight_pin; - uint8_t backlight_level; - uint8_t backlight_power; + std::string _hostname; + + uint8_t _backlight_pin; + uint8_t _backlight_level; + uint8_t _backlight_power; void update_backlight(); }; diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 9447de8b..31ca7dd5 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -15,7 +15,11 @@ void Win32Device::reboot() const char* Win32Device::get_hostname() { - return "winhasp"; + return _hostname.c_str(); +} +void Win32Device::set_hostname(const char* hostname) +{ + _hostname = hostname; } const char* Win32Device::get_core_version() { @@ -23,40 +27,40 @@ const char* Win32Device::get_core_version() } const char* Win32Device::get_display_driver() { - return "test"; + return "SDL2"; } void Win32Device::set_backlight_pin(uint8_t pin) { - Win32Device::backlight_pin = pin; + Win32Device::_backlight_pin = pin; } void Win32Device::set_backlight_level(uint8_t level) { - backlight_level = level >= 0 ? level : 0; - backlight_level = backlight_level <= 100 ? backlight_level : 100; + _backlight_level = level >= 0 ? level : 0; + _backlight_level = _backlight_level <= 100 ? _backlight_level : 100; update_backlight(); } uint8_t Win32Device::get_backlight_level() { - return backlight_level; + return _backlight_level; } void Win32Device::set_backlight_power(bool power) { - backlight_power = power; + _backlight_power = power; update_backlight(); } bool Win32Device::get_backlight_power() { - return backlight_power != 0; + return _backlight_power != 0; } void Win32Device::update_backlight() { - if(backlight_pin == -1) return; + if(_backlight_pin == -1) return; } size_t Win32Device::get_free_max_block() diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index 2d739e9a..3e742e6e 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -5,6 +5,7 @@ #define HASP_DEVICE_WINDOWS_H #include +#include #include "Windows.h" #include "hasp_conf.h" @@ -17,11 +18,20 @@ namespace dev { class Win32Device : public BaseDevice { public: + Win32Device() + { + _hostname = "winplate"; + _backlight_pin = -1; + _backlight_power = 1; + _backlight_level = 100; + } + void reboot() override; - const char* get_hostname() override; - const char* get_core_version() override; - const char* get_display_driver() override; + const char* get_hostname(); + void set_hostname(const char*); + const char* get_core_version(); + const char* get_display_driver(); void set_backlight_pin(uint8_t pin); void set_backlight_level(uint8_t val); @@ -35,9 +45,11 @@ class Win32Device : public BaseDevice { uint16_t get_cpu_frequency(); private: - uint8_t backlight_pin; - uint8_t backlight_level; - uint8_t backlight_power; + std::string _hostname; + + uint8_t _backlight_pin; + uint8_t _backlight_level; + uint8_t _backlight_power; void update_backlight(); }; diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 3ca31c20..7c920419 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -1026,7 +1026,7 @@ void dispatchLoop() void dispatchEverySecond() { if(dispatch_setings.teleperiod > 0 && (millis() - dispatchLastMillis) >= dispatch_setings.teleperiod * 1000) { - dispatchLastMillis = millis(); + dispatchLastMillis += dispatch_setings.teleperiod * 1000; dispatch_output_statusupdate(NULL, NULL); } } diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index 1bab42f0..5e1855a4 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -5,22 +5,24 @@ #include "hasp_conf.h" #ifndef WINDOWS - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 - #include "PubSubClient.h" +#include "PubSubClient.h" - #include "hasp/hasp.h" - #include "hasp/hasp_dispatch.h" - #include "hal/hasp_hal.h" - #include "hasp_mqtt.h" - #include "hasp_mqtt_ha.h" +#include "hasp/hasp.h" +#include "hasp/hasp_dispatch.h" +#include "hal/hasp_hal.h" +#include "dev/device.h" - #define RETAINED true - #define HASP_MAC_ADDRESS halGetMacAddress(0, "").c_str() - #define HASP_MAC_ADDRESS_STR halGetMacAddress(0, "") +#include "hasp_mqtt.h" +#include "hasp_mqtt_ha.h" + +#define RETAINED true +#define HASP_MAC_ADDRESS halGetMacAddress(0, "").c_str() +#define HASP_MAC_ADDRESS_STR halGetMacAddress(0, "") extern PubSubClient mqttClient; -extern char mqttNodeName[16]; +// extern char mqttNodeName[16]; extern char mqttNodeTopic[24]; extern char mqttGroupTopic[24]; extern bool mqttEnabled; @@ -34,7 +36,7 @@ const char FP_MQTT_HA_NAME[] PROGMEM = "name"; const char FP_MQTT_HA_MODEL[] PROGMEM = "mdl"; const char FP_MQTT_HA_MANUFACTURER[] PROGMEM = "mf"; -void mqtt_ha_send_json(char * topic, JsonDocument & doc) +void mqtt_ha_send_json(char* topic, JsonDocument& doc) { LOG_VERBOSE(TAG_MQTT_PUB, topic); mqttClient.beginPublish(topic, measureJson(doc), RETAINED); @@ -43,18 +45,18 @@ void mqtt_ha_send_json(char * topic, JsonDocument & doc) } // adds the device identifiers to the HA MQTT auto-discovery message -void mqtt_ha_add_device_ids(JsonDocument & doc) +void mqtt_ha_add_device_ids(JsonDocument& doc) { JsonObject device = doc.createNestedObject(FPSTR(FP_MQTT_HA_DEVICE)); JsonArray ids = device.createNestedArray(FPSTR(FP_MQTT_HA_IDENTIFIERS)); - ids.add(mqttNodeName); + ids.add(haspDevice.get_hostname()); ids.add(HASP_MAC_ADDRESS_STR); char buffer[32]; haspGetVersion(buffer, sizeof(buffer)); device[F("sw")] = buffer; - device[FPSTR(FP_MQTT_HA_NAME)] = mqttNodeName; + device[FPSTR(FP_MQTT_HA_NAME)] = haspDevice.get_hostname(); device[FPSTR(FP_MQTT_HA_MODEL)] = F(PIOENV); device[FPSTR(FP_MQTT_HA_MANUFACTURER)] = F(D_MANUFACTURER); @@ -62,11 +64,11 @@ void mqtt_ha_add_device_ids(JsonDocument & doc) } // adds the name and unique_id to the HA MQTT auto-discovery message -void mqtt_ha_add_unique_id(JsonDocument & doc, char * item) +void mqtt_ha_add_unique_id(JsonDocument& doc, char* item) { char buffer[64]; - snprintf_P(buffer, sizeof(buffer), PSTR("HASP %s %s"), mqttNodeName, item); + snprintf_P(buffer, sizeof(buffer), PSTR("HASP %s %s"), haspDevice.get_hostname(), item); doc[FPSTR(FP_MQTT_HA_NAME)] = buffer; snprintf_P(buffer, sizeof(buffer), PSTR("hasp_%s-%s"), HASP_MAC_ADDRESS, item); @@ -90,28 +92,28 @@ void mqtt_ha_register_button(uint8_t page, uint8_t id) doc[F("pl")] = buffer; doc[F("type")] = "button_short_press"; snprintf_P(buffer, sizeof(buffer), PSTR("%s/device_automation/%s/" HASP_OBJECT_NOTATION "_%s/config"), - discovery_prefix, mqttNodeName, page, id, "short_press"); + discovery_prefix, haspDevice.get_hostname(), page, id, "short_press"); mqtt_ha_send_json(buffer, doc); dispatch_get_event_name(HASP_EVENT_SHORT, buffer, sizeof(buffer)); doc[F("pl")] = buffer; doc[F("type")] = "button_short_release"; snprintf_P(buffer, sizeof(buffer), PSTR("%s/device_automation/%s/" HASP_OBJECT_NOTATION "_%s/config"), - discovery_prefix, mqttNodeName, page, id, "short_release"); + discovery_prefix, haspDevice.get_hostname(), page, id, "short_release"); mqtt_ha_send_json(buffer, doc); dispatch_get_event_name(HASP_EVENT_LONG, buffer, sizeof(buffer)); doc[F("pl")] = buffer; doc[F("type")] = "button_long_press"; snprintf_P(buffer, sizeof(buffer), PSTR("%s/device_automation/%s/" HASP_OBJECT_NOTATION "_%s/config"), - discovery_prefix, mqttNodeName, page, id, "long_press"); + discovery_prefix, haspDevice.get_hostname(), page, id, "long_press"); mqtt_ha_send_json(buffer, doc); dispatch_get_event_name(HASP_EVENT_UP, buffer, sizeof(buffer)); doc[F("pl")] = buffer; doc[F("type")] = "button_long_release"; snprintf_P(buffer, sizeof(buffer), PSTR("%s/device_automation/%s/" HASP_OBJECT_NOTATION "_%s/config"), - discovery_prefix, mqttNodeName, page, id, "long_release"); + discovery_prefix, haspDevice.get_hostname(), page, id, "long_release"); mqtt_ha_send_json(buffer, doc); } @@ -131,7 +133,7 @@ void mqtt_ha_register_switch(uint8_t page, uint8_t id) doc[F("type")] = F("button_short_release"); snprintf_P(buffer, sizeof(buffer), PSTR("%s/device_automation/%s/" HASP_OBJECT_NOTATION "_%s/config"), - discovery_prefix, mqttNodeName, page, id, "short"); + discovery_prefix, haspDevice.get_hostname(), page, id, "short"); mqtt_ha_send_json(buffer, doc); } @@ -149,7 +151,8 @@ void mqtt_ha_register_connectivity() mqtt_ha_add_unique_id(doc, item); char buffer[128]; - snprintf_P(buffer, sizeof(buffer), PSTR("%s/binary_sensor/%s/%s/config"), discovery_prefix, mqttNodeName, item); + snprintf_P(buffer, sizeof(buffer), PSTR("%s/binary_sensor/%s/%s/config"), discovery_prefix, + haspDevice.get_hostname(), item); mqtt_ha_send_json(buffer, doc); } @@ -174,7 +177,8 @@ void mqtt_ha_register_backlight() // doc[F("pl_off")] = F("OFF"); char buffer[128]; - snprintf_P(buffer, sizeof(buffer), PSTR("%s/light/%s/%s/config"), discovery_prefix, mqttNodeName, item); + snprintf_P(buffer, sizeof(buffer), PSTR("%s/light/%s/%s/config"), discovery_prefix, haspDevice.get_hostname(), + item); mqtt_ha_send_json(buffer, doc); } @@ -205,7 +209,8 @@ void mqtt_ha_register_moodlight() // doc[F("rgb_command_template")] = F("{{ '%02x%02x%02x0000'| format(red, green, blue) }}"); char buffer[128]; - snprintf_P(buffer, sizeof(buffer), PSTR("%s/light/%s/%s/config"), discovery_prefix, mqttNodeName, item); + snprintf_P(buffer, sizeof(buffer), PSTR("%s/light/%s/%s/config"), discovery_prefix, haspDevice.get_hostname(), + item); mqtt_ha_send_json(buffer, doc); } @@ -221,7 +226,8 @@ void mqtt_ha_register_idle() mqtt_ha_add_unique_id(doc, item); char buffer[128]; - snprintf_P(buffer, sizeof(buffer), PSTR("%s/sensor/%s/%s/config"), discovery_prefix, mqttNodeName, item); + snprintf_P(buffer, sizeof(buffer), PSTR("%s/sensor/%s/%s/config"), discovery_prefix, haspDevice.get_hostname(), + item); mqtt_ha_send_json(buffer, doc); } @@ -237,7 +243,8 @@ void mqtt_ha_register_activepage() mqtt_ha_add_unique_id(doc, item); char buffer[128]; - snprintf_P(buffer, sizeof(buffer), PSTR("%s/number/%s/%s/config"), discovery_prefix, mqttNodeName, item); + snprintf_P(buffer, sizeof(buffer), PSTR("%s/number/%s/%s/config"), discovery_prefix, haspDevice.get_hostname(), + item); mqtt_ha_send_json(buffer, doc); } @@ -252,7 +259,7 @@ void mqtt_ha_register_auto_discovery() mqtt_ha_register_idle(); mqtt_ha_register_connectivity(); } - #endif +#endif #endif /* diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index f8fbde27..e96cb92d 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -81,10 +81,10 @@ bool mqttHAautodiscover = true; #define LWT_TOPIC "LWT" -char mqttServer[16] = MQTT_HOST; -char mqttUser[23] = MQTT_USER; -char mqttPassword[32] = MQTT_PASSW; -char mqttNodeName[16] = MQTT_NODENAME; +char mqttServer[16] = MQTT_HOST; +char mqttUser[23] = MQTT_USER; +char mqttPassword[32] = MQTT_PASSW; +// char mqttNodeName[16] = MQTT_NODENAME; char mqttGroupName[16] = MQTT_GROUPNAME; uint16_t mqttPort = MQTT_PORT; PubSubClient mqttClient(mqttNetworkClient); @@ -368,8 +368,8 @@ bool mqttGetConfig(const JsonObject& settings) { bool changed = false; - if(strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)].as().c_str()) != 0) changed = true; - settings[FPSTR(FP_CONFIG_NAME)] = mqttNodeName; + if(strcmp(haspDevice.get_hostname(), settings[FPSTR(FP_CONFIG_NAME)].as().c_str()) != 0) changed = true; + settings[FPSTR(FP_CONFIG_NAME)] = haspDevice.get_hostname(); if(strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)].as().c_str()) != 0) changed = true; settings[FPSTR(FP_CONFIG_GROUP)] = mqttGroupName; @@ -406,14 +406,17 @@ bool mqttSetConfig(const JsonObject& settings) changed |= configSet(mqttPort, settings[FPSTR(FP_CONFIG_PORT)], F("mqttPort")); if(!settings[FPSTR(FP_CONFIG_NAME)].isNull()) { - changed |= strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)]) != 0; - strncpy(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)], sizeof(mqttNodeName)); + changed |= strcmp(haspDevice.get_hostname(), settings[FPSTR(FP_CONFIG_NAME)]) != 0; + // strncpy(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)], sizeof(mqttNodeName)); + haspDevice.set_hostname(settings[FPSTR(FP_CONFIG_NAME)].as()); } // Prefill node name - if(strlen(mqttNodeName) == 0) { + if(strlen(haspDevice.get_hostname()) == 0) { + char mqttNodeName[64]; String mac = halGetMacAddress(3, ""); mac.toLowerCase(); snprintf_P(mqttNodeName, sizeof(mqttNodeName), PSTR(D_MQTT_DEFAULT_NAME), mac.c_str()); + haspDevice.set_hostname(mqttNodeName); changed = true; } @@ -443,7 +446,7 @@ bool mqttSetConfig(const JsonObject& settings) strncpy(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)], sizeof(mqttPassword)); } - snprintf_P(mqttNodeTopic, sizeof(mqttNodeTopic), PSTR(MQTT_PREFIX "/%s/"), mqttNodeName); + snprintf_P(mqttNodeTopic, sizeof(mqttNodeTopic), PSTR(MQTT_PREFIX "/%s/"), haspDevice.get_hostname()); snprintf_P(mqttGroupTopic, sizeof(mqttGroupTopic), PSTR(MQTT_PREFIX "/%s/"), mqttGroupName); return changed; diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index f4751797..878654d8 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -63,7 +63,7 @@ ESP8266WebServer webServer(80); WebServer webServer(80); #endif // ESP32 -HTTPUpload * upload; +HTTPUpload* upload; static const char HTTP_MENU_BUTTON[] PROGMEM = "

"; @@ -113,11 +113,11 @@ const char HTTP_FOOTER[] PROGMEM = " by Francis Van Roie"; // // Default link to compiled Nextion firmware images // String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft"; -#if HASP_USE_MQTT > 0 -extern char mqttNodeName[16]; -#else -char mqttNodeName[3] = "na"; -#endif +// #if HASP_USE_MQTT > 0 +// extern char mqttNodeName[16]; +// #else +// char mqttNodeName[3] = "na"; +// #endif //////////////////////////////////////////////////////////////////////////////////////////////////// String getOption(int value, String label, bool selected) @@ -136,14 +136,14 @@ String getOption(String value, String label, bool selected) return buffer; } -static void add_gpio_select_option(String & str, uint8_t gpio, uint8_t bcklpin) +static void add_gpio_select_option(String& str, uint8_t gpio, uint8_t bcklpin) { char buffer[10]; snprintf_P(buffer, sizeof(buffer), PSTR("GPIO %d"), gpio); str += getOption(gpio, buffer, bcklpin == gpio); } -static void add_button(String & str, const __FlashStringHelper * label, const __FlashStringHelper * extra) +static void add_button(String& str, const __FlashStringHelper* label, const __FlashStringHelper* extra) { str += F("

"); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -350,14 +350,14 @@ void httpHandleReboot() if(!httpIsAuthenticated(F("reboot"))) return; { - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage = F(D_DISPATCH_REBOOT); - webSendPage(httpGetNodename(), httpMessage.length(), true); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), true); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -381,7 +381,7 @@ void webHandleScreenshot() } if(webServer.hasArg(F("q"))) { - lv_disp_t * disp = lv_disp_get_default(); + lv_disp_t* disp = lv_disp_get_default(); webServer.setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t)); webServer.send_P(200, PSTR("image/bmp"), ""); guiTakeScreenshot(); @@ -389,10 +389,10 @@ void webHandleScreenshot() } else { { - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage += @@ -413,7 +413,7 @@ void webHandleScreenshot() "

"); httpMessage += FPSTR(MAIN_MENU_BUTTON); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -428,7 +428,7 @@ void webHandleAbout() if(!httpIsAuthenticated(F("about"))) return; { - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

HASP OpenHardware edition

Copyright© 2020 Francis Van Roie "); @@ -469,7 +469,7 @@ void webHandleAbout() httpMessage += FPSTR(MAIN_MENU_BUTTON); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -483,10 +483,10 @@ void webHandleInfo() { char size_buf[32]; - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); /* HASP Stats */ @@ -638,7 +638,7 @@ void webHandleInfo() char mqttClientId[64]; String mac = halGetMacAddress(3, ""); mac.toLowerCase(); - snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%s"), mqttNodeName, mac.c_str()); + snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%s"), haspDevice.get_hostname(), mac.c_str()); httpMessage += mqttClientId; } @@ -677,7 +677,7 @@ void webHandleInfo() httpMessage += FPSTR(MAIN_MENU_BUTTON); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -714,7 +714,7 @@ void webHandleInfo() // return F("text/plain"); // } -static String getContentType(const String & path) +static String getContentType(const String& path) { char buff[sizeof(mime::mimeTable[0].mimeType)]; // Check all entries but last one for match, return if found @@ -772,9 +772,9 @@ void webUploadProgress() static inline void webUpdatePrintError() { #if defined(ARDUINO_ARCH_ESP8266) - String output((char *)0); + String output((char*)0); output.reserve(128); - StringStream stream((String &)output); + StringStream stream((String&)output); Update.printError(stream); // ESP8266 only has printError() LOG_ERROR(TAG_HTTP, output.c_str()); haspProgressMsg(output.c_str()); @@ -789,14 +789,14 @@ void webUpdateReboot() LOG_INFO(TAG_HTTP, F("Update Success: %u bytes received. Rebooting..."), upload->totalSize); { - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage += F("Upload complete. Rebooting device, please wait..."); - webSendPage(httpGetNodename(), httpMessage.length(), true); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), true); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -875,7 +875,7 @@ void handleFileUpload() if(upload->status == UPLOAD_FILE_START) { if(!httpIsAuthenticated(F("fileupload"))) return; LOG_INFO(TAG_HTTP, F("Total size: %s"), webServer.headerName(0).c_str()); - String filename((char *)0); + String filename((char*)0); filename.reserve(128); filename = upload->filename; if(!filename.startsWith("/")) { @@ -1040,10 +1040,10 @@ void webHandleConfig() #endif { - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); #if HASP_USE_WIFI > 0 @@ -1080,7 +1080,7 @@ void webHandleConfig() httpMessage += FPSTR(MAIN_MENU_BUTTON); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -1098,10 +1098,10 @@ void webHandleMqttConfig() { // char buffer[128]; - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage += F("
"); @@ -1133,7 +1133,7 @@ void webHandleMqttConfig() // D_HTTP_CONFIGURATION // "

"); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -1150,10 +1150,10 @@ void webHandleGuiConfig() StaticJsonDocument<256> settings; guiGetConfig(settings.to()); - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage += F("
"); @@ -1228,7 +1228,7 @@ void webHandleGuiConfig() // D_HTTP_CONFIGURATION // "

"); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } webSendFooter(); @@ -1245,10 +1245,10 @@ void webHandleWifiConfig() StaticJsonDocument<256> settings; wifiGetConfig(settings.to()); - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage += F("
"); @@ -1272,7 +1272,7 @@ void webHandleWifiConfig() } #endif - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); #if defined(STM32F4xx) httpMessage = ""; @@ -1296,7 +1296,7 @@ void webHandleHttpConfig() // String httpMessage((char *)0); // httpMessage.reserve(HTTP_PAGE_SIZE); // httpMessage += F("

"); - // httpMessage += httpGetNodename(); + // httpMessage += haspDevice.get_hostname(); // httpMessage += F("


"); // httpMessage += F(""); @@ -1328,14 +1328,14 @@ void webHandleHttpConfig() "

" "

"), - httpGetNodename(), settings[FPSTR(FP_CONFIG_USER)].as().c_str(), + haspDevice.get_hostname(), settings[FPSTR(FP_CONFIG_USER)].as().c_str(), settings[FPSTR(FP_CONFIG_PASS)].as().c_str()); // if(settings[FPSTR(FP_CONFIG_PASS)].as() != "") { // httpMessage += F(D_PASSWORD_MASK); // } - webSendPage(httpGetNodename(), len, false); + webSendPage(haspDevice.get_hostname(), len, false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -1368,10 +1368,10 @@ void webHandleGpioConfig() } { - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage += F("
"); @@ -1466,7 +1466,7 @@ void webHandleGpioConfig() // D_HTTP_CONFIGURATION // "

"); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -1484,10 +1484,10 @@ void webHandleGpioOptions() uint8_t config_id = webServer.arg(F("id")).toInt(); - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage += F("
"); @@ -1542,7 +1542,7 @@ void webHandleGpioOptions() httpMessage += F("

Group "D_HTTP_CONFIGURATION"

"); httpMessage += FPSTR(MAIN_MENU_BUTTON); - webSendPage(httpGetNodename(), httpMessage.length(), false); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -1759,7 +1759,7 @@ void httpHandleNotFound() // LOG_TRACE(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); #endif - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("File Not Found\n\nURI: "); @@ -1781,10 +1781,10 @@ void webHandleFirmware() if(!httpIsAuthenticated(F("firmware"))) return; { - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("
"); httpMessage += F("

ESP update

Updating ESP firmware from: "); httpMessage += webServer.arg("espFirmware"); - webSendPage(httpGetNodename(), httpMessage.length(), true); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), true); webServer.sendContent(httpMessage); // httpMessage.clear(); } @@ -1846,10 +1846,10 @@ void httpHandleResetConfig() bool resetConfirmed = webServer.arg(F("confirm")) == F("yes"); { - String httpMessage((char *)0); + String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); - httpMessage += httpGetNodename(); + httpMessage += haspDevice.get_hostname(); httpMessage += F("


"); if(resetConfirmed) { // User has confirmed, so reset everything @@ -1877,7 +1877,7 @@ void httpHandleResetConfig() // "

"); } - webSendPage(httpGetNodename(), httpMessage.length(), resetConfirmed); + webSendPage(haspDevice.get_hostname(), httpMessage.length(), resetConfirmed); webServer.sendContent(httpMessage); } // httpMessage.clear(); @@ -1928,8 +1928,8 @@ void httpSetup() // httpSetConfig(settings); // ask server to track these headers - const char * headerkeys[] = {"Content-Length"}; // "Authentication" - size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *); + const char* headerkeys[] = {"Content-Length"}; // "Authentication" + size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); webServer.collectHeaders(headerkeys, headerkeyssize); // Shared pages @@ -2050,7 +2050,7 @@ void httpEvery5Seconds() //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_CONFIG > 0 -bool httpGetConfig(const JsonObject & settings) +bool httpGetConfig(const JsonObject& settings) { bool changed = false; @@ -2077,7 +2077,7 @@ bool httpGetConfig(const JsonObject & settings) * * @param[in] settings JsonObject with the config settings. **/ -bool httpSetConfig(const JsonObject & settings) +bool httpSetConfig(const JsonObject& settings) { configOutput(settings, TAG_HTTP); bool changed = false; @@ -2098,7 +2098,7 @@ bool httpSetConfig(const JsonObject & settings) } #endif // HASP_USE_CONFIG -size_t httpClientWrite(const uint8_t * buf, size_t size) +size_t httpClientWrite(const uint8_t* buf, size_t size) { /***** Sending 16Kb at once freezes on STM32 EthernetClient *****/ size_t bytes_sent = 0; From 1ccbbf16ea612348d3932e924e5e641bd7563160 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 19 Feb 2021 01:58:20 +0100 Subject: [PATCH 052/236] Add virtual backlight dimming --- lib/lv_drivers/display/monitor.c | 90 ++++++++++++++++---------------- lib/lv_drivers/display/monitor.h | 5 +- src/dev/esp32/esp32.cpp | 10 ++-- src/dev/win32/hasp_win32.cpp | 7 ++- src/dev/win32/hasp_win32.h | 4 +- 5 files changed, 60 insertions(+), 56 deletions(-) diff --git a/lib/lv_drivers/display/monitor.c b/lib/lv_drivers/display/monitor.c index 491646b4..831ac7ff 100644 --- a/lib/lv_drivers/display/monitor.c +++ b/lib/lv_drivers/display/monitor.c @@ -10,7 +10,7 @@ #if USE_MONITOR #ifndef MONITOR_SDL_INCLUDE_PATH -# define MONITOR_SDL_INCLUDE_PATH +#define MONITOR_SDL_INCLUDE_PATH #endif #include @@ -24,51 +24,52 @@ /********************* * DEFINES *********************/ -#define SDL_REFR_PERIOD 50 /*ms*/ +#define SDL_REFR_PERIOD 50 /*ms*/ #ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 +#define MONITOR_ZOOM 1 #endif #ifndef MONITOR_HOR_RES -#define MONITOR_HOR_RES LV_HOR_RES +#define MONITOR_HOR_RES LV_HOR_RES #endif #ifndef MONITOR_VER_RES -#define MONITOR_VER_RES LV_VER_RES +#define MONITOR_VER_RES LV_VER_RES #endif #if defined(__APPLE__) && defined(TARGET_OS_MAC) -# if __APPLE__ && TARGET_OS_MAC +#if __APPLE__ && TARGET_OS_MAC #define MONITOR_APPLE -# endif +#endif #endif #if defined(__EMSCRIPTEN__) -# define MONITOR_EMSCRIPTEN +#define MONITOR_EMSCRIPTEN #endif /********************** * TYPEDEFS **********************/ -typedef struct { - SDL_Window * window; - SDL_Renderer * renderer; - SDL_Texture * texture; +typedef struct +{ + SDL_Window* window; + SDL_Renderer* renderer; + SDL_Texture* texture; volatile bool sdl_refr_qry; #if MONITOR_DOUBLE_BUFFERED - uint32_t * tft_fb_act; + uint32_t* tft_fb_act; #else uint32_t tft_fb[LV_HOR_RES_MAX * LV_VER_RES_MAX]; #endif -}monitor_t; +} monitor_t; /********************** * STATIC PROTOTYPES **********************/ -static int monitor_sdl_refr_thread(void * param); -static void window_create(monitor_t * m); -static void window_update(monitor_t * m); +static int monitor_sdl_refr_thread(void* param); +static void window_create(monitor_t* m); +static void window_update(monitor_t* m); /*********************** * GLOBAL PROTOTYPES @@ -83,10 +84,10 @@ monitor_t monitor; monitor_t monitor2; #endif -static volatile bool sdl_inited = false; +static volatile bool sdl_inited = false; static volatile bool sdl_quit_qry = false; -int quit_filter(void * userdata, SDL_Event * event); +int quit_filter(void* userdata, SDL_Event* event); static void monitor_sdl_clean_up(void); static void monitor_sdl_init(void); #ifdef MONITOR_EMSCRIPTEN @@ -115,7 +116,8 @@ void monitor_init(void) #ifndef MONITOR_EMSCRIPTEN SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL); - while(sdl_inited == false); /*Wait until 'sdl_refr' initializes the SDL*/ + while(sdl_inited == false) + ; /*Wait until 'sdl_refr' initializes the SDL*/ #endif } @@ -125,12 +127,12 @@ void monitor_init(void) * @param area an area where to copy `color_p` * @param color_p an array of pixel to copy to the `area` part of the screen */ -void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) +void monitor_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) { lv_coord_t hres = disp_drv->rotated == 0 ? disp_drv->hor_res : disp_drv->ver_res; lv_coord_t vres = disp_drv->rotated == 0 ? disp_drv->ver_res : disp_drv->hor_res; -// printf("x1:%d,y1:%d,x2:%d,y2:%d\n", area->x1, area->y1, area->x2, area->y2); + // printf("x1:%d,y1:%d,x2:%d,y2:%d\n", area->x1, area->y1, area->x2, area->y2); /*Return if the area is out the screen*/ if(area->x2 < 0 || area->y2 < 0 || area->x1 > hres - 1 || area->y1 > vres - 1) { @@ -140,7 +142,7 @@ void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t } #if MONITOR_DOUBLE_BUFFERED - monitor.tft_fb_act = (uint32_t *)color_p; + monitor.tft_fb_act = (uint32_t*)color_p; monitor.sdl_refr_qry = true; @@ -149,14 +151,13 @@ void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t #else int32_t y; -#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/ +#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/ int32_t x; for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) { for(x = area->x1; x <= area->x2; x++) { monitor.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p); color_p++; } - } #else uint32_t w = lv_area_get_width(area); @@ -173,7 +174,6 @@ void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t #endif } - #if MONITOR_DUAL /** @@ -182,7 +182,7 @@ void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * @param area an area where to copy `color_p` * @param color_p an array of pixel to copy to the `area` part of the screen */ -void monitor_flush2(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) +void monitor_flush2(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) { lv_coord_t hres = disp_drv->rotated == 0 ? disp_drv->hor_res : disp_drv->ver_res; lv_coord_t vres = disp_drv->rotated == 0 ? disp_drv->ver_res : disp_drv->hor_res; @@ -194,7 +194,7 @@ void monitor_flush2(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t } #if MONITOR_DOUBLE_BUFFERED - monitor2.tft_fb_act = (uint32_t *)color_p; + monitor2.tft_fb_act = (uint32_t*)color_p; monitor2.sdl_refr_qry = true; @@ -203,14 +203,13 @@ void monitor_flush2(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t #else int32_t y; -#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/ +#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/ int32_t x; for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) { for(x = area->x1; x <= area->x2; x++) { monitor2.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p); color_p++; } - } #else uint32_t w = lv_area_get_width(area); @@ -237,7 +236,7 @@ void monitor_flush2(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * It initializes SDL, handles drawing and the mouse. */ -static int monitor_sdl_refr_thread(void * param) +static int monitor_sdl_refr_thread(void* param) { (void)param; @@ -257,7 +256,7 @@ static int monitor_sdl_refr_thread(void * param) return 0; } -int quit_filter(void * userdata, SDL_Event * event) +int quit_filter(void* userdata, SDL_Event* event) { (void)userdata; @@ -265,13 +264,10 @@ int quit_filter(void * userdata, SDL_Event * event) if(event->window.event == SDL_WINDOWEVENT_CLOSE) { sdl_quit_qry = true; } - } - else if(event->type == SDL_QUIT) { + } else if(event->type == SDL_QUIT) { sdl_quit_qry = true; } - - return 1; } @@ -291,6 +287,12 @@ static void monitor_sdl_clean_up(void) SDL_Quit(); } +void monitor_backlight(uint8_t level) +{ + SDL_SetTextureColorMod(monitor.texture, level, level, level); + window_update(&monitor); +} + static void monitor_sdl_init(void) { /*Initialize the SDL*/ @@ -363,22 +365,21 @@ static void monitor_sdl_refr_core(void) /*Sleep some time*/ SDL_Delay(SDL_REFR_PERIOD); - } -static void window_create(monitor_t * m) +static void window_create(monitor_t* m) { - m->window = SDL_CreateWindow("TFT Simulator", - SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/ + m->window = SDL_CreateWindow("TFT Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, + 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/ #if MONITOR_VIRTUAL_MACHINE || defined(MONITOR_EMSCRIPTEN) m->renderer = SDL_CreateRenderer(m->window, -1, SDL_RENDERER_SOFTWARE); #else m->renderer = SDL_CreateRenderer(m->window, -1, 0); #endif - m->texture = SDL_CreateTexture(m->renderer, - SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, MONITOR_VER_RES); + m->texture = SDL_CreateTexture(m->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, + MONITOR_VER_RES); SDL_SetTextureBlendMode(m->texture, SDL_BLENDMODE_BLEND); /*Initialize the frame buffer to gray (77 is an empirical value) */ @@ -389,10 +390,9 @@ static void window_create(monitor_t * m) #endif m->sdl_refr_qry = true; - } -static void window_update(monitor_t * m) +static void window_update(monitor_t* m) { #if MONITOR_DOUBLE_BUFFERED == 0 SDL_UpdateTexture(m->texture, NULL, m->tft_fb, MONITOR_HOR_RES * sizeof(uint32_t)); diff --git a/lib/lv_drivers/display/monitor.h b/lib/lv_drivers/display/monitor.h index 6ef4d6d3..9156c32a 100644 --- a/lib/lv_drivers/display/monitor.h +++ b/lib/lv_drivers/display/monitor.h @@ -41,8 +41,9 @@ extern "C" { * GLOBAL PROTOTYPES **********************/ void monitor_init(void); -void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); -void monitor_flush2(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); +void monitor_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p); +void monitor_flush2(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p); +void monitor_backlight(uint8_t level); /********************** * MACROS diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index 36129a85..bc9bb28a 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -45,7 +45,7 @@ void Esp32Device::set_backlight_pin(uint8_t pin) Esp32Device::_backlight_pin = pin; /* Setup Backlight Control Pin */ - if(pin != (uint8_t)-1) { + if(pin < GPIO_NUM_MAX) { LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); ledcSetup(BACKLIGHT_CHANNEL, 20000, 12); ledcAttachPin(pin, BACKLIGHT_CHANNEL); @@ -81,10 +81,10 @@ bool Esp32Device::get_backlight_power() void Esp32Device::update_backlight() { - if(_backlight_pin == (uint8_t)-1) return; - - uint32_t duty = _backlight_power ? map(_backlight_level, 0, 100, 0, 4095) : 0; - ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value + if(pin < GPIO_NUM_MAX) { + uint32_t duty = _backlight_power ? map(_backlight_level, 0, 100, 0, 4095) : 0; + ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value + } } size_t Esp32Device::get_free_max_block() diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 31ca7dd5..7654e2e2 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -7,6 +7,9 @@ #include "hasp_conf.h" #include "hasp_debug.h" +#include "hasp/hasp_utilities.h" + +#include "display/monitor.h" namespace dev { @@ -32,7 +35,7 @@ const char* Win32Device::get_display_driver() void Win32Device::set_backlight_pin(uint8_t pin) { - Win32Device::_backlight_pin = pin; + // Win32Device::_backlight_pin = pin; } void Win32Device::set_backlight_level(uint8_t level) @@ -60,7 +63,7 @@ bool Win32Device::get_backlight_power() void Win32Device::update_backlight() { - if(_backlight_pin == -1) return; + monitor_backlight(_backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0); } size_t Win32Device::get_free_max_block() diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index 3e742e6e..0788bd48 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -20,8 +20,8 @@ class Win32Device : public BaseDevice { public: Win32Device() { - _hostname = "winplate"; - _backlight_pin = -1; + _hostname = "winplate"; + // _backlight_pin = -1; _backlight_power = 1; _backlight_level = 100; } From 59512141384706e5623d6978cfe911997de8839d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Feb 2021 01:20:25 +0100 Subject: [PATCH 053/236] Switch paho from async to single thread sync client --- ...mqtt_paho.cpp => hasp_mqtt_paho_async.cpp} | 15 +- src/mqtt/hasp_mqtt_paho_single.cpp | 371 ++++++++++++++++++ user_setups/win32/emulator_64bits.ini | 8 +- 3 files changed, 391 insertions(+), 3 deletions(-) rename src/mqtt/{hasp_mqtt_paho.cpp => hasp_mqtt_paho_async.cpp} (97%) create mode 100644 src/mqtt/hasp_mqtt_paho_single.cpp diff --git a/src/mqtt/hasp_mqtt_paho.cpp b/src/mqtt/hasp_mqtt_paho_async.cpp similarity index 97% rename from src/mqtt/hasp_mqtt_paho.cpp rename to src/mqtt/hasp_mqtt_paho_async.cpp index d33fa022..af3aab4e 100644 --- a/src/mqtt/hasp_mqtt_paho.cpp +++ b/src/mqtt/hasp_mqtt_paho_async.cpp @@ -1,11 +1,13 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ +/* Multi threaded asynchronous paho client */ + #include #include "hasp_conf.h" -#if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT_ASYNC > 0 #ifdef USE_PAHO /******************************************************************************* @@ -29,6 +31,7 @@ #include #include #include +#include #include "MQTTAsync.h" @@ -90,6 +93,9 @@ bool mqttHAautodiscover = true; #define LWT_TOPIC "LWT" +std::recursive_mutex dispatch_mtx; +std::recursive_mutex publish_mtx; + char mqttServer[16] = MQTT_HOST; char mqttUser[23] = MQTT_USER; char mqttPassword[32] = MQTT_PASSW; @@ -137,7 +143,9 @@ static void mqtt_message_cb(char* topic, char* payload, unsigned int length) // Group topic topic += strlen(mqttGroupTopic); // shorten topic + dispatch_mtx.lock(); dispatch_topic_payload(topic, (const char*)payload); + dispatch_mtx.unlock(); return; } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic @@ -170,7 +178,9 @@ static void mqtt_message_cb(char* topic, char* payload, unsigned int length) // LOG_TRACE(TAG_MQTT, F("ignoring LWT = online")); } } else { + dispatch_mtx.lock(); dispatch_topic_payload(topic, (const char*)payload); + dispatch_mtx.unlock(); } } @@ -303,9 +313,12 @@ static bool mqttPublish(const char* topic, const char* payload, size_t len, bool pubmsg.payloadlen = (int)strlen(payload); pubmsg.qos = QOS; pubmsg.retained = 0; + dispatch_mtx.lock(); if((rc = MQTTAsync_sendMessage(mqtt_client, topic, &pubmsg, &opts)) != MQTTASYNC_SUCCESS) { + dispatch_mtx.unlock(); LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " %s => %s"), topic, payload); } else { + dispatch_mtx.unlock(); LOG_TRACE(TAG_MQTT_PUB, F("%s => %s"), topic, payload); return true; } diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp new file mode 100644 index 00000000..c4e86946 --- /dev/null +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -0,0 +1,371 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +/* Single threaded synchronous paho client */ + +#include + +#include "hasp_conf.h" + +#if HASP_USE_MQTT > 0 +#ifdef USE_PAHO + +/******************************************************************************* + * Copyright (c) 2012, 2020 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * https://www.eclipse.org/legal/epl-2.0/ + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial contribution + *******************************************************************************/ + +#include +#include +#include +#include +#include + +#include "MQTTClient.h" + +#include "hasp_mqtt.h" // functions to implement here + +#include "hasp/hasp_dispatch.h" // for dispatch_topic_payload +#include "hasp_debug.h" // for logging + +#if !defined(_WIN32) +#include +#else +#include +#endif + +#if defined(_WRS_KERNEL) +#include +#endif + +#define ADDRESS "10.4.0.5:1883" +#define CLIENTID "test1123" +#define TOPIC "hasp/plate35/" +#define QOS 1 +#define TIMEOUT 1000L + +const char* mqttNodeTopic = "hasp/plate35/"; +const char* mqttGroupTopic = "hasp/plates/"; +// char mqttNodeTopic[24]; +// char mqttGroupTopic[24]; +bool mqttEnabled = false; +bool mqttHAautodiscover = true; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// These defaults may be overwritten with values saved by the web interface +#ifndef MQTT_HOST +#define MQTT_HOST ""; +#endif + +#ifndef MQTT_PORT +#define MQTT_PORT 1883; +#endif + +#ifndef MQTT_USER +#define MQTT_USER ""; +#endif + +#ifndef MQTT_PASSW +#define MQTT_PASSW ""; +#endif +#ifndef MQTT_NODENAME +#define MQTT_NODENAME ""; +#endif +#ifndef MQTT_GROUPNAME +#define MQTT_GROUPNAME ""; +#endif + +#ifndef MQTT_PREFIX +#define MQTT_PREFIX "hasp" +#endif + +#define LWT_TOPIC "LWT" + +char mqttServer[16] = MQTT_HOST; +char mqttUser[23] = MQTT_USER; +char mqttPassword[32] = MQTT_PASSW; +// char mqttNodeName[16] = MQTT_NODENAME; +char mqttGroupName[16] = MQTT_GROUPNAME; +uint16_t mqttPort = MQTT_PORT; + +MQTTClient mqtt_client; + +int disc_finished = 0; +int subscribed = 0; +int connected = 0; + +static bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain); + +/* ===== Paho event callbacks ===== */ + +void connlost(void* context, char* cause) +{ + printf("\nConnection lost\n"); + if(cause) printf(" cause: %s\n", cause); + + printf("Reconnecting\n"); + mqttStart(); +} + +// Receive incoming messages +static void mqtt_message_cb(char* topic, char* payload, unsigned int length) +{ // Handle incoming commands from MQTT + if(length + 1 >= MQTT_MAX_PACKET_SIZE) { + LOG_ERROR(TAG_MQTT_RCV, F("Payload too long (%d bytes)"), length); + return; + } else { + payload[length] = '\0'; + } + + LOG_TRACE(TAG_MQTT_RCV, F("%s = %s"), topic, (char*)payload); + + if(topic == strstr(topic, mqttNodeTopic)) { // startsWith mqttNodeTopic + + // Node topic + topic += strlen(mqttNodeTopic); // shorten topic + + } else if(topic == strstr(topic, mqttGroupTopic)) { // startsWith mqttGroupTopic + + // Group topic + topic += strlen(mqttGroupTopic); // shorten topic + dispatch_topic_payload(topic, (const char*)payload); + return; + + } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic + if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { + // dispatch_current_state(); + // mqtt_ha_register_auto_discovery(); + } + return; + + } else { + // Other topic + LOG_ERROR(TAG_MQTT, F(D_MQTT_INVALID_TOPIC)); + return; + } + + // catch a dangling LWT from a previous connection if it appears + if(!strcmp_P(topic, PSTR(LWT_TOPIC))) { // endsWith LWT + if(!strcasecmp_P((char*)payload, PSTR("offline"))) { + { + char msg[8]; + char tmp_topic[strlen(mqttNodeTopic) + 8]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" LWT_TOPIC), mqttNodeTopic); + snprintf_P(msg, sizeof(msg), PSTR("online")); + + // /*bool res =*/mqttClient.publish(tmp_topic, msg, true); + mqttPublish(tmp_topic, msg, strlen(msg), true); + } + + } else { + // LOG_TRACE(TAG_MQTT, F("ignoring LWT = online")); + } + } else { + dispatch_topic_payload(topic, (const char*)payload); + } +} + +int msgarrvd(void* context, char* topicName, int topicLen, MQTTClient_message* message) +{ + // printf("MQT RCV >> "); + // printf("%s => %.*s (%d)\n", topicName, message->payloadlen, (char *)message->payload, message->payloadlen); + + char msg[message->payloadlen + 1]; + memcpy(msg, (char*)message->payload, message->payloadlen); + msg[message->payloadlen] = '\0'; + + mqtt_message_cb(topicName, (char*)message->payload, message->payloadlen); + + MQTTClient_freeMessage(&message); + MQTTClient_free(topicName); + return 1; // the message was received properly +} + +void mqtt_subscribe(void* context, const char* topic) +{ + MQTTClient client = (MQTTClient)context; + int rc; + + printf("Subscribing to topic %s\nfor client %s using QoS%d\n\n", topic, CLIENTID, QOS); + if((rc = MQTTClient_subscribe(client, topic, QOS)) != MQTTCLIENT_SUCCESS) { + printf("Failed to start subscribe, return code %d\n", rc); + } +} + +/* ===== Local HASP MQTT functions ===== */ + +bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain) +{ + if(mqttIsConnected()) { + MQTTClient_message pubmsg = MQTTClient_message_initializer; + MQTTClient_deliveryToken token; + + pubmsg.payload = (char*)payload; + pubmsg.payloadlen = len; // (int)strlen(payload); + pubmsg.qos = QOS; + pubmsg.retained = retain; + + MQTTClient_publishMessage(mqtt_client, topic, &pubmsg, &token); + int rc = MQTTClient_waitForCompletion(mqtt_client, token, TIMEOUT); + + if(rc != MQTTCLIENT_SUCCESS) { + LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " '%s' => %s"), topic, payload); + } else { + LOG_TRACE(TAG_MQTT_PUB, F("'%s' => %s OK"), topic, payload); + return true; + } + } else { + LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_CONNECTED)); + } + return false; +} + +// static bool mqttPublish(const char* topic, const char* payload, bool retain) +// { +// return mqttPublish(topic, payload, strlen(payload), retain); +// } + +/* ===== Public HASP MQTT functions ===== */ + +bool mqttIsConnected() +{ + return connected == 1; +} + +void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) +{ + char tmp_topic[strlen(mqttNodeTopic) + 20]; + // printf(("%sstate/%s\n"), mqttNodeTopic, subtopic); + snprintf_P(tmp_topic, sizeof(tmp_topic), ("%sstate/%s"), mqttNodeTopic, subtopic); + mqttPublish(tmp_topic, payload, strlen(payload), false); +} + +void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) +{ + char tmp_topic[strlen(mqttNodeTopic) + 20]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/p%ub%u"), mqttNodeTopic, pageid, btnid); + mqttPublish(tmp_topic, payload, strlen(payload), false); +} + +static void onConnect(void* context) +{ + MQTTClient client = (MQTTClient)context; + connected = 1; + + printf("Successful connection\n"); + + mqtt_subscribe(mqtt_client, TOPIC "command/#"); + mqtt_subscribe(mqtt_client, TOPIC "command"); + mqtt_subscribe(mqtt_client, TOPIC "light"); + mqtt_subscribe(mqtt_client, TOPIC "dim"); + + mqttPublish(TOPIC LWT_TOPIC, "online", 6, false); + + mqtt_send_object_state(0, 0, "connected"); + std::cout << std::endl; +} + +void mqttStart() +{ + MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; + MQTTClient_willOptions will_opts = MQTTClient_willOptions_initializer; + int rc; + int ch; + + if((rc = MQTTClient_create(&mqtt_client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_NONE, NULL)) != + MQTTCLIENT_SUCCESS) { + printf("Failed to create client, return code %d\n", rc); + rc = EXIT_FAILURE; + return; + } + + // if((rc = MQTTClient_setCallbacks(mqtt_client, mqtt_client, connlost, msgarrvd, NULL)) != MQTTCLIENT_SUCCESS) { + // printf("Failed to set callbacks, return code %d\n", rc); + // rc = EXIT_FAILURE; + // return; + // } + + conn_opts.will = &will_opts; + conn_opts.will->message = "offline"; + conn_opts.will->qos = 1; + conn_opts.will->retained = 0; + conn_opts.will->topicName = "hasp/plate35/LWT"; + + conn_opts.keepAliveInterval = 20; + conn_opts.cleansession = 1; + + // conn_opts.username = ""; + // conn_opts.password = ""; + + if((rc = MQTTClient_connect(mqtt_client, &conn_opts)) != MQTTCLIENT_SUCCESS) { + printf("Failed to start connect, return code %d\n", rc); + rc = EXIT_FAILURE; + // goto destroy_exit; + } else { + onConnect(&mqtt_client); + } + + // while (!subscribed && !finished) + // #if defined(_WIN32) + // Sleep(100); + // #else + // usleep(10000L); + // #endif + + // if (finished) + // goto exit; +} + +void mqttStop() +{ + int rc; + // MQTTClient_disconnectOptions disc_opts = MQTTClient_disconnectOptions_initializer; + // disc_opts.onSuccess = onDisconnect; + // disc_opts.onFailure = onDisconnectFailure; + if((rc = MQTTClient_disconnect(mqtt_client, 1000)) != MQTTCLIENT_SUCCESS) { + printf("Failed to start disconnect, return code %d\n", rc); + rc = EXIT_FAILURE; + // goto destroy_exit; + } + // while (!disc_finished) + // { + // #if defined(_WIN32) + // Sleep(100); + // #else + // usleep(10000L); + // #endif + // } + + // destroy_exit: + // MQTTClient_destroy(&client); + // exit: + // return rc; +} + +void mqttSetup(){}; + +char* topicName; +int topicLen; +MQTTClient_message* message; +void mqttLoop() +{ + + int rc = MQTTClient_receive(mqtt_client, &topicName, &topicLen, &message, 4); + if(rc == MQTTCLIENT_SUCCESS && message) msgarrvd(mqtt_client, topicName, topicLen, message); +}; + +void mqttEvery5Seconds(bool wifiIsConnected){}; + +#endif // USE_PAHO +#endif // USE_MQTT \ No newline at end of file diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/emulator_64bits.ini index 2c24a6e8..67cf5d38 100644 --- a/user_setups/win32/emulator_64bits.ini +++ b/user_setups/win32/emulator_64bits.ini @@ -87,10 +87,14 @@ src_filter = -<*.h> +<../hal/sdl2> +<../.pio/libdeps/emulator_64bits/paho/src/*.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> + +<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTAsync.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTAsyncUtils.c> -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> - - + + + - + - - - - From 94842f7036074215f5027a6f7076dc9397bf3461 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Feb 2021 01:53:59 +0100 Subject: [PATCH 054/236] Tweak backlight dimming --- lib/lv_drivers/display/monitor.h | 3 +++ src/dev/esp32/esp32.cpp | 4 ++-- src/dev/win32/hasp_win32.cpp | 10 +++++++--- src/hasp/hasp_dispatch.cpp | 17 +---------------- src/hasp_gui.cpp | 2 +- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/lib/lv_drivers/display/monitor.h b/lib/lv_drivers/display/monitor.h index 9156c32a..b8f618de 100644 --- a/lib/lv_drivers/display/monitor.h +++ b/lib/lv_drivers/display/monitor.h @@ -43,7 +43,10 @@ extern "C" { void monitor_init(void); void monitor_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p); void monitor_flush2(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p); + +// HASP Customized functions void monitor_backlight(uint8_t level); +void monitor_title(const char* title); /********************** * MACROS diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index bc9bb28a..f9ef5ff1 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -42,7 +42,7 @@ const char* Esp32Device::get_display_driver() void Esp32Device::set_backlight_pin(uint8_t pin) { - Esp32Device::_backlight_pin = pin; + _backlight_pin = pin; /* Setup Backlight Control Pin */ if(pin < GPIO_NUM_MAX) { @@ -81,7 +81,7 @@ bool Esp32Device::get_backlight_power() void Esp32Device::update_backlight() { - if(pin < GPIO_NUM_MAX) { + if(_backlight_pin < GPIO_NUM_MAX) { uint32_t duty = _backlight_power ? map(_backlight_level, 0, 100, 0, 4095) : 0; ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value } diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 7654e2e2..c75f36dc 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -40,9 +40,13 @@ void Win32Device::set_backlight_pin(uint8_t pin) void Win32Device::set_backlight_level(uint8_t level) { - _backlight_level = level >= 0 ? level : 0; - _backlight_level = _backlight_level <= 100 ? _backlight_level : 100; - update_backlight(); + uint8_t new_level = level >= 0 ? level : 0; + new_level = new_level <= 100 ? new_level : 100; + + if(_backlight_level != new_level) { + _backlight_level = new_level; + update_backlight(); + } } uint8_t Win32Device::get_backlight_level() diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 7c920419..bf2c2dcb 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -897,32 +897,20 @@ void dispatch_output_statusupdate(const char*, const char*) { char buffer[128]; - printf("%s %d\n", __FILE__, __LINE__); - fflush(stdout); - haspGetVersion(buffer, sizeof(buffer)); snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), haspDevice.get_hostname(), buffer, long(millis() / 1000)); - printf("%s %d\n", __FILE__, __LINE__); - fflush(stdout); - #if HASP_USE_WIFI > 0 network_get_statusupdate(buffer, sizeof(buffer)); strcat(data, buffer); #endif - printf("%s %d\n", __FILE__, __LINE__); - fflush(stdout); - snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","), haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), haspDevice.get_core_version()); strcat(data, buffer); - printf("%s %d\n", __FILE__, __LINE__); - fflush(stdout); - snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), haspGetPage(), (HASP_NUM_PAGES)); strcat(data, buffer); @@ -932,9 +920,6 @@ void dispatch_output_statusupdate(const char*, const char*) strcat(data, buffer); #endif - printf("%s %d\n", __FILE__, __LINE__); - fflush(stdout); - snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), haspDevice.get_display_driver(), (TFT_WIDTH), (TFT_HEIGHT)); strcat(data, buffer); @@ -1019,7 +1004,7 @@ void dispatchSetup() void dispatchLoop() { - // Not used + lv_task_handler(); // process animations } #if 1 || ARDUINO diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 9b3cc7ff..cc9f2706 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -205,6 +205,7 @@ void guiSetup(void) /* Setup Backlight Control Pin */ haspDevice.set_backlight_pin(gui_settings.backlight_pin); + // if(gui_settings.backlight_pin >= 0) { // LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), gui_settings.backlight_pin); @@ -290,7 +291,6 @@ void guiLoop(void) // tick.update(); #endif - lv_task_handler(); // process animations #if !defined(WINDOWS) drv_touch_loop(); // update touch #endif From ea7d3757ad4a82f4ac171e693ac54481c6d712d3 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Feb 2021 01:56:55 +0100 Subject: [PATCH 055/236] Allow stretched window for fullscreen --- lib/lv_drivers/indev/mouse.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/lv_drivers/indev/mouse.c b/lib/lv_drivers/indev/mouse.c index 01d850fa..e4d519b9 100644 --- a/lib/lv_drivers/indev/mouse.c +++ b/lib/lv_drivers/indev/mouse.c @@ -13,7 +13,7 @@ * DEFINES *********************/ #ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 +#define MONITOR_ZOOM 1 #endif /********************** @@ -28,8 +28,8 @@ * STATIC VARIABLES **********************/ static bool left_button_down = false; -static int16_t last_x = 0; -static int16_t last_y = 0; +static int16_t last_x = 0; +static int16_t last_y = 0; /********************** * MACROS @@ -43,9 +43,7 @@ static int16_t last_y = 0; * Initialize the mouse */ void mouse_init(void) -{ - -} +{} /** * Get the current position and state of the mouse @@ -53,14 +51,14 @@ void mouse_init(void) * @param data store the mouse data here * @return false: because the points are not buffered, so no more data to be read */ -bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +bool mouse_read(lv_indev_drv_t* indev_drv, lv_indev_data_t* data) { - (void) indev_drv; /*Unused*/ + (void)indev_drv; /*Unused*/ /*Store the collected data*/ data->point.x = last_x; data->point.y = last_y; - data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; + data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; return false; } @@ -68,27 +66,31 @@ bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) /** * It will be called from the main SDL thread */ -void mouse_handler(SDL_Event * event) +void mouse_handler(SDL_Event* event) { + int x; + int y; + + SDL_Window* window = SDL_GetWindowFromID(event->window.windowID); + SDL_GetWindowSize(window, &x, &y); + switch(event->type) { case SDL_MOUSEBUTTONUP: - if(event->button.button == SDL_BUTTON_LEFT) - left_button_down = false; + if(event->button.button == SDL_BUTTON_LEFT) left_button_down = false; break; case SDL_MOUSEBUTTONDOWN: if(event->button.button == SDL_BUTTON_LEFT) { left_button_down = true; - last_x = event->motion.x / MONITOR_ZOOM; - last_y = event->motion.y / MONITOR_ZOOM; + if(x != 0) last_x = event->motion.x * TFT_WIDTH / x; // / MONITOR_ZOOM; + if(y != 0) last_y = event->motion.y * TFT_HEIGHT / y; // / MONITOR_ZOOM; } break; case SDL_MOUSEMOTION: - last_x = event->motion.x / MONITOR_ZOOM; - last_y = event->motion.y / MONITOR_ZOOM; + if(x != 0) last_x = event->motion.x * TFT_WIDTH / x; // / MONITOR_ZOOM; + if(y != 0) last_y = event->motion.y * TFT_HEIGHT / y; // / MONITOR_ZOOM; break; } - } /********************** From fb9a844fc78fe852ead04dd1c70d50d25125a516 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Feb 2021 01:59:42 +0100 Subject: [PATCH 056/236] move lvgl init to hasp_gui --- hal/sdl2/app_hal.c | 52 ++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/hal/sdl2/app_hal.c b/hal/sdl2/app_hal.c index 326c8282..72ba9bba 100644 --- a/hal/sdl2/app_hal.c +++ b/hal/sdl2/app_hal.c @@ -1,18 +1,17 @@ #include -#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/ +#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/ #include #include "display/monitor.h" #include "indev/mouse.h" #include "indev/mousewheel.h" #include "indev/keyboard.h" - /** * A task to measure the elapsed time for LittlevGL * @param data unused * @return never return */ -static int tick_thread(void * data) +static int tick_thread(void* data) { (void)data; @@ -24,52 +23,33 @@ static int tick_thread(void * data) return 0; } - void hal_setup(void) { - // Workaround for sdl2 `-m32` crash - // https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7 - #ifndef WIN32 - setenv("DBUS_FATAL_WARNINGS", "0", 1); - #endif +// Workaround for sdl2 `-m32` crash +// https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7 +#ifndef WIN32 + setenv("DBUS_FATAL_WARNINGS", "0", 1); +#endif /* Add a display * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ monitor_init(); - /* Tick init. - * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed - * Create an SDL thread to do this*/ - SDL_CreateThread(tick_thread, "tick", NULL); - - lv_init(); - static lv_disp_buf_t disp_buf; - static lv_color_t buf[LV_HOR_RES_MAX * 10]; /*Declare a buffer for 10 lines*/ - lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/ - - lv_disp_drv_t disp_drv; - lv_disp_drv_init(&disp_drv); /*Basic initialization*/ - disp_drv.flush_cb = monitor_flush; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/ - disp_drv.buffer = &disp_buf; - //disp_drv.disp_fill = monitor_fill; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ - //disp_drv.disp_map = monitor_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ - lv_disp_drv_register(&disp_drv); /* Add the mouse as input device * Use the 'mouse' driver which reads the PC's mouse*/ mouse_init(); - lv_indev_drv_t indev_drv; - lv_indev_drv_init(&indev_drv); /*Basic initialization*/ - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read_cb = mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/ - lv_indev_drv_register(&indev_drv); - + /* Tick init. + * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed + * Create an SDL thread to do this*/ + SDL_CreateThread(tick_thread, "tick", NULL); } void hal_loop(void) { - /*while(1)*/ { - SDL_Delay(5); - lv_task_handler(); - } + // we don't use thise !! + // while(1) { + // SDL_Delay(5); + // lv_task_handler(); + // } } From bee68ca79177998a2d5df5af6ced362c94d26292 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Feb 2021 02:43:09 +0100 Subject: [PATCH 057/236] Console & Windows app, add command line options --- src/main_windows.cpp | 170 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 158 insertions(+), 12 deletions(-) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index c2e113ab..35d5e478 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -3,10 +3,15 @@ #ifdef WINDOWS +#include +#include +#include + #include "hasp_conf.h" #include "lvgl.h" #include "app_hal.h" +#include "display/monitor.h" #include "hasp_debug.h" #include "hasp_gui.h" @@ -22,8 +27,67 @@ bool isRunning = 1; uint8_t mainLoopCounter = 0; unsigned long mainLastLoopTime = 0; -void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, - const char * descr) +// https://gist.github.com/kingseva/a918ec66079a9475f19642ec31276a21 +void BindStdHandlesToConsole() +{ + // TODO: Add Error checking. + + // Redirect the CRT standard input, output, and error handles to the console + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stderr); + freopen("CONOUT$", "w", stdout); + + // Note that there is no CONERR$ file + HANDLE hStdout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE hStdin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + SetStdHandle(STD_OUTPUT_HANDLE, hStdout); + SetStdHandle(STD_ERROR_HANDLE, hStdout); + SetStdHandle(STD_INPUT_HANDLE, hStdin); + + // Clear the error state for each of the C++ standard stream objects. + std::wclog.clear(); + std::clog.clear(); + std::wcout.clear(); + std::cout.clear(); + std::wcerr.clear(); + std::cerr.clear(); + std::wcin.clear(); + std::cin.clear(); +} + +void InitializeConsoleOutput() +{ + bool isConsoleApp; + + // How to check if the program is run from a console? + // https://stackoverflow.com/questions/9009333/how-to-check-if-the-program-is-run-from-a-console + HWND consoleWnd = GetConsoleWindow(); + DWORD dwProcessId; + GetWindowThreadProcessId(consoleWnd, &dwProcessId); + + if(GetCurrentProcessId() == dwProcessId) { + isConsoleApp = true; // Opened in Console + } else { + isConsoleApp = false; // Opened in Windows + } + + // Use normal console that launched the program + AttachConsole(ATTACH_PARENT_PROCESS); + + // Test if the application was started from a Console Window + if(!isConsoleApp) { + // If started from Windows, use detached Log Console Window + AllocConsole(); + } + + // Redirect all standard output streams to the console + BindStdHandlesToConsole(); +} + +void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr) { printf("%s %d\n", file, line); } @@ -46,22 +110,23 @@ void setup() dispatchSetup(); // debugSetup(); // Init the console -#if HASP_USE_MQTT > 0 - printf("%s %d\n", __FILE__, __LINE__); - mqttSetup(); // Load Hostname before starting WiFi -#endif - printf("%s %d\n", __FILE__, __LINE__); haspSetup(); + +#if HASP_USE_MQTT > 0 + printf("%s %d\n", __FILE__, __LINE__); + mqttSetup(); // Hasp must be running + mqttStart(); +#endif + mainLastLoopTime = millis() - 1000; // reset loop counter delay(250); - - mqttStart(); } void loop() { haspLoop(); + mqttLoop(); // debugLoop(); // Console haspDevice.loop(); @@ -70,7 +135,8 @@ void loop() /* Timer Loop */ if(millis() - mainLastLoopTime >= 1000) { /* Runs Every Second */ - haspEverySecond(); // sleep timer + haspEverySecond(); // sleep timer + dispatchEverySecond(); // sleep timer #if HASP_USE_OTA > 0 otaEverySecond(); // progressbar @@ -91,17 +157,97 @@ void loop() mainLastLoopTime += 1000; } - delay(6); + // delay(6); } #ifdef WINDOWS -int main(int argv, char ** args) + +void usage(char* progName) { + std::cout << progName << " [options]" << std::endl + << std::endl + << "Options:" << std::endl + << " -h | --help Print this help" << std::endl + << " -n | --name Plate hostname used in the mqtt topic" + << std::endl + // << " -b | --broker Mqtt broker name or ip address" << std::endl + // << " -P | --port Mqtt broker port (default: 1883)" << std::endl + // << " -u | --user Mqtt username (optional)" << std::endl + // << " -p | --pass Mqtt password (optional)" << std::endl + // << " -t | --topic Base topic of the mqtt messages (default: hasp)" << std::endl + // << " -g | --group Group topic of on which to accept incoming messages (default: plates)" + // << std::endl + // << " -f | --fullscreen Open the application fullscreen" << std::endl + // << " -v | --verbose Verbosity level" << std::endl + << std::endl; + fflush(stdout); + + static const char s[] = "\n"; + DWORD slen = lstrlen(s); + WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), s, slen, &slen, NULL); +} + +int main(int argc, char* argv[]) +{ + bool showhelp = false; + int count; + + InitializeConsoleOutput(); + + // Display each command-line argument. + std::cout << "\nCommand-line arguments:\n"; + for(count = 0; count < argc; count++) + std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; + + SetConsoleCP(65001); // 65001 = UTF-8 + static const char s[] = "tränenüberströmt™\n"; + DWORD slen = lstrlen(s); + WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), s, slen, &slen, NULL); + + HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); + if(std_out == INVALID_HANDLE_VALUE) { + // return 66; + } + if(!WriteConsole(std_out, "Hello World!", 12, NULL, NULL)) { + // return 67; + } + + for(count = 0; count < argc; count++) { + if(argv[count][0] == '-') { + + if(strncmp(argv[count], "--help", 6) == 0 || strncmp(argv[count], "-h", 2) == 0) { + std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; + fflush(stdout); + exit(0); + } + + if(strncmp(argv[count], "--name", 6) == 0) { + std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; + fflush(stdout); + if(count + 1 < argc) { + haspDevice.set_hostname(argv[count] + 1); + } else { + showhelp = true; + } + } + } + } + + if(showhelp) { + usage("hasp-lvgl"); + WriteConsole(std_out, "bye", 3, NULL, NULL); + + FreeConsole(); + return 0; + } + // printf("%s %d\n", __FILE__, __LINE__); // fflush(stdout); setup(); + monitor_title(haspDevice.get_hostname()); while(isRunning) { + loop(); // std::cout << "HSetup OK\n"; } From 578ab093183b603c57c5b910f60861ddd0418cf2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Feb 2021 03:01:18 +0100 Subject: [PATCH 058/236] Update tests --- test/test_colors.tavern.yaml | 10 ++++----- test/test_label.tavern.yaml | 40 ++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/test/test_colors.tavern.yaml b/test/test_colors.tavern.yaml index dd8a7d35..172fff36 100644 --- a/test/test_colors.tavern.yaml +++ b/test/test_colors.tavern.yaml @@ -70,7 +70,7 @@ marks: - parametrize: key: obj vals: - - cb + - checkbox - btn stages: @@ -88,13 +88,13 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p[1].b[0].bg_color={color}" - delay_after: 0.1 + delay_after: 0.02 - name: Clear page mqtt_publish: topic: hasp/{plate}/command/clearpage payload: "" - delay_after: 0.2 + delay_after: 0.02 - name: Create object mqtt_publish: @@ -106,13 +106,13 @@ stages: r: !int "{r:d}" g: !int "{g:d}" b: !int "{b:d}" - delay_after: 0.1 + delay_after: 0.02 - name: Set bg_color mqtt_publish: topic: hasp/{plate}/command payload: "p[1].b[0].bg_color={rgb565}" - delay_after: 0.1 + delay_after: 0.02 - name: Test named COLOR mqtt_publish: diff --git a/test/test_label.tavern.yaml b/test/test_label.tavern.yaml index fa995d2b..f5dace3d 100644 --- a/test/test_label.tavern.yaml +++ b/test/test_label.tavern.yaml @@ -12,7 +12,7 @@ paho-mqtt: &mqtt_spec connect: host: "{host}" port: !int "{port:d}" - timeout: 3 + timeout: 1 stages: - name: Page 1 @@ -23,13 +23,13 @@ stages: topic: hasp/{plate}/state/page payload: "1" timeout: 1 - delay_after: 0.1 + delay_after: 0.02 - name: Clear page mqtt_publish: topic: hasp/{plate}/command/clearpage payload: "" - delay_after: 0.1 + delay_after: 0.02 - name: Create object mqtt_publish: @@ -37,13 +37,13 @@ stages: json: objid: 12 id: 1 - delay_after: 0.1 + delay_after: 0.02 - name: Set x mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.x=50" - delay_after: 0.1 + delay_after: 0.02 - name: Get x mqtt_publish: topic: hasp/{plate}/command @@ -71,7 +71,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.y=50" - delay_after: 0.1 + delay_after: 0.02 - name: Get y mqtt_publish: topic: hasp/{plate}/command @@ -85,7 +85,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.y=25" - delay_after: 0.1 + delay_after: 0.02 - name: Get y mqtt_publish: topic: hasp/{plate}/command @@ -100,7 +100,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.w=50" - delay_after: 0.1 + delay_after: 0.02 - name: Get w mqtt_publish: topic: hasp/{plate}/command @@ -128,7 +128,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.h=50" - delay_after: 0.1 + delay_after: 0.02 - name: Get h mqtt_publish: topic: hasp/{plate}/command @@ -142,7 +142,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.h=25" - delay_after: 0.1 + delay_after: 0.02 - name: Get h mqtt_publish: topic: hasp/{plate}/command @@ -157,7 +157,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.mode=crop" - delay_after: 0.1 + delay_after: 0.02 - name: Get mode mqtt_publish: topic: hasp/{plate}/command @@ -167,7 +167,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.w=50" - delay_after: 0.1 + delay_after: 0.02 - name: Get w mqtt_publish: topic: hasp/{plate}/command @@ -195,7 +195,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.h=50" - delay_after: 0.1 + delay_after: 0.02 - name: Get h mqtt_publish: topic: hasp/{plate}/command @@ -209,7 +209,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.h=45" - delay_after: 0.1 + delay_after: 0.02 - name: Get h mqtt_publish: topic: hasp/{plate}/command @@ -224,7 +224,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.enabled=0" - delay_after: 0.1 + delay_after: 0.02 - name: Get enabled mqtt_publish: topic: hasp/{plate}/command @@ -238,7 +238,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.enabled=1" - delay_after: 0.1 + delay_after: 0.02 - name: Get enabled mqtt_publish: topic: hasp/{plate}/command @@ -253,7 +253,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.hidden=1" - delay_after: 0.1 + delay_after: 0.02 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command @@ -277,7 +277,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.hidden=0" - delay_after: 0.1 + delay_after: 0.02 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command @@ -301,7 +301,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.vis=0" - delay_after: 0.1 + delay_after: 0.02 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command @@ -325,7 +325,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.vis=1" - delay_after: 0.1 + delay_after: 0.02 - name: Get hidden mqtt_publish: topic: hasp/{plate}/command From aa2a3b3fc22b5156611d68b2c1871b66c79f9285 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 00:08:07 +0100 Subject: [PATCH 059/236] Add name command line parameter --- src/main_windows.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 35d5e478..7e4c6e4e 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -194,6 +194,26 @@ int main(int argc, char* argv[]) InitializeConsoleOutput(); + char hostbuffer[256]; + char* IPbuffer; + struct hostent* host_entry; + int hostname; + + // To retrieve hostname + hostname = gethostname(hostbuffer, sizeof(hostbuffer)); + // checkHostName(hostname); + + // To retrieve host information + host_entry = gethostbyname(hostbuffer); + // checkHostEntry(host_entry); + + // To convert an Internet network + // address into ASCII string + // IPbuffer = inet_ntoa(*((struct in_addr*)host_entry->h_addr_list[0])); + + printf("Hostname: %s", hostbuffer); + // printf("Host IP: %s", IPbuffer); + // Display each command-line argument. std::cout << "\nCommand-line arguments:\n"; for(count = 0; count < argc; count++) @@ -225,7 +245,7 @@ int main(int argc, char* argv[]) std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; fflush(stdout); if(count + 1 < argc) { - haspDevice.set_hostname(argv[count] + 1); + haspDevice.set_hostname(argv[count + 1]); } else { showhelp = true; } @@ -247,7 +267,6 @@ int main(int argc, char* argv[]) monitor_title(haspDevice.get_hostname()); while(isRunning) { - loop(); // std::cout << "HSetup OK\n"; } From 2a2fc45425df3bb35e2207830dfbf1b7aec9a63c Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:36:38 +0100 Subject: [PATCH 060/236] Add strcasecmp --- include/hasp_conf.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 577c3d78..3c64ab88 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -254,13 +254,14 @@ static WiFiSpiClass WiFi; #ifdef WINDOWS #include +#include #include #include #include #define snprintf_P snprintf #define memcpy_P memcpy -#define strcasecmp_P strcmp // TODO: should be strcasecmp +#define strcasecmp_P strcasecmp #define strcmp_P strcmp #define strstr_P strstr #define halRestartMcu() From 898518071abfbee697fabe18093ef514d5074283 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:44:28 +0100 Subject: [PATCH 061/236] Test rotation and fullscreen --- lib/lv_drivers/display/monitor.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/lv_drivers/display/monitor.c b/lib/lv_drivers/display/monitor.c index 831ac7ff..fe0c0f27 100644 --- a/lib/lv_drivers/display/monitor.c +++ b/lib/lv_drivers/display/monitor.c @@ -62,6 +62,7 @@ typedef struct #else uint32_t tft_fb[LV_HOR_RES_MAX * LV_VER_RES_MAX]; #endif + double rotation; } monitor_t; /********************** @@ -293,6 +294,12 @@ void monitor_backlight(uint8_t level) window_update(&monitor); } +void monitor_title(const char* title) +{ + SDL_SetWindowTitle(monitor.window, title); + // SDL_SetWindowFullscreen(monitor.window, SDL_WINDOW_FULLSCREEN_DESKTOP); +} + static void monitor_sdl_init(void) { /*Initialize the SDL*/ @@ -408,7 +415,8 @@ static void window_update(monitor_t* m) // SDL_RenderDrawRect(renderer, &r); /*Update the renderer with the texture containing the rendered image*/ - SDL_RenderCopy(m->renderer, m->texture, NULL, NULL); + // SDL_RenderCopy(m->renderer, m->texture, NULL, NULL); + SDL_RenderCopyEx(m->renderer, m->texture, NULL, NULL, m->rotation, NULL, SDL_FLIP_NONE); SDL_RenderPresent(m->renderer); } From 2223e5722af82753dc8ae335d691644ae55d1ab8 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:45:43 +0100 Subject: [PATCH 062/236] Move to haspTft class --- src/drv/tft_driver.h | 48 +++++++++ src/drv/tft_driver_sdl2.h | 93 ++++++++++++++++++ src/drv/tft_driver_tftesp.cpp | 7 ++ src/drv/tft_driver_tftespi.h | 177 ++++++++++++++++++++++++++++++++++ src/hasp_gui.cpp | 95 +++++------------- 5 files changed, 347 insertions(+), 73 deletions(-) create mode 100644 src/drv/tft_driver.h create mode 100644 src/drv/tft_driver_sdl2.h create mode 100644 src/drv/tft_driver_tftesp.cpp create mode 100644 src/drv/tft_driver_tftespi.h diff --git a/src/drv/tft_driver.h b/src/drv/tft_driver.h new file mode 100644 index 00000000..a44dfba4 --- /dev/null +++ b/src/drv/tft_driver.h @@ -0,0 +1,48 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_BASE_TFT_DRIVER_H +#define HASP_BASE_TFT_DRIVER_H + +#ifdef ARDUINO +#include "Arduino.h" +#endif +#include "lvgl.h" + +namespace dev { + +class BaseTft { + public: + virtual void init(int w, int h) + {} + virtual void show_info() + {} + virtual void set_rotation(uint8_t rotation) + {} + virtual void set_invert(bool invert_display) + {} + static void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) + {} +}; + +} // namespace dev + +#if defined(ESP32) +#warning Building for ESP32 Devices +#include "tft_driver_tftespi.h" +#elif defined(ESP8266) +#warning Building for ESP8266 Devices +#include "tft_driver_tftespi.h" +#elif defined(STM32F4) +#warning Building for STM32F4xx Devices +#include "tft_driver_tftespi.h" +#elif defined(WINDOWS) +#warning Building for Win32 Devices +#include "tft_driver_sdl2.h" +#else +#warning Building for Generic Devices +using dev::BaseTft; +extern dev::BaseTft haspTft; +#endif + +#endif \ No newline at end of file diff --git a/src/drv/tft_driver_sdl2.h b/src/drv/tft_driver_sdl2.h new file mode 100644 index 00000000..0419427a --- /dev/null +++ b/src/drv/tft_driver_sdl2.h @@ -0,0 +1,93 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_SDL2_DRIVER_H +#define HASP_SDL2_DRIVER_H + +#include "lvgl.h" +#include + +#include "display/monitor.h" +#include "indev/mouse.h" + +#include "tft_driver.h" +#include "dev/device.h" +#include "hasp_debug.h" + +//#include "bootscreen.h" // Sketch tab header for xbm images + +namespace dev { + +/** + * A task to measure the elapsed time for LittlevGL + * @param data unused + * @return never return + */ +static int tick_thread(void* data) +{ + (void)data; + + while(1) { + SDL_Delay(5); /*Sleep for 5 millisecond*/ + lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/ + } + + return 0; +} + +class TftSdl2 : BaseTft { + public: + void init(int w, int h) + { + +// Workaround for sdl2 `-m32` crash +// https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7 +#ifndef WIN32 + setenv("DBUS_FATAL_WARNINGS", "0", 1); +#endif + + /* Add a display + * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ + monitor_init(); + monitor_title(haspDevice.get_hostname()); + + /* Add the mouse as input device + * Use the 'mouse' driver which reads the PC's mouse*/ + mouse_init(); + + /* Tick init. + * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed + * Create an SDL thread to do this*/ + SDL_CreateThread(tick_thread, "tick", NULL); + } + void show_info() + { + SDL_version linked; + SDL_GetVersion(&linked); + LOG_VERBOSE(TAG_TFT, F("SDL2 : v%d.%d.%d"), linked.major, linked.minor, linked.patch); + LOG_VERBOSE(TAG_TFT, F("Driver : SDL2")); + } + + void splashscreen() + { + // tft.fillScreen(TFT_DARKCYAN); + // int x = (tft.width() - logoWidth) / 2; + // int y = (tft.height() - logoHeight) / 2; + // tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE); + } + void set_rotation(uint8_t rotation) + {} + void set_invert(bool invert) + {} + static void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) + { + monitor_flush(disp, area, color_p); + } +}; + +} // namespace dev + +using dev::TftSdl2; +extern dev::TftSdl2 haspTft; + +#endif \ No newline at end of file diff --git a/src/drv/tft_driver_tftesp.cpp b/src/drv/tft_driver_tftesp.cpp new file mode 100644 index 00000000..2928d035 --- /dev/null +++ b/src/drv/tft_driver_tftesp.cpp @@ -0,0 +1,7 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifdef ARDUINO +#include "tft_driver_tftespi.h" +dev::TftEspi haspTft; +#endif \ No newline at end of file diff --git a/src/drv/tft_driver_tftespi.h b/src/drv/tft_driver_tftespi.h new file mode 100644 index 00000000..d6e46793 --- /dev/null +++ b/src/drv/tft_driver_tftespi.h @@ -0,0 +1,177 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_TFTESPI_DRIVER_H +#define HASP_TFTESPI_DRIVER_H + +#ifdef ARDUINO +#include "Arduino.h" +#endif + +#include "lvgl.h" +#include "tft_espi.h" + +#include "tft_driver.h" +#include "hal/hasp_hal.h" +#include "dev/device.h" +#include "hasp_debug.h" + +#include "bootscreen.h" // Sketch tab header for xbm images + +namespace dev { + +class TftEspi : BaseTft { + + public: + void init(int w, int h) + { + tft.begin(); + tft.setSwapBytes(true); /* set endianess */ + } + void show_info() + { + + setup_t tftSetup; + tft.getSetup(tftSetup); + + LOG_VERBOSE(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str()); + LOG_VERBOSE(TAG_TFT, F("Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); + LOG_VERBOSE(TAG_TFT, F("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel")); + +#if defined(ARDUINO_ARCH_ESP8266) + LOG_VERBOSE(TAG_TFT, F("SPI overlap: %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No")); +#endif + + if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch + { + LOG_VERBOSE(TAG_TFT, F("Driver : %s"), halDisplayDriverName().c_str()); // tftSetup.tft_driver); + LOG_VERBOSE(TAG_TFT, F("Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height); + } else if(tftSetup.tft_driver == 0xE9D) + LOG_VERBOSE(TAG_TFT, F("Driver = ePaper")); + + // Offsets, not all used yet + tftOffsetInfo(0, tftSetup.r0_x_offset, tftSetup.r0_y_offset); + tftOffsetInfo(1, tftSetup.r1_x_offset, tftSetup.r1_y_offset); + tftOffsetInfo(2, tftSetup.r2_x_offset, tftSetup.r2_y_offset); + tftOffsetInfo(3, tftSetup.r3_x_offset, tftSetup.r3_y_offset); + /* replaced by tftOffsetInfo + // if(tftSetup.r1_x_offset != 0) Serial.printf("R1 x offset = %i \n", tftSetup.r1_x_offset); + // if(tftSetup.r1_y_offset != 0) Serial.printf("R1 y offset = %i \n", tftSetup.r1_y_offset); + // if(tftSetup.r2_x_offset != 0) Serial.printf("R2 x offset = %i \n", tftSetup.r2_x_offset); + // if(tftSetup.r2_y_offset != 0) Serial.printf("R2 y offset = %i \n", tftSetup.r2_y_offset); + // if(tftSetup.r3_x_offset != 0) Serial.printf("R3 x offset = %i \n", tftSetup.r3_x_offset); + // if(tftSetup.r3_y_offset != 0) Serial.printf("R3 y offset = %i \n", tftSetup.r3_y_offset); + */ + + tftPinInfo(F("MOSI"), tftSetup.pin_tft_mosi); + tftPinInfo(F("MISO"), tftSetup.pin_tft_miso); + tftPinInfo(F("SCLK"), tftSetup.pin_tft_clk); + +#if defined(ARDUINO_ARCH_ESP8266) + if(tftSetup.overlap == true) { + LOG_VERBOSE(TAG_TFT, F("Overlap selected, following pins MUST be used:")); + + LOG_VERBOSE(TAG_TFT, F("MOSI : SD1 (GPIO 8)")); + LOG_VERBOSE(TAG_TFT, F("MISO : SD0 (GPIO 7)")); + LOG_VERBOSE(TAG_TFT, F("SCK : CLK (GPIO 6)")); + LOG_VERBOSE(TAG_TFT, F("TFT_CS : D3 (GPIO 0)")); + + LOG_VERBOSE(TAG_TFT, F("TFT_DC and TFT_RST pins can be tftSetup defined")); + } +#endif + + tftPinInfo(F("TFT_CS"), tftSetup.pin_tft_cs); + tftPinInfo(F("TFT_DC"), tftSetup.pin_tft_dc); + tftPinInfo(F("TFT_RST"), tftSetup.pin_tft_rst); + + tftPinInfo(F("TOUCH_CS"), tftSetup.pin_tch_cs); + + tftPinInfo(F("TFT_WR"), tftSetup.pin_tft_wr); + tftPinInfo(F("TFT_RD"), tftSetup.pin_tft_rd); + + tftPinInfo(F("TFT_D0"), tftSetup.pin_tft_d0); + tftPinInfo(F("TFT_D1"), tftSetup.pin_tft_d1); + tftPinInfo(F("TFT_D2"), tftSetup.pin_tft_d2); + tftPinInfo(F("TFT_D3"), tftSetup.pin_tft_d3); + tftPinInfo(F("TFT_D4"), tftSetup.pin_tft_d4); + tftPinInfo(F("TFT_D5"), tftSetup.pin_tft_d5); + tftPinInfo(F("TFT_D6"), tftSetup.pin_tft_d6); + tftPinInfo(F("TFT_D7"), tftSetup.pin_tft_d7); + + if(tftSetup.serial == 1) { + LOG_VERBOSE(TAG_TFT, F("Display SPI freq. : %d.%d MHz"), tftSetup.tft_spi_freq / 10, + tftSetup.tft_spi_freq % 10); + } + if(tftSetup.pin_tch_cs != -1) { + LOG_VERBOSE(TAG_TFT, F("Touch SPI freq. : %d.%d MHz"), tftSetup.tch_spi_freq / 10, + tftSetup.tch_spi_freq % 10); + } + } + void splashscreen() + { + tft.fillScreen(TFT_DARKCYAN); + int x = (tft.width() - logoWidth) / 2; + int y = (tft.height() - logoHeight) / 2; + tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE); + } + void set_rotation(uint8_t rotation) + { + LOG_VERBOSE(TAG_TFT, F("Rotation : %d"), rotation); + tft.setRotation(rotation); + } + void set_invert(bool invert) + { + char buffer[4]; + memcpy_P(buffer, invert ? PSTR("yes") : PSTR("no"), sizeof(buffer)); + + LOG_VERBOSE(TAG_TFT, F("Invert Disp: %s"), buffer); + tft.invertDisplay(invert); + } + void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) + { + size_t len = lv_area_get_size(area); + + /* Update TFT */ + tft.startWrite(); /* Start new TFT transaction */ + tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */ +#ifdef USE_DMA_TO_TFT + tft.pushPixelsDMA((uint16_t*)color_p, len); /* Write words at once */ +#else + tft.pushPixels((uint16_t*)color_p, len); /* Write words at once */ +#endif + tft.endWrite(); /* terminate TFT transaction */ + + /* Tell lvgl that flushing is done */ + lv_disp_flush_ready(disp); + } + + private: + TFT_eSPI tft; + + void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset) + { + if(x_offset != 0) { + LOG_VERBOSE(TAG_TFT, F("R%u x offset = %i"), pin, x_offset); + } + if(y_offset != 0) { + LOG_VERBOSE(TAG_TFT, F("R%u y offset = %i"), pin, y_offset); + } + } + + void tftPinInfo(const __FlashStringHelper* pinfunction, int8_t pin) + { + if(pin != -1) { + char buffer[64]; + snprintf_P(buffer, sizeof(buffer), PSTR("%-11s: %s (GPIO %02d)"), pinfunction, halGpioName(pin).c_str(), + pin); + LOG_VERBOSE(TAG_TFT, buffer); + } + } +}; + +} // namespace dev + +using dev::TftEspi; +extern dev::TftEspi haspTft; + +#endif \ No newline at end of file diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index cc9f2706..7063d104 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -12,7 +12,9 @@ #include "lv_fs_if.h" // Device Drivers +#include "drv/tft_driver.h" #include "dev/device.h" + #include "drv/hasp_drv_display.h" #include "drv/hasp_drv_touch.h" @@ -79,6 +81,10 @@ gui_conf_t gui_settings = {.show_pointer = false, // { // lv_tick_inc(LVGL_TICK_PERIOD); // } +void gui_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) +{ + haspTft.flush_pixels(disp, area, color_p); +} void guiCalibrate(void) { @@ -105,6 +111,12 @@ void guiSetup(void) lv_log_register_print_cb(debugLvglLogEvent); #endif + // Initialize the TFT + haspTft.init(240, 320); + haspTft.set_rotation(gui_settings.rotation); + haspTft.set_invert(gui_settings.invert_display); + haspTft.show_info(); + /* Create the Virtual Device Buffers */ #if defined(ARDUINO_ARCH_ESP32) @@ -163,14 +175,8 @@ void guiSetup(void) /* Initialize the display driver */ lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); - disp_drv.buffer = &disp_buf; - -#if defined(WINDOWS) - disp_drv.flush_cb = monitor_flush; -#else - drv_display_init(&disp_drv, gui_settings.rotation, - gui_settings.invert_display); // Set display driver callback & rotation -#endif + disp_drv.buffer = &disp_buf; + disp_drv.flush_cb = gui_flush_cb; disp_drv.hor_res = TFT_WIDTH; disp_drv.ver_res = TFT_HEIGHT; lv_disp_t* display = lv_disp_drv_register(&disp_drv); @@ -206,18 +212,6 @@ void guiSetup(void) /* Setup Backlight Control Pin */ haspDevice.set_backlight_pin(gui_settings.backlight_pin); - // if(gui_settings.backlight_pin >= 0) { - // LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), gui_settings.backlight_pin); - - // #if defined(ARDUINO_ARCH_ESP32) - // ledcSetup(BACKLIGHT_CHANNEL, 20000, 12); - // ledcAttachPin(gui_settings.backlight_pin, BACKLIGHT_CHANNEL); - // #elif defined(ARDUINO_ARCH_ESP8266) - // pinMode(gui_settings.backlight_pin, OUTPUT); - // #endif - // } - LOG_VERBOSE(TAG_GUI, F("Rotation : %d"), gui_settings.rotation); - LOG_VERBOSE(TAG_LVGL, F("Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH, PSTR(LVGL_VERSION_INFO)); @@ -321,57 +315,6 @@ void guiStop() // #endif } -//////////////////////////////////////////////////////////////////////////////////////////////////// -/* -bool guiGetBacklight() -{ - return guiBacklightIsOn; -} - -void guiSetBacklight(bool lighton) -{ - guiBacklightIsOn = lighton; - - if(!lighton) hasp_enable_wakeup_touch(); - - if(gui_settings.backlight_pin >= 0) { - -#if defined(ARDUINO_ARCH_ESP32) - ledcWrite(BACKLIGHT_CHANNEL, lighton ? map(guiDimLevel, 0, 100, 0, 4095) : 0); // ledChannel and value -#else - analogWrite(gui_settings.backlight_pin, lighton ? map(guiDimLevel, 0, 100, 0, 1023) : 0); -#endif - - } else { - guiBacklightIsOn = true; - } -} - -void guiSetDim(int8_t level) -{ - if(gui_settings.backlight_pin >= 0) { - guiDimLevel = level >= 0 ? level : 0; - guiDimLevel = guiDimLevel <= 100 ? guiDimLevel : 100; - - if(guiBacklightIsOn) { // The backlight is ON -#if defined(ARDUINO_ARCH_ESP32) - ledcWrite(BACKLIGHT_CHANNEL, map(guiDimLevel, 0, 100, 0, 4095)); // ledChannel and value -#else - analogWrite(gui_settings.backlight_pin, map(guiDimLevel, 0, 100, 0, 1023)); -#endif - } - - } else { - guiDimLevel = -1; - } -} - -int8_t guiGetDim() -{ - return guiDimLevel; -} -*/ - //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_CONFIG > 0 bool guiGetConfig(const JsonObject& settings) @@ -587,7 +530,10 @@ static void gui_screenshot_to_file(lv_disp_drv_t* disp, const lv_area_t* area, l len *= sizeof(lv_color_t); /* Number of bytes */ size_t res = pFileOut.write((uint8_t*)color_p, len); if(res != len) gui_flush_not_complete(); - drv_display_flush_cb(disp, area, color_p); // indirect callback to flush screenshot data to the screen + + // indirect callback to flush screenshot data to the screen + // drv_display_flush_cb(disp, area, color_p); + haspTft.flush_pixels(disp, area, color_p); } /** Take Screenshot. @@ -642,7 +588,10 @@ static void gui_screenshot_to_http(lv_disp_drv_t* disp, const lv_area_t* area, l len *= sizeof(lv_color_t); /* Number of bytes */ size_t res = httpClientWrite((uint8_t*)color_p, len); if(res != len) gui_flush_not_complete(); - drv_display_flush_cb(disp, area, color_p); + + // indirect callback to flush screenshot data to the screen + // drv_display_flush_cb(disp, area, color_p); + haspTft.flush_pixels(disp, area, color_p); } /** Take Screenshot. From cc4cc54c22effa4282c2f210a4e95c06e4c8c741 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:46:29 +0100 Subject: [PATCH 063/236] Hamonize mqtt drivers --- src/mqtt/hasp_mqtt.h | 2 + src/mqtt/hasp_mqtt.old | 450 ---------------------------- src/mqtt/hasp_mqtt_ha.cpp | 55 ++-- src/mqtt/hasp_mqtt_paho_async.cpp | 4 +- src/mqtt/hasp_mqtt_paho_single.cpp | 30 +- src/mqtt/hasp_mqtt_pubsubclient.cpp | 8 +- 6 files changed, 64 insertions(+), 485 deletions(-) delete mode 100644 src/mqtt/hasp_mqtt.old diff --git a/src/mqtt/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h index 16c1abcd..b10d9e4d 100644 --- a/src/mqtt/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -21,6 +21,8 @@ void mqttStop(); void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload); void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload); +bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain); + bool mqttIsConnected(); #if HASP_USE_CONFIG > 0 diff --git a/src/mqtt/hasp_mqtt.old b/src/mqtt/hasp_mqtt.old deleted file mode 100644 index 0c67bc24..00000000 --- a/src/mqtt/hasp_mqtt.old +++ /dev/null @@ -1,450 +0,0 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie - For full license information read the LICENSE file in the project folder */ - -#include "hasp_conf.h" -#if HASP_USE_MQTT > 0 - - #include "PubSubClient.h" - - #include "hasp/hasp.h" - #include "hasp_mqtt.h" - #include "hasp_mqtt_ha.h" - - #if defined(ARDUINO_ARCH_ESP32) - #include -WiFiClient mqttNetworkClient; - #elif defined(ARDUINO_ARCH_ESP8266) - #include - #include - #include -WiFiClient mqttNetworkClient; - #else - #if defined(STM32F4xx) && HASP_USE_WIFI > 0 -// #include -WiFiSpiClient mqttNetworkClient; - #else - #if defined(W5500_MOSI) && defined(W5500_MISO) && defined(W5500_SCLK) - #define W5500_LAN - #include - #else - #include - #endif - -EthernetClient mqttNetworkClient; - #endif - #endif - - #include "hasp_hal.h" - #include "log/hasp_debug.h" - #include "hasp_config.h" - - #include "../hasp/hasp_dispatch.h" - - #ifdef USE_CONFIG_OVERRIDE - #include "user_config_override.h" - #endif - -char mqttNodeTopic[24]; -char mqttGroupTopic[24]; -bool mqttEnabled = false; -bool mqttHAautodiscover = true; - - //////////////////////////////////////////////////////////////////////////////////////////////////// - // These defaults may be overwritten with values saved by the web interface - #ifndef MQTT_HOST - #define MQTT_HOST ""; - #endif - - #ifndef MQTT_PORT - #define MQTT_PORT 1883; - #endif - - #ifndef MQTT_USER - #define MQTT_USER ""; - #endif - - #ifndef MQTT_PASSW - #define MQTT_PASSW ""; - #endif - #ifndef MQTT_NODENAME - #define MQTT_NODENAME ""; - #endif - #ifndef MQTT_GROUPNAME - #define MQTT_GROUPNAME ""; - #endif - - #ifndef MQTT_PREFIX - #define MQTT_PREFIX "hasp" - #endif - - #define LWT_TOPIC "LWT" - -char mqttServer[16] = MQTT_HOST; -char mqttUser[23] = MQTT_USER; -char mqttPassword[32] = MQTT_PASSW; -char mqttNodeName[16] = MQTT_NODENAME; -char mqttGroupName[16] = MQTT_GROUPNAME; -uint16_t mqttPort = MQTT_PORT; -PubSubClient mqttClient(mqttNetworkClient); - -static bool mqttPublish(const char * topic, const char * payload, size_t len, bool retain = false) -{ - if(mqttIsConnected()) { - if(mqttClient.beginPublish(topic, len, retain)) { - mqttClient.write((uint8_t *)payload, len); - mqttClient.endPublish(); - - LOG_TRACE(TAG_MQTT_PUB, F("%s => %s"), topic, payload); - return true; - } else { - LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " %s => %s"), topic, payload); - } - } else { - LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_CONNECTED)); - } - return false; -} - -static bool mqttPublish(const char * topic, const char * payload, bool retain = false) -{ - return mqttPublish(topic, payload, strlen(payload), retain); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Send changed values OUT - -bool mqttIsConnected() -{ - return mqttEnabled && mqttClient.connected(); -} - -void mqtt_send_lwt(bool online) -{ - char tmp_payload[8]; - char tmp_topic[strlen(mqttNodeTopic) + 4]; - strncpy(tmp_topic, mqttNodeTopic, sizeof(tmp_topic)); - strncat_P(tmp_topic, PSTR(LWT_TOPIC), sizeof(tmp_topic)); - // snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" LWT_TOPIC), mqttNodeTopic); - - size_t len = snprintf_P(tmp_payload, sizeof(tmp_payload), online ? PSTR("online") : PSTR("offline")); - bool res = mqttPublish(tmp_topic, tmp_payload, len, true); -} - -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload) -{ - char tmp_topic[strlen(mqttNodeTopic) + 16]; - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/" HASP_OBJECT_NOTATION), mqttNodeTopic, pageid, btnid); - mqttPublish(tmp_topic, payload); -} - -void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload) -{ - char tmp_topic[strlen(mqttNodeTopic) + 20]; - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/%s"), mqttNodeTopic, subtopic); - mqttPublish(tmp_topic, payload); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Receive incoming messages -static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) -{ // Handle incoming commands from MQTT - if(length + 1 >= mqttClient.getBufferSize()) { - LOG_ERROR(TAG_MQTT_RCV, F("Payload too long (%d bytes)"), length); - return; - } else { - payload[length] = '\0'; - } - - LOG_TRACE(TAG_MQTT_RCV, F("%s = %s"), topic, (char *)payload); - - if(topic == strstr(topic, mqttNodeTopic)) { // startsWith mqttNodeTopic - - // Node topic - topic += strlen(mqttNodeTopic); // shorten topic - - } else if(topic == strstr(topic, mqttGroupTopic)) { // startsWith mqttGroupTopic - - // Group topic - topic += strlen(mqttGroupTopic); // shorten topic - dispatch_topic_payload(topic, (const char *)payload); - return; - - } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic - if(mqttHAautodiscover && !strcasecmp_P((char *)payload, PSTR("online"))) { - dispatch_current_state(); - mqtt_ha_register_auto_discovery(); - } - return; - - } else { - // Other topic - LOG_ERROR(TAG_MQTT, F(D_MQTT_INVALID_TOPIC)); - return; - } - - // catch a dangling LWT from a previous connection if it appears - if(!strcmp_P(topic, PSTR(LWT_TOPIC))) { // endsWith LWT - if(!strcasecmp_P((char *)payload, PSTR("offline"))) { - { - char msg[8]; - char tmp_topic[strlen(mqttNodeTopic) + 8]; - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" LWT_TOPIC), mqttNodeTopic); - snprintf_P(msg, sizeof(msg), PSTR("online")); - - /*bool res =*/mqttClient.publish(tmp_topic, msg, true); - } - - } else { - // LOG_TRACE(TAG_MQTT, F("ignoring LWT = online")); - } - } else { - dispatch_topic_payload(topic, (const char *)payload); - } -} - -static void mqttSubscribeTo(const __FlashStringHelper * format, const char * data) -{ - char tmp_topic[strlen_P((PGM_P)format) + 2 + strlen(data)]; - snprintf_P(tmp_topic, sizeof(tmp_topic), (PGM_P)format, data); - if(mqttClient.subscribe(tmp_topic)) { - LOG_VERBOSE(TAG_MQTT, F(D_BULLET D_MQTT_SUBSCRIBED), tmp_topic); - } else { - LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_SUBSCRIBED), tmp_topic); - } -} - -void mqttStart() -{ - char buffer[64]; - char mqttClientId[64]; - char lastWillPayload[8]; - static uint8_t mqttReconnectCount = 0; - // bool mqttFirstConnect = true; - - mqttClient.setServer(mqttServer, 1883); - // mqttClient.setSocketTimeout(10); //in seconds - - /* Construct unique Client ID*/ - { - String mac = halGetMacAddress(3, ""); - mac.toLowerCase(); - memset(mqttClientId, 0, sizeof(mqttClientId)); - snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR(D_MQTT_DEFAULT_NAME), mac.c_str()); - LOG_INFO(TAG_MQTT, mqttClientId); - } - - // Attempt to connect and set LWT and Clean Session - snprintf_P(buffer, sizeof(buffer), PSTR("%s" LWT_TOPIC), mqttNodeTopic); // lastWillTopic - snprintf_P(lastWillPayload, sizeof(lastWillPayload), PSTR("offline")); // lastWillPayload - - haspProgressMsg(F(D_MQTT_CONNECTING)); - haspProgressVal(mqttReconnectCount * 5); - if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, true, lastWillPayload, true)) { - // Retry until we give up and restart after connectTimeout seconds - mqttReconnectCount++; - - switch(mqttClient.state()) { - case MQTT_CONNECTION_TIMEOUT: - LOG_WARNING(TAG_MQTT, F("Connection timeout")); - break; - case MQTT_CONNECTION_LOST: - LOG_WARNING(TAG_MQTT, F("Connection lost")); - break; - case MQTT_CONNECT_FAILED: - LOG_WARNING(TAG_MQTT, F("Connection failed")); - break; - case MQTT_DISCONNECTED: - snprintf_P(buffer, sizeof(buffer), PSTR(D_MQTT_DISCONNECTED)); - break; - case MQTT_CONNECTED: - break; - case MQTT_CONNECT_BAD_PROTOCOL: - LOG_WARNING(TAG_MQTT, F("MQTT version not suported")); - break; - case MQTT_CONNECT_BAD_CLIENT_ID: - LOG_WARNING(TAG_MQTT, F("Client ID rejected")); - break; - case MQTT_CONNECT_UNAVAILABLE: - LOG_WARNING(TAG_MQTT, F("Server unavailable")); - break; - case MQTT_CONNECT_BAD_CREDENTIALS: - LOG_WARNING(TAG_MQTT, F("Bad credentials")); - break; - case MQTT_CONNECT_UNAUTHORIZED: - LOG_WARNING(TAG_MQTT, F("Unauthorized")); - break; - default: - LOG_WARNING(TAG_MQTT, F("Unknown failure")); - } - - if(mqttReconnectCount > 20) { - LOG_ERROR(TAG_MQTT, F("Retry count exceeded, rebooting...")); - dispatch_reboot(false); - } - return; - } - - LOG_INFO(TAG_MQTT, F(D_MQTT_CONNECTED), mqttServer, mqttClientId); - - // Subscribe to our incoming topics - const __FlashStringHelper * F_topic; - F_topic = F("%scommand/#"); - mqttSubscribeTo(F_topic, mqttGroupTopic); - mqttSubscribeTo(F_topic, mqttNodeTopic); - F_topic = F("%sconfig/#"); - mqttSubscribeTo(F_topic, mqttGroupTopic); - mqttSubscribeTo(F_topic, mqttNodeTopic); - mqttSubscribeTo(F("%slight/#"), mqttNodeTopic); - mqttSubscribeTo(F("%sbrightness/#"), mqttNodeTopic); - // mqttSubscribeTo(F("%s"LWT_TOPIC), mqttNodeTopic); - mqttSubscribeTo(F("hass/status"), mqttClientId); - - /* Home Assistant auto-configuration */ - if(mqttHAautodiscover) mqttSubscribeTo(F("homeassistant/status"), mqttClientId); - - // Force any subscribed clients to toggle offline/online when we first connect to - // make sure we get a full panel refresh at power on. Sending offline, - // "online" will be sent by the mqttStatusTopic subscription action. - mqtt_send_lwt(true); - - // mqttFirstConnect = false; - mqttReconnectCount = 0; - - haspReconnect(); - haspProgressVal(255); - - dispatch_current_state(); -} - -void mqttSetup() -{ - mqttEnabled = strlen(mqttServer) > 0 && mqttPort > 0; - if(mqttEnabled) { - mqttClient.setServer(mqttServer, mqttPort); - mqttClient.setCallback(mqtt_message_cb); - // if(!mqttClient.setBufferSize(1024)) { - // LOG_ERROR(TAG_MQTT, F("Buffer allocation failed")); - // } else { - LOG_INFO(TAG_MQTT, F(D_MQTT_STARTED), mqttClient.getBufferSize()); - // } - } else { - LOG_WARNING(TAG_MQTT, F(D_MQTT_NOT_CONFIGURED)); - } -} - -void mqttLoop(void) -{ - if(mqttEnabled) mqttClient.loop(); -} - -void mqttEvery5Seconds(bool networkIsConnected) -{ - if(mqttEnabled && networkIsConnected && !mqttClient.connected()) { - LOG_TRACE(TAG_MQTT, F(D_MQTT_RECONNECTING)); - mqttStart(); - } -} - -String mqttGetNodename() -{ - return mqttNodeName; -} - -void mqttStop() -{ - if(mqttEnabled && mqttClient.connected()) { - LOG_TRACE(TAG_MQTT, F(D_MQTT_DISCONNECTING)); - mqtt_send_lwt(false); - mqttClient.disconnect(); - LOG_INFO(TAG_MQTT, F(D_MQTT_DISCONNECTED)); - } -} - - #if HASP_USE_CONFIG > 0 -bool mqttGetConfig(const JsonObject & settings) -{ - bool changed = false; - - if(strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)].as().c_str()) != 0) changed = true; - settings[FPSTR(FP_CONFIG_NAME)] = mqttNodeName; - - if(strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)].as().c_str()) != 0) changed = true; - settings[FPSTR(FP_CONFIG_GROUP)] = mqttGroupName; - - if(strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)].as().c_str()) != 0) changed = true; - settings[FPSTR(FP_CONFIG_HOST)] = mqttServer; - - if(mqttPort != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true; - settings[FPSTR(FP_CONFIG_PORT)] = mqttPort; - - if(strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true; - settings[FPSTR(FP_CONFIG_USER)] = mqttUser; - - if(strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true; - settings[FPSTR(FP_CONFIG_PASS)] = mqttPassword; - - if(changed) configOutput(settings, TAG_MQTT); - return changed; -} - -/** Set MQTT Configuration. - * - * Read the settings from json and sets the application variables. - * - * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. - * - * @param[in] settings JsonObject with the config settings. - **/ -bool mqttSetConfig(const JsonObject & settings) -{ - configOutput(settings, TAG_MQTT); - bool changed = false; - - changed |= configSet(mqttPort, settings[FPSTR(FP_CONFIG_PORT)], F("mqttPort")); - - if(!settings[FPSTR(FP_CONFIG_NAME)].isNull()) { - changed |= strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)]) != 0; - strncpy(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)], sizeof(mqttNodeName)); - } - // Prefill node name - if(strlen(mqttNodeName) == 0) { - String mac = halGetMacAddress(3, ""); - mac.toLowerCase(); - snprintf_P(mqttNodeName, sizeof(mqttNodeName), PSTR(D_MQTT_DEFAULT_NAME), mac.c_str()); - changed = true; - } - - if(!settings[FPSTR(FP_CONFIG_GROUP)].isNull()) { - changed |= strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)]) != 0; - strncpy(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)], sizeof(mqttGroupName)); - } - - if(strlen(mqttGroupName) == 0) { - strcpy_P(mqttGroupName, PSTR("plates")); - changed = true; - } - - if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) { - changed |= strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)]) != 0; - strncpy(mqttServer, settings[FPSTR(FP_CONFIG_HOST)], sizeof(mqttServer)); - } - - if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) { - changed |= strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)]) != 0; - strncpy(mqttUser, settings[FPSTR(FP_CONFIG_USER)], sizeof(mqttUser)); - } - - if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() && - settings[FPSTR(FP_CONFIG_PASS)].as() != String(FPSTR(D_PASSWORD_MASK))) { - changed |= strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)]) != 0; - strncpy(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)], sizeof(mqttPassword)); - } - - snprintf_P(mqttNodeTopic, sizeof(mqttNodeTopic), PSTR(MQTT_PREFIX "/%s/"), mqttNodeName); - snprintf_P(mqttGroupTopic, sizeof(mqttGroupTopic), PSTR(MQTT_PREFIX "/%s/"), mqttGroupName); - - return changed; -} - #endif // HASP_USE_CONFIG - -#endif // HASP_USE_MQTT diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index 5e1855a4..ddb4ae6c 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -4,24 +4,17 @@ #include "ArduinoJson.h" #include "hasp_conf.h" -#ifndef WINDOWS #if HASP_USE_MQTT > 0 -#include "PubSubClient.h" - #include "hasp/hasp.h" #include "hasp/hasp_dispatch.h" -#include "hal/hasp_hal.h" #include "dev/device.h" #include "hasp_mqtt.h" #include "hasp_mqtt_ha.h" #define RETAINED true -#define HASP_MAC_ADDRESS halGetMacAddress(0, "").c_str() -#define HASP_MAC_ADDRESS_STR halGetMacAddress(0, "") -extern PubSubClient mqttClient; // extern char mqttNodeName[16]; extern char mqttNodeTopic[24]; extern char mqttGroupTopic[24]; @@ -36,12 +29,41 @@ const char FP_MQTT_HA_NAME[] PROGMEM = "name"; const char FP_MQTT_HA_MODEL[] PROGMEM = "mdl"; const char FP_MQTT_HA_MANUFACTURER[] PROGMEM = "mf"; +#ifndef WINDOWS + +#include "hal/hasp_hal.h" + +#define HASP_MAC_ADDRESS halGetMacAddress(0, "").c_str() +#define HASP_MAC_ADDRESS_STR halGetMacAddress(0, "") + +// #include "PubSubClient.h" +// extern PubSubClient mqttClient; + +#else + +#define HASP_MAC_ADDRESS "aabbccddeeff" +#define HASP_MAC_ADDRESS_STR "aabbccddeeff" + +#endif + void mqtt_ha_send_json(char* topic, JsonDocument& doc) { LOG_VERBOSE(TAG_MQTT_PUB, topic); - mqttClient.beginPublish(topic, measureJson(doc), RETAINED); - serializeJson(doc, mqttClient); - mqttClient.endPublish(); + + // size_t n; + // LOG_VERBOSE(TAG_MQTT_PUB, " >>> measureJson & serializeJson start "); + // long start = millis(); + // mqttClient.beginPublish(topic, measureJson(doc), RETAINED); + // n = serializeJson(doc, mqttClient); + // mqttClient.endPublish(); + // LOG_VERBOSE(TAG_MQTT_PUB, " >>> measureJson & serializeJson done, %d bytes in %d millis\n", n, millis() - start); + + // LOG_VERBOSE(TAG_MQTT_PUB, " >>> serializeJson start "); + // start = millis(); + char buffer[800]; + size_t len = serializeJson(doc, buffer, sizeof(buffer)); + mqttPublish(topic, buffer, len, RETAINED); + // LOG_VERBOSE(TAG_MQTT_PUB, " >>> serializeJson done, %d bytes in %d millis\n", n, millis() - start); } // adds the device identifiers to the HA MQTT auto-discovery message @@ -77,7 +99,7 @@ void mqtt_ha_add_unique_id(JsonDocument& doc, char* item) void mqtt_ha_register_button(uint8_t page, uint8_t id) { - StaticJsonDocument<640> doc; + StaticJsonDocument<800> doc; mqtt_ha_add_device_ids(doc); char buffer[128]; @@ -119,7 +141,7 @@ void mqtt_ha_register_button(uint8_t page, uint8_t id) void mqtt_ha_register_switch(uint8_t page, uint8_t id) { - StaticJsonDocument<640> doc; + StaticJsonDocument<800> doc; mqtt_ha_add_device_ids(doc); char buffer[128]; @@ -140,7 +162,7 @@ void mqtt_ha_register_switch(uint8_t page, uint8_t id) void mqtt_ha_register_connectivity() { - StaticJsonDocument<640> doc; + StaticJsonDocument<1024> doc; char item[16]; snprintf_P(item, sizeof(item), PSTR("connectivity")); @@ -158,7 +180,7 @@ void mqtt_ha_register_connectivity() void mqtt_ha_register_backlight() { - StaticJsonDocument<640> doc; + StaticJsonDocument<800> doc; char item[16]; snprintf_P(item, sizeof(item), PSTR("backlight")); @@ -216,7 +238,7 @@ void mqtt_ha_register_moodlight() void mqtt_ha_register_idle() { - StaticJsonDocument<640> doc; + StaticJsonDocument<800> doc; char item[16]; snprintf_P(item, sizeof(item), PSTR("idle")); @@ -233,7 +255,7 @@ void mqtt_ha_register_idle() void mqtt_ha_register_activepage() { - StaticJsonDocument<640> doc; + StaticJsonDocument<800> doc; char item[16]; snprintf_P(item, sizeof(item), PSTR("page")); @@ -260,7 +282,6 @@ void mqtt_ha_register_auto_discovery() mqtt_ha_register_connectivity(); } #endif -#endif /* diff --git a/src/mqtt/hasp_mqtt_paho_async.cpp b/src/mqtt/hasp_mqtt_paho_async.cpp index af3aab4e..b0930d33 100644 --- a/src/mqtt/hasp_mqtt_paho_async.cpp +++ b/src/mqtt/hasp_mqtt_paho_async.cpp @@ -150,8 +150,8 @@ static void mqtt_message_cb(char* topic, char* payload, unsigned int length) } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { - // dispatch_current_state(); - // mqtt_ha_register_auto_discovery(); + dispatch_current_state(); + mqtt_ha_register_auto_discovery(); } return; diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index c4e86946..d355d641 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -34,7 +34,8 @@ #include "MQTTClient.h" -#include "hasp_mqtt.h" // functions to implement here +#include "hasp_mqtt.h" // functions to implement here +#include "hasp_mqtt_ha.h" // HA functions #include "hasp/hasp_dispatch.h" // for dispatch_topic_payload #include "hasp_debug.h" // for logging @@ -49,13 +50,13 @@ #include #endif -#define ADDRESS "10.4.0.5:1883" +#define ADDRESS "10.1.0.208:1883" #define CLIENTID "test1123" #define TOPIC "hasp/plate35/" #define QOS 1 #define TIMEOUT 1000L -const char* mqttNodeTopic = "hasp/plate35/"; +char mqttNodeTopic[24] = "hasp/plate35/"; const char* mqttGroupTopic = "hasp/plates/"; // char mqttNodeTopic[24]; // char mqttGroupTopic[24]; @@ -105,7 +106,7 @@ int disc_finished = 0; int subscribed = 0; int connected = 0; -static bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain); +bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain); /* ===== Paho event callbacks ===== */ @@ -144,8 +145,8 @@ static void mqtt_message_cb(char* topic, char* payload, unsigned int length) } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { - // dispatch_current_state(); - // mqtt_ha_register_auto_discovery(); + dispatch_current_state(); + mqtt_ha_register_auto_discovery(); } return; @@ -197,7 +198,8 @@ void mqtt_subscribe(void* context, const char* topic) MQTTClient client = (MQTTClient)context; int rc; - printf("Subscribing to topic %s\nfor client %s using QoS%d\n\n", topic, CLIENTID, QOS); + printf("Subscribing to topic %s\n", topic); + //\nfor client %s using QoS%d\n\n", topic, CLIENTID, QOS); if((rc = MQTTClient_subscribe(client, topic, QOS)) != MQTTCLIENT_SUCCESS) { printf("Failed to start subscribe, return code %d\n", rc); } @@ -266,9 +268,13 @@ static void onConnect(void* context) printf("Successful connection\n"); mqtt_subscribe(mqtt_client, TOPIC "command/#"); - mqtt_subscribe(mqtt_client, TOPIC "command"); - mqtt_subscribe(mqtt_client, TOPIC "light"); - mqtt_subscribe(mqtt_client, TOPIC "dim"); + // mqtt_subscribe(mqtt_client, TOPIC "command"); + mqtt_subscribe(mqtt_client, TOPIC "light/#"); + mqtt_subscribe(mqtt_client, TOPIC "brightness/#"); + mqtt_subscribe(mqtt_client, "hass/status"); + + /* Home Assistant auto-configuration */ + if(mqttHAautodiscover) mqtt_subscribe(mqtt_client, "homeassistant/status"); mqttPublish(TOPIC LWT_TOPIC, "online", 6, false); @@ -305,8 +311,8 @@ void mqttStart() conn_opts.keepAliveInterval = 20; conn_opts.cleansession = 1; - // conn_opts.username = ""; - // conn_opts.password = ""; + conn_opts.username = "hasp"; + conn_opts.password = "hasp"; if((rc = MQTTClient_connect(mqtt_client, &conn_opts)) != MQTTCLIENT_SUCCESS) { printf("Failed to start connect, return code %d\n", rc); diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index e96cb92d..f77db9ac 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -89,7 +89,7 @@ char mqttGroupName[16] = MQTT_GROUPNAME; uint16_t mqttPort = MQTT_PORT; PubSubClient mqttClient(mqttNetworkClient); -static bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain = false) +bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain) { if(mqttIsConnected()) { if(mqttClient.beginPublish(topic, len, retain)) { @@ -107,7 +107,7 @@ static bool mqttPublish(const char* topic, const char* payload, size_t len, bool return false; } -static bool mqttPublish(const char* topic, const char* payload, bool retain = false) +static bool mqttPublish(const char* topic, const char* payload, bool retain) { return mqttPublish(topic, payload, strlen(payload), retain); } @@ -136,14 +136,14 @@ void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 16]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/" HASP_OBJECT_NOTATION), mqttNodeTopic, pageid, btnid); - mqttPublish(tmp_topic, payload); + mqttPublish(tmp_topic, payload, false); } void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/%s"), mqttNodeTopic, subtopic); - mqttPublish(tmp_topic, payload); + mqttPublish(tmp_topic, payload, false); } //////////////////////////////////////////////////////////////////////////////////////////////////// From 748fe573346491c459617be3003010354189c759 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:48:41 +0100 Subject: [PATCH 064/236] Update device drivers --- src/dev/device.cpp | 3 +++ src/dev/device.h | 18 ++++++++++++++---- src/dev/esp32/esp32.cpp | 10 ++++++++++ src/dev/esp32/esp32.h | 1 + src/dev/esp32/lanbonl8.cpp | 3 +++ src/dev/esp32/m5stackcore2.cpp | 3 +++ src/dev/esp8266/esp8266.cpp | 16 +++++++++++++--- src/dev/esp8266/esp8266.h | 9 +++++---- src/dev/win32/hasp_win32.cpp | 33 +++++++++++++++++++++++++++++++-- src/dev/win32/hasp_win32.h | 17 ++++++++++++++++- 10 files changed, 99 insertions(+), 14 deletions(-) diff --git a/src/dev/device.cpp b/src/dev/device.cpp index ce356046..7bee8627 100644 --- a/src/dev/device.cpp +++ b/src/dev/device.cpp @@ -1,3 +1,6 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + #include "device.h" #if defined(LANBONL8) diff --git a/src/dev/device.h b/src/dev/device.h index ac2524a3..13989e04 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -39,6 +39,8 @@ class BaseDevice { virtual void init() {} + virtual void show_info() + {} virtual void post_setup() {} virtual void loop() @@ -60,13 +62,21 @@ class BaseDevice { return true; } virtual size_t get_free_max_block() - {} + { + return 0; + } virtual size_t get_free_heap() - {} + { + return 0; + } virtual uint8_t get_heap_fragmentation() - {} + { + return 0; + } virtual uint16_t get_cpu_frequency() - {} + { + return 0; + } }; } // namespace dev diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index f9ef5ff1..bde329ea 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -1,3 +1,6 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + #if defined(ESP32) #include "Arduino.h" @@ -23,6 +26,13 @@ void Esp32Device::reboot() ESP.restart(); } +void Esp32Device::show_info() +{ + LOG_VERBOSE(TAG_DEV, F("Processor : ESP32")); + LOG_VERBOSE(TAG_DEV, F("CPU freq. : %i MHz"), get_cpu_frequency()); + // LOG_VERBOSE(TAG_DEV, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined +} + const char* Esp32Device::get_hostname() { return _hostname.c_str(); diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index d7627047..5cdb4f90 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -21,6 +21,7 @@ class Esp32Device : public BaseDevice { _backlight_level = 100; } void reboot() override; + void show_info() override; const char* get_hostname(); void set_hostname(const char*); diff --git a/src/dev/esp32/lanbonl8.cpp b/src/dev/esp32/lanbonl8.cpp index e72c21c5..39b7a182 100644 --- a/src/dev/esp32/lanbonl8.cpp +++ b/src/dev/esp32/lanbonl8.cpp @@ -1,3 +1,6 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + #include "lanbonl8.h" #if defined(LANBONL8) diff --git a/src/dev/esp32/m5stackcore2.cpp b/src/dev/esp32/m5stackcore2.cpp index e86bb404..f4da47ab 100644 --- a/src/dev/esp32/m5stackcore2.cpp +++ b/src/dev/esp32/m5stackcore2.cpp @@ -1,3 +1,6 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + #include "m5stackcore2.h" #if defined(M5STACK) diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index 95a9c08a..a4ce90ad 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -1,3 +1,6 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + #if defined(ESP8266) #include "Arduino.h" @@ -17,6 +20,13 @@ void Esp8266Device::reboot() ESP.restart(); } +void Esp8266Device::show_info() +{ + LOG_VERBOSE(TAG_DEV, F("Processor : ESP8266")); + LOG_VERBOSE(TAG_DEV, F("CPU freq. : %i MHz"), get_cpu_frequency()); + LOG_VERBOSE(TAG_DEV, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined +} + const char* Esp8266Device::get_hostname() { return _hostname.c_str(); @@ -32,7 +42,7 @@ void Esp8266Device::set_backlight_pin(uint8_t pin) /* Setup Backlight Control Pin */ if(pin >= 0) { LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); - pinMode(backlight_pin, OUTPUT); + pinMode(_backlight_pin, OUTPUT); update_backlight(); } } @@ -40,7 +50,7 @@ void Esp8266Device::set_backlight_pin(uint8_t pin) void Esp8266Device::set_backlight_level(uint8_t level) { _backlight_level = level >= 0 ? level : 0; - _backlight_level = _backlight_level <= 100 ? backlight_level : 100; + _backlight_level = _backlight_level <= 100 ? _backlight_level : 100; update_backlight(); } @@ -65,7 +75,7 @@ void Esp8266Device::update_backlight() { if(_backlight_pin == -1) return; - analogWrite(backlight_pin, _backlight_power ? map(_backlight_level, 0, 100, 0, 1023) : 0); + analogWrite(_backlight_pin, _backlight_power ? map(_backlight_level, 0, 100, 0, 1023) : 0); } size_t Esp8266Device::get_free_max_block() diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 4ef5421c..05a02e1a 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -16,13 +16,14 @@ class Esp8266Device : public BaseDevice { public: Esp8266Device() { - hostname = "plate"; - backlight_pin = TFT_BCKL; - backlight_power = 1; - backlight_level = 100; + _hostname = "plate"; + _backlight_pin = TFT_BCKL; + _backlight_power = 1; + _backlight_level = 100; } void reboot() override; + void show_info() override; const char* get_hostname(); void set_hostname(const char*); diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index c75f36dc..dd2c8906 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -1,3 +1,6 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + #if defined(WINDOWS) #include @@ -6,16 +9,39 @@ #include "hasp_win32.h" #include "hasp_conf.h" -#include "hasp_debug.h" #include "hasp/hasp_utilities.h" +#include "hasp_debug.h" #include "display/monitor.h" namespace dev { +static inline void native_cpuid(unsigned int* eax, unsigned int* ebx, unsigned int* ecx, unsigned int* edx) +{ + /* ecx is often an input as well as an output. */ + asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "0"(*eax), "2"(*ecx) : "memory"); +} + void Win32Device::reboot() {} +void Win32Device::show_info() +{ + + unsigned int eax, ebx, ecx, edx; + eax = 0; + native_cpuid(&eax, &ebx, &ecx, &edx); + printf("EAX: %08X EBX: %08X ECX: %08X EDX: %08X\n", eax, ebx, ecx, edx); + char vendor[13]; + memcpy(vendor, &ebx, 4); + memcpy(vendor + 4, &edx, 4); + memcpy(vendor + 8, &ecx, 4); + vendor[12] = '\0'; + + LOG_VERBOSE(0, F("Processor : %s"), vendor); + LOG_VERBOSE(0, F("CPU freq. : %i MHz"), get_cpu_frequency()); +} + const char* Win32Device::get_hostname() { return _hostname.c_str(); @@ -77,7 +103,10 @@ size_t Win32Device::get_free_max_block() size_t Win32Device::get_free_heap(void) { - return 0; + MEMORYSTATUSEX status; + status.dwLength = sizeof(status); + GlobalMemoryStatusEx(&status); + return status.ullAvailPhys; } uint8_t Win32Device::get_heap_fragmentation() diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index 0788bd48..ae7015a0 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -20,13 +20,28 @@ class Win32Device : public BaseDevice { public: Win32Device() { - _hostname = "winplate"; + char buffer[MAX_COMPUTERNAME_LENGTH + 1]; + DWORD length = sizeof(buffer); + + if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNameNetBIOS, buffer, &length)) { + _hostname = buffer; + } else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNameDnsHostname, buffer, &length)) { + _hostname = buffer; + } else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNamePhysicalDnsHostname, buffer, &length)) { + _hostname = buffer; + } else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNamePhysicalDnsDomain, buffer, &length)) { + _hostname = buffer; + } else { + _hostname = "localhost"; + } + // _backlight_pin = -1; _backlight_power = 1; _backlight_level = 100; } void reboot() override; + void show_info() override; const char* get_hostname(); void set_hostname(const char*); From 8452cbaecdb7ad56d09621559876682ad264b26d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:50:26 +0100 Subject: [PATCH 065/236] Update display drivers --- src/drv/hasp_drv_display.cpp | 7 ++++-- src/drv/hasp_drv_touch.cpp | 7 ++++-- src/drv/tft_espi_drv.cpp | 27 ++++++++++---------- src/drv/tft_espi_drv.h | 48 +++++++++++++++++------------------- 4 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/drv/hasp_drv_display.cpp b/src/drv/hasp_drv_display.cpp index 54d96c6c..e9c18840 100644 --- a/src/drv/hasp_drv_display.cpp +++ b/src/drv/hasp_drv_display.cpp @@ -1,8 +1,11 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + #include "hasp_drv_display.h" #include "tft_espi_drv.h" //#include "fsmc_ili9341.h" -void drv_display_init(lv_disp_drv_t * disp_drv, uint8_t rotation, bool invert_display) +void drv_display_init(lv_disp_drv_t* disp_drv, uint8_t rotation, bool invert_display) { /* TFT init */ #if defined(USE_FSMC) @@ -18,7 +21,7 @@ void drv_display_init(lv_disp_drv_t * disp_drv, uint8_t rotation, bool invert_di /* Callback used for screenshots only: */ /* indirect callback to flush screenshot data to the screen */ -void drv_display_flush_cb(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) +void drv_display_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) { #if defined(USE_FSMC) fsmc_ili9341_flush(disp, area, color_p); diff --git a/src/drv/hasp_drv_touch.cpp b/src/drv/hasp_drv_touch.cpp index 28bafd31..f2ed5b33 100644 --- a/src/drv/hasp_drv_touch.cpp +++ b/src/drv/hasp_drv_touch.cpp @@ -1,3 +1,6 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + #include "hasp_drv_touch.h" #include "hasp/hasp.h" #include "lvgl.h" @@ -60,7 +63,7 @@ void drv_touch_init(uint8_t rotation) #endif } -static inline bool drv_touchpad_getXY(int16_t * touchX, int16_t * touchY) +static inline bool drv_touchpad_getXY(int16_t* touchX, int16_t* touchY) { bool touched; int16_t normal_x; @@ -151,7 +154,7 @@ bool touch_rotate = false; bool touch_invert_x = false; bool touch_invert_y = false; -bool drv_touch_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) +bool drv_touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) { #if TOUCH_DRIVER > 0 int16_t touchX = 0; diff --git a/src/drv/tft_espi_drv.cpp b/src/drv/tft_espi_drv.cpp index dc924ba0..3ce1fce7 100644 --- a/src/drv/tft_espi_drv.cpp +++ b/src/drv/tft_espi_drv.cpp @@ -1,7 +1,5 @@ -/** - * @file tft_espi_drv.cpp - * - */ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ /********************* * INCLUDES @@ -163,17 +161,18 @@ static void tftShowConfig(TFT_eSPI& tft) setup_t tftSetup; tft.getSetup(tftSetup); - LOG_VERBOSE(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str()); -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - LOG_VERBOSE(TAG_TFT, F("Processor : ESP%x"), tftSetup.esp); -#else - LOG_VERBOSE(TAG_TFT, F("Processor : STM%x"), tftSetup.esp); -#endif - LOG_VERBOSE(TAG_TFT, F("CPU freq. : %i MHz"), haspDevice.get_cpu_frequency()); + // LOG_VERBOSE(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str()); + // #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + // LOG_VERBOSE(TAG_TFT, F("Processor : ESP%x"), tftSetup.esp); + // #else + // LOG_VERBOSE(TAG_TFT, F("Processor : STM%x"), tftSetup.esp); + // #endif + // LOG_VERBOSE(TAG_TFT, F("CPU freq. : %i MHz"), haspDevice.get_cpu_frequency()); + + // #if defined(ARDUINO_ARCH_ESP8266) + // LOG_VERBOSE(TAG_TFT, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined + // #endif -#if defined(ARDUINO_ARCH_ESP8266) - LOG_VERBOSE(TAG_TFT, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined -#endif LOG_VERBOSE(TAG_TFT, F("Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); LOG_VERBOSE(TAG_TFT, F("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel")); #if defined(ARDUINO_ARCH_ESP8266) diff --git a/src/drv/tft_espi_drv.h b/src/drv/tft_espi_drv.h index 1bb0b4e2..c02607df 100644 --- a/src/drv/tft_espi_drv.h +++ b/src/drv/tft_espi_drv.h @@ -1,7 +1,5 @@ -/** - * @file tft_espi_drv.h - * - */ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ #ifndef TFT_ESPI_DRV_H #define TFT_ESPI_DRV_H @@ -14,20 +12,20 @@ extern "C" { * INCLUDES *********************/ #ifndef LV_DRV_NO_CONF - #ifdef LV_CONF_INCLUDE_SIMPLE - #include "lv_drv_conf.h" - #else - #include "../../lv_drv_conf.h" - #endif +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_drv_conf.h" +#else +#include "../../lv_drv_conf.h" +#endif #endif #if USE_TFT_ESPI - #ifdef LV_LVGL_H_INCLUDE_SIMPLE - #include "lvgl.h" - #else - #include "lvgl/lvgl.h" - #endif +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include "lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif /********************* * DEFINES @@ -40,21 +38,21 @@ extern "C" { /********************** * GLOBAL PROTOTYPES **********************/ -void tft_espi_init(uint8_t rotation, bool invert_display=false); -void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p); +void tft_espi_init(uint8_t rotation, bool invert_display = false); +void tft_espi_flush(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); // void tft_espi_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); void tft_espi_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); -void tft_espi_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); +void tft_espi_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t* color_p); - #if defined(TOUCH_CS) -void tft_espi_calibrate(uint16_t * calData); -void tft_espi_set_touch(uint16_t * calData); -bool tft_espi_get_touch(int16_t * touchX, int16_t * touchY, uint16_t threshold); - #endif +#if defined(TOUCH_CS) +void tft_espi_calibrate(uint16_t* calData); +void tft_espi_set_touch(uint16_t* calData); +bool tft_espi_get_touch(int16_t* touchX, int16_t* touchY, uint16_t threshold); +#endif - /********************** - * MACROS - **********************/ +/********************** + * MACROS + **********************/ #endif /* USE_TFT_ESPI */ From 9dca1e0891f32e1440c652f040db117108a44900 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:51:19 +0100 Subject: [PATCH 066/236] Harmonize setup routines --- src/main_arduino.cpp | 16 ++++++++-------- src/main_windows.cpp | 9 +++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 65272907..41920295 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -61,6 +61,13 @@ void setup() guiSetup(); debugSetup(); // Init the console +#if HASP_USE_CONFIG > 0 + if(!oobeSetup()) +#endif + { + haspSetup(); + } + #if HASP_USE_GPIO > 0 gpioSetup(); #endif @@ -77,13 +84,6 @@ void setup() networkSetup(); #endif -#if HASP_USE_CONFIG > 0 - if(!oobeSetup()) -#endif - { - haspSetup(); - } - #if HASP_USE_MDNS > 0 mdnsSetup(); #endif @@ -106,7 +106,7 @@ void setup() mainLastLoopTime = millis() - 1000; // reset loop counter delay(250); - guiStart(); + // guiStart(); } void loop() diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 7e4c6e4e..8e409690 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -100,14 +100,14 @@ void setup() // debug_init(); // Initialize lvgl environment - lv_init(); lv_log_register_print_cb(debugLvglLogEvent); + lv_init(); haspDevice.init(); - hal_setup(); + // hal_setup(); + dispatchSetup(); guiSetup(); - dispatchSetup(); // debugSetup(); // Init the console printf("%s %d\n", __FILE__, __LINE__); @@ -194,6 +194,8 @@ int main(int argc, char* argv[]) InitializeConsoleOutput(); + haspDevice.show_info(); + char hostbuffer[256]; char* IPbuffer; struct hostent* host_entry; @@ -264,7 +266,6 @@ int main(int argc, char* argv[]) // printf("%s %d\n", __FILE__, __LINE__); // fflush(stdout); setup(); - monitor_title(haspDevice.get_hostname()); while(isRunning) { loop(); From d28805903582204af6a54f1e2fac41c2dc90acdd Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:51:48 +0100 Subject: [PATCH 067/236] Move dispatchLoop --- src/hasp/hasp.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 319852b2..3437ff04 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -272,7 +272,7 @@ void haspProgressVal(uint8_t val) } lv_bar_set_value(bar, val, LV_ANIM_OFF); } - lv_task_handler(); /* let the GUI do its work */ + // lv_task_handler(); /* let the GUI do its work */ } } @@ -287,14 +287,14 @@ void haspProgressMsg(const char* msg) hasp_process_obj_attribute(bar, value_str, msg, true); } - lv_task_handler(); /* let the GUI do its work */ + // lv_task_handler(); /* let the GUI do its work */ /* if(bar) { progress_str.reserve(64); progress_str = msg; lv_obj_set_style_local_value_str(bar, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, progress_str.c_str()); - lv_task_handler(); // let the GUI do its work + // lv_task_handler(); // let the GUI do its work } */ } @@ -478,7 +478,9 @@ void haspSetup(void) **********************/ void haspLoop(void) -{} +{ + dispatchLoop(); +} /* void hasp_background(uint16_t pageid, uint16_t imageid) From 0c695f6c8a5a1b098554add0bd6b4c27ca71a594 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:52:21 +0100 Subject: [PATCH 068/236] Add TAG_DEV --- src/hasp_debug.h | 71 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 3cc1794a..22bd138f 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -22,23 +22,46 @@ void debugStart(void); void debugStop(void); /* ===== Special Event Processors ===== */ -void debugLvglLogEvent(lv_log_level_t level, const char *file, uint32_t line, const char *funcname, - const char *descr); -void debugPrintHaspHeader(Print *output); +void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr); +void debugPrintHaspHeader(Print* output); void debugStartSyslog(void); void debugStopSyslog(void); // void syslogSend(uint8_t log, const char * debugText); #else #include -#define LOG_FATAL(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) -#define LOG_ERROR(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) -#define LOG_WARNING(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) -#define LOG_NOTICE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) -#define LOG_TRACE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) -#define LOG_VERBOSE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) -#define LOG_DEBUG(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) -#define LOG_INFO(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_FATAL(x, ...) \ + printf(__VA_ARGS__); \ + std::cout << std::endl; \ + fflush(stdout) +#define LOG_ERROR(x, ...) \ + printf(__VA_ARGS__); \ + std::cout << std::endl; \ + fflush(stdout) +#define LOG_WARNING(x, ...) \ + printf(__VA_ARGS__); \ + std::cout << std::endl; \ + fflush(stdout) +#define LOG_NOTICE(x, ...) \ + printf(__VA_ARGS__); \ + std::cout << std::endl; \ + fflush(stdout) +#define LOG_TRACE(x, ...) \ + printf(__VA_ARGS__); \ + std::cout << std::endl; \ + fflush(stdout) +#define LOG_VERBOSE(x, ...) \ + printf(__VA_ARGS__); \ + std::cout << std::endl; \ + fflush(stdout) +#define LOG_DEBUG(x, ...) \ + printf(__VA_ARGS__); \ + std::cout << std::endl; \ + fflush(stdout) +#define LOG_INFO(x, ...) \ + printf(__VA_ARGS__); \ + std::cout << std::endl; \ + fflush(stdout) /* json keys used in the configfile */ // const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage"; @@ -84,23 +107,23 @@ void debugStopSyslog(void); /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 -bool debugGetConfig(const JsonObject &settings); -bool debugSetConfig(const JsonObject &settings); +bool debugGetConfig(const JsonObject& settings); +bool debugSetConfig(const JsonObject& settings); #endif // void debugPrintPrefix(int level, Print * _logOutput); // void debugPrintSuffix(int level, Print * _logOutput); // void debugSendOuput(const char * buffer); -enum -{ +enum { TAG_MAIN = 0, TAG_HASP = 1, TAG_ATTR = 2, TAG_MSGR = 3, TAG_OOBE = 4, - TAG_HAL = 5, + TAG_HAL = 5, TAG_DRVR = 6, + TAG_DEV = 7, TAG_DEBG = 10, TAG_TELN = 11, @@ -108,8 +131,8 @@ enum TAG_TASM = 13, TAG_CONF = 20, - TAG_GUI = 21, - TAG_TFT = 22, + TAG_GUI = 21, + TAG_TFT = 22, TAG_EPRM = 30, TAG_FILE = 31, @@ -117,12 +140,12 @@ enum TAG_FWUP = 50, - TAG_ETH = 60, - TAG_WIFI = 61, - TAG_HTTP = 62, - TAG_OTA = 63, - TAG_MDNS = 64, - TAG_MQTT = 65, + TAG_ETH = 60, + TAG_WIFI = 61, + TAG_HTTP = 62, + TAG_OTA = 63, + TAG_MDNS = 64, + TAG_MQTT = 65, TAG_MQTT_PUB = 66, TAG_MQTT_RCV = 67, From ae4ee0f5348b551e0705377738a11c83ebdf84fb Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:58:49 +0100 Subject: [PATCH 069/236] Change TFT_eSPI.h --- src/drv/tft_driver_tftespi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drv/tft_driver_tftespi.h b/src/drv/tft_driver_tftespi.h index d6e46793..83ae4097 100644 --- a/src/drv/tft_driver_tftespi.h +++ b/src/drv/tft_driver_tftespi.h @@ -9,7 +9,7 @@ #endif #include "lvgl.h" -#include "tft_espi.h" +#include "TFT_eSPI.h" #include "tft_driver.h" #include "hal/hasp_hal.h" From 91026864fdd839bd75d0e66a97da48276cb14c31 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 22 Feb 2021 00:51:58 +0100 Subject: [PATCH 070/236] Add missing member methods --- src/dev/esp8266/esp8266.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index a4ce90ad..e21ca697 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -10,6 +10,7 @@ #include "hasp_conf.h" #include "hasp_debug.h" +#include "hasp/hasp_utilities.h" #define BACKLIGHT_CHANNEL 0 @@ -36,6 +37,16 @@ void Esp8266Device::set_hostname(const char* hostname) _hostname = hostname; } +const char* Esp8266Device::get_core_version() +{ + return ESP.getCoreVersion().c_str(); +} + +const char* Esp8266Device::get_display_driver() +{ + return Utilities::tft_driver_name().c_str(); +} + void Esp8266Device::set_backlight_pin(uint8_t pin) { _backlight_pin = pin; From e17404358f57105603ec47d5996c06479a4c2bc1 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 22 Feb 2021 01:57:34 +0100 Subject: [PATCH 071/236] Code cleanup --- src/hasp_gui.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/hasp_gui.h b/src/hasp_gui.h index ccaccf76..46722dae 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -28,12 +28,6 @@ void guiCalibrate(void); void guiTakeScreenshot(const char* pFileName); // to file void guiTakeScreenshot(void); // webclient -/* ===== Getter and Setter Functions ===== */ -// void guiSetDim(int8_t level); -// int8_t guiGetDim(); -// void guiSetBacklight(bool lighton); -// bool guiGetBacklight(); - /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 bool guiGetConfig(const JsonObject& settings); From 0df9d188c1e459569e1e8bfea116985511c4696f Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 22 Feb 2021 22:44:35 +0100 Subject: [PATCH 072/236] Fix AP webserver not saving --- src/sys/svc/hasp_http.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 878654d8..14c1e1d6 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1937,19 +1937,24 @@ void httpSetup() webServer.onNotFound(httpHandleNotFound); #if HASP_USE_WIFI > 0 + + // These two endpoints are needed in STA and AP mode + webServer.on(F("/"), webHandleWifiConfig); + webServer.on(F("/config"), webHandleWifiConfig); + #if !defined(STM32F4xx) #if HASP_USE_CONFIG > 0 if(WiFi.getMode() != WIFI_STA) { LOG_TRACE(TAG_HTTP, F("Wifi access point")); - webServer.on(F("/"), webHandleWifiConfig); return; } -#endif -#endif -#endif +#endif // HASP_USE_CONFIG +#endif // !STM32F4xx +#endif // HASP_USE_WIFI + // The following endpoints are only needed in STA mode webServer.on(F("/page/"), []() { String pageid = webServer.arg(F("page")); webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'"); @@ -1979,7 +1984,6 @@ void httpSetup() handleFileUpload); #endif - webServer.on(F("/"), webHandleRoot); webServer.on(F("/info"), webHandleInfo); webServer.on(F("/screenshot"), webHandleScreenshot); webServer.on(F("/firmware"), webHandleFirmware); @@ -2002,7 +2006,6 @@ void httpSetup() #endif webServer.on(F("/saveConfig"), webHandleSaveConfig); webServer.on(F("/resetConfig"), httpHandleResetConfig); - webServer.on(F("/config"), webHandleConfig); #endif // HASP_USE_CONFIG #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) From 81b30d830305f90aedbcc7d49a0fa656724a0285 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:04:45 +0100 Subject: [PATCH 073/236] Update env:my_custom_build --- platformio_override-template.ini | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/platformio_override-template.ini b/platformio_override-template.ini index cd14bc2a..a0dcdf65 100644 --- a/platformio_override-template.ini +++ b/platformio_override-template.ini @@ -67,22 +67,29 @@ upload_port = ${env:lolind32pro-lolintft24.monitor_port} ;region -- Custom Environment configuration example ----------------- [env:my_custom_build] -platform = espressif32 +extends = esp32 board = nodemcu-32s -monitor_port = COM3 -upload_port = ${env:my_custom_build.monitor_port} + +upload_port = COM12 ; To change the port, use platform_override.ini +monitor_port = COM12 ; To change the port, use platform_override.ini + +board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv ; default.csv + debug_tool = esp-prog debug_init_break = tbreak setup build_flags = + ${env.build_flags} ${esp32.build_flags} ;region -- TFT_eSPI build options ----------------------------------- - ${lcd.raspberrypi} + ${lcd.lolin24} ${esp32.vspi} - -D TFT_CS=5 - -D TFT_DC=4 - -D TFT_RST=32 - -D TFT_BCKL=-1 ; None, configurable via web UI (e.g. 21) - -D TOUCH_CS=22 + -D TFT_DC=5 + -D TFT_CS=26 + -D TFT_RST=-1 ; RST + -D TFT_BCKL=22 ; None, configurable via web UI (e.g. 21) + -D TOUCH_CS=17 ; (can also be 22 or 16) +; -- Options ---------------------------------------- + -D HASP_USE_TELNET=1 ;endregion ;endregion \ No newline at end of file From 05901395d1d9b24365306d4a57940d1b1496832a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:12:46 +0100 Subject: [PATCH 074/236] Fix AP mode soes not start webServer --- src/sys/net/hasp_wifi.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sys/net/hasp_wifi.cpp b/src/sys/net/hasp_wifi.cpp index 24380503..0e6c40e5 100644 --- a/src/sys/net/hasp_wifi.cpp +++ b/src/sys/net/hasp_wifi.cpp @@ -345,6 +345,7 @@ bool wifiShowAP(char* ssid, char* pass) LOG_WARNING(TAG_WIFI, F("Temporary Access Point %s password: %s"), ssid, pass); LOG_WARNING(TAG_WIFI, F("AP IP address : %s"), WiFi.softAPIP().toString().c_str()); + networkStart(); // httpReconnect();} #endif return true; @@ -352,14 +353,18 @@ bool wifiShowAP(char* ssid, char* pass) static void wifiReconnect(void) { - WiFi.disconnect(true); #if defined(ARDUINO_ARCH_ESP8266) + WiFi.disconnect(true); + WiFi.begin(wifiSsid, wifiPassword); WiFi.hostname(haspDevice.get_hostname()); + #elif defined(ARDUINO_ARCH_ESP32) + // https://github.com/espressif/arduino-esp32/issues/3438#issuecomment-721428310 + WiFi.disconnect(true); + WiFi.begin(wifiSsid, wifiPassword); WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.setHostname(haspDevice.get_hostname()); #endif - WiFi.begin(wifiSsid, wifiPassword); } /* ============ Setup, Loop, Start, Stop =================================================== */ From a1f818f83c5df0abdf0466843331820ad1bf355f Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 00:04:44 +0100 Subject: [PATCH 075/236] Set correct webHandleConfig callback --- src/svc/hasp_http.cpp | 2121 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2121 insertions(+) create mode 100644 src/svc/hasp_http.cpp diff --git a/src/svc/hasp_http.cpp b/src/svc/hasp_http.cpp new file mode 100644 index 00000000..11b66f44 --- /dev/null +++ b/src/svc/hasp_http.cpp @@ -0,0 +1,2121 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +//#include "webServer.h" +#include "ArduinoJson.h" +#include "ArduinoLog.h" +#include "lvgl.h" + +#if defined(ARDUINO_ARCH_ESP32) +#include "Update.h" +#endif + +#include "hasp_conf.h" + +#include "hasp_gui.h" +#include "hasp_hal.h" +#include "hasp_debug.h" +#include "hasp_config.h" + +#include "hasp/hasp_utilities.h" +#include "hasp/hasp_dispatch.h" +#include "hasp/hasp.h" + +#if HASP_USE_HTTP > 0 + +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +File fsUploadFile; +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////// +bool webServerStarted = false; + +// bool httpEnable = true; +// uint16_t httpPort = 80; +// char httpUser[32] = ""; +// char httpPassword[32] = ""; +hasp_http_config_t http_config; + +#define HTTP_PAGE_SIZE (6 * 256) + +#if defined(STM32F4xx) && HASP_USE_ETHERNET > 0 +#include +EthernetWebServer webServer(80); +#endif + +#if defined(STM32F4xx) && HASP_USE_WIFI > 0 +#include +// #include +EthernetWebServer webServer(80); +#endif + +#if defined(ARDUINO_ARCH_ESP8266) +#include "StringStream.h" +#include +#include +ESP8266WebServer webServer(80); +#endif + +#if defined(ARDUINO_ARCH_ESP32) +#include +#include +WebServer webServer(80); +#endif // ESP32 + +HTTPUpload* upload; + +static const char HTTP_MENU_BUTTON[] PROGMEM = + "

"; + +const char MAIN_MENU_BUTTON[] PROGMEM = + "

"; +const char MIT_LICENSE[] PROGMEM = "
MIT License

"; + +const char HTTP_DOCTYPE[] PROGMEM = + ""; +const char HTTP_META_GO_BACK[] PROGMEM = ""; +const char HTTP_HEADER[] PROGMEM = "%s"; +const char HTTP_STYLE[] PROGMEM = + ""; +const char HTTP_SCRIPT[] PROGMEM = ""; +const char HTTP_HEADER_END[] PROGMEM = + "
"; +const char HTTP_END[] PROGMEM = ""; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +// URL for auto-update "version.json" +// const char UPDATE_URL[] PROGMEM = "http://haswitchplate.com/update/version.json"; +// // Default link to compiled Arduino firmware image +// String espFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.ino.d1_mini.bin"; +// // Default link to compiled Nextion firmware images +// String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft"; + +#if HASP_USE_MQTT > 0 +extern char mqttNodeName[16]; +#else +char mqttNodeName[3] = "na"; +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////// +String getOption(int value, String label, bool selected) +{ + char buffer[128]; + snprintf_P(buffer, sizeof(buffer), PSTR(""), value, + (selected ? PSTR(" selected") : ""), label.c_str()); + return buffer; +} + +String getOption(String value, String label, bool selected) +{ + char buffer[128]; + snprintf_P(buffer, sizeof(buffer), PSTR(""), value.c_str(), + (selected ? PSTR(" selected") : ""), label.c_str()); + return buffer; +} + +static void add_gpio_select_option(String& str, uint8_t gpio, uint8_t bcklpin) +{ + char buffer[10]; + snprintf_P(buffer, sizeof(buffer), PSTR("GPIO %d"), gpio); + str += getOption(gpio, buffer, bcklpin == gpio); +} + +static void add_button(String& str, const __FlashStringHelper* label, const __FlashStringHelper* extra) +{ + str += F(""); +} + +static void close_form(String& str) +{ + str += F("

"); +} + +static void add_form_button(String& str, const __FlashStringHelper* label, const __FlashStringHelper* action, + const __FlashStringHelper* extra) +{ + str += F("

"); + add_button(str, label, extra); + close_form(str); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleHaspConfig(); + +static inline char* httpGetNodename() +{ + return mqttNodeName; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +bool httpIsAuthenticated(const __FlashStringHelper* fstr_page) +{ + if(http_config.password[0] != '\0') { // Request HTTP auth if httpPassword is set + if(!webServer.authenticate(http_config.user, http_config.password)) { + webServer.requestAuthentication(); + return false; + } + } + +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + LOG_TRACE(TAG_HTTP, F("Sending %S page to client connected from: %s"), fstr_page, + webServer.client().remoteIP().toString().c_str()); +#else + // LOG_INFO(TAG_HTTP,F("Sending %s page to client connected from: %s"), page, + // String(webServer.client().remoteIP()).c_str()); +#endif + + return true; +} + +void webSendFooter() +{ + char buffer[16]; + haspGetVersion(buffer, sizeof(buffer)); + +#if defined(STM32F4xx) + webServer.sendContent(HTTP_END); + webServer.sendContent(buffer); + webServer.sendContent(HTTP_FOOTER); +#else + webServer.sendContent_P(HTTP_END); + webServer.sendContent(buffer); + webServer.sendContent_P(HTTP_FOOTER); +#endif +} + +void webSendPage(char* nodename, uint32_t httpdatalength, bool gohome = false) +{ + { + char buffer[64]; + haspGetVersion(buffer, sizeof(buffer)); + + /* Calculate Content Length upfront */ + uint16_t contentLength = strlen(buffer); // verion length + contentLength += sizeof(HTTP_DOCTYPE) - 1; + contentLength += sizeof(HTTP_HEADER) - 1 - 2 + strlen(nodename); // -2 for %s + contentLength += sizeof(HTTP_SCRIPT) - 1; + contentLength += sizeof(HTTP_STYLE) - 1; + // contentLength += sizeof(HASP_STYLE) - 1; + if(gohome) contentLength += sizeof(HTTP_META_GO_BACK) - 1; + contentLength += sizeof(HTTP_HEADER_END) - 1; + contentLength += sizeof(HTTP_END) - 1; + contentLength += sizeof(HTTP_FOOTER) - 1; + + if(httpdatalength > HTTP_PAGE_SIZE) { + LOG_WARNING(TAG_HTTP, F("Sending page with %u static and %u dynamic bytes"), contentLength, httpdatalength); + } + + webServer.setContentLength(contentLength + httpdatalength); +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122 +#else + webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122 +#endif + + snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename); + webServer.sendContent(buffer); // 17-2+len + } + +#if defined(STM32F4xx) + webServer.sendContent(HTTP_SCRIPT); // 131 + webServer.sendContent(HTTP_STYLE); // 487 + // webServer.sendContent(HASP_STYLE); // 145 + if(gohome) webServer.sendContent(HTTP_META_GO_BACK); // 47 + webServer.sendContent(HTTP_HEADER_END); // 80 +#else + webServer.sendContent_P(HTTP_SCRIPT); // 131 + webServer.sendContent_P(HTTP_STYLE); // 487 + // webServer.sendContent_P(HASP_STYLE); // 145 + if(gohome) webServer.sendContent_P(HTTP_META_GO_BACK); // 47 + webServer.sendContent_P(HTTP_HEADER_END); // 80 +#endif +} + +void saveConfig() +{ + if(webServer.method() == HTTP_POST) { + if(webServer.hasArg(PSTR("save"))) { + String save = webServer.arg(PSTR("save")); + + StaticJsonDocument<256> settings; + for(int i = 0; i < webServer.args(); i++) settings[webServer.argName(i)] = webServer.arg(i); + + if(save == String(PSTR("hasp"))) { + haspSetConfig(settings.as()); + +#if HASP_USE_MQTT > 0 + } else if(save == String(PSTR("mqtt"))) { + mqttSetConfig(settings.as()); +#endif + + } else if(save == String(PSTR("gui"))) { + settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cur")); + settings[FPSTR(FP_GUI_INVERT)] = webServer.hasArg(PSTR("inv")); + guiSetConfig(settings.as()); + + } else if(save == String(PSTR("debug"))) { + debugSetConfig(settings.as()); + + } else if(save == String(PSTR("http"))) { + httpSetConfig(settings.as()); + + // Password might have changed + if(!httpIsAuthenticated(F("config"))) return; + +#if HASP_USE_WIFI > 0 + } else if(save == String(PSTR("wifi"))) { + wifiSetConfig(settings.as()); +#endif + } + } + } +} + +void webHandleRoot() +{ + if(!httpIsAuthenticated(F("root"))) return; + + saveConfig(); + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("

"); + + httpMessage += F("

"); + httpMessage += + F("

"); + add_form_button(httpMessage, F(D_HTTP_CONFIGURATION), F("/config"), F("")); + // httpMessage += F("

"); + + httpMessage += F("

"); + +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + if(HASP_FS.exists(F("/edit.htm.gz"))) { + httpMessage += + F("

"); + } +#endif + + httpMessage += F("

"); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void httpHandleReboot() +{ // http://plate01/reboot + if(!httpIsAuthenticated(F("reboot"))) return; + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + httpMessage = F(D_DISPATCH_REBOOT); + + webSendPage(httpGetNodename(), httpMessage.length(), true); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); + + delay(200); + dispatch_reboot(true); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleScreenshot() +{ // http://plate01/screenshot + if(!httpIsAuthenticated(F("screenshot"))) return; + + if(webServer.hasArg(F("a"))) { + if(webServer.arg(F("a")) == F("next")) { + dispatch_page_next(); + } else if(webServer.arg(F("a")) == F("prev")) { + dispatch_page_prev(); + } + } + + if(webServer.hasArg(F("q"))) { + lv_disp_t* disp = lv_disp_get_default(); + webServer.setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t)); + webServer.send_P(200, PSTR("image/bmp"), ""); + guiTakeScreenshot(); + webServer.client().stop(); + + } else { + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += + F(""); + httpMessage += F("

"); + + httpMessage += F("

"); + httpMessage += + F("

"); + httpMessage += + F("

"); + httpMessage += FPSTR(MAIN_MENU_BUTTON); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +void webHandleAbout() +{ // http://plate01/about + if(!httpIsAuthenticated(F("about"))) return; + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + + httpMessage += F("

HASP OpenHardware edition

Copyright© 2020 Francis Van Roie "); + httpMessage += FPSTR(MIT_LICENSE); + httpMessage += F("

Based on the previous work of the following open source developers.


"); + httpMessage += F("

HASwitchPlate

Copyright© 2019 Allen Derusha allen@derusha.org"); + httpMessage += FPSTR(MIT_LICENSE); + httpMessage += + F("

LittlevGL

Copyright© 2016 Gábor Kiss-Vámosi
Copyright© 2019 " + "LittlevGL"); + httpMessage += FPSTR(MIT_LICENSE); + httpMessage += F("

zi Font Engine

Copyright© 2020 Francis Van Roie"); + httpMessage += FPSTR(MIT_LICENSE); + httpMessage += F("

TFT_eSPI Library

Copyright© 2020 Bodmer (https://github.com/Bodmer) All " + "rights reserved.
FreeBSD License

"); + httpMessage += + F("

includes parts from the Adafruit_GFX library
Copyright© 2012 Adafruit Industries. " + "All rights reserved
BSD License

"); + httpMessage += F("

ArduinoJson

Copyright© 2014-2020 Benoit BLANCHON"); + httpMessage += FPSTR(MIT_LICENSE); + httpMessage += F("

PubSubClient

Copyright© 2008-2015 Nicholas O'Leary"); + httpMessage += FPSTR(MIT_LICENSE); + httpMessage += + F("

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, " + "dhylands, Josha blemasle, mfalkvidd"); + httpMessage += FPSTR(MIT_LICENSE); +#if HASP_USE_SYSLOG > 0 + // Replaced with WiFiUDP client + // httpMessage += F("

Syslog

Copyright© 2016 Martin Sloup"); + // httpMessage += FPSTR(MIT_LICENSE); +#endif +#if HASP_USE_QRCODE > 0 + httpMessage += F("

QR Code generator

Copyright© Project Nayuki"); + httpMessage += FPSTR(MIT_LICENSE); +#endif + httpMessage += F("

AceButton

Copyright© 2018 Brian T. Park"); + httpMessage += FPSTR(MIT_LICENSE); + + httpMessage += FPSTR(MAIN_MENU_BUTTON); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleInfo() +{ // http://plate01/ + if(!httpIsAuthenticated(F("info"))) return; + + { + char size_buf[32]; + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + /* HASP Stats */ + httpMessage += F("HASP Version: "); + { + char version[32]; + haspGetVersion(version, sizeof(version)); + httpMessage += version; + } + httpMessage += F("
Build DateTime: "); + httpMessage += __DATE__; + httpMessage += F(" "); + httpMessage += __TIME__; + httpMessage += F(" CET
Uptime: "); + + unsigned long time = millis() / 1000; + uint16_t day = time / 86400; + time = time % 86400; + uint8_t hour = time / 3600; + time = time % 3600; + uint8_t min = time / 60; + time = time % 60; + uint8_t sec = time; + + if(day > 0) { + httpMessage += String(day); + httpMessage += F("d "); + } + if(day > 0 || hour > 0) { + httpMessage += String(hour); + httpMessage += F("h "); + } + if(day > 0 || hour > 0 || min > 0) { + httpMessage += String(min); + httpMessage += F("m "); + } + httpMessage += String(sec); + httpMessage += F("s"); + + httpMessage += F("
Free Memory: "); + hasp_util_format_bytes(halGetFreeHeap(), size_buf, sizeof(size_buf)); + httpMessage += size_buf; + httpMessage += F("
Memory Fragmentation: "); + httpMessage += String(halGetHeapFragmentation()); + +#if ARDUINO_ARCH_ESP32 + if(psramFound()) { + httpMessage += F("
Free PSRam: "); + hasp_util_format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf)); + httpMessage += size_buf; + httpMessage += F("
PSRam Size: "); + hasp_util_format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf)); + httpMessage += size_buf; + } +#endif + + /* LVGL Stats */ + lv_mem_monitor_t mem_mon; + lv_mem_monitor(&mem_mon); + httpMessage += F("

LVGL Memory: "); + hasp_util_format_bytes(mem_mon.total_size, size_buf, sizeof(size_buf)); + httpMessage += size_buf; + httpMessage += F("
LVGL Free: "); + hasp_util_format_bytes(mem_mon.free_size, size_buf, sizeof(size_buf)); + httpMessage += size_buf; + httpMessage += F("
LVGL Fragmentation: "); + httpMessage += mem_mon.frag_pct; + + // httpMessage += F("
LCD Model: ")) + String(LV_HASP_HOR_RES_MAX) + " x " + + // String(LV_HASP_VER_RES_MAX); httpMessage += F("
LCD Version: ")) + + // String(lcdVersion); + httpMessage += F("

LCD Active Page: "); + httpMessage += String(haspGetPage()); + + /* Wifi Stats */ +#if HASP_USE_WIFI > 0 + httpMessage += F("

SSID: "); + httpMessage += String(WiFi.SSID()); + httpMessage += F("
Signal Strength: "); + + int8_t rssi = WiFi.RSSI(); + httpMessage += String(rssi); + httpMessage += F("dBm ("); + + if(rssi >= -50) { + httpMessage += F("Excellent)"); + } else if(rssi >= -60) { + httpMessage += F("Good)"); + } else if(rssi >= -70) { + httpMessage += F("Fair)"); + } else if(rssi >= -80) { + httpMessage += F("Weak)"); + } else { + httpMessage += F("Very Bad)"); + } +#if defined(STM32F4xx) + byte mac[6]; + WiFi.macAddress(mac); + char macAddress[16]; + snprintf_P(macAddress, sizeof(macAddress), PSTR("%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], + mac[5]); + httpMessage += F("
IP Address: "); + httpMessage += String(WiFi.localIP()); + httpMessage += F("
Gateway: "); + httpMessage += String(WiFi.gatewayIP()); + httpMessage += F("
MAC Address: "); + httpMessage += String(macAddress); +#else + httpMessage += F("
IP Address: "); + httpMessage += String(WiFi.localIP().toString()); + httpMessage += F("
Gateway: "); + httpMessage += String(WiFi.gatewayIP().toString()); + httpMessage += F("
DNS Server: "); + httpMessage += String(WiFi.dnsIP().toString()); + httpMessage += F("
MAC Address: "); + httpMessage += String(WiFi.macAddress()); +#endif +#endif +#if HASP_USE_ETHERNET > 0 +#if defined(ARDUINO_ARCH_ESP32) + httpMessage += F("

Ethernet: "); + httpMessage += String(ETH.linkSpeed()); + httpMessage += F(" Mbps"); + if(ETH.fullDuplex()) { + httpMessage += F(" FULL_DUPLEX"); + } + httpMessage += F("
IP Address: "); + httpMessage += String(ETH.localIP().toString()); + httpMessage += F("
Gateway: "); + httpMessage += String(ETH.gatewayIP().toString()); + httpMessage += F("
DNS Server: "); + httpMessage += String(ETH.dnsIP().toString()); + httpMessage += F("
MAC Address: "); + httpMessage += String(ETH.macAddress()); +#endif +#endif +/* Mqtt Stats */ +#if HASP_USE_MQTT > 0 + httpMessage += F("

MQTT Status: "); + if(mqttIsConnected()) { // Check MQTT connection + httpMessage += F("Connected"); + } else { + httpMessage += F("Disconnected, return code: "); + // +String(mqttClient.returnCode()); + } + httpMessage += F("
MQTT ClientID: "); + + { + char mqttClientId[64]; + String mac = halGetMacAddress(3, ""); + mac.toLowerCase(); + snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%s"), mqttNodeName, mac.c_str()); + httpMessage += mqttClientId; + } + +#endif // MQTT + + /* ESP Stats */ + httpMessage += F("

MCU Model: "); + httpMessage += halGetChipModel(); + httpMessage += F("
CPU Frequency: "); + httpMessage += String(halGetCpuFreqMHz()); + httpMessage += F("MHz"); + +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + httpMessage += F("
Flash Chip Size: "); + hasp_util_format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf)); + httpMessage += size_buf; + + httpMessage += F("
Program Size: "); + hasp_util_format_bytes(ESP.getSketchSize(), size_buf, sizeof(size_buf)); + httpMessage += size_buf; + + httpMessage += F("
Free Program Space: "); + hasp_util_format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf)); + httpMessage += size_buf; +#endif + + //#if defined(ARDUINO_ARCH_ESP32) + // httpMessage += F("
ESP SDK version: "); + // httpMessage += String(ESP.getSdkVersion()); + //#else + httpMessage += F("
Core version: "); + httpMessage += String(halGetCoreVersion()); + //#endif + httpMessage += F("
Last Reset: "); + httpMessage += halGetResetInfo(); + + httpMessage += FPSTR(MAIN_MENU_BUTTON); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} + +// String getContentType(String filename) +// { +// if(webServer.hasArg(F("download"))) { +// return F("application/octet-stream"); +// } else if(filename.endsWith(F(".htm")) || filename.endsWith(F(".html"))) { +// return F("text/html"); +// } else if(filename.endsWith(F(".css"))) { +// return F("text/css"); +// } else if(filename.endsWith(F(".js"))) { +// return F("application/javascript"); +// } else if(filename.endsWith(F(".png"))) { +// return F("image/png"); +// } else if(filename.endsWith(F(".gif"))) { +// return F("image/gif"); +// } else if(filename.endsWith(F(".jpg"))) { +// return F("image/jpeg"); +// } else if(filename.endsWith(F(".ico"))) { +// return F("image/x-icon"); +// } else if(filename.endsWith(F(".xml"))) { +// return F("text/xml"); +// } else if(filename.endsWith(F(".pdf"))) { +// return F("application/x-pdf"); +// } else if(filename.endsWith(F(".zip"))) { +// return F("application/x-zip"); +// } else if(filename.endsWith(F(".gz"))) { +// return F("application/x-gzip"); +// } +// return F("text/plain"); +// } + +static String getContentType(const String& path) +{ + char buff[sizeof(mime::mimeTable[0].mimeType)]; + // Check all entries but last one for match, return if found + for(size_t i = 0; i < sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1; i++) { + strcpy_P(buff, mime::mimeTable[i].endsWith); + if(path.endsWith(buff)) { + strcpy_P(buff, mime::mimeTable[i].mimeType); + return String(buff); + } + } + // Fall-through and just return default type + strcpy_P(buff, mime::mimeTable[sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1].mimeType); + return String(buff); +} + +/* String urldecode(String str) +{ + String encodedString = ""; + char c; + for(unsigned int i = 0; i < str.length(); i++) { + c = str.charAt(i); + if(c == '+') { + encodedString += ' '; + } else if(c == '%') { + // char buffer[3]; + char buffer[128]; + i++; + buffer[0] = str.charAt(i); + i++; + buffer[1] = str.charAt(i); + buffer[2] = '\0'; + c = (char)strtol((const char *)&buffer, NULL, 16); + encodedString += c; + } else { + encodedString += c; + } + yield(); + } + return encodedString; +} */ + +static unsigned long htppLastLoopTime = 0; +void webUploadProgress() +{ + long t = webServer.header("Content-Length").toInt(); + if(millis() - htppLastLoopTime >= 1250) { + LOG_VERBOSE(TAG_HTTP, F(D_BULLET "Uploaded %u / %d bytes"), upload->totalSize + upload->currentSize, t); + htppLastLoopTime = millis(); + } + if(t > 0) t = (upload->totalSize + upload->currentSize) * 100 / t; + haspProgressVal(t); +} + +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) +static inline void webUpdatePrintError() +{ +#if defined(ARDUINO_ARCH_ESP8266) + String output((char*)0); + output.reserve(128); + StringStream stream((String&)output); + Update.printError(stream); // ESP8266 only has printError() + LOG_ERROR(TAG_HTTP, output.c_str()); + haspProgressMsg(output.c_str()); +#elif defined(ARDUINO_ARCH_ESP32) + LOG_ERROR(TAG_HTTP, Update.errorString()); // ESP32 has errorString() + haspProgressMsg(Update.errorString()); +#endif +} + +void webUpdateReboot() +{ + LOG_INFO(TAG_HTTP, F("Update Success: %u bytes received. Rebooting..."), upload->totalSize); + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + httpMessage += F("Upload complete. Rebooting device, please wait..."); + + webSendPage(httpGetNodename(), httpMessage.length(), true); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); + + delay(250); + dispatch_reboot(true); // Save the current config +} + +void webHandleFirmwareUpload() +{ + upload = &webServer.upload(); + + if(upload->status == UPLOAD_FILE_START) { + if(!httpIsAuthenticated(F("update"))) return; + LOG_TRACE(TAG_HTTP, F("Update: %s"), upload->filename.c_str()); + haspProgressMsg(upload->filename.c_str()); + // WiFiUDP::stopAll(); + uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; + // if(!Update.begin(UPDATE_SIZE_UNKNOWN)) { // start with max available size + if(!Update.begin(maxSketchSpace)) { // start with max available size + webUpdatePrintError(); + } + + } else if(upload->status == UPLOAD_FILE_WRITE) { + // flashing firmware to ESP + if(Update.write(upload->buf, upload->currentSize) != upload->currentSize) { + webUpdatePrintError(); + } else { + webUploadProgress(); + } + + } else if(upload->status == UPLOAD_FILE_END) { + haspProgressVal(100); + if(Update.end(true)) { // true to set the size to the current progress + haspProgressMsg(F(D_OTA_UPDATE_APPLY)); + webUpdateReboot(); + } else { + webUpdatePrintError(); + } + } +} +#endif + +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +bool handleFileRead(String path) +{ + if(!httpIsAuthenticated(F("fileread"))) return false; + + path = webServer.urlDecode(path).substring(0, 31); + if(path.endsWith("/")) { + path += F("index.htm"); + } + String pathWithGz = path + F(".gz"); + if(HASP_FS.exists(pathWithGz) || HASP_FS.exists(path)) { + if(HASP_FS.exists(pathWithGz)) path += F(".gz"); + + File file = HASP_FS.open(path, "r"); + String contentType = getContentType(path); + if(path == F("/edit.htm.gz")) { + contentType = F("text/html"); + } + webServer.streamFile(file, contentType); + file.close(); + return true; + } + return false; +} + +void handleFileUpload() +{ + if(webServer.uri() != "/edit") { + return; + } + upload = &webServer.upload(); + if(upload->status == UPLOAD_FILE_START) { + if(!httpIsAuthenticated(F("fileupload"))) return; + LOG_INFO(TAG_HTTP, F("Total size: %s"), webServer.headerName(0).c_str()); + String filename((char*)0); + filename.reserve(128); + filename = upload->filename; + if(!filename.startsWith("/")) { + filename = "/"; + filename += upload->filename; + } + if(filename.length() < 32) { + fsUploadFile = HASP_FS.open(filename, "w"); + LOG_TRACE(TAG_HTTP, F("handleFileUpload Name: %s"), filename.c_str()); + haspProgressMsg(fsUploadFile.name()); + } else { + LOG_ERROR(TAG_HTTP, F("Filename %s is too long"), filename.c_str()); + } + } else if(upload->status == UPLOAD_FILE_WRITE) { + // DBG_OUTPUT_PORT.print("handleFileUpload Data: "); debugPrintln(upload.currentSize); + if(fsUploadFile) { + if(fsUploadFile.write(upload->buf, upload->currentSize) != upload->currentSize) { + LOG_ERROR(TAG_HTTP, F("Failed to write received data to file")); + } else { + webUploadProgress(); // Moved to httpEverySecond Loop + } + } + } else if(upload->status == UPLOAD_FILE_END) { + if(fsUploadFile) { + LOG_INFO(TAG_HTTP, F("Uploaded %s (%u bytes)"), fsUploadFile.name(), upload->totalSize); + fsUploadFile.close(); + } + haspProgressVal(255); + + // Redirect to /config/hasp page. This flushes the web buffer and frees the memory + webServer.sendHeader(String(F("Location")), String(F("/config/hasp")), true); + webServer.send_P(302, PSTR("text/plain"), ""); + // httpReconnect(); + } +} + +void handleFileDelete() +{ + if(!httpIsAuthenticated(F("filedelete"))) return; + + char mimetype[16]; + snprintf_P(mimetype, sizeof(mimetype), PSTR("text/plain")); + + if(webServer.args() == 0) { + return webServer.send_P(500, mimetype, PSTR("BAD ARGS")); + } + String path = webServer.arg(0); + LOG_TRACE(TAG_HTTP, F("handleFileDelete: %s"), path.c_str()); + if(path == "/") { + return webServer.send_P(500, mimetype, PSTR("BAD PATH")); + } + if(!HASP_FS.exists(path)) { + return webServer.send_P(404, mimetype, PSTR("FileNotFound")); + } + HASP_FS.remove(path); + webServer.send_P(200, mimetype, PSTR("")); + // path.clear(); +} + +void handleFileCreate() +{ + if(!httpIsAuthenticated(F("filecreate"))) return; + + if(webServer.args() == 0) { + return webServer.send(500, PSTR("text/plain"), PSTR("BAD ARGS")); + } + String path = webServer.arg(0); + LOG_TRACE(TAG_HTTP, F("handleFileCreate: %s"), path.c_str()); + if(path == "/") { + return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH")); + } + if(HASP_FS.exists(path)) { + return webServer.send(500, PSTR("text/plain"), PSTR("FILE EXISTS")); + } + File file = HASP_FS.open(path, "w"); + if(file) { + file.close(); + } else { + return webServer.send(500, PSTR("text/plain"), PSTR("CREATE FAILED")); + } + webServer.send(200, PSTR("text/plain"), ""); + path.clear(); +} + +void handleFileList() +{ + if(!httpIsAuthenticated(F("filelist"))) return; + + if(!webServer.hasArg(F("dir"))) { + webServer.send(500, PSTR("text/plain"), PSTR("BAD ARGS")); + return; + } + + String path = webServer.arg(F("dir")); + LOG_TRACE(TAG_HTTP, F("handleFileList: %s"), path.c_str()); + path.clear(); + +#if defined(ARDUINO_ARCH_ESP32) + File root = HASP_FS.open("/", FILE_READ); + File file = root.openNextFile(); + String output = "["; + + while(file) { + if(output != "[") { + output += ','; + } + bool isDir = false; + output += F("{\"type\":\""); + output += (isDir) ? F("dir") : F("file"); + output += F("\",\"name\":\""); + if(file.name()[0] == '/') { + output += &(file.name()[1]); + } else { + output += file.name(); + } + output += F("\"}"); + + // file.close(); + file = root.openNextFile(); + } + output += "]"; + webServer.send(200, PSTR("text/json"), output); +#elif defined(ARDUINO_ARCH_ESP8266) + Dir dir = HASP_FS.openDir(path); + String output = "["; + while(dir.next()) { + File entry = dir.openFile("r"); + if(output != "[") { + output += ','; + } + bool isDir = false; + output += F("{\"type\":\""); + output += (isDir) ? F("dir") : F("file"); + output += F("\",\"name\":\""); + if(entry.name()[0] == '/') { + output += &(entry.name()[1]); + } else { + output += entry.name(); + } + output += F("\"}"); + entry.close(); + } + output += "]"; + webServer.send(200, PSTR("text/json"), output); +#endif +} +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_CONFIG > 0 +void webHandleConfig() +{ // http://plate01/config + if(!httpIsAuthenticated(F("config"))) return; + + saveConfig(); + +// Reboot after saving wifi config in AP mode +#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) + if(WiFi.getMode() != WIFI_STA) { + httpHandleReboot(); + } +#endif + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + +#if HASP_USE_WIFI > 0 + httpMessage += F("

"); +#endif + +#if HASP_USE_MQTT > 0 + httpMessage += F("

"); +#endif + + httpMessage += F("

"); + + httpMessage += F("

"); + + // httpMessage += + // F("

"); + +#if HASP_USE_GPIO > 0 + httpMessage += F("

"); +#endif + + httpMessage += F("

"); + + httpMessage += + F("

"); + + httpMessage += FPSTR(MAIN_MENU_BUTTON); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_MQTT > 0 +void webHandleMqttConfig() +{ // http://plate01/config/mqtt + if(!httpIsAuthenticated(F("config/mqtt"))) return; + + StaticJsonDocument<256> settings; + mqttGetConfig(settings.to()); + + { + // char buffer[128]; + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("
"); + httpMessage += F("HASP Node Name (required. lowercase letters, numbers, and _ only)" + "

Group Name (required)

MQTT Broker (required)
MQTT Port (required)
MQTT User (optional)
MQTT Password (optional)

"); + + add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); + // httpMessage += PSTR("

"); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleGuiConfig() +{ // http://plate01/config/wifi + if(!httpIsAuthenticated(F("config/gui"))) return; + + { + StaticJsonDocument<256> settings; + guiGetConfig(settings.to()); + + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("
"); + + httpMessage += F("

Short Idle

"); + + httpMessage += F("

Long Idle

"); + + int8_t rotation = settings[FPSTR(FP_GUI_ROTATION)].as(); + httpMessage += F("

Orientation

"); + + httpMessage += F("

()) httpMessage += F(" checked"); + httpMessage += F(">Invert Colors"); + + httpMessage += F("

()) httpMessage += F(" checked"); + httpMessage += F(">Show Pointer"); + + int8_t bcklpin = settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as(); + httpMessage += F("

Backlight Control

"); + + add_button(httpMessage, F(D_HTTP_SAVE_SETTINGS), F("name='save' value='gui'")); + close_form(httpMessage); + // httpMessage += + // F("

"); + +#if TOUCH_DRIVER == 2046 && defined(TOUCH_CS) + add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='action' value='calibrate'")); + +// httpMessage += PSTR("

"); +#endif + + add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); + + // httpMessage += PSTR("

"); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + webSendFooter(); + + if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_WIFI > 0 +void webHandleWifiConfig() +{ // http://plate01/config/wifi + if(!httpIsAuthenticated(F("config/wifi"))) return; + + StaticJsonDocument<256> settings; + wifiGetConfig(settings.to()); + + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("
"); + httpMessage += F("WiFi SSID (required)
WiFi Password (required)

"); + +#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) + if(WiFi.getMode() == WIFI_STA) { + add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); + // httpMessage += PSTR("

"); + } +#endif + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); +#if defined(STM32F4xx) + httpMessage = ""; +#else + httpMessage.clear(); +#endif + webSendFooter(); +} +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_HTTP > 0 +void webHandleHttpConfig() +{ // http://plate01/config/http + if(!httpIsAuthenticated(F("config/http"))) return; + + { + StaticJsonDocument<256> settings; + httpGetConfig(settings.to()); + + // String httpMessage((char *)0); + // httpMessage.reserve(HTTP_PAGE_SIZE); + // httpMessage += F("

"); + // httpMessage += httpGetNodename(); + // httpMessage += F("


"); + + // httpMessage += F("
"); + // httpMessage += F("Web Username (optional)
Web Password (optional)

"); + + // httpMessage += PSTR("

"); + + char httpMessage[HTTP_PAGE_SIZE]; + + size_t len = snprintf_P( + httpMessage, sizeof(httpMessage), + PSTR("

%s


" + "
" + "Web Username (optional)" + "
" + "Web Password (optional)" + "" + "

" + "

"), + httpGetNodename(), settings[FPSTR(FP_CONFIG_USER)].as().c_str(), + settings[FPSTR(FP_CONFIG_PASS)].as().c_str()); + + // if(settings[FPSTR(FP_CONFIG_PASS)].as() != "") { + // httpMessage += F(D_PASSWORD_MASK); + // } + + webSendPage(httpGetNodename(), len, false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) +void webHandleGpioConfig() +{ // http://plate01/config/gpio + if(!httpIsAuthenticated(F("config/gpio"))) return; + uint8_t configCount = 0; + + // StaticJsonDocument<256> settings; + // gpioGetConfig(settings.to()); + + if(webServer.hasArg(PSTR("save"))) { + uint8_t id = webServer.arg(F("id")).toInt(); + uint8_t pin = webServer.arg(F("pin")).toInt(); + uint8_t type = webServer.arg(F("type")).toInt() + webServer.arg(F("state")).toInt(); + uint8_t group = webServer.arg(F("group")).toInt(); + uint8_t pinfunc = webServer.arg(F("func")).toInt(); + gpioSavePinConfig(id, pin, type, group, pinfunc); + } + if(webServer.hasArg(PSTR("del"))) { + uint8_t id = webServer.arg(F("id")).toInt(); + uint8_t pin = webServer.arg(F("pin")).toInt(); + gpioSavePinConfig(id, pin, HASP_GPIO_FREE, 0, 0); + } + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("
"); + + httpMessage += F(""); + + for(uint8_t gpio = 0; gpio < NUM_DIGITAL_PINS; gpio++) { + for(uint8_t id = 0; id < HASP_NUM_GPIO_CONFIG; id++) { + hasp_gpio_config_t conf = gpioGetPinConfig(id); + if((conf.pin == gpio) && gpioConfigInUse(id) && gpioInUse(gpio) && !gpioIsSystemPin(gpio)) { + httpMessage += F(""); + configCount++; + } + } + } + + httpMessage += F("
PinTypeGroupDefaultAction
"); + httpMessage += halGpioName(gpio); + httpMessage += F(""); + + switch(conf.type & 0xfe) { + case HASP_GPIO_SWITCH: + // case HASP_GPIO_SWITCH_INVERTED: + httpMessage += F("Switch"); + break; + case HASP_GPIO_BUTTON: + // case HASP_GPIO_BUTTON_INVERTED: + httpMessage += F("Button"); + break; + case HASP_GPIO_LED: + // case HASP_GPIO_LED_INVERTED: + httpMessage += F("Led"); + break; + case HASP_GPIO_LED_R: + case HASP_GPIO_LED_G: + case HASP_GPIO_LED_B: + // case HASP_GPIO_LED_INVERTED: + httpMessage += F("Mood "); + break; + case HASP_GPIO_RELAY: + // case HASP_GPIO_RELAY_INVERTED: + httpMessage += F("Relay"); + break; + case HASP_GPIO_PWM: + // case HASP_GPIO_PWM_INVERTED: + httpMessage += F("PWM"); + break; + default: + httpMessage += F("Unknown"); + } + + switch(conf.type & 0xfe) { + case HASP_GPIO_LED_R: + httpMessage += F("Red"); + break; + case HASP_GPIO_LED_G: + httpMessage += F("Green"); + break; + case HASP_GPIO_LED_B: + httpMessage += F("Blue"); + break; + } + + httpMessage += F(""); + httpMessage += conf.group; + httpMessage += F(""); + + // bool inverted = (conf.type == HASP_GPIO_BUTTON_INVERTED) || + // (conf.type == HASP_GPIO_SWITCH_INVERTED) || (conf.type == HASP_GPIO_LED_INVERTED) + // || (conf.type == HASP_GPIO_RELAY_INVERTED) || (conf.type == + // HASP_GPIO_PWM_INVERTED); + + httpMessage += (conf.type & 0x1) ? F("High") : F("Low"); + + httpMessage += F("Edit Delete
"); + + if(configCount < HASP_NUM_GPIO_CONFIG) { + httpMessage += F("

"); + httpMessage += F("

"); + } + + add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); + // httpMessage += F("

"); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleGpioOptions() +{ // http://plate01/config/gpio/options + if(!httpIsAuthenticated(F("config/gpio/options"))) return; + + { + StaticJsonDocument<256> settings; + guiGetConfig(settings.to()); + + uint8_t config_id = webServer.arg(F("id")).toInt(); + + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("
"); + httpMessage += F(""); + + httpMessage += F("

GPIO Options"); + httpMessage += config_id; + httpMessage += F(" Options

"); + + httpMessage += F("

Pin

"); + + bool selected; + httpMessage += F("

Type

"); + + httpMessage += F("

Group

"); + + httpMessage += F("

Default State

"); + + httpMessage += + F("

"); + + httpMessage += PSTR("

"); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + webSendFooter(); + + if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check +} +#endif // HASP_USE_GPIO + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleDebugConfig() +{ // http://plate01/config/debug + if(!httpIsAuthenticated(F("config/debug"))) return; + + StaticJsonDocument<256> settings; + debugGetConfig(settings.to()); + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("
"); + + uint16_t baudrate = settings[FPSTR(FP_CONFIG_BAUD)].as(); + httpMessage += F("

Serial Port

Telemetry Period (Seconds, 0=disable) " + "

"); + +#if HASP_USE_SYSLOG > 0 + httpMessage += F("Syslog Hostame (optional)
Syslog Port (optional) Syslog Facility
Syslog Protocol () == 0) httpMessage += F(" checked"); + httpMessage += F(">IETF (RFC 5424)   () == 1) httpMessage += F(" checked"); + httpMessage += F(">BSD (RFC 3164)"); +#endif + + httpMessage += + F("

"); + + add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); + // httpMessage += PSTR("

"); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleHaspConfig() +{ // http://plate01/config/http + if(!httpIsAuthenticated(F("config/hasp"))) return; + + StaticJsonDocument<256> settings; + haspGetConfig(settings.to()); + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("

"); + httpMessage += F("


"); + + // httpMessage += F("
"); + httpMessage += F(""); + httpMessage += F("

UI Theme (required)
"); + httpMessage += + F("Hue

"); + httpMessage += F("

Default Font

"); + + httpMessage += F("

Startup Layout (optional)
Startup Page (required)

Startup Brightness (required)

"); + + httpMessage += + F("

"); + + // httpMessage += + // F("

"); + httpMessage += FPSTR(MAIN_MENU_BUTTON); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} +#endif // HASP_USE_CONFIG + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void httpHandleNotFound() +{ // webServer 404 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + if(handleFileRead(webServer.uri())) return; +#endif + +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + LOG_TRACE(TAG_HTTP, F("Sending 404 to client connected from: %s"), + webServer.client().remoteIP().toString().c_str()); +#else + // LOG_TRACE(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); +#endif + + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + + httpMessage += F("File Not Found\n\nURI: "); + httpMessage += webServer.uri(); + httpMessage += F("\nMethod: "); + httpMessage += (webServer.method() == HTTP_GET) ? F("GET") : F("POST"); + httpMessage += F("\nArguments: "); + httpMessage += webServer.args(); + httpMessage += "\n"; + for(int i = 0; i < webServer.args(); i++) { + httpMessage += " " + webServer.argName(i) + ": " + webServer.arg(i) + "\n"; + } + webServer.send(404, PSTR("text/plain"), httpMessage.c_str()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleFirmware() +{ + if(!httpIsAuthenticated(F("firmware"))) return; + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("

"); + httpMessage += F("

"); + + // httpMessage += F("

"); + // httpMessage += F("

"); + + httpMessage += FPSTR(MAIN_MENU_BUTTON); + + webSendPage(httpGetNodename(), httpMessage.length(), false); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void httpHandleEspFirmware() +{ // http://plate01/espfirmware + if(!httpIsAuthenticated(F("espfirmware"))) return; + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + httpMessage += F("

ESP update

Updating ESP firmware from: "); + httpMessage += webServer.arg("espFirmware"); + + webSendPage(httpGetNodename(), httpMessage.length(), true); + webServer.sendContent(httpMessage); + // httpMessage.clear(); + } + webSendFooter(); + + LOG_TRACE(TAG_HTTP, F("Attempting ESP firmware update from: %s"), webServer.arg("espFirmware").c_str()); + // espStartOta(webServer.arg("espFirmware")); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_CONFIG > 0 +void webHandleSaveConfig() +{ + if(!httpIsAuthenticated(F("saveConfig"))) return; + + configWriteConfig(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void httpHandleResetConfig() +{ // http://plate01/resetConfig + if(!httpIsAuthenticated(F("resetConfig"))) return; + + bool resetConfirmed = webServer.arg(F("confirm")) == F("yes"); + + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += httpGetNodename(); + httpMessage += F("


"); + + if(resetConfirmed) { // User has confirmed, so reset everything + bool formatted = configClearEeprom(); + if(formatted) { + httpMessage += F("Resetting all saved settings and restarting device"); + } else { + httpMessage += F("Failed to format the internal flash partition"); + resetConfirmed = false; + } + } else { + httpMessage += + F("

Warning

This process will reset all settings to the default values. The internal flash " + "will " + "be erased and the device is restarted. You may need to connect to the WiFi AP displayed on the " + "panel to " + "re-configure the device before accessing it again. ALL FILES WILL BE LOST!" + "


" + "

" + "


"); + + add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); + // httpMessage += + // PSTR("

"); + } + + webSendPage(httpGetNodename(), httpMessage.length(), resetConfirmed); + webServer.sendContent(httpMessage); + } + // httpMessage.clear(); + webSendFooter(); + + if(resetConfirmed) { + delay(250); + // configClearSaved(); + dispatch_reboot(false); // Do not save the current config + } +} +#endif // HASP_USE_CONFIG + +void httpStart() +{ + webServer.begin(); + webServerStarted = true; +#if HASP_USE_WIFI > 0 +#if defined(STM32F4xx) + IPAddress ip; + ip = WiFi.localIP(); + LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); +#else + LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"), + (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); +#endif +#else + IPAddress ip; +#if defined(ARDUINO_ARCH_ESP32) + ip = ETH.localIP(); +#else + ip = Ethernet.localIP(); +#endif + LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); +#endif +} + +void httpStop() +{ + webServer.stop(); + webServerStarted = false; + LOG_WARNING(TAG_HTTP, F(D_SERVICE_STOPPED)); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void httpSetup() +{ + // httpSetConfig(settings); + + // ask server to track these headers + const char* headerkeys[] = {"Content-Length"}; // "Authentication" + size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); + webServer.collectHeaders(headerkeys, headerkeyssize); + + // Shared pages + webServer.on(F("/about"), webHandleAbout); + webServer.onNotFound(httpHandleNotFound); + +#if HASP_USE_WIFI > 0 +#if !defined(STM32F4xx) + +#if HASP_USE_CONFIG > 0 + if(WiFi.getMode() != WIFI_STA) { + LOG_TRACE(TAG_HTTP, F("Wifi access point")); + webServer.on(F("/"), webHandleWifiConfig); + webServer.on(F("/config"), webHandleConfig); + return; + } + +#endif +#endif +#endif + + webServer.on(F("/page/"), []() { + String pageid = webServer.arg(F("page")); + webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'"); + haspSetPage(pageid.toInt()); + }); + +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + webServer.on(F("/list"), HTTP_GET, handleFileList); + // load editor + webServer.on(F("/edit"), HTTP_GET, []() { + if(!handleFileRead("/edit.htm")) { + char mimetype[16]; + snprintf_P(mimetype, sizeof(mimetype), PSTR("text/plain")); + webServer.send_P(404, mimetype, PSTR("FileNotFound")); + } + }); + webServer.on(F("/edit"), HTTP_PUT, handleFileCreate); + webServer.on(F("/edit"), HTTP_DELETE, handleFileDelete); + // first callback is called after the request has ended with all parsed arguments + // second callback handles file uploads at that location + webServer.on( + F("/edit"), HTTP_POST, + []() { + webServer.send(200, "text/plain", ""); + LOG_VERBOSE(TAG_HTTP, F("Headers: %d"), webServer.headers()); + }, + handleFileUpload); +#endif + + webServer.on(F("/"), webHandleRoot); + webServer.on(F("/info"), webHandleInfo); + webServer.on(F("/screenshot"), webHandleScreenshot); + webServer.on(F("/firmware"), webHandleFirmware); + webServer.on(F("/reboot"), httpHandleReboot); + +#if HASP_USE_CONFIG > 0 + webServer.on(F("/config/hasp"), webHandleHaspConfig); + webServer.on(F("/config/http"), webHandleHttpConfig); + webServer.on(F("/config/gui"), webHandleGuiConfig); + webServer.on(F("/config/debug"), webHandleDebugConfig); +#if HASP_USE_MQTT > 0 + webServer.on(F("/config/mqtt"), webHandleMqttConfig); +#endif +#if HASP_USE_WIFI > 0 + webServer.on(F("/config/wifi"), webHandleWifiConfig); +#endif +#if HASP_USE_GPIO > 0 + webServer.on(F("/config/gpio"), webHandleGpioConfig); + webServer.on(F("/config/gpio/options"), webHandleGpioOptions); +#endif + webServer.on(F("/saveConfig"), webHandleSaveConfig); + webServer.on(F("/resetConfig"), httpHandleResetConfig); + webServer.on(F("/config"), webHandleConfig); +#endif // HASP_USE_CONFIG + +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + webServer.on( + F("/update"), HTTP_POST, + []() { + webServer.send(200, "text/plain", ""); + LOG_VERBOSE(TAG_HTTP, F("Total size: %s"), webServer.hostHeader().c_str()); + }, + webHandleFirmwareUpload); + webServer.on(F("/espfirmware"), httpHandleEspFirmware); +#endif + + LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED)); + // webStart(); Wait for network connection +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void httpReconnect() +{ + if(!http_config.enable) return; + + if(webServerStarted) { + httpStop(); + } else +#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) + if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA) +#endif + { + httpStart(); + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void httpLoop(void) +{ + if(http_config.enable) webServer.handleClient(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void httpEvery5Seconds() +{ + // if(httpEnable && !webServerStarted) httpReconnect(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +#if HASP_USE_CONFIG > 0 +bool httpGetConfig(const JsonObject& settings) +{ + bool changed = false; + + settings[FPSTR(FP_CONFIG_ENABLE)] = http_config.enable; + + if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true; + settings[FPSTR(FP_CONFIG_PORT)] = http_config.port; + + if(strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true; + settings[FPSTR(FP_CONFIG_USER)] = http_config.user; + + if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true; + settings[FPSTR(FP_CONFIG_PASS)] = http_config.password; + + if(changed) configOutput(settings, TAG_HTTP); + return changed; +} + +/** Set HTTP Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ +bool httpSetConfig(const JsonObject& settings) +{ + configOutput(settings, TAG_HTTP); + bool changed = false; + + changed |= configSet(http_config.port, settings[FPSTR(FP_CONFIG_PORT)], F("httpPort")); + + if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) { + changed |= strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)]) != 0; + strncpy(http_config.user, settings[FPSTR(FP_CONFIG_USER)], sizeof(http_config.user)); + } + + if(!settings[FPSTR(FP_CONFIG_PASS)].isNull()) { + changed |= strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)]) != 0; + strncpy(http_config.password, settings[FPSTR(FP_CONFIG_PASS)], sizeof(http_config.password)); + } + + return changed; +} +#endif // HASP_USE_CONFIG + +size_t httpClientWrite(const uint8_t* buf, size_t size) +{ + /***** Sending 16Kb at once freezes on STM32 EthernetClient *****/ + size_t bytes_sent = 0; + while(bytes_sent < size) { + if(!webServer.client()) return bytes_sent; + if(size - bytes_sent >= 2048) { + bytes_sent += webServer.client().write(buf + bytes_sent, 2048); + } else { + bytes_sent += webServer.client().write(buf + bytes_sent, size - bytes_sent); + } + // Serial.println(bytes_sent); + + // stm32_eth_scheduler(); // already in write + // webServer.client().flush(); + delay(1); // Fixes the freeze + } + return bytes_sent; +} + +#endif \ No newline at end of file From 202c95805754ce22d9432a4338092ae7112bb378 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 00:05:10 +0100 Subject: [PATCH 076/236] Change power to state --- src/hasp/hasp_dispatch.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index bf2c2dcb..9484ff4b 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -800,7 +800,7 @@ void dispatch_moodlight(const char* topic, const char* payload) dispatch_json_error(TAG_MSGR, jsonError); } else { - if(!json[F("power")].isNull()) moodlight.power = Utilities::is_true(json[F("power")].as()); + if(!json[F("state")].isNull()) moodlight.power = Utilities::is_true(json[F("state")].as()); if(!json[F("r")].isNull()) moodlight.r = json[F("r")].as(); if(!json[F("g")].isNull()) moodlight.r = json[F("g")].as(); @@ -826,9 +826,10 @@ void dispatch_moodlight(const char* topic, const char* payload) // Return the current state char buffer[128]; - snprintf_P(buffer, sizeof(buffer), - PSTR("{\"power\":\"%u\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"), moodlight.power, - moodlight.r, moodlight.g, moodlight.b, moodlight.r, moodlight.g, moodlight.b); + snprintf_P( + // buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"), + buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":[%u,%u,%u]}"), moodlight.power ? "ON" : "OFF", + moodlight.r, moodlight.g, moodlight.b); dispatch_state_msg(F("moodlight"), buffer); } From 28f420be1cee52b5f7f7f2015faa4694a26b40f4 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 00:26:00 +0100 Subject: [PATCH 077/236] Fix webHandleConfig callback --- src/svc/hasp_http.cpp | 2121 ------------------------------------- src/sys/svc/hasp_http.cpp | 2 +- 2 files changed, 1 insertion(+), 2122 deletions(-) delete mode 100644 src/svc/hasp_http.cpp diff --git a/src/svc/hasp_http.cpp b/src/svc/hasp_http.cpp deleted file mode 100644 index 11b66f44..00000000 --- a/src/svc/hasp_http.cpp +++ /dev/null @@ -1,2121 +0,0 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie - For full license information read the LICENSE file in the project folder */ - -//#include "webServer.h" -#include "ArduinoJson.h" -#include "ArduinoLog.h" -#include "lvgl.h" - -#if defined(ARDUINO_ARCH_ESP32) -#include "Update.h" -#endif - -#include "hasp_conf.h" - -#include "hasp_gui.h" -#include "hasp_hal.h" -#include "hasp_debug.h" -#include "hasp_config.h" - -#include "hasp/hasp_utilities.h" -#include "hasp/hasp_dispatch.h" -#include "hasp/hasp.h" - -#if HASP_USE_HTTP > 0 - -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) -File fsUploadFile; -#endif - -//////////////////////////////////////////////////////////////////////////////////////////////////// -bool webServerStarted = false; - -// bool httpEnable = true; -// uint16_t httpPort = 80; -// char httpUser[32] = ""; -// char httpPassword[32] = ""; -hasp_http_config_t http_config; - -#define HTTP_PAGE_SIZE (6 * 256) - -#if defined(STM32F4xx) && HASP_USE_ETHERNET > 0 -#include -EthernetWebServer webServer(80); -#endif - -#if defined(STM32F4xx) && HASP_USE_WIFI > 0 -#include -// #include -EthernetWebServer webServer(80); -#endif - -#if defined(ARDUINO_ARCH_ESP8266) -#include "StringStream.h" -#include -#include -ESP8266WebServer webServer(80); -#endif - -#if defined(ARDUINO_ARCH_ESP32) -#include -#include -WebServer webServer(80); -#endif // ESP32 - -HTTPUpload* upload; - -static const char HTTP_MENU_BUTTON[] PROGMEM = - "

"; - -const char MAIN_MENU_BUTTON[] PROGMEM = - "

"; -const char MIT_LICENSE[] PROGMEM = "
MIT License

"; - -const char HTTP_DOCTYPE[] PROGMEM = - ""; -const char HTTP_META_GO_BACK[] PROGMEM = ""; -const char HTTP_HEADER[] PROGMEM = "%s"; -const char HTTP_STYLE[] PROGMEM = - ""; -const char HTTP_SCRIPT[] PROGMEM = ""; -const char HTTP_HEADER_END[] PROGMEM = - "
"; -const char HTTP_END[] PROGMEM = ""; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -// URL for auto-update "version.json" -// const char UPDATE_URL[] PROGMEM = "http://haswitchplate.com/update/version.json"; -// // Default link to compiled Arduino firmware image -// String espFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.ino.d1_mini.bin"; -// // Default link to compiled Nextion firmware images -// String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft"; - -#if HASP_USE_MQTT > 0 -extern char mqttNodeName[16]; -#else -char mqttNodeName[3] = "na"; -#endif - -//////////////////////////////////////////////////////////////////////////////////////////////////// -String getOption(int value, String label, bool selected) -{ - char buffer[128]; - snprintf_P(buffer, sizeof(buffer), PSTR(""), value, - (selected ? PSTR(" selected") : ""), label.c_str()); - return buffer; -} - -String getOption(String value, String label, bool selected) -{ - char buffer[128]; - snprintf_P(buffer, sizeof(buffer), PSTR(""), value.c_str(), - (selected ? PSTR(" selected") : ""), label.c_str()); - return buffer; -} - -static void add_gpio_select_option(String& str, uint8_t gpio, uint8_t bcklpin) -{ - char buffer[10]; - snprintf_P(buffer, sizeof(buffer), PSTR("GPIO %d"), gpio); - str += getOption(gpio, buffer, bcklpin == gpio); -} - -static void add_button(String& str, const __FlashStringHelper* label, const __FlashStringHelper* extra) -{ - str += F(""); -} - -static void close_form(String& str) -{ - str += F("

"); -} - -static void add_form_button(String& str, const __FlashStringHelper* label, const __FlashStringHelper* action, - const __FlashStringHelper* extra) -{ - str += F("

"); - add_button(str, label, extra); - close_form(str); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void webHandleHaspConfig(); - -static inline char* httpGetNodename() -{ - return mqttNodeName; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -bool httpIsAuthenticated(const __FlashStringHelper* fstr_page) -{ - if(http_config.password[0] != '\0') { // Request HTTP auth if httpPassword is set - if(!webServer.authenticate(http_config.user, http_config.password)) { - webServer.requestAuthentication(); - return false; - } - } - -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - LOG_TRACE(TAG_HTTP, F("Sending %S page to client connected from: %s"), fstr_page, - webServer.client().remoteIP().toString().c_str()); -#else - // LOG_INFO(TAG_HTTP,F("Sending %s page to client connected from: %s"), page, - // String(webServer.client().remoteIP()).c_str()); -#endif - - return true; -} - -void webSendFooter() -{ - char buffer[16]; - haspGetVersion(buffer, sizeof(buffer)); - -#if defined(STM32F4xx) - webServer.sendContent(HTTP_END); - webServer.sendContent(buffer); - webServer.sendContent(HTTP_FOOTER); -#else - webServer.sendContent_P(HTTP_END); - webServer.sendContent(buffer); - webServer.sendContent_P(HTTP_FOOTER); -#endif -} - -void webSendPage(char* nodename, uint32_t httpdatalength, bool gohome = false) -{ - { - char buffer[64]; - haspGetVersion(buffer, sizeof(buffer)); - - /* Calculate Content Length upfront */ - uint16_t contentLength = strlen(buffer); // verion length - contentLength += sizeof(HTTP_DOCTYPE) - 1; - contentLength += sizeof(HTTP_HEADER) - 1 - 2 + strlen(nodename); // -2 for %s - contentLength += sizeof(HTTP_SCRIPT) - 1; - contentLength += sizeof(HTTP_STYLE) - 1; - // contentLength += sizeof(HASP_STYLE) - 1; - if(gohome) contentLength += sizeof(HTTP_META_GO_BACK) - 1; - contentLength += sizeof(HTTP_HEADER_END) - 1; - contentLength += sizeof(HTTP_END) - 1; - contentLength += sizeof(HTTP_FOOTER) - 1; - - if(httpdatalength > HTTP_PAGE_SIZE) { - LOG_WARNING(TAG_HTTP, F("Sending page with %u static and %u dynamic bytes"), contentLength, httpdatalength); - } - - webServer.setContentLength(contentLength + httpdatalength); -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122 -#else - webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122 -#endif - - snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename); - webServer.sendContent(buffer); // 17-2+len - } - -#if defined(STM32F4xx) - webServer.sendContent(HTTP_SCRIPT); // 131 - webServer.sendContent(HTTP_STYLE); // 487 - // webServer.sendContent(HASP_STYLE); // 145 - if(gohome) webServer.sendContent(HTTP_META_GO_BACK); // 47 - webServer.sendContent(HTTP_HEADER_END); // 80 -#else - webServer.sendContent_P(HTTP_SCRIPT); // 131 - webServer.sendContent_P(HTTP_STYLE); // 487 - // webServer.sendContent_P(HASP_STYLE); // 145 - if(gohome) webServer.sendContent_P(HTTP_META_GO_BACK); // 47 - webServer.sendContent_P(HTTP_HEADER_END); // 80 -#endif -} - -void saveConfig() -{ - if(webServer.method() == HTTP_POST) { - if(webServer.hasArg(PSTR("save"))) { - String save = webServer.arg(PSTR("save")); - - StaticJsonDocument<256> settings; - for(int i = 0; i < webServer.args(); i++) settings[webServer.argName(i)] = webServer.arg(i); - - if(save == String(PSTR("hasp"))) { - haspSetConfig(settings.as()); - -#if HASP_USE_MQTT > 0 - } else if(save == String(PSTR("mqtt"))) { - mqttSetConfig(settings.as()); -#endif - - } else if(save == String(PSTR("gui"))) { - settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cur")); - settings[FPSTR(FP_GUI_INVERT)] = webServer.hasArg(PSTR("inv")); - guiSetConfig(settings.as()); - - } else if(save == String(PSTR("debug"))) { - debugSetConfig(settings.as()); - - } else if(save == String(PSTR("http"))) { - httpSetConfig(settings.as()); - - // Password might have changed - if(!httpIsAuthenticated(F("config"))) return; - -#if HASP_USE_WIFI > 0 - } else if(save == String(PSTR("wifi"))) { - wifiSetConfig(settings.as()); -#endif - } - } - } -} - -void webHandleRoot() -{ - if(!httpIsAuthenticated(F("root"))) return; - - saveConfig(); - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("

"); - - httpMessage += F("

"); - httpMessage += - F("

"); - add_form_button(httpMessage, F(D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += F("

"); - - httpMessage += F("

"); - -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - if(HASP_FS.exists(F("/edit.htm.gz"))) { - httpMessage += - F("

"); - } -#endif - - httpMessage += F("

"); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void httpHandleReboot() -{ // http://plate01/reboot - if(!httpIsAuthenticated(F("reboot"))) return; - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - httpMessage = F(D_DISPATCH_REBOOT); - - webSendPage(httpGetNodename(), httpMessage.length(), true); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); - - delay(200); - dispatch_reboot(true); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void webHandleScreenshot() -{ // http://plate01/screenshot - if(!httpIsAuthenticated(F("screenshot"))) return; - - if(webServer.hasArg(F("a"))) { - if(webServer.arg(F("a")) == F("next")) { - dispatch_page_next(); - } else if(webServer.arg(F("a")) == F("prev")) { - dispatch_page_prev(); - } - } - - if(webServer.hasArg(F("q"))) { - lv_disp_t* disp = lv_disp_get_default(); - webServer.setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t)); - webServer.send_P(200, PSTR("image/bmp"), ""); - guiTakeScreenshot(); - webServer.client().stop(); - - } else { - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += - F(""); - httpMessage += F("

"); - - httpMessage += F("

"); - httpMessage += - F("

"); - httpMessage += - F("

"); - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -void webHandleAbout() -{ // http://plate01/about - if(!httpIsAuthenticated(F("about"))) return; - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - - httpMessage += F("

HASP OpenHardware edition

Copyright© 2020 Francis Van Roie "); - httpMessage += FPSTR(MIT_LICENSE); - httpMessage += F("

Based on the previous work of the following open source developers.


"); - httpMessage += F("

HASwitchPlate

Copyright© 2019 Allen Derusha allen@derusha.org"); - httpMessage += FPSTR(MIT_LICENSE); - httpMessage += - F("

LittlevGL

Copyright© 2016 Gábor Kiss-Vámosi
Copyright© 2019 " - "LittlevGL"); - httpMessage += FPSTR(MIT_LICENSE); - httpMessage += F("

zi Font Engine

Copyright© 2020 Francis Van Roie"); - httpMessage += FPSTR(MIT_LICENSE); - httpMessage += F("

TFT_eSPI Library

Copyright© 2020 Bodmer (https://github.com/Bodmer) All " - "rights reserved.
FreeBSD License

"); - httpMessage += - F("

includes parts from the Adafruit_GFX library
Copyright© 2012 Adafruit Industries. " - "All rights reserved
BSD License

"); - httpMessage += F("

ArduinoJson

Copyright© 2014-2020 Benoit BLANCHON"); - httpMessage += FPSTR(MIT_LICENSE); - httpMessage += F("

PubSubClient

Copyright© 2008-2015 Nicholas O'Leary"); - httpMessage += FPSTR(MIT_LICENSE); - httpMessage += - F("

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, " - "dhylands, Josha blemasle, mfalkvidd"); - httpMessage += FPSTR(MIT_LICENSE); -#if HASP_USE_SYSLOG > 0 - // Replaced with WiFiUDP client - // httpMessage += F("

Syslog

Copyright© 2016 Martin Sloup"); - // httpMessage += FPSTR(MIT_LICENSE); -#endif -#if HASP_USE_QRCODE > 0 - httpMessage += F("

QR Code generator

Copyright© Project Nayuki"); - httpMessage += FPSTR(MIT_LICENSE); -#endif - httpMessage += F("

AceButton

Copyright© 2018 Brian T. Park"); - httpMessage += FPSTR(MIT_LICENSE); - - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void webHandleInfo() -{ // http://plate01/ - if(!httpIsAuthenticated(F("info"))) return; - - { - char size_buf[32]; - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - /* HASP Stats */ - httpMessage += F("HASP Version: "); - { - char version[32]; - haspGetVersion(version, sizeof(version)); - httpMessage += version; - } - httpMessage += F("
Build DateTime: "); - httpMessage += __DATE__; - httpMessage += F(" "); - httpMessage += __TIME__; - httpMessage += F(" CET
Uptime: "); - - unsigned long time = millis() / 1000; - uint16_t day = time / 86400; - time = time % 86400; - uint8_t hour = time / 3600; - time = time % 3600; - uint8_t min = time / 60; - time = time % 60; - uint8_t sec = time; - - if(day > 0) { - httpMessage += String(day); - httpMessage += F("d "); - } - if(day > 0 || hour > 0) { - httpMessage += String(hour); - httpMessage += F("h "); - } - if(day > 0 || hour > 0 || min > 0) { - httpMessage += String(min); - httpMessage += F("m "); - } - httpMessage += String(sec); - httpMessage += F("s"); - - httpMessage += F("
Free Memory: "); - hasp_util_format_bytes(halGetFreeHeap(), size_buf, sizeof(size_buf)); - httpMessage += size_buf; - httpMessage += F("
Memory Fragmentation: "); - httpMessage += String(halGetHeapFragmentation()); - -#if ARDUINO_ARCH_ESP32 - if(psramFound()) { - httpMessage += F("
Free PSRam: "); - hasp_util_format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf)); - httpMessage += size_buf; - httpMessage += F("
PSRam Size: "); - hasp_util_format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf)); - httpMessage += size_buf; - } -#endif - - /* LVGL Stats */ - lv_mem_monitor_t mem_mon; - lv_mem_monitor(&mem_mon); - httpMessage += F("

LVGL Memory: "); - hasp_util_format_bytes(mem_mon.total_size, size_buf, sizeof(size_buf)); - httpMessage += size_buf; - httpMessage += F("
LVGL Free: "); - hasp_util_format_bytes(mem_mon.free_size, size_buf, sizeof(size_buf)); - httpMessage += size_buf; - httpMessage += F("
LVGL Fragmentation: "); - httpMessage += mem_mon.frag_pct; - - // httpMessage += F("
LCD Model: ")) + String(LV_HASP_HOR_RES_MAX) + " x " + - // String(LV_HASP_VER_RES_MAX); httpMessage += F("
LCD Version: ")) + - // String(lcdVersion); - httpMessage += F("

LCD Active Page: "); - httpMessage += String(haspGetPage()); - - /* Wifi Stats */ -#if HASP_USE_WIFI > 0 - httpMessage += F("

SSID: "); - httpMessage += String(WiFi.SSID()); - httpMessage += F("
Signal Strength: "); - - int8_t rssi = WiFi.RSSI(); - httpMessage += String(rssi); - httpMessage += F("dBm ("); - - if(rssi >= -50) { - httpMessage += F("Excellent)"); - } else if(rssi >= -60) { - httpMessage += F("Good)"); - } else if(rssi >= -70) { - httpMessage += F("Fair)"); - } else if(rssi >= -80) { - httpMessage += F("Weak)"); - } else { - httpMessage += F("Very Bad)"); - } -#if defined(STM32F4xx) - byte mac[6]; - WiFi.macAddress(mac); - char macAddress[16]; - snprintf_P(macAddress, sizeof(macAddress), PSTR("%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], - mac[5]); - httpMessage += F("
IP Address: "); - httpMessage += String(WiFi.localIP()); - httpMessage += F("
Gateway: "); - httpMessage += String(WiFi.gatewayIP()); - httpMessage += F("
MAC Address: "); - httpMessage += String(macAddress); -#else - httpMessage += F("
IP Address: "); - httpMessage += String(WiFi.localIP().toString()); - httpMessage += F("
Gateway: "); - httpMessage += String(WiFi.gatewayIP().toString()); - httpMessage += F("
DNS Server: "); - httpMessage += String(WiFi.dnsIP().toString()); - httpMessage += F("
MAC Address: "); - httpMessage += String(WiFi.macAddress()); -#endif -#endif -#if HASP_USE_ETHERNET > 0 -#if defined(ARDUINO_ARCH_ESP32) - httpMessage += F("

Ethernet: "); - httpMessage += String(ETH.linkSpeed()); - httpMessage += F(" Mbps"); - if(ETH.fullDuplex()) { - httpMessage += F(" FULL_DUPLEX"); - } - httpMessage += F("
IP Address: "); - httpMessage += String(ETH.localIP().toString()); - httpMessage += F("
Gateway: "); - httpMessage += String(ETH.gatewayIP().toString()); - httpMessage += F("
DNS Server: "); - httpMessage += String(ETH.dnsIP().toString()); - httpMessage += F("
MAC Address: "); - httpMessage += String(ETH.macAddress()); -#endif -#endif -/* Mqtt Stats */ -#if HASP_USE_MQTT > 0 - httpMessage += F("

MQTT Status: "); - if(mqttIsConnected()) { // Check MQTT connection - httpMessage += F("Connected"); - } else { - httpMessage += F("Disconnected, return code: "); - // +String(mqttClient.returnCode()); - } - httpMessage += F("
MQTT ClientID: "); - - { - char mqttClientId[64]; - String mac = halGetMacAddress(3, ""); - mac.toLowerCase(); - snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%s"), mqttNodeName, mac.c_str()); - httpMessage += mqttClientId; - } - -#endif // MQTT - - /* ESP Stats */ - httpMessage += F("

MCU Model: "); - httpMessage += halGetChipModel(); - httpMessage += F("
CPU Frequency: "); - httpMessage += String(halGetCpuFreqMHz()); - httpMessage += F("MHz"); - -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - httpMessage += F("
Flash Chip Size: "); - hasp_util_format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf)); - httpMessage += size_buf; - - httpMessage += F("
Program Size: "); - hasp_util_format_bytes(ESP.getSketchSize(), size_buf, sizeof(size_buf)); - httpMessage += size_buf; - - httpMessage += F("
Free Program Space: "); - hasp_util_format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf)); - httpMessage += size_buf; -#endif - - //#if defined(ARDUINO_ARCH_ESP32) - // httpMessage += F("
ESP SDK version: "); - // httpMessage += String(ESP.getSdkVersion()); - //#else - httpMessage += F("
Core version: "); - httpMessage += String(halGetCoreVersion()); - //#endif - httpMessage += F("
Last Reset: "); - httpMessage += halGetResetInfo(); - - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} - -// String getContentType(String filename) -// { -// if(webServer.hasArg(F("download"))) { -// return F("application/octet-stream"); -// } else if(filename.endsWith(F(".htm")) || filename.endsWith(F(".html"))) { -// return F("text/html"); -// } else if(filename.endsWith(F(".css"))) { -// return F("text/css"); -// } else if(filename.endsWith(F(".js"))) { -// return F("application/javascript"); -// } else if(filename.endsWith(F(".png"))) { -// return F("image/png"); -// } else if(filename.endsWith(F(".gif"))) { -// return F("image/gif"); -// } else if(filename.endsWith(F(".jpg"))) { -// return F("image/jpeg"); -// } else if(filename.endsWith(F(".ico"))) { -// return F("image/x-icon"); -// } else if(filename.endsWith(F(".xml"))) { -// return F("text/xml"); -// } else if(filename.endsWith(F(".pdf"))) { -// return F("application/x-pdf"); -// } else if(filename.endsWith(F(".zip"))) { -// return F("application/x-zip"); -// } else if(filename.endsWith(F(".gz"))) { -// return F("application/x-gzip"); -// } -// return F("text/plain"); -// } - -static String getContentType(const String& path) -{ - char buff[sizeof(mime::mimeTable[0].mimeType)]; - // Check all entries but last one for match, return if found - for(size_t i = 0; i < sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1; i++) { - strcpy_P(buff, mime::mimeTable[i].endsWith); - if(path.endsWith(buff)) { - strcpy_P(buff, mime::mimeTable[i].mimeType); - return String(buff); - } - } - // Fall-through and just return default type - strcpy_P(buff, mime::mimeTable[sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1].mimeType); - return String(buff); -} - -/* String urldecode(String str) -{ - String encodedString = ""; - char c; - for(unsigned int i = 0; i < str.length(); i++) { - c = str.charAt(i); - if(c == '+') { - encodedString += ' '; - } else if(c == '%') { - // char buffer[3]; - char buffer[128]; - i++; - buffer[0] = str.charAt(i); - i++; - buffer[1] = str.charAt(i); - buffer[2] = '\0'; - c = (char)strtol((const char *)&buffer, NULL, 16); - encodedString += c; - } else { - encodedString += c; - } - yield(); - } - return encodedString; -} */ - -static unsigned long htppLastLoopTime = 0; -void webUploadProgress() -{ - long t = webServer.header("Content-Length").toInt(); - if(millis() - htppLastLoopTime >= 1250) { - LOG_VERBOSE(TAG_HTTP, F(D_BULLET "Uploaded %u / %d bytes"), upload->totalSize + upload->currentSize, t); - htppLastLoopTime = millis(); - } - if(t > 0) t = (upload->totalSize + upload->currentSize) * 100 / t; - haspProgressVal(t); -} - -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) -static inline void webUpdatePrintError() -{ -#if defined(ARDUINO_ARCH_ESP8266) - String output((char*)0); - output.reserve(128); - StringStream stream((String&)output); - Update.printError(stream); // ESP8266 only has printError() - LOG_ERROR(TAG_HTTP, output.c_str()); - haspProgressMsg(output.c_str()); -#elif defined(ARDUINO_ARCH_ESP32) - LOG_ERROR(TAG_HTTP, Update.errorString()); // ESP32 has errorString() - haspProgressMsg(Update.errorString()); -#endif -} - -void webUpdateReboot() -{ - LOG_INFO(TAG_HTTP, F("Update Success: %u bytes received. Rebooting..."), upload->totalSize); - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - httpMessage += F("Upload complete. Rebooting device, please wait..."); - - webSendPage(httpGetNodename(), httpMessage.length(), true); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); - - delay(250); - dispatch_reboot(true); // Save the current config -} - -void webHandleFirmwareUpload() -{ - upload = &webServer.upload(); - - if(upload->status == UPLOAD_FILE_START) { - if(!httpIsAuthenticated(F("update"))) return; - LOG_TRACE(TAG_HTTP, F("Update: %s"), upload->filename.c_str()); - haspProgressMsg(upload->filename.c_str()); - // WiFiUDP::stopAll(); - uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; - // if(!Update.begin(UPDATE_SIZE_UNKNOWN)) { // start with max available size - if(!Update.begin(maxSketchSpace)) { // start with max available size - webUpdatePrintError(); - } - - } else if(upload->status == UPLOAD_FILE_WRITE) { - // flashing firmware to ESP - if(Update.write(upload->buf, upload->currentSize) != upload->currentSize) { - webUpdatePrintError(); - } else { - webUploadProgress(); - } - - } else if(upload->status == UPLOAD_FILE_END) { - haspProgressVal(100); - if(Update.end(true)) { // true to set the size to the current progress - haspProgressMsg(F(D_OTA_UPDATE_APPLY)); - webUpdateReboot(); - } else { - webUpdatePrintError(); - } - } -} -#endif - -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 -bool handleFileRead(String path) -{ - if(!httpIsAuthenticated(F("fileread"))) return false; - - path = webServer.urlDecode(path).substring(0, 31); - if(path.endsWith("/")) { - path += F("index.htm"); - } - String pathWithGz = path + F(".gz"); - if(HASP_FS.exists(pathWithGz) || HASP_FS.exists(path)) { - if(HASP_FS.exists(pathWithGz)) path += F(".gz"); - - File file = HASP_FS.open(path, "r"); - String contentType = getContentType(path); - if(path == F("/edit.htm.gz")) { - contentType = F("text/html"); - } - webServer.streamFile(file, contentType); - file.close(); - return true; - } - return false; -} - -void handleFileUpload() -{ - if(webServer.uri() != "/edit") { - return; - } - upload = &webServer.upload(); - if(upload->status == UPLOAD_FILE_START) { - if(!httpIsAuthenticated(F("fileupload"))) return; - LOG_INFO(TAG_HTTP, F("Total size: %s"), webServer.headerName(0).c_str()); - String filename((char*)0); - filename.reserve(128); - filename = upload->filename; - if(!filename.startsWith("/")) { - filename = "/"; - filename += upload->filename; - } - if(filename.length() < 32) { - fsUploadFile = HASP_FS.open(filename, "w"); - LOG_TRACE(TAG_HTTP, F("handleFileUpload Name: %s"), filename.c_str()); - haspProgressMsg(fsUploadFile.name()); - } else { - LOG_ERROR(TAG_HTTP, F("Filename %s is too long"), filename.c_str()); - } - } else if(upload->status == UPLOAD_FILE_WRITE) { - // DBG_OUTPUT_PORT.print("handleFileUpload Data: "); debugPrintln(upload.currentSize); - if(fsUploadFile) { - if(fsUploadFile.write(upload->buf, upload->currentSize) != upload->currentSize) { - LOG_ERROR(TAG_HTTP, F("Failed to write received data to file")); - } else { - webUploadProgress(); // Moved to httpEverySecond Loop - } - } - } else if(upload->status == UPLOAD_FILE_END) { - if(fsUploadFile) { - LOG_INFO(TAG_HTTP, F("Uploaded %s (%u bytes)"), fsUploadFile.name(), upload->totalSize); - fsUploadFile.close(); - } - haspProgressVal(255); - - // Redirect to /config/hasp page. This flushes the web buffer and frees the memory - webServer.sendHeader(String(F("Location")), String(F("/config/hasp")), true); - webServer.send_P(302, PSTR("text/plain"), ""); - // httpReconnect(); - } -} - -void handleFileDelete() -{ - if(!httpIsAuthenticated(F("filedelete"))) return; - - char mimetype[16]; - snprintf_P(mimetype, sizeof(mimetype), PSTR("text/plain")); - - if(webServer.args() == 0) { - return webServer.send_P(500, mimetype, PSTR("BAD ARGS")); - } - String path = webServer.arg(0); - LOG_TRACE(TAG_HTTP, F("handleFileDelete: %s"), path.c_str()); - if(path == "/") { - return webServer.send_P(500, mimetype, PSTR("BAD PATH")); - } - if(!HASP_FS.exists(path)) { - return webServer.send_P(404, mimetype, PSTR("FileNotFound")); - } - HASP_FS.remove(path); - webServer.send_P(200, mimetype, PSTR("")); - // path.clear(); -} - -void handleFileCreate() -{ - if(!httpIsAuthenticated(F("filecreate"))) return; - - if(webServer.args() == 0) { - return webServer.send(500, PSTR("text/plain"), PSTR("BAD ARGS")); - } - String path = webServer.arg(0); - LOG_TRACE(TAG_HTTP, F("handleFileCreate: %s"), path.c_str()); - if(path == "/") { - return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH")); - } - if(HASP_FS.exists(path)) { - return webServer.send(500, PSTR("text/plain"), PSTR("FILE EXISTS")); - } - File file = HASP_FS.open(path, "w"); - if(file) { - file.close(); - } else { - return webServer.send(500, PSTR("text/plain"), PSTR("CREATE FAILED")); - } - webServer.send(200, PSTR("text/plain"), ""); - path.clear(); -} - -void handleFileList() -{ - if(!httpIsAuthenticated(F("filelist"))) return; - - if(!webServer.hasArg(F("dir"))) { - webServer.send(500, PSTR("text/plain"), PSTR("BAD ARGS")); - return; - } - - String path = webServer.arg(F("dir")); - LOG_TRACE(TAG_HTTP, F("handleFileList: %s"), path.c_str()); - path.clear(); - -#if defined(ARDUINO_ARCH_ESP32) - File root = HASP_FS.open("/", FILE_READ); - File file = root.openNextFile(); - String output = "["; - - while(file) { - if(output != "[") { - output += ','; - } - bool isDir = false; - output += F("{\"type\":\""); - output += (isDir) ? F("dir") : F("file"); - output += F("\",\"name\":\""); - if(file.name()[0] == '/') { - output += &(file.name()[1]); - } else { - output += file.name(); - } - output += F("\"}"); - - // file.close(); - file = root.openNextFile(); - } - output += "]"; - webServer.send(200, PSTR("text/json"), output); -#elif defined(ARDUINO_ARCH_ESP8266) - Dir dir = HASP_FS.openDir(path); - String output = "["; - while(dir.next()) { - File entry = dir.openFile("r"); - if(output != "[") { - output += ','; - } - bool isDir = false; - output += F("{\"type\":\""); - output += (isDir) ? F("dir") : F("file"); - output += F("\",\"name\":\""); - if(entry.name()[0] == '/') { - output += &(entry.name()[1]); - } else { - output += entry.name(); - } - output += F("\"}"); - entry.close(); - } - output += "]"; - webServer.send(200, PSTR("text/json"), output); -#endif -} -#endif - -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if HASP_USE_CONFIG > 0 -void webHandleConfig() -{ // http://plate01/config - if(!httpIsAuthenticated(F("config"))) return; - - saveConfig(); - -// Reboot after saving wifi config in AP mode -#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) - if(WiFi.getMode() != WIFI_STA) { - httpHandleReboot(); - } -#endif - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - -#if HASP_USE_WIFI > 0 - httpMessage += F("

"); -#endif - -#if HASP_USE_MQTT > 0 - httpMessage += F("

"); -#endif - - httpMessage += F("

"); - - httpMessage += F("

"); - - // httpMessage += - // F("

"); - -#if HASP_USE_GPIO > 0 - httpMessage += F("

"); -#endif - - httpMessage += F("

"); - - httpMessage += - F("

"); - - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if HASP_USE_MQTT > 0 -void webHandleMqttConfig() -{ // http://plate01/config/mqtt - if(!httpIsAuthenticated(F("config/mqtt"))) return; - - StaticJsonDocument<256> settings; - mqttGetConfig(settings.to()); - - { - // char buffer[128]; - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("
"); - httpMessage += F("HASP Node Name (required. lowercase letters, numbers, and _ only)" - "

Group Name (required)

MQTT Broker (required)
MQTT Port (required)
MQTT User (optional)
MQTT Password (optional)

"); - - add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += PSTR("

"); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} -#endif - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void webHandleGuiConfig() -{ // http://plate01/config/wifi - if(!httpIsAuthenticated(F("config/gui"))) return; - - { - StaticJsonDocument<256> settings; - guiGetConfig(settings.to()); - - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("
"); - - httpMessage += F("

Short Idle

"); - - httpMessage += F("

Long Idle

"); - - int8_t rotation = settings[FPSTR(FP_GUI_ROTATION)].as(); - httpMessage += F("

Orientation

"); - - httpMessage += F("

()) httpMessage += F(" checked"); - httpMessage += F(">Invert Colors"); - - httpMessage += F("

()) httpMessage += F(" checked"); - httpMessage += F(">Show Pointer"); - - int8_t bcklpin = settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as(); - httpMessage += F("

Backlight Control

"); - - add_button(httpMessage, F(D_HTTP_SAVE_SETTINGS), F("name='save' value='gui'")); - close_form(httpMessage); - // httpMessage += - // F("

"); - -#if TOUCH_DRIVER == 2046 && defined(TOUCH_CS) - add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='action' value='calibrate'")); - -// httpMessage += PSTR("

"); -#endif - - add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - - // httpMessage += PSTR("

"); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - webSendFooter(); - - if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if HASP_USE_WIFI > 0 -void webHandleWifiConfig() -{ // http://plate01/config/wifi - if(!httpIsAuthenticated(F("config/wifi"))) return; - - StaticJsonDocument<256> settings; - wifiGetConfig(settings.to()); - - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("
"); - httpMessage += F("WiFi SSID (required)
WiFi Password (required)

"); - -#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) - if(WiFi.getMode() == WIFI_STA) { - add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += PSTR("

"); - } -#endif - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); -#if defined(STM32F4xx) - httpMessage = ""; -#else - httpMessage.clear(); -#endif - webSendFooter(); -} -#endif - -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if HASP_USE_HTTP > 0 -void webHandleHttpConfig() -{ // http://plate01/config/http - if(!httpIsAuthenticated(F("config/http"))) return; - - { - StaticJsonDocument<256> settings; - httpGetConfig(settings.to()); - - // String httpMessage((char *)0); - // httpMessage.reserve(HTTP_PAGE_SIZE); - // httpMessage += F("

"); - // httpMessage += httpGetNodename(); - // httpMessage += F("


"); - - // httpMessage += F("
"); - // httpMessage += F("Web Username (optional)
Web Password (optional)

"); - - // httpMessage += PSTR("

"); - - char httpMessage[HTTP_PAGE_SIZE]; - - size_t len = snprintf_P( - httpMessage, sizeof(httpMessage), - PSTR("

%s


" - "
" - "Web Username (optional)" - "
" - "Web Password (optional)" - "" - "

" - "

"), - httpGetNodename(), settings[FPSTR(FP_CONFIG_USER)].as().c_str(), - settings[FPSTR(FP_CONFIG_PASS)].as().c_str()); - - // if(settings[FPSTR(FP_CONFIG_PASS)].as() != "") { - // httpMessage += F(D_PASSWORD_MASK); - // } - - webSendPage(httpGetNodename(), len, false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} -#endif - -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) -void webHandleGpioConfig() -{ // http://plate01/config/gpio - if(!httpIsAuthenticated(F("config/gpio"))) return; - uint8_t configCount = 0; - - // StaticJsonDocument<256> settings; - // gpioGetConfig(settings.to()); - - if(webServer.hasArg(PSTR("save"))) { - uint8_t id = webServer.arg(F("id")).toInt(); - uint8_t pin = webServer.arg(F("pin")).toInt(); - uint8_t type = webServer.arg(F("type")).toInt() + webServer.arg(F("state")).toInt(); - uint8_t group = webServer.arg(F("group")).toInt(); - uint8_t pinfunc = webServer.arg(F("func")).toInt(); - gpioSavePinConfig(id, pin, type, group, pinfunc); - } - if(webServer.hasArg(PSTR("del"))) { - uint8_t id = webServer.arg(F("id")).toInt(); - uint8_t pin = webServer.arg(F("pin")).toInt(); - gpioSavePinConfig(id, pin, HASP_GPIO_FREE, 0, 0); - } - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("
"); - - httpMessage += F(""); - - for(uint8_t gpio = 0; gpio < NUM_DIGITAL_PINS; gpio++) { - for(uint8_t id = 0; id < HASP_NUM_GPIO_CONFIG; id++) { - hasp_gpio_config_t conf = gpioGetPinConfig(id); - if((conf.pin == gpio) && gpioConfigInUse(id) && gpioInUse(gpio) && !gpioIsSystemPin(gpio)) { - httpMessage += F(""); - configCount++; - } - } - } - - httpMessage += F("
PinTypeGroupDefaultAction
"); - httpMessage += halGpioName(gpio); - httpMessage += F(""); - - switch(conf.type & 0xfe) { - case HASP_GPIO_SWITCH: - // case HASP_GPIO_SWITCH_INVERTED: - httpMessage += F("Switch"); - break; - case HASP_GPIO_BUTTON: - // case HASP_GPIO_BUTTON_INVERTED: - httpMessage += F("Button"); - break; - case HASP_GPIO_LED: - // case HASP_GPIO_LED_INVERTED: - httpMessage += F("Led"); - break; - case HASP_GPIO_LED_R: - case HASP_GPIO_LED_G: - case HASP_GPIO_LED_B: - // case HASP_GPIO_LED_INVERTED: - httpMessage += F("Mood "); - break; - case HASP_GPIO_RELAY: - // case HASP_GPIO_RELAY_INVERTED: - httpMessage += F("Relay"); - break; - case HASP_GPIO_PWM: - // case HASP_GPIO_PWM_INVERTED: - httpMessage += F("PWM"); - break; - default: - httpMessage += F("Unknown"); - } - - switch(conf.type & 0xfe) { - case HASP_GPIO_LED_R: - httpMessage += F("Red"); - break; - case HASP_GPIO_LED_G: - httpMessage += F("Green"); - break; - case HASP_GPIO_LED_B: - httpMessage += F("Blue"); - break; - } - - httpMessage += F(""); - httpMessage += conf.group; - httpMessage += F(""); - - // bool inverted = (conf.type == HASP_GPIO_BUTTON_INVERTED) || - // (conf.type == HASP_GPIO_SWITCH_INVERTED) || (conf.type == HASP_GPIO_LED_INVERTED) - // || (conf.type == HASP_GPIO_RELAY_INVERTED) || (conf.type == - // HASP_GPIO_PWM_INVERTED); - - httpMessage += (conf.type & 0x1) ? F("High") : F("Low"); - - httpMessage += F("Edit Delete
"); - - if(configCount < HASP_NUM_GPIO_CONFIG) { - httpMessage += F("

"); - httpMessage += F("

"); - } - - add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += F("

"); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void webHandleGpioOptions() -{ // http://plate01/config/gpio/options - if(!httpIsAuthenticated(F("config/gpio/options"))) return; - - { - StaticJsonDocument<256> settings; - guiGetConfig(settings.to()); - - uint8_t config_id = webServer.arg(F("id")).toInt(); - - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("
"); - httpMessage += F(""); - - httpMessage += F("

GPIO Options"); - httpMessage += config_id; - httpMessage += F(" Options

"); - - httpMessage += F("

Pin

"); - - bool selected; - httpMessage += F("

Type

"); - - httpMessage += F("

Group

"); - - httpMessage += F("

Default State

"); - - httpMessage += - F("

"); - - httpMessage += PSTR("

"); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - webSendFooter(); - - if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check -} -#endif // HASP_USE_GPIO - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void webHandleDebugConfig() -{ // http://plate01/config/debug - if(!httpIsAuthenticated(F("config/debug"))) return; - - StaticJsonDocument<256> settings; - debugGetConfig(settings.to()); - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("
"); - - uint16_t baudrate = settings[FPSTR(FP_CONFIG_BAUD)].as(); - httpMessage += F("

Serial Port

Telemetry Period (Seconds, 0=disable) " - "

"); - -#if HASP_USE_SYSLOG > 0 - httpMessage += F("Syslog Hostame (optional)
Syslog Port (optional) Syslog Facility
Syslog Protocol () == 0) httpMessage += F(" checked"); - httpMessage += F(">IETF (RFC 5424)   () == 1) httpMessage += F(" checked"); - httpMessage += F(">BSD (RFC 3164)"); -#endif - - httpMessage += - F("

"); - - add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += PSTR("

"); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void webHandleHaspConfig() -{ // http://plate01/config/http - if(!httpIsAuthenticated(F("config/hasp"))) return; - - StaticJsonDocument<256> settings; - haspGetConfig(settings.to()); - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("

"); - httpMessage += F("


"); - - // httpMessage += F("
"); - httpMessage += F(""); - httpMessage += F("

UI Theme (required)
"); - httpMessage += - F("Hue

"); - httpMessage += F("

Default Font

"); - - httpMessage += F("

Startup Layout (optional)
Startup Page (required)

Startup Brightness (required)

"); - - httpMessage += - F("

"); - - // httpMessage += - // F("

"); - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} -#endif // HASP_USE_CONFIG - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void httpHandleNotFound() -{ // webServer 404 -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - if(handleFileRead(webServer.uri())) return; -#endif - -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - LOG_TRACE(TAG_HTTP, F("Sending 404 to client connected from: %s"), - webServer.client().remoteIP().toString().c_str()); -#else - // LOG_TRACE(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); -#endif - - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - - httpMessage += F("File Not Found\n\nURI: "); - httpMessage += webServer.uri(); - httpMessage += F("\nMethod: "); - httpMessage += (webServer.method() == HTTP_GET) ? F("GET") : F("POST"); - httpMessage += F("\nArguments: "); - httpMessage += webServer.args(); - httpMessage += "\n"; - for(int i = 0; i < webServer.args(); i++) { - httpMessage += " " + webServer.argName(i) + ": " + webServer.arg(i) + "\n"; - } - webServer.send(404, PSTR("text/plain"), httpMessage.c_str()); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void webHandleFirmware() -{ - if(!httpIsAuthenticated(F("firmware"))) return; - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("

"); - httpMessage += F("

"); - - // httpMessage += F("

"); - // httpMessage += F("

"); - - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendPage(httpGetNodename(), httpMessage.length(), false); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void httpHandleEspFirmware() -{ // http://plate01/espfirmware - if(!httpIsAuthenticated(F("espfirmware"))) return; - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - httpMessage += F("

ESP update

Updating ESP firmware from: "); - httpMessage += webServer.arg("espFirmware"); - - webSendPage(httpGetNodename(), httpMessage.length(), true); - webServer.sendContent(httpMessage); - // httpMessage.clear(); - } - webSendFooter(); - - LOG_TRACE(TAG_HTTP, F("Attempting ESP firmware update from: %s"), webServer.arg("espFirmware").c_str()); - // espStartOta(webServer.arg("espFirmware")); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if HASP_USE_CONFIG > 0 -void webHandleSaveConfig() -{ - if(!httpIsAuthenticated(F("saveConfig"))) return; - - configWriteConfig(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void httpHandleResetConfig() -{ // http://plate01/resetConfig - if(!httpIsAuthenticated(F("resetConfig"))) return; - - bool resetConfirmed = webServer.arg(F("confirm")) == F("yes"); - - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += httpGetNodename(); - httpMessage += F("


"); - - if(resetConfirmed) { // User has confirmed, so reset everything - bool formatted = configClearEeprom(); - if(formatted) { - httpMessage += F("Resetting all saved settings and restarting device"); - } else { - httpMessage += F("Failed to format the internal flash partition"); - resetConfirmed = false; - } - } else { - httpMessage += - F("

Warning

This process will reset all settings to the default values. The internal flash " - "will " - "be erased and the device is restarted. You may need to connect to the WiFi AP displayed on the " - "panel to " - "re-configure the device before accessing it again. ALL FILES WILL BE LOST!" - "


" - "

" - "


"); - - add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += - // PSTR("

"); - } - - webSendPage(httpGetNodename(), httpMessage.length(), resetConfirmed); - webServer.sendContent(httpMessage); - } - // httpMessage.clear(); - webSendFooter(); - - if(resetConfirmed) { - delay(250); - // configClearSaved(); - dispatch_reboot(false); // Do not save the current config - } -} -#endif // HASP_USE_CONFIG - -void httpStart() -{ - webServer.begin(); - webServerStarted = true; -#if HASP_USE_WIFI > 0 -#if defined(STM32F4xx) - IPAddress ip; - ip = WiFi.localIP(); - LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); -#else - LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"), - (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); -#endif -#else - IPAddress ip; -#if defined(ARDUINO_ARCH_ESP32) - ip = ETH.localIP(); -#else - ip = Ethernet.localIP(); -#endif - LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); -#endif -} - -void httpStop() -{ - webServer.stop(); - webServerStarted = false; - LOG_WARNING(TAG_HTTP, F(D_SERVICE_STOPPED)); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void httpSetup() -{ - // httpSetConfig(settings); - - // ask server to track these headers - const char* headerkeys[] = {"Content-Length"}; // "Authentication" - size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); - webServer.collectHeaders(headerkeys, headerkeyssize); - - // Shared pages - webServer.on(F("/about"), webHandleAbout); - webServer.onNotFound(httpHandleNotFound); - -#if HASP_USE_WIFI > 0 -#if !defined(STM32F4xx) - -#if HASP_USE_CONFIG > 0 - if(WiFi.getMode() != WIFI_STA) { - LOG_TRACE(TAG_HTTP, F("Wifi access point")); - webServer.on(F("/"), webHandleWifiConfig); - webServer.on(F("/config"), webHandleConfig); - return; - } - -#endif -#endif -#endif - - webServer.on(F("/page/"), []() { - String pageid = webServer.arg(F("page")); - webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'"); - haspSetPage(pageid.toInt()); - }); - -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - webServer.on(F("/list"), HTTP_GET, handleFileList); - // load editor - webServer.on(F("/edit"), HTTP_GET, []() { - if(!handleFileRead("/edit.htm")) { - char mimetype[16]; - snprintf_P(mimetype, sizeof(mimetype), PSTR("text/plain")); - webServer.send_P(404, mimetype, PSTR("FileNotFound")); - } - }); - webServer.on(F("/edit"), HTTP_PUT, handleFileCreate); - webServer.on(F("/edit"), HTTP_DELETE, handleFileDelete); - // first callback is called after the request has ended with all parsed arguments - // second callback handles file uploads at that location - webServer.on( - F("/edit"), HTTP_POST, - []() { - webServer.send(200, "text/plain", ""); - LOG_VERBOSE(TAG_HTTP, F("Headers: %d"), webServer.headers()); - }, - handleFileUpload); -#endif - - webServer.on(F("/"), webHandleRoot); - webServer.on(F("/info"), webHandleInfo); - webServer.on(F("/screenshot"), webHandleScreenshot); - webServer.on(F("/firmware"), webHandleFirmware); - webServer.on(F("/reboot"), httpHandleReboot); - -#if HASP_USE_CONFIG > 0 - webServer.on(F("/config/hasp"), webHandleHaspConfig); - webServer.on(F("/config/http"), webHandleHttpConfig); - webServer.on(F("/config/gui"), webHandleGuiConfig); - webServer.on(F("/config/debug"), webHandleDebugConfig); -#if HASP_USE_MQTT > 0 - webServer.on(F("/config/mqtt"), webHandleMqttConfig); -#endif -#if HASP_USE_WIFI > 0 - webServer.on(F("/config/wifi"), webHandleWifiConfig); -#endif -#if HASP_USE_GPIO > 0 - webServer.on(F("/config/gpio"), webHandleGpioConfig); - webServer.on(F("/config/gpio/options"), webHandleGpioOptions); -#endif - webServer.on(F("/saveConfig"), webHandleSaveConfig); - webServer.on(F("/resetConfig"), httpHandleResetConfig); - webServer.on(F("/config"), webHandleConfig); -#endif // HASP_USE_CONFIG - -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - webServer.on( - F("/update"), HTTP_POST, - []() { - webServer.send(200, "text/plain", ""); - LOG_VERBOSE(TAG_HTTP, F("Total size: %s"), webServer.hostHeader().c_str()); - }, - webHandleFirmwareUpload); - webServer.on(F("/espfirmware"), httpHandleEspFirmware); -#endif - - LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED)); - // webStart(); Wait for network connection -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void httpReconnect() -{ - if(!http_config.enable) return; - - if(webServerStarted) { - httpStop(); - } else -#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) - if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA) -#endif - { - httpStart(); - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void httpLoop(void) -{ - if(http_config.enable) webServer.handleClient(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -void httpEvery5Seconds() -{ - // if(httpEnable && !webServerStarted) httpReconnect(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if HASP_USE_CONFIG > 0 -bool httpGetConfig(const JsonObject& settings) -{ - bool changed = false; - - settings[FPSTR(FP_CONFIG_ENABLE)] = http_config.enable; - - if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true; - settings[FPSTR(FP_CONFIG_PORT)] = http_config.port; - - if(strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true; - settings[FPSTR(FP_CONFIG_USER)] = http_config.user; - - if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true; - settings[FPSTR(FP_CONFIG_PASS)] = http_config.password; - - if(changed) configOutput(settings, TAG_HTTP); - return changed; -} - -/** Set HTTP Configuration. - * - * Read the settings from json and sets the application variables. - * - * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. - * - * @param[in] settings JsonObject with the config settings. - **/ -bool httpSetConfig(const JsonObject& settings) -{ - configOutput(settings, TAG_HTTP); - bool changed = false; - - changed |= configSet(http_config.port, settings[FPSTR(FP_CONFIG_PORT)], F("httpPort")); - - if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) { - changed |= strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)]) != 0; - strncpy(http_config.user, settings[FPSTR(FP_CONFIG_USER)], sizeof(http_config.user)); - } - - if(!settings[FPSTR(FP_CONFIG_PASS)].isNull()) { - changed |= strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)]) != 0; - strncpy(http_config.password, settings[FPSTR(FP_CONFIG_PASS)], sizeof(http_config.password)); - } - - return changed; -} -#endif // HASP_USE_CONFIG - -size_t httpClientWrite(const uint8_t* buf, size_t size) -{ - /***** Sending 16Kb at once freezes on STM32 EthernetClient *****/ - size_t bytes_sent = 0; - while(bytes_sent < size) { - if(!webServer.client()) return bytes_sent; - if(size - bytes_sent >= 2048) { - bytes_sent += webServer.client().write(buf + bytes_sent, 2048); - } else { - bytes_sent += webServer.client().write(buf + bytes_sent, size - bytes_sent); - } - // Serial.println(bytes_sent); - - // stm32_eth_scheduler(); // already in write - // webServer.client().flush(); - delay(1); // Fixes the freeze - } - return bytes_sent; -} - -#endif \ No newline at end of file diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 14c1e1d6..95232d91 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1940,7 +1940,7 @@ void httpSetup() // These two endpoints are needed in STA and AP mode webServer.on(F("/"), webHandleWifiConfig); - webServer.on(F("/config"), webHandleWifiConfig); + webServer.on(F("/config"), webHandleConfig); #if !defined(STM32F4xx) From 8b25b87b3fa673c6d716338dd0e8ec1f23d77db9 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 01:37:38 +0100 Subject: [PATCH 078/236] Update License header --- include/user_config_override-template.h | 2 +- src/dev/device.cpp | 2 +- src/dev/device.h | 2 +- src/dev/esp32/esp32.cpp | 2 +- src/dev/esp32/esp32.h | 2 +- src/dev/esp32/lanbonl8.cpp | 2 +- src/dev/esp32/lanbonl8.h | 2 +- src/dev/esp32/m5stackcore2.cpp | 2 +- src/dev/esp32/m5stackcore2.h | 2 +- src/dev/esp8266/esp8266.cpp | 2 +- src/dev/esp8266/esp8266.h | 2 +- src/dev/win32/hasp_win32.cpp | 2 +- src/dev/win32/hasp_win32.h | 2 +- src/drv/hasp_drv_display.cpp | 2 +- src/drv/hasp_drv_display.h | 10 +- src/drv/hasp_drv_touch.cpp | 2 +- src/drv/hasp_drv_touch.h | 6 +- src/drv/tft_driver.h | 2 +- src/drv/tft_driver_sdl2.h | 2 +- src/drv/tft_driver_tftesp.cpp | 2 +- src/drv/tft_driver_tftespi.h | 2 +- src/drv/tft_espi_drv.cpp | 2 +- src/drv/tft_espi_drv.h | 2 +- src/drv/touch/hasp_drv_ft5206.h | 4 +- src/drv/touch/hasp_drv_ft6336u.h | 4 +- src/drv/touch/hasp_drv_gt911.h | 4 +- src/drv/touch/hasp_drv_xpt2046.h | 22 +-- src/hal/hasp_hal.cpp | 16 +- src/hal/hasp_hal.h | 4 +- src/hasp/hasp.cpp | 2 +- src/hasp/hasp.h | 2 +- src/hasp/hasp_attribute.cpp | 185 ++++++++++++------------ src/hasp/hasp_attribute.h | 20 +-- src/hasp/hasp_dispatch.cpp | 2 +- src/hasp/hasp_dispatch.h | 2 +- src/hasp/hasp_object.cpp | 2 +- src/hasp/hasp_object.h | 32 ++-- src/hasp/hasp_parser.cpp | 6 +- src/hasp/hasp_parser.h | 4 +- src/hasp/hasp_utilities.h | 2 +- src/hasp_config.cpp | 164 ++++++++++----------- src/hasp_config.h | 26 ++-- src/hasp_debug.h | 2 +- src/hasp_eeprom.cpp | 16 +- src/hasp_eeprom.h | 4 +- src/hasp_filesystem.cpp | 44 +++--- src/hasp_filesystem.h | 26 ++-- src/hasp_gui.cpp | 2 +- src/hasp_gui.h | 2 +- src/hasp_oobe.cpp | 2 +- src/hasp_oobe.h | 4 +- src/log/hasp_debug.cpp | 2 +- src/main_arduino copy.cpp | 2 +- src/main_arduino.cpp | 2 +- src/main_windows.cpp | 2 +- src/mqtt/hasp_mqtt.h | 2 +- src/mqtt/hasp_mqtt_ha.cpp | 2 +- src/mqtt/hasp_mqtt_ha.h | 2 +- src/mqtt/hasp_mqtt_paho_async.cpp | 2 +- src/mqtt/hasp_mqtt_paho_single.cpp | 2 +- src/mqtt/hasp_mqtt_pubsubclient.cpp | 2 +- src/sys/gpio/hasp_gpio.cpp | 36 ++--- src/sys/gpio/hasp_gpio.h | 6 +- src/sys/net/hasp_ethernet_esp32.cpp | 2 +- src/sys/net/hasp_ethernet_esp32.h | 4 +- src/sys/net/hasp_ethernet_stm32.cpp | 26 ++-- src/sys/net/hasp_ethernet_stm32.h | 4 +- src/sys/net/hasp_network.cpp | 2 +- src/sys/net/hasp_network.h | 4 +- src/sys/net/hasp_wifi.cpp | 2 +- src/sys/net/hasp_wifi.h | 12 +- src/sys/svc/hasp_http.cpp | 2 +- src/sys/svc/hasp_http.h | 8 +- src/sys/svc/hasp_mdns.cpp | 2 +- src/sys/svc/hasp_mdns.h | 8 +- src/sys/svc/hasp_ota.cpp | 2 +- src/sys/svc/hasp_ota.h | 4 +- src/sys/svc/hasp_slave.cpp | 18 +-- src/sys/svc/hasp_slave.h | 10 +- src/sys/svc/hasp_telnet.cpp | 2 +- src/sys/svc/hasp_telnet.h | 6 +- 81 files changed, 422 insertions(+), 421 deletions(-) diff --git a/include/user_config_override-template.h b/include/user_config_override-template.h index 31d9b2c9..4d0d8806 100644 --- a/include/user_config_override-template.h +++ b/include/user_config_override-template.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ /*************************************************** diff --git a/src/dev/device.cpp b/src/dev/device.cpp index 7bee8627..dd5b7531 100644 --- a/src/dev/device.cpp +++ b/src/dev/device.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "device.h" diff --git a/src/dev/device.h b/src/dev/device.h index 13989e04..cafcec5d 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DEVICE_H diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index bde329ea..e3f55935 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if defined(ESP32) diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 5cdb4f90..8c445521 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DEVICE_ESP32_H diff --git a/src/dev/esp32/lanbonl8.cpp b/src/dev/esp32/lanbonl8.cpp index 39b7a182..f2f50ad9 100644 --- a/src/dev/esp32/lanbonl8.cpp +++ b/src/dev/esp32/lanbonl8.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "lanbonl8.h" diff --git a/src/dev/esp32/lanbonl8.h b/src/dev/esp32/lanbonl8.h index 3ec1fa93..f32e1fa4 100644 --- a/src/dev/esp32/lanbonl8.h +++ b/src/dev/esp32/lanbonl8.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DEVICE_LANBONL8_H diff --git a/src/dev/esp32/m5stackcore2.cpp b/src/dev/esp32/m5stackcore2.cpp index f4da47ab..11785afe 100644 --- a/src/dev/esp32/m5stackcore2.cpp +++ b/src/dev/esp32/m5stackcore2.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "m5stackcore2.h" diff --git a/src/dev/esp32/m5stackcore2.h b/src/dev/esp32/m5stackcore2.h index b41f4a6e..7bc48dd3 100644 --- a/src/dev/esp32/m5stackcore2.h +++ b/src/dev/esp32/m5stackcore2.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DEVICE_M5STACKCORE2_H diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index e21ca697..1bceb5f7 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if defined(ESP8266) diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 05a02e1a..39af24c6 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DEVICE_ESP8266_H diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index dd2c8906..6dc27817 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if defined(WINDOWS) diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index ae7015a0..2eb3614a 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DEVICE_WINDOWS_H diff --git a/src/drv/hasp_drv_display.cpp b/src/drv/hasp_drv_display.cpp index e9c18840..c0b569ed 100644 --- a/src/drv/hasp_drv_display.cpp +++ b/src/drv/hasp_drv_display.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_drv_display.h" diff --git a/src/drv/hasp_drv_display.h b/src/drv/hasp_drv_display.h index 75a26c63..78bdf4c2 100644 --- a/src/drv/hasp_drv_display.h +++ b/src/drv/hasp_drv_display.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DRV_DISPLAY_H @@ -8,12 +8,12 @@ // Select Display Driver #if defined(USE_FSMC) - #include "fsmc_ili9341.h" +#include "fsmc_ili9341.h" #else - #include "tft_espi_drv.h" +#include "tft_espi_drv.h" #endif -void drv_display_init(lv_disp_drv_t * disp_drv, uint8_t rotation, bool invert_display); -void drv_display_flush_cb(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p); +void drv_display_init(lv_disp_drv_t* disp_drv, uint8_t rotation, bool invert_display); +void drv_display_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); #endif \ No newline at end of file diff --git a/src/drv/hasp_drv_touch.cpp b/src/drv/hasp_drv_touch.cpp index f2ed5b33..a7a872e9 100644 --- a/src/drv/hasp_drv_touch.cpp +++ b/src/drv/hasp_drv_touch.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_drv_touch.h" diff --git a/src/drv/hasp_drv_touch.h b/src/drv/hasp_drv_touch.h index 6273ef71..f1b83f10 100644 --- a/src/drv/hasp_drv_touch.h +++ b/src/drv/hasp_drv_touch.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DRV_TOUCH_H @@ -7,11 +7,11 @@ #include "lvgl.h" #ifndef TOUCH_DRIVER - #define TOUCH_DRIVER -1 // No Touch +#define TOUCH_DRIVER -1 // No Touch #endif void drv_touch_init(uint8_t rotation); -bool drv_touch_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data); +bool drv_touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data); void drv_touch_loop(); #endif \ No newline at end of file diff --git a/src/drv/tft_driver.h b/src/drv/tft_driver.h index a44dfba4..a5193456 100644 --- a/src/drv/tft_driver.h +++ b/src/drv/tft_driver.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_BASE_TFT_DRIVER_H diff --git a/src/drv/tft_driver_sdl2.h b/src/drv/tft_driver_sdl2.h index 0419427a..f8d81554 100644 --- a/src/drv/tft_driver_sdl2.h +++ b/src/drv/tft_driver_sdl2.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_SDL2_DRIVER_H diff --git a/src/drv/tft_driver_tftesp.cpp b/src/drv/tft_driver_tftesp.cpp index 2928d035..4a4a74bc 100644 --- a/src/drv/tft_driver_tftesp.cpp +++ b/src/drv/tft_driver_tftesp.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifdef ARDUINO diff --git a/src/drv/tft_driver_tftespi.h b/src/drv/tft_driver_tftespi.h index 83ae4097..4cb29f70 100644 --- a/src/drv/tft_driver_tftespi.h +++ b/src/drv/tft_driver_tftespi.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_TFTESPI_DRIVER_H diff --git a/src/drv/tft_espi_drv.cpp b/src/drv/tft_espi_drv.cpp index 3ce1fce7..d005a380 100644 --- a/src/drv/tft_espi_drv.cpp +++ b/src/drv/tft_espi_drv.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ /********************* diff --git a/src/drv/tft_espi_drv.h b/src/drv/tft_espi_drv.h index c02607df..9f55e73f 100644 --- a/src/drv/tft_espi_drv.h +++ b/src/drv/tft_espi_drv.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef TFT_ESPI_DRV_H diff --git a/src/drv/touch/hasp_drv_ft5206.h b/src/drv/touch/hasp_drv_ft5206.h index 9f1d9786..1922d7cb 100644 --- a/src/drv/touch/hasp_drv_ft5206.h +++ b/src/drv/touch/hasp_drv_ft5206.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DRV_FT5206_H @@ -10,7 +10,7 @@ #include "hasp_debug.h" // for TAG_DRVR -bool FT5206_getXY(int16_t * touchX, int16_t * touchY, bool debug); +bool FT5206_getXY(int16_t* touchX, int16_t* touchY, bool debug); void FT5206_init(); #endif diff --git a/src/drv/touch/hasp_drv_ft6336u.h b/src/drv/touch/hasp_drv_ft6336u.h index 652ca87b..a52100e1 100644 --- a/src/drv/touch/hasp_drv_ft6336u.h +++ b/src/drv/touch/hasp_drv_ft6336u.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DRV_FT6336U_H @@ -8,7 +8,7 @@ #include "hasp_debug.h" // for TAG_DRVR -bool FT6336U_getXY(int16_t * touchX, int16_t * touchY, bool debug); +bool FT6336U_getXY(int16_t* touchX, int16_t* touchY, bool debug); void FT6336U_init(); #endif diff --git a/src/drv/touch/hasp_drv_gt911.h b/src/drv/touch/hasp_drv_gt911.h index 761ae081..727a84e7 100644 --- a/src/drv/touch/hasp_drv_gt911.h +++ b/src/drv/touch/hasp_drv_gt911.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DRV_911_H @@ -8,7 +8,7 @@ #include "hasp_debug.h" // for TAG_DRVR -bool GT911_getXY(int16_t * touchX, int16_t * touchY, bool debug); +bool GT911_getXY(int16_t* touchX, int16_t* touchY, bool debug); void GT911_init(); void GT911_loop(); diff --git a/src/drv/touch/hasp_drv_xpt2046.h b/src/drv/touch/hasp_drv_xpt2046.h index 188d31f7..e4217fa9 100644 --- a/src/drv/touch/hasp_drv_xpt2046.h +++ b/src/drv/touch/hasp_drv_xpt2046.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DRV_XPT2046B_H @@ -6,18 +6,18 @@ #if TOUCH_DRIVER == 0x2046B - #include "XPT2046_Touchscreen.h" +#include "XPT2046_Touchscreen.h" - #define XPT2046_HOR_RES TFT_WIDTH - #define XPT2046_VER_RES TFT_HEIGHT - #define XPT2046_X_MIN 200 - #define XPT2046_Y_MIN 200 - #define XPT2046_X_MAX 3800 - #define XPT2046_Y_MAX 3800 - #define XPT2046_AVG 4 - #define XPT2046_INV 0 +#define XPT2046_HOR_RES TFT_WIDTH +#define XPT2046_VER_RES TFT_HEIGHT +#define XPT2046_X_MIN 200 +#define XPT2046_Y_MIN 200 +#define XPT2046_X_MAX 3800 +#define XPT2046_Y_MAX 3800 +#define XPT2046_AVG 4 +#define XPT2046_INV 0 -bool XPT2046_getXY(int16_t * touchX, int16_t * touchY, bool debug); +bool XPT2046_getXY(int16_t* touchX, int16_t* touchY, bool debug); void XPT2046_init(); #endif diff --git a/src/hal/hasp_hal.cpp b/src/hal/hasp_hal.cpp index f2bea6a0..316f6ddf 100644 --- a/src/hal/hasp_hal.cpp +++ b/src/hal/hasp_hal.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_hal.h" @@ -26,7 +26,7 @@ String esp32ResetReason(uint8_t cpuid) } RESET_REASON reason = rtc_get_reset_reason(cpuid); - String resetReason((char *)0); + String resetReason((char*)0); resetReason.reserve(128); resetReason += F("CPU"); @@ -102,7 +102,7 @@ void halRestartMcu(void) String halGetResetInfo() { #if defined(ARDUINO_ARCH_ESP32) - String resetReason((char *)0); + String resetReason((char*)0); resetReason.reserve(128); resetReason += String(esp32ResetReason(0)); @@ -129,7 +129,7 @@ String halGetCoreVersion() String halGetChipModel() { - String model((char *)0); + String model((char*)0); model.reserve(128); #if defined(STM32F4xx) @@ -181,7 +181,7 @@ int freeHighMemory() { char top; #ifdef __arm__ - return &top - reinterpret_cast(sbrk(0)); + return &top - reinterpret_cast(sbrk(0)); #elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151) return &top - __brkval; #else // __arm__ @@ -254,12 +254,12 @@ uint8_t halGetHeapFragmentation() #endif } -String halGetMacAddress(int start, const char * seperator) +String halGetMacAddress(int start, const char* seperator) { byte mac[6]; #if defined(STM32F4xx) - uint8_t * mac_p = nullptr; + uint8_t* mac_p = nullptr; #if HASP_USE_ETHERNET > 0 #if USE_BUILTIN_ETHERNET > 0 mac_p = Ethernet.MACAddress(); @@ -272,7 +272,7 @@ String halGetMacAddress(int start, const char * seperator) WiFi.macAddress(mac); #endif - String cMac((char *)0); + String cMac((char*)0); cMac.reserve(32); for(int i = start; i < 6; ++i) { diff --git a/src/hal/hasp_hal.h b/src/hal/hasp_hal.h index 0ccd03df..3a8d5860 100644 --- a/src/hal/hasp_hal.h +++ b/src/hal/hasp_hal.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_HAL_H @@ -13,7 +13,7 @@ String halGetResetInfo(void); // size_t halGetFreeHeap(void); String halGetCoreVersion(void); String halGetChipModel(); -String halGetMacAddress(int start, const char * seperator); +String halGetMacAddress(int start, const char* seperator); // uint16_t halGetCpuFreqMHz(void); String halDisplayDriverName(void); String halGpioName(uint8_t gpio); diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 3437ff04..cb9f21d8 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifdef ARDUINO diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index d7bc4eaa..986eefc8 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_H diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index a5f6bab7..b2313255 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1,13 +1,13 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifdef ARDUINO - #include "ArduinoLog.h" +#include "ArduinoLog.h" #endif #include "lvgl.h" #if LVGL_VERSION_MAJOR != 7 - #include "../lv_components.h" +#include "../lv_components.h" #endif #include "hasp.h" @@ -18,8 +18,8 @@ #include "hasp_parser.h" LV_FONT_DECLARE(unscii_8_icon); -extern lv_font_t * haspFonts[8]; -extern const char ** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map +extern lv_font_t* haspFonts[8]; +extern const char** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map #if 0 static bool attribute_lookup_lv_property(uint16_t hash, uint8_t * prop) @@ -111,20 +111,20 @@ static bool attribute_lookup_lv_property(uint16_t hash, uint8_t * prop) {ATTR_TRANSITION_PATH, LV_STYLE_TRANSITION_PATH & LV_STYLE_PROP_ALL}, {ATTR_VALUE_STR, LV_STYLE_VALUE_STR & LV_STYLE_PROP_ALL}, - #if LV_USE_SHADOW +#if LV_USE_SHADOW {ATTR_SHADOW_WIDTH, LV_STYLE_SHADOW_WIDTH & LV_STYLE_PROP_ALL}, {ATTR_SHADOW_OFS_X, LV_STYLE_SHADOW_OFS_X & LV_STYLE_PROP_ALL}, {ATTR_SHADOW_OFS_Y, LV_STYLE_SHADOW_OFS_Y & LV_STYLE_PROP_ALL}, {ATTR_SHADOW_SPREAD, LV_STYLE_SHADOW_SPREAD & LV_STYLE_PROP_ALL}, {ATTR_SHADOW_COLOR, LV_STYLE_SHADOW_COLOR & LV_STYLE_PROP_ALL}, {ATTR_SHADOW_OPA, LV_STYLE_SHADOW_OPA & LV_STYLE_PROP_ALL}, - #endif +#endif - #if LV_USE_BLEND_MODES && LV_USE_SHADOW +#if LV_USE_BLEND_MODES && LV_USE_SHADOW {ATTR_SHADOW_BLEND_MODE, LV_STYLE_SHADOW_BLEND_MODE & LV_STYLE_PROP_ALL}, - #endif +#endif - #if LV_USE_BLEND_MODES +#if LV_USE_BLEND_MODES {ATTR_BG_BLEND_MODE, LV_STYLE_BG_BLEND_MODE & LV_STYLE_PROP_ALL}, {ATTR_PATTERN_BLEND_MODE, LV_STYLE_PATTERN_BLEND_MODE & LV_STYLE_PROP_ALL}, {ATTR_IMAGE_BLEND_MODE, LV_STYLE_IMAGE_BLEND_MODE & LV_STYLE_PROP_ALL}, @@ -133,7 +133,7 @@ static bool attribute_lookup_lv_property(uint16_t hash, uint8_t * prop) {ATTR_OUTLINE_BLEND_MODE, LV_STYLE_OUTLINE_BLEND_MODE & LV_STYLE_PROP_ALL}, {ATTR_VALUE_BLEND_MODE, LV_STYLE_VALUE_BLEND_MODE & LV_STYLE_PROP_ALL}, {ATTR_TEXT_BLEND_MODE, LV_STYLE_TEXT_BLEND_MODE & LV_STYLE_PROP_ALL}, - #endif +#endif }; for(uint32_t i = 0; i < sizeof(props) / sizeof(props[0]); i++) { @@ -185,9 +185,9 @@ static bool attribute_update_lv_property(lv_obj_t * obj, const char * attr_p, ui #endif // OK - this function is missing in lvgl -static uint8_t my_roller_get_visible_row_count(lv_obj_t * roller) +static uint8_t my_roller_get_visible_row_count(lv_obj_t* roller) { - const lv_font_t * font = lv_obj_get_style_text_font(roller, LV_ROLLER_PART_BG); + const lv_font_t* font = lv_obj_get_style_text_font(roller, LV_ROLLER_PART_BG); lv_style_int_t line_space = lv_obj_get_style_text_line_space(roller, LV_ROLLER_PART_BG); lv_coord_t h = lv_obj_get_height(roller); @@ -198,32 +198,32 @@ static uint8_t my_roller_get_visible_row_count(lv_obj_t * roller) } // OK - this function is missing in lvgl -static inline int16_t my_arc_get_rotation(lv_obj_t * arc) +static inline int16_t my_arc_get_rotation(lv_obj_t* arc) { - lv_arc_ext_t * ext = (lv_arc_ext_t *)lv_obj_get_ext_attr(arc); + lv_arc_ext_t* ext = (lv_arc_ext_t*)lv_obj_get_ext_attr(arc); return ext->rotation_angle; } // OK - this function is missing in lvgl -static inline int16_t my_chart_get_min_value(lv_obj_t * chart) +static inline int16_t my_chart_get_min_value(lv_obj_t* chart) { - lv_chart_ext_t * ext = (lv_chart_ext_t *)lv_obj_get_ext_attr(chart); + lv_chart_ext_t* ext = (lv_chart_ext_t*)lv_obj_get_ext_attr(chart); return ext->ymin[LV_CHART_AXIS_PRIMARY_Y]; } // OK - this function is missing in lvgl -static inline int16_t my_chart_get_max_value(lv_obj_t * chart) +static inline int16_t my_chart_get_max_value(lv_obj_t* chart) { - lv_chart_ext_t * ext = (lv_chart_ext_t *)lv_obj_get_ext_attr(chart); + lv_chart_ext_t* ext = (lv_chart_ext_t*)lv_obj_get_ext_attr(chart); return ext->ymax[LV_CHART_AXIS_PRIMARY_Y]; } -lv_chart_series_t * my_chart_get_series(lv_obj_t * chart, uint8_t ser_num) +lv_chart_series_t* my_chart_get_series(lv_obj_t* chart, uint8_t ser_num) { - lv_chart_ext_t * ext = (lv_chart_ext_t *)lv_obj_get_ext_attr(chart); - lv_chart_series_t * ser = (lv_chart_series_t *)_lv_ll_get_tail(&ext->series_ll); + lv_chart_ext_t* ext = (lv_chart_ext_t*)lv_obj_get_ext_attr(chart); + lv_chart_series_t* ser = (lv_chart_series_t*)_lv_ll_get_tail(&ext->series_ll); while(ser_num > 0 && ser) { - ser = (lv_chart_series_t *)_lv_ll_get_prev(&ext->series_ll, ser); + ser = (lv_chart_series_t*)_lv_ll_get_prev(&ext->series_ll, ser); ser_num--; } return ser; @@ -234,11 +234,11 @@ lv_chart_series_t * my_chart_get_series(lv_obj_t * chart, uint8_t ser_num) * @param obj pointer to a object * @param text '\0' terminated character string. NULL to refresh with the current text. */ -void my_obj_set_value_str_txt(lv_obj_t * obj, uint8_t part, lv_state_t state, const char * text) +void my_obj_set_value_str_txt(lv_obj_t* obj, uint8_t part, lv_state_t state, const char* text) { // LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); - const void * value_str_p = lv_obj_get_style_value_str(obj, part); + const void* value_str_p = lv_obj_get_style_value_str(obj, part); lv_obj_invalidate(obj); if(text == NULL || text[0] == 0) { @@ -257,13 +257,13 @@ void my_obj_set_value_str_txt(lv_obj_t * obj, uint8_t part, lv_state_t state, co /*Allocate space for the new text*/ // LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); - value_str_p = (char *)lv_mem_alloc(len); + value_str_p = (char*)lv_mem_alloc(len); LV_ASSERT_MEM(value_str_p); if(value_str_p == NULL) return; // LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); - strncpy((char *)value_str_p, text, len); - lv_obj_set_style_local_value_str(obj, part, state, (char *)value_str_p); + strncpy((char*)value_str_p, text, len); + lv_obj_set_style_local_value_str(obj, part, state, (char*)value_str_p); // LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); return; } @@ -294,17 +294,17 @@ void my_obj_set_value_str_txt(lv_obj_t * obj, uint8_t part, lv_state_t state, co /*Allocate space for the new text*/ value_str_p = lv_mem_alloc(len); LV_ASSERT_MEM(value_str_p); - if(value_str_p != NULL) strcpy((char *)value_str_p, text); - lv_obj_set_style_local_value_str(obj, part, state, (char *)value_str_p); + if(value_str_p != NULL) strcpy((char*)value_str_p, text); + lv_obj_set_style_local_value_str(obj, part, state, (char*)value_str_p); } // LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); } -void my_btnmatrix_map_clear(lv_obj_t * obj) +void my_btnmatrix_map_clear(lv_obj_t* obj) { - lv_btnmatrix_ext_t * ext = (lv_btnmatrix_ext_t *)lv_obj_get_ext_attr(obj); - const char ** map_p_tmp = ext->map_p; // store current pointer + lv_btnmatrix_ext_t* ext = (lv_btnmatrix_ext_t*)lv_obj_get_ext_attr(obj); + const char** map_p_tmp = ext->map_p; // store current pointer LOG_VERBOSE(TAG_ATTR, "%s %d %x btn_cnt: %d", __FILE__, __LINE__, map_p_tmp, ext->btn_cnt); @@ -326,9 +326,9 @@ void my_btnmatrix_map_clear(lv_obj_t * obj) } } -static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload) +static void my_btnmatrix_map_create(lv_obj_t* obj, const char* payload) { - const char ** map_p = lv_btnmatrix_get_map_array(obj); + const char** map_p = lv_btnmatrix_get_map_array(obj); // Create new map // Reserve memory for JsonDocument @@ -343,8 +343,8 @@ static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload) JsonArray arr = map_doc.as(); // Parse payload - size_t tot_len = sizeof(char *) * (arr.size() + 1); - const char ** map_data_str = (const char **)lv_mem_alloc(tot_len); + size_t tot_len = sizeof(char*) * (arr.size() + 1); + const char** map_data_str = (const char**)lv_mem_alloc(tot_len); if(map_data_str == NULL) { LOG_ERROR(TAG_ATTR, F("Out of memory while creating button map")); return; @@ -355,12 +355,12 @@ static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload) tot_len = 0; for(JsonVariant btn : arr) { // tot_len += btn.as().length() + 1; - tot_len += strlen(btn.as()) + 1; + tot_len += strlen(btn.as()) + 1; } tot_len++; // trailing '\0' LOG_VERBOSE(TAG_ATTR, F("Array Size = %d, Map Length = %d"), arr.size(), tot_len); - char * buffer_addr = (char *)lv_mem_alloc(tot_len); + char* buffer_addr = (char*)lv_mem_alloc(tot_len); if(buffer_addr == NULL) { lv_mem_free(map_data_str); LOG_ERROR(TAG_ATTR, F("Out of memory while creating button map")); @@ -378,12 +378,12 @@ static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload) LOG_VERBOSE(TAG_ATTR, F("%s %d lbl addr: %x"), __FILE__, __LINE__, buffer_addr); for(JsonVariant btn : arr) { // size_t len = btn.as().length() + 1; - size_t len = strlen(btn.as()) + 1; - LOG_VERBOSE(TAG_ATTR, F(D_BULLET "Adding button: %s (%d bytes) %x"), btn.as(), len, + size_t len = strlen(btn.as()) + 1; + LOG_VERBOSE(TAG_ATTR, F(D_BULLET "Adding button: %s (%d bytes) %x"), btn.as(), len, buffer_addr + pos); // LOG_VERBOSE(TAG_ATTR, F(D_BULLET "Adding button: %s (%d bytes) %x"), btn.as().c_str(), len, // buffer_addr + pos); - memccpy(buffer_addr + pos, btn.as(), 0, len); // Copy the label text into the buffer + memccpy(buffer_addr + pos, btn.as(), 0, len); // Copy the label text into the buffer // memccpy(buffer_addr + pos, btn.as().c_str(), 0, len); // Copy the label text into the buffer map_data_str[index++] = buffer_addr + pos; // save pointer to the label in the array pos += len; @@ -395,17 +395,17 @@ static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload) LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); } -void line_clear_points(lv_obj_t * obj) +void line_clear_points(lv_obj_t* obj) { - lv_line_ext_t * ext = (lv_line_ext_t *)lv_obj_get_ext_attr(obj); + lv_line_ext_t* ext = (lv_line_ext_t*)lv_obj_get_ext_attr(obj); if(ext->point_array && (ext->point_num > 0)) { - const lv_point_t * ptr = ext->point_array; + const lv_point_t* ptr = ext->point_array; lv_line_set_points(obj, NULL, 0); lv_mem_free(ptr); } } -static void line_set_points(lv_obj_t * obj, const char * payload) +static void line_set_points(lv_obj_t* obj, const char* payload) { line_clear_points(obj); // delete pointmap @@ -422,8 +422,8 @@ static void line_set_points(lv_obj_t * obj, const char * payload) JsonArray arr = doc.as(); // Parse payload - size_t tot_len = sizeof(lv_point_t *) * (arr.size()); - lv_point_t * point_arr = (lv_point_t *)lv_mem_alloc(tot_len); + size_t tot_len = sizeof(lv_point_t*) * (arr.size()); + lv_point_t* point_arr = (lv_point_t*)lv_mem_alloc(tot_len); if(point_arr == NULL) { LOG_ERROR(TAG_ATTR, F("Out of memory while creating line points")); return; @@ -454,7 +454,7 @@ static inline lv_color_t haspLogColor(lv_color_t color) return color; } -static lv_font_t * haspPayloadToFont(const char * payload) +static lv_font_t* haspPayloadToFont(const char* payload) { uint8_t var = atoi(payload); @@ -470,25 +470,25 @@ static lv_font_t * haspPayloadToFont(const char * payload) #ifndef ARDUINO_ARCH_ESP8266 - #ifdef LV_FONT_CUSTOM_12 +#ifdef LV_FONT_CUSTOM_12 case 12: return LV_THEME_DEFAULT_FONT_SMALL; - #endif +#endif - #ifdef LV_FONT_CUSTOM_16 +#ifdef LV_FONT_CUSTOM_16 case 16: return LV_THEME_DEFAULT_FONT_NORMAL; - #endif +#endif - #ifdef LV_FONT_CUSTOM_22 +#ifdef LV_FONT_CUSTOM_22 case 22: return LV_THEME_DEFAULT_FONT_SUBTITLE; - #endif +#endif - #ifdef LV_FONT_CUSTOM_28 +#ifdef LV_FONT_CUSTOM_28 case 28: return LV_THEME_DEFAULT_FONT_TITLE; - #endif +#endif #endif @@ -497,27 +497,27 @@ static lv_font_t * haspPayloadToFont(const char * payload) } } -static void gauge_format_10(lv_obj_t * gauge, char * buf, int bufsize, int32_t value) +static void gauge_format_10(lv_obj_t* gauge, char* buf, int bufsize, int32_t value) { snprintf(buf, bufsize, PSTR("%d"), value / 10); } -static void gauge_format_100(lv_obj_t * gauge, char * buf, int bufsize, int32_t value) +static void gauge_format_100(lv_obj_t* gauge, char* buf, int bufsize, int32_t value) { snprintf(buf, bufsize, PSTR("%d"), value / 100); } -static void gauge_format_1k(lv_obj_t * gauge, char * buf, int bufsize, int32_t value) +static void gauge_format_1k(lv_obj_t* gauge, char* buf, int bufsize, int32_t value) { snprintf(buf, bufsize, PSTR("%d"), value / 1000); } -static void gauge_format_10k(lv_obj_t * gauge, char * buf, int bufsize, int32_t value) +static void gauge_format_10k(lv_obj_t* gauge, char* buf, int bufsize, int32_t value) { snprintf(buf, bufsize, PSTR("%d"), value / 10000); } -static void hasp_process_label_long_mode(lv_obj_t * obj, const char * payload, bool update) +static void hasp_process_label_long_mode(lv_obj_t* obj, const char* payload, bool update) { if(update) { lv_label_long_mode_t mode = LV_LABEL_LONG_EXPAND; @@ -545,10 +545,10 @@ static void hasp_process_label_long_mode(lv_obj_t * obj, const char * payload, b } // OK -lv_obj_t * FindButtonLabel(lv_obj_t * btn) +lv_obj_t* FindButtonLabel(lv_obj_t* btn) { if(btn) { - lv_obj_t * label = lv_obj_get_child_back(btn, NULL); + lv_obj_t* label = lv_obj_get_child_back(btn, NULL); #if 1 if(label) { if(check_obj_type(label, LV_HASP_LABEL)) { @@ -558,7 +558,7 @@ lv_obj_t * FindButtonLabel(lv_obj_t * btn) if(label) { lv_obj_type_t list; lv_obj_get_type(label, &list); - const char * objtype = list.type[0]; + const char* objtype = list.type[0]; if(check_obj_type(objtype, LV_HASP_LABEL)) { return label; @@ -575,23 +575,23 @@ lv_obj_t * FindButtonLabel(lv_obj_t * btn) } // OK -static inline void haspSetLabelText(lv_obj_t * obj, const char * value) +static inline void haspSetLabelText(lv_obj_t* obj, const char* value) { - lv_obj_t * label = FindButtonLabel(obj); + lv_obj_t* label = FindButtonLabel(obj); if(label) { lv_label_set_text(label, value); } } // OK -static bool haspGetLabelText(lv_obj_t * obj, char ** text) +static bool haspGetLabelText(lv_obj_t* obj, char** text) { if(!obj) { LOG_WARNING(TAG_ATTR, F("Button not defined")); return false; } - lv_obj_t * label = lv_obj_get_child_back(obj, NULL); + lv_obj_t* label = lv_obj_get_child_back(obj, NULL); if(label) { #if 1 if(check_obj_type(label, LV_HASP_LABEL)) { @@ -615,8 +615,8 @@ static bool haspGetLabelText(lv_obj_t * obj, char ** text) return false; } -static void hasp_attribute_get_part_state(lv_obj_t * obj, const char * attr_in, char * attr_out, uint8_t & part, - uint8_t & state) +static void hasp_attribute_get_part_state(lv_obj_t* obj, const char* attr_in, char* attr_out, uint8_t& part, + uint8_t& state) { int len = strlen(attr_in); if(len <= 0 || len >= 32) { @@ -668,7 +668,7 @@ static void hasp_attribute_get_part_state(lv_obj_t * obj, const char * attr_in, (LV_SLIDER_PART_BG != LV_SWITCH_PART_BG) || (LV_SLIDER_PART_INDIC != LV_ARC_PART_INDIC) || \ (LV_SLIDER_PART_KNOB != LV_ARC_PART_KNOB) || (LV_SLIDER_PART_BG != LV_ARC_PART_BG) || \ (LV_SLIDER_PART_INDIC != LV_BAR_PART_INDIC) || (LV_SLIDER_PART_BG != LV_BAR_PART_BG) - #error "LV_SLIDER, LV_BAR, LV_ARC, LV_SWITCH parts should match!" +#error "LV_SLIDER, LV_BAR, LV_ARC, LV_SWITCH parts should match!" #endif if(check_obj_type(obj, LV_HASP_SLIDER) || check_obj_type(obj, LV_HASP_SWITCH) || check_obj_type(obj, LV_HASP_ARC) || @@ -719,7 +719,7 @@ static void hasp_attribute_get_part_state(lv_obj_t * obj, const char * attr_in, * @param update bool: change/set the value if true, dispatch/get value if false * @note setting a value won't return anything, getting will dispatch the value */ -static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t attr_hash, const char * payload, +static void hasp_local_style_attr(lv_obj_t* obj, const char* attr_p, uint16_t attr_hash, const char* payload, bool update) { char attr[32]; @@ -857,7 +857,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t return; } case ATTR_TEXT_FONT: { - lv_font_t * font = haspPayloadToFont(payload); + lv_font_t* font = haspPayloadToFont(payload); if(font) { uint8_t count = 3; if(check_obj_type(obj, LV_HASP_ROLLER)) count = my_roller_get_visible_row_count(obj); @@ -1015,7 +1015,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t return; } case ATTR_VALUE_FONT: { - lv_font_t * font = haspPayloadToFont(payload); + lv_font_t* font = haspPayloadToFont(payload); if(font) { return lv_obj_set_style_local_value_font(obj, part, state, font); } else { @@ -1058,14 +1058,14 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_UNKNOWN " (%d)"), attr_p, attr_hash); } -static void hasp_process_arc_attribute(lv_obj_t * obj, const char * attr_p, uint16_t attr_hash, const char * payload, +static void hasp_process_arc_attribute(lv_obj_t* obj, const char* attr_p, uint16_t attr_hash, const char* payload, bool update) { // We already know it's a arc object int16_t intval = atoi(payload); uint16_t val = atoi(payload); - char * attr = (char *)attr_p; + char* attr = (char*)attr_p; if(*attr == '.') attr++; // strip leading '.' switch(attr_hash) { @@ -1102,7 +1102,7 @@ static void hasp_process_arc_attribute(lv_obj_t * obj, const char * attr_p, uint LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_UNKNOWN), attr_p); } -static void hasp_process_lmeter_attribute(lv_obj_t * obj, const char * attr_p, uint16_t attr_hash, const char * payload, +static void hasp_process_lmeter_attribute(lv_obj_t* obj, const char* attr_p, uint16_t attr_hash, const char* payload, bool update) { // We already know it's a linemeter object @@ -1112,7 +1112,7 @@ static void hasp_process_lmeter_attribute(lv_obj_t * obj, const char * attr_p, u uint16_t line_count = lv_linemeter_get_line_count(obj); uint16_t angle = lv_linemeter_get_scale_angle(obj); - char * attr = (char *)attr_p; + char* attr = (char*)attr_p; if(*attr == '.') attr++; // strip leading '.' switch(attr_hash) { @@ -1134,7 +1134,7 @@ static void hasp_process_lmeter_attribute(lv_obj_t * obj, const char * attr_p, u LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_UNKNOWN), attr_p); } -static void hasp_process_gauge_attribute(lv_obj_t * obj, const char * attr_p, uint16_t attr_hash, const char * payload, +static void hasp_process_gauge_attribute(lv_obj_t* obj, const char* attr_p, uint16_t attr_hash, const char* payload, bool update) { // We already know it's a gauge object @@ -1145,7 +1145,7 @@ static void hasp_process_gauge_attribute(lv_obj_t * obj, const char * attr_p, ui uint16_t line_count = lv_gauge_get_line_count(obj); uint16_t angle = lv_gauge_get_scale_angle(obj); - char * attr = (char *)attr_p; + char* attr = (char*)attr_p; if(*attr == '.') attr++; // strip leading '.' switch(attr_hash) { @@ -1193,7 +1193,7 @@ static void hasp_process_gauge_attribute(lv_obj_t * obj, const char * attr_p, ui // ##################### Common Attributes ######################################################## -static void hasp_process_obj_attribute_txt(lv_obj_t * obj, const char * attr, const char * payload, bool update) +static void hasp_process_obj_attribute_txt(lv_obj_t* obj, const char* attr, const char* payload, bool update) { /* Attributes depending on objecttype */ // lv_obj_type_t list; @@ -1204,7 +1204,7 @@ static void hasp_process_obj_attribute_txt(lv_obj_t * obj, const char * attr, co if(update) { haspSetLabelText(obj, payload); } else { - char * text = NULL; + char* text = NULL; if(haspGetLabelText(obj, &text) && text) hasp_out_str(obj, attr, text); } return; @@ -1235,7 +1235,7 @@ static void hasp_process_obj_attribute_txt(lv_obj_t * obj, const char * attr, co LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_UNKNOWN), attr); } -bool hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, const char * payload, bool update) +bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, const char* payload, bool update) { int16_t intval = atoi(payload); @@ -1283,7 +1283,7 @@ bool hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, const cha return true; } -static void hasp_process_obj_attribute_range(lv_obj_t * obj, const char * attr, const char * payload, bool update, +static void hasp_process_obj_attribute_range(lv_obj_t* obj, const char* attr, const char* payload, bool update, bool set_min, bool set_max) { int16_t val = atoi(payload); @@ -1355,7 +1355,7 @@ static void hasp_process_obj_attribute_range(lv_obj_t * obj, const char * attr, * @param update bool: change/set the value if true, dispatch/get value if false * @note setting a value won't return anything, getting will dispatch the value */ -void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char * payload, bool update) +void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* payload, bool update) { // unsigned long start = millis(); if(!obj) { @@ -1364,7 +1364,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char } int16_t val = atoi(payload); - char * attr = (char *)attr_p; + char* attr = (char*)attr_p; if(*attr == '.') attr++; // strip leading '.' uint16_t attr_hash = Utilities::get_sdbm(attr); @@ -1471,7 +1471,8 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char break; // attribute_found case ATTR_ENABLED: - update ? lv_obj_set_click(obj, Utilities::is_true(payload)) : hasp_out_int(obj, attr, lv_obj_get_click(obj)); + update ? lv_obj_set_click(obj, Utilities::is_true(payload)) + : hasp_out_int(obj, attr, lv_obj_get_click(obj)); break; // attribute_found case ATTR_SRC: @@ -1483,7 +1484,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char case LV_IMG_SRC_FILE: return hasp_out_str(obj, attr, lv_img_get_file_name(obj)); case LV_IMG_SRC_SYMBOL: - return hasp_out_str(obj, attr, (char *)lv_img_get_src(obj)); + return hasp_out_str(obj, attr, (char*)lv_img_get_src(obj)); default: return; } @@ -1521,7 +1522,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char case ATTR_ALIGN: if(check_obj_type(obj, LV_HASP_BUTTON)) { - lv_obj_t * label = FindButtonLabel(obj); + lv_obj_t* label = FindButtonLabel(obj); if(label == NULL) goto attribute_not_found; else @@ -1540,7 +1541,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char case ATTR_MODE: if(check_obj_type(obj, LV_HASP_BUTTON)) { - lv_obj_t * label = FindButtonLabel(obj); + lv_obj_t* label = FindButtonLabel(obj); if(label) { hasp_process_label_long_mode(label, payload, update); lv_obj_set_width(label, lv_obj_get_width(obj)); @@ -1575,7 +1576,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char } } else if(check_obj_type(obj, LV_HASP_ROLLER)) { if(update) { - lv_roller_ext_t * ext = (lv_roller_ext_t *)lv_obj_get_ext_attr(obj); + lv_roller_ext_t* ext = (lv_roller_ext_t*)lv_obj_get_ext_attr(obj); lv_roller_set_options(obj, payload, ext->mode); } else { hasp_out_str(obj, attr, lv_roller_get_options(obj)); diff --git a/src/hasp/hasp_attribute.h b/src/hasp/hasp_attribute.h index 7273cd21..ff8ccf50 100644 --- a/src/hasp/hasp_attribute.h +++ b/src/hasp/hasp_attribute.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_ATTR_SET_H @@ -6,7 +6,7 @@ #include "lvgl.h" #if LVGL_VERSION_MAJOR != 7 - #include "../lv_components.h" +#include "../lv_components.h" #endif #include "hasp_conf.h" @@ -18,14 +18,14 @@ extern "C" { #endif // test -lv_chart_series_t * my_chart_get_series(lv_obj_t * chart, uint8_t ser_num); -void my_obj_set_value_str_txt(lv_obj_t * obj, uint8_t part, lv_state_t state, const char * text); +lv_chart_series_t* my_chart_get_series(lv_obj_t* chart, uint8_t ser_num); +void my_obj_set_value_str_txt(lv_obj_t* obj, uint8_t part, lv_state_t state, const char* text); -void my_btnmatrix_map_clear(lv_obj_t * obj); -void line_clear_points(lv_obj_t * obj); +void my_btnmatrix_map_clear(lv_obj_t* obj); +void line_clear_points(lv_obj_t* obj); -void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char * payload, bool update); -bool hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, const char * payload, bool update); +void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* payload, bool update); +bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, const char* payload, bool update); #ifdef __cplusplus } /* extern "C" */ @@ -37,8 +37,8 @@ bool hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, const cha #define hasp_out_color hasp_send_obj_attribute_color #define _HASP_ATTRIBUTE(prop_name, func_name, value_type) \ - static inline void attribute_##func_name(lv_obj_t * obj, uint8_t part, lv_state_t state, bool update, \ - const char * attr, value_type val) \ + static inline void attribute_##func_name(lv_obj_t* obj, uint8_t part, lv_state_t state, bool update, \ + const char* attr, value_type val) \ { \ if(update) { \ return lv_obj_set_style_local_##func_name(obj, part, state, (value_type)val); \ diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 9484ff4b..4e6a360a 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 254c1d0d..39f8cacc 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DISPATCH_H diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 68312705..6fa91a78 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ /* ******************************************************************************************** diff --git a/src/hasp/hasp_object.h b/src/hasp/hasp_object.h index 012e4782..e280883a 100644 --- a/src/hasp/hasp_object.h +++ b/src/hasp/hasp_object.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_OBJECT_H @@ -60,27 +60,27 @@ enum lv_hasp_obj_type_t { LV_HASP_MASK = 63, // placeholder }; -void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id); +void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id); -lv_obj_t * hasp_find_obj_from_parent_id(lv_obj_t * parent, uint8_t objid); +lv_obj_t* hasp_find_obj_from_parent_id(lv_obj_t* parent, uint8_t objid); // lv_obj_t * hasp_find_obj_from_page_id(uint8_t pageid, uint8_t objid); -bool hasp_find_id_from_obj(lv_obj_t * obj, uint8_t * pageid, uint8_t * objid); +bool hasp_find_id_from_obj(lv_obj_t* obj, uint8_t* pageid, uint8_t* objid); // bool check_obj_type_str(const char * lvobjtype, lv_hasp_obj_type_t haspobjtype); -bool check_obj_type(lv_obj_t * obj, lv_hasp_obj_type_t haspobjtype); -void hasp_object_tree(lv_obj_t * parent, uint8_t pageid, uint16_t level); -void hasp_object_delete(lv_obj_t * obj); +bool check_obj_type(lv_obj_t* obj, lv_hasp_obj_type_t haspobjtype); +void hasp_object_tree(lv_obj_t* parent, uint8_t pageid, uint16_t level); +void hasp_object_delete(lv_obj_t* obj); -void hasp_send_obj_attribute_str(lv_obj_t * obj, const char * attribute, const char * data); -void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t val); -void hasp_send_obj_attribute_color(lv_obj_t * obj, const char * attribute, lv_color_t color); -void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, const char * payload); +void hasp_send_obj_attribute_str(lv_obj_t* obj, const char* attribute, const char* data); +void hasp_send_obj_attribute_int(lv_obj_t* obj, const char* attribute, int32_t val); +void hasp_send_obj_attribute_color(lv_obj_t* obj, const char* attribute, lv_color_t color); +void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload); -void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t * src_obj); +void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t* src_obj); -void generic_event_handler(lv_obj_t * obj, lv_event_t event); -void toggle_event_handler(lv_obj_t * obj, lv_event_t event); -void slider_event_handler(lv_obj_t * obj, lv_event_t event); -void wakeup_event_handler(lv_obj_t * obj, lv_event_t event); +void generic_event_handler(lv_obj_t* obj, lv_event_t event); +void toggle_event_handler(lv_obj_t* obj, lv_event_t event); +void slider_event_handler(lv_obj_t* obj, lv_event_t event); +void wakeup_event_handler(lv_obj_t* obj, lv_event_t event); #define HASP_OBJ_BAR 1971 #define HASP_OBJ_BTN 3164 diff --git a/src/hasp/hasp_parser.cpp b/src/hasp/hasp_parser.cpp index af46a4ec..6742b1f7 100644 --- a/src/hasp/hasp_parser.cpp +++ b/src/hasp/hasp_parser.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include @@ -13,13 +13,13 @@ #include "hasp_parser.h" #include "hasp_utilities.h" -bool Parser::haspPayloadToColor(const char * payload, lv_color32_t & color) +bool Parser::haspPayloadToColor(const char* payload, lv_color32_t& color) { /* HEX format #rrggbb or #rgb */ if(*payload == '#') { if(strlen(payload) >= 8) return false; - char * pEnd; + char* pEnd; long color_int = strtol(payload + 1, &pEnd, HEX); if(pEnd - payload == 7) { // #rrbbgg diff --git a/src/hasp/hasp_parser.h b/src/hasp/hasp_parser.h index 2ffc058c..d0697a17 100644 --- a/src/hasp/hasp_parser.h +++ b/src/hasp/hasp_parser.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_PARSER_H @@ -10,7 +10,7 @@ class Parser { public: - static bool haspPayloadToColor(const char * payload, lv_color32_t & color); + static bool haspPayloadToColor(const char* payload, lv_color32_t& color); }; /* Named COLOR attributes */ diff --git a/src/hasp/hasp_utilities.h b/src/hasp/hasp_utilities.h index e44a86ca..d8793f93 100644 --- a/src/hasp/hasp_utilities.h +++ b/src/hasp/hasp_utilities.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_UTILITIES_H diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 540d995f..b92b9e13 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -1,29 +1,29 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if HASP_USE_CONFIG > 0 - #include "ArduinoJson.h" - #include "StreamUtils.h" // For EEPromStream +#include "ArduinoJson.h" +#include "StreamUtils.h" // For EEPromStream - #include "hasp_conf.h" +#include "hasp_conf.h" - #include "hasp_config.h" - #include "hasp_debug.h" - #include "hasp_gui.h" +#include "hasp_config.h" +#include "hasp_debug.h" +#include "hasp_gui.h" - //#include "hasp_ota.h" included in conf - //#include "hasp_filesystem.h" included in conf - //#include "hasp_telnet.h" included in conf - //#include "hasp_gpio.h" included in conf +//#include "hasp_ota.h" included in conf +//#include "hasp_filesystem.h" included in conf +//#include "hasp_telnet.h" included in conf +//#include "hasp_gpio.h" included in conf - //#include "hasp_eeprom.h" - #include "hasp/hasp.h" - #include "hasp/hasp_dispatch.h" +//#include "hasp_eeprom.h" +#include "hasp/hasp.h" +#include "hasp/hasp_dispatch.h" - #if HASP_USE_EEPROM > 0 - #include "EEPROM.h" - #endif +#if HASP_USE_EEPROM > 0 +#include "EEPROM.h" +#endif extern uint16_t dispatchTelePeriod; extern uint32_t dispatchLastMillis; @@ -31,7 +31,7 @@ extern uint32_t dispatchLastMillis; extern gui_conf_t gui_settings; extern dispatch_conf_t dispatch_settings; -void confDebugSet(const __FlashStringHelper * fstr_name) +void confDebugSet(const __FlashStringHelper* fstr_name) { /*char buffer[128]; snprintf_P(buffer, sizeof(buffer), PSTR(" * %s set"), name); @@ -39,7 +39,7 @@ void confDebugSet(const __FlashStringHelper * fstr_name) LOG_VERBOSE(TAG_CONF, F(D_BULLET "%S set"), fstr_name); } -bool configSet(int8_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name) +bool configSet(int8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) { if(!setting.isNull()) { int8_t val = setting.as(); @@ -51,7 +51,7 @@ bool configSet(int8_t & value, const JsonVariant & setting, const __FlashStringH } return false; } -bool configSet(uint8_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name) +bool configSet(uint8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) { if(!setting.isNull()) { uint8_t val = setting.as(); @@ -63,7 +63,7 @@ bool configSet(uint8_t & value, const JsonVariant & setting, const __FlashString } return false; } -bool configSet(uint16_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name) +bool configSet(uint16_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) { if(!setting.isNull()) { uint16_t val = setting.as(); @@ -76,31 +76,31 @@ bool configSet(uint16_t & value, const JsonVariant & setting, const __FlashStrin return false; } -void configStartDebug(bool setupdebug, String & configFile) +void configStartDebug(bool setupdebug, String& configFile) { if(setupdebug) { debugStart(); // Debug started, now we can use it; HASP header sent - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 LOG_INFO(TAG_CONF, F("SPI flash FS mounted")); filesystemInfo(); filesystemList(); - #endif +#endif } - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 LOG_TRACE(TAG_CONF, F(D_FILE_LOADING), configFile.c_str()); - #else +#else LOG_TRACE(TAG_CONF, F(D_FILE_LOADING), "EEPROM"); - #endif +#endif } -void configRead(JsonDocument & settings, bool setupdebug = false) +void configRead(JsonDocument& settings, bool setupdebug = false) { - String configFile((char *)0); + String configFile((char*)0); configFile.reserve(32); configFile = String(FPSTR(FP_HASP_CONFIG_FILE)); DeserializationError error; - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 File file = HASP_FS.open(configFile, "r"); if(file) { @@ -123,8 +123,8 @@ void configRead(JsonDocument & settings, bool setupdebug = false) // show settings in log String output; serializeJson(settings, output); - String passmask = F(D_PASSWORD_MASK); - const __FlashStringHelper * pass = F("pass"); + String passmask = F(D_PASSWORD_MASK); + const __FlashStringHelper* pass = F("pass"); output.replace(settings[FPSTR(FP_HTTP)][pass].as(), passmask); output.replace(settings[FPSTR(FP_MQTT)][pass].as(), passmask); output.replace(settings[FPSTR(FP_WIFI)][pass].as(), passmask); @@ -135,14 +135,14 @@ void configRead(JsonDocument & settings, bool setupdebug = false) return; } } - #else +#else - #if HASP_USE_EEPROM > 0 +#if HASP_USE_EEPROM > 0 EepromStream eepromStream(0, 1024); error = deserializeJson(settings, eepromStream); - #endif +#endif - #endif +#endif // File does not exist or error reading file if(setupdebug) { @@ -150,9 +150,9 @@ void configRead(JsonDocument & settings, bool setupdebug = false) } configStartDebug(setupdebug, configFile); - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 LOG_ERROR(TAG_CONF, F(D_FILE_LOAD_FAILED), configFile.c_str()); - #endif +#endif } /* void configBackupToEeprom() @@ -186,11 +186,11 @@ void configBackupToEeprom() */ void configWrite() { - String configFile((char *)0); + String configFile((char*)0); configFile.reserve(32); configFile = String(FPSTR(FP_HASP_CONFIG_FILE)); - String settingsChanged((char *)0); + String settingsChanged((char*)0); settingsChanged.reserve(128); settingsChanged = F(D_CONFIG_CHANGED); @@ -210,9 +210,9 @@ void configWrite() bool writefile = false; bool changed = false; - const __FlashStringHelper * module; + const __FlashStringHelper* module; - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 module = FPSTR(FP_WIFI); if(settings[module].as().isNull()) settings.createNestedObject(module); changed = wifiGetConfig(settings[module]); @@ -221,9 +221,9 @@ void configWrite() configOutput(settings[module], TAG_WIFI); writefile = true; } - #endif +#endif - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 module = FPSTR(FP_MQTT); if(settings[module].as().isNull()) settings.createNestedObject(module); changed = mqttGetConfig(settings[module]); @@ -232,9 +232,9 @@ void configWrite() configOutput(settings[module], TAG_MQTT); writefile = true; } - #endif +#endif - #if HASP_USE_TELNET > 0 +#if HASP_USE_TELNET > 0 module = F("telnet"); if(settings[module].as().isNull()) settings.createNestedObject(module); changed = telnetGetConfig(settings[module]); @@ -243,9 +243,9 @@ void configWrite() configOutput(settings[module], TAG_TELN); writefile = true; } - #endif +#endif - #if HASP_USE_MDNS > 0 +#if HASP_USE_MDNS > 0 module = FPSTR(FP_MDNS); if(settings[module].as().isNull()) settings.createNestedObject(module); changed = mdnsGetConfig(settings[module]); @@ -254,9 +254,9 @@ void configWrite() configOutput(settings[module], TAG_MDNS); writefile = true; } - #endif +#endif - #if HASP_USE_HTTP > 0 +#if HASP_USE_HTTP > 0 if(settings[FPSTR(FP_HTTP)].as().isNull()) settings.createNestedObject(F("http")); changed = httpGetConfig(settings[FPSTR(FP_HTTP)]); if(changed) { @@ -264,9 +264,9 @@ void configWrite() configOutput(settings[FPSTR(FP_HTTP)], TAG_HTTP); writefile = true; } - #endif +#endif - #if HASP_USE_GPIO > 0 +#if HASP_USE_GPIO > 0 module = FPSTR(FP_GPIO); if(settings[module].as().isNull()) settings.createNestedObject(module); changed = gpioGetConfig(settings[module]); @@ -275,7 +275,7 @@ void configWrite() configOutput(settings[module], TAG_GPIO); writefile = true; } - #endif +#endif module = FPSTR(FP_DEBUG); if(settings[module].as().isNull()) settings.createNestedObject(module); @@ -305,7 +305,7 @@ void configWrite() // changed |= otaGetConfig(settings[F("ota")].as()); if(writefile) { - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 File file = HASP_FS.open(configFile, "w"); if(file) { LOG_TRACE(TAG_CONF, F(D_FILE_SAVING), configFile.c_str()); @@ -320,7 +320,7 @@ void configWrite() } else { LOG_ERROR(TAG_CONF, F(D_FILE_SAVE_FAILED), configFile.c_str()); } - #endif +#endif // Method 1 // LOG_INFO(TAG_CONF,F("Writing to EEPROM")); @@ -330,7 +330,7 @@ void configWrite() // bufferedWifiClient.flush(); // <- OPTIONAL // eepromStream.flush(); // (for ESP) - #if defined(STM32F4xx) +#if defined(STM32F4xx) // Method 2 LOG_INFO(TAG_CONF, F(F_FILE_SAVING), "EEPROM"); char buffer[1024 + 128]; @@ -344,7 +344,7 @@ void configWrite() } else { LOG_ERROR(TAG_CONF, F(D_FILE_WRITE_FAILED), "EEPROM"); } - #endif +#endif } else { LOG_INFO(TAG_CONF, F(D_CONFIG_NOT_CHANGED)); @@ -361,19 +361,19 @@ void configSetup() Serial.println(__LINE__); if(i == 0) { - #if HASP_USE_SPIFFS > 0 +#if HASP_USE_SPIFFS > 0 EepromStream eepromStream(0, 2048); DeserializationError err = deserializeJson(settings, eepromStream); - #else +#else continue; - #endif +#endif } else { - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 if(!filesystemSetup()) { LOG_ERROR(TAG_CONF, F("FILE: SPI flash init failed. Unable to mount FS: Using default settings...")); return; } - #endif +#endif configRead(settings, true); } @@ -386,35 +386,35 @@ void configSetup() haspSetConfig(settings[FPSTR(FP_HASP)]); // otaGetConfig(settings[F("ota")]); - #if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 LOG_INFO(TAG_WIFI, F("Loading WiFi settings")); wifiSetConfig(settings[FPSTR(FP_WIFI)]); - #endif +#endif - #if HASP_USE_MQTT > 0 +#if HASP_USE_MQTT > 0 LOG_INFO(TAG_MQTT, F("Loading MQTT settings")); mqttSetConfig(settings[FPSTR(FP_MQTT)]); - #endif +#endif - #if HASP_USE_TELNET > 0 +#if HASP_USE_TELNET > 0 LOG_INFO(TAG_TELN, F("Loading Telnet settings")); telnetSetConfig(settings[F("telnet")]); - #endif +#endif - #if HASP_USE_MDNS > 0 +#if HASP_USE_MDNS > 0 LOG_INFO(TAG_MDNS, F("Loading MDNS settings")); mdnsSetConfig(settings[FPSTR(FP_MDNS)]); - #endif +#endif - #if HASP_USE_HTTP > 0 +#if HASP_USE_HTTP > 0 LOG_INFO(TAG_HTTP, F("Loading HTTP settings")); httpSetConfig(settings[FPSTR(FP_HTTP)]); - #endif +#endif - #if HASP_USE_GPIO > 0 +#if HASP_USE_GPIO > 0 LOG_INFO(TAG_GPIO, F("Loading GPIO settings")); gpioSetConfig(settings[FPSTR(FP_GPIO)]); - #endif +#endif LOG_INFO(TAG_CONF, F(D_CONFIG_LOADED)); } @@ -424,17 +424,17 @@ void configSetup() void configLoop(void) {} -void configOutput(const JsonObject & settings, uint8_t tag) +void configOutput(const JsonObject& settings, uint8_t tag) { - String output((char *)0); + String output((char*)0); output.reserve(128); serializeJson(settings, output); - String passmask((char *)0); + String passmask((char*)0); passmask.reserve(128); passmask = F("\"pass\":\"" D_PASSWORD_MASK "\""); - String password((char *)0); + String password((char*)0); password.reserve(128); String pass = F("pass"); @@ -471,7 +471,7 @@ void configOutput(const JsonObject & settings, uint8_t tag) bool configClearEeprom() { - #if defined(STM32F4xx) +#if defined(STM32F4xx) LOG_TRACE(TAG_CONF, F("Clearing EEPROM")); char buffer[1024 + 128]; memset(buffer, 1, sizeof(buffer)); @@ -486,11 +486,11 @@ bool configClearEeprom() LOG_ERROR(TAG_CONF, F("Failed to clear to EEPROM")); return false; } - #elif HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#elif HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 return HASP_FS.format(); - #else +#else return false; - #endif +#endif } #endif // HAS_USE_CONFIG \ No newline at end of file diff --git a/src/hasp_config.h b/src/hasp_config.h index 76cd5448..77eb6e01 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -1,14 +1,14 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if HASP_USE_CONFIG > 0 - #ifndef HASP_CONFIG_H - #define HASP_CONFIG_H +#ifndef HASP_CONFIG_H +#define HASP_CONFIG_H - #include "hasp_conf.h" - #include "ArduinoJson.h" - #include "hasp_debug.h" // for TAG_CONF +#include "hasp_conf.h" +#include "ArduinoJson.h" +#include "hasp_debug.h" // for TAG_CONF /* ===== Default Event Processors ===== */ void configSetup(void); @@ -19,17 +19,17 @@ void configStop(void); /* ===== Special Event Processors ===== */ void configWrite(void); -void configOutput(const JsonObject & settings, uint8_t tag = TAG_CONF); +void configOutput(const JsonObject& settings, uint8_t tag = TAG_CONF); bool configClearEeprom(void); /* ===== Getter and Setter Functions ===== */ -bool configSet(int8_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name); -bool configSet(uint8_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name); -bool configSet(uint16_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name); +bool configSet(int8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name); +bool configSet(uint8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name); +bool configSet(uint16_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name); /* ===== Read/Write Configuration ===== */ -void configSetConfig(JsonObject & settings); -void configGetConfig(JsonDocument & settings); +void configSetConfig(JsonObject& settings); +void configGetConfig(JsonDocument& settings); /* json keys used in the configfile */ const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage"; @@ -71,6 +71,6 @@ const char FP_HASP[] PROGMEM = "hasp"; const char FP_GUI[] PROGMEM = "gui"; const char FP_DEBUG[] PROGMEM = "debug"; - #endif +#endif #endif // HASP_USE_CONFIG \ No newline at end of file diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 22bd138f..97bff5a0 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_DEBUG_H diff --git a/src/hasp_eeprom.cpp b/src/hasp_eeprom.cpp index 80a1a27d..fdb02824 100644 --- a/src/hasp_eeprom.cpp +++ b/src/hasp_eeprom.cpp @@ -1,20 +1,20 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" // load first #if HASP_USE_EEPROM > 0 - #ifdef ARDUINO - #include "Arduino.h" - #endif +#ifdef ARDUINO +#include "Arduino.h" +#endif - #include "EEPROM.h" +#include "EEPROM.h" void eepromSetup() { - #if defined(STM32Fxx) +#if defined(STM32Fxx) eeprom_buffer_fill(); char buffer[] = "{\"objid\":10,\"id\":1,\"page\":0,\"x\":10,\"y\":45,\"w\":220,\"h\":55,\"toggle\":\"TRUE\"," "\"txt\":\"Toggle Me\"}"; @@ -22,8 +22,8 @@ void eepromSetup() uint16_t i; for(i = 0; i < size; i++) eeprom_buffered_write_byte(i + 4096, buffer[i]); eeprom_buffered_write_byte(i + 4096, 0); - // eeprom_buffer_flush(); - #endif + // eeprom_buffer_flush(); +#endif // ESP8266 // Don't start at boot, only at write // EEPROM.begin(1024); diff --git a/src/hasp_eeprom.h b/src/hasp_eeprom.h index c2d83d22..db8d40bd 100644 --- a/src/hasp_eeprom.h +++ b/src/hasp_eeprom.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_EEPROM_H @@ -8,7 +8,7 @@ void eepromSetup(void); void eepromLoop(void); -void eepromWrite(uint16_t addr, std::string & data); +void eepromWrite(uint16_t addr, std::string& data); std::string eepromRead(uint16_t addr); #endif \ No newline at end of file diff --git a/src/hasp_filesystem.cpp b/src/hasp_filesystem.cpp index c8d915f8..6a014e7d 100644 --- a/src/hasp_filesystem.cpp +++ b/src/hasp_filesystem.cpp @@ -1,20 +1,20 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" // include first #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - #include - #include "ArduinoJson.h" - #include "ArduinoLog.h" +#include +#include "ArduinoJson.h" +#include "ArduinoLog.h" - #include "hasp_debug.h" - #include "hasp_filesystem.h" +#include "hasp_debug.h" +#include "hasp_filesystem.h" void filesystemInfo() { // Get all information of your SPIFFS - #if 0 +#if 0 FSInfo fs_info; SPIFFS.info(fs_info); @@ -64,38 +64,38 @@ void filesystemInfo() Serial.print("Max path lenght: "); // Serial.println(SPIFFS.maxPathLength()); - #endif +#endif } void filesystemList() { - #if HASP_USE_SPIFFS > 0 - #if defined(ARDUINO_ARCH_ESP8266) +#if HASP_USE_SPIFFS > 0 +#if defined(ARDUINO_ARCH_ESP8266) if(!SPIFFS.begin()) { - #else +#else if(!SPIFFS.begin(true)) { - #endif +#endif LOG_ERROR(TAG_FILE, F("Flash file system not mouted.")); } else { LOG_VERBOSE(TAG_FILE, F("Listing files on the internal flash:")); - #if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) File root = SPIFFS.open("/"); File file = root.openNextFile(); while(file) { LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), file.name(), (uint32_t)file.size()); file = root.openNextFile(); } - #endif - #if defined(ARDUINO_ARCH_ESP8266) +#endif +#if defined(ARDUINO_ARCH_ESP8266) Dir dir = SPIFFS.openDir("/"); while(dir.next()) { LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize()); } - #endif +#endif } - #endif +#endif } bool filesystemSetup(void) @@ -106,19 +106,19 @@ bool filesystemSetup(void) // Logging is defered until debugging has started // FS success or failure is printed at that time ! - #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - #if defined(ARDUINO_ARCH_ESP8266) +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 +#if defined(ARDUINO_ARCH_ESP8266) if(!HASP_FS.begin()) { - #else +#else if(!HASP_FS.begin(true)) { - #endif +#endif // LOG_ERROR(TAG_FILE, F("SPI flash init failed. Unable to mount FS.")); return false; } else { // LOG_INFO(TAG_FILE, F("SPI Flash FS mounted")); return true; } - #endif +#endif return false; } diff --git a/src/hasp_filesystem.h b/src/hasp_filesystem.h index ed3b773b..bda556ed 100644 --- a/src/hasp_filesystem.h +++ b/src/hasp_filesystem.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_FILESYSTEM_H @@ -12,22 +12,22 @@ void filesystemList(); void filesystemInfo(); #if defined(ARDUINO_ARCH_ESP32) - #if HASP_USE_SPIFFS > 0 - #include "SPIFFS.h" - #define HASP_FS SPIFFS - #elif HASP_USE_LITTLEFS > 0 - #include "LITTLEFS.h" - #define HASP_FS LITTLEFS - #endif +#if HASP_USE_SPIFFS > 0 +#include "SPIFFS.h" +#define HASP_FS SPIFFS +#elif HASP_USE_LITTLEFS > 0 +#include "LITTLEFS.h" +#define HASP_FS LITTLEFS +#endif #elif defined(ARDUINO_ARCH_ESP8266) - // included by default - #include - #define HASP_FS LittleFS +// included by default +#include +#define HASP_FS LittleFS #endif // ARDUINO_ARCH #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - #include - #include +#include +#include #endif // ARDUINO_ARCH #endif // HASP_FILESYSTEM_H \ No newline at end of file diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 7063d104..de4e2ece 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" diff --git a/src/hasp_gui.h b/src/hasp_gui.h index 46722dae..3e33d068 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_GUI_H diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index b3748dea..74481ba0 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if HASP_USE_CONFIG > 0 diff --git a/src/hasp_oobe.h b/src/hasp_oobe.h index 8e3e7f4b..a2ed71d4 100644 --- a/src/hasp_oobe.h +++ b/src/hasp_oobe.h @@ -1,10 +1,10 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if HASP_USE_CONFIG > 0 void oobeSetAutoCalibrate(bool cal); bool oobeSetup(); -void oobeFakeSetup(const char *, const char *); // for testing purposes only +void oobeFakeSetup(const char*, const char*); // for testing purposes only #endif // HASP_USE_CONFIG diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index c36ba4f5..d58726bc 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ /* =========================================================================== diff --git a/src/main_arduino copy.cpp b/src/main_arduino copy.cpp index 6d14b297..9f93e141 100644 --- a/src/main_arduino copy.cpp +++ b/src/main_arduino copy.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if 0 && ARDUINO diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 41920295..3b014ace 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef WINDOWS diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 8e409690..8ccf9171 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifdef WINDOWS diff --git a/src/mqtt/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h index b10d9e4d..8e47773c 100644 --- a/src/mqtt/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_MQTT_H diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index ddb4ae6c..3eeebcbb 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "ArduinoJson.h" diff --git a/src/mqtt/hasp_mqtt_ha.h b/src/mqtt/hasp_mqtt_ha.h index 5580f79e..9d84db6f 100644 --- a/src/mqtt/hasp_mqtt_ha.h +++ b/src/mqtt/hasp_mqtt_ha.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_MQTT_HA_H diff --git a/src/mqtt/hasp_mqtt_paho_async.cpp b/src/mqtt/hasp_mqtt_paho_async.cpp index b0930d33..d8b94f2b 100644 --- a/src/mqtt/hasp_mqtt_paho_async.cpp +++ b/src/mqtt/hasp_mqtt_paho_async.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ /* Multi threaded asynchronous paho client */ diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index d355d641..bcdbdcb0 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ /* Single threaded synchronous paho client */ diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index f77db9ac..73afab25 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" diff --git a/src/sys/gpio/hasp_gpio.cpp b/src/sys/gpio/hasp_gpio.cpp index 91f519cd..f2963f1c 100644 --- a/src/sys/gpio/hasp_gpio.cpp +++ b/src/sys/gpio/hasp_gpio.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "AceButton.h" @@ -12,13 +12,13 @@ #include "hasp/hasp.h" #ifdef ARDUINO_ARCH_ESP8266 - #define INPUT_PULLDOWN INPUT +#define INPUT_PULLDOWN INPUT #endif uint8_t gpioUsedInputCount = 0; using namespace ace_button; -static AceButton * button[HASP_NUM_INPUTS]; +static AceButton* button[HASP_NUM_INPUTS]; // An array of button pins, led pins, and the led states. Cannot be const // because ledState is mutable. @@ -49,7 +49,7 @@ class TouchConfig : public ButtonConfig { TouchConfig touchConfig(); #endif -static void gpio_event_handler(AceButton * button, uint8_t eventType, uint8_t buttonState) +static void gpio_event_handler(AceButton* button, uint8_t eventType, uint8_t buttonState) { uint8_t btnid = button->getId(); uint8_t eventid; @@ -95,7 +95,7 @@ static void gpio_event_handler(AceButton * button, uint8_t eventType, uint8_t bu void aceButtonSetup(void) { - ButtonConfig * buttonConfig = ButtonConfig::getSystemButtonConfig(); + ButtonConfig* buttonConfig = ButtonConfig::getSystemButtonConfig(); buttonConfig->setEventHandler(gpio_event_handler); // Features @@ -128,14 +128,14 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8 if(!button[i]) { LOG_TRACE(TAG_GPIO, F("Creating Button%d on pin %d (index %d) mode %d default %d"), i, pin, index, - input_mode, default_state); + input_mode, default_state); button[i] = new AceButton(pin, default_state, index); if(button[i]) { // pinMode(pin, input_mode); - ButtonConfig * buttonConfig = button[i]->getButtonConfig(); + ButtonConfig* buttonConfig = button[i]->getButtonConfig(); buttonConfig->setEventHandler(gpio_event_handler); buttonConfig->setFeature(ButtonConfig::kFeatureClick); buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick); @@ -146,7 +146,7 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8 buttonConfig->setFeature(ButtonConfig::kFeatureSuppressAfterClick); LOG_INFO(TAG_GPIO, F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, - input_mode, default_state); + input_mode, default_state); gpioUsedInputCount = i + 1; return; } @@ -163,19 +163,19 @@ void gpioAddSwitch(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8 if(!button[i]) { LOG_TRACE(TAG_GPIO, F("Creating Switch%d on pin %d (index %d) mode %d default %d"), i, pin, index, - input_mode, default_state); + input_mode, default_state); button[i] = new AceButton(pin, default_state, index); if(button[i]) { // pinMode(pin, input_mode); - ButtonConfig * buttonConfig = button[i]->getButtonConfig(); + ButtonConfig* buttonConfig = button[i]->getButtonConfig(); buttonConfig->setEventHandler(gpio_event_handler); buttonConfig->setFeature(ButtonConfig::kFeatureSuppressAll); LOG_INFO(TAG_GPIO, F("Button%d switch on pin %d (index %d) mode %d default %d"), i, pin, index, - input_mode, default_state); + input_mode, default_state); gpioUsedInputCount = i + 1; return; } @@ -196,7 +196,7 @@ void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, if(button[i]) { pinMode(pin, input_mode); - ButtonConfig * buttonConfig = button[i]->getButtonConfig(); + ButtonConfig* buttonConfig = button[i]->getButtonConfig(); buttonConfig->setEventHandler(gpio_event_handler); buttonConfig->setFeature(ButtonConfig::kFeatureClick); buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick); @@ -206,7 +206,7 @@ void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses LOG_INFO(TAG_GPIO, F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, - input_mode, default_state); + input_mode, default_state); gpioUsedInputCount = i + 1; return; } @@ -472,9 +472,9 @@ bool gpioIsSystemPin(uint8_t gpio) #ifdef ARDUINO_ARCH_ESP8266 if((gpio >= 6) && (gpio <= 11)) return true; // integrated SPI flash - #ifndef TFT_SPI_OVERLAP +#ifndef TFT_SPI_OVERLAP if((gpio >= 12) && (gpio <= 14)) return true; // HSPI - #endif +#endif #endif return false; @@ -505,7 +505,7 @@ bool gpioSavePinConfig(uint8_t config_num, uint8_t pin, uint8_t type, uint8_t gr gpioConfig[config_num].group = group; gpioConfig[config_num].gpio_function = pinfunc; LOG_TRACE(TAG_GPIO, F("Saving Pin config #%d pin %d - type %d - group %d - func %d"), config_num, pin, type, - group, pinfunc); + group, pinfunc); return true; } @@ -535,7 +535,7 @@ hasp_gpio_config_t gpioGetPinConfig(uint8_t num) //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_CONFIG > 0 -bool gpioGetConfig(const JsonObject & settings) +bool gpioGetConfig(const JsonObject& settings) { bool changed = false; @@ -579,7 +579,7 @@ bool gpioGetConfig(const JsonObject & settings) * * @param[in] settings JsonObject with the config settings. **/ -bool gpioSetConfig(const JsonObject & settings) +bool gpioSetConfig(const JsonObject& settings) { configOutput(settings); bool changed = false; diff --git a/src/sys/gpio/hasp_gpio.h b/src/sys/gpio/hasp_gpio.h index 1ff8507c..1419e1b5 100644 --- a/src/sys/gpio/hasp_gpio.h +++ b/src/sys/gpio/hasp_gpio.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_GPIO_H @@ -36,8 +36,8 @@ int8_t gpioGetFreeConfigId(); hasp_gpio_config_t gpioGetPinConfig(uint8_t num); #if HASP_USE_CONFIG > 0 -bool gpioGetConfig(const JsonObject & settings); -bool gpioSetConfig(const JsonObject & settings); +bool gpioGetConfig(const JsonObject& settings); +bool gpioSetConfig(const JsonObject& settings); #endif #define HASP_GPIO_FREE 0x00 diff --git a/src/sys/net/hasp_ethernet_esp32.cpp b/src/sys/net/hasp_ethernet_esp32.cpp index 270c44ba..6b78e836 100644 --- a/src/sys/net/hasp_ethernet_esp32.cpp +++ b/src/sys/net/hasp_ethernet_esp32.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" diff --git a/src/sys/net/hasp_ethernet_esp32.h b/src/sys/net/hasp_ethernet_esp32.h index 5e824a34..3eb24e4e 100644 --- a/src/sys/net/hasp_ethernet_esp32.h +++ b/src/sys/net/hasp_ethernet_esp32.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_ETHERNET_ESP32_H @@ -10,6 +10,6 @@ void ethernetSetup(); void ethernetLoop(void); bool ethernetEvery5Seconds(); -void ethernet_get_statusupdate(char * buffer, size_t len); +void ethernet_get_statusupdate(char* buffer, size_t len); #endif \ No newline at end of file diff --git a/src/sys/net/hasp_ethernet_stm32.cpp b/src/sys/net/hasp_ethernet_stm32.cpp index 32bdebe7..8741a89c 100644 --- a/src/sys/net/hasp_ethernet_stm32.cpp +++ b/src/sys/net/hasp_ethernet_stm32.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" @@ -13,9 +13,9 @@ IPAddress ip; void ethernetSetup() { - #if USE_BUILTIN_ETHERNET > 0 +#if USE_BUILTIN_ETHERNET > 0 // start Ethernet and UDP - LOG_TRACE(TAG_ETH, F("LAN8720 "D_SERVICE_STARTING)); + LOG_TRACE(TAG_ETH, F("LAN8720 " D_SERVICE_STARTING)); if(Ethernet.begin() == 0) { LOG_TRACE(TAG_ETH, F("Failed to configure Ethernet using DHCP")); eth_connected = false; @@ -27,7 +27,7 @@ void ethernetSetup() LOG_TRACE(TAG_ETH, F("MAC Address %s"), halGetMacAddress(0, ":")); - #else +#else byte mac[6]; uint32_t baseUID = (uint32_t)UID_BASE; mac[0] = 0x00; @@ -44,14 +44,14 @@ void ethernetSetup() Ethernet.setCsPin(W5500_CS); Ethernet.setRstPin(W5500_RST); Ethernet.setHostname(ethHostname); - LOG_TRACE(TAG_ETH, F("W5500 "D_SERVICE_STARTING)); + LOG_TRACE(TAG_ETH, F("W5500 " D_SERVICE_STARTING)); if(Ethernet.begin(mac) == 0) { LOG_TRACE(TAG_ETH, F("Failed to configure Ethernet using DHCP")); } else { ip = Ethernet.localIP(); LOG_TRACE(TAG_ETH, F("DHCP Success got IP %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); } - #endif +#endif } void ethernetLoop(void) @@ -88,22 +88,22 @@ void ethernetLoop(void) bool ethernetEvery5Seconds() { bool state; - #if USE_BUILTIN_ETHERNET > 0 +#if USE_BUILTIN_ETHERNET > 0 state = Ethernet.linkStatus() == LinkON; - #else +#else state = Ethernet.link() == 1; - #endif +#endif LOG_WARNING(TAG_ETH, state ? F(D_NETWORK_ONLINE) : F(D_NETWORK_OFFLINE)); return state; } -void ethernet_get_statusupdate(char * buffer, size_t len) +void ethernet_get_statusupdate(char* buffer, size_t len) { - #if USE_BUILTIN_ETHERNET > 0 +#if USE_BUILTIN_ETHERNET > 0 bool state = Ethernet.linkStatus() == LinkON; - #else +#else bool state = Ethernet.link() == 1; - #endif +#endif IPAddress ip = Ethernet.localIP(); snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":%d,\"ip\":\"%d.%d.%d.%d\","), state ? F("ON") : F("OFF"), 10, diff --git a/src/sys/net/hasp_ethernet_stm32.h b/src/sys/net/hasp_ethernet_stm32.h index 04ddec72..ed3a76c1 100644 --- a/src/sys/net/hasp_ethernet_stm32.h +++ b/src/sys/net/hasp_ethernet_stm32.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_ETHERNET_STM32_H @@ -10,6 +10,6 @@ void ethernetSetup(); void ethernetLoop(void); bool ethernetEvery5Seconds(); -void ethernet_get_statusupdate(char * buffer, size_t len); +void ethernet_get_statusupdate(char* buffer, size_t len); #endif \ No newline at end of file diff --git a/src/sys/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp index 467b6330..2545d5f8 100644 --- a/src/sys/net/hasp_network.cpp +++ b/src/sys/net/hasp_network.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include diff --git a/src/sys/net/hasp_network.h b/src/sys/net/hasp_network.h index facd76e7..094d96ad 100644 --- a/src/sys/net/hasp_network.h +++ b/src/sys/net/hasp_network.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_NETWORK_H @@ -15,7 +15,7 @@ void networkStop(void); /* ===== Special Event Processors ===== */ /* ===== Getter and Setter Functions ===== */ -void network_get_statusupdate(char * buffer, size_t len); +void network_get_statusupdate(char* buffer, size_t len); /* ===== Read/Write Configuration ===== */ diff --git a/src/sys/net/hasp_wifi.cpp b/src/sys/net/hasp_wifi.cpp index 0e6c40e5..c2fa9170 100644 --- a/src/sys/net/hasp_wifi.cpp +++ b/src/sys/net/hasp_wifi.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include diff --git a/src/sys/net/hasp_wifi.h b/src/sys/net/hasp_wifi.h index 5364150f..9854d449 100644 --- a/src/sys/net/hasp_wifi.h +++ b/src/sys/net/hasp_wifi.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_WIFI_H @@ -8,16 +8,16 @@ void wifiSetup(); bool wifiShowAP(); -bool wifiShowAP(char * ssid, char * pass); +bool wifiShowAP(char* ssid, char* pass); bool wifiEvery5Seconds(void); void wifiStop(void); -bool wifiValidateSsid(const char * ssid, const char * pass); -void wifi_get_statusupdate(char * buffer, size_t len); +bool wifiValidateSsid(const char* ssid, const char* pass); +void wifi_get_statusupdate(char* buffer, size_t len); #if HASP_USE_CONFIG > 0 -bool wifiGetConfig(const JsonObject & settings); -bool wifiSetConfig(const JsonObject & settings); +bool wifiGetConfig(const JsonObject& settings); +bool wifiSetConfig(const JsonObject& settings); #endif #endif \ No newline at end of file diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 95232d91..dd7b0637 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ //#include "webServer.h" diff --git a/src/sys/svc/hasp_http.h b/src/sys/svc/hasp_http.h index 34e2bd1d..51313c6d 100644 --- a/src/sys/svc/hasp_http.h +++ b/src/sys/svc/hasp_http.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_HTTP_H @@ -22,11 +22,11 @@ void httpEvery5Seconds(void); void httpStart(void); void httpStop(void); -size_t httpClientWrite(const uint8_t * buf, size_t size); // Screenshot Write Data +size_t httpClientWrite(const uint8_t* buf, size_t size); // Screenshot Write Data #if HASP_USE_CONFIG > 0 -bool httpGetConfig(const JsonObject & settings); -bool httpSetConfig(const JsonObject & settings); +bool httpGetConfig(const JsonObject& settings); +bool httpSetConfig(const JsonObject& settings); #endif // HASP_USE_CONFIG #endif \ No newline at end of file diff --git a/src/sys/svc/hasp_mdns.cpp b/src/sys/svc/hasp_mdns.cpp index 1c6c127e..822c7970 100644 --- a/src/sys/svc/hasp_mdns.cpp +++ b/src/sys/svc/hasp_mdns.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" diff --git a/src/sys/svc/hasp_mdns.h b/src/sys/svc/hasp_mdns.h index 9886b823..2700595b 100644 --- a/src/sys/svc/hasp_mdns.h +++ b/src/sys/svc/hasp_mdns.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_MDNS_H @@ -8,7 +8,7 @@ struct hasp_mdns_config_t { - uint8_t enable = true; + uint8_t enable = true; }; /* ===== Default Event Processors ===== */ @@ -19,8 +19,8 @@ void mdnsStop(void); /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 -bool mdnsGetConfig(const JsonObject & settings); -bool mdnsSetConfig(const JsonObject & settings); +bool mdnsGetConfig(const JsonObject& settings); +bool mdnsSetConfig(const JsonObject& settings); #endif #endif \ No newline at end of file diff --git a/src/sys/svc/hasp_ota.cpp b/src/sys/svc/hasp_ota.cpp index ba643b60..9e82b11e 100644 --- a/src/sys/svc/hasp_ota.cpp +++ b/src/sys/svc/hasp_ota.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) diff --git a/src/sys/svc/hasp_ota.h b/src/sys/svc/hasp_ota.h index 9d023c1f..215cd73a 100644 --- a/src/sys/svc/hasp_ota.h +++ b/src/sys/svc/hasp_ota.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) @@ -14,7 +14,7 @@ void otaLoop(void); void otaEverySecond(void); /* ===== Special Event Processors ===== */ -void otaHttpUpdate(const char * espOtaUrl); +void otaHttpUpdate(const char* espOtaUrl); #endif #endif \ No newline at end of file diff --git a/src/sys/svc/hasp_slave.cpp b/src/sys/svc/hasp_slave.cpp index 840269b2..a3739845 100644 --- a/src/sys/svc/hasp_slave.cpp +++ b/src/sys/svc/hasp_slave.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" @@ -25,7 +25,7 @@ unsigned long updatLedPeriod = 1000; // timer in msec for tele mqtt send bool ledstate = false; -void slave_send_state(const __FlashStringHelper * subtopic, const char * payload) +void slave_send_state(const __FlashStringHelper* subtopic, const char* payload) { // page = 0 // p[0].b[0].attr = abc @@ -37,32 +37,32 @@ void slave_send_state(const __FlashStringHelper * subtopic, const char * payload char cBuffer[strlen(payload) + 64]; memset(cBuffer, 0, sizeof(cBuffer)); snprintf_P(cBuffer, sizeof(cBuffer), PSTR("publish %sstate/%s %s"), slaveNodeTopic, subtopic, payload); - slave.ExecuteCommand((char *)cBuffer); + slave.ExecuteCommand((char*)cBuffer); // Log after char buffers are cleared LOG_TRACE(TAG_TASM, F("TAS PUB: %sstate/%S = %s"), slaveNodeTopic, subtopic, payload); } -void slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) +void slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char* attribute, const char* data) { char cBuffer[192]; memset(cBuffer, 0, sizeof(cBuffer)); snprintf_P(cBuffer, sizeof(cBuffer), PSTR("publish %sstate/json {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, attribute, data); - slave.ExecuteCommand((char *)cBuffer); + slave.ExecuteCommand((char*)cBuffer); // Log after char buffers are cleared LOG_TRACE(TAG_TASM, F("TAS PUB: %sstate/json = {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, attribute, data); } -void slave_send_input(uint8_t id, const char * payload) +void slave_send_input(uint8_t id, const char* payload) { // LOG_VERBOSE(TAG_TASM,F("MQTT TST: %sstate/input%u = %s"), mqttNodeTopic, id, payload); // to be removed char cBuffer[strlen(payload) + 64]; memset(cBuffer, 0, sizeof(cBuffer)); snprintf_P(cBuffer, sizeof(cBuffer), PSTR("publish %sstate/input%u %s"), slaveNodeTopic, id, payload); - slave.ExecuteCommand((char *)cBuffer); + slave.ExecuteCommand((char*)cBuffer); // Log after char buffers are cleared LOG_TRACE(TAG_TASM, F("TAS PUB: %sstate/input%u = %s"), slaveNodeTopic, id, payload); @@ -85,12 +85,12 @@ void TASMO_TELE_JSON() halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); strcat(data, buffer); } - slave.sendJSON((char *)data); + slave.sendJSON((char*)data); // slave_send_state(F("statusupdate"), data); // debugLastMillis = millis(); } -void TASMO_DATA_RECEIVE(char * data) +void TASMO_DATA_RECEIVE(char* data) { LOG_INFO(TAG_TASM, F("Slave IN [%s]"), data); diff --git a/src/sys/svc/hasp_slave.h b/src/sys/svc/hasp_slave.h index 9271732a..0fe530c7 100644 --- a/src/sys/svc/hasp_slave.h +++ b/src/sys/svc/hasp_slave.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_TASMOTACLIENT_H @@ -9,10 +9,10 @@ #define HASP_TASMOTACLIENT_SPEED 57600 void TASMO_EVERY_SECOND(void); -void TASMO_DATA_RECEIVE(char * data); -void slave_send_state(const __FlashStringHelper * subtopic, const char * payload); -void slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data); -void slave_send_input(uint8_t id, const char * payload); +void TASMO_DATA_RECEIVE(char* data); +void slave_send_state(const __FlashStringHelper* subtopic, const char* payload); +void slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char* attribute, const char* data); +void slave_send_input(uint8_t id, const char* payload); void slave_send_statusupdate(); void slaveSetup(); diff --git a/src/sys/svc/hasp_telnet.cpp b/src/sys/svc/hasp_telnet.cpp index 50697059..e760b7cf 100644 --- a/src/sys/svc/hasp_telnet.cpp +++ b/src/sys/svc/hasp_telnet.cpp @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" diff --git a/src/sys/svc/hasp_telnet.h b/src/sys/svc/hasp_telnet.h index 98a958ee..314e678b 100644 --- a/src/sys/svc/hasp_telnet.h +++ b/src/sys/svc/hasp_telnet.h @@ -1,4 +1,4 @@ -/* MIT License - Copyright (c) 2020 Francis Van Roie +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_TELNET_H @@ -23,8 +23,8 @@ void telnetStop(void); /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 -bool telnetSetConfig(const JsonObject & settings); -bool telnetGetConfig(const JsonObject & settings); +bool telnetSetConfig(const JsonObject& settings); +bool telnetGetConfig(const JsonObject& settings); #endif #define TELNET_UNAUTHENTICATED 0 From c38b75dd1a7cf522403338d1269a0ed069c37570 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 14:54:56 +0100 Subject: [PATCH 079/236] Fix webServer landing page in STA mode --- src/sys/svc/hasp_http.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index dd7b0637..170e088e 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1939,13 +1939,13 @@ void httpSetup() #if HASP_USE_WIFI > 0 // These two endpoints are needed in STA and AP mode - webServer.on(F("/"), webHandleWifiConfig); webServer.on(F("/config"), webHandleConfig); #if !defined(STM32F4xx) #if HASP_USE_CONFIG > 0 if(WiFi.getMode() != WIFI_STA) { + webServer.on(F("/"), webHandleWifiConfig); LOG_TRACE(TAG_HTTP, F("Wifi access point")); return; } @@ -1984,6 +1984,7 @@ void httpSetup() handleFileUpload); #endif + webServer.on(F("/"), webHandleRoot); webServer.on(F("/info"), webHandleInfo); webServer.on(F("/screenshot"), webHandleScreenshot); webServer.on(F("/firmware"), webHandleFirmware); From df09d8ae5c17df31aae4a0022f62aac1853e7c3b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 14:55:10 +0100 Subject: [PATCH 080/236] Fix screen refresh during long updates --- src/hasp/hasp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index cb9f21d8..98554c24 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -272,7 +272,7 @@ void haspProgressVal(uint8_t val) } lv_bar_set_value(bar, val, LV_ANIM_OFF); } - // lv_task_handler(); /* let the GUI do its work */ + lv_task_handler(); // needed to let the GUI do its work during long updates } } @@ -287,7 +287,7 @@ void haspProgressMsg(const char* msg) hasp_process_obj_attribute(bar, value_str, msg, true); } - // lv_task_handler(); /* let the GUI do its work */ + lv_task_handler(); // needed to let the GUI do its work during long updates /* if(bar) { progress_str.reserve(64); From e97d7459f4940eb51c560146241eff60ff7c55bf Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 14:55:21 +0100 Subject: [PATCH 081/236] Enable telnet --- platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index ce3e8871..08cf0f6d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -116,7 +116,7 @@ build_flags = ; -- tft_espi build options ------------------------ ;-D USE_DMA_TO_TFT ; -- hasp-lvgl build options ------------------------ - ;-D HASP_USE_TELNET=1 + -D HASP_USE_TELNET=1 ;-D HASP_USE_SPIFFS=1 -D HASP_USE_LITTLEFS=1 ;-D HASP_USE_EEPROM=1 @@ -184,7 +184,7 @@ build_flags= ; -- ArduinoJson build options ---------------------------- -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments ; -- hasp-lvgl build options ------------------------ - ;-D HASP_USE_TELNET=1 + -D HASP_USE_TELNET=1 ;-D HASP_USE_SPIFFS=1 -D HASP_USE_LITTLEFS=1 -D HASP_USE_EEPROM=1 From c5204b48d51dbd93e5c136e9c5b2c36352ce3949 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 20:40:16 +0100 Subject: [PATCH 082/236] Add is_system_pin --- src/dev/device.h | 4 ++++ src/dev/esp32/esp32.cpp | 10 ++++++++++ src/dev/esp32/esp32.h | 2 ++ src/dev/esp8266/esp8266.cpp | 7 +++++++ src/dev/esp8266/esp8266.h | 2 ++ src/dev/win32/hasp_win32.cpp | 5 +++++ src/dev/win32/hasp_win32.h | 2 ++ 7 files changed, 32 insertions(+) diff --git a/src/dev/device.h b/src/dev/device.h index cafcec5d..8de3974f 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -77,6 +77,10 @@ class BaseDevice { { return 0; } + virtual bool is_system_pin(uint8_t pin) + { + return false; + } }; } // namespace dev diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index e3f55935..ede2dbdb 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -122,6 +122,16 @@ uint16_t Esp32Device::get_cpu_frequency() return ESP.getCpuFreqMHz(); } +bool Esp32Device::is_system_pin(uint8_t pin) +{ + if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash + if((pin == 37) || (pin == 38)) return true; // unavailable + if(psramFound()) { + if((pin == 16) || (pin == 17)) return true; // PSRAM + } + return false; +} + } // namespace dev #if defined(LANBONL8) diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 8c445521..44be6a6b 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -39,6 +39,8 @@ class Esp32Device : public BaseDevice { uint8_t get_heap_fragmentation() override; uint16_t get_cpu_frequency() override; + bool is_system_pin(uint8_t pin) override; + private: std::string _hostname; diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index 1bceb5f7..bcd9a850 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -109,6 +109,13 @@ uint16_t Esp8266Device::get_cpu_frequency() return ESP.getCpuFreqMHz(); } +bool Esp8266Device::is_system_pin(uint8_t pin) +{ + if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash + if((pin >= 12) && (pin <= 14)) return true; // HSPI + return false; +} + } // namespace dev dev::Esp8266Device haspDevice; diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 39af24c6..cdd6526d 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -41,6 +41,8 @@ class Esp8266Device : public BaseDevice { uint8_t get_heap_fragmentation() override; uint16_t get_cpu_frequency() override; + bool is_system_pin(uint8_t pin) override; + private: std::string _hostname; diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 6dc27817..6142cdb8 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -119,6 +119,11 @@ uint16_t Win32Device::get_cpu_frequency() return 0; } +bool Win32Device::is_system_pin(uint8_t pin) +{ + return false; +} + } // namespace dev dev::Win32Device haspDevice; diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index 2eb3614a..75f72bac 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -59,6 +59,8 @@ class Win32Device : public BaseDevice { uint8_t get_heap_fragmentation(); uint16_t get_cpu_frequency(); + bool is_system_pin(uint8_t pin) override; + private: std::string _hostname; From 10420768456ef529fe7aa6afe3cdd934b30c68d8 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 20:40:47 +0100 Subject: [PATCH 083/236] Add is_driver_pin --- src/drv/tft_driver.h | 2 + src/drv/tft_driver_sdl2.h | 4 + src/drv/tft_driver_tftesp.cpp | 227 ++++++++++++++++++++++++++++++++++ src/drv/tft_driver_tftespi.h | 126 ++----------------- 4 files changed, 240 insertions(+), 119 deletions(-) diff --git a/src/drv/tft_driver.h b/src/drv/tft_driver.h index a5193456..8423b503 100644 --- a/src/drv/tft_driver.h +++ b/src/drv/tft_driver.h @@ -23,6 +23,8 @@ class BaseTft { {} static void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) {} + virtual bool is_driver_pin(uint8_t) + {} }; } // namespace dev diff --git a/src/drv/tft_driver_sdl2.h b/src/drv/tft_driver_sdl2.h index f8d81554..b3633f86 100644 --- a/src/drv/tft_driver_sdl2.h +++ b/src/drv/tft_driver_sdl2.h @@ -83,6 +83,10 @@ class TftSdl2 : BaseTft { { monitor_flush(disp, area, color_p); } + bool is_driver_pin(uint8_t pin) + { + return false; + } }; } // namespace dev diff --git a/src/drv/tft_driver_tftesp.cpp b/src/drv/tft_driver_tftesp.cpp index 4a4a74bc..e015b567 100644 --- a/src/drv/tft_driver_tftesp.cpp +++ b/src/drv/tft_driver_tftesp.cpp @@ -3,5 +3,232 @@ #ifdef ARDUINO #include "tft_driver_tftespi.h" + +namespace dev { + +void TftEspi::init(int w, int h) +{ + tft.begin(); + tft.setSwapBytes(true); /* set endianess */ +} + +void TftEspi::show_info() +{ + + setup_t tftSetup; + tft.getSetup(tftSetup); + + LOG_VERBOSE(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str()); + LOG_VERBOSE(TAG_TFT, F("Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); + LOG_VERBOSE(TAG_TFT, F("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel")); + +#if defined(ARDUINO_ARCH_ESP8266) + LOG_VERBOSE(TAG_TFT, F("SPI overlap: %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No")); +#endif + + if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch + { + LOG_VERBOSE(TAG_TFT, F("Driver : %s"), halDisplayDriverName().c_str()); // tftSetup.tft_driver); + LOG_VERBOSE(TAG_TFT, F("Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height); + } else if(tftSetup.tft_driver == 0xE9D) + LOG_VERBOSE(TAG_TFT, F("Driver = ePaper")); + + // Offsets, not all used yet + tftOffsetInfo(0, tftSetup.r0_x_offset, tftSetup.r0_y_offset); + tftOffsetInfo(1, tftSetup.r1_x_offset, tftSetup.r1_y_offset); + tftOffsetInfo(2, tftSetup.r2_x_offset, tftSetup.r2_y_offset); + tftOffsetInfo(3, tftSetup.r3_x_offset, tftSetup.r3_y_offset); + /* replaced by tftOffsetInfo + // if(tftSetup.r1_x_offset != 0) Serial.printf("R1 x offset = %i \n", tftSetup.r1_x_offset); + // if(tftSetup.r1_y_offset != 0) Serial.printf("R1 y offset = %i \n", tftSetup.r1_y_offset); + // if(tftSetup.r2_x_offset != 0) Serial.printf("R2 x offset = %i \n", tftSetup.r2_x_offset); + // if(tftSetup.r2_y_offset != 0) Serial.printf("R2 y offset = %i \n", tftSetup.r2_y_offset); + // if(tftSetup.r3_x_offset != 0) Serial.printf("R3 x offset = %i \n", tftSetup.r3_x_offset); + // if(tftSetup.r3_y_offset != 0) Serial.printf("R3 y offset = %i \n", tftSetup.r3_y_offset); + */ + + tftPinInfo(F("MOSI"), tftSetup.pin_tft_mosi); + tftPinInfo(F("MISO"), tftSetup.pin_tft_miso); + tftPinInfo(F("SCLK"), tftSetup.pin_tft_clk); + +#if defined(ARDUINO_ARCH_ESP8266) + if(tftSetup.overlap == true) { + LOG_VERBOSE(TAG_TFT, F("Overlap selected, following pins MUST be used:")); + + LOG_VERBOSE(TAG_TFT, F("MOSI : SD1 (GPIO 8)")); + LOG_VERBOSE(TAG_TFT, F("MISO : SD0 (GPIO 7)")); + LOG_VERBOSE(TAG_TFT, F("SCK : CLK (GPIO 6)")); + LOG_VERBOSE(TAG_TFT, F("TFT_CS : D3 (GPIO 0)")); + + LOG_VERBOSE(TAG_TFT, F("TFT_DC and TFT_RST pins can be tftSetup defined")); + } +#endif + + tftPinInfo(F("TFT_CS"), tftSetup.pin_tft_cs); + tftPinInfo(F("TFT_DC"), tftSetup.pin_tft_dc); + tftPinInfo(F("TFT_RST"), tftSetup.pin_tft_rst); + + tftPinInfo(F("TOUCH_CS"), tftSetup.pin_tch_cs); + + tftPinInfo(F("TFT_WR"), tftSetup.pin_tft_wr); + tftPinInfo(F("TFT_RD"), tftSetup.pin_tft_rd); + + tftPinInfo(F("TFT_D0"), tftSetup.pin_tft_d0); + tftPinInfo(F("TFT_D1"), tftSetup.pin_tft_d1); + tftPinInfo(F("TFT_D2"), tftSetup.pin_tft_d2); + tftPinInfo(F("TFT_D3"), tftSetup.pin_tft_d3); + tftPinInfo(F("TFT_D4"), tftSetup.pin_tft_d4); + tftPinInfo(F("TFT_D5"), tftSetup.pin_tft_d5); + tftPinInfo(F("TFT_D6"), tftSetup.pin_tft_d6); + tftPinInfo(F("TFT_D7"), tftSetup.pin_tft_d7); + + if(tftSetup.serial == 1) { + LOG_VERBOSE(TAG_TFT, F("Display SPI freq. : %d.%d MHz"), tftSetup.tft_spi_freq / 10, + tftSetup.tft_spi_freq % 10); + } + if(tftSetup.pin_tch_cs != -1) { + LOG_VERBOSE(TAG_TFT, F("Touch SPI freq. : %d.%d MHz"), tftSetup.tch_spi_freq / 10, + tftSetup.tch_spi_freq % 10); + } +} + +void TftEspi::splashscreen() +{ + tft.fillScreen(TFT_DARKCYAN); + int x = (tft.width() - logoWidth) / 2; + int y = (tft.height() - logoHeight) / 2; + tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE); +} + +void TftEspi::set_rotation(uint8_t rotation) +{ + LOG_VERBOSE(TAG_TFT, F("Rotation : %d"), rotation); + tft.setRotation(rotation); +} + +void TftEspi::set_invert(bool invert) +{ + char buffer[4]; + memcpy_P(buffer, invert ? PSTR("yes") : PSTR("no"), sizeof(buffer)); + + LOG_VERBOSE(TAG_TFT, F("Invert Disp: %s"), buffer); + tft.invertDisplay(invert); +} + +void TftEspi::flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) +{ + size_t len = lv_area_get_size(area); + + /* Update TFT */ + tft.startWrite(); /* Start new TFT transaction */ + tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */ +#ifdef USE_DMA_TO_TFT + tft.pushPixelsDMA((uint16_t*)color_p, len); /* Write words at once */ +#else + tft.pushPixels((uint16_t*)color_p, len); /* Write words at once */ +#endif + tft.endWrite(); /* terminate TFT transaction */ + + /* Tell lvgl that flushing is done */ + lv_disp_flush_ready(disp); +} + +bool TftEspi::is_driver_pin(uint8_t pin) +{ + if(false // start condition is always needed + +// Use individual checks instead of switch statement, as some case labels could be duplicated +#ifdef TOUCH_CS + || (pin == TOUCH_CS) +#endif +#ifdef TFT_MOSI + || (pin == TFT_MOSI) +#endif +#ifdef TFT_MISO + || (pin == TFT_MISO) +#endif +#ifdef TFT_SCLK + || (pin == TFT_SCLK) +#endif +#ifdef TFT_CS + || (pin == TFT_CS) +#endif +#ifdef TFT_DC + || (pin == TFT_DC) +#endif +#ifdef TFT_BL + || (pin == TFT_BL) +#endif +#ifdef TFT_RST + || (pin == TFT_RST) +#endif +#ifdef TFT_WR + || (pin == TFT_WR) +#endif +#ifdef TFT_RD + || (pin == TFT_RD) +#endif +#ifdef TFT_D0 + || (pin == TFT_D0) +#endif +#ifdef TFT_D1 + || (pin == TFT_D1) +#endif +#ifdef TFT_D2 + || (pin == TFT_D2) +#endif +#ifdef TFT_D3 + || (pin == TFT_D3) +#endif +#ifdef TFT_D4 + || (pin == TFT_D4) +#endif +#ifdef TFT_D5 + || (pin == TFT_D5) +#endif +#ifdef TFT_D6 + || (pin == TFT_D6) +#endif +#ifdef TFT_D7 + || (pin == TFT_D7) +#endif +#ifdef TFT_D8 + || (pin == TFT_D8) +#endif +#ifdef TFT_D9 + || (pin == TFT_D9) +#endif +#ifdef TFT_D10 + || (pin == TFT_D10) +#endif +#ifdef TFT_D11 + || (pin == TFT_D11) +#endif +#ifdef TFT_D12 + || (pin == TFT_D12) +#endif +#ifdef TFT_D13 + || (pin == TFT_D13) +#endif +#ifdef TFT_D14 + || (pin == TFT_D14) +#endif +#ifdef TFT_D15 + || (pin == TFT_D15) +#endif + ) { + return true; + } + +#ifdef ARDUINO_ARCH_ESP8266 +#ifndef TFT_SPI_OVERLAP + if((pin >= 12) && (pin <= 14)) return true; // HSPI +#endif +#endif + + return false; +} +} // namespace dev + dev::TftEspi haspTft; #endif \ No newline at end of file diff --git a/src/drv/tft_driver_tftespi.h b/src/drv/tft_driver_tftespi.h index 4cb29f70..63931c0a 100644 --- a/src/drv/tft_driver_tftespi.h +++ b/src/drv/tft_driver_tftespi.h @@ -23,127 +23,15 @@ namespace dev { class TftEspi : BaseTft { public: - void init(int w, int h) - { - tft.begin(); - tft.setSwapBytes(true); /* set endianess */ - } - void show_info() - { + void init(int w, int h); + void show_info(); + void splashscreen(); - setup_t tftSetup; - tft.getSetup(tftSetup); + void set_rotation(uint8_t rotation); + void set_invert(bool invert); - LOG_VERBOSE(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str()); - LOG_VERBOSE(TAG_TFT, F("Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); - LOG_VERBOSE(TAG_TFT, F("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel")); - -#if defined(ARDUINO_ARCH_ESP8266) - LOG_VERBOSE(TAG_TFT, F("SPI overlap: %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No")); -#endif - - if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch - { - LOG_VERBOSE(TAG_TFT, F("Driver : %s"), halDisplayDriverName().c_str()); // tftSetup.tft_driver); - LOG_VERBOSE(TAG_TFT, F("Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height); - } else if(tftSetup.tft_driver == 0xE9D) - LOG_VERBOSE(TAG_TFT, F("Driver = ePaper")); - - // Offsets, not all used yet - tftOffsetInfo(0, tftSetup.r0_x_offset, tftSetup.r0_y_offset); - tftOffsetInfo(1, tftSetup.r1_x_offset, tftSetup.r1_y_offset); - tftOffsetInfo(2, tftSetup.r2_x_offset, tftSetup.r2_y_offset); - tftOffsetInfo(3, tftSetup.r3_x_offset, tftSetup.r3_y_offset); - /* replaced by tftOffsetInfo - // if(tftSetup.r1_x_offset != 0) Serial.printf("R1 x offset = %i \n", tftSetup.r1_x_offset); - // if(tftSetup.r1_y_offset != 0) Serial.printf("R1 y offset = %i \n", tftSetup.r1_y_offset); - // if(tftSetup.r2_x_offset != 0) Serial.printf("R2 x offset = %i \n", tftSetup.r2_x_offset); - // if(tftSetup.r2_y_offset != 0) Serial.printf("R2 y offset = %i \n", tftSetup.r2_y_offset); - // if(tftSetup.r3_x_offset != 0) Serial.printf("R3 x offset = %i \n", tftSetup.r3_x_offset); - // if(tftSetup.r3_y_offset != 0) Serial.printf("R3 y offset = %i \n", tftSetup.r3_y_offset); - */ - - tftPinInfo(F("MOSI"), tftSetup.pin_tft_mosi); - tftPinInfo(F("MISO"), tftSetup.pin_tft_miso); - tftPinInfo(F("SCLK"), tftSetup.pin_tft_clk); - -#if defined(ARDUINO_ARCH_ESP8266) - if(tftSetup.overlap == true) { - LOG_VERBOSE(TAG_TFT, F("Overlap selected, following pins MUST be used:")); - - LOG_VERBOSE(TAG_TFT, F("MOSI : SD1 (GPIO 8)")); - LOG_VERBOSE(TAG_TFT, F("MISO : SD0 (GPIO 7)")); - LOG_VERBOSE(TAG_TFT, F("SCK : CLK (GPIO 6)")); - LOG_VERBOSE(TAG_TFT, F("TFT_CS : D3 (GPIO 0)")); - - LOG_VERBOSE(TAG_TFT, F("TFT_DC and TFT_RST pins can be tftSetup defined")); - } -#endif - - tftPinInfo(F("TFT_CS"), tftSetup.pin_tft_cs); - tftPinInfo(F("TFT_DC"), tftSetup.pin_tft_dc); - tftPinInfo(F("TFT_RST"), tftSetup.pin_tft_rst); - - tftPinInfo(F("TOUCH_CS"), tftSetup.pin_tch_cs); - - tftPinInfo(F("TFT_WR"), tftSetup.pin_tft_wr); - tftPinInfo(F("TFT_RD"), tftSetup.pin_tft_rd); - - tftPinInfo(F("TFT_D0"), tftSetup.pin_tft_d0); - tftPinInfo(F("TFT_D1"), tftSetup.pin_tft_d1); - tftPinInfo(F("TFT_D2"), tftSetup.pin_tft_d2); - tftPinInfo(F("TFT_D3"), tftSetup.pin_tft_d3); - tftPinInfo(F("TFT_D4"), tftSetup.pin_tft_d4); - tftPinInfo(F("TFT_D5"), tftSetup.pin_tft_d5); - tftPinInfo(F("TFT_D6"), tftSetup.pin_tft_d6); - tftPinInfo(F("TFT_D7"), tftSetup.pin_tft_d7); - - if(tftSetup.serial == 1) { - LOG_VERBOSE(TAG_TFT, F("Display SPI freq. : %d.%d MHz"), tftSetup.tft_spi_freq / 10, - tftSetup.tft_spi_freq % 10); - } - if(tftSetup.pin_tch_cs != -1) { - LOG_VERBOSE(TAG_TFT, F("Touch SPI freq. : %d.%d MHz"), tftSetup.tch_spi_freq / 10, - tftSetup.tch_spi_freq % 10); - } - } - void splashscreen() - { - tft.fillScreen(TFT_DARKCYAN); - int x = (tft.width() - logoWidth) / 2; - int y = (tft.height() - logoHeight) / 2; - tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE); - } - void set_rotation(uint8_t rotation) - { - LOG_VERBOSE(TAG_TFT, F("Rotation : %d"), rotation); - tft.setRotation(rotation); - } - void set_invert(bool invert) - { - char buffer[4]; - memcpy_P(buffer, invert ? PSTR("yes") : PSTR("no"), sizeof(buffer)); - - LOG_VERBOSE(TAG_TFT, F("Invert Disp: %s"), buffer); - tft.invertDisplay(invert); - } - void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) - { - size_t len = lv_area_get_size(area); - - /* Update TFT */ - tft.startWrite(); /* Start new TFT transaction */ - tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */ -#ifdef USE_DMA_TO_TFT - tft.pushPixelsDMA((uint16_t*)color_p, len); /* Write words at once */ -#else - tft.pushPixels((uint16_t*)color_p, len); /* Write words at once */ -#endif - tft.endWrite(); /* terminate TFT transaction */ - - /* Tell lvgl that flushing is done */ - lv_disp_flush_ready(disp); - } + void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); + bool is_driver_pin(uint8_t pin); private: TFT_eSPI tft; From 6d2ac824529b61d2731905c03c2a7b24c8bb9df6 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 20:41:28 +0100 Subject: [PATCH 084/236] Corrected HASP_USE_GPIO --- src/hasp/hasp_dispatch.cpp | 41 ++++++++++++++++++++++++++------------ src/sys/gpio/hasp_gpio.cpp | 2 +- src/sys/svc/hasp_http.cpp | 2 +- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 4e6a360a..f8752c82 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -613,7 +613,7 @@ void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t* { if(groupid > 0) { LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d"), groupid, value); -#if USE_GPIO +#if HASP_USE_GPIO > 0 gpio_set_normalized_group_value(groupid, value); #endif // object_set_group_state(groupid, value, obj); @@ -652,15 +652,20 @@ void dispatch_parse_json(const char*, const char* payload) uint8_t savedPage = haspGetPage(); hasp_new_object(json.as(), savedPage); +#ifdef ARDUINO + } else if(json.is()) { // handle json as a single command + dispatch_text_line(json.as().c_str()); +#else + } else if(json.is()) { // handle json as a single command + dispatch_text_line(json.as().c_str()); +#endif + } else if(json.is()) { // handle json as a single command dispatch_text_line(json.as()); } else if(json.is()) { // handle json as a single command dispatch_text_line(json.as()); - // } else if(json.is()) { // handle json as a single command - // dispatch_text_line(json.as().c_str()); - } else { LOG_WARNING(TAG_MSGR, F(D_DISPATCH_COMMAND_NOT_FOUND), payload); } @@ -800,22 +805,32 @@ void dispatch_moodlight(const char* topic, const char* payload) dispatch_json_error(TAG_MSGR, jsonError); } else { - if(!json[F("state")].isNull()) moodlight.power = Utilities::is_true(json[F("state")].as()); + if(!json[F("state")].isNull()) + moodlight.power = Utilities::is_true(json[F("state")].as().c_str()); if(!json[F("r")].isNull()) moodlight.r = json[F("r")].as(); if(!json[F("g")].isNull()) moodlight.r = json[F("g")].as(); if(!json[F("b")].isNull()) moodlight.r = json[F("b")].as(); if(!json[F("color")].isNull()) { - lv_color32_t color; - if(Parser::haspPayloadToColor(json[F("color")].as(), color)) { - moodlight.r = color.ch.red; - moodlight.g = color.ch.green; - moodlight.b = color.ch.blue; + if(!json[F("color")]["r"].isNull()) { + moodlight.r = json[F("color")]["r"].as(); } + if(!json[F("color")]["g"].isNull()) { + moodlight.g = json[F("color")]["g"].as(); + } + if(!json[F("color")]["b"].isNull()) { + moodlight.b = json[F("color")]["b"].as(); + } + // lv_color32_t color; + // if(Parser::haspPayloadToColor(json[F("color")].as(), color)) { + // moodlight.r = color.ch.red; + // moodlight.g = color.ch.green; + // moodlight.b = color.ch.blue; + // } } -#ifdef USE_GPIO +#if HASP_USE_GPIO > 0 if(moodlight.power) gpio_set_moodlight(moodlight.r, moodlight.g, moodlight.b); else @@ -828,8 +843,8 @@ void dispatch_moodlight(const char* topic, const char* payload) char buffer[128]; snprintf_P( // buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"), - buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":[%u,%u,%u]}"), moodlight.power ? "ON" : "OFF", - moodlight.r, moodlight.g, moodlight.b); + buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":{\"r\":%u,\"g\":%u,\"b\":%u}}"), + moodlight.power ? "ON" : "OFF", moodlight.r, moodlight.g, moodlight.b); dispatch_state_msg(F("moodlight"), buffer); } diff --git a/src/sys/gpio/hasp_gpio.cpp b/src/sys/gpio/hasp_gpio.cpp index f2963f1c..adc96484 100644 --- a/src/sys/gpio/hasp_gpio.cpp +++ b/src/sys/gpio/hasp_gpio.cpp @@ -460,7 +460,7 @@ bool gpioIsSystemPin(uint8_t gpio) // Backlight GPIO // Network GPIOs // Serial GPIOs - // Tasmota Slave GPIOs + // Tasmota Client GPIOs #ifdef ARDUINO_ARCH_ESP32 if((gpio >= 6) && (gpio <= 11)) return true; // integrated SPI flash diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 170e088e..b8c51533 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1344,7 +1344,7 @@ void webHandleHttpConfig() #endif //////////////////////////////////////////////////////////////////////////////////////////////////// -#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) +#if HASP_USE_GPIO > 0 void webHandleGpioConfig() { // http://plate01/config/gpio if(!httpIsAuthenticated(F("config/gpio"))) return; From 13563809d963be3de2cee23b54a31cf4ba3457e5 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 20:42:09 +0100 Subject: [PATCH 085/236] Update moodlight auto-discovery --- src/mqtt/hasp_mqtt_ha.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index 3eeebcbb..bac982c8 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -214,12 +214,22 @@ void mqtt_ha_register_moodlight() deserializeJson(doc, F("{" "\"cmd_t\":\"~command/moodlight\"," "\"stat_t\":\"~state/moodlight\"," - "\"avty_t\":\"~LWT\"," - "\"bri_stat_t\":\"~state/moodlight/dim\"," - "\"bri_cmd_t\":\"~command/moodlight/dim\"," - "\"bri_scl\":100," - "\"rgb_stat_t\":\"~state/moodlight/rgb\"," - "\"rgb_cmd_t\":\"~command/moodlight/rgb\"}")); + "\"platform\":\"mqtt\"," + "\"schema\":\"json\"," + "\"rgb\":true," + "\"brightness\":true," + "\"avty_t\":\"~LWT\"}")); + + /* deserializeJson(doc, F("{" + "\"cmd_t\":\"~command/moodlight\"," + // "\"stat_t\":\"~state/moodlight\"," + "\"avty_t\":\"~LWT\"," + "\"bri_stat_t\":\"~state/moodlight/dim\"," + "\"bri_cmd_t\":\"~command/moodlight/dim\"," + "\"bri_scl\":100," + "\"rgb_stat_t\":\"~state/moodlight/rgb\"," + "\"rgb_cmd_t\":\"~command/moodlight/rgb\"}")); + */ mqtt_ha_add_device_ids(doc); mqtt_ha_add_unique_id(doc, item); From 0f24c6c4ae7c4a99b8fbade1dab57901bc53d51a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 21:15:10 +0100 Subject: [PATCH 086/236] Code clean-up --- src/sys/svc/hasp_telnet.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sys/svc/hasp_telnet.cpp b/src/sys/svc/hasp_telnet.cpp index e760b7cf..52de8836 100644 --- a/src/sys/svc/hasp_telnet.cpp +++ b/src/sys/svc/hasp_telnet.cpp @@ -30,8 +30,6 @@ static EthernetServer telnetServer(23); #endif #if HASP_USE_HTTP > 0 -// extern char http_config.user[32]; -// extern char http_config.password[32]; extern hasp_http_config_t http_config; #endif From 5ca89f9c84b61c72ffe2d349da51c5a1f66127eb Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:13:11 +0100 Subject: [PATCH 087/236] Fix gpio lag when changing moodlight --- src/sys/gpio/hasp_gpio.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sys/gpio/hasp_gpio.cpp b/src/sys/gpio/hasp_gpio.cpp index adc96484..21caa060 100644 --- a/src/sys/gpio/hasp_gpio.cpp +++ b/src/sys/gpio/hasp_gpio.cpp @@ -343,14 +343,17 @@ void gpio_set_normalized_group_value(uint8_t groupid, uint16_t state) void gpio_set_moodlight(uint8_t r, uint8_t g, uint8_t b) { for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) { - switch(gpioConfig[i].type & 0xfe) { + switch(gpioConfig[i].type) { case HASP_GPIO_LED_R: + case HASP_GPIO_LED_R_INVERTED: gpio_set_normalized_value(gpioConfig[i], map(r, 0, 0xFF, 0, 0xFFFFU)); break; case HASP_GPIO_LED_G: + case HASP_GPIO_LED_G_INVERTED: gpio_set_normalized_value(gpioConfig[i], map(g, 0, 0xFF, 0, 0xFFFFU)); break; case HASP_GPIO_LED_B: + case HASP_GPIO_LED_B_INVERTED: gpio_set_normalized_value(gpioConfig[i], map(b, 0, 0xFF, 0, 0xFFFFU)); break; } From e3156d659d89cd3d7fe0bdd00831b322edbd9f5a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:13:31 +0100 Subject: [PATCH 088/236] Remove HASP prefix from enitiy names --- src/mqtt/hasp_mqtt_ha.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index bac982c8..2de8af07 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -90,7 +90,7 @@ void mqtt_ha_add_unique_id(JsonDocument& doc, char* item) { char buffer[64]; - snprintf_P(buffer, sizeof(buffer), PSTR("HASP %s %s"), haspDevice.get_hostname(), item); + snprintf_P(buffer, sizeof(buffer), PSTR("%s %s"), haspDevice.get_hostname(), item); doc[FPSTR(FP_MQTT_HA_NAME)] = buffer; snprintf_P(buffer, sizeof(buffer), PSTR("hasp_%s-%s"), HASP_MAC_ADDRESS, item); From 301af99dd6687499c3aea1ee2b1142f24ceb39ee Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:13:52 +0100 Subject: [PATCH 089/236] Add default return value to is_driver_pin --- src/drv/tft_driver.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/drv/tft_driver.h b/src/drv/tft_driver.h index 8423b503..c528ede4 100644 --- a/src/drv/tft_driver.h +++ b/src/drv/tft_driver.h @@ -24,7 +24,9 @@ class BaseTft { static void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) {} virtual bool is_driver_pin(uint8_t) - {} + { + return false; + } }; } // namespace dev From abb69ce5dd800212c8efad9d1550f6ea70e5b799 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:14:25 +0100 Subject: [PATCH 090/236] Check if TFT_BCKL is defined before using --- src/dev/esp32/esp32.h | 6 +++++- src/dev/esp8266/esp8266.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 44be6a6b..90f7485a 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -16,9 +16,13 @@ class Esp32Device : public BaseDevice { Esp32Device() { _hostname = "plate"; - _backlight_pin = TFT_BCKL; _backlight_power = 1; _backlight_level = 100; +#ifdef TFT_BCKL + _backlight_pin = TFT_BCKL; +#else + _backlight_pin = -1; +#endif } void reboot() override; void show_info() override; diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index cdd6526d..458add99 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -17,9 +17,13 @@ class Esp8266Device : public BaseDevice { Esp8266Device() { _hostname = "plate"; - _backlight_pin = TFT_BCKL; _backlight_power = 1; _backlight_level = 100; +#ifdef TFT_BCKL + _backlight_pin = TFT_BCKL; +#else + _backlight_pin = -1; +#endif } void reboot() override; From 38f80b0b9108185b0cd175036b6f602b9ca0e579 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:15:52 +0100 Subject: [PATCH 091/236] Add ARDUINOJSON_ENABLE_STD_STRING for std::string --- platformio.ini | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/platformio.ini b/platformio.ini index 08cf0f6d..4f6c92de 100644 --- a/platformio.ini +++ b/platformio.ini @@ -171,25 +171,26 @@ board_build.f_cpu = 160000000L ; set frequency to 160MHz monitor_filters = esp8266_exception_decoder build_flags= - -D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer - -D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages - -D HASP_CONSOLE_BUFFER=160 ; maximum length of a console/telnet command - -D ATOMIC_FS_UPDATE ; enabled compressed ota updates - -D NO_GLOBAL_HTTPUPDATE ; dont instantiate httpUpdate + -D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer + -D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages + -D HASP_CONSOLE_BUFFER=160 ; maximum length of a console/telnet command + -D ATOMIC_FS_UPDATE ; enabled compressed ota updates + -D NO_GLOBAL_HTTPUPDATE ; dont instantiate httpUpdate ; -- lwIP Variant ----------------------------------- ;-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY ; -- lvgl build options ----------------------------- - -D LV_MEM_SIZE=12288U ; 12kB lvgl memory + -D LV_MEM_SIZE=12288U ; 12kB lvgl memory ; -- ArduinoJson build options ---------------------------- - -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments + -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments + -D ARDUINOJSON_ENABLE_STD_STRING=1 ; for std::string ; -- hasp-lvgl build options ------------------------ -D HASP_USE_TELNET=1 ;-D HASP_USE_SPIFFS=1 -D HASP_USE_LITTLEFS=1 -D HASP_USE_EEPROM=1 -D HASP_USE_ETHERNET=0 - -D HASP_USE_CONFIG=1 ; Native application, not library + -D HASP_USE_CONFIG=1 ; Native application, not library lib_ignore = ESP32 BLE Arduino @@ -204,18 +205,18 @@ lib_deps = framework = arduino build_flags= -I include/stm32f4 - -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages - -D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command - -D IRAM_ATTR= ; No IRAM_ATTR available on STM32 + -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages + -D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command + -D IRAM_ATTR= ; No IRAM_ATTR available on STM32 -D ICACHE_RAM_ATTR= -D STM32 -D STREAMUTILS_USE_EEPROM_UPDATE=1 ; update cell only when changed ; -- lvgl build options ----------------------------- - -D LV_MEM_SIZE=20480U ; 20kB lvgl memory - -D HASP_USE_SYSLOG=0 ; Needs UDP + -D LV_MEM_SIZE=20480U ; 20kB lvgl memory + -D HASP_USE_SYSLOG=0 ; Needs UDP -D HASP_USE_SPIFFS=0 -D HASP_USE_LITTLEFS=0 - -D HASP_USE_CONFIG=1 ; Native application, not library + -D HASP_USE_CONFIG=1 ; Native application, not library lib_deps = ; sstaub/Ticker @ ^3.2.0 From 45a364c076e5fff01313e6df575ccab5f9607953 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 03:09:05 +0100 Subject: [PATCH 092/236] Fix build errors on ESP32 ethernet --- include/hasp_conf.h | 2 +- src/mqtt/hasp_mqtt.h | 1 + src/sys/net/hasp_ethernet_esp32.cpp | 4 +++- src/sys/net/hasp_ethernet_esp32.h | 1 + src/sys/net/hasp_ethernet_stm32.h | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 3c64ab88..eb034f37 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -160,7 +160,7 @@ static WiFiSpiClass WiFi; #define ETH_TYPE ETH_PHY_LAN8720 #define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT -#include "net/hasp_ethernet_esp32.h" +#include "sys/net/hasp_ethernet_esp32.h" #warning Using ESP32 Ethernet LAN8720 #else diff --git a/src/mqtt/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h index 8e47773c..18f007ea 100644 --- a/src/mqtt/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -5,6 +5,7 @@ #define HASP_MQTT_H #include +#include "ArduinoJson.h" #include "hasp_conf.h" diff --git a/src/sys/net/hasp_ethernet_esp32.cpp b/src/sys/net/hasp_ethernet_esp32.cpp index 6b78e836..c3244afe 100644 --- a/src/sys/net/hasp_ethernet_esp32.cpp +++ b/src/sys/net/hasp_ethernet_esp32.cpp @@ -2,10 +2,12 @@ For full license information read the LICENSE file in the project folder */ #include "hasp_conf.h" -#include "hal/hasp_hal.h" #include "hasp_debug.h" #include "hasp_network.h" +#include "hal/hasp_hal.h" +#include "dev/device.h" + #if HASP_USE_ETHERNET > 0 && defined(ARDUINO_ARCH_ESP32) IPAddress ip; diff --git a/src/sys/net/hasp_ethernet_esp32.h b/src/sys/net/hasp_ethernet_esp32.h index 3eb24e4e..8a25a147 100644 --- a/src/sys/net/hasp_ethernet_esp32.h +++ b/src/sys/net/hasp_ethernet_esp32.h @@ -9,6 +9,7 @@ static bool eth_connected = false; void ethernetSetup(); void ethernetLoop(void); +bool ethernetEverySecond(); bool ethernetEvery5Seconds(); void ethernet_get_statusupdate(char* buffer, size_t len); diff --git a/src/sys/net/hasp_ethernet_stm32.h b/src/sys/net/hasp_ethernet_stm32.h index ed3a76c1..f499069f 100644 --- a/src/sys/net/hasp_ethernet_stm32.h +++ b/src/sys/net/hasp_ethernet_stm32.h @@ -9,6 +9,7 @@ static bool eth_connected = false; void ethernetSetup(); void ethernetLoop(void); +bool ethernetEverySecond(); bool ethernetEvery5Seconds(); void ethernet_get_statusupdate(char* buffer, size_t len); From 8481ba85f7b346e4e02caa0becd68f8cefb2c1a2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 03:09:14 +0100 Subject: [PATCH 093/236] Code clean-up --- platformio.ini | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/platformio.ini b/platformio.ini index 4f6c92de..163f6391 100644 --- a/platformio.ini +++ b/platformio.ini @@ -222,30 +222,4 @@ lib_deps = ; sstaub/Ticker @ ^3.2.0 stm32duino/STM32duino LwIP @ ^2.1.2 ;https://github.com/stm32duino/LwIP.git - - -;*************************************************** -; Native build -;*************************************************** -;[env:native] -;platform = native -;build_flags = -; -D LV_CONF_INCLUDE_SIMPLE -; ; -I src Required to find lv_conf.h -; -I src -; -I drivers/sdl2 -; -lSDL2 -; ; SDL drivers options -; -D LV_LVGL_H_INCLUDE_SIMPLE -; -D LV_DRV_NO_CONF -; -D USE_MONITOR -; -D MONITOR_ZOOM=2 -; -D USE_MOUSE -; -D USE_MOUSEWHEEL -; -D USE_KEYBOARD -;lib_deps = -; ;lvgl=https://github.com/littlevgl/lvgl/archive/master.zip -; ;lvgl@^6.1.0 -; ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/master.zip -; lv_drivers@^6.0.2 -;src_filter = +<*> +<../drivers/sdl2> + \ No newline at end of file From 5be38e90204581cdd22a122711eadf30afcd86ac Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 04:05:51 +0100 Subject: [PATCH 094/236] Create README --- src/sys/README | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/sys/README diff --git a/src/sys/README b/src/sys/README new file mode 100644 index 00000000..33252851 --- /dev/null +++ b/src/sys/README @@ -0,0 +1,4 @@ +System Component functions +- net : Control of the user customizable GPIO funcionality +- net : Unified network functions for wifi or ethernet +- svc : Network services From 218aa2565b3591f723023211f6bb0925172fb625 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 04:06:11 +0100 Subject: [PATCH 095/236] Rename README to README.md --- src/sys/{README => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/sys/{README => README.md} (100%) diff --git a/src/sys/README b/src/sys/README.md similarity index 100% rename from src/sys/README rename to src/sys/README.md From fd2deddd40fdc4585b42e68cf79f07ac60044fcb Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 04:26:23 +0100 Subject: [PATCH 096/236] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d542cfdb..1b7ddf49 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Control your home-automation devices from a customizable touchscreen UI connecte This project is a re-implementation of the popular HASwitchPlate sketch created by aderusha. The [original HASwitchPlate][1] project uses a Wemos D1 mini and requires a Nextion/TJC HMI display. -This rewrite removes the Nextion/TJC requirement by using the [Littlev Graphics Library][2] on the MCU to drive a cheap commodity display. +This rewrite removes the Nextion/TJC requirement by using the [Light and Versatile Graphics Library][2] on the MCU to drive a cheap commodity display. This version also adds ESP32 and STM32F4 support to take advantage of the additional hardware capabilities. @@ -72,7 +72,7 @@ For support using hasp-lvgl, please join the [#hasp-lvgl channel][6] on Discord. [1]: https://github.com/aderusha/HASwitchPlate -[2]: https://github.com/littlevgl/lvgl +[2]: https://github.com/lvgl/lvgl [3]: https://littlevgl.com/themes [4]: https://github.com/fvanroie/HMI-Font-Pack/releases [5]: https://fontawesome.com/cheatsheet/ From 8ac166ce2d006b7ebd1a302c56a85d5aac227e8b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 04:26:44 +0100 Subject: [PATCH 097/236] Update stm32 base environment --- platformio.ini | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 163f6391..f65889e5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -203,6 +203,7 @@ lib_deps = [stm32f4] framework = arduino +platform = ststm32 build_flags= -I include/stm32f4 -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages @@ -210,6 +211,8 @@ build_flags= -D IRAM_ATTR= ; No IRAM_ATTR available on STM32 -D ICACHE_RAM_ATTR= -D STM32 + -D ARDUINOJSON_DECODE_UNICODE=1 ; for utf-8 symbols + -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments -D STREAMUTILS_USE_EEPROM_UPDATE=1 ; update cell only when changed ; -- lvgl build options ----------------------------- -D LV_MEM_SIZE=20480U ; 20kB lvgl memory @@ -222,4 +225,3 @@ lib_deps = ; sstaub/Ticker @ ^3.2.0 stm32duino/STM32duino LwIP @ ^2.1.2 ;https://github.com/stm32duino/LwIP.git - \ No newline at end of file From ebc8490dcbfd911fcd8e079e4a6c97fad24dd21e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 04:27:18 +0100 Subject: [PATCH 098/236] Add Stm32f4Device --- src/dev/stm32f4/stm32f4.cpp | 122 ++++++++++++++++++++++++++++++++++++ src/dev/stm32f4/stm32f4.h | 67 ++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 src/dev/stm32f4/stm32f4.cpp create mode 100644 src/dev/stm32f4/stm32f4.h diff --git a/src/dev/stm32f4/stm32f4.cpp b/src/dev/stm32f4/stm32f4.cpp new file mode 100644 index 00000000..78e84484 --- /dev/null +++ b/src/dev/stm32f4/stm32f4.cpp @@ -0,0 +1,122 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#if defined(STM32F4xx) + +#include "Arduino.h" + +#include "stm32f4.h" + +#include "hasp_conf.h" +#include "hasp_debug.h" +#include "hasp/hasp_utilities.h" + +#define BACKLIGHT_CHANNEL 0 + +namespace dev { + +void Stm32f4Device::reboot() +{ + // ESP.restart(); +} + +void Stm32f4Device::show_info() +{ + LOG_VERBOSE(TAG_DEV, F("Processor : STM32F4xx")); + // LOG_VERBOSE(TAG_DEV, F("CPU freq. : %i MHz"), get_cpu_frequency()); + // LOG_VERBOSE(TAG_DEV, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined +} + +const char* Stm32f4Device::get_hostname() +{ + return _hostname.c_str(); +} +void Stm32f4Device::set_hostname(const char* hostname) +{ + _hostname = hostname; +} + +const char* Stm32f4Device::get_core_version() +{ + // return ESP.getCoreVersion().c_str(); +} + +const char* Stm32f4Device::get_display_driver() +{ + return Utilities::tft_driver_name().c_str(); +} + +void Stm32f4Device::set_backlight_pin(uint8_t pin) +{ + _backlight_pin = pin; + /* Setup Backlight Control Pin */ + if(pin >= 0) { + LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); + pinMode(_backlight_pin, OUTPUT); + update_backlight(); + } +} + +void Stm32f4Device::set_backlight_level(uint8_t level) +{ + _backlight_level = level >= 0 ? level : 0; + _backlight_level = _backlight_level <= 100 ? _backlight_level : 100; + + update_backlight(); +} + +uint8_t Stm32f4Device::get_backlight_level() +{ + return _backlight_level; +} + +void Stm32f4Device::set_backlight_power(bool power) +{ + _backlight_power = power; + update_backlight(); +} + +bool Stm32f4Device::get_backlight_power() +{ + return _backlight_power != 0; +} + +void Stm32f4Device::update_backlight() +{ + if(_backlight_pin == -1) return; + + // analogWrite(_backlight_pin, _backlight_power ? map(_backlight_level, 0, 100, 0, 1023) : 0); +} + +size_t Stm32f4Device::get_free_max_block() +{ + // return ESP.getMaxFreeBlockSize(); +} + +size_t Stm32f4Device::get_free_heap(void) +{ + // return ESP.getFreeHeap(); +} + +uint8_t Stm32f4Device::get_heap_fragmentation() +{ + // return ESP.getHeapFragmentation(); +} + +uint16_t Stm32f4Device::get_cpu_frequency() +{ + // return ESP.getCpuFreqMHz(); +} + +bool Stm32f4Device::is_system_pin(uint8_t pin) +{ + // if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash + // if((pin >= 12) && (pin <= 14)) return true; // HSPI + return false; +} + +} // namespace dev + +dev::Stm32f4Device haspDevice; + +#endif // STM32F4xx \ No newline at end of file diff --git a/src/dev/stm32f4/stm32f4.h b/src/dev/stm32f4/stm32f4.h new file mode 100644 index 00000000..fcd76eba --- /dev/null +++ b/src/dev/stm32f4/stm32f4.h @@ -0,0 +1,67 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_DEVICE_STM32F4_H +#define HASP_DEVICE_STM32F4_H + +#include "hasp_conf.h" +#include "dev/device.h" + +#if defined(STM32F4xx) + +namespace dev { + +class Stm32f4Device : public BaseDevice { + + public: + Stm32f4Device() + { + _hostname = "plate"; + _backlight_power = 1; + _backlight_level = 100; +#ifdef TFT_BCKL + _backlight_pin = TFT_BCKL; +#else + _backlight_pin = -1; +#endif + } + + void reboot() override; + void show_info() override; + + const char* get_hostname(); + void set_hostname(const char*); + const char* get_core_version(); + const char* get_display_driver(); + + void set_backlight_pin(uint8_t pin) override; + void set_backlight_level(uint8_t val) override; + uint8_t get_backlight_level() override; + void set_backlight_power(bool power) override; + bool get_backlight_power() override; + + size_t get_free_max_block() override; + size_t get_free_heap() override; + uint8_t get_heap_fragmentation() override; + uint16_t get_cpu_frequency() override; + + bool is_system_pin(uint8_t pin) override; + + private: + std::string _hostname; + + uint8_t _backlight_pin; + uint8_t _backlight_level; + uint8_t _backlight_power; + + void update_backlight(); +}; + +} // namespace dev + +using dev::Stm32f4Device; +extern dev::Stm32f4Device haspDevice; + +#endif // STM32F4xx + +#endif // HASP_DEVICE_STM32F4_H \ No newline at end of file From 920911dec0d41f150a0a84675ea92599593a84ab Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 04:28:11 +0100 Subject: [PATCH 099/236] Update ststm32 platform environment --- user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini | 2 +- user_setups/stm32f4xx/stm32f407-black_ili9341.ini | 2 +- user_setups/stm32f4xx/stm32f407-black_ili9341_parallel.ini | 2 +- user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini | 2 +- user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini b/user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini index 0534321f..7af5c6d8 100644 --- a/user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini +++ b/user_setups/stm32f4xx/STM32F407VET6_black_fsmc.ini @@ -22,7 +22,7 @@ ; Documentation: https://github.com/mcauser/BLACK_F407ZG [env:STM32F407VET6_black_fsmc] -platform = ststm32 +extends = stm32f4 board = black_f407ve ; upload_protocol = dfu upload_protocol = dfu diff --git a/user_setups/stm32f4xx/stm32f407-black_ili9341.ini b/user_setups/stm32f4xx/stm32f407-black_ili9341.ini index 2b3d9388..a6e4e8d4 100644 --- a/user_setups/stm32f4xx/stm32f407-black_ili9341.ini +++ b/user_setups/stm32f4xx/stm32f407-black_ili9341.ini @@ -6,7 +6,7 @@ ;***************************************************; [env:black_f407vg] -platform = ststm32 +extends = stm32f4 board = diymore_f407vgt board_build.mcu = stm32f407vgt6 upload_protocol = dfu diff --git a/user_setups/stm32f4xx/stm32f407-black_ili9341_parallel.ini b/user_setups/stm32f4xx/stm32f407-black_ili9341_parallel.ini index 54221de1..930292b9 100644 --- a/user_setups/stm32f4xx/stm32f407-black_ili9341_parallel.ini +++ b/user_setups/stm32f4xx/stm32f407-black_ili9341_parallel.ini @@ -6,7 +6,7 @@ ;***************************************************; [env:stm32f4xx-parallel] -platform = ststm32 +extends = stm32f4 board = diymore_f407vgt board_build.mcu = stm32f407vet6 upload_protocol = dfu diff --git a/user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini b/user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini index b019108b..a87b5fe9 100644 --- a/user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini +++ b/user_setups/stm32f4xx/stm32f407-black_ili9341_wifi.ini @@ -6,7 +6,7 @@ ;***************************************************; [env:black_f407vg_wifi] -platform = ststm32 +extends = stm32f4 board = diymore_f407vgt board_build.mcu = stm32f407vgt6 upload_protocol = dfu diff --git a/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini b/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini index 4005c4a8..29613e17 100644 --- a/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini +++ b/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini @@ -15,7 +15,7 @@ ; - STM32F407VGT6 has 1 MB flash [env:DevEBox_STM32F4xx] -platform = ststm32 +extends = stm32f4 board = black_f407vg board_upload.maximum_size = 1048576 ; Flash size is wrong in variant ; upload_protocol = dfu From 257f7530578f4726fe1fe5d59aa227acd95f6132 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 22:35:00 +0100 Subject: [PATCH 100/236] Move AXP192 library to external github --- lib/AXP192/AXP192.cpp | 602 ---------------------------- lib/AXP192/AXP192.h | 106 ----- lib/AXP192/LICENSE | 21 - user_setups/esp32/m5stack_core2.ini | 2 +- 4 files changed, 1 insertion(+), 730 deletions(-) delete mode 100644 lib/AXP192/AXP192.cpp delete mode 100644 lib/AXP192/AXP192.h delete mode 100644 lib/AXP192/LICENSE diff --git a/lib/AXP192/AXP192.cpp b/lib/AXP192/AXP192.cpp deleted file mode 100644 index 7480a9e7..00000000 --- a/lib/AXP192/AXP192.cpp +++ /dev/null @@ -1,602 +0,0 @@ -#include "AXP192.h" - -AXP192::AXP192() -{ -} - -void AXP192::begin(void) -{ - - Wire1.begin(21, 22); - Wire1.setClock(400000); - - //AXP192 30H - Write1Byte(0x30, (Read8bit(0x30) & 0x04) | 0X02); - Serial.printf("axp: vbus limit off\n"); - - //AXP192 GPIO1:OD OUTPUT - Write1Byte(0x92, Read8bit(0x92) & 0xf8); - Serial.printf("axp: gpio1 init\n"); - - //AXP192 GPIO2:OD OUTPUT - Write1Byte(0x93, Read8bit(0x93) & 0xf8); - Serial.printf("axp: gpio2 init\n"); - - //AXP192 RTC CHG - Write1Byte(0x35, (Read8bit(0x35) & 0x1c) | 0xa2); - Serial.printf("axp: rtc battery charging enabled\n"); - - SetESPVoltage(3350); - Serial.printf("axp: esp32 power voltage was set to 3.35v\n"); - - SetLcdVoltage(2800); - Serial.printf("axp: lcd backlight voltage was set to 2.80v\n"); - - SetLDOVoltage(2, 3300); //Periph power voltage preset (LCD_logic, SD card) - Serial.printf("axp: lcd logic and sdcard voltage preset to 3.3v\n"); - - SetLDOVoltage(3, 2000); //Vibrator power voltage preset - Serial.printf("axp: vibrator voltage preset to 2v\n"); - - SetLDOEnable(2, true); - SetDCDC3(true); // LCD backlight - SetLed(true); - - SetCHGCurrent(kCHG_100mA); - //SetAxpPriphPower(1); - //Serial.printf("axp: lcd_logic and sdcard power enabled\n\n"); - - //pinMode(39, INPUT_PULLUP); - - //AXP192 GPIO4 - Write1Byte(0X95, (Read8bit(0x95) & 0x72) | 0X84); - - Write1Byte(0X36, 0X4C); - - Write1Byte(0x82,0xff); - - SetLCDRSet(0); - delay(100); - SetLCDRSet(1); - delay(100); - // I2C_WriteByteDataAt(0X15,0XFE,0XFF); - - // bus power mode_output - SetBusPowerMode(0); -} - -void AXP192::Write1Byte(uint8_t Addr, uint8_t Data) -{ - Wire1.beginTransmission(0x34); - Wire1.write(Addr); - Wire1.write(Data); - Wire1.endTransmission(); -} - -uint8_t AXP192::Read8bit(uint8_t Addr) -{ - Wire1.beginTransmission(0x34); - Wire1.write(Addr); - Wire1.endTransmission(); - Wire1.requestFrom(0x34, 1); - return Wire1.read(); -} - -uint16_t AXP192::Read12Bit(uint8_t Addr) -{ - uint16_t Data = 0; - uint8_t buf[2]; - ReadBuff(Addr, 2, buf); - Data = ((buf[0] << 4) + buf[1]); // - return Data; -} - -uint16_t AXP192::Read13Bit(uint8_t Addr) -{ - uint16_t Data = 0; - uint8_t buf[2]; - ReadBuff(Addr, 2, buf); - Data = ((buf[0] << 5) + buf[1]); // - return Data; -} - -uint16_t AXP192::Read16bit(uint8_t Addr) -{ - uint16_t ReData = 0; - Wire1.beginTransmission(0x34); - Wire1.write(Addr); - Wire1.endTransmission(); - Wire1.requestFrom(0x34, 2); - for (int i = 0; i < 2; i++) - { - ReData <<= 8; - ReData |= Wire1.read(); - } - return ReData; -} - -uint32_t AXP192::Read24bit(uint8_t Addr) -{ - uint32_t ReData = 0; - Wire1.beginTransmission(0x34); - Wire1.write(Addr); - Wire1.endTransmission(); - Wire1.requestFrom(0x34, 3); - for (int i = 0; i < 3; i++) - { - ReData <<= 8; - ReData |= Wire1.read(); - } - return ReData; -} - -uint32_t AXP192::Read32bit(uint8_t Addr) -{ - uint32_t ReData = 0; - Wire1.beginTransmission(0x34); - Wire1.write(Addr); - Wire1.endTransmission(); - Wire1.requestFrom(0x34, 2); - for (int i = 0; i < 4; i++) - { - ReData <<= 8; - ReData |= Wire1.read(); - } - return ReData; -} - -void AXP192::ReadBuff(uint8_t Addr, uint8_t Size, uint8_t *Buff) -{ - Wire1.beginTransmission(0x34); - Wire1.write(Addr); - Wire1.endTransmission(); - Wire1.requestFrom(0x34, (int)Size); - for (int i = 0; i < Size; i++) - { - *(Buff + i) = Wire1.read(); - } -} - -void AXP192::ScreenBreath(uint8_t brightness) -{ - if (brightness > 12) - { - brightness = 12; - } - uint8_t buf = Read8bit(0x28); - Write1Byte(0x28, ((buf & 0x0f) | (brightness << 4))); -} - -bool AXP192::GetBatState() -{ - if (Read8bit(0x01) | 0x20) - return true; - else - return false; -} -//---------coulombcounter_from_here--------- -//enable: void EnableCoulombcounter(void); -//disable: void DisableCOulombcounter(void); -//stop: void StopCoulombcounter(void); -//clear: void ClearCoulombcounter(void); -//get charge data: uint32_t GetCoulombchargeData(void); -//get discharge data: uint32_t GetCoulombdischargeData(void); -//get coulomb val affter calculation: float GetCoulombData(void); -//------------------------------------------ -void AXP192::EnableCoulombcounter(void) -{ - Write1Byte(0xB8, 0x80); -} - -void AXP192::DisableCoulombcounter(void) -{ - Write1Byte(0xB8, 0x00); -} - -void AXP192::StopCoulombcounter(void) -{ - Write1Byte(0xB8, 0xC0); -} - -void AXP192::ClearCoulombcounter(void) -{ - Write1Byte(0xB8, 0xA0); -} - -uint32_t AXP192::GetCoulombchargeData(void) -{ - return Read32bit(0xB0); -} - -uint32_t AXP192::GetCoulombdischargeData(void) -{ - return Read32bit(0xB4); -} - -float AXP192::GetCoulombData(void) -{ - - uint32_t coin = 0; - uint32_t coout = 0; - - coin = GetCoulombchargeData(); - coout = GetCoulombdischargeData(); - - //c = 65536 * current_LSB * (coin - coout) / 3600 / ADC rate - //Adc rate can be read from 84H ,change this variable if you change the ADC reate - float ccc = 65536 * 0.5 * (coin - coout) / 3600.0 / 25.0; - return ccc; -} - -// Cut all power, except for LDO1 (RTC) -void AXP192::PowerOff(void) -{ - Write1Byte(0x32, Read8bit(0x32) | 0b10000000); -} - -void AXP192::SetAdcState(bool state) -{ - // Enable / Disable all ADCs - Write1Byte(0x82, state ? 0xff : 0x00); -} - -void AXP192::PrepareToSleep(void) -{ - // Disable ADCs - SetAdcState(false); - - // Turn LED off - SetLed(false); - - // Turn LCD backlight off - SetDCDC3(false); -} - -void AXP192::RestoreFromLightSleep(void) -{ - // Turn LCD backlight on - SetDCDC3(true); - - // Turn LED on - SetLed(true); - - // Enable ADCs - SetAdcState(true); -} - -uint8_t AXP192::GetWarningLeve(void) -{ - Wire1.beginTransmission(0x34); - Wire1.write(0x47); - Wire1.endTransmission(); - Wire1.requestFrom(0x34, 1); - uint8_t buf = Wire1.read(); - return (buf & 0x01); -} - -// -- sleep -void AXP192::DeepSleep(uint64_t time_in_us) -{ - PrepareToSleep(); - - if (time_in_us > 0) - { - esp_sleep_enable_timer_wakeup(time_in_us); - } - else - { - esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER); - } - (time_in_us == 0) ? esp_deep_sleep_start() : esp_deep_sleep(time_in_us); - - // Never reached - after deep sleep ESP32 restarts -} - -void AXP192::LightSleep(uint64_t time_in_us) -{ - PrepareToSleep(); - - if (time_in_us > 0) - { - esp_sleep_enable_timer_wakeup(time_in_us); - } - else - { - esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER); - } - esp_light_sleep_start(); - - RestoreFromLightSleep(); -} - -uint8_t AXP192::GetWarningLevel(void) -{ - return Read8bit(0x47) & 0x01; -} - -float AXP192::GetBatVoltage() -{ - float ADCLSB = 1.1 / 1000.0; - uint16_t ReData = Read12Bit(0x78); - return ReData * ADCLSB; -} - -float AXP192::GetBatCurrent() -{ - float ADCLSB = 0.5; - uint16_t CurrentIn = Read13Bit(0x7A); - uint16_t CurrentOut = Read13Bit(0x7C); - return (CurrentIn - CurrentOut) * ADCLSB; -} - -float AXP192::GetVinVoltage() -{ - float ADCLSB = 1.7 / 1000.0; - uint16_t ReData = Read12Bit(0x56); - return ReData * ADCLSB; -} - -float AXP192::GetVinCurrent() -{ - float ADCLSB = 0.625; - uint16_t ReData = Read12Bit(0x58); - return ReData * ADCLSB; -} - -float AXP192::GetVBusVoltage() -{ - float ADCLSB = 1.7 / 1000.0; - uint16_t ReData = Read12Bit(0x5A); - return ReData * ADCLSB; -} - -float AXP192::GetVBusCurrent() -{ - float ADCLSB = 0.375; - uint16_t ReData = Read12Bit(0x5C); - return ReData * ADCLSB; -} - -float AXP192::GetTempInAXP192() -{ - float ADCLSB = 0.1; - const float OFFSET_DEG_C = -144.7; - uint16_t ReData = Read12Bit(0x5E); - return OFFSET_DEG_C + ReData * ADCLSB; -} - -float AXP192::GetBatPower() -{ - float VoltageLSB = 1.1; - float CurrentLCS = 0.5; - uint32_t ReData = Read24bit(0x70); - return VoltageLSB * CurrentLCS * ReData / 1000.0; -} - -float AXP192::GetBatChargeCurrent() -{ - float ADCLSB = 0.5; - uint16_t ReData = Read12Bit(0x7A); - return ReData * ADCLSB; -} -float AXP192::GetAPSVoltage() -{ - float ADCLSB = 1.4 / 1000.0; - uint16_t ReData = Read12Bit(0x7E); - return ReData * ADCLSB; -} - -float AXP192::GetBatCoulombInput() -{ - uint32_t ReData = Read32bit(0xB0); - return ReData * 65536 * 0.5 / 3600 / 25.0; -} - -float AXP192::GetBatCoulombOut() -{ - uint32_t ReData = Read32bit(0xB4); - return ReData * 65536 * 0.5 / 3600 / 25.0; -} - -void AXP192::SetCoulombClear() -{ - Write1Byte(0xB8, 0x20); -} - -void AXP192::SetLDO2(bool State) -{ - uint8_t buf = Read8bit(0x12); - if (State == true) - buf = (1 << 2) | buf; - else - buf = ~(1 << 2) & buf; - Write1Byte(0x12, buf); -} - -void AXP192::SetDCDC3(bool State) -{ - uint8_t buf = Read8bit(0x12); - if (State == true) - buf = (1 << 1) | buf; - else - buf = ~(1 << 1) & buf; - Write1Byte(0x12, buf); -} - -uint8_t AXP192::AXPInState() -{ - return Read8bit(0x00); -} -bool AXP192::isACIN() -{ - return ( Read8bit(0x00) & 0x80 ) ? true : false; -} -bool AXP192::isCharging() -{ - return ( Read8bit(0x00) & 0x04 ) ? true : false; -} -bool AXP192::isVBUS() -{ - return ( Read8bit(0x00) & 0x20 ) ? true : false; -} - -void AXP192::SetLDOVoltage(uint8_t number, uint16_t voltage) -{ - voltage = (voltage > 3300) ? 15 : (voltage / 100) - 18; - switch (number) - { - //uint8_t reg, data; - case 2: - Write1Byte(0x28, (Read8bit(0x28) & 0X0F) | (voltage << 4)); - break; - case 3: - Write1Byte(0x28, (Read8bit(0x28) & 0XF0) | voltage); - break; - } -} - -void AXP192::SetDCVoltage(uint8_t number, uint16_t voltage) -{ - uint8_t addr; - if (number > 2) - return; - voltage = (voltage < 700) ? 0 : (voltage - 700) / 25; - switch (number) - { - case 0: - addr = 0x26; - break; - case 1: - addr = 0x25; - break; - case 2: - addr = 0x27; - break; - } - Write1Byte(addr, (Read8bit(addr) & 0X80) | (voltage & 0X7F)); -} - -void AXP192::SetESPVoltage(uint16_t voltage) -{ - if (voltage >= 3000 && voltage <= 3400) - { - SetDCVoltage(0, voltage); - } -} -void AXP192::SetLcdVoltage(uint16_t voltage) -{ - if (voltage >= 2500 && voltage <= 3300) - { - SetDCVoltage(2, voltage); - } -} - -void AXP192::SetLDOEnable(uint8_t number, bool state) -{ - uint8_t mark = 0x01; - if ((number < 2) || (number > 3)) - return; - - mark <<= number; - if (state) - { - Write1Byte(0x12, (Read8bit(0x12) | mark)); - } - else - { - Write1Byte(0x12, (Read8bit(0x12) & (~mark))); - } -} - -void AXP192::SetLCDRSet(bool state) -{ - uint8_t reg_addr = 0x96; - uint8_t gpio_bit = 0x02; - uint8_t data; - data = Read8bit(reg_addr); - - if (state) - { - data |= gpio_bit; - } - else - { - data &= ~gpio_bit; - } - - Write1Byte(reg_addr, data); -} - -void AXP192::SetBusPowerMode(uint8_t state) -{ - uint8_t data; - if (state == 0) - { - data = Read8bit(0x91); - Write1Byte(0x91, (data & 0X0F) | 0XF0); - - data = Read8bit(0x90); - Write1Byte(0x90, (data & 0XF8) | 0X02); //set GPIO0 to LDO OUTPUT , pullup N_VBUSEN to disable supply from BUS_5V - - data = Read8bit(0x91); - - data = Read8bit(0x12); //read reg 0x12 - Write1Byte(0x12, data | 0x40); //set EXTEN to enable 5v boost - } - else - { - data = Read8bit(0x12); //read reg 0x10 - Write1Byte(0x12, data & 0XBF); //set EXTEN to disable 5v boost - - //delay(2000); - - data = Read8bit(0x90); - Write1Byte(0x90, (data & 0xF8) | 0X01); //set GPIO0 to float , using enternal pulldown resistor to enable supply from BUS_5VS - } -} - -void AXP192::SetLed(uint8_t state) -{ - uint8_t reg_addr=0x94; - uint8_t data; - data=Read8bit(reg_addr); - - if(state) - { - data=data&0XFD; - } - else - { - data|=0X02; - } - - Write1Byte(reg_addr,data); -} - -//set led state(GPIO high active,set 1 to enable amplifier) -void AXP192::SetSpkEnable(uint8_t state) -{ - uint8_t reg_addr=0x94; - uint8_t gpio_bit=0x04; - uint8_t data; - data=Read8bit(reg_addr); - - if(state) - { - data|=gpio_bit; - } - else - { - data&=~gpio_bit; - } - - Write1Byte(reg_addr,data); -} - -void AXP192::SetCHGCurrent(uint8_t state) -{ - uint8_t data = Read8bit(0x33); - data &= 0xf0; - data = data | ( state & 0x0f ); - Write1Byte(0x33,data); -} diff --git a/lib/AXP192/AXP192.h b/lib/AXP192/AXP192.h deleted file mode 100644 index 662c37e8..00000000 --- a/lib/AXP192/AXP192.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef __AXP192_H__ -#define __AXP192_H__ - -#include -#include - -#define SLEEP_MSEC(us) (((uint64_t)us) * 1000L) -#define SLEEP_SEC(us) (((uint64_t)us) * 1000000L) -#define SLEEP_MIN(us) (((uint64_t)us) * 60L * 1000000L) -#define SLEEP_HR(us) (((uint64_t)us) * 60L * 60L * 1000000L) - -#define AXP_ADDR 0X34 - -#define PowerOff(x) SetSleep(x) - -class AXP192 { -public: - - enum CHGCurrent{ - kCHG_100mA = 0, - kCHG_190mA, - kCHG_280mA, - kCHG_360mA, - kCHG_450mA, - kCHG_550mA, - kCHG_630mA, - kCHG_700mA, - kCHG_780mA, - kCHG_880mA, - kCHG_960mA, - kCHG_1000mA, - kCHG_1080mA, - kCHG_1160mA, - kCHG_1240mA, - kCHG_1320mA, - }; - - AXP192(); - void begin(void); - void ScreenBreath(uint8_t brightness); - bool GetBatState(); - - void EnableCoulombcounter(void); - void DisableCoulombcounter(void); - void StopCoulombcounter(void); - void ClearCoulombcounter(void); - uint32_t GetCoulombchargeData(void); - uint32_t GetCoulombdischargeData(void); - float GetCoulombData(void); - void PowerOff(void); - void SetAdcState(bool state); - // -- sleep - void PrepareToSleep(void); - void RestoreFromLightSleep(void); - void DeepSleep(uint64_t time_in_us = 0); - void LightSleep(uint64_t time_in_us = 0); - uint8_t GetWarningLeve(void); - -public: - // void SetChargeVoltage( uint8_t ); - // void SetChargeCurrent( uint8_t ); - float GetBatVoltage(); - float GetBatCurrent(); - float GetVinVoltage(); - float GetVinCurrent(); - float GetVBusVoltage(); - float GetVBusCurrent(); - float GetTempInAXP192(); - float GetBatPower(); - float GetBatChargeCurrent(); - float GetAPSVoltage(); - float GetBatCoulombInput(); - float GetBatCoulombOut(); - uint8_t GetWarningLevel(void); - void SetCoulombClear(); - void SetLDO2( bool State ); - void SetDCDC3( bool State ); - - uint8_t AXPInState(); - bool isACIN(); - bool isCharging(); - bool isVBUS(); - - void SetLDOVoltage(uint8_t number , uint16_t voltage); - void SetDCVoltage(uint8_t number , uint16_t voltage); - void SetESPVoltage(uint16_t voltage); - void SetLcdVoltage(uint16_t voltage); - void SetLDOEnable( uint8_t number ,bool state ); - void SetLCDRSet( bool state ); - void SetBusPowerMode( uint8_t state ); - void SetLed(uint8_t state); - void SetSpkEnable(uint8_t state); - void SetCHGCurrent(uint8_t state); - -private: - void Write1Byte( uint8_t Addr , uint8_t Data ); - uint8_t Read8bit( uint8_t Addr ); - uint16_t Read12Bit( uint8_t Addr); - uint16_t Read13Bit( uint8_t Addr); - uint16_t Read16bit( uint8_t Addr ); - uint32_t Read24bit( uint8_t Addr ); - uint32_t Read32bit( uint8_t Addr ); - void ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff ); -}; - -#endif diff --git a/lib/AXP192/LICENSE b/lib/AXP192/LICENSE deleted file mode 100644 index 6580a5df..00000000 --- a/lib/AXP192/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 M5Stack - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/user_setups/esp32/m5stack_core2.ini b/user_setups/esp32/m5stack_core2.ini index bd2dbb04..c14e5d78 100644 --- a/user_setups/esp32/m5stack_core2.ini +++ b/user_setups/esp32/m5stack_core2.ini @@ -36,6 +36,7 @@ lib_deps = ${env.lib_deps} ${esp32.lib_deps} git+https://github.com/aselectroworks/Arduino-FT6336U.git + https://github.com/fvanroie/M5Core2.git#AXP192 lib_ignore = ${env.lib_ignore} @@ -47,7 +48,6 @@ lib_ignore = sstaub/Ticker lv_drv_fsmc_ili9341 lv_drivers - ; AXP192 -- needed for M5Stack core2 ;endregion extra_scripts = From 662a634c603ec9244376439fe0842f29941d6f28 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 22:36:04 +0100 Subject: [PATCH 101/236] Fix for STM32F4 --- src/sys/net/hasp_network.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sys/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp index 2545d5f8..3adfced0 100644 --- a/src/sys/net/hasp_network.cpp +++ b/src/sys/net/hasp_network.cpp @@ -19,9 +19,11 @@ #if HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0 void networkStart(void) { - haspProgressVal(255); // hide +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) configTzTime(MYTZ, "pool.ntp.org", "time.nist.gov", NULL); // literal string +#endif + haspProgressVal(255); // hide haspReconnect(); debugStartSyslog(); // mqttStart(); From cea0439c7599a13fb34ac9c7469c725775608c95 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 22:36:42 +0100 Subject: [PATCH 102/236] Fix incorrect defines --- src/hasp_config.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index b92b9e13..4240ceb6 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -332,7 +332,7 @@ void configWrite() #if defined(STM32F4xx) // Method 2 - LOG_INFO(TAG_CONF, F(F_FILE_SAVING), "EEPROM"); + LOG_INFO(TAG_CONF, F(D_FILE_SAVING), "EEPROM"); char buffer[1024 + 128]; size_t size = serializeJson(doc, buffer, sizeof(buffer)); if(size > 0) { @@ -340,9 +340,9 @@ void configWrite() for(i = 0; i < size; i++) eeprom_buffered_write_byte(i, buffer[i]); eeprom_buffered_write_byte(i, 0); eeprom_buffer_flush(); - LOG_INFO(TAG_CONF, F(F_FILE_SAVED), "EEPROM"); + LOG_INFO(TAG_CONF, F(D_FILE_SAVED), "EEPROM"); } else { - LOG_ERROR(TAG_CONF, F(D_FILE_WRITE_FAILED), "EEPROM"); + LOG_ERROR(TAG_CONF, F(D_FILE_SAVE_FAILED), "EEPROM"); } #endif From 43bfcae843661cef3a113477b9ad8bd25d9cc080 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 22:37:03 +0100 Subject: [PATCH 103/236] Add support for STM32F4 --- src/log/hasp_debug.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index d58726bc..4f6d36b0 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -25,6 +25,8 @@ #elif defined(ARDUINO_ARCH_ESP32) #include #include +#elif defined(STM32F4xx) +#include #endif #include "hasp_conf.h" @@ -336,11 +338,12 @@ static void debugPrintTimestamp(int level, Print* _logOutput) struct tm* timeinfo; int rslt; - rslt = gettimeofday(&tval, NULL); - if(rslt) { - // uint32_t msecs = millis(); - // _logOutput->printf(PSTR("[%9d.%03d]"), msecs / 1000, msecs % 1000); - } else { + /* rslt = gettimeofday(&tval, NULL); + if(rslt) { + // uint32_t msecs = millis(); + // _logOutput->printf(PSTR("[%9d.%03d]"), msecs / 1000, msecs % 1000); + } else */ + { timeinfo = localtime(&tval.tv_sec); } From ea70eb6fedb68b4f18383601aa78113ac45ca582 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 22:38:46 +0100 Subject: [PATCH 104/236] Code formatting --- lib/ArduinoLog/ArduinoLog.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/ArduinoLog/ArduinoLog.h b/lib/ArduinoLog/ArduinoLog.h index 68060baa..921a92db 100644 --- a/lib/ArduinoLog/ArduinoLog.h +++ b/lib/ArduinoLog/ArduinoLog.h @@ -17,12 +17,12 @@ Licensed under the MIT License . #include #include #if defined(ARDUINO) && ARDUINO >= 100 - #include "Arduino.h" +#include "Arduino.h" #else - #include "WProgram.h" +#include "WProgram.h" #endif //#include "StringStream.h" -typedef void (*printfunction)(uint8_t tag, int level, Print *); +typedef void (*printfunction)(uint8_t tag, int level, Print*); //#include //#include @@ -92,7 +92,7 @@ class Logging { */ Logging() #ifndef DISABLE_LOGGING - // : _level(LOG_LEVEL_SILENT), _showLevel(true) + // : _level(LOG_LEVEL_SILENT), _showLevel(true) #endif {} @@ -116,7 +116,7 @@ class Logging { * \return void * */ - void registerOutput(uint8_t slot, Print * logOutput, int level, bool showLevel); + void registerOutput(uint8_t slot, Print* logOutput, int level, bool showLevel); /** * Unregister the printer in a certain slot @@ -311,11 +311,11 @@ class Logging { } private: - void print(Print * logOutput, const char * format, va_list args); + void print(Print* logOutput, const char* format, va_list args); - void print(Print * logOutput, const __FlashStringHelper * format, va_list args); + void print(Print* logOutput, const __FlashStringHelper* format, va_list args); - void printFormat(Print * logOutput, const char format, va_list * args); + void printFormat(Print* logOutput, const char format, va_list* args); template void printLevel(uint8_t tag, int level, T msg, ...) { @@ -343,7 +343,7 @@ class Logging { #ifndef DISABLE_LOGGING int _level[3]; bool _showLevel[3]; - Print * _logOutput[3]; + Print* _logOutput[3]; printfunction _prefix = NULL; printfunction _suffix = NULL; From 241cb0ff4e48062af0eea3424bd71d62fb6050e2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 22:39:01 +0100 Subject: [PATCH 105/236] Bump ArduinoJson version --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index f65889e5..9edb1cce 100644 --- a/platformio.ini +++ b/platformio.ini @@ -67,7 +67,7 @@ build_flags = ; Warning : don't put comments after github links => causes infinite download loop lib_deps = bxparks/AceButton@^1.8.2 ; GPIO button library - bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + bblanchon/ArduinoJson@^6.17.3 ; Json(l) parser bblanchon/StreamUtils@1.6.0 ; for EEPromStream knolleary/PubSubClient@^2.8.0 ; MQTT client git+https://github.com/fvanroie/ConsoleInput.git From 6c6f645692b975bf8d1eedae329cc623cf8d8953 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 23:06:23 +0100 Subject: [PATCH 106/236] Rename file to the environment name --- user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini b/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini index 29613e17..a28ab857 100644 --- a/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini +++ b/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini @@ -14,7 +14,8 @@ ; - STM32F407VET6 has 512 KB flash ; - STM32F407VGT6 has 1 MB flash -[env:DevEBox_STM32F4xx] +;[env:DevEBox_STM32F4xx] +[env:stm32f407-devebox_ili9341] extends = stm32f4 board = black_f407vg board_upload.maximum_size = 1048576 ; Flash size is wrong in variant From 87557f8b05dc6c901c548d9c8f0d3fa0ce69884d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 24 Feb 2021 23:06:51 +0100 Subject: [PATCH 107/236] Fixes for STM32F4 --- include/hasp_conf.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/include/hasp_conf.h b/include/hasp_conf.h index eb034f37..a7c08cbc 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -176,7 +176,7 @@ static WiFiSpiClass WiFi; #include "Ethernet.h" #warning Use W5x00 Ethernet shield #endif -#include "net/hasp_ethernet_stm32.h" +#include "sys/net/hasp_ethernet_stm32.h" #endif #endif @@ -222,15 +222,6 @@ static WiFiSpiClass WiFi; #include "sys/svc/hasp_slave.h" #endif -#ifdef WINDOWS -#ifndef FPSTR -#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) -#endif - -#ifndef __FlashStringHelper -#define __FlashStringHelper char -#endif - #ifndef FPSTR #define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) #endif @@ -239,6 +230,11 @@ static WiFiSpiClass WiFi; #define PGM_P const char* #endif +#if defined(WINDOWS) +#ifndef __FlashStringHelper +#define __FlashStringHelper char +#endif + #ifndef F #define F(x) (x) #endif From 5967d137f6400fbc3d56d4a0d076aeff3a7f01e2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 25 Feb 2021 20:00:31 +0100 Subject: [PATCH 108/236] Add scale attributes --- src/hasp/hasp_attribute.cpp | 38 +++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index b2313255..a9444c5c 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -10,12 +10,7 @@ #include "../lv_components.h" #endif -#include "hasp.h" -#include "hasp_object.h" -#include "hasp_dispatch.h" -#include "hasp_attribute.h" -#include "hasp_utilities.h" -#include "hasp_parser.h" +#include "hasplib.h" LV_FONT_DECLARE(unscii_8_icon); extern lv_font_t* haspFonts[8]; @@ -826,6 +821,37 @@ static void hasp_local_style_attr(lv_obj_t* obj, const char* attr_p, uint16_t at return attribute_pad_inner(obj, part, state, update, attr_p, (lv_style_int_t)var); #endif + /* Scale attributes */ + case ATTR_SCALE_GRAD_COLOR: { + if(update) { + lv_color32_t c; + if(Parser::haspPayloadToColor(payload, c) && part != 64) + lv_obj_set_style_local_scale_grad_color(obj, part, state, + lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); + } else { + hasp_out_color(obj, attr, lv_obj_get_style_scale_grad_color(obj, part)); + } + return; + } + case ATTR_SCALE_END_COLOR: + if(update) { + lv_color32_t c; + if(Parser::haspPayloadToColor(payload, c)) + lv_obj_set_style_local_scale_end_color(obj, part, state, + lv_color_make(c.ch.red, c.ch.green, c.ch.blue)); + } else { + hasp_out_color(obj, attr, lv_obj_get_style_scale_end_color(obj, part)); + } + return; + case ATTR_SCALE_END_LINE_WIDTH: + return attribute_scale_end_line_width(obj, part, state, update, attr_p, (lv_style_int_t)var); + case ATTR_SCALE_END_BORDER_WIDTH: + return attribute_scale_end_border_width(obj, part, state, update, attr_p, (lv_style_int_t)var); + case ATTR_SCALE_BORDER_WIDTH: + return attribute_scale_border_width(obj, part, state, update, attr_p, (lv_style_int_t)var); + case ATTR_SCALE_WIDTH: + return attribute_scale_width(obj, part, state, update, attr_p, (lv_style_int_t)var); + /* Text attributes */ case ATTR_TEXT_LETTER_SPACE: return attribute_text_letter_space(obj, part, state, update, attr_p, (lv_style_int_t)var); From a115cb2b9bd9238b4a136d05b58b2c52c2446a3e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 25 Feb 2021 20:01:11 +0100 Subject: [PATCH 109/236] Add hasplib --- src/hasp/hasp.cpp | 11 +++-------- src/hasp/hasp_dispatch.cpp | 21 +++++++-------------- src/hasp/hasp_object.cpp | 7 +------ src/hasp/hasp_parser.cpp | 4 +--- src/hasp/hasp_utilities.cpp | 1 - src/hasplib.h | 10 ++++++++++ 6 files changed, 22 insertions(+), 32 deletions(-) create mode 100644 src/hasplib.h diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 98554c24..0cc018be 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -6,9 +6,6 @@ #endif #include "ArduinoJson.h" -#include "hasp_conf.h" - -#include "dev/device.h" #if HASP_USE_EEPROM > 0 #include "StreamUtils.h" // For EEPromStream @@ -28,13 +25,11 @@ //#include "hasp_filesystem.h" included in hasp_conf.h #endif -#include "hasp_object.h" -#include "hasp_dispatch.h" - -#include "hasp_attribute.h" -#include "hasp.h" +#include "hasplib.h" #include "lv_theme_hasp.h" +#include "dev/device.h" + #if HASP_USE_EEPROM > 0 #include "EEPROM.h" #endif diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index f8752c82..55eb8770 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -4,14 +4,7 @@ #include //#include "ArduinoLog.h" -#include "hasp_conf.h" - -#include "hasp_dispatch.h" -#include "hasp_object.h" -#include "hasp.h" -#include "hasp_utilities.h" -#include "hasp_parser.h" -#include "hasp_attribute.h" +#include "hasplib.h" #include "dev/device.h" @@ -652,13 +645,13 @@ void dispatch_parse_json(const char*, const char* payload) uint8_t savedPage = haspGetPage(); hasp_new_object(json.as(), savedPage); -#ifdef ARDUINO - } else if(json.is()) { // handle json as a single command - dispatch_text_line(json.as().c_str()); -#else + // #ifdef ARDUINO + // } else if(json.is()) { // handle json as a single command + // dispatch_text_line(json.as().c_str()); + // #else } else if(json.is()) { // handle json as a single command dispatch_text_line(json.as().c_str()); -#endif + // #endif } else if(json.is()) { // handle json as a single command dispatch_text_line(json.as()); @@ -937,7 +930,7 @@ void dispatch_output_statusupdate(const char*, const char*) #endif snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), - haspDevice.get_display_driver(), (TFT_WIDTH), (TFT_HEIGHT)); + Utilities::tft_driver_name().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); strcat(data, buffer); } mqtt_send_state(F("statusupdate"), data); diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 6fa91a78..46610f2e 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -22,12 +22,7 @@ #include "../lv_components.h" #endif -#include "hasp.h" -#include "hasp_object.h" -#include "hasp_dispatch.h" -#include "hasp_attribute.h" -#include "hasp_utilities.h" -#include "hasp_parser.h" +#include "hasplib.h" const char** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map // static unsigned long last_change_event = 0; diff --git a/src/hasp/hasp_parser.cpp b/src/hasp/hasp_parser.cpp index 6742b1f7..10336a42 100644 --- a/src/hasp/hasp_parser.cpp +++ b/src/hasp/hasp_parser.cpp @@ -8,10 +8,8 @@ #endif #include "lvgl.h" -#include "hasp_conf.h" -#include "hasp_parser.h" -#include "hasp_utilities.h" +#include "hasplib.h" bool Parser::haspPayloadToColor(const char* payload, lv_color32_t& color) { diff --git a/src/hasp/hasp_utilities.cpp b/src/hasp/hasp_utilities.cpp index fd39dc09..5ae92422 100644 --- a/src/hasp/hasp_utilities.cpp +++ b/src/hasp/hasp_utilities.cpp @@ -6,7 +6,6 @@ #endif #include "hasp_conf.h" - #include "hasp_utilities.h" /* 16-bit hashing function http://www.cse.yorku.ca/~oz/hash.html */ diff --git a/src/hasplib.h b/src/hasplib.h new file mode 100644 index 00000000..8f1596e9 --- /dev/null +++ b/src/hasplib.h @@ -0,0 +1,10 @@ +#include "hasp_conf.h" + +#include "hasp/hasp.h" +#include "hasp/hasp_attribute.h" +#include "hasp/hasp_dispatch.h" +#include "hasp/hasp_object.h" +#include "hasp/hasp_parser.h" +#include "hasp/hasp_utilities.h" + +#include "hasp/lv_theme_hasp.h" \ No newline at end of file From 7c9b420c8cf415e8d0a09ea02b72147ebe5938f4 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 25 Feb 2021 20:01:28 +0100 Subject: [PATCH 110/236] Fix wrong #endif --- src/hasp/lv_theme_hasp.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/hasp/lv_theme_hasp.h b/src/hasp/lv_theme_hasp.h index 49425093..f6fe647c 100644 --- a/src/hasp/lv_theme_hasp.h +++ b/src/hasp/lv_theme_hasp.h @@ -22,10 +22,10 @@ extern "C" { * DEFINES *********************/ typedef enum { - LV_THEME_HASP_FLAG_DARK = 0x01, - LV_THEME_HASP_FLAG_LIGHT = 0x02, - LV_THEME_HASP_FLAG_NO_TRANSITION = 0x10, - LV_THEME_HASP_FLAG_NO_FOCUS = 0x20, + LV_THEME_HASP_FLAG_DARK = 0x01, + LV_THEME_HASP_FLAG_LIGHT = 0x02, + LV_THEME_HASP_FLAG_NO_TRANSITION = 0x10, + LV_THEME_HASP_FLAG_NO_FOCUS = 0x20, } lv_theme_hasp_flag_t; /********************** @@ -47,17 +47,15 @@ typedef enum { * @param font_title pointer to a extra large font * @return a pointer to reference this theme later */ -lv_theme_t * lv_theme_hasp_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, - const lv_font_t * font_small, const lv_font_t * font_normal, - const lv_font_t * font_subtitle, const lv_font_t * font_title); +lv_theme_t* lv_theme_hasp_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, + const lv_font_t* font_small, const lv_font_t* font_normal, + const lv_font_t* font_subtitle, const lv_font_t* font_title); /********************** * MACROS **********************/ -#endif - #ifdef __cplusplus } /* extern "C" */ #endif -//#endif /*LV_THEME_HASP_H*/ +#endif /*LV_THEME_HASP_H*/ From 0ca341a7aed09584b41770df4b3111fe019b0506 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 25 Feb 2021 20:01:37 +0100 Subject: [PATCH 111/236] Fix filename --- src/drv/{tft_driver_tftesp.cpp => tft_driver_tftespi.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/drv/{tft_driver_tftesp.cpp => tft_driver_tftespi.cpp} (100%) diff --git a/src/drv/tft_driver_tftesp.cpp b/src/drv/tft_driver_tftespi.cpp similarity index 100% rename from src/drv/tft_driver_tftesp.cpp rename to src/drv/tft_driver_tftespi.cpp From 6d6e1b99ef658c988ee23d51942b8f2fee8bc9ab Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 26 Feb 2021 23:24:46 +0100 Subject: [PATCH 112/236] Make commands array autosized --- src/hasp/hasp_dispatch.cpp | 88 +++++++++++++++++++------------------- src/hasp/hasp_dispatch.h | 2 +- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 55eb8770..16491f63 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -40,10 +40,48 @@ extern uint8_t hasp_sleep_state; dispatch_conf_t dispatch_setings = {.teleperiod = 10}; - uint32_t dispatchLastMillis; -uint8_t nCommands = 0; -haspCommand_t commands[17]; + +/* Declare all Command Handlers */ +void dispatch_parse_json(const char*, const char* payload); +void dispatch_parse_jsonl(const char*, const char* payload); +void dispatch_page(const char*, const char* payload); +void dispatch_wakeup(const char*, const char* payload); +void dispatch_output_statusupdate(const char*, const char* payload); +void dispatch_clear_page(const char*, const char* payload); +void dispatch_dim(const char*, const char* payload); +void dispatch_backlight(const char*, const char* payload); +void dispatch_moodlight(const char*, const char* payload); +void dispatch_calibrate(const char*, const char* payload); +void dispatch_web_update(const char*, const char* payload); +void dispatch_reboot(const char*, const char* payload); +void dispatch_screenshot(const char*, const char* payload); +void dispatch_factory_reset(const char*, const char* payload); + +/* Map Commands to Command Handlers */ +haspCommand_t commands[] = { + + {PSTR("json"), dispatch_parse_json}, + {PSTR("page"), dispatch_page}, + {PSTR("wakeup"), dispatch_wakeup}, + {PSTR("statusupdate"), dispatch_output_statusupdate}, + {PSTR("clearpage"), dispatch_clear_page}, + {PSTR("jsonl"), dispatch_parse_jsonl}, + {PSTR("dim"), dispatch_dim}, + {PSTR("brightness"), dispatch_dim}, + {PSTR("light"), dispatch_backlight}, + {PSTR("moodlight"), dispatch_moodlight}, + {PSTR("calibrate"), dispatch_calibrate}, + {PSTR("update"), dispatch_web_update}, + {PSTR("reboot"), dispatch_reboot}, + {PSTR("restart"), dispatch_reboot}, + {PSTR("screenshot"), dispatch_screenshot}, +#if HASP_USE_CONFIG > 0 + {PSTR("setupap"), oobeFakeSetup}, +#endif + {PSTR("factoryreset"), dispatch_factory_reset} + +}; struct moodlight_t { @@ -59,7 +97,6 @@ static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const void dispatch_screenshot(const char*, const char* filename) { #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - if(strlen(filename) == 0) { // no filename given char tempfile[32]; memcpy_P(tempfile, PSTR("/screenshot.bmp"), sizeof(tempfile)); @@ -200,7 +237,7 @@ void dispatch_command(const char* topic, const char* payload) /* ================================= Standard payload commands ======================================= */ // check and execute commands from commands array - for(int i = 0; i < nCommands; i++) { + for(int i = 0; i < sizeof(commands) / sizeof(haspCommand_t); i++) { if(!strcasecmp_P(topic, commands[i].p_cmdstr)) { // LOG_DEBUG(TAG_MSGR, F("Command %d found in array !!!"), i); commands[i].func(topic, payload); /* execute command */ @@ -901,7 +938,6 @@ void dispatch_current_state() void dispatch_output_statusupdate(const char*, const char*) { #if HASP_USE_MQTT > 0 - char data[3 * 128]; { char buffer[128]; @@ -970,46 +1006,8 @@ void dispatch_factory_reset(const char*, const char*) /******************************************* Commands builder *******************************************/ -static void dispatch_add_command(const char* p_cmdstr, void (*func)(const char*, const char*)) -{ - if(nCommands >= sizeof(commands) / sizeof(haspCommand_t)) { - LOG_FATAL(TAG_MSGR, F("CMD_OVERFLOW %d"), nCommands); - while(1) { - } - } else { - commands[nCommands].p_cmdstr = p_cmdstr; - commands[nCommands].func = func; - nCommands++; - } -} - void dispatchSetup() -{ - // In order of importance : commands are NOT case-sensitive - // The command.func() call will receive the full topic and payload parameters! - - /* WARNING: remember to expand the commands array when adding new commands */ - dispatch_add_command(PSTR("json"), dispatch_parse_json); - dispatch_add_command(PSTR("page"), dispatch_page); - dispatch_add_command(PSTR("wakeup"), dispatch_wakeup); - dispatch_add_command(PSTR("statusupdate"), dispatch_output_statusupdate); - dispatch_add_command(PSTR("clearpage"), dispatch_clear_page); - dispatch_add_command(PSTR("jsonl"), dispatch_parse_jsonl); - dispatch_add_command(PSTR("dim"), dispatch_dim); - dispatch_add_command(PSTR("brightness"), dispatch_dim); - dispatch_add_command(PSTR("light"), dispatch_backlight); - dispatch_add_command(PSTR("moodlight"), dispatch_moodlight); - dispatch_add_command(PSTR("calibrate"), dispatch_calibrate); - dispatch_add_command(PSTR("update"), dispatch_web_update); - dispatch_add_command(PSTR("reboot"), dispatch_reboot); - dispatch_add_command(PSTR("restart"), dispatch_reboot); - dispatch_add_command(PSTR("screenshot"), dispatch_screenshot); - dispatch_add_command(PSTR("factoryreset"), dispatch_factory_reset); -#if HASP_USE_CONFIG > 0 - dispatch_add_command(PSTR("setupap"), oobeFakeSetup); -#endif - /* WARNING: remember to expand the commands array when adding new commands */ -} +{} void dispatchLoop() { diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 39f8cacc..1dba3b41 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -79,8 +79,8 @@ void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char /* ===== Structs and Constants ===== */ struct haspCommand_t { - void (*func)(const char*, const char*); const char* p_cmdstr; + void (*func)(const char*, const char*); }; #endif \ No newline at end of file From da00c41a21b24b360889ed76eb4b49d49e989304 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 26 Feb 2021 23:52:54 +0100 Subject: [PATCH 113/236] Move dispatchSetup to haspSetup --- src/hasp/hasp.cpp | 1 + src/hasp/hasp_dispatch.cpp | 88 +++++++++++++++++++------------------- src/main_arduino.cpp | 3 +- src/main_windows.cpp | 3 +- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 0cc018be..dbae6d46 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -319,6 +319,7 @@ static void custom_font_apply_cb(lv_theme_t* th, lv_obj_t* obj, lv_theme_style_t */ void haspSetup(void) { + dispatchSetup(); haspDevice.set_backlight_level(haspStartDim); /******* File System Test ********************************************************************/ diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 16491f63..55eb8770 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -40,48 +40,10 @@ extern uint8_t hasp_sleep_state; dispatch_conf_t dispatch_setings = {.teleperiod = 10}; + uint32_t dispatchLastMillis; - -/* Declare all Command Handlers */ -void dispatch_parse_json(const char*, const char* payload); -void dispatch_parse_jsonl(const char*, const char* payload); -void dispatch_page(const char*, const char* payload); -void dispatch_wakeup(const char*, const char* payload); -void dispatch_output_statusupdate(const char*, const char* payload); -void dispatch_clear_page(const char*, const char* payload); -void dispatch_dim(const char*, const char* payload); -void dispatch_backlight(const char*, const char* payload); -void dispatch_moodlight(const char*, const char* payload); -void dispatch_calibrate(const char*, const char* payload); -void dispatch_web_update(const char*, const char* payload); -void dispatch_reboot(const char*, const char* payload); -void dispatch_screenshot(const char*, const char* payload); -void dispatch_factory_reset(const char*, const char* payload); - -/* Map Commands to Command Handlers */ -haspCommand_t commands[] = { - - {PSTR("json"), dispatch_parse_json}, - {PSTR("page"), dispatch_page}, - {PSTR("wakeup"), dispatch_wakeup}, - {PSTR("statusupdate"), dispatch_output_statusupdate}, - {PSTR("clearpage"), dispatch_clear_page}, - {PSTR("jsonl"), dispatch_parse_jsonl}, - {PSTR("dim"), dispatch_dim}, - {PSTR("brightness"), dispatch_dim}, - {PSTR("light"), dispatch_backlight}, - {PSTR("moodlight"), dispatch_moodlight}, - {PSTR("calibrate"), dispatch_calibrate}, - {PSTR("update"), dispatch_web_update}, - {PSTR("reboot"), dispatch_reboot}, - {PSTR("restart"), dispatch_reboot}, - {PSTR("screenshot"), dispatch_screenshot}, -#if HASP_USE_CONFIG > 0 - {PSTR("setupap"), oobeFakeSetup}, -#endif - {PSTR("factoryreset"), dispatch_factory_reset} - -}; +uint8_t nCommands = 0; +haspCommand_t commands[17]; struct moodlight_t { @@ -97,6 +59,7 @@ static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const void dispatch_screenshot(const char*, const char* filename) { #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + if(strlen(filename) == 0) { // no filename given char tempfile[32]; memcpy_P(tempfile, PSTR("/screenshot.bmp"), sizeof(tempfile)); @@ -237,7 +200,7 @@ void dispatch_command(const char* topic, const char* payload) /* ================================= Standard payload commands ======================================= */ // check and execute commands from commands array - for(int i = 0; i < sizeof(commands) / sizeof(haspCommand_t); i++) { + for(int i = 0; i < nCommands; i++) { if(!strcasecmp_P(topic, commands[i].p_cmdstr)) { // LOG_DEBUG(TAG_MSGR, F("Command %d found in array !!!"), i); commands[i].func(topic, payload); /* execute command */ @@ -938,6 +901,7 @@ void dispatch_current_state() void dispatch_output_statusupdate(const char*, const char*) { #if HASP_USE_MQTT > 0 + char data[3 * 128]; { char buffer[128]; @@ -1006,8 +970,46 @@ void dispatch_factory_reset(const char*, const char*) /******************************************* Commands builder *******************************************/ +static void dispatch_add_command(const char* p_cmdstr, void (*func)(const char*, const char*)) +{ + if(nCommands >= sizeof(commands) / sizeof(haspCommand_t)) { + LOG_FATAL(TAG_MSGR, F("CMD_OVERFLOW %d"), nCommands); + while(1) { + } + } else { + commands[nCommands].p_cmdstr = p_cmdstr; + commands[nCommands].func = func; + nCommands++; + } +} + void dispatchSetup() -{} +{ + // In order of importance : commands are NOT case-sensitive + // The command.func() call will receive the full topic and payload parameters! + + /* WARNING: remember to expand the commands array when adding new commands */ + dispatch_add_command(PSTR("json"), dispatch_parse_json); + dispatch_add_command(PSTR("page"), dispatch_page); + dispatch_add_command(PSTR("wakeup"), dispatch_wakeup); + dispatch_add_command(PSTR("statusupdate"), dispatch_output_statusupdate); + dispatch_add_command(PSTR("clearpage"), dispatch_clear_page); + dispatch_add_command(PSTR("jsonl"), dispatch_parse_jsonl); + dispatch_add_command(PSTR("dim"), dispatch_dim); + dispatch_add_command(PSTR("brightness"), dispatch_dim); + dispatch_add_command(PSTR("light"), dispatch_backlight); + dispatch_add_command(PSTR("moodlight"), dispatch_moodlight); + dispatch_add_command(PSTR("calibrate"), dispatch_calibrate); + dispatch_add_command(PSTR("update"), dispatch_web_update); + dispatch_add_command(PSTR("reboot"), dispatch_reboot); + dispatch_add_command(PSTR("restart"), dispatch_reboot); + dispatch_add_command(PSTR("screenshot"), dispatch_screenshot); + dispatch_add_command(PSTR("factoryreset"), dispatch_factory_reset); +#if HASP_USE_CONFIG > 0 + dispatch_add_command(PSTR("setupap"), oobeFakeSetup); +#endif + /* WARNING: remember to expand the commands array when adding new commands */ +} void dispatchLoop() { diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 3b014ace..8dfec4c7 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -57,7 +57,6 @@ void setup() configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart() #endif - dispatchSetup(); guiSetup(); debugSetup(); // Init the console @@ -100,7 +99,7 @@ void setup() telnetSetup(); #endif -#if HASP_USE_TASMOTA_CLINET > 0 +#if HASP_USE_TASMOTA_CLIENT > 0 slaveSetup(); #endif diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 8ccf9171..2efb6f21 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -103,9 +103,8 @@ void setup() lv_log_register_print_cb(debugLvglLogEvent); lv_init(); - haspDevice.init(); + haspDevice.init(); // hardware setup // hal_setup(); - dispatchSetup(); guiSetup(); // debugSetup(); // Init the console From 80052140f347c681eee2ce2bd525be0c97df0b2d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 27 Feb 2021 01:17:51 +0100 Subject: [PATCH 114/236] Add lvfs config --- include/lv_conf_v7.h | 14 +- lib/lv_fs_if/lv_fs_pc.c | 219 ++++++++++++++------------ src/hasp/hasp_lvfs.cpp | 36 +++++ src/hasp/hasp_lvfs.h | 9 ++ src/hasp_gui.cpp | 9 +- src/hasplib.h | 1 + user_setups/win32/emulator_64bits.ini | 1 - 7 files changed, 176 insertions(+), 113 deletions(-) create mode 100644 src/hasp/hasp_lvfs.cpp create mode 100644 src/hasp/hasp_lvfs.h diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index 0e7024f5..68955047 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -5,9 +5,9 @@ #if 1 /*Set it to "1" to enable content*/ - #ifndef LV_CONF_H - #define LV_CONF_H - /* clang-format off */ +#ifndef LV_CONF_H +#define LV_CONF_H +/* clang-format off */ #include @@ -183,14 +183,14 @@ typedef void* lv_group_user_data_t; typedef void* lv_fs_drv_user_data_t; /*File system interface*/ -#define LV_USE_FS_IF 0 +#define LV_USE_FS_IF 1 #if LV_USE_FS_IF # define LV_FS_IF_FATFS '\0' -#if defined(ARDUINO_ARCH_ESP32) // || defined(ARDUINO_ARCH_ESP8266) -# define LV_FS_IF_PC 'S' +#if defined(STM32F4xx) // || defined(ARDUINO_ARCH_ESP8266) +# define LV_FS_IF_PC '\0' # define LV_FS_IF_SPIFFS '\0' // internal esp Flash #else -# define LV_FS_IF_PC '\0' +# define LV_FS_IF_PC 'S' # define LV_FS_IF_SPIFFS '\0' // no internal esp Flash #endif #endif /*LV_USE_FS_IF*/ diff --git a/lib/lv_fs_if/lv_fs_pc.c b/lib/lv_fs_if/lv_fs_pc.c index d76ab87e..e3dd160d 100644 --- a/lib/lv_fs_if/lv_fs_pc.c +++ b/lib/lv_fs_if/lv_fs_pc.c @@ -8,58 +8,62 @@ *********************/ #include "lv_fs_if.h" #if LV_USE_FS_IF - #if LV_FS_IF_PC != '\0' +#if LV_FS_IF_PC != '\0' - #include - #include - #include - #include - #ifdef WIN32 - #include - #endif +#include +#include +#include +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(STM32F4xx) +#include +#endif +#ifdef WIN32 +#include +#endif - /********************* - * DEFINES - *********************/ - #ifndef LV_FS_PC_PATH - #ifndef WIN32 - #define LV_FS_PC_PATH "/fs" /*Projet root*/ - #else - #define LV_FS_PC_PATH ".\\" /*Projet root*/ - #endif - #endif /*LV_FS_PATH*/ +/********************* + * DEFINES + *********************/ +#ifndef LV_FS_PC_PATH +#ifndef WIN32 +#define LV_FS_PC_PATH "/fs" /*Projet root*/ +#else +#define LV_FS_PC_PATH ".\\" /*Projet root*/ +#endif +#endif /*LV_FS_PATH*/ /********************** * TYPEDEFS **********************/ /* Create a type to store the required data about your file. */ -typedef FILE * file_t; +typedef FILE* file_t; - /*Similarly to `file_t` create a type for directory reading too */ - #ifndef WIN32 -typedef DIR * dir_t; - #else +/*Similarly to `file_t` create a type for directory reading too */ +#if defined(WIN32) typedef HANDLE dir_t; - #endif +#elif defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx) +typedef FILE* dir_t; +#else +typedef DIR* dir_t; +#endif /********************** * STATIC PROTOTYPES **********************/ -static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode); -static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p); -static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br); -static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw); -static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos); -static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p); -static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p); -static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path); -static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p); -static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * newname); -static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p); -static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * path); -static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn); -static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p); +static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode); +static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p); +static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br); +static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw); +static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos); +static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p); +static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p); +static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path); +static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p); +static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname); +static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p); +static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path); +static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn); +static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p); /********************** * STATIC VARIABLES @@ -121,12 +125,12 @@ void lv_fs_if_pc_init(void) * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) +static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode) { (void)drv; /*Unused*/ errno = 0; - const char * flags = ""; + const char* flags = ""; if(mode == LV_FS_MODE_WR) flags = "wb"; @@ -135,16 +139,16 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = "rb+"; - /*Make the path relative to the current directory (the projects root folder)*/ + /*Make the path relative to the current directory (the projects root folder)*/ - #ifndef WIN32 +#ifndef WIN32 char buf[256]; sprintf(buf, LV_FS_PC_PATH "/%s", path); printf("%s\n", buf); - #else +#else char buf[256]; sprintf(buf, LV_FS_PC_PATH "\\%s", path); - #endif +#endif file_t f = fopen(buf, flags); if(f == NULL) { @@ -156,8 +160,8 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, /* 'file_p' is pointer to a file descriptor and * we need to store our file descriptor here*/ - file_t * fp = file_p; /*Just avoid the confusing casings*/ - *fp = f; + file_t* fp = file_p; /*Just avoid the confusing casings*/ + *fp = f; return LV_FS_RES_OK; } @@ -169,10 +173,10 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p) +static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p) { - (void)drv; /*Unused*/ - file_t * fp = file_p; /*Just avoid the confusing casings*/ + (void)drv; /*Unused*/ + file_t* fp = file_p; /*Just avoid the confusing casings*/ fclose(*fp); return LV_FS_RES_OK; } @@ -187,11 +191,11 @@ static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br) +static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br) { - (void)drv; /*Unused*/ - file_t * fp = file_p; /*Just avoid the confusing casings*/ - *br = fread(buf, 1, btr, *fp); + (void)drv; /*Unused*/ + file_t* fp = file_p; /*Just avoid the confusing casings*/ + *br = fread(buf, 1, btr, *fp); return LV_FS_RES_OK; } @@ -204,11 +208,11 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_ * @param br the number of real written bytes (Bytes Written). NULL if unused. * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw) +static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw) { - (void)drv; /*Unused*/ - file_t * fp = file_p; /*Just avoid the confusing casings*/ - *bw = fwrite(buf, 1, btw, *fp); + (void)drv; /*Unused*/ + file_t* fp = file_p; /*Just avoid the confusing casings*/ + *bw = fwrite(buf, 1, btw, *fp); return LV_FS_RES_OK; } @@ -220,10 +224,10 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos) +static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos) { - (void)drv; /*Unused*/ - file_t * fp = file_p; /*Just avoid the confusing casings*/ + (void)drv; /*Unused*/ + file_t* fp = file_p; /*Just avoid the confusing casings*/ fseek(*fp, pos, SEEK_SET); return LV_FS_RES_OK; } @@ -235,10 +239,10 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos) * @param size pointer to a variable to store the size * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p) +static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p) { - (void)drv; /*Unused*/ - file_t * fp = file_p; /*Just avoid the confusing casings*/ + (void)drv; /*Unused*/ + file_t* fp = file_p; /*Just avoid the confusing casings*/ uint32_t cur = ftell(*fp); @@ -258,11 +262,11 @@ static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) +static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p) { - (void)drv; /*Unused*/ - file_t * fp = file_p; /*Just avoid the confusing casings*/ - *pos_p = ftell(*fp); + (void)drv; /*Unused*/ + file_t* fp = file_p; /*Just avoid the confusing casings*/ + *pos_p = ftell(*fp); return LV_FS_RES_OK; } @@ -272,7 +276,7 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) * @param path path of the file to delete * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path) +static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path) { (void)drv; /*Unused*/ lv_fs_res_t res = LV_FS_RES_NOT_IMP; @@ -289,10 +293,10 @@ static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p) +static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p) { - (void)drv; /*Unused*/ - file_t * fp = file_p; /*Just avoid the confusing casings*/ + (void)drv; /*Unused*/ + file_t* fp = file_p; /*Just avoid the confusing casings*/ fflush(*fp); /*If not syncronized fclose can write the truncated part*/ uint32_t p = ftell(*fp); @@ -307,7 +311,7 @@ static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p) * @param newname path with the new name * @return LV_FS_RES_OK or any error from 'fs_res_t' */ -static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * newname) +static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname) { (void)drv; /*Unused*/ static char new[512]; @@ -316,12 +320,14 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char sprintf(old, LV_FS_PC_PATH "/%s", oldname); sprintf(new, LV_FS_PC_PATH "/%s", newname); - int r = rename(old, new); + return LV_FS_RES_UNKNOWN; - if(r == 0) - return LV_FS_RES_OK; - else - return LV_FS_RES_UNKNOWN; + // int r = rename(old, new); + + // if(r == 0) + // return LV_FS_RES_OK; + // else + // return LV_FS_RES_UNKNOWN; } /** @@ -332,7 +338,7 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * @param free_p pointer to store the free size [kB] * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p) +static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p) { (void)drv; /*Unused*/ lv_fs_res_t res = LV_FS_RES_NOT_IMP; @@ -342,9 +348,9 @@ static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fre return res; } - #ifdef WIN32 +#ifdef WIN32 static char next_fn[256]; - #endif +#endif /** * Initialize a 'fs_read_dir_t' variable for directory reading @@ -353,11 +359,14 @@ static char next_fn[256]; * @param path path to a directory * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * path) +static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path) { (void)drv; /*Unused*/ dir_t d; - #ifndef WIN32 +#if defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx) + return LV_FS_RES_UNKNOWN; + +#elif !defined(WIN32) /*Make the path relative to the current directory (the projects root folder)*/ char buf[256]; sprintf(buf, LV_FS_PC_PATH "/%s", path); @@ -366,10 +375,10 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat } else { /* 'dir_p' is pointer to a file descriptor and * we need to store our file descriptor here*/ - dir_t * dp = dir_p; /*Just avoid the confusing casings*/ - *dp = d; + dir_t* dp = dir_p; /*Just avoid the confusing casings*/ + *dp = d; } - #else +#else d = INVALID_HANDLE_VALUE; WIN32_FIND_DATA fdata; @@ -393,10 +402,10 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat } } while(FindNextFileA(d, &fdata)); - dir_t * dp = dir_p; /*Just avoid the confusing casings*/ - *dp = d; + dir_t* dp = dir_p; /*Just avoid the confusing casings*/ + *dp = d; - #endif +#endif return LV_FS_RES_OK; } @@ -409,17 +418,18 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat * @param fn pointer to a buffer to store the filename * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn) +static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn) { - (void)drv; /*Unused*/ - dir_t * dp = dir_p; /*Just avoid the confusing casings*/ + (void)drv; /*Unused*/ + dir_t* dp = dir_p; /*Just avoid the confusing casings*/ - #ifndef WIN32 - struct dirent * entry; +#ifdef ARDUINO_ARCH_ESP32 + struct dirent* entry; do { entry = readdir(*dp); if(entry) { + if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name); else @@ -428,7 +438,9 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn) strcpy(fn, ""); } } while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0); - #else +#endif + +#ifdef WIN32 strcpy(fn, next_fn); strcpy(next_fn, ""); @@ -449,7 +461,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn) } } while(FindNextFile(*dp, &fdata)); - #endif +#endif return LV_FS_RES_OK; } @@ -459,18 +471,21 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn) * @param dir_p pointer to an initialized 'fs_read_dir_t' variable * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p) +static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p) { (void)drv; /*Unused*/ - dir_t * dp = dir_p; - #ifndef WIN32 + dir_t* dp = dir_p; +#if defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx) + return LV_FS_RES_UNKNOWN; + +#elif !defined(WIN32) closedir(*dp); - #else +#else FindClose(*dp); *dp = INVALID_HANDLE_VALUE; - #endif +#endif return LV_FS_RES_OK; } - #endif /*LV_USE_FS_IF*/ -#endif /*LV_FS_IF_FATFS*/ +#endif /*LV_USE_FS_IF*/ +#endif /*LV_FS_IF_FATFS*/ diff --git a/src/hasp/hasp_lvfs.cpp b/src/hasp/hasp_lvfs.cpp new file mode 100644 index 00000000..996ba567 --- /dev/null +++ b/src/hasp/hasp_lvfs.cpp @@ -0,0 +1,36 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#include "lv_fs_if.h" + +#include "hasp_conf.h" // include first +#include "hasp_debug.h" + +void filesystem_list_path(const char* path) +{ + lv_fs_dir_t dir; + lv_fs_res_t res; + res = lv_fs_dir_open(&dir, path); + if(res != LV_FS_RES_OK) { + LOG_ERROR(TAG_LVFS, "Error opening directory %s", path); + } else { + char fn[256]; + while(1) { + res = lv_fs_dir_read(&dir, fn); + if(res != LV_FS_RES_OK) { + LOG_ERROR(TAG_LVFS, "Directory %s can not be read", path); + break; + } + + /*fn is empty, if not more files to read*/ + if(strlen(fn) == 0) { + LOG_WARNING(TAG_LVFS, "Directory %s listing complete", path); + break; + } + + LOG_VERBOSE(TAG_LVFS, D_BULLET "%s", fn); + } + } + + lv_fs_dir_close(&dir); +} diff --git a/src/hasp/hasp_lvfs.h b/src/hasp/hasp_lvfs.h new file mode 100644 index 00000000..2dde864d --- /dev/null +++ b/src/hasp/hasp_lvfs.h @@ -0,0 +1,9 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_LVFS_H +#define HASP_LVFS_H + +void filesystem_list_path(const char* path); + +#endif \ No newline at end of file diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index de4e2ece..0a9ef0b0 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -23,8 +23,7 @@ #include "hasp_gui.h" #include "hasp_oobe.h" -#include "hasp/hasp_dispatch.h" -#include "hasp/hasp.h" +#include "hasplib.h" #ifdef WINDOWS #include "display/monitor.h" @@ -194,8 +193,12 @@ void guiSetup(void) /* Initialize Filesystems */ #if LV_USE_FS_IF != 0 - _lv_fs_init(); // lvgl File System + // _lv_fs_init(); // lvgl File System -- not neaded, it done in lv_init() when LV_USE_FILESYSTEM is set + LOG_VERBOSE(TAG_LVGL, F("Filesystem : Enabled")); lv_fs_if_init(); // auxilary file system drivers + filesystem_list_path("S:/"); +#else + LOG_VERBOSE(TAG_LVGL, F("Filesystem : Disabled")); #endif /* Initialize PNG decoder */ diff --git a/src/hasplib.h b/src/hasplib.h index 8f1596e9..158a6e56 100644 --- a/src/hasplib.h +++ b/src/hasplib.h @@ -6,5 +6,6 @@ #include "hasp/hasp_object.h" #include "hasp/hasp_parser.h" #include "hasp/hasp_utilities.h" +#include "hasp/hasp_lvfs.h" #include "hasp/lv_theme_hasp.h" \ No newline at end of file diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/emulator_64bits.ini index 67cf5d38..1e359947 100644 --- a/user_setups/win32/emulator_64bits.ini +++ b/user_setups/win32/emulator_64bits.ini @@ -80,7 +80,6 @@ lib_ignore = paho AXP192 ArduinoLog - lv_fs_if src_filter = +<*> From 51c97f16d94d297c86f1a2e2f90c4435251d8746 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 27 Feb 2021 13:51:49 +0100 Subject: [PATCH 115/236] Add mqtt username and password to tests --- test/config.yaml | 7 ++++--- test/test_colors.tavern.yaml | 3 +++ test/test_label.tavern.yaml | 3 +++ test/test_mqtt.tavern.yaml | 8 +++++--- test/test_obj.tavern.yaml | 31 ++++++++++++++++++++++++++++--- test/test_value_str.tavern.yaml | 14 ++++++++------ 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/test/config.yaml b/test/config.yaml index 123df340..8e75a5fc 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -1,10 +1,11 @@ # config.yaml --- - name: Common test information description: Connection information for MQTT Client variables: - host: 10.4.0.5 + host: homeassistant.local + username: hasp + password: hasp port: 1883 - plate: plate35 \ No newline at end of file + plate: plate35 diff --git a/test/test_colors.tavern.yaml b/test/test_colors.tavern.yaml index 172fff36..8db18eaf 100644 --- a/test/test_colors.tavern.yaml +++ b/test/test_colors.tavern.yaml @@ -13,6 +13,9 @@ paho-mqtt: host: "{host}" port: !int "{port:d}" timeout: 3 + auth: + username: "{username}" + password: "{password}" marks: - parametrize: diff --git a/test/test_label.tavern.yaml b/test/test_label.tavern.yaml index f5dace3d..207baafe 100644 --- a/test/test_label.tavern.yaml +++ b/test/test_label.tavern.yaml @@ -13,6 +13,9 @@ paho-mqtt: &mqtt_spec host: "{host}" port: !int "{port:d}" timeout: 1 + auth: + username: "{username}" + password: "{password}" stages: - name: Page 1 diff --git a/test/test_mqtt.tavern.yaml b/test/test_mqtt.tavern.yaml index 2e103523..c923b848 100644 --- a/test/test_mqtt.tavern.yaml +++ b/test/test_mqtt.tavern.yaml @@ -1,6 +1,5 @@ # test_page.tavern.yaml --- - test_name: Page command includes: @@ -14,6 +13,9 @@ paho-mqtt: host: "{host}" port: !int "{port:d}" timeout: 3 + auth: + username: "{username}" + password: "{password}" stages: - name: step 1 - Page test @@ -46,7 +48,7 @@ stages: - name: step 4 - Page test mqtt_publish: topic: hasp/{plate}/command/json - payload: "[\"page=1\"]" + payload: '["page=1"]' mqtt_response: topic: hasp/{plate}/state/page payload: "1" @@ -55,7 +57,7 @@ stages: - name: step 5 - Page test mqtt_publish: topic: hasp/{plate}/command/json - payload: "[\"page 300\"]" + payload: '["page 300"]' mqtt_response: topic: hasp/{plate}/state/page payload: "1" diff --git a/test/test_obj.tavern.yaml b/test/test_obj.tavern.yaml index 9fe6ae5a..684e7fd5 100644 --- a/test/test_obj.tavern.yaml +++ b/test/test_obj.tavern.yaml @@ -13,6 +13,9 @@ paho-mqtt: host: "{host}" port: !int "{port:d}" timeout: 3 + auth: + username: "{username}" + password: "{password}" marks: - parametrize: @@ -52,8 +55,30 @@ marks: vals: - [1, 0, 120, 121, 122, 123, 0, 255, "I'm sorry.", "louie"] - [1, 0, -10, -10, 256, 257, 1, 64, "louie", " The cat stretched."] - - [0, 1, 1024, 1025, 1026, 1027, 5, 0, "The pipe began to rust while new.", ""] - - [0, 1, 80, 81, 82, 83, 32535, 192, "" ," Oak is strong and also gives shade."] + - [ + 0, + 1, + 1024, + 1025, + 1026, + 1027, + 5, + 0, + "The pipe began to rust while new.", + "", + ] + - [ + 0, + 1, + 80, + 81, + 82, + 83, + 32535, + 192, + "", + " Oak is strong and also gives shade.", + ] stages: - name: Page 1 @@ -202,7 +227,7 @@ stages: json: radius: !int "{radius:d}" timeout: 1 - + - name: Set value_str mqtt_publish: topic: "hasp/{plate}/command/p1b1.value_str" diff --git a/test/test_value_str.tavern.yaml b/test/test_value_str.tavern.yaml index e3448654..f22688e8 100644 --- a/test/test_value_str.tavern.yaml +++ b/test/test_value_str.tavern.yaml @@ -1,6 +1,5 @@ # test_value_str.tavern.yaml --- - test_name: Obj Standard Properties includes: @@ -14,6 +13,9 @@ paho-mqtt: host: "{host}" port: !int "{port:d}" timeout: 3 + auth: + username: "{username}" + password: "{password}" marks: - parametrize: @@ -26,14 +28,14 @@ marks: - 30 - 31 - 32 -# - 33 -# - 40 + # - 33 + # - 40 - 41 - 50 - 51 - 91 -# - 90 -# - 1 + # - 90 + # - 1 - 2 - 71 - 80 @@ -93,7 +95,7 @@ stages: x: 128 y: 128 delay_after: 0 - + - name: Set value_str mqtt_publish: topic: "hasp/{plate}/command/p[1].b[1].value_str" From 96dddbb5b2631ea6a7528692dfd78ce74c48ef5d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 27 Feb 2021 18:25:46 +0100 Subject: [PATCH 116/236] Add config/gpio support --- src/hasp/hasp_dispatch.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 55eb8770..66fa5a7f 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -420,6 +420,15 @@ static void dispatch_config(const char* topic, const char* payload) haspGetConfig(settings); } +#if HASP_USE_GPIO > 0 + else if(strcasecmp_P(topic, PSTR("gpio")) == 0) { + if(update) + gpioSetConfig(settings); + else + gpioGetConfig(settings); + } +#endif + #if HASP_USE_WIFI > 0 else if(strcasecmp_P(topic, PSTR("wifi")) == 0) { if(update) From 489ccd40343802a434da398ffc184110a2d7b561 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 27 Feb 2021 18:26:54 +0100 Subject: [PATCH 117/236] Move dispatchSetup to main setup for oobe support --- src/hasp/hasp.cpp | 1 - src/main_arduino.cpp | 3 ++- src/main_windows.cpp | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index dbae6d46..0cc018be 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -319,7 +319,6 @@ static void custom_font_apply_cb(lv_theme_t* th, lv_obj_t* obj, lv_theme_style_t */ void haspSetup(void) { - dispatchSetup(); haspDevice.set_backlight_level(haspStartDim); /******* File System Test ********************************************************************/ diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 8dfec4c7..c9c792a8 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -58,7 +58,8 @@ void setup() #endif guiSetup(); - debugSetup(); // Init the console + debugSetup(); // Init the console + dispatchSetup(); // for hasp and oobe #if HASP_USE_CONFIG > 0 if(!oobeSetup()) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 2efb6f21..00a4272c 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -110,6 +110,7 @@ void setup() // debugSetup(); // Init the console printf("%s %d\n", __FILE__, __LINE__); + dispatchSetup(); // for hasp and oobe haspSetup(); #if HASP_USE_MQTT > 0 From 51a6a7396726c891d4324e810d4c7d9d412605ab Mon Sep 17 00:00:00 2001 From: arovak Date: Sun, 28 Feb 2021 00:13:15 +0100 Subject: [PATCH 118/236] add stmpe610 touch driver --- src/drv/hasp_drv_touch.cpp | 8 +++++ src/drv/touch/hasp_drv_stmpe610.cpp | 54 +++++++++++++++++++++++++++++ src/drv/touch/hasp_drv_stmpe610.h | 15 ++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/drv/touch/hasp_drv_stmpe610.cpp create mode 100644 src/drv/touch/hasp_drv_stmpe610.h diff --git a/src/drv/hasp_drv_touch.cpp b/src/drv/hasp_drv_touch.cpp index a7a872e9..446018b6 100644 --- a/src/drv/hasp_drv_touch.cpp +++ b/src/drv/hasp_drv_touch.cpp @@ -23,6 +23,8 @@ #include "drv/touch/hasp_drv_ft5206.h" #elif TOUCH_DRIVER == 6336 #include "drv/touch/hasp_drv_ft6336u.h" +#elif TOUCH_DRIVER == 610 +#include "drv/touch/hasp_drv_stmpe610.h" #else //#include "tp_i2c.h" //#include "ft6x36.h" @@ -56,6 +58,9 @@ void drv_touch_init(uint8_t rotation) #elif TOUCH_DRIVER == 6336 FT6336U_init(); +#elif TOUCH_DRIVER == 610 + STMPE610_init(); + #else // xpt2046_alt_drv_read(indev_driver, data); // xpt2046_read(indev_driver, data); @@ -86,6 +91,9 @@ static inline bool drv_touchpad_getXY(int16_t* touchX, int16_t* touchY) #elif TOUCH_DRIVER == 6336 touched = FT6336U_getXY(&normal_x, &normal_y, true); +#elif TOUCH_DRIVER == 610 + touched = STMPE610_getXY(&normal_x, &normal_y, drv_touch_rotation, true); + #else // xpt2046_alt_drv_read(indev_driver, data); // xpt2046_read(indev_driver, data); diff --git a/src/drv/touch/hasp_drv_stmpe610.cpp b/src/drv/touch/hasp_drv_stmpe610.cpp new file mode 100644 index 00000000..27dbc245 --- /dev/null +++ b/src/drv/touch/hasp_drv_stmpe610.cpp @@ -0,0 +1,54 @@ +#if TOUCH_DRIVER == 610 + + #include + #include "Adafruit_STMPE610.h" + #include "ArduinoLog.h" + + #include "hasp_drv_stmpe610.h" + +// This is calibration data for the raw touch data to the screen coordinates + #define TS_MINX 3800 + #define TS_MAXX 100 + #define TS_MINY 100 + #define TS_MAXY 3750 + +static Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS); + +// Read touch points from global variable +bool IRAM_ATTR STMPE610_getXY(int16_t * touchX, int16_t * touchY, uint8_t touchRotation, bool debug) +{ + uint16_t x, y; + uint8_t z; + if(! touch.touched()) return false; + + while (! touch.bufferEmpty()) { + touch.readData(&x, &y, &z); + if(debug) Log.trace(TAG_DRVR, F("STMPE610: x=%i y=%i z=%i r=%i"), x, y, z, touchRotation); + } + touch.writeRegister8(STMPE_INT_STA, 0xFF); + if (1 == touchRotation) { + y = map(y, TS_MINX, TS_MAXX, 0, TFT_WIDTH); + x = map(x, TS_MINY, TS_MAXY, 0, TFT_HEIGHT); + } else if (2 == touchRotation) { + x = map(x, TS_MAXX, TS_MINX, 0, TFT_WIDTH); + y = map(y, TS_MAXY, TS_MINY, 0, TFT_HEIGHT); + } else { + x = map(x, TS_MINX, TS_MAXX, 0, TFT_WIDTH); + y = map(y, TS_MINY, TS_MAXY, 0, TFT_HEIGHT); + } + + *touchX = x; + *touchY = y; + return true; + +} + +void STMPE610_init() +{ + if (! touch.begin()) { + Log.trace(TAG_DRVR, F("STMPE610 not found!")); + } else { + Log.trace(TAG_DRVR, F("STMPE610 touch driver started")); + } +} +#endif \ No newline at end of file diff --git a/src/drv/touch/hasp_drv_stmpe610.h b/src/drv/touch/hasp_drv_stmpe610.h new file mode 100644 index 00000000..2eb07f99 --- /dev/null +++ b/src/drv/touch/hasp_drv_stmpe610.h @@ -0,0 +1,15 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_DRV_STMPE610_H +#define HASP_DRV_STMPE610_H + +#if TOUCH_DRIVER == 610 + + #include "hasp_debug.h" // for TAG_DRVR + +bool IRAM_ATTR STMPE610_getXY(int16_t * touchX, int16_t * touchY, uint8_t touchRotation, bool debug); +void STMPE610_init(); + +#endif +#endif \ No newline at end of file From b62b2841c93856427f1490141dd7a677a3d4acb0 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 28 Feb 2021 00:51:16 +0100 Subject: [PATCH 119/236] Change event names to lower case --- src/hasp/hasp_dispatch.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 66fa5a7f..3b7bc995 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -500,31 +500,31 @@ void dispatch_get_event_name(uint8_t eventid, char* buffer, size_t size) { switch(eventid) { case HASP_EVENT_ON: - memcpy_P(buffer, PSTR("ON"), size); + memcpy_P(buffer, PSTR("on"), size); break; case HASP_EVENT_OFF: - memcpy_P(buffer, PSTR("OFF"), size); + memcpy_P(buffer, PSTR("off"), size); break; case HASP_EVENT_UP: - memcpy_P(buffer, PSTR("UP"), size); + memcpy_P(buffer, PSTR("up"), size); break; case HASP_EVENT_DOWN: - memcpy_P(buffer, PSTR("DOWN"), size); + memcpy_P(buffer, PSTR("down"), size); break; case HASP_EVENT_SHORT: - memcpy_P(buffer, PSTR("SHORT"), size); + memcpy_P(buffer, PSTR("short"), size); break; case HASP_EVENT_LONG: - memcpy_P(buffer, PSTR("LONG"), size); + memcpy_P(buffer, PSTR("long"), size); break; case HASP_EVENT_HOLD: - memcpy_P(buffer, PSTR("HOLD"), size); + memcpy_P(buffer, PSTR("hold"), size); break; case HASP_EVENT_LOST: - memcpy_P(buffer, PSTR("LOST"), size); + memcpy_P(buffer, PSTR("lost"), size); break; default: - memcpy_P(buffer, PSTR("UNKNOWN"), size); + memcpy_P(buffer, PSTR("unknown"), size); } } @@ -811,8 +811,8 @@ void dispatch_moodlight(const char* topic, const char* payload) moodlight.power = Utilities::is_true(json[F("state")].as().c_str()); if(!json[F("r")].isNull()) moodlight.r = json[F("r")].as(); - if(!json[F("g")].isNull()) moodlight.r = json[F("g")].as(); - if(!json[F("b")].isNull()) moodlight.r = json[F("b")].as(); + if(!json[F("g")].isNull()) moodlight.g = json[F("g")].as(); + if(!json[F("b")].isNull()) moodlight.b = json[F("b")].as(); if(!json[F("color")].isNull()) { if(!json[F("color")]["r"].isNull()) { From 6d8a3967d7058632cfd32136df9d5cc78b0eea0a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 28 Feb 2021 02:10:23 +0100 Subject: [PATCH 120/236] Change idle events to lowercase --- src/hasp/hasp_dispatch.cpp | 6 +++--- src/mqtt/hasp_mqtt_ha.cpp | 2 +- test/test_mqtt.tavern.yaml | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 3b7bc995..bbf8853c 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -322,13 +322,13 @@ void dispatch_output_idle_state(uint8_t state) char payload[6]; switch(state) { case HASP_SLEEP_LONG: - memcpy_P(payload, PSTR("LONG"), 5); + memcpy_P(payload, PSTR("long"), 5); break; case HASP_SLEEP_SHORT: - memcpy_P(payload, PSTR("SHORT"), 6); + memcpy_P(payload, PSTR("short"), 6); break; default: - memcpy_P(payload, PSTR("OFF"), 4); + memcpy_P(payload, PSTR("off"), 4); } dispatch_state_msg(F("idle"), payload); } diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index 2de8af07..2ef28441 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -151,7 +151,7 @@ void mqtt_ha_register_switch(uint8_t page, uint8_t id) doc[F("t")] = buffer; // topic doc[F("atype")] = F("binary_sensor"); // automation_type - doc[F("pl")] = F("SHORT"); // payload + doc[F("pl")] = F("short"); // payload doc[F("type")] = F("button_short_release"); snprintf_P(buffer, sizeof(buffer), PSTR("%s/device_automation/%s/" HASP_OBJECT_NOTATION "_%s/config"), diff --git a/test/test_mqtt.tavern.yaml b/test/test_mqtt.tavern.yaml index c923b848..c0aa526a 100644 --- a/test/test_mqtt.tavern.yaml +++ b/test/test_mqtt.tavern.yaml @@ -112,7 +112,7 @@ stages: payload: "wakeup" mqtt_response: topic: hasp/{plate}/state/idle - payload: "LONG" + payload: "long" timeout: 190 delay_after: 0 @@ -122,7 +122,7 @@ stages: payload: "wakeup" mqtt_response: topic: hasp/{plate}/state/idle - payload: "SHORT" + payload: "short" timeout: 70 delay_after: 0 @@ -132,6 +132,6 @@ stages: payload: "wakeup" mqtt_response: topic: hasp/{plate}/state/idle - payload: "OFF" + payload: "off" timeout: 1 delay_after: 0 From 5e25c85689d78cf6430394bec598e6e2ee0bd63e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 28 Feb 2021 02:16:20 +0100 Subject: [PATCH 121/236] Change on/off states to lower case --- src/hasp/hasp_dispatch.cpp | 4 ++-- src/mqtt/hasp_mqtt_ha.cpp | 8 ++++---- src/sys/net/hasp_ethernet_esp32.cpp | 2 +- src/sys/net/hasp_ethernet_stm32.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index bbf8853c..cd566a68 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -846,7 +846,7 @@ void dispatch_moodlight(const char* topic, const char* payload) snprintf_P( // buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"), buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":{\"r\":%u,\"g\":%u,\"b\":%u}}"), - moodlight.power ? "ON" : "OFF", moodlight.r, moodlight.g, moodlight.b); + moodlight.power ? "on" : "off", moodlight.r, moodlight.g, moodlight.b); dispatch_state_msg(F("moodlight"), buffer); } @@ -857,7 +857,7 @@ void dispatch_backlight(const char*, const char* payload) // Return the current state char buffer[4]; - memcpy_P(buffer, haspDevice.get_backlight_power() ? PSTR("ON") : PSTR("OFF"), sizeof(buffer)); + memcpy_P(buffer, haspDevice.get_backlight_power() ? PSTR("on") : PSTR("off"), sizeof(buffer)); dispatch_state_msg(F("light"), buffer); } diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index 2ef28441..8a8acde5 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -195,8 +195,8 @@ void mqtt_ha_register_backlight() mqtt_ha_add_device_ids(doc); mqtt_ha_add_unique_id(doc, item); - // doc[F("pl_on")] = F("ON"); - // doc[F("pl_off")] = F("OFF"); + // doc[F("pl_on")] = F("on"); + // doc[F("pl_off")] = F("off"); char buffer[128]; snprintf_P(buffer, sizeof(buffer), PSTR("%s/light/%s/%s/config"), discovery_prefix, haspDevice.get_hostname(), @@ -341,8 +341,8 @@ device: "bri_stat_t": "~/state/dim", "bri_cmd_t": "~/command/dim", "bri_scl": 100, - "pl_on": "ON", - "pl_off": "OFF" + "pl_on": "on", + "pl_off": "off" } { diff --git a/src/sys/net/hasp_ethernet_esp32.cpp b/src/sys/net/hasp_ethernet_esp32.cpp index c3244afe..a0415e71 100644 --- a/src/sys/net/hasp_ethernet_esp32.cpp +++ b/src/sys/net/hasp_ethernet_esp32.cpp @@ -67,7 +67,7 @@ bool ethernetEvery5Seconds() void ethernet_get_statusupdate(char* buffer, size_t len) { snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":\"%d Mbps\",\"ip\":\"%s\","), - eth_connected ? F("ON") : F("OFF"), ETH.linkSpeed(), ETH.localIP().toString().c_str()); + eth_connected ? F("on") : F("off"), ETH.linkSpeed(), ETH.localIP().toString().c_str()); } #endif \ No newline at end of file diff --git a/src/sys/net/hasp_ethernet_stm32.cpp b/src/sys/net/hasp_ethernet_stm32.cpp index 8741a89c..39787953 100644 --- a/src/sys/net/hasp_ethernet_stm32.cpp +++ b/src/sys/net/hasp_ethernet_stm32.cpp @@ -106,7 +106,7 @@ void ethernet_get_statusupdate(char* buffer, size_t len) #endif IPAddress ip = Ethernet.localIP(); - snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":%d,\"ip\":\"%d.%d.%d.%d\","), state ? F("ON") : F("OFF"), 10, + snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":%d,\"ip\":\"%d.%d.%d.%d\","), state ? F("on") : F("off"), 10, ip[0], ip[1], ip[2], ip[3]); } #endif \ No newline at end of file From 56bbc19414803f51e8c8d9461f8f6cdb3b323e98 Mon Sep 17 00:00:00 2001 From: arovak Date: Sun, 28 Feb 2021 20:13:07 +0100 Subject: [PATCH 122/236] huzzah32-featherwings ini files --- user_setups/esp32/huzzah32-featherwing-24.ini | 33 +++++++++++++++++++ user_setups/esp32/huzzah32-featherwing-35.ini | 33 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 user_setups/esp32/huzzah32-featherwing-24.ini create mode 100644 user_setups/esp32/huzzah32-featherwing-35.ini diff --git a/user_setups/esp32/huzzah32-featherwing-24.ini b/user_setups/esp32/huzzah32-featherwing-24.ini new file mode 100644 index 00000000..79b57552 --- /dev/null +++ b/user_setups/esp32/huzzah32-featherwing-24.ini @@ -0,0 +1,33 @@ +;***************************************************; +; HUZZAH32 ESP32 with Featherwing TFT 2.4" ; +; - HUZZAH32 esp32 board ; +; - ili9341 TFT Featherwing 2.4" ; +; - STMPE610 touch controller ; +;***************************************************; + +[env:huzzah32-featherwing-24] +extends = esp32 +board = featheresp32 + +build_flags = + ${env.build_flags} + ${esp32.build_flags} +;region -- TFT_eSPI build options ------------------------ + ${lcd.featherwing-24} + -D TFT_MISO=19 + -D TFT_MOSI=18 + -D TFT_SCLK=5 + -D TFT_DC=33 + -D TFT_CS=15 + -D TFT_RST=-1 ; RST + -D TFT_BCKL=-1 ; Solder the LITE pad to a PWM enabled pin of the ESP. + -D STMPE_CS=32 +;endregion + +lib_deps = + ${env.lib_deps} + ${esp32.lib_deps} + +lib_ignore = + ${env.lib_ignore} + ${esp32.lib_ignore} \ No newline at end of file diff --git a/user_setups/esp32/huzzah32-featherwing-35.ini b/user_setups/esp32/huzzah32-featherwing-35.ini new file mode 100644 index 00000000..db9e512f --- /dev/null +++ b/user_setups/esp32/huzzah32-featherwing-35.ini @@ -0,0 +1,33 @@ +;***************************************************; +; HUZZAH32 ESP32 with Featherwing TFT 3.5" ; +; - HUZZAH32 esp32 board ; +; - HX8357D TFT Featherwing 3.5" ; +; - STMPE610 touch controller ; +;***************************************************; + +[env:huzzah32-featherwing-35] +extends = esp32 +board = featheresp32 + +build_flags = + ${env.build_flags} + ${esp32.build_flags} +;region -- TFT_eSPI build options ------------------------ + ${lcd.featherwing-35} + -D TFT_MISO=19 + -D TFT_MOSI=18 + -D TFT_SCLK=5 + -D TFT_DC=33 + -D TFT_CS=15 + -D TFT_RST=-1 ; RST + -D TFT_BCKL=-1 ; Solder the LITE pad to a PWM enabled pin of the ESP. + -D STMPE_CS=32 +;endregion + +lib_deps = + ${env.lib_deps} + ${esp32.lib_deps} + +lib_ignore = + ${env.lib_ignore} + ${esp32.lib_ignore} \ No newline at end of file From 3ecf71c1aca3072668221b78cc41ffd1db87ffde Mon Sep 17 00:00:00 2001 From: arovak Date: Sun, 28 Feb 2021 20:14:07 +0100 Subject: [PATCH 123/236] add featherwing lcd_config --- user_setups/lcd_config.ini | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/user_setups/lcd_config.ini b/user_setups/lcd_config.ini index 366fd709..2065f3c9 100644 --- a/user_setups/lcd_config.ini +++ b/user_setups/lcd_config.ini @@ -86,3 +86,27 @@ wt32-sc01 = -D SPI_FREQUENCY=40000000 -D USER_SETUP_LOADED=1 ;-D SUPPORT_TRANSACTIONS ; Default on ESP32 + +featherwing-35 = + -D HX8357D_DRIVER=1 + -D TFT_WIDTH=320 + -D TFT_HEIGHT=480 + -D TFT_ROTATION=0 ; Use default, see TFT_ROTATION values + -D SPI_FREQUENCY=27000000 + -D SPI_TOUCH_FREQUENCY=2500000 + -D SPI_READ_FREQUENCY=20000000 + -D USER_SETUP_LOADED=1 + -D TOUCH_DRIVER=610 ;STMPE610 + ;-D SUPPORT_TRANSACTIONS ; Default on ESP32 + +featherwing-24 = + -D ILI9341_DRIVER=1 + -D TFT_WIDTH=240 + -D TFT_HEIGHT=320 + -D TFT_ROTATION=0 ; Use default, see TFT_ROTATION values + -D SPI_FREQUENCY=27000000 + -D SPI_TOUCH_FREQUENCY=2500000 + -D SPI_READ_FREQUENCY=20000000 + -D USER_SETUP_LOADED=1 + -D TOUCH_DRIVER=610 ;STMPE610 + ;-D SUPPORT_TRANSACTIONS ; Default on ESP32 \ No newline at end of file From a1971947f34dd58ed8395c73e32c5fc2a1487da8 Mon Sep 17 00:00:00 2001 From: arovak Date: Sun, 28 Feb 2021 20:15:59 +0100 Subject: [PATCH 124/236] stmpe610 touch driver --- platformio.ini | 1 + src/drv/touch/hasp_drv_stmpe610.cpp | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9edb1cce..e2dfa89a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -83,6 +83,7 @@ lib_deps = ;AsyncTCP ;https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip ;https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip + adafruit/Adafruit STMPE610@^1.1.3 ;STMPE610 touch controller src_filter = +<*> -<.git/> - - - - - diff --git a/src/drv/touch/hasp_drv_stmpe610.cpp b/src/drv/touch/hasp_drv_stmpe610.cpp index 27dbc245..f1a6df4a 100644 --- a/src/drv/touch/hasp_drv_stmpe610.cpp +++ b/src/drv/touch/hasp_drv_stmpe610.cpp @@ -27,14 +27,29 @@ bool IRAM_ATTR STMPE610_getXY(int16_t * touchX, int16_t * touchY, uint8_t touchR } touch.writeRegister8(STMPE_INT_STA, 0xFF); if (1 == touchRotation) { - y = map(y, TS_MINX, TS_MAXX, 0, TFT_WIDTH); - x = map(x, TS_MINY, TS_MAXY, 0, TFT_HEIGHT); - } else if (2 == touchRotation) { + #if HX8357D_DRIVER == 1 + y = map(y, TS_MINX, TS_MAXX, 0, TFT_HEIGHT); + x = map(x, TS_MINY, TS_MAXY, TFT_WIDTH, 0); + #else x = map(x, TS_MAXX, TS_MINX, 0, TFT_WIDTH); y = map(y, TS_MAXY, TS_MINY, 0, TFT_HEIGHT); + #endif + } else if (2 == touchRotation) { + #if HX8357D_DRIVER == 1 + x = map(x, TS_MAXX, TS_MINX, TFT_WIDTH, 0); + y = map(y, TS_MAXY, TS_MINY, 0, TFT_HEIGHT); + #else + x = map(x, TS_MAXX, TS_MINX, 0, TFT_WIDTH); + y = map(y, TS_MAXY, TS_MINY, 0, TFT_HEIGHT); + #endif } else { + #if HX8357D_DRIVER == 1 + x = map(x, TS_MINX, TS_MAXX, TFT_WIDTH, 0); + y = map(y, TS_MINY, TS_MAXY, 0, TFT_HEIGHT); + #else x = map(x, TS_MINX, TS_MAXX, 0, TFT_WIDTH); y = map(y, TS_MINY, TS_MAXY, 0, TFT_HEIGHT); + #endif } *touchX = x; From 190f2d649eb8faed545ba11f30c732f5447eb75b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 28 Feb 2021 20:49:04 +0100 Subject: [PATCH 125/236] Add D_ERROR_UNKNOWN --- src/lang/en_US.h | 1 + src/lang/nl_NL.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/lang/en_US.h b/src/lang/en_US.h index e5747b38..02a73ae1 100644 --- a/src/lang/en_US.h +++ b/src/lang/en_US.h @@ -6,6 +6,7 @@ #define D_SSID "Ssid:" #define D_ERROR_OUT_OF_MEMORY "Out of memory" +#define D_ERROR_UNKNOWN "Unkown error" #define D_CONFIG_NOT_CHANGED "Settings did not change" #define D_CONFIG_CHANGED "Settings changed" diff --git a/src/lang/nl_NL.h b/src/lang/nl_NL.h index 6a5022fc..be8d2202 100644 --- a/src/lang/nl_NL.h +++ b/src/lang/nl_NL.h @@ -6,6 +6,7 @@ #define D_SSID "Ssid:" #define D_ERROR_OUT_OF_MEMORY "Geen geheugen bechikbaar" +#define D_ERROR_UNKNOWN "Unbekende fout" #define D_CONFIG_NOT_CHANGED "Instellingen ongewijzigd" #define D_CONFIG_CHANGED "Instellingen gewijzigd" From 17550d7b66c7b9944fc6d4d990a93dfe58d8ffc8 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 28 Feb 2021 20:49:55 +0100 Subject: [PATCH 126/236] Add MQTT error codes --- src/mqtt/hasp_mqtt.h | 16 ++++++++--- src/mqtt/hasp_mqtt_paho_async.cpp | 2 +- src/mqtt/hasp_mqtt_paho_single.cpp | 44 ++++++++++++++--------------- src/mqtt/hasp_mqtt_pubsubclient.cpp | 30 +++++++++----------- 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/mqtt/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h index 18f007ea..5760bede 100644 --- a/src/mqtt/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -13,16 +13,24 @@ #define __FlashStringHelper char #endif +enum hasp_mqtt_error_t { + MQTT_ERR_OK = 0, + MQTT_ERR_DISABLED = -1, + MQTT_ERR_NO_CONN = -2, + MQTT_ERR_SUB_FAIL = -3, + MQTT_ERR_PUB_FAIL = -4, + MQTT_ERR_UNKNOWN = -128 +}; + void mqttSetup(); void mqttLoop(); void mqttEvery5Seconds(bool wifiIsConnected); void mqttStart(); void mqttStop(); -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload); -void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload); - -bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain); +int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload); +int mqtt_send_state(const char* subtopic, const char* payload); +int mqttPublish(const char* topic, const char* payload, size_t len, bool retain); bool mqttIsConnected(); diff --git a/src/mqtt/hasp_mqtt_paho_async.cpp b/src/mqtt/hasp_mqtt_paho_async.cpp index d8b94f2b..be17e3f9 100644 --- a/src/mqtt/hasp_mqtt_paho_async.cpp +++ b/src/mqtt/hasp_mqtt_paho_async.cpp @@ -343,7 +343,7 @@ void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) mqttPublish(tmp_topic, payload, false); } -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) +void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/p%ub%u"), mqttNodeTopic, pageid, btnid); diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index bcdbdcb0..a1e45b66 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -106,7 +106,7 @@ int disc_finished = 0; int subscribed = 0; int connected = 0; -bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain); +int mqttPublish(const char* topic, const char* payload, size_t len, bool retain); /* ===== Paho event callbacks ===== */ @@ -207,30 +207,28 @@ void mqtt_subscribe(void* context, const char* topic) /* ===== Local HASP MQTT functions ===== */ -bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain) +int mqttPublish(const char* topic, const char* payload, size_t len, bool retain) { - if(mqttIsConnected()) { - MQTTClient_message pubmsg = MQTTClient_message_initializer; - MQTTClient_deliveryToken token; + if(!mqttIsConnected()) return MQTT_ERR_NO_CONN; - pubmsg.payload = (char*)payload; - pubmsg.payloadlen = len; // (int)strlen(payload); - pubmsg.qos = QOS; - pubmsg.retained = retain; + MQTTClient_message pubmsg = MQTTClient_message_initializer; + MQTTClient_deliveryToken token; - MQTTClient_publishMessage(mqtt_client, topic, &pubmsg, &token); - int rc = MQTTClient_waitForCompletion(mqtt_client, token, TIMEOUT); + pubmsg.payload = (char*)payload; + pubmsg.payloadlen = len; // (int)strlen(payload); + pubmsg.qos = QOS; + pubmsg.retained = retain; - if(rc != MQTTCLIENT_SUCCESS) { - LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " '%s' => %s"), topic, payload); - } else { - LOG_TRACE(TAG_MQTT_PUB, F("'%s' => %s OK"), topic, payload); - return true; - } + MQTTClient_publishMessage(mqtt_client, topic, &pubmsg, &token); + int rc = MQTTClient_waitForCompletion(mqtt_client, token, TIMEOUT); + + if(rc != MQTTCLIENT_SUCCESS) { + LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " '%s' => %s"), topic, payload); + return MQTT_ERR_PUB_FAIL; } else { - LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_CONNECTED)); + LOG_TRACE(TAG_MQTT_PUB, F("'%s' => %s OK"), topic, payload); + return MQTT_ERR_OK; } - return false; } // static bool mqttPublish(const char* topic, const char* payload, bool retain) @@ -245,19 +243,19 @@ bool mqttIsConnected() return connected == 1; } -void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) +int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; // printf(("%sstate/%s\n"), mqttNodeTopic, subtopic); snprintf_P(tmp_topic, sizeof(tmp_topic), ("%sstate/%s"), mqttNodeTopic, subtopic); - mqttPublish(tmp_topic, payload, strlen(payload), false); + return mqttPublish(tmp_topic, payload, strlen(payload), false); } -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) +int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/p%ub%u"), mqttNodeTopic, pageid, btnid); - mqttPublish(tmp_topic, payload, strlen(payload), false); + return mqttPublish(tmp_topic, payload, strlen(payload), false); } static void onConnect(void* context) diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index 73afab25..05a795cb 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -89,25 +89,21 @@ char mqttGroupName[16] = MQTT_GROUPNAME; uint16_t mqttPort = MQTT_PORT; PubSubClient mqttClient(mqttNetworkClient); -bool mqttPublish(const char* topic, const char* payload, size_t len, bool retain) +int mqttPublish(const char* topic, const char* payload, size_t len, bool retain) { - if(mqttIsConnected()) { - if(mqttClient.beginPublish(topic, len, retain)) { - mqttClient.write((uint8_t*)payload, len); - mqttClient.endPublish(); + if(!mqttEnabled) return MQTT_ERR_DISABLED; + if(!mqttClient.connected()) return MQTT_ERR_NO_CONN; - LOG_TRACE(TAG_MQTT_PUB, F("%s => %s"), topic, payload); - return true; - } else { - LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " %s => %s"), topic, payload); - } - } else { - LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_CONNECTED)); + if(mqttClient.beginPublish(topic, len, retain)) { + mqttClient.write((uint8_t*)payload, len); + mqttClient.endPublish(); + return MQTT_ERR_OK; } - return false; + + return MQTT_ERR_PUB_FAIL; } -static bool mqttPublish(const char* topic, const char* payload, bool retain) +int mqttPublish(const char* topic, const char* payload, bool retain) { return mqttPublish(topic, payload, strlen(payload), retain); } @@ -132,18 +128,18 @@ void mqtt_send_lwt(bool online) bool res = mqttPublish(tmp_topic, tmp_payload, len, true); } -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) +void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 16]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/" HASP_OBJECT_NOTATION), mqttNodeTopic, pageid, btnid); mqttPublish(tmp_topic, payload, false); } -void mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) +int mqtt_send_state(const char* subtopic, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/%s"), mqttNodeTopic, subtopic); - mqttPublish(tmp_topic, payload, false); + return mqttPublish(tmp_topic, payload, false); } //////////////////////////////////////////////////////////////////////////////////////////////////// From 9f71460a65915ee2fb5d8ebfa505c1a8a364e676 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 28 Feb 2021 21:19:03 +0100 Subject: [PATCH 127/236] Fix 255.255.255.255 IP error --- src/sys/net/hasp_wifi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/net/hasp_wifi.cpp b/src/sys/net/hasp_wifi.cpp index c2fa9170..6ed4a553 100644 --- a/src/sys/net/hasp_wifi.cpp +++ b/src/sys/net/hasp_wifi.cpp @@ -362,7 +362,7 @@ static void wifiReconnect(void) // https://github.com/espressif/arduino-esp32/issues/3438#issuecomment-721428310 WiFi.disconnect(true); WiFi.begin(wifiSsid, wifiPassword); - WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); + // WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); // causes 255.255.255.255 IP errors WiFi.setHostname(haspDevice.get_hostname()); #endif } From 0ef0f8c52077cde7e5bad04d7cb240ed8ef56779 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 28 Feb 2021 22:04:12 +0100 Subject: [PATCH 128/236] New event handler state senders --- src/hasp/hasp_dispatch.cpp | 230 ++++++++++++++++++++-------- src/hasp/hasp_dispatch.h | 11 +- src/hasp/hasp_object.cpp | 62 ++++---- src/mqtt/hasp_mqtt.h | 6 +- src/mqtt/hasp_mqtt_paho_single.cpp | 2 +- src/mqtt/hasp_mqtt_pubsubclient.cpp | 4 +- 6 files changed, 217 insertions(+), 98 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index cd566a68..00af337f 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -54,25 +54,63 @@ moodlight_t moodlight; static void dispatch_config(const char* topic, const char* payload); // void dispatch_group_value(uint8_t groupid, int16_t state, lv_obj_t * obj); -static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const char* payload); -void dispatch_screenshot(const char*, const char* filename) +/* Sends the payload out on the state/subtopic + */ +void dispatch_state_subtopic(const char* subtopic, const char* payload) { -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - - if(strlen(filename) == 0) { // no filename given - char tempfile[32]; - memcpy_P(tempfile, PSTR("/screenshot.bmp"), sizeof(tempfile)); - guiTakeScreenshot(tempfile); - } else if(strlen(filename) > 31 || filename[0] != '/') { // Invalid filename - LOG_WARNING(TAG_MSGR, "Invalid filename %s", filename); - } else { // Valid filename - guiTakeScreenshot(filename); - } - +#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_CLIENT) + LOG_TRACE(TAG_MSGR, F("%s => %s"), subtopic, payload); #else - LOG_WARNING(TAG_MSGR, "Failed to save %s, no storage", filename); + +#if HASP_USE_MQTT > 0 + switch(mqtt_send_state(subtopic, payload)) { + case MQTT_ERR_OK: + LOG_TRACE(TAG_MQTT_PUB, F("%s => %s"), subtopic, payload); + break; + case MQTT_ERR_PUB_FAIL: + LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " %s => %s"), subtopic, payload); + break; + case MQTT_ERR_NO_CONN: + LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_CONNECTED)); + break; + default: + LOG_ERROR(TAG_MQTT, F(D_ERROR_UNKNOWN)); + } #endif + +#if HASP_USE_TASMOTA_CLIENT > 0 + slave_send_state(subtopic, payload); +#endif + +#endif +} + +/* Sends the data out on the state/pxby topic + */ +void dispatch_state_object(uint8_t pageid, uint8_t btnid, const char* payload) +{ + char topic[16]; + snprintf_P(topic, sizeof(topic), PSTR(HASP_OBJECT_NOTATION), pageid, btnid); + dispatch_state_subtopic(topic, payload); +} + +/* Takes and lv_obj and finds the pageid and objid + Then sends the data out on the state/pxby topic +*/ +void dispatch_obj_data(lv_obj_t* obj, const char* data) +{ + uint8_t pageid; + uint8_t objid; + + if(hasp_find_id_from_obj(obj, &pageid, &objid)) { + if(!data) return; +#if HASP_USE_MQTT > 0 + dispatch_state_object(pageid, objid, data); +#endif + } else { + LOG_ERROR(TAG_MSGR, F(D_OBJECT_UNKNOWN)); + } } // Format filesystem and erase EEPROM @@ -319,6 +357,7 @@ void dispatch_text_line(const char* cmnd) // send idle state to the client void dispatch_output_idle_state(uint8_t state) { + char topic[6]; char payload[6]; switch(state) { case HASP_SLEEP_LONG: @@ -330,17 +369,20 @@ void dispatch_output_idle_state(uint8_t state) default: memcpy_P(payload, PSTR("off"), 4); } - dispatch_state_msg(F("idle"), payload); + memcpy_P(topic, PSTR("idle"), 5); + dispatch_state_subtopic(topic, payload); } void dispatch_output_group_state(uint8_t groupid, uint16_t state) { char payload[64]; char number[16]; // Return the current state + char topic[8]; itoa(state, number, DEC); snprintf_P(payload, sizeof(payload), PSTR("{\"group\":%d,\"state\":\"%s\"}"), groupid, number); - dispatch_state_msg(F("output"), payload); + memcpy_P(topic, PSTR("output"), 7); + dispatch_state_subtopic(topic, payload); } void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char* attribute, const char* data) @@ -350,7 +392,7 @@ void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char* char payload[32 + strlen(data) + strlen(attribute)]; snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":\"%s\"}"), attribute, data); - mqtt_send_object_state(pageid, btnid, payload); + dispatch_state_object(pageid, btnid, payload); } void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char* attribute, int32_t val) @@ -360,7 +402,7 @@ void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char* char payload[64 + strlen(attribute)]; snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":%d}"), attribute, val); - mqtt_send_object_state(pageid, btnid, payload); + dispatch_state_object(pageid, btnid, payload); } void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char* attribute, uint8_t r, uint8_t g, @@ -372,7 +414,7 @@ void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":\"#%02x%02x%02x\",\"r\":%d,\"g\":%d,\"b\":%d}"), attribute, r, g, b, r, g, b); - mqtt_send_object_state(pageid, btnid, payload); + dispatch_state_object(pageid, btnid, payload); } #if HASP_USE_CONFIG > 0 @@ -468,9 +510,12 @@ static void dispatch_config(const char* topic, const char* payload) // Send output if(!update) { + char subtopic[8]; settings.remove(F("pass")); // hide password in output + size_t size = serializeJson(doc, buffer, sizeof(buffer)); - dispatch_state_msg(F("config"), buffer); + memcpy_P(subtopic, PSTR("config"), 7); + dispatch_state_subtopic(subtopic, buffer); } } #endif // HASP_USE_CONFIG @@ -523,6 +568,9 @@ void dispatch_get_event_name(uint8_t eventid, char* buffer, size_t size) case HASP_EVENT_LOST: memcpy_P(buffer, PSTR("lost"), size); break; + case HASP_EVENT_CHANGED: + memcpy_P(buffer, PSTR("changed"), size); + break; default: memcpy_P(buffer, PSTR("unknown"), size); } @@ -532,12 +580,14 @@ void dispatch_get_event_name(uint8_t eventid, char* buffer, size_t size) void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid) { char payload[64]; + char topic[8]; char event[8]; dispatch_get_event_name(eventid, event, sizeof(event)); snprintf_P(payload, sizeof(payload), PSTR("{\"pin\":%d,\"group\":%d,\"event\":\"%s\"}"), pin, group, event); #if HASP_USE_MQTT > 0 - mqtt_send_state(F("input"), payload); + memcpy_P(topic, PSTR("input"), 6); + dispatch_state_subtopic(topic, payload); #endif // update outputstates @@ -545,45 +595,67 @@ void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid) } #endif -void dispatch_object_event(lv_obj_t* obj, uint8_t eventid) +/* ============================== Event Senders ============================ */ + +// Send out the event that occured +void dispatch_object_generic_event(lv_obj_t* obj, uint8_t eventid) { - char topic[8]; - char payload[8]; - uint8_t pageid, objid; + char data[40]; + char eventname[8]; - snprintf_P(topic, sizeof(topic), PSTR("event")); - dispatch_get_event_name(eventid, payload, sizeof(payload)); - - if(hasp_find_id_from_obj(obj, &pageid, &objid)) { - dispatch_send_obj_attribute_str(pageid, objid, topic, payload); - } - - // dispatch_group_onoff(obj->user_data.groupid, dispatch_get_event_state(eventid), obj); + dispatch_get_event_name(eventid, eventname, sizeof(eventname)); + snprintf_P(data, sizeof(data), PSTR("{\"event\":\"%s\"}"), eventname); + dispatch_obj_data(obj, data); } +// Send out the on/off event, with the val +void dispatch_object_toggle_event(lv_obj_t* obj, bool state) +{ + char data[40]; + char eventname[8]; + + dispatch_get_event_name(state, eventname, sizeof(eventname)); + snprintf_P(data, sizeof(data), PSTR("{\"event\":\"%s\",\"val\":%d}"), eventname, state); + dispatch_obj_data(obj, data); +} + +// Send out the changed event, with the val void dispatch_object_value_changed(lv_obj_t* obj, int16_t state) { - char topic[4]; + char data[48]; - hasp_update_sleep_state(); // wakeup? - snprintf_P(topic, sizeof(topic), PSTR("val")); - hasp_send_obj_attribute_int(obj, topic, state); + snprintf_P(data, sizeof(data), PSTR("{\"event\":\"changed\",\"val\":%d}"), state); + dispatch_obj_data(obj, data); +} + +// Send out the changed event, with the val and text +void dispatch_object_selection_changed(lv_obj_t* obj, int16_t val, const char* text) +{ + char data[200]; + + snprintf_P(data, sizeof(data), PSTR("{\"event\":\"changed\",\"val\":%d,\"text\":\"%s\"}"), val, text); + dispatch_obj_data(obj, data); +} + +// Send out the changed event, with the color +void dispatch_object_color_changed(lv_obj_t* obj, lv_color_t color) +{ + char data[80]; + lv_color32_t c32; + c32.full = lv_color_to32(color); + + snprintf_P(data, sizeof(data), + PSTR("{\"event\":\"changed\",\"color\":\"#%02x%02x%02x\",\"r\":%d,\"g\":%d,\"b\":%d}"), c32.ch.red, + c32.ch.green, c32.ch.blue, c32.ch.red, c32.ch.green, c32.ch.blue); + dispatch_obj_data(obj, data); } /********************************************** Output States ******************************************/ +/* static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const char* payload) { -#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_CLIENT) - LOG_TRACE(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload); -#else -#if HASP_USE_MQTT > 0 - mqtt_send_state(subtopic, payload); -#endif -#if HASP_USE_TASMOTA_CLIENT > 0 - slave_send_state(subtopic, payload); -#endif -#endif -} + +}*/ // void dispatch_group_onoff(uint8_t groupid, uint16_t eventid, lv_obj_t * obj) // { @@ -624,6 +696,25 @@ void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t* /********************************************** Native Commands ****************************************/ +void dispatch_screenshot(const char*, const char* filename) +{ +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + + if(strlen(filename) == 0) { // no filename given + char tempfile[32]; + memcpy_P(tempfile, PSTR("/screenshot.bmp"), sizeof(tempfile)); + guiTakeScreenshot(tempfile); + } else if(strlen(filename) > 31 || filename[0] != '/') { // Invalid filename + LOG_WARNING(TAG_MSGR, "Invalid filename %s", filename); + } else { // Valid filename + guiTakeScreenshot(filename); + } + +#else + LOG_WARNING(TAG_MSGR, "Failed to save %s, no storage", filename); +#endif +} + void dispatch_parse_json(const char*, const char* payload) { // Parse an incoming JSON array into individual commands /* if(strPayload.endsWith(",]")) { @@ -719,10 +810,12 @@ void dispatch_parse_jsonl(const char*, const char* payload) void dispatch_output_current_page() { - // Log result - char payload[4]; - itoa(haspGetPage(), payload, DEC); - dispatch_state_msg(F("page"), payload); + char topic[8]; + char payload[8]; + + memcpy_P(topic, PSTR("page"), 5); + snprintf_P(payload, sizeof(payload), PSTR("%d"), haspGetPage()); + dispatch_state_subtopic(topic, payload); } // Get or Set a page @@ -785,9 +878,12 @@ void dispatch_dim(const char*, const char* level) // Set the current state if(strlen(level) != 0) haspDevice.set_backlight_level(atoi(level)); - char payload[5]; - itoa(haspDevice.get_backlight_level(), payload, DEC); - dispatch_state_msg(F("dim"), payload); + char topic[8]; + char payload[8]; + + memcpy_P(topic, PSTR("dim"), 4); + snprintf_P(payload, sizeof(payload), PSTR("%d"), haspDevice.get_backlight_level()); + dispatch_state_subtopic(topic, payload); } void dispatch_moodlight(const char* topic, const char* payload) @@ -843,11 +939,14 @@ void dispatch_moodlight(const char* topic, const char* payload) // Return the current state char buffer[128]; + char out_topic[16]; + memcpy_P(out_topic, PSTR("moodlight"), 10); snprintf_P( - // buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"), + // buffer, sizeof(buffer), + // PSTR("{\"state\":\"%s\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"), buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":{\"r\":%u,\"g\":%u,\"b\":%u}}"), moodlight.power ? "on" : "off", moodlight.r, moodlight.g, moodlight.b); - dispatch_state_msg(F("moodlight"), buffer); + dispatch_state_subtopic(out_topic, buffer); } void dispatch_backlight(const char*, const char* payload) @@ -856,9 +955,11 @@ void dispatch_backlight(const char*, const char* payload) if(strlen(payload) != 0) haspDevice.set_backlight_power(Utilities::is_true(payload)); // Return the current state + char topic[8]; char buffer[4]; + memcpy_P(topic, PSTR("light"), 6); memcpy_P(buffer, haspDevice.get_backlight_power() ? PSTR("on") : PSTR("off"), sizeof(buffer)); - dispatch_state_msg(F("light"), buffer); + dispatch_state_subtopic(topic, buffer); } void dispatch_web_update(const char*, const char* espOtaUrl) @@ -925,12 +1026,12 @@ void dispatch_output_statusupdate(const char*, const char*) strcat(data, buffer); #endif - snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","), + snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"core\":\"%s\","), haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), haspDevice.get_core_version()); strcat(data, buffer); - snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), - haspGetPage(), (HASP_NUM_PAGES)); + snprintf_P(buffer, sizeof(buffer), PSTR("\"canUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), haspGetPage(), + (HASP_NUM_PAGES)); strcat(data, buffer); #if defined(ARDUINO_ARCH_ESP8266) @@ -942,7 +1043,10 @@ void dispatch_output_statusupdate(const char*, const char*) Utilities::tft_driver_name().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); strcat(data, buffer); } - mqtt_send_state(F("statusupdate"), data); + + char topic[16]; + memcpy_P(topic, PSTR("statusupdate"), 13); + dispatch_state_subtopic(topic, data); dispatchLastMillis = millis(); /* if(updateEspAvailable) { diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 1dba3b41..ac0e591b 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -22,7 +22,9 @@ enum hasp_event_t { // even = released, odd = pressed HASP_EVENT_LONG = 5, HASP_EVENT_LOST = 6, HASP_EVENT_HOLD = 7, - HASP_EVENT_DOUBLE = 8 + HASP_EVENT_DOUBLE = 8, + + HASP_EVENT_CHANGED = 32 }; /* ===== Default Event Processors ===== */ @@ -60,7 +62,6 @@ void dispatch_output_statusupdate(const char*, const char*); void dispatch_current_state(); void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid); -void dispatch_object_event(lv_obj_t* obj, uint8_t eventid); bool dispatch_get_event_state(uint8_t eventid); void dispatch_get_event_name(uint8_t eventid, char* buffer, size_t size); void dispatch_object_value_changed(lv_obj_t* obj, int16_t state); @@ -72,6 +73,12 @@ void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char* void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char* attribute, uint8_t r, uint8_t g, uint8_t b); +void dispatch_object_generic_event(lv_obj_t* obj, uint8_t eventid); +void dispatch_object_toggle_event(lv_obj_t* obj, bool state); +void dispatch_object_value_changed(lv_obj_t* obj, int16_t state); +void dispatch_object_selection_changed(lv_obj_t* obj, int16_t val, const char* text); +void dispatch_object_color_changed(lv_obj_t* obj, lv_color_t color); + /* ===== Getter and Setter Functions ===== */ /* ===== Read/Write Configuration ===== */ diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 46610f2e..a91e7a76 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -269,6 +269,23 @@ void hasp_send_obj_attribute_color(lv_obj_t* obj, const char* attribute, lv_colo // ##################### Event Handlers ######################################################## +/** + * Called when a press on the system layer is detected + * @param obj pointer to a button matrix + * @param event type of event that occured + */ +void wakeup_event_handler(lv_obj_t* obj, lv_event_t event) +{ + if(obj == lv_disp_get_layer_sys(NULL)) { + hasp_update_sleep_state(); // wakeup? + + if(event == LV_EVENT_CLICKED) { + lv_obj_set_click(obj, false); // disable first touch + LOG_VERBOSE(TAG_HASP, F("Wakeup touch disabled")); + } + } +} + /** * Called when a button-style object is clicked * @param obj pointer to a button object @@ -317,7 +334,7 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) return; case LV_EVENT_VALUE_CHANGED: - LOG_WARNING(TAG_HASP, F("Value changed Event %d occured"), event); + LOG_WARNING(TAG_HASP, F("Value changed Event %d occured"), event); // Shouldn't happen in this event handler last_press_was_short = false; return; @@ -333,28 +350,11 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) return; } - hasp_update_sleep_state(); // wakeup? - dispatch_object_event(obj, eventid); // send object event + hasp_update_sleep_state(); // wakeup? + dispatch_object_generic_event(obj, eventid); // send object event dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(dispatch_get_event_state(eventid), 0, 1), obj); } -/** - * Called when a press on the system layer is detected - * @param obj pointer to a button matrix - * @param event type of event that occured - */ -void wakeup_event_handler(lv_obj_t* obj, lv_event_t event) -{ - if(obj == lv_disp_get_layer_sys(NULL)) { - hasp_update_sleep_state(); // wakeup? - - if(event == LV_EVENT_CLICKED) { - lv_obj_set_click(obj, false); // disable first touch - LOG_VERBOSE(TAG_HASP, F("Wakeup touch disabled")); - } - } -} - /** * Called when a object state is toggled on/off * @param obj pointer to a switch object @@ -363,7 +363,7 @@ void wakeup_event_handler(lv_obj_t* obj, lv_event_t event) void toggle_event_handler(lv_obj_t* obj, lv_event_t event) { if(event == LV_EVENT_VALUE_CHANGED) { - char property[4]; + char property[36]; // 4 for val only bool val = 0; hasp_update_sleep_state(); // wakeup? @@ -385,8 +385,11 @@ void toggle_event_handler(lv_obj_t* obj, lv_event_t event) return; } - snprintf_P(property, sizeof(property), PSTR("val")); - hasp_send_obj_attribute_int(obj, property, val); + // snprintf_P(property, sizeof(property), PSTR("val")); + // hasp_send_obj_attribute_int(obj, property, val); + + hasp_update_sleep_state(); // wakeup? + dispatch_object_toggle_event(obj, val); dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(val, 0, 1), obj); } else if(event == LV_EVENT_DELETE) { @@ -437,7 +440,7 @@ static void selector_event_handler(lv_obj_t* obj, lv_event_t event) const char* txt = lv_table_get_cell_value(obj, row, col); strncpy(buffer, txt, sizeof(buffer)); - snprintf_P(property, sizeof(property), PSTR("row\":%d,\"col\":%d,\"txt"), row, col); + snprintf_P(property, sizeof(property), PSTR("row\":%d,\"col\":%d,\"text"), row, col); hasp_send_obj_attribute_str(obj, property, buffer); return; } @@ -447,8 +450,10 @@ static void selector_event_handler(lv_obj_t* obj, lv_event_t event) } // set the property - snprintf_P(property, sizeof(property), PSTR("val\":%d,\"text"), val); - hasp_send_obj_attribute_str(obj, property, buffer); + // snprintf_P(property, sizeof(property), PSTR("val\":%d,\"text"), val); + // hasp_send_obj_attribute_str(obj, property, buffer); + + dispatch_object_selection_changed(obj, val, buffer); if(max > 0) dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(val, 0, max), obj); } else if(event == LV_EVENT_DELETE) { @@ -481,6 +486,7 @@ void slider_event_handler(lv_obj_t* obj, lv_event_t event) int16_t val = 0; int16_t min = 0; int16_t max = 0; + hasp_update_sleep_state(); // wakeup? if(obj->user_data.objid == LV_HASP_SLIDER) { val = lv_slider_get_value(obj); @@ -514,7 +520,9 @@ static void cpicker_event_handler(lv_obj_t* obj, lv_event_t event) if(event == LV_EVENT_VALUE_CHANGED) { hasp_update_sleep_state(); // wakeup? - hasp_send_obj_attribute_color(obj, color, lv_cpicker_get_color(obj)); + // hasp_send_obj_attribute_color(obj, color, lv_cpicker_get_color(obj)); + dispatch_object_color_changed(obj, lv_cpicker_get_color(obj)); + } else if(event == LV_EVENT_DELETE) { LOG_VERBOSE(TAG_HASP, F(D_OBJECT_DELETED)); hasp_object_delete(obj); diff --git a/src/mqtt/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h index 5760bede..aa67ff0b 100644 --- a/src/mqtt/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -9,9 +9,9 @@ #include "hasp_conf.h" -#ifdef WINDOWS -#define __FlashStringHelper char -#endif +// #ifdef WINDOWS +// #define __FlashStringHelper char +// #endif enum hasp_mqtt_error_t { MQTT_ERR_OK = 0, diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index a1e45b66..c2afbe56 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -251,7 +251,7 @@ int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) return mqttPublish(tmp_topic, payload, strlen(payload), false); } -int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char* payload) +int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 20]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/p%ub%u"), mqttNodeTopic, pageid, btnid); diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index 05a795cb..a485721b 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -128,11 +128,11 @@ void mqtt_send_lwt(bool online) bool res = mqttPublish(tmp_topic, tmp_payload, len, true); } -void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload) +int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload) { char tmp_topic[strlen(mqttNodeTopic) + 16]; snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/" HASP_OBJECT_NOTATION), mqttNodeTopic, pageid, btnid); - mqttPublish(tmp_topic, payload, false); + return mqttPublish(tmp_topic, payload, false); } int mqtt_send_state(const char* subtopic, const char* payload) From c780fabead9f67942503b167af05ca836c398d39 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 1 Mar 2021 04:29:53 +0100 Subject: [PATCH 129/236] Switch HA message order --- src/mqtt/hasp_mqtt_pubsubclient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index a485721b..3fe89dff 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -169,8 +169,8 @@ static void mqtt_message_cb(char* topic, byte* payload, unsigned int length) } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { - dispatch_current_state(); - mqtt_ha_register_auto_discovery(); + mqtt_ha_register_auto_discovery(); // auto-discovery first + dispatch_current_state(); // send the data } return; From 67a63105ce004deaf5dfa71ff71616e15aa66749 Mon Sep 17 00:00:00 2001 From: Thomas Langewouters Date: Mon, 1 Mar 2021 21:38:45 +0100 Subject: [PATCH 130/236] Add linux emulator platform --- include/hasp_conf.h | 18 ++-- include/hasp_macro.h | 4 +- lib/lv_lib_zifont/lv_zifont.cpp | 2 +- src/dev/device.h | 13 ++- src/dev/posix/hasp_posix.cpp | 108 ++++++++++++++++++++++ src/dev/posix/hasp_posix.h | 76 +++++++++++++++ src/drv/tft_driver.h | 4 +- src/hasp/hasp_dispatch.cpp | 6 +- src/hasp/hasp_object.cpp | 4 +- src/hasp_debug.h | 2 +- src/hasp_gui.cpp | 12 +-- src/main_arduino.cpp | 4 +- src/main_windows.cpp | 36 ++++++-- src/mqtt/hasp_mqtt.h | 4 +- src/mqtt/hasp_mqtt_ha.cpp | 2 +- src/mqtt/hasp_mqtt_paho_async.cpp | 2 +- tools/sdl2_build_extra.py | 24 ----- tools/windows_build_extra.py | 25 +++++ user_setups/linux_sdl/emulator_64bits.ini | 92 ++++++++++++++++++ user_setups/win32/emulator_64bits.ini | 4 +- 20 files changed, 377 insertions(+), 65 deletions(-) create mode 100644 src/dev/posix/hasp_posix.cpp create mode 100644 src/dev/posix/hasp_posix.h create mode 100644 tools/windows_build_extra.py create mode 100644 user_setups/linux_sdl/emulator_64bits.ini diff --git a/include/hasp_conf.h b/include/hasp_conf.h index a7c08cbc..52d2e081 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -107,6 +107,7 @@ #ifdef WINDOWS #include "winsock2.h" #include "Windows.h" +#elif defined(POSIX) #else #include "Arduino.h" #endif @@ -183,7 +184,7 @@ static WiFiSpiClass WiFi; #if HASP_USE_MQTT > 0 #include "mqtt/hasp_mqtt.h" -#ifdef WINDOWS +#if defined(WINDOWS) || defined(POSIX) #define USE_PAHO #else #define USE_PUBSUBCLIENT @@ -230,7 +231,7 @@ static WiFiSpiClass WiFi; #define PGM_P const char* #endif -#if defined(WINDOWS) +#if defined(WINDOWS) || defined(POSIX) #ifndef __FlashStringHelper #define __FlashStringHelper char #endif @@ -248,11 +249,17 @@ static WiFiSpiClass WiFi; #endif #endif -#ifdef WINDOWS +#if defined(WINDOWS) +#include +#define delay Sleep +#endif +#if defined(POSIX) +#define delay SDL_Delay +#endif +#if defined(WINDOWS) || defined(POSIX) #include #include #include -#include #include #define snprintf_P snprintf @@ -261,7 +268,6 @@ static WiFiSpiClass WiFi; #define strcmp_P strcmp #define strstr_P strstr #define halRestartMcu() -#define delay Sleep #define millis SDL_GetTicks #define DEC 10 @@ -275,4 +281,4 @@ static WiFiSpiClass WiFi; //#define guiCalibrate() #endif -#endif // HASP_CONF_H \ No newline at end of file +#endif // HASP_CONF_H diff --git a/include/hasp_macro.h b/include/hasp_macro.h index a129cbe0..f9199099 100644 --- a/include/hasp_macro.h +++ b/include/hasp_macro.h @@ -1,7 +1,7 @@ #ifndef HASP_MACRO_H #define HASP_MACRO_H -#ifdef WINDOWS +#if defined(WINDOWS) || defined(POSIX) #define LOG_OUTPUT(x, ...) printf(__VA_ARGS__) #else #define LOG_OUTPUT(...) Log.output(...) @@ -69,4 +69,4 @@ #endif -#endif \ No newline at end of file +#endif diff --git a/lib/lv_lib_zifont/lv_zifont.cpp b/lib/lv_lib_zifont/lv_zifont.cpp index 25bfe0b4..29955d7a 100644 --- a/lib/lv_lib_zifont/lv_zifont.cpp +++ b/lib/lv_lib_zifont/lv_zifont.cpp @@ -2,7 +2,7 @@ * INCLUDES *********************/ -#ifndef WINDOWS +#if !(defined(WINDOWS)||defined(POSIX)) #include #include diff --git a/src/dev/device.h b/src/dev/device.h index 8de3974f..3e49d271 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -8,8 +8,13 @@ #include "Arduino.h" #endif -#ifdef WINDOWS +#if defined(WINDOWS) || defined(POSIX) #include +#endif +#if defined(POSIX) +#include +#endif +#ifdef WINDOWS #include "Windows.h" #endif @@ -97,10 +102,14 @@ class BaseDevice { #elif defined(WINDOWS) #warning Building for Win32 Devices #include "win32/hasp_win32.h" +#elif defined(POSIX) +#warning Building for Posix Devices +#include "posix/hasp_posix.h" + #else #warning Building for Generic Devices using dev::BaseDevice; extern dev::BaseDevice haspDevice; #endif -#endif \ No newline at end of file +#endif diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp new file mode 100644 index 00000000..b3782006 --- /dev/null +++ b/src/dev/posix/hasp_posix.cpp @@ -0,0 +1,108 @@ +#if defined(POSIX) + +#include + +#include "hasp_posix.h" + +#include "hasp_conf.h" +#include "hasp/hasp_utilities.h" +#include "hasp_debug.h" + +#include "display/monitor.h" + +namespace dev { + +void PosixDevice::reboot() +{} +void PosixDevice::show_info() +{ + LOG_VERBOSE(0, F("Processor : %s"), "unknown"); + LOG_VERBOSE(0, F("CPU freq. : %i MHz"), 0); +} + + +const char* PosixDevice::get_hostname() +{ + return _hostname.c_str(); +} +void PosixDevice::set_hostname(const char* hostname) +{ + _hostname = hostname; +} +const char* PosixDevice::get_core_version() +{ + return "posix"; +} +const char* PosixDevice::get_display_driver() +{ + return "SDL2"; +} + +void PosixDevice::set_backlight_pin(uint8_t pin) +{ + // PosixDevice::backlight_pin = pin; +} + +void PosixDevice::set_backlight_level(uint8_t level) +{ + uint8_t new_level = level >= 0 ? level : 0; + new_level = new_level <= 100 ? new_level : 100; + + if(_backlight_level != new_level) + { + _backlight_level = new_level; + update_backlight(); + } +} + +uint8_t PosixDevice::get_backlight_level() +{ + return _backlight_level; +} + +void PosixDevice::set_backlight_power(bool power) +{ + _backlight_power = power; + update_backlight(); +} + +bool PosixDevice::get_backlight_power() +{ + return _backlight_power != 0; +} + +void PosixDevice::update_backlight() +{ + monitor_backlight(_backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0); +} + +size_t PosixDevice::get_free_max_block() +{ + return 0; +} + +size_t PosixDevice::get_free_heap(void) +{ + return 0; +} + +uint8_t PosixDevice::get_heap_fragmentation() +{ + return 0; +} + +uint16_t PosixDevice::get_cpu_frequency() +{ + return 0; +} + +bool PosixDevice::is_system_pin(uint8_t pin) +{ + return false; +} + +} // namespace dev + +dev::PosixDevice haspDevice; + +#endif // POSIX diff --git a/src/dev/posix/hasp_posix.h b/src/dev/posix/hasp_posix.h new file mode 100644 index 00000000..eebcfd7c --- /dev/null +++ b/src/dev/posix/hasp_posix.h @@ -0,0 +1,76 @@ +/* MIT License - Copyright (c) 2020 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_DEVICE_POSIX_H +#define HASP_DEVICE_POSIX_H + +#include +#include +extern "C" +{ +#include +#include +#include +} + +#include "hasp_conf.h" +#include "../device.h" + +#if defined(POSIX) +static inline void itoa(int i, char *out, int unused_) +{ + (void) unused_; + sprintf(out, "%d", i); +} + +namespace dev { + +class PosixDevice : public BaseDevice { + + public: + PosixDevice() + { + _hostname = "localhost"; + _backlight_power = 1; + _backlight_level = 100; + } + + void reboot() override; + void show_info() override; + + const char* get_hostname(); + void set_hostname(const char*); + const char* get_core_version(); + const char* get_display_driver(); + + void set_backlight_pin(uint8_t pin); + void set_backlight_level(uint8_t val); + uint8_t get_backlight_level(); + void set_backlight_power(bool power); + bool get_backlight_power(); + + size_t get_free_max_block(); + size_t get_free_heap(); + uint8_t get_heap_fragmentation(); + uint16_t get_cpu_frequency(); + + bool is_system_pin(uint8_t pin) override; + + private: + std::string _hostname; + + uint8_t _backlight_pin; + uint8_t _backlight_level; + uint8_t _backlight_power; + + void update_backlight(); +}; + +} // namespace dev + +using dev::PosixDevice; +extern dev::PosixDevice haspDevice; + +#endif // POSIX + +#endif // HASP_DEVICE_POSIX_H diff --git a/src/drv/tft_driver.h b/src/drv/tft_driver.h index c528ede4..0488a2f3 100644 --- a/src/drv/tft_driver.h +++ b/src/drv/tft_driver.h @@ -40,7 +40,7 @@ class BaseTft { #elif defined(STM32F4) #warning Building for STM32F4xx Devices #include "tft_driver_tftespi.h" -#elif defined(WINDOWS) +#elif defined(WINDOWS) || defined(POSIX) #warning Building for Win32 Devices #include "tft_driver_sdl2.h" #else @@ -49,4 +49,4 @@ using dev::BaseTft; extern dev::BaseTft haspTft; #endif -#endif \ No newline at end of file +#endif diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 55eb8770..7569f082 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -14,7 +14,7 @@ #include "../hasp_debug.h" #include "hasp_gui.h" // for screenshot -#if WINDOWS +#if defined(WINDOWS) || defined(POSIX) #include #include #include @@ -878,7 +878,7 @@ void dispatch_reboot(bool saveConfig) LOG_VERBOSE(TAG_MSGR, F("-------------------------------------")); LOG_TRACE(TAG_MSGR, F(D_DISPATCH_REBOOT)); -#if WINDOWS +#if defined(WINDOWS) || defined(POSIX) fflush(stdout); #else Serial.flush(); @@ -1039,4 +1039,4 @@ void everySecond() } } } -#endif \ No newline at end of file +#endif diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 46610f2e..05380bd0 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -597,7 +597,7 @@ void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, con int hasp_parse_json_attributes(lv_obj_t* obj, const JsonObject& doc) { int i = 0; -#ifdef WINDOWS +#if defined(WINDOWS) || defined(POSIX) // String v((char *)0); // v.reserve(64); std::string v; @@ -1043,4 +1043,4 @@ void hasp_object_delete(lv_obj_t* obj) // TODO: delete value_str data for ALL parts my_obj_set_value_str_txt(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, NULL); -} \ No newline at end of file +} diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 97bff5a0..9218ba37 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -10,7 +10,7 @@ #include "lang/lang.h" -#ifndef WINDOWS +#if (!defined(WINDOWS)) && (!defined(POSIX)) #include "ArduinoLog.h" /* ===== Default Event Processors ===== */ diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index de4e2ece..ef76ed04 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -26,7 +26,7 @@ #include "hasp/hasp_dispatch.h" #include "hasp/hasp.h" -#ifdef WINDOWS +#if defined(WINDOWS) || defined(POSIX) #include "display/monitor.h" #include "indev/mouse.h" #endif @@ -152,7 +152,7 @@ void guiSetup(void) const size_t guiVDBsize = 2 * 512u; // 4 KBytes * 2 guiVdbBuffer1 = (lv_color_t*)malloc(sizeof(lv_color_t) * guiVDBsize); -#elif defined(WINDOWS) +#elif defined(WINDOWS) || defined(POSIX) const size_t guiVDBsize = LV_HOR_RES_MAX * 10; static lv_color_t guiVdbBuffer1[guiVDBsize]; /*Declare a buffer for 10 lines*/ @@ -224,7 +224,7 @@ void guiSetup(void) lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; -#if defined(WINDOWS) +#if defined(WINDOWS) || defined(POSIX) indev_drv.read_cb = mouse_read; #else indev_drv.read_cb = drv_touch_read; @@ -256,7 +256,7 @@ void guiSetup(void) lv_indev_set_cursor(mouse_indev, cursor); /*Connect the image object to the driver*/ } -#if !defined(WINDOWS) +#if !(defined(WINDOWS) || defined(POSIX)) drv_touch_init(gui_settings.rotation); // Touch driver #endif @@ -285,7 +285,7 @@ void guiLoop(void) // tick.update(); #endif -#if !defined(WINDOWS) +#if !(defined(WINDOWS) || defined(POSIX)) drv_touch_loop(); // update touch #endif } @@ -623,4 +623,4 @@ void guiTakeScreenshot() LOG_ERROR(TAG_GUI, F("Data sent does not match header size")); } } -#endif \ No newline at end of file +#endif diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 3b014ace..fdb2177f 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -1,7 +1,7 @@ /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#ifndef WINDOWS +#if !(defined(WINDOWS) || defined(POSIX)) #include #include "lvgl.h" @@ -164,4 +164,4 @@ void loop() #endif } -#endif \ No newline at end of file +#endif diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 8ccf9171..1a6af883 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -1,9 +1,14 @@ /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#ifdef WINDOWS - +#if defined(WINDOWS) #include +#endif +#if defined(POSIX) +#include +#include +#endif + #include #include @@ -27,6 +32,7 @@ bool isRunning = 1; uint8_t mainLoopCounter = 0; unsigned long mainLastLoopTime = 0; +#if defined(WINDOWS) // https://gist.github.com/kingseva/a918ec66079a9475f19642ec31276a21 void BindStdHandlesToConsole() { @@ -86,6 +92,7 @@ void InitializeConsoleOutput() // Redirect all standard output streams to the console BindStdHandlesToConsole(); } +#endif void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr) { @@ -121,11 +128,14 @@ void setup() mainLastLoopTime = millis() - 1000; // reset loop counter delay(250); + printf("%s %d\n", __FILE__, __LINE__); } void loop() { + printf("1 \n"); haspLoop(); + printf("2 \n"); mqttLoop(); // debugLoop(); // Console @@ -156,11 +166,11 @@ void loop() } mainLastLoopTime += 1000; } - + printf("loop\n"); // delay(6); } -#ifdef WINDOWS +#if defined(WINDOWS) || defined(POSIX) void usage(char* progName) { @@ -181,18 +191,20 @@ void usage(char* progName) // << " -v | --verbose Verbosity level" << std::endl << std::endl; fflush(stdout); - +#if defined(WINDOWS) static const char s[] = "\n"; DWORD slen = lstrlen(s); WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), s, slen, &slen, NULL); +#endif } int main(int argc, char* argv[]) { bool showhelp = false; int count; - +#ifdef WINDOWS InitializeConsoleOutput(); +#endif haspDevice.show_info(); @@ -221,6 +233,7 @@ int main(int argc, char* argv[]) for(count = 0; count < argc; count++) std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; +#if defined(WINDOWS) SetConsoleCP(65001); // 65001 = UTF-8 static const char s[] = "tränenüberströmt™\n"; DWORD slen = lstrlen(s); @@ -233,7 +246,7 @@ int main(int argc, char* argv[]) if(!WriteConsole(std_out, "Hello World!", 12, NULL, NULL)) { // return 67; } - +#endif for(count = 0; count < argc; count++) { if(argv[count][0] == '-') { @@ -257,24 +270,29 @@ int main(int argc, char* argv[]) if(showhelp) { usage("hasp-lvgl"); + +#if defined(WINDOWS) WriteConsole(std_out, "bye", 3, NULL, NULL); FreeConsole(); +#endif return 0; } // printf("%s %d\n", __FILE__, __LINE__); // fflush(stdout); + printf("pre setup\n"); setup(); + printf("to loop\n"); while(isRunning) { loop(); // std::cout << "HSetup OK\n"; } + printf("endrunning\n"); return 0; } -#endif -#endif \ No newline at end of file +#endif diff --git a/src/mqtt/hasp_mqtt.h b/src/mqtt/hasp_mqtt.h index 18f007ea..030ce8a9 100644 --- a/src/mqtt/hasp_mqtt.h +++ b/src/mqtt/hasp_mqtt.h @@ -9,7 +9,7 @@ #include "hasp_conf.h" -#ifdef WINDOWS +#if defined(WINDOWS) || defined(POSIX) #define __FlashStringHelper char #endif @@ -35,4 +35,4 @@ bool mqttSetConfig(const JsonObject& settings); // String mqttGetNodename(void); // #endif -#endif \ No newline at end of file +#endif diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index 2de8af07..248ca3e4 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -29,7 +29,7 @@ const char FP_MQTT_HA_NAME[] PROGMEM = "name"; const char FP_MQTT_HA_MODEL[] PROGMEM = "mdl"; const char FP_MQTT_HA_MANUFACTURER[] PROGMEM = "mf"; -#ifndef WINDOWS +#if !(defined(WINDOWS) || defined(POSIX)) #include "hal/hasp_hal.h" diff --git a/src/mqtt/hasp_mqtt_paho_async.cpp b/src/mqtt/hasp_mqtt_paho_async.cpp index d8b94f2b..906c1514 100644 --- a/src/mqtt/hasp_mqtt_paho_async.cpp +++ b/src/mqtt/hasp_mqtt_paho_async.cpp @@ -433,4 +433,4 @@ void mqttLoop(){}; void mqttEvery5Seconds(bool wifiIsConnected){}; #endif // USE_PAHO -#endif // USE_MQTT \ No newline at end of file +#endif // USE_MQTT diff --git a/tools/sdl2_build_extra.py b/tools/sdl2_build_extra.py index 34ec79ce..358540f5 100644 --- a/tools/sdl2_build_extra.py +++ b/tools/sdl2_build_extra.py @@ -6,28 +6,4 @@ for e in [ env, projenv ]: if "-m32" in e['CCFLAGS']: e.Append(LINKFLAGS = ["-m32"]) -env.Append( - LINKFLAGS=[ - "-static", - "-static-libgcc", - "-static-libstdc++" - ] -) -# Override unused "upload" to execute compiled binary -from SCons.Script import AlwaysBuild -AlwaysBuild(env.Alias("build", "$BUILD_DIR/${PROGNAME}", "$BUILD_DIR/${PROGNAME}")) - -# Add custom target to explorer -env.AddTarget( - name = "execute", - dependencies = "$BUILD_DIR\${PROGNAME}.exe", - actions = "$BUILD_DIR\${PROGNAME}.exe", -# actions = 'cmd.exe /C "start cmd.exe /C $BUILD_DIR\${PROGNAME}.exe"', - title = "Execute", - description = "Build and execute", - group="General" -) - -#print('=====================================') -#print(env.Dump()) diff --git a/tools/windows_build_extra.py b/tools/windows_build_extra.py new file mode 100644 index 00000000..4f1c18e4 --- /dev/null +++ b/tools/windows_build_extra.py @@ -0,0 +1,25 @@ +env.Append( + LINKFLAGS=[ + "-static", + "-static-libgcc", + "-static-libstdc++" + ] +) + +# Override unused "upload" to execute compiled binary +from SCons.Script import AlwaysBuild +AlwaysBuild(env.Alias("build", "$BUILD_DIR/${PROGNAME}", "$BUILD_DIR/${PROGNAME}")) + +# Add custom target to explorer +env.AddTarget( + name = "execute", + dependencies = "$BUILD_DIR\${PROGNAME}.exe", + actions = "$BUILD_DIR\${PROGNAME}.exe", +# actions = 'cmd.exe /C "start cmd.exe /C $BUILD_DIR\${PROGNAME}.exe"', + title = "Execute", + description = "Build and execute", + group="General" +) + +#print('=====================================') +#print(env.Dump()) diff --git a/user_setups/linux_sdl/emulator_64bits.ini b/user_setups/linux_sdl/emulator_64bits.ini new file mode 100644 index 00000000..a83e7004 --- /dev/null +++ b/user_setups/linux_sdl/emulator_64bits.ini @@ -0,0 +1,92 @@ +[env:emulator_64bits] +platform = native@^1.1.3 +extra_scripts = tools/sdl2_build_extra.py +build_flags = + ${env.build_flags} + ; ----- Monitor + -D TFT_WIDTH=240 + -D TFT_HEIGHT=320 + ; SDL drivers options + ;-D LV_LVGL_H_INCLUDE_SIMPLE + ;-D LV_DRV_NO_CONF + -D LV_MEM_SIZE=262144U ; 256kB lvgl memory + -D USE_MONITOR + -D MONITOR_ZOOM=1 ; can be fractional like 1.5 or 2 + -D USE_MOUSE + -D USE_MOUSEWHEEL + -D USE_KEYBOARD + ; ----- ArduinoJson + -D ARDUINOJSON_DECODE_UNICODE=1 + -D HASP_NUM_PAGES=12 + -D HASP_USE_SPIFFS=0 + -D HASP_USE_LITTLEFS=0 + -D HASP_USE_EEPROM=0 + -D HASP_USE_GPIO=0 + -D HASP_USE_CONFIG=0 ; Standalone application, as library + -D HASP_USE_DEBUG=1 + -D HASP_USE_MQTT=1 + -D MQTT_MAX_PACKET_SIZE=2048 + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO + ;-D LV_LOG_PRINTF=1 + ; Add recursive dirs for hal headers search + -D POSIX + -D PAHO_MQTT_STATIC + -DPAHO_WITH_SSL=TRUE + -DPAHO_BUILD_DOCUMENTATION=FALSE + -DPAHO_BUILD_SAMPLES=FALSE + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_VERBOSE_MAKEFILE=TRUE + ;-D NO_PERSISTENCE + -I.pio/libdeps/emulator_64bits/paho/src + -I.pio/libdeps/emulator_64bits/ArduinoJson/src + -I lib/ArduinoJson/src + -I lib/lv_fs_if + !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" + ; ----- Statically linked libraries -------------------- + -lSDL2 + -lm + -lpthread + +lib_deps = + ${env.lib_deps} + ;lv_drivers@~7.9.0 + ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip + https://github.com/eclipse/paho.mqtt.c.git + bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + +lib_ignore = + paho + AXP192 + ArduinoLog + lv_fs_if + +src_filter = + +<*> + -<*.h> + +<../hal/sdl2> + +<../.pio/libdeps/emulator_64bits/paho/src/*.c> + +<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTAsync.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTAsyncUtils.c> + -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> + -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> + + + - + - + - + - + - + - + - + - + - + + + - + - + - + + + + + + + - + + + +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/emulator_64bits.ini index 67cf5d38..fce20b09 100644 --- a/user_setups/win32/emulator_64bits.ini +++ b/user_setups/win32/emulator_64bits.ini @@ -1,6 +1,8 @@ [env:emulator_64bits] platform = native@^1.1.3 -extra_scripts = tools/sdl2_build_extra.py +extra_scripts = + tools/sdl2_build_extra.py + tools/windows_build_extra.py build_flags = ${env.build_flags} ; ----- Monitor From f4339203b799ab8d0b8c124eae4f8517d1391a6d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 2 Mar 2021 00:23:54 +0100 Subject: [PATCH 131/236] Set backlight payload to lowercase --- src/mqtt/hasp_mqtt_ha.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index 8a8acde5..a7da3795 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -180,7 +180,7 @@ void mqtt_ha_register_connectivity() void mqtt_ha_register_backlight() { - StaticJsonDocument<800> doc; + DynamicJsonDocument doc(1024); char item[16]; snprintf_P(item, sizeof(item), PSTR("backlight")); @@ -188,6 +188,8 @@ void mqtt_ha_register_backlight() deserializeJson(doc, F("{" "\"cmd_t\":\"~command/light\"," "\"stat_t\":\"~state/light\"," + "\"pl_on\":\"on\"," + "\"pl_off\":\"off\"," "\"avty_t\":\"~LWT\"," "\"bri_stat_t\":\"~state/dim\"," "\"bri_cmd_t\":\"~command/dim\"," From 8ece088ce0a9939dd433a10cd5c0f34011d722b8 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 2 Mar 2021 00:24:22 +0100 Subject: [PATCH 132/236] Set moodlight payload to uppercase --- src/hasp/hasp_dispatch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 00af337f..03532a51 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -945,7 +945,7 @@ void dispatch_moodlight(const char* topic, const char* payload) // buffer, sizeof(buffer), // PSTR("{\"state\":\"%s\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"), buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":{\"r\":%u,\"g\":%u,\"b\":%u}}"), - moodlight.power ? "on" : "off", moodlight.r, moodlight.g, moodlight.b); + moodlight.power ? "ON" : "OFF", moodlight.r, moodlight.g, moodlight.b); dispatch_state_subtopic(out_topic, buffer); } @@ -1000,9 +1000,9 @@ void dispatch_reboot(bool saveConfig) void dispatch_current_state() { - dispatch_output_current_page(); dispatch_output_statusupdate(NULL, NULL); dispatch_output_idle_state(hasp_sleep_state); + dispatch_output_current_page(); } /******************************************* Command Wrapper Functions *********************************/ From 80ed53e0625d21ab227a07e986902c0f97a3360e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 3 Mar 2021 18:18:50 +0100 Subject: [PATCH 133/236] remove hasp_drv_display --- src/drv/hasp_drv_display.cpp | 50 ++++++++++++++++++------------------ src/drv/hasp_drv_display.h | 2 +- src/drv/hasp_drv_touch.cpp | 3 ++- src/drv/tft_driver_tftespi.h | 4 +-- src/drv/tft_espi_drv.cpp | 32 ++++++++++++++++++++++- src/hasp_gui.cpp | 7 ++--- 6 files changed, 65 insertions(+), 33 deletions(-) diff --git a/src/drv/hasp_drv_display.cpp b/src/drv/hasp_drv_display.cpp index c0b569ed..5cf555da 100644 --- a/src/drv/hasp_drv_display.cpp +++ b/src/drv/hasp_drv_display.cpp @@ -1,31 +1,31 @@ /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#include "hasp_drv_display.h" -#include "tft_espi_drv.h" -//#include "fsmc_ili9341.h" +// #include "hasp_drv_display.h" +// #include "tft_espi_drv.h" +// //#include "fsmc_ili9341.h" -void drv_display_init(lv_disp_drv_t* disp_drv, uint8_t rotation, bool invert_display) -{ - /* TFT init */ -#if defined(USE_FSMC) - fsmc_ili9341_init(rotation, invert_display); - disp_drv->flush_cb = fsmc_ili9341_flush; // Normal callback when flushing - // xpt2046_init(rotation); -#else - tft_espi_init(rotation, invert_display); - disp_drv->flush_cb = tft_espi_flush; // Normal callback when flushing -#endif -} +// void drv_display_init(lv_disp_drv_t* disp_drv, uint8_t rotation, bool invert_display) +// { +// /* TFT init */ +// #if defined(USE_FSMC) +// fsmc_ili9341_init(rotation, invert_display); +// disp_drv->flush_cb = fsmc_ili9341_flush; // Normal callback when flushing +// // xpt2046_init(rotation); +// #else +// tft_espi_init(rotation, invert_display); +// disp_drv->flush_cb = tft_espi_flush; // Normal callback when flushing +// #endif +// } -/* Callback used for screenshots only: */ +// /* Callback used for screenshots only: */ -/* indirect callback to flush screenshot data to the screen */ -void drv_display_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) -{ -#if defined(USE_FSMC) - fsmc_ili9341_flush(disp, area, color_p); -#else - tft_espi_flush(disp, area, color_p); -#endif -} \ No newline at end of file +// /* indirect callback to flush screenshot data to the screen */ +// void drv_display_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) +// { +// #if defined(USE_FSMC) +// fsmc_ili9341_flush(disp, area, color_p); +// #else +// tft_espi_flush(disp, area, color_p); +// #endif +// } \ No newline at end of file diff --git a/src/drv/hasp_drv_display.h b/src/drv/hasp_drv_display.h index 78bdf4c2..1a9b0a37 100644 --- a/src/drv/hasp_drv_display.h +++ b/src/drv/hasp_drv_display.h @@ -1,7 +1,7 @@ /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#ifndef HASP_DRV_DISPLAY_H +#if 0 // ndef HASP_DRV_DISPLAY_H #define HASP_DRV_DISPLAY_H #include "lvgl.h" diff --git a/src/drv/hasp_drv_touch.cpp b/src/drv/hasp_drv_touch.cpp index 446018b6..da3a80ee 100644 --- a/src/drv/hasp_drv_touch.cpp +++ b/src/drv/hasp_drv_touch.cpp @@ -3,6 +3,7 @@ #include "hasp_drv_touch.h" #include "hasp/hasp.h" +#include "drv/tft_driver.h" #include "lvgl.h" #if TOUCH_DRIVER == 2046 @@ -74,7 +75,7 @@ static inline bool drv_touchpad_getXY(int16_t* touchX, int16_t* touchY) int16_t normal_x; int16_t normal_y; #if TOUCH_DRIVER == 2046 // XPT2046 Resistive touch panel driver - touched = tft_espi_get_touch(&normal_x, &normal_y, 300u); + touched = haspTft.tft.getTouch((uint16_t*)&normal_x, (uint16_t*)&normal_y, 20); #elif TOUCH_DRIVER == 0x2046B touched = XPT2046_getXY(&normal_x, &normal_y, true); diff --git a/src/drv/tft_driver_tftespi.h b/src/drv/tft_driver_tftespi.h index 63931c0a..40da4274 100644 --- a/src/drv/tft_driver_tftespi.h +++ b/src/drv/tft_driver_tftespi.h @@ -23,6 +23,8 @@ namespace dev { class TftEspi : BaseTft { public: + TFT_eSPI tft; + void init(int w, int h); void show_info(); void splashscreen(); @@ -34,8 +36,6 @@ class TftEspi : BaseTft { bool is_driver_pin(uint8_t pin); private: - TFT_eSPI tft; - void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset) { if(x_offset != 0) { diff --git a/src/drv/tft_espi_drv.cpp b/src/drv/tft_espi_drv.cpp index d005a380..9fdc66c6 100644 --- a/src/drv/tft_espi_drv.cpp +++ b/src/drv/tft_espi_drv.cpp @@ -8,12 +8,42 @@ #include "hal/hasp_hal.h" // for halGpioName() #include "dev/device.h" +#include "drv/tft_driver.h" #include "tft_espi_drv.h" #include "ArduinoLog.h" #include "hasp_macro.h" -#if USE_TFT_ESPI != 0 +#if defined(TOUCH_CS) + +void tft_espi_calibrate(uint16_t* calData) +{ + haspTft.tft.fillScreen(TFT_BLACK); + haspTft.tft.setCursor(20, 0); + haspTft.tft.setTextFont(1); + haspTft.tft.setTextSize(1); + haspTft.tft.setTextColor(TFT_WHITE, TFT_BLACK); + + // tft.println(PSTR("Touch corners as indicated")); + + haspTft.tft.setTextFont(1); + delay(500); + haspTft.tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15); + haspTft.tft.setTouch(calData); +} + +void tft_espi_set_touch(uint16_t* calData) +{ + haspTft.tft.setTouch(calData); +} + +bool tft_espi_get_touch(int16_t* touchX, int16_t* touchY, uint16_t threshold) +{ + return haspTft.tft.getTouch((uint16_t*)touchX, (uint16_t*)touchY, threshold); +} +#endif + +#if 0 // USE_TFT_ESPI != 0 #include #include "TFT_eSPI.h" diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 0a9ef0b0..a95a48b3 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -15,8 +15,9 @@ #include "drv/tft_driver.h" #include "dev/device.h" -#include "drv/hasp_drv_display.h" +//#include "drv/hasp_drv_display.h" #include "drv/hasp_drv_touch.h" +#include "drv/tft_espi_drv.h" #include "hasp_debug.h" #include "hasp_config.h" @@ -196,7 +197,7 @@ void guiSetup(void) // _lv_fs_init(); // lvgl File System -- not neaded, it done in lv_init() when LV_USE_FILESYSTEM is set LOG_VERBOSE(TAG_LVGL, F("Filesystem : Enabled")); lv_fs_if_init(); // auxilary file system drivers - filesystem_list_path("S:/"); + filesystem_list_path("S:/fs/"); #else LOG_VERBOSE(TAG_LVGL, F("Filesystem : Disabled")); #endif @@ -626,4 +627,4 @@ void guiTakeScreenshot() LOG_ERROR(TAG_GUI, F("Data sent does not match header size")); } } -#endif \ No newline at end of file +#endif From 719f0c403898b9fdfbfb961c32d904a4a248a10f Mon Sep 17 00:00:00 2001 From: fvanroie Date: Thu, 4 Mar 2021 20:37:42 +0100 Subject: [PATCH 134/236] Include .vscode/extensions.json --- .gitignore | 4 +++- .vscode/extensions.json | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .vscode/extensions.json diff --git a/.gitignore b/.gitignore index 756b6d8b..43182a35 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,9 @@ build_output/firmware/*.exe *.bin ## Visual Studio Code specific ###### -.vscode +!.vscode +.vscode/* +!.vscode/extensions.json .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json .vscode/launch.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..4ffe4f0c --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "platformio.platformio-ide","ms-vscode.cpptools" + ] +} \ No newline at end of file From 73ec50af2748dc4a6b7e7f826f1e29dadaa57957 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 15:36:43 +0100 Subject: [PATCH 135/236] Formatting --- .vscode/extensions.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4ffe4f0c..d304a5ef 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,8 @@ -{ - "recommendations": [ - "platformio.platformio-ide","ms-vscode.cpptools" - ] -} \ No newline at end of file +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "ms-vscode.cpptools", + "platformio.platformio-ide" + ] +} From 7591ce4418f0c9fab2b062cb3c4b22f6b4ed7d06 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 16:43:58 +0100 Subject: [PATCH 136/236] Add linux_sdl environment --- include/lv_conf_v7.h | 2 +- src/{main_windows.cpp => main_sdl2.cpp} | 0 tools/linux_build_extra.py | 19 +++++++++++++++ ...ulator_64bits.ini => linux_sdl_64bits.ini} | 24 ++++++++++--------- 4 files changed, 33 insertions(+), 12 deletions(-) rename src/{main_windows.cpp => main_sdl2.cpp} (100%) create mode 100644 tools/linux_build_extra.py rename user_setups/linux_sdl/{emulator_64bits.ini => linux_sdl_64bits.ini} (75%) diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index 68955047..99166358 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -183,7 +183,7 @@ typedef void* lv_group_user_data_t; typedef void* lv_fs_drv_user_data_t; /*File system interface*/ -#define LV_USE_FS_IF 1 +#define LV_USE_FS_IF 0 #if LV_USE_FS_IF # define LV_FS_IF_FATFS '\0' #if defined(STM32F4xx) // || defined(ARDUINO_ARCH_ESP8266) diff --git a/src/main_windows.cpp b/src/main_sdl2.cpp similarity index 100% rename from src/main_windows.cpp rename to src/main_sdl2.cpp diff --git a/tools/linux_build_extra.py b/tools/linux_build_extra.py new file mode 100644 index 00000000..c849af5c --- /dev/null +++ b/tools/linux_build_extra.py @@ -0,0 +1,19 @@ +Import("env", "projenv") + +# Override unused "upload" to execute compiled binary +from SCons.Script import AlwaysBuild +AlwaysBuild(env.Alias("build", "$BUILD_DIR/${PROGNAME}", "$BUILD_DIR/${PROGNAME}")) + +# Add custom target to explorer +env.AddTarget( + name = "execute", + dependencies = "$BUILD_DIR/${PROGNAME}", + actions = "$BUILD_DIR/${PROGNAME}", +# actions = 'cmd.exe /C "start cmd.exe /C $BUILD_DIR\${PROGNAME}.exe"', + title = "Execute", + description = "Build and execute", + group="General" +) + +#print('=====================================') +#print(env.Dump()) diff --git a/user_setups/linux_sdl/emulator_64bits.ini b/user_setups/linux_sdl/linux_sdl_64bits.ini similarity index 75% rename from user_setups/linux_sdl/emulator_64bits.ini rename to user_setups/linux_sdl/linux_sdl_64bits.ini index a83e7004..ac81d624 100644 --- a/user_setups/linux_sdl/emulator_64bits.ini +++ b/user_setups/linux_sdl/linux_sdl_64bits.ini @@ -1,6 +1,8 @@ -[env:emulator_64bits] +[env:linux_sdl_64bits] platform = native@^1.1.3 -extra_scripts = tools/sdl2_build_extra.py +extra_scripts = + tools/sdl2_build_extra.py + tools/linux_build_extra.py build_flags = ${env.build_flags} ; ----- Monitor @@ -37,8 +39,8 @@ build_flags = -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE ;-D NO_PERSISTENCE - -I.pio/libdeps/emulator_64bits/paho/src - -I.pio/libdeps/emulator_64bits/ArduinoJson/src + -I.pio/libdeps/linux_sdl_64bits/paho/src + -I.pio/libdeps/linux_sdl_64bits/ArduinoJson/src -I lib/ArduinoJson/src -I lib/lv_fs_if !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" @@ -64,12 +66,12 @@ src_filter = +<*> -<*.h> +<../hal/sdl2> - +<../.pio/libdeps/emulator_64bits/paho/src/*.c> - +<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTAsync.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTAsyncUtils.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> - -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> + +<../.pio/libdeps/linux_sdl_64bits/paho/src/*.c> + +<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTClient.c> + -<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTAsync.c> + -<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTAsyncUtils.c> + -<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTVersion.c> + -<../.pio/libdeps/linux_sdl_64bits/paho/src/SSLSocket.c> + - - @@ -89,4 +91,4 @@ src_filter = + - + - +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> + +<../.pio/libdeps/linux_sdl_64bits/ArduinoJson/src/ArduinoJson.h> From 62d26eb1898469a391f86474de28e93a8bba2d6f Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 18:04:20 +0100 Subject: [PATCH 137/236] Remove debug messages --- src/main_sdl2.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main_sdl2.cpp b/src/main_sdl2.cpp index 8c0be57a..13f926e6 100644 --- a/src/main_sdl2.cpp +++ b/src/main_sdl2.cpp @@ -133,9 +133,7 @@ void setup() void loop() { - printf("1 \n"); haspLoop(); - printf("2 \n"); mqttLoop(); // debugLoop(); // Console @@ -166,7 +164,6 @@ void loop() } mainLastLoopTime += 1000; } - printf("loop\n"); // delay(6); } From 549728d30b3792e254435ebe22ef719d32423443 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 19:38:33 +0100 Subject: [PATCH 138/236] Move platform #if to top of the file --- src/main_sdl2.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main_sdl2.cpp b/src/main_sdl2.cpp index 13f926e6..302fcf29 100644 --- a/src/main_sdl2.cpp +++ b/src/main_sdl2.cpp @@ -1,6 +1,8 @@ /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ +#if defined(WINDOWS) || defined(POSIX) + #if defined(WINDOWS) #include #endif @@ -167,7 +169,6 @@ void loop() // delay(6); } -#if defined(WINDOWS) || defined(POSIX) void usage(char* progName) { From 0aa869d5e252b269f3dc33331779d909135f4463 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 5 Mar 2021 19:43:20 +0100 Subject: [PATCH 139/236] Add linux_sdl_64bits --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7797036f..966575d6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,7 +37,7 @@ jobs: run: | cat platformio_override.ini - name: Run PlatformIO - run: pio run -e d1-mini-esp32_ili9341 -e lanbon_l8 -e wt32-sc01 -e d1-mini-esp8266_ili9341 + run: pio run -e d1-mini-esp32_ili9341 -e lanbon_l8 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits - name: Upload output file uses: actions/upload-artifact@v2 with: From 0e56f4e213cbae8e2d9bd613b04bd7ce610f57de Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 19:50:41 +0100 Subject: [PATCH 140/236] Rename build workflow --- .github/workflows/{test.yaml => build.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{test.yaml => build.yaml} (100%) diff --git a/.github/workflows/test.yaml b/.github/workflows/build.yaml similarity index 100% rename from .github/workflows/test.yaml rename to .github/workflows/build.yaml From d995c719f4e5744c5fa1da034edaf7df3df1877c Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 19:55:00 +0100 Subject: [PATCH 141/236] Enable linux platforms --- .github/workflows/build.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 966575d6..2ec50105 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -30,6 +30,9 @@ jobs: - name: Enable ESP platforms from platformio_override-template.ini run: | sed 's/; user_setups\/esp/user_setups\/esp/g' platformio_override-template.ini > platformio_override.ini + - name: Enable Linux platform from platformio_override.ini + run: | + sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini - name: List all files in current folder run: | ls -la From 8028861729915378a906a97166c89211b091e9af Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 20:03:59 +0100 Subject: [PATCH 142/236] Add user_setups/linux_sdl --- platformio_override-template.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platformio_override-template.ini b/platformio_override-template.ini index a0dcdf65..237ee3c7 100644 --- a/platformio_override-template.ini +++ b/platformio_override-template.ini @@ -10,7 +10,8 @@ extra_configs = ; user_setups/esp8266/*.ini ; user_setups/stm32f4xx/*.ini ; user_setups/win32/*.ini - + ; user_setups/linux_sdl/*.ini + [override] ; -- Hasp config options -------------------------------------- build_flags = From 7875e9af96b7b965cedda2105c62e788880d071e Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 20:25:00 +0100 Subject: [PATCH 143/236] Add libsdl2-dev --- .github/workflows/build.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2ec50105..2a5c6eb2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -33,6 +33,10 @@ jobs: - name: Enable Linux platform from platformio_override.ini run: | sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini + - name: Install PlatformIO + run: | + apt update + apt install libsdl2-dev - name: List all files in current folder run: | ls -la From b013481cebfaa1c2ee1b087dae7c8d8e6631333f Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 20:29:04 +0100 Subject: [PATCH 144/236] Add Install SDL2 library --- .github/workflows/build.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2a5c6eb2..7ed8ed1e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -33,10 +33,10 @@ jobs: - name: Enable Linux platform from platformio_override.ini run: | sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini - - name: Install PlatformIO + - name: Install SDL2 library run: | - apt update - apt install libsdl2-dev + sudo apt-get update + sudo apt-get install libsdl2-dev - name: List all files in current folder run: | ls -la From 82061a9ecdecae675c09adaf79058eda1a29b4c9 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 20:40:46 +0100 Subject: [PATCH 145/236] Inlude MQTTClient.h --- user_setups/linux_sdl/linux_sdl_64bits.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/user_setups/linux_sdl/linux_sdl_64bits.ini b/user_setups/linux_sdl/linux_sdl_64bits.ini index ac81d624..a753886b 100644 --- a/user_setups/linux_sdl/linux_sdl_64bits.ini +++ b/user_setups/linux_sdl/linux_sdl_64bits.ini @@ -67,6 +67,7 @@ src_filter = -<*.h> +<../hal/sdl2> +<../.pio/libdeps/linux_sdl_64bits/paho/src/*.c> + +<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTClient.h> +<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTClient.c> -<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTAsync.c> -<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTAsyncUtils.c> From d12bab2b83d889e89ed0022aa752943139d42fd3 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 21:04:09 +0100 Subject: [PATCH 146/236] Fix build error in linux if paho/src isn't there --- .github/workflows/build.yaml | 1 + user_setups/linux_sdl/linux_sdl_64bits.ini | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7ed8ed1e..85e4c79e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -33,6 +33,7 @@ jobs: - name: Enable Linux platform from platformio_override.ini run: | sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini + mkdir .pio/libdeps/linux_sdl_64bits/paho/src - name: Install SDL2 library run: | sudo apt-get update diff --git a/user_setups/linux_sdl/linux_sdl_64bits.ini b/user_setups/linux_sdl/linux_sdl_64bits.ini index a753886b..ac81d624 100644 --- a/user_setups/linux_sdl/linux_sdl_64bits.ini +++ b/user_setups/linux_sdl/linux_sdl_64bits.ini @@ -67,7 +67,6 @@ src_filter = -<*.h> +<../hal/sdl2> +<../.pio/libdeps/linux_sdl_64bits/paho/src/*.c> - +<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTClient.h> +<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTClient.c> -<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTAsync.c> -<../.pio/libdeps/linux_sdl_64bits/paho/src/MQTTAsyncUtils.c> From 20ac36f727693ad578c1b0e7904202fe510c6d3b Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 21:07:49 +0100 Subject: [PATCH 147/236] Add -p to mkdir --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 85e4c79e..f554432f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -33,7 +33,7 @@ jobs: - name: Enable Linux platform from platformio_override.ini run: | sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini - mkdir .pio/libdeps/linux_sdl_64bits/paho/src + mkdir -p .pio/libdeps/linux_sdl_64bits/paho/src - name: Install SDL2 library run: | sudo apt-get update From 157c5e944906dcabed9ede695a6ae2a9d8843ad9 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 23:01:25 +0100 Subject: [PATCH 148/236] Use the zero terminated copy as payload --- src/mqtt/hasp_mqtt_paho_single.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index c2afbe56..5acf5de9 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -186,7 +186,7 @@ int msgarrvd(void* context, char* topicName, int topicLen, MQTTClient_message* m memcpy(msg, (char*)message->payload, message->payloadlen); msg[message->payloadlen] = '\0'; - mqtt_message_cb(topicName, (char*)message->payload, message->payloadlen); + mqtt_message_cb(topicName, msg, message->payloadlen); MQTTClient_freeMessage(&message); MQTTClient_free(topicName); From 3fa56fd862417ea8589fee4609227dfbcaafd3e0 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 5 Mar 2021 23:15:10 +0100 Subject: [PATCH 149/236] Update action name --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f554432f..edf5c834 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,4 +1,4 @@ -name: PlatformIO CI +name: Build test on: [push] From 28c41ac8894e25029d6f002ab43de70ab9586009 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Sat, 6 Mar 2021 00:05:58 +0100 Subject: [PATCH 150/236] Update action name --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index edf5c834..fa495979 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,4 +1,4 @@ -name: Build test +name: Build 0.4.0-dev branch on: [push] From aeb9c03bd10441b04e1ab95e9b1352fdd9e0bf70 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 6 Mar 2021 00:53:35 +0100 Subject: [PATCH 151/236] Small code improvements --- .vscode/extensions.json | 7 +++++-- src/hasp/hasp_dispatch.h | 2 +- src/sys/gpio/hasp_gpio.cpp | 23 ++++++++++++++++++----- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4ffe4f0c..9a44568a 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,8 @@ { + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format "recommendations": [ - "platformio.platformio-ide","ms-vscode.cpptools" + "ms-vscode.cpptools", + "platformio.platformio-ide" ] -} \ No newline at end of file +} diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index ac0e591b..193ed7c2 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -54,7 +54,7 @@ void dispatch_page_prev(); void dispatch_dim(const char* level); void dispatch_backlight(const char* payload); -void dispatch_web_update(const char* espOtaUrl); +void dispatch_web_update(const char*, const char* espOtaUrl); void dispatch_reboot(bool saveConfig); void dispatch_output_idle_state(uint8_t state); diff --git a/src/sys/gpio/hasp_gpio.cpp b/src/sys/gpio/hasp_gpio.cpp index 21caa060..b4be2746 100644 --- a/src/sys/gpio/hasp_gpio.cpp +++ b/src/sys/gpio/hasp_gpio.cpp @@ -294,12 +294,21 @@ void gpio_set_normalized_value(hasp_gpio_config_t gpio, uint16_t state) case HASP_GPIO_LED_R: case HASP_GPIO_LED_G: case HASP_GPIO_LED_B: +#if defined(ARDUINO_ARCH_ESP32) + gpio.val = map(state, 0, 0xFFFFU, 0, 4095); + ledcWrite(gpio.group, gpio.val); // ledChannel and value +#else + gpio.val = map(state, 0, 0xFFFFU, 0, 1023); + analogWrite(gpio.pin, gpio.val); +#endif + break; case HASP_GPIO_PWM: #if defined(ARDUINO_ARCH_ESP32) gpio.val = map(state, 0, 0xFFFFU, 0, 4095); ledcWrite(gpio.group, gpio.val); // ledChannel and value #else - analogWrite(gpio.pin, map(state, 0, 0xFFFFU, 0, 1023)); + gpio.val = map(state, 0, 0xFFFFU, 0, 1023); + analogWrite(gpio.pin, gpio.val); #endif break; case HASP_GPIO_LED_INVERTED: @@ -311,7 +320,8 @@ void gpio_set_normalized_value(hasp_gpio_config_t gpio, uint16_t state) gpio.val = map(0xFFFFU - state, 0, 0xFFFFU, 0, 4095); ledcWrite(gpio.group, gpio.val); // ledChannel and value #else - analogWrite(gpio.pin, map(0xFFFFU - state, 0, 0xFFFFU, 0, 1023)); + gpio.val = map(0xFFFFU - state, 0, 0xFFFFU, 0, 1023); + analogWrite(gpio.pin, gpio.val); #endif break; @@ -342,19 +352,22 @@ void gpio_set_normalized_group_value(uint8_t groupid, uint16_t state) void gpio_set_moodlight(uint8_t r, uint8_t g, uint8_t b) { + // uint16_t max_level = power == 0 ? 0 : map(brightness, 0, 0xFF, 0, 0xFFFFU); + uint16_t max_level = 0xFFFFU; + for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) { switch(gpioConfig[i].type) { case HASP_GPIO_LED_R: case HASP_GPIO_LED_R_INVERTED: - gpio_set_normalized_value(gpioConfig[i], map(r, 0, 0xFF, 0, 0xFFFFU)); + gpio_set_normalized_value(gpioConfig[i], map(r, 0, 0xFF, 0, max_level)); break; case HASP_GPIO_LED_G: case HASP_GPIO_LED_G_INVERTED: - gpio_set_normalized_value(gpioConfig[i], map(g, 0, 0xFF, 0, 0xFFFFU)); + gpio_set_normalized_value(gpioConfig[i], map(g, 0, 0xFF, 0, max_level)); break; case HASP_GPIO_LED_B: case HASP_GPIO_LED_B_INVERTED: - gpio_set_normalized_value(gpioConfig[i], map(b, 0, 0xFF, 0, 0xFFFFU)); + gpio_set_normalized_value(gpioConfig[i], map(b, 0, 0xFF, 0, max_level)); break; } } From f4ad8ed3d854a3cd6d06ed9756b6c5f2d2ae6542 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 6 Mar 2021 00:55:01 +0100 Subject: [PATCH 152/236] Enable updates from http server --- src/sys/svc/hasp_http.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index b8c51533..071eee2f 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1795,6 +1795,12 @@ void webHandleFirmware() // "name='filename' accept='.spiffs'>"); // httpMessage += F("

"); + httpMessage += F("
"); + httpMessage += F("
Update ESP from URL"); + httpMessage += F("


"); + httpMessage += FPSTR(MAIN_MENU_BUTTON); webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); @@ -1807,6 +1813,9 @@ void webHandleFirmware() //////////////////////////////////////////////////////////////////////////////////////////////////// void httpHandleEspFirmware() { // http://plate01/espfirmware + char url[4]; + memcpy_P(url, PSTR("url"), 4); + if(!httpIsAuthenticated(F("espfirmware"))) return; { @@ -1817,7 +1826,7 @@ void httpHandleEspFirmware() httpMessage += F("
"); httpMessage += F("

ESP update

Updating ESP firmware from: "); - httpMessage += webServer.arg("espFirmware"); + httpMessage += webServer.arg(url); webSendPage(haspDevice.get_hostname(), httpMessage.length(), true); webServer.sendContent(httpMessage); @@ -1825,8 +1834,8 @@ void httpHandleEspFirmware() } webSendFooter(); - LOG_TRACE(TAG_HTTP, F("Attempting ESP firmware update from: %s"), webServer.arg("espFirmware").c_str()); - // espStartOta(webServer.arg("espFirmware")); + LOG_TRACE(TAG_HTTP, F("Attempting ESP firmware update from: %s"), webServer.arg(url).c_str()); + dispatch_web_update(NULL, webServer.arg(url).c_str()); } //////////////////////////////////////////////////////////////////////////////////////////////////// From 9ed1a6f8e568cbdf694cc70bed0118a5f106dba9 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Sat, 6 Mar 2021 11:39:08 +0000 Subject: [PATCH 153/236] add support for darwin (MacOS) --- src/dev/posix/hasp_posix.cpp | 2 + src/drv/tft_driver_sdl2.h | 4 +- tools/osx_build_extra.py | 15 ++++ tools/osx_build_script.py | 38 ++++++++ user_setups/darwin_sdl/darwin_sdl_64bits.ini | 95 ++++++++++++++++++++ 5 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 tools/osx_build_extra.py create mode 100644 tools/osx_build_script.py create mode 100644 user_setups/darwin_sdl/darwin_sdl_64bits.ini diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index b3782006..52604f2a 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -73,7 +73,9 @@ bool PosixDevice::get_backlight_power() void PosixDevice::update_backlight() { +#ifndef TARGET_OS_MAC monitor_backlight(_backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0); +#endif } size_t PosixDevice::get_free_max_block() diff --git a/src/drv/tft_driver_sdl2.h b/src/drv/tft_driver_sdl2.h index b3633f86..e917ee74 100644 --- a/src/drv/tft_driver_sdl2.h +++ b/src/drv/tft_driver_sdl2.h @@ -49,7 +49,9 @@ class TftSdl2 : BaseTft { /* Add a display * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ monitor_init(); +#ifndef TARGET_OS_MAC monitor_title(haspDevice.get_hostname()); +#endif /* Add the mouse as input device * Use the 'mouse' driver which reads the PC's mouse*/ @@ -94,4 +96,4 @@ class TftSdl2 : BaseTft { using dev::TftSdl2; extern dev::TftSdl2 haspTft; -#endif \ No newline at end of file +#endif diff --git a/tools/osx_build_extra.py b/tools/osx_build_extra.py new file mode 100644 index 00000000..e02f2e42 --- /dev/null +++ b/tools/osx_build_extra.py @@ -0,0 +1,15 @@ +Import("env") + +env.Append( + BUILD_FLAGS=[ + "-I/usr/local/include", + "-L/usr/local/lib", + "-DTARGET_OS_MAC=1"], +) + +env.Replace(CC="gcc-10", CXX="g++-10") + +env.Replace(BUILD_SCRIPT="tools/osx_build_script.py") + +#print('=====================================') +print(env.Dump()) diff --git a/tools/osx_build_script.py b/tools/osx_build_script.py new file mode 100644 index 00000000..b1fbe229 --- /dev/null +++ b/tools/osx_build_script.py @@ -0,0 +1,38 @@ +""" + Builder for native platform +""" + +from SCons.Script import AlwaysBuild, Default, DefaultEnvironment + +env = DefaultEnvironment() + +# Preserve C and C++ build flags +backup_cflags = env.get("CFLAGS", []) +backup_cxxflags = env.get("CXXFLAGS", []) + +# Scan for GCC compiler +env.Tool("gcc") +env.Tool("g++") + +# Restore C/C++ build flags as they were overridden by env.Tool +env.Append(CFLAGS=backup_cflags, CXXFLAGS=backup_cxxflags) + +# +# Target: Build executable program +# + +target_bin = env.BuildProgram() + +# +# Target: Print binary size +# + +target_size = env.Alias("size", target_bin, env.VerboseAction( + "$SIZEPRINTCMD", "Calculating size $SOURCE")) +AlwaysBuild(target_size) + +# +# Default targets +# + +Default([target_bin]) diff --git a/user_setups/darwin_sdl/darwin_sdl_64bits.ini b/user_setups/darwin_sdl/darwin_sdl_64bits.ini new file mode 100644 index 00000000..5953df26 --- /dev/null +++ b/user_setups/darwin_sdl/darwin_sdl_64bits.ini @@ -0,0 +1,95 @@ +[env:darwin_sdl_64bits] +lib_archive = false +platform = native@^1.1.3 +extra_scripts = + pre:tools/osx_build_extra.py + tools/linux_build_extra.py +build_flags = + ${env.build_flags} + ; ----- Monitor + -D TFT_WIDTH=240 + -D TFT_HEIGHT=320 + ; SDL drivers options + ;-D LV_LVGL_H_INCLUDE_SIMPLE + ;-D LV_DRV_NO_CONF + -D LV_MEM_SIZE=262144U ; 256kB lvgl memory + -D USE_MONITOR + -D MONITOR_ZOOM=1 ; can be fractional like 1.5 or 2 + -D USE_MOUSE + -D USE_MOUSEWHEEL + -D USE_KEYBOARD + ; ----- ArduinoJson + -D ARDUINOJSON_DECODE_UNICODE=1 + -D HASP_NUM_PAGES=12 + -D HASP_USE_SPIFFS=0 + -D HASP_USE_LITTLEFS=0 + -D HASP_USE_EEPROM=0 + -D HASP_USE_GPIO=0 + -D HASP_USE_CONFIG=0 ; Standalone application, as library + -D HASP_USE_DEBUG=1 + -D HASP_USE_MQTT=1 + -D MQTT_MAX_PACKET_SIZE=2048 + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO + ;-D LV_LOG_PRINTF=1 + ; Add recursive dirs for hal headers search + -D POSIX + -D PAHO_MQTT_STATIC + -DPAHO_WITH_SSL=TRUE + -DPAHO_BUILD_DOCUMENTATION=FALSE + -DPAHO_BUILD_SAMPLES=FALSE + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_VERBOSE_MAKEFILE=TRUE + ;-D NO_PERSISTENCE + -I.pio/libdeps/darwin_sdl_64bits/paho/src + -I.pio/libdeps/darwin_sdl_64bits/ArduinoJson/src + -I lib/ArduinoJson/src + -I lib/lv_fs_if + !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" + ; ----- Statically linked libraries -------------------- + -lSDL2 + -lm + -lpthread + +lib_deps = + ${env.lib_deps} + lv_drivers@~7.9.1 + ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip + https://github.com/eclipse/paho.mqtt.c.git + bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + +lib_ignore = + paho + AXP192 + ArduinoLog + lv_fs_if + +src_filter = + +<*> + -<*.h> + +<../hal/sdl2> + +<../.pio/libdeps/darwin_sdl_64bits/paho/src/*.c> + +<../.pio/libdeps/darwin_sdl_64bits/paho/src/MQTTClient.c> + -<../.pio/libdeps/darwin_sdl_64bits/paho/src/MQTTAsync.c> + -<../.pio/libdeps/darwin_sdl_64bits/paho/src/MQTTAsyncUtils.c> + -<../.pio/libdeps/darwin_sdl_64bits/paho/src/MQTTVersion.c> + -<../.pio/libdeps/darwin_sdl_64bits/paho/src/SSLSocket.c> + + + - + - + - + - + - + - + - + - + - + + + - + - + - + + + + + + + - + + + +<../.pio/libdeps/darwin_sdl_64bits/ArduinoJson/src/ArduinoJson.h> From 4ff22c622ecde9624f32a9ff619b6c7f9a82cbe8 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Sat, 6 Mar 2021 11:43:04 +0000 Subject: [PATCH 154/236] remove print --- tools/osx_build_extra.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/osx_build_extra.py b/tools/osx_build_extra.py index e02f2e42..18617dd6 100644 --- a/tools/osx_build_extra.py +++ b/tools/osx_build_extra.py @@ -12,4 +12,4 @@ env.Replace(CC="gcc-10", CXX="g++-10") env.Replace(BUILD_SCRIPT="tools/osx_build_script.py") #print('=====================================') -print(env.Dump()) +#print(env.Dump()) From 902431332e19f489c3d6d3a18176adb4f26ff620 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Sat, 6 Mar 2021 11:46:09 +0000 Subject: [PATCH 155/236] move to ini --- tools/osx_build_extra.py | 7 ------- user_setups/darwin_sdl/darwin_sdl_64bits.ini | 4 ++++ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/osx_build_extra.py b/tools/osx_build_extra.py index 18617dd6..3f445946 100644 --- a/tools/osx_build_extra.py +++ b/tools/osx_build_extra.py @@ -1,12 +1,5 @@ Import("env") -env.Append( - BUILD_FLAGS=[ - "-I/usr/local/include", - "-L/usr/local/lib", - "-DTARGET_OS_MAC=1"], -) - env.Replace(CC="gcc-10", CXX="g++-10") env.Replace(BUILD_SCRIPT="tools/osx_build_script.py") diff --git a/user_setups/darwin_sdl/darwin_sdl_64bits.ini b/user_setups/darwin_sdl/darwin_sdl_64bits.ini index 5953df26..08bda544 100644 --- a/user_setups/darwin_sdl/darwin_sdl_64bits.ini +++ b/user_setups/darwin_sdl/darwin_sdl_64bits.ini @@ -49,6 +49,10 @@ build_flags = -lSDL2 -lm -lpthread + ; MacOS with Homebrew + -I/usr/local/include + -L/usr/local/lib + -DTARGET_OS_MAC=1 lib_deps = ${env.lib_deps} From 7be618ccf7f46ebc7b93b6045b0052f75f869911 Mon Sep 17 00:00:00 2001 From: nagyrobi Date: Sun, 7 Mar 2021 21:23:41 +0100 Subject: [PATCH 156/236] Update lanbon_l8.ini Ignore ESP32 BLE Arduino as Lanbon doesn't have BLE hardware. --- user_setups/esp32/lanbon_l8.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_setups/esp32/lanbon_l8.ini b/user_setups/esp32/lanbon_l8.ini index 4328cc6e..5c4ab00e 100644 --- a/user_setups/esp32/lanbon_l8.ini +++ b/user_setups/esp32/lanbon_l8.ini @@ -48,8 +48,9 @@ lib_deps = lib_ignore = ${env.lib_ignore} ${esp32.lib_ignore} + ESP32 BLE Arduino ;endregion extra_scripts = ${env.extra_scripts} - ${esp32.extra_scripts} \ No newline at end of file + ${esp32.extra_scripts} From cc6ce5c4f872b404b5092dbedd4d75c7677be643 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Mon, 8 Mar 2021 03:37:21 +0100 Subject: [PATCH 157/236] Add local page navigation action --- include/lv_conf_v7.h | 3 +- src/hasp/hasp.cpp | 117 ++------------------------- src/hasp/hasp.h | 7 -- src/hasp/hasp_attribute.cpp | 5 ++ src/hasp/hasp_attribute.h | 1 + src/hasp/hasp_dispatch.cpp | 92 +++++++++++----------- src/hasp/hasp_dispatch.h | 3 +- src/hasp/hasp_object.cpp | 60 +++++++++----- src/hasp/hasp_page.cpp | 152 ++++++++++++++++++++++++++++++++++++ src/hasp/hasp_page.h | 55 +++++++++++++ src/hasplib.h | 1 + src/log/hasp_debug.cpp | 2 +- src/sys/svc/hasp_http.cpp | 10 ++- 13 files changed, 319 insertions(+), 189 deletions(-) create mode 100644 src/hasp/hasp_page.cpp create mode 100644 src/hasp/hasp_page.h diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index 99166358..c6b4a3ed 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -518,8 +518,9 @@ typedef void* lv_font_user_data_t; /*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/ typedef struct { uint8_t objid:8; + uint8_t pageaction:8; uint8_t groupid:8; - uint8_t id; + uint8_t id:8; } lv_obj_user_data_t; /*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/ diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 0cc018be..ada116c0 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -26,6 +26,7 @@ #endif #include "hasplib.h" +#include "hasp.h" #include "lv_theme_hasp.h" #include "dev/device.h" @@ -68,7 +69,6 @@ LV_IMG_DECLARE(img_bubble_pattern) /********************** * GLOBAL FUNCTIONS **********************/ -void haspLoadPage(const char* pages); //////////////////////////////////////////////////////////////////////////////////////////////////// uint8_t hasp_sleep_state = HASP_SLEEP_OFF; // Used in hasp_drv_touch.cpp @@ -86,10 +86,8 @@ lv_style_t style_mbox_bg; /*Black bg. style with opacity*/ lv_obj_t* kb; // lv_font_t * defaultFont; -lv_obj_t* pages[HASP_NUM_PAGES]; static lv_font_t* haspFonts[4] = {nullptr, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE}; -uint8_t current_page = 1; /** * Get Font ID @@ -164,42 +162,6 @@ void haspEverySecond() dispatchEverySecond(); } -//////////////////////////////////////////////////////////////////////////////////////////////////// -/** - * Get Page Object by PageID - */ -lv_obj_t* get_page_obj(uint8_t pageid) -{ - if(pageid == 0) return lv_layer_top(); // 254 - if(pageid == 255) return lv_layer_sys(); - if(pageid > sizeof pages / sizeof *pages) return NULL; // >=0 - return pages[pageid - PAGE_START_INDEX]; -} - -bool get_page_id(lv_obj_t* obj, uint8_t* pageid) -{ - lv_obj_t* page = lv_obj_get_screen(obj); - - if(!page) return false; - - if(page == lv_layer_top()) { - *pageid = 0; // 254 - return true; - } - if(page == lv_layer_sys()) { - *pageid = 255; - return true; - } - - for(uint8_t i = 0; i < sizeof pages / sizeof *pages; i++) { - if(page == pages[i]) { - *pageid = i + PAGE_START_INDEX; - return true; - } - } - return false; -} - //////////////////////////////////////////////////////////////////////////////////////////////////// void haspDisconnect() @@ -245,7 +207,7 @@ void haspReconnect() void haspProgressVal(uint8_t val) { lv_obj_t* layer = lv_disp_get_layer_sys(NULL); - lv_obj_t* bar = hasp_find_obj_from_parent_id(get_page_obj(255), (uint8_t)10); + lv_obj_t* bar = hasp_find_obj_from_parent_id(haspPages.get_obj(255), (uint8_t)10); if(layer && bar) { if(val == 255) { if(!lv_obj_get_hidden(bar)) { @@ -274,7 +236,7 @@ void haspProgressVal(uint8_t val) // Sets the value string of the global progress bar void haspProgressMsg(const char* msg) { - lv_obj_t* bar = hasp_find_obj_from_parent_id(get_page_obj(255), (uint8_t)10); + lv_obj_t* bar = hasp_find_obj_from_parent_id(haspPages.get_obj(255), (uint8_t)10); if(bar) { char value_str[10]; @@ -454,9 +416,6 @@ void haspSetup(void) } /* Create all screens using the theme */ - for(int i = 0; i < (sizeof pages / sizeof *pages); i++) { - pages[i] = lv_obj_create(NULL, NULL); - } #if HASP_USE_WIFI > 0 if(!wifiShowAP()) { @@ -464,8 +423,9 @@ void haspSetup(void) } #endif - haspLoadPage(haspPagesPath); - haspSetPage(haspStartPage); + haspPages.init(haspStartPage); + haspPages.load_jsonl(haspPagesPath); + haspPages.set(haspStartPage); } /********************** @@ -533,71 +493,6 @@ void haspGetVersion(char* version, size_t len) snprintf_P(version, len, PSTR("%u.%u.%u"), HASP_VER_MAJ, HASP_VER_MIN, HASP_VER_REV); } -void haspClearPage(uint16_t pageid) -{ - lv_obj_t* page = get_page_obj(pageid); - if(!page || (pageid > HASP_NUM_PAGES)) { - LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_PAGE), pageid); - } else if(page == lv_layer_sys() /*|| page == lv_layer_top()*/) { - LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_LAYER)); - } else { - LOG_TRACE(TAG_HASP, F(D_HASP_CLEAR_PAGE), pageid); - lv_obj_clean(page); - } -} - -uint8_t haspGetPage() -{ - return current_page; -} - -void haspSetPage(uint8_t pageid) -{ - lv_obj_t* page = get_page_obj(pageid); - if(!page || pageid == 0 || pageid > HASP_NUM_PAGES) { - LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_PAGE), pageid); - } else { - LOG_TRACE(TAG_HASP, F(D_HASP_CHANGE_PAGE), pageid); - current_page = pageid; - lv_scr_load(page); - hasp_object_tree(page, pageid, 0); - } -} - -void haspLoadPage(const char* pagesfile) -{ -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - if(pagesfile[0] == '\0') return; - - if(!filesystemSetup()) { - LOG_ERROR(TAG_HASP, F("FS not mounted. Failed to load %s"), pagesfile); - return; - } - - if(!HASP_FS.exists(pagesfile)) { - LOG_ERROR(TAG_HASP, F("Non existing file %s"), pagesfile); - return; - } - - LOG_TRACE(TAG_HASP, F("Loading file %s"), pagesfile); - - File file = HASP_FS.open(pagesfile, "r"); - dispatch_parse_jsonl(file); - file.close(); - - LOG_INFO(TAG_HASP, F("File %s loaded"), pagesfile); -#else - -#if HASP_USE_EEPROM > 0 - LOG_TRACE(TAG_HASP, F("Loading jsonl from EEPROM...")); - EepromStream eepromStream(4096, 1024); - dispatch_parse_jsonl(eepromStream); - LOG_INFO(TAG_HASP, F("Loaded jsonl from EEPROM")); -#endif - -#endif -} - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_CONFIG > 0 bool haspGetConfig(const JsonObject& settings) diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index 986eefc8..d43b68fd 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -56,13 +56,6 @@ void haspEverySecond(void); void haspReconnect(void); void haspDisconnect(void); -lv_obj_t* get_page_obj(uint8_t pageid); -bool get_page_id(lv_obj_t* obj, uint8_t* pageid); - -void haspSetPage(uint8_t id); -uint8_t haspGetPage(); -void haspClearPage(uint16_t pageid); - void haspGetVersion(char* version, size_t len); // void haspBackground(uint16_t pageid, uint16_t imageid); diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index a9444c5c..6cbfe8d3 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1406,6 +1406,11 @@ void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* p update ? (void)(obj->user_data.groupid = (uint8_t)val) : hasp_out_int(obj, attr, obj->user_data.groupid); break; // attribute_found + case ATTR_ACTION: + update ? (void)(obj->user_data.pageaction = (uint8_t)val) + : hasp_out_int(obj, attr, obj->user_data.pageaction); + break; // attribute_found + case ATTR_OBJID: if(update) { LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_READ_ONLY), attr_p); diff --git a/src/hasp/hasp_attribute.h b/src/hasp/hasp_attribute.h index ff8ccf50..8eac5816 100644 --- a/src/hasp/hasp_attribute.h +++ b/src/hasp/hasp_attribute.h @@ -312,6 +312,7 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t) #define ATTR_MAP 45628 /* hasp user data */ +#define ATTR_ACTION 42102 #define ATTR_GROUPID 48986 #define ATTR_OBJID 41010 diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 58d17e0a..1c7d2efa 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -742,7 +742,7 @@ void dispatch_parse_json(const char*, const char* payload) } // guiStart(); } else if(json.is()) { // handle json as a jsonl - uint8_t savedPage = haspGetPage(); + uint8_t savedPage = haspPages.get(); hasp_new_object(json.as(), savedPage); // #ifdef ARDUINO @@ -770,7 +770,7 @@ void dispatch_parse_jsonl(Stream& stream) void dispatch_parse_jsonl(std::istringstream& stream) #endif { - uint8_t savedPage = haspGetPage(); + uint8_t savedPage = haspPages.get(); size_t line = 1; DynamicJsonDocument jsonl(MQTT_MAX_PACKET_SIZE / 2 + 128); // max ~256 characters per line DeserializationError jsonError = deserializeJson(jsonl, stream); @@ -814,63 +814,65 @@ void dispatch_output_current_page() char payload[8]; memcpy_P(topic, PSTR("page"), 5); - snprintf_P(payload, sizeof(payload), PSTR("%d"), haspGetPage()); + snprintf_P(payload, sizeof(payload), PSTR("%d"), haspPages.get()); dispatch_state_subtopic(topic, payload); } -// Get or Set a page -void dispatch_page(const char*, const char* page) -{ - if(strlen(page) > 0) { - if(Utilities::is_only_digits(page)) { - uint8_t pageid = atoi(page); - haspSetPage(pageid); - } else { - - if(!strcasecmp_P(page, PSTR("prev"))) { - dispatch_page_prev(); - } else if(!strcasecmp_P(page, PSTR("next"))) { - dispatch_page_next(); - } else { - LOG_WARNING(TAG_MSGR, PSTR(D_DISPATCH_INVALID_PAGE), page); - } - return; - } - } - - dispatch_output_current_page(); -} - +// Dispatch Page Get or Set void dispatch_page_next() { - uint8_t page = haspGetPage(); - if(page >= HASP_NUM_PAGES) { - page = 1; - } else { - page++; - } - haspSetPage(page); + haspPages.next(); dispatch_output_current_page(); } void dispatch_page_prev() { - uint8_t page = haspGetPage(); - if(page == 1) { - page = HASP_NUM_PAGES; - } else { - page--; - } - haspSetPage(page); + haspPages.prev(); dispatch_output_current_page(); } +void dispatch_page_back() +{ + haspPages.back(); + dispatch_output_current_page(); +} + +void dispatch_set_page(uint8_t pageid) +{ + haspPages.set(pageid); + dispatch_output_current_page(); +} + +void dispatch_page(const char*, const char* page) +{ + if(strlen(page) == 0) { + dispatch_output_current_page(); // No payload, send current page + return; + } + + if(Utilities::is_only_digits(page)) { + uint8_t pageid = atoi(page); + dispatch_set_page(pageid); + } else if(!strcasecmp_P(page, PSTR("prev"))) { + dispatch_page_prev(); + } else if(!strcasecmp_P(page, PSTR("next"))) { + dispatch_page_next(); + } else if(!strcasecmp_P(page, PSTR("back"))) { + dispatch_page_back(); + } else { + LOG_WARNING(TAG_MSGR, PSTR(D_DISPATCH_INVALID_PAGE), page); + } +} + // Clears a page id or the current page if empty void dispatch_clear_page(const char*, const char* page) { - uint8_t pageid = haspGetPage(); - if(strlen(page) > 0) pageid = atoi(page); - haspClearPage(pageid); + uint8_t pageid; + if(strlen(page) > 0) + pageid = atoi(page); + else + pageid = haspPages.get(); + haspPages.clear(pageid); } void dispatch_dim(const char*, const char* level) @@ -1030,8 +1032,8 @@ void dispatch_output_statusupdate(const char*, const char*) haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), haspDevice.get_core_version()); strcat(data, buffer); - snprintf_P(buffer, sizeof(buffer), PSTR("\"canUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), haspGetPage(), - (HASP_NUM_PAGES)); + snprintf_P(buffer, sizeof(buffer), PSTR("\"canUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), + haspPages.get(), haspPages.count()); strcat(data, buffer); #if defined(ARDUINO_ARCH_ESP8266) diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index ac0e591b..a12f492c 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -47,9 +47,10 @@ void dispatch_parse_jsonl(std::istringstream& stream); void dispatch_clear_page(const char* page); void dispatch_json_error(uint8_t tag, DeserializationError& jsonError); -// void dispatchPage(uint8_t page); +void dispatch_set_page(uint8_t pageid); void dispatch_page_next(); void dispatch_page_prev(); +void dispatch_page_back(); void dispatch_dim(const char* level); void dispatch_backlight(const char* payload); diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 20350691..ac0b853b 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -71,7 +71,7 @@ lv_obj_t* hasp_find_obj_from_parent_id(lv_obj_t* parent, uint8_t objid) bool hasp_find_id_from_obj(lv_obj_t* obj, uint8_t* pageid, uint8_t* objid) { - if(!get_page_id(obj, pageid)) return false; + if(!haspPages.get_id(obj, pageid)) return false; if(!(obj->user_data.id > 0)) return false; // memcpy(objid, &obj->user_data.id, sizeof(lv_obj_user_data_t)); *objid = obj->user_data.id; @@ -350,8 +350,20 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) return; } - hasp_update_sleep_state(); // wakeup? - dispatch_object_generic_event(obj, eventid); // send object event + hasp_update_sleep_state(); // wakeup? + + /* If a pageaction is attached, perform that action on UP event only */ + if(obj->user_data.pageaction) { + if(eventid == HASP_EVENT_UP) { + lv_scr_load_anim_t effectid = LV_SCR_LOAD_ANIM_NONE; + if(obj->user_data.pageaction >> 4 <= LV_SCR_LOAD_ANIM_FADE_ON) + effectid = (lv_scr_load_anim_t)(obj->user_data.pageaction >> 4); + uint8_t pageid = obj->user_data.pageaction & 0x0F; + haspPages.set(pageid, effectid); + } + } else { + dispatch_object_generic_event(obj, eventid); // send object event + } dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(dispatch_get_event_state(eventid), 0, 1), obj); } @@ -540,7 +552,7 @@ void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t* src_obj) for(uint8_t page = 0; page < HASP_NUM_PAGES; page++) { uint8_t startid = 1; for(uint8_t objid = startid; objid < 20; objid++) { - lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(page), objid); + lv_obj_t* obj = hasp_find_obj_from_parent_id(haspPages.get_obj(page), objid); if(obj && obj != src_obj && obj->user_data.groupid == groupid) { // skip source object, if set lv_obj_set_state(obj, state ? LV_STATE_PRESSED | LV_STATE_CHECKED : LV_STATE_DEFAULT); } @@ -593,7 +605,7 @@ void object_set_group_value(uint8_t groupid, int16_t state) // Used in the dispatcher & hasp_new_object void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload) { - if(lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(pageid), objid)) { + if(lv_obj_t* obj = hasp_find_obj_from_parent_id(haspPages.get_obj(pageid), objid)) { hasp_process_obj_attribute(obj, attr, payload, strlen(payload) > 0); } else { LOG_WARNING(TAG_HASP, F(D_OBJECT_UNKNOWN " " HASP_OBJECT_NOTATION), pageid, objid); @@ -639,17 +651,23 @@ int hasp_parse_json_attributes(lv_obj_t* obj, const JsonObject& doc) */ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) { - /* Page selection: page is the default parent_obj */ - uint8_t pageid = config[FPSTR(FP_PAGE)].isNull() ? saved_page_id : config[FPSTR(FP_PAGE)].as(); - lv_obj_t* parent_obj = get_page_obj(pageid); + /* Page selection */ + uint8_t pageid = saved_page_id; + if(!config[FPSTR(FP_PAGE)].isNull()) { + config[FPSTR(FP_PAGE)].as(); + config.remove(FPSTR(FP_PAGE)); + } + + /* Page with pageid is the default parent_obj */ + lv_obj_t* parent_obj = haspPages.get_obj(pageid); if(!parent_obj) { LOG_WARNING(TAG_HASP, F(D_OBJECT_PAGE_UNKNOWN), pageid); return; } else { - saved_page_id = pageid; /* save the current pageid */ + saved_page_id = pageid; /* save the current pageid for next objects */ } - // lv_obj_t * parent_obj = page; + /* A custom parentid was set */ if(!config[FPSTR(FP_PARENTID)].isNull()) { uint8_t parentid = config[FPSTR(FP_PARENTID)].as(); parent_obj = hasp_find_obj_from_parent_id(parent_obj, parentid); @@ -659,13 +677,15 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) } else { LOG_VERBOSE(TAG_HASP, F("Parent ID " HASP_OBJECT_NOTATION " found"), pageid, parentid); } + config.remove(FPSTR(FP_PARENTID)); } uint16_t sdbm = 0; - uint8_t id = config[FPSTR(FP_ID)].as(); uint8_t groupid = config[FPSTR(FP_GROUPID)].as(); + uint8_t id = config[FPSTR(FP_ID)].as(); + config.remove(FPSTR(FP_ID)); - /* Define Objects*/ + /* Create the object if it does not exist */ lv_obj_t* obj = hasp_find_obj_from_parent_id(parent_obj, id); if(!obj) { @@ -677,9 +697,11 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) return; // comments } else { sdbm = Utilities::get_sdbm(config[FPSTR(FP_OBJ)].as()); + config.remove(FPSTR(FP_OBJ)); } } else { sdbm = config[FPSTR(FP_OBJID)].as(); + config.remove(FPSTR(FP_OBJID)); } switch(sdbm) { @@ -1015,19 +1037,17 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) LOG_VERBOSE(TAG_HASP, F(D_BULLET HASP_OBJECT_NOTATION " = %s"), pageid, temp, list.type[0]); /* test double-check */ - lv_obj_t* test = hasp_find_obj_from_parent_id(get_page_obj(pageid), (uint8_t)temp); + lv_obj_t* test = hasp_find_obj_from_parent_id(haspPages.get_obj(pageid), (uint8_t)temp); if(test != obj) { LOG_ERROR(TAG_HASP, F(D_OBJECT_MISMATCH)); return; + } else { + // object created successfully } - } - /* do not process these attributes */ - config.remove(FPSTR(FP_PAGE)); - config.remove(FPSTR(FP_ID)); - config.remove(FPSTR(FP_OBJ)); - config.remove(FPSTR(FP_OBJID)); // TODO: obsolete objid - config.remove(FPSTR(FP_PARENTID)); + } else { + // object already exists + } hasp_parse_json_attributes(obj, config); } diff --git a/src/hasp/hasp_page.cpp b/src/hasp/hasp_page.cpp new file mode 100644 index 00000000..41285997 --- /dev/null +++ b/src/hasp/hasp_page.cpp @@ -0,0 +1,152 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#include "hasp_conf.h" +#include "hasplib.h" + +#include "hasp_page.h" + +namespace hasp { + +Page::Page() +{ + // LVGL is not yet initialized at construction time +} + +size_t Page::count() +{ + return sizeof(_pages) / sizeof(*_pages); +} + +void Page::init(uint8_t start_page) +{ + for(int i = 0; i < count(); i++) { + _pages[i] = lv_obj_create(NULL, NULL); + + uint16_t thispage = i + PAGE_START_INDEX; + _meta_data[i].prev = thispage == PAGE_START_INDEX ? HASP_NUM_PAGES : thispage - PAGE_START_INDEX; + _meta_data[i].next = thispage == HASP_NUM_PAGES ? PAGE_START_INDEX : thispage + PAGE_START_INDEX; + _meta_data[i].back = start_page; + } +} + +void Page::clear(uint16_t pageid) +{ + lv_obj_t* page = get_obj(pageid); + if(!page || (pageid > HASP_NUM_PAGES)) { + LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_PAGE), pageid); + } else if(page == lv_layer_sys() /*|| page == lv_layer_top()*/) { + LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_LAYER)); + } else { + LOG_TRACE(TAG_HASP, F(D_HASP_CLEAR_PAGE), pageid); + lv_obj_clean(page); + } +} + +void Page::set(uint8_t pageid) +{ + set(pageid, LV_SCR_LOAD_ANIM_NONE); +} + +void Page::set(uint8_t pageid, lv_scr_load_anim_t effectid) +{ + lv_obj_t* page = get_obj(pageid); + if(!page || pageid == 0 || pageid > HASP_NUM_PAGES) { + LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_PAGE), pageid); + } else { + LOG_TRACE(TAG_HASP, F(D_HASP_CHANGE_PAGE), pageid); + _current_page = pageid; + lv_scr_load_anim(page, effectid, 1000, 0, false); + hasp_object_tree(page, pageid, 0); + } +} + +void Page::next() +{ + set(_meta_data[_current_page - PAGE_START_INDEX].next); +} + +void Page::prev() +{ + set(_meta_data[_current_page - PAGE_START_INDEX].prev); +} + +void Page::back() +{ + set(_meta_data[_current_page - PAGE_START_INDEX].back); +} + +uint8_t Page::get() +{ + return _current_page; +} + +void Page::load_jsonl(const char* pagesfile) +{ +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + if(pagesfile[0] == '\0') return; + + if(!filesystemSetup()) { + LOG_ERROR(TAG_HASP, F("FS not mounted. Failed to load %s"), pagesfile); + return; + } + + if(!HASP_FS.exists(pagesfile)) { + LOG_ERROR(TAG_HASP, F("Non existing file %s"), pagesfile); + return; + } + + LOG_TRACE(TAG_HASP, F("Loading file %s"), pagesfile); + + File file = HASP_FS.open(pagesfile, "r"); + dispatch_parse_jsonl(file); + file.close(); + + LOG_INFO(TAG_HASP, F("File %s loaded"), pagesfile); +#else + +#if HASP_USE_EEPROM > 0 + LOG_TRACE(TAG_HASP, F("Loading jsonl from EEPROM...")); + EepromStream eepromStream(4096, 1024); + dispatch_parse_jsonl(eepromStream); + LOG_INFO(TAG_HASP, F("Loaded jsonl from EEPROM")); +#endif + +#endif +} + +lv_obj_t* Page::get_obj(uint8_t pageid) +{ + if(pageid == 0) return lv_layer_top(); // 254 + if(pageid == 255) return lv_layer_sys(); + if(pageid > count()) return NULL; // >=0 + return _pages[pageid - PAGE_START_INDEX]; +} + +bool Page::get_id(lv_obj_t* obj, uint8_t* pageid) +{ + lv_obj_t* page = lv_obj_get_screen(obj); + + if(!page) return false; + + if(page == lv_layer_top()) { + *pageid = 0; + return true; + } + if(page == lv_layer_sys()) { + *pageid = 255; + return true; + } + + for(uint8_t i = 0; i < count(); i++) { + if(page == _pages[i]) { + *pageid = i + PAGE_START_INDEX; + return true; + } + } + return false; +} + +} // namespace hasp + +hasp::Page haspPages; diff --git a/src/hasp/hasp_page.h b/src/hasp/hasp_page.h new file mode 100644 index 00000000..60f3c382 --- /dev/null +++ b/src/hasp/hasp_page.h @@ -0,0 +1,55 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_PAGES_H +#define HASP_PAGES_H + +#include "hasp_conf.h" +#include "hasplib.h" + +/********************* + * DEFINES + *********************/ +#define PAGE_START_INDEX 1 // Page number of array index 0 + +/********************** + * TYPEDEFS + **********************/ + +typedef struct hasp_page_meta_data_t +{ + uint8_t prev : 4; + uint8_t next : 4; + uint8_t back : 4; +}; + +namespace hasp { + +class Page { + private: + hasp_page_meta_data_t _meta_data[HASP_NUM_PAGES]; // index 0 = Page 1 etc. + lv_obj_t* _pages[HASP_NUM_PAGES]; // index 0 = Page 1 etc. + uint8_t _current_page; + + public: + Page(); + size_t count(); + void init(uint8_t start_page); + void clear(uint16_t pageid); + void set(uint8_t pageid); + void set(uint8_t pageid, lv_scr_load_anim_t effectid); + void next(); + void prev(); + void back(); + uint8_t get(); + void load_jsonl(const char* pagesfile); + lv_obj_t* get_obj(uint8_t pageid); + bool get_id(lv_obj_t* obj, uint8_t* pageid); +}; + +} // namespace hasp + +using hasp::Page; +extern hasp::Page haspPages; + +#endif // HASP_PAGES_H diff --git a/src/hasplib.h b/src/hasplib.h index 158a6e56..ada7b224 100644 --- a/src/hasplib.h +++ b/src/hasplib.h @@ -4,6 +4,7 @@ #include "hasp/hasp_attribute.h" #include "hasp/hasp_dispatch.h" #include "hasp/hasp_object.h" +#include "hasp/hasp_page.h" #include "hasp/hasp_parser.h" #include "hasp/hasp_utilities.h" #include "hasp/hasp_lvfs.h" diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index 4f6d36b0..514b24d0 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -706,7 +706,7 @@ void debugLoop(void) break; case(ConsoleInput::KEY_FN)...(ConsoleInput::KEY_FN + 12): - haspSetPage(keypress - ConsoleInput::KEY_FN - 1); + dispatch_set_page(keypress - ConsoleInput::KEY_FN); break; } } while(keypress != 0); diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index b8c51533..04492f3a 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -14,12 +14,14 @@ #include "dev/device.h" #include "hasp_gui.h" -#include "hal/hasp_hal.h" +#include "hasp/hasp_dispatch.h" #include "hasp_debug.h" #include "hasp_config.h" +#include "hal/hasp_hal.h" #include "hasp/hasp_utilities.h" #include "hasp/hasp_dispatch.h" +#include "hasp/hasp_page.h" #include "hasp/hasp.h" #if HASP_USE_HTTP > 0 @@ -377,6 +379,8 @@ void webHandleScreenshot() dispatch_page_next(); } else if(webServer.arg(F("a")) == F("prev")) { dispatch_page_prev(); + } else if(webServer.arg(F("a")) == F("back")) { + dispatch_page_back(); } } @@ -559,7 +563,7 @@ void webHandleInfo() // String(LV_HASP_VER_RES_MAX); httpMessage += F("
LCD Version: ")) + // String(lcdVersion); httpMessage += F("

LCD Active Page: "); - httpMessage += String(haspGetPage()); + httpMessage += String(haspPages.get()); /* Wifi Stats */ #if HASP_USE_WIFI > 0 @@ -1958,7 +1962,7 @@ void httpSetup() webServer.on(F("/page/"), []() { String pageid = webServer.arg(F("page")); webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'"); - haspSetPage(pageid.toInt()); + dispatch_set_page(pageid.toInt()); }); #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 From 27e7c95cefa00ae4a75f51a47416c4bef2f4f347 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Mon, 8 Mar 2021 04:30:59 +0100 Subject: [PATCH 158/236] Add local page transitions --- include/lv_conf_v7.h | 7 ++++--- include/lv_conf_v8.h | 6 ++++-- src/hasp/hasp.cpp | 2 +- src/hasp/hasp_attribute.cpp | 8 ++++++-- src/hasp/hasp_attribute.h | 1 + src/hasp/hasp_dispatch.cpp | 28 +++++++++++++++++----------- src/hasp/hasp_dispatch.h | 9 +++++---- src/hasp/hasp_object.cpp | 14 ++++++-------- src/hasp/hasp_page.cpp | 24 ++++++++++++------------ src/hasp/hasp_page.h | 10 +++++----- src/log/hasp_debug.cpp | 6 +++--- src/sys/svc/hasp_http.cpp | 8 ++++---- 12 files changed, 68 insertions(+), 55 deletions(-) diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index c6b4a3ed..857f5001 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -517,10 +517,11 @@ typedef void* lv_font_user_data_t; /*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/ typedef struct { - uint8_t objid:8; - uint8_t pageaction:8; - uint8_t groupid:8; uint8_t id:8; + uint8_t objid:8; + uint8_t transitionid:4; + uint8_t actionid:4; + uint8_t groupid:4; } lv_obj_user_data_t; /*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/ diff --git a/include/lv_conf_v8.h b/include/lv_conf_v8.h index 0534d9ff..afaa51ea 100644 --- a/include/lv_conf_v8.h +++ b/include/lv_conf_v8.h @@ -582,9 +582,11 @@ typedef void * lv_font_user_data_t; *==================*/ typedef struct { + uint8_t id:8; uint8_t objid:8; - uint8_t groupid:8; - uint8_t id; + uint8_t transitionid:4; + uint8_t actionid:4; + uint8_t groupid:4; } lv_obj_user_data_t; #if LV_USE_USER_DATA diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index ada116c0..6351a112 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -425,7 +425,7 @@ void haspSetup(void) haspPages.init(haspStartPage); haspPages.load_jsonl(haspPagesPath); - haspPages.set(haspStartPage); + haspPages.set(haspStartPage, LV_SCR_LOAD_ANIM_NONE); } /********************** diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 6cbfe8d3..7208de34 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1407,8 +1407,12 @@ void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* p break; // attribute_found case ATTR_ACTION: - update ? (void)(obj->user_data.pageaction = (uint8_t)val) - : hasp_out_int(obj, attr, obj->user_data.pageaction); + update ? (void)(obj->user_data.actionid = (uint8_t)val) : hasp_out_int(obj, attr, obj->user_data.actionid); + break; // attribute_found + + case ATTR_TRANSITION: + update ? (void)(obj->user_data.transitionid = (uint8_t)val) + : hasp_out_int(obj, attr, obj->user_data.transitionid); break; // attribute_found case ATTR_OBJID: diff --git a/src/hasp/hasp_attribute.h b/src/hasp/hasp_attribute.h index 8eac5816..21543959 100644 --- a/src/hasp/hasp_attribute.h +++ b/src/hasp/hasp_attribute.h @@ -313,6 +313,7 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t) /* hasp user data */ #define ATTR_ACTION 42102 +#define ATTR_TRANSITION 10933 #define ATTR_GROUPID 48986 #define ATTR_OBJID 41010 diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 1c7d2efa..0bbdfed1 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -819,27 +819,32 @@ void dispatch_output_current_page() } // Dispatch Page Get or Set -void dispatch_page_next() +void dispatch_page_next(lv_scr_load_anim_t animation) { - haspPages.next(); + haspPages.next(animation); dispatch_output_current_page(); } -void dispatch_page_prev() +void dispatch_page_prev(lv_scr_load_anim_t animation) { - haspPages.prev(); + haspPages.prev(animation); dispatch_output_current_page(); } -void dispatch_page_back() +void dispatch_page_back(lv_scr_load_anim_t animation) { - haspPages.back(); + haspPages.back(animation); dispatch_output_current_page(); } void dispatch_set_page(uint8_t pageid) { - haspPages.set(pageid); + dispatch_set_page(pageid, LV_SCR_LOAD_ANIM_NONE); +} + +void dispatch_set_page(uint8_t pageid, lv_scr_load_anim_t animation) +{ + haspPages.set(pageid, animation); dispatch_output_current_page(); } @@ -850,15 +855,16 @@ void dispatch_page(const char*, const char* page) return; } + lv_scr_load_anim_t animation = LV_SCR_LOAD_ANIM_NONE; if(Utilities::is_only_digits(page)) { uint8_t pageid = atoi(page); - dispatch_set_page(pageid); + dispatch_set_page(pageid, animation); } else if(!strcasecmp_P(page, PSTR("prev"))) { - dispatch_page_prev(); + dispatch_page_prev(animation); } else if(!strcasecmp_P(page, PSTR("next"))) { - dispatch_page_next(); + dispatch_page_next(animation); } else if(!strcasecmp_P(page, PSTR("back"))) { - dispatch_page_back(); + dispatch_page_back(animation); } else { LOG_WARNING(TAG_MSGR, PSTR(D_DISPATCH_INVALID_PAGE), page); } diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index a12f492c..07312081 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -47,10 +47,11 @@ void dispatch_parse_jsonl(std::istringstream& stream); void dispatch_clear_page(const char* page); void dispatch_json_error(uint8_t tag, DeserializationError& jsonError); -void dispatch_set_page(uint8_t pageid); -void dispatch_page_next(); -void dispatch_page_prev(); -void dispatch_page_back(); +// void dispatch_set_page(uint8_t pageid); +void dispatch_set_page(uint8_t pageid, lv_scr_load_anim_t effectid); +void dispatch_page_next(lv_scr_load_anim_t effectid); +void dispatch_page_prev(lv_scr_load_anim_t effectid); +void dispatch_page_back(lv_scr_load_anim_t effectid); void dispatch_dim(const char* level); void dispatch_backlight(const char* payload); diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index ac0b853b..b94de5d5 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -352,14 +352,12 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) hasp_update_sleep_state(); // wakeup? - /* If a pageaction is attached, perform that action on UP event only */ - if(obj->user_data.pageaction) { - if(eventid == HASP_EVENT_UP) { - lv_scr_load_anim_t effectid = LV_SCR_LOAD_ANIM_NONE; - if(obj->user_data.pageaction >> 4 <= LV_SCR_LOAD_ANIM_FADE_ON) - effectid = (lv_scr_load_anim_t)(obj->user_data.pageaction >> 4); - uint8_t pageid = obj->user_data.pageaction & 0x0F; - haspPages.set(pageid, effectid); + /* If an actionid is attached, perform that action on UP event only */ + if(obj->user_data.actionid) { + if(eventid == HASP_EVENT_UP || eventid == HASP_EVENT_SHORT) { + lv_scr_load_anim_t transitionid = (lv_scr_load_anim_t)obj->user_data.transitionid; + haspPages.set(obj->user_data.actionid, transitionid); + dispatch_set_page(obj->user_data.actionid, transitionid); } } else { dispatch_object_generic_event(obj, eventid); // send object event diff --git a/src/hasp/hasp_page.cpp b/src/hasp/hasp_page.cpp index 41285997..7a36b9eb 100644 --- a/src/hasp/hasp_page.cpp +++ b/src/hasp/hasp_page.cpp @@ -43,12 +43,12 @@ void Page::clear(uint16_t pageid) } } -void Page::set(uint8_t pageid) -{ - set(pageid, LV_SCR_LOAD_ANIM_NONE); -} +// void Page::set(uint8_t pageid) +// { +// set(pageid, LV_SCR_LOAD_ANIM_NONE); +// } -void Page::set(uint8_t pageid, lv_scr_load_anim_t effectid) +void Page::set(uint8_t pageid, lv_scr_load_anim_t animation) { lv_obj_t* page = get_obj(pageid); if(!page || pageid == 0 || pageid > HASP_NUM_PAGES) { @@ -56,24 +56,24 @@ void Page::set(uint8_t pageid, lv_scr_load_anim_t effectid) } else { LOG_TRACE(TAG_HASP, F(D_HASP_CHANGE_PAGE), pageid); _current_page = pageid; - lv_scr_load_anim(page, effectid, 1000, 0, false); + lv_scr_load_anim(page, animation, 1000, 0, false); hasp_object_tree(page, pageid, 0); } } -void Page::next() +void Page::next(lv_scr_load_anim_t animation) { - set(_meta_data[_current_page - PAGE_START_INDEX].next); + set(_meta_data[_current_page - PAGE_START_INDEX].next, animation); } -void Page::prev() +void Page::prev(lv_scr_load_anim_t animation) { - set(_meta_data[_current_page - PAGE_START_INDEX].prev); + set(_meta_data[_current_page - PAGE_START_INDEX].prev, animation); } -void Page::back() +void Page::back(lv_scr_load_anim_t animation) { - set(_meta_data[_current_page - PAGE_START_INDEX].back); + set(_meta_data[_current_page - PAGE_START_INDEX].back, animation); } uint8_t Page::get() diff --git a/src/hasp/hasp_page.h b/src/hasp/hasp_page.h index 60f3c382..1e2bfaa4 100644 --- a/src/hasp/hasp_page.h +++ b/src/hasp/hasp_page.h @@ -36,11 +36,11 @@ class Page { size_t count(); void init(uint8_t start_page); void clear(uint16_t pageid); - void set(uint8_t pageid); - void set(uint8_t pageid, lv_scr_load_anim_t effectid); - void next(); - void prev(); - void back(); + // void set(uint8_t pageid); + void set(uint8_t pageid, lv_scr_load_anim_t animation); + void next(lv_scr_load_anim_t animation); + void prev(lv_scr_load_anim_t animation); + void back(lv_scr_load_anim_t animation); uint8_t get(); void load_jsonl(const char* pagesfile); lv_obj_t* get_obj(uint8_t pageid); diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index 514b24d0..7a5dbfd6 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -698,15 +698,15 @@ void debugLoop(void) switch(keypress = debugConsole.readKey()) { case ConsoleInput::KEY_PAGE_UP: - dispatch_page_next(); + dispatch_page_next(LV_SCR_LOAD_ANIM_NONE); break; case ConsoleInput::KEY_PAGE_DOWN: - dispatch_page_prev(); + dispatch_page_prev(LV_SCR_LOAD_ANIM_NONE); break; case(ConsoleInput::KEY_FN)...(ConsoleInput::KEY_FN + 12): - dispatch_set_page(keypress - ConsoleInput::KEY_FN); + dispatch_set_page(keypress - ConsoleInput::KEY_FN, LV_SCR_LOAD_ANIM_NONE); break; } } while(keypress != 0); diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 04492f3a..1148127a 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -376,11 +376,11 @@ void webHandleScreenshot() if(webServer.hasArg(F("a"))) { if(webServer.arg(F("a")) == F("next")) { - dispatch_page_next(); + dispatch_page_next(LV_SCR_LOAD_ANIM_NONE); } else if(webServer.arg(F("a")) == F("prev")) { - dispatch_page_prev(); + dispatch_page_prev(LV_SCR_LOAD_ANIM_NONE); } else if(webServer.arg(F("a")) == F("back")) { - dispatch_page_back(); + dispatch_page_back(LV_SCR_LOAD_ANIM_NONE); } } @@ -1962,7 +1962,7 @@ void httpSetup() webServer.on(F("/page/"), []() { String pageid = webServer.arg(F("page")); webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'"); - dispatch_set_page(pageid.toInt()); + dispatch_set_page(pageid.toInt(), LV_SCR_LOAD_ANIM_NONE); }); #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 From e25b87d1814c4cf13367ed163726991fa0c8f818 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Mon, 8 Mar 2021 15:50:08 +0100 Subject: [PATCH 159/236] Add darwin_sdl --- platformio_override-template.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platformio_override-template.ini b/platformio_override-template.ini index 237ee3c7..226f7038 100644 --- a/platformio_override-template.ini +++ b/platformio_override-template.ini @@ -9,8 +9,9 @@ extra_configs = ; user_setups/esp32/*.ini ; user_setups/esp8266/*.ini ; user_setups/stm32f4xx/*.ini - ; user_setups/win32/*.ini + ; user_setups/darwin_sdl/*.ini ; user_setups/linux_sdl/*.ini + ; user_setups/win32/*.ini [override] ; -- Hasp config options -------------------------------------- From aac809e4787666de36252dbbaedfb1fd115cc3a6 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 00:25:19 +0100 Subject: [PATCH 160/236] Fix wakeup touch --- src/hasp/hasp.cpp | 6 ++++++ src/hasp/hasp.h | 1 + src/hasp/hasp_dispatch.cpp | 21 +++++++++++++++++++-- src/hasp/hasp_dispatch.h | 2 +- src/hasp/hasp_object.cpp | 10 +++++----- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 0cc018be..63635ecd 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -137,6 +137,12 @@ void hasp_enable_wakeup_touch() lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), wakeup_event_handler); } +void hasp_disable_wakeup_touch() +{ + LOG_VERBOSE(TAG_HASP, F("Wakeup touch disabled")); + lv_obj_set_click(lv_disp_get_layer_sys(NULL), false); // disable first touch +} + /** * Return the sleep times */ diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index 986eefc8..5b1dc1a5 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -81,6 +81,7 @@ bool hasp_update_sleep_state(); void hasp_get_sleep_time(uint16_t& short_time, uint16_t& long_time); void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time); void hasp_enable_wakeup_touch(); +void hasp_disable_wakeup_touch(); /********************** * MACROS diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 58d17e0a..ce337b65 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -43,7 +43,7 @@ dispatch_conf_t dispatch_setings = {.teleperiod = 10}; uint32_t dispatchLastMillis; uint8_t nCommands = 0; -haspCommand_t commands[17]; +haspCommand_t commands[18]; struct moodlight_t { @@ -952,7 +952,17 @@ void dispatch_moodlight(const char* topic, const char* payload) void dispatch_backlight(const char*, const char* payload) { // Set the current state - if(strlen(payload) != 0) haspDevice.set_backlight_power(Utilities::is_true(payload)); + if(strlen(payload) != 0) { + bool power = Utilities::is_true(payload); + + if(haspDevice.get_backlight_power() != power) { + haspDevice.set_backlight_power(power); + if(power) + hasp_disable_wakeup_touch(); + else + hasp_enable_wakeup_touch(); + } + } // Return the current state char topic[8]; @@ -1067,6 +1077,12 @@ void dispatch_calibrate(const char* topic = NULL, const char* payload = NULL) void dispatch_wakeup(const char*, const char*) { lv_disp_trig_activity(NULL); + hasp_disable_wakeup_touch(); +} + +void dispatch_sleep(const char*, const char*) +{ + hasp_enable_wakeup_touch(); } void dispatch_reboot(const char*, const char*) @@ -1105,6 +1121,7 @@ void dispatchSetup() dispatch_add_command(PSTR("json"), dispatch_parse_json); dispatch_add_command(PSTR("page"), dispatch_page); dispatch_add_command(PSTR("wakeup"), dispatch_wakeup); + dispatch_add_command(PSTR("sleep"), dispatch_sleep); dispatch_add_command(PSTR("statusupdate"), dispatch_output_statusupdate); dispatch_add_command(PSTR("clearpage"), dispatch_clear_page); dispatch_add_command(PSTR("jsonl"), dispatch_parse_jsonl); diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index ac0e591b..29b1e3d4 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -52,7 +52,7 @@ void dispatch_page_next(); void dispatch_page_prev(); void dispatch_dim(const char* level); -void dispatch_backlight(const char* payload); +void dispatch_backlight(const char*, const char* payload); void dispatch_web_update(const char* espOtaUrl); void dispatch_reboot(bool saveConfig); diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 20350691..690dccbb 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -276,12 +276,12 @@ void hasp_send_obj_attribute_color(lv_obj_t* obj, const char* attribute, lv_colo */ void wakeup_event_handler(lv_obj_t* obj, lv_event_t event) { - if(obj == lv_disp_get_layer_sys(NULL)) { + if(event == LV_EVENT_RELEASED && obj == lv_disp_get_layer_sys(NULL)) { hasp_update_sleep_state(); // wakeup? - - if(event == LV_EVENT_CLICKED) { - lv_obj_set_click(obj, false); // disable first touch - LOG_VERBOSE(TAG_HASP, F("Wakeup touch disabled")); + if(!haspDevice.get_backlight_power()) + dispatch_backlight(NULL, "1"); // backlight on and also disable wakeup touch + else { + hasp_disable_wakeup_touch(); // only disable wakeup touch } } } From 70c063635e2c644a16ffec707cad5ae24e3c0a10 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 16:31:03 +0100 Subject: [PATCH 161/236] Add backlight and title to MacOS --- src/dev/posix/hasp_posix.cpp | 2 -- src/drv/tft_driver_sdl2.h | 2 -- src/main_sdl2.cpp | 2 ++ user_setups/darwin_sdl/darwin_sdl_64bits.ini | 3 ++- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index 52604f2a..b3782006 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -73,9 +73,7 @@ bool PosixDevice::get_backlight_power() void PosixDevice::update_backlight() { -#ifndef TARGET_OS_MAC monitor_backlight(_backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0); -#endif } size_t PosixDevice::get_free_max_block() diff --git a/src/drv/tft_driver_sdl2.h b/src/drv/tft_driver_sdl2.h index e917ee74..2b443fad 100644 --- a/src/drv/tft_driver_sdl2.h +++ b/src/drv/tft_driver_sdl2.h @@ -49,9 +49,7 @@ class TftSdl2 : BaseTft { /* Add a display * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ monitor_init(); -#ifndef TARGET_OS_MAC monitor_title(haspDevice.get_hostname()); -#endif /* Add the mouse as input device * Use the 'mouse' driver which reads the PC's mouse*/ diff --git a/src/main_sdl2.cpp b/src/main_sdl2.cpp index 302fcf29..80ef08a9 100644 --- a/src/main_sdl2.cpp +++ b/src/main_sdl2.cpp @@ -218,6 +218,7 @@ int main(int argc, char* argv[]) // To retrieve host information host_entry = gethostbyname(hostbuffer); // checkHostEntry(host_entry); + haspDevice.set_hostname(hostbuffer); // To convert an Internet network // address into ASCII string @@ -245,6 +246,7 @@ int main(int argc, char* argv[]) // return 67; } #endif + for(count = 0; count < argc; count++) { if(argv[count][0] == '-') { diff --git a/user_setups/darwin_sdl/darwin_sdl_64bits.ini b/user_setups/darwin_sdl/darwin_sdl_64bits.ini index 08bda544..1b16060d 100644 --- a/user_setups/darwin_sdl/darwin_sdl_64bits.ini +++ b/user_setups/darwin_sdl/darwin_sdl_64bits.ini @@ -56,10 +56,11 @@ build_flags = lib_deps = ${env.lib_deps} - lv_drivers@~7.9.1 + ; lv_drivers@~7.9.1 ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip https://github.com/eclipse/paho.mqtt.c.git bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + https://github.com/fvanroie/lv_drivers lib_ignore = paho From be2019d34441d9870e3380aac96ab43206024a08 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 16:31:14 +0100 Subject: [PATCH 162/236] Add README --- src/hal/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/hal/README.md diff --git a/src/hal/README.md b/src/hal/README.md new file mode 100644 index 00000000..25db048a --- /dev/null +++ b/src/hal/README.md @@ -0,0 +1,2 @@ +These files need to be obsoleted. +The functions should be moved to the respective device ot tft objects. \ No newline at end of file From 29294f0096d8112af8568c344eb24d5194ea433a Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 16:58:20 +0100 Subject: [PATCH 163/236] Don't call window_update directly --- lib/lv_drivers/display/monitor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/lv_drivers/display/monitor.c b/lib/lv_drivers/display/monitor.c index fe0c0f27..67af9944 100644 --- a/lib/lv_drivers/display/monitor.c +++ b/lib/lv_drivers/display/monitor.c @@ -291,7 +291,9 @@ static void monitor_sdl_clean_up(void) void monitor_backlight(uint8_t level) { SDL_SetTextureColorMod(monitor.texture, level, level, level); - window_update(&monitor); + // window_update(&monitor); + monitor.sdl_refr_qry = true; + monitor_sdl_refr_core(); } void monitor_title(const char* title) From 3109960e253acf7ef6814ab55a6c916700ec1555 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 20:23:30 +0100 Subject: [PATCH 164/236] Add hostname --- src/dev/posix/hasp_posix.cpp | 30 +++++++++++++++++++--- src/dev/win32/hasp_win32.cpp | 1 + user_setups/linux_sdl/linux_sdl_64bits.ini | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index b3782006..96e46630 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -1,6 +1,7 @@ #if defined(POSIX) #include +#include #include "hasp_posix.h" @@ -10,14 +11,29 @@ #include "display/monitor.h" +extern monitor_t monitor; + namespace dev { void PosixDevice::reboot() {} void PosixDevice::show_info() { - LOG_VERBOSE(0, F("Processor : %s"), "unknown"); - LOG_VERBOSE(0, F("CPU freq. : %i MHz"), 0); + + struct utsname uts; + + if (uname(&uts) < 0) { + LOG_ERROR(0,"uname() error"); + } else { + LOG_VERBOSE(0,"Sysname: %s", uts.sysname); + LOG_VERBOSE(0,"Nodename: %s", uts.nodename); + LOG_VERBOSE(0,"Release: %s", uts.release); + LOG_VERBOSE(0,"Version: %s", uts.version); + LOG_VERBOSE(0,"Machine: %s", uts.machine); + } + + LOG_VERBOSE(0, "Processor : %s", "unknown"); + LOG_VERBOSE(0, "CPU freq. : %i MHz", 0); } @@ -28,6 +44,7 @@ const char* PosixDevice::get_hostname() void PosixDevice::set_hostname(const char* hostname) { _hostname = hostname; + SDL_SetWindowTitle(monitor.window, hostname); } const char* PosixDevice::get_core_version() { @@ -73,7 +90,14 @@ bool PosixDevice::get_backlight_power() void PosixDevice::update_backlight() { - monitor_backlight(_backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0); + uint8_t level = _backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0; + + SDL_SetTextureColorMod(monitor.texture, level, level, level); + // window_update(&monitor); + monitor.sdl_refr_qry = true; + // monitor_sdl_refr(NULL); + const lv_area_t area = {1,1,0,0}; + //monitor_flush(NULL,&area,NULL); } size_t PosixDevice::get_free_max_block() diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 6142cdb8..eb7494bc 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -49,6 +49,7 @@ const char* Win32Device::get_hostname() void Win32Device::set_hostname(const char* hostname) { _hostname = hostname; + SDL_SetWindowTitle(monitor.window, hostname); } const char* Win32Device::get_core_version() { diff --git a/user_setups/linux_sdl/linux_sdl_64bits.ini b/user_setups/linux_sdl/linux_sdl_64bits.ini index ac81d624..7587733c 100644 --- a/user_setups/linux_sdl/linux_sdl_64bits.ini +++ b/user_setups/linux_sdl/linux_sdl_64bits.ini @@ -55,6 +55,7 @@ lib_deps = ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip https://github.com/eclipse/paho.mqtt.c.git bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + https://github.com/fvanroie/lv_drivers lib_ignore = paho From 34292fb6846a8c826e9ebd5abaed4bedd858ccf9 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 20:24:30 +0100 Subject: [PATCH 165/236] Remove lv_drivers --- lib/lv_drivers/.gitignore | 1 - lib/lv_drivers/LICENSE | 21 -- lib/lv_drivers/README.md | 7 - lib/lv_drivers/display/R61581.c | 425 ----------------------- lib/lv_drivers/display/R61581.h | 57 --- lib/lv_drivers/display/SHARP_MIP.c | 182 ---------- lib/lv_drivers/display/SHARP_MIP.h | 63 ---- lib/lv_drivers/display/SSD1963.c | 292 ---------------- lib/lv_drivers/display/SSD1963.h | 150 -------- lib/lv_drivers/display/ST7565.c | 289 --------------- lib/lv_drivers/display/ST7565.h | 58 ---- lib/lv_drivers/display/UC1610.c | 206 ----------- lib/lv_drivers/display/UC1610.h | 58 ---- lib/lv_drivers/display/display.mk | 12 - lib/lv_drivers/display/fbdev.c | 241 ------------- lib/lv_drivers/display/fbdev.h | 58 ---- lib/lv_drivers/display/monitor.c | 425 ----------------------- lib/lv_drivers/display/monitor.h | 61 ---- lib/lv_drivers/docs/astyle_c | 1 - lib/lv_drivers/docs/astyle_h | 1 - lib/lv_drivers/indev/AD_touch.c | 383 -------------------- lib/lv_drivers/indev/AD_touch.h | 120 ------- lib/lv_drivers/indev/FT5406EE8.c | 179 ---------- lib/lv_drivers/indev/FT5406EE8.h | 56 --- lib/lv_drivers/indev/XPT2046.cpp | 210 ----------- lib/lv_drivers/indev/XPT2046.h | 56 --- lib/lv_drivers/indev/XPT2046_alt_drv.cpp | 75 ---- lib/lv_drivers/indev/XPT2046_alt_drv.h | 56 --- lib/lv_drivers/indev/evdev.c | 223 ------------ lib/lv_drivers/indev/evdev.h | 73 ---- lib/lv_drivers/indev/indev.mk | 12 - lib/lv_drivers/indev/keyboard.c | 130 ------- lib/lv_drivers/indev/keyboard.h | 78 ----- lib/lv_drivers/indev/libinput.c | 175 ---------- lib/lv_drivers/indev/libinput_drv.h | 74 ---- lib/lv_drivers/indev/mouse.c | 100 ------ lib/lv_drivers/indev/mouse.h | 78 ----- lib/lv_drivers/indev/mousewheel.c | 100 ------ lib/lv_drivers/indev/mousewheel.h | 79 ----- lib/lv_drivers/library.json | 13 - lib/lv_drivers/lv_drivers.mk | 10 - lib/lv_drivers/lv_drv_conf_templ.h | 357 ------------------- lib/lv_drivers/win_drv.c | 318 ----------------- lib/lv_drivers/win_drv.h | 60 ---- 44 files changed, 5623 deletions(-) delete mode 100644 lib/lv_drivers/.gitignore delete mode 100644 lib/lv_drivers/LICENSE delete mode 100644 lib/lv_drivers/README.md delete mode 100644 lib/lv_drivers/display/R61581.c delete mode 100644 lib/lv_drivers/display/R61581.h delete mode 100644 lib/lv_drivers/display/SHARP_MIP.c delete mode 100644 lib/lv_drivers/display/SHARP_MIP.h delete mode 100644 lib/lv_drivers/display/SSD1963.c delete mode 100644 lib/lv_drivers/display/SSD1963.h delete mode 100644 lib/lv_drivers/display/ST7565.c delete mode 100644 lib/lv_drivers/display/ST7565.h delete mode 100644 lib/lv_drivers/display/UC1610.c delete mode 100644 lib/lv_drivers/display/UC1610.h delete mode 100644 lib/lv_drivers/display/display.mk delete mode 100644 lib/lv_drivers/display/fbdev.c delete mode 100644 lib/lv_drivers/display/fbdev.h delete mode 100644 lib/lv_drivers/display/monitor.c delete mode 100644 lib/lv_drivers/display/monitor.h delete mode 100644 lib/lv_drivers/docs/astyle_c delete mode 100644 lib/lv_drivers/docs/astyle_h delete mode 100644 lib/lv_drivers/indev/AD_touch.c delete mode 100644 lib/lv_drivers/indev/AD_touch.h delete mode 100644 lib/lv_drivers/indev/FT5406EE8.c delete mode 100644 lib/lv_drivers/indev/FT5406EE8.h delete mode 100644 lib/lv_drivers/indev/XPT2046.cpp delete mode 100644 lib/lv_drivers/indev/XPT2046.h delete mode 100644 lib/lv_drivers/indev/XPT2046_alt_drv.cpp delete mode 100644 lib/lv_drivers/indev/XPT2046_alt_drv.h delete mode 100644 lib/lv_drivers/indev/evdev.c delete mode 100644 lib/lv_drivers/indev/evdev.h delete mode 100644 lib/lv_drivers/indev/indev.mk delete mode 100644 lib/lv_drivers/indev/keyboard.c delete mode 100644 lib/lv_drivers/indev/keyboard.h delete mode 100644 lib/lv_drivers/indev/libinput.c delete mode 100644 lib/lv_drivers/indev/libinput_drv.h delete mode 100644 lib/lv_drivers/indev/mouse.c delete mode 100644 lib/lv_drivers/indev/mouse.h delete mode 100644 lib/lv_drivers/indev/mousewheel.c delete mode 100644 lib/lv_drivers/indev/mousewheel.h delete mode 100644 lib/lv_drivers/library.json delete mode 100644 lib/lv_drivers/lv_drivers.mk delete mode 100644 lib/lv_drivers/lv_drv_conf_templ.h delete mode 100644 lib/lv_drivers/win_drv.c delete mode 100644 lib/lv_drivers/win_drv.h diff --git a/lib/lv_drivers/.gitignore b/lib/lv_drivers/.gitignore deleted file mode 100644 index 2372cca0..00000000 --- a/lib/lv_drivers/.gitignore +++ /dev/null @@ -1 +0,0 @@ -**/*.o \ No newline at end of file diff --git a/lib/lv_drivers/LICENSE b/lib/lv_drivers/LICENSE deleted file mode 100644 index cc227abe..00000000 --- a/lib/lv_drivers/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 LittlevGL - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/lib/lv_drivers/README.md b/lib/lv_drivers/README.md deleted file mode 100644 index 160d08ae..00000000 --- a/lib/lv_drivers/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Display and Touch pad drivers - -Display controller and touchpad driver to can be directly used with [LittlevGL](https://littlevgl.com). - -To learn more about using drivers in LittlevGL visit the [Porting guide](https://littlevgl.com/porting). - -If you used a new display or touch pad driver with LittlevGL please share it with other people! diff --git a/lib/lv_drivers/display/R61581.c b/lib/lv_drivers/display/R61581.c deleted file mode 100644 index 4d21bff9..00000000 --- a/lib/lv_drivers/display/R61581.c +++ /dev/null @@ -1,425 +0,0 @@ -/** - * @file R61581.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "R61581.h" -#if USE_R61581 != 0 - -#include -#include "lvgl/lv_core/lv_vdb.h" -#include LV_DRV_DISP_INCLUDE -#include LV_DRV_DELAY_INCLUDE - -/********************* - * DEFINES - *********************/ -#define R61581_CMD_MODE 0 -#define R61581_DATA_MODE 1 - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static void r61581_io_init(void); -static void r61581_reset(void); -static void r61581_set_tft_spec(void); -static inline void r61581_cmd_mode(void); -static inline void r61581_data_mode(void); -static inline void r61581_cmd(uint8_t cmd); -static inline void r61581_data(uint8_t data); - -/********************** - * STATIC VARIABLES - **********************/ -static bool cmd_mode = true; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the R61581 display controller - * @return HW_RES_OK or any error from hw_res_t enum - */ -void r61581_init(void) -{ - r61581_io_init(); - - /*Slow mode until the PLL is not started in the display controller*/ - LV_DRV_DISP_PAR_SLOW; - - r61581_reset(); - - r61581_set_tft_spec(); - - r61581_cmd(0x13); //SET display on - - r61581_cmd(0x29); //SET display on - LV_DRV_DELAY_MS(30); - - /*Parallel to max speed*/ - LV_DRV_DISP_PAR_FAST; -} - -void r61581_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p) -{ - /*Return if the area is out the screen*/ - if(x2 < 0) return; - if(y2 < 0) return; - if(x1 > R61581_HOR_RES - 1) return; - if(y1 > R61581_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > R61581_HOR_RES - 1 ? R61581_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > R61581_VER_RES - 1 ? R61581_VER_RES - 1 : y2; - - - //Set the rectangular area - r61581_cmd(0x002A); - r61581_data(act_x1 >> 8); - r61581_data(0x00FF & act_x1); - r61581_data(act_x2 >> 8); - r61581_data(0x00FF & act_x2); - - r61581_cmd(0x002B); - r61581_data(act_y1 >> 8); - r61581_data(0x00FF & act_y1); - r61581_data(act_y2 >> 8); - r61581_data(0x00FF & act_y2); - - r61581_cmd(0x2c); - - int16_t i; - uint16_t full_w = x2 - x1 + 1; - - r61581_data_mode(); - -#if LV_COLOR_DEPTH == 16 - uint16_t act_w = act_x2 - act_x1 + 1; - for(i = act_y1; i <= act_y2; i++) { - LV_DRV_DISP_PAR_WR_ARRAY((uint16_t *)color_p, act_w); - color_p += full_w; - } -#else - int16_t j; - for(i = act_y1; i <= act_y2; i++) { - for(j = 0; j <= act_x2 - act_x1 + 1; j++) { - LV_DRV_DISP_PAR_WR_WORD(lv_color_to16(color_p[j])); - color_p += full_w; - } - } -#endif - - lv_flush_ready(); -} - -void r61581_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color) -{ - /*Return if the area is out the screen*/ - if(x2 < 0) return; - if(y2 < 0) return; - if(x1 > R61581_HOR_RES - 1) return; - if(y1 > R61581_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > R61581_HOR_RES - 1 ? R61581_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > R61581_VER_RES - 1 ? R61581_VER_RES - 1 : y2; - - //Set the rectangular area - r61581_cmd(0x002A); - r61581_data(act_x1 >> 8); - r61581_data(0x00FF & act_x1); - r61581_data(act_x2 >> 8); - r61581_data(0x00FF & act_x2); - - r61581_cmd(0x002B); - r61581_data(act_y1 >> 8); - r61581_data(0x00FF & act_y1); - r61581_data(act_y2 >> 8); - r61581_data(0x00FF & act_y2); - - r61581_cmd(0x2c); - - r61581_data_mode(); - - uint16_t color16 = lv_color_to16(color); - uint32_t size = (act_x2 - act_x1 + 1) * (act_y2 - act_y1 + 1); - uint32_t i; - for(i = 0; i < size; i++) { - LV_DRV_DISP_PAR_WR_WORD(color16); - } -} - -void r61581_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p) -{ - /*Return if the area is out the screen*/ - if(x2 < 0) return; - if(y2 < 0) return; - if(x1 > R61581_HOR_RES - 1) return; - if(y1 > R61581_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > R61581_HOR_RES - 1 ? R61581_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > R61581_VER_RES - 1 ? R61581_VER_RES - 1 : y2; - - - //Set the rectangular area - r61581_cmd(0x002A); - r61581_data(act_x1 >> 8); - r61581_data(0x00FF & act_x1); - r61581_data(act_x2 >> 8); - r61581_data(0x00FF & act_x2); - - r61581_cmd(0x002B); - r61581_data(act_y1 >> 8); - r61581_data(0x00FF & act_y1); - r61581_data(act_y2 >> 8); - r61581_data(0x00FF & act_y2); - - r61581_cmd(0x2c); - - int16_t i; - uint16_t full_w = x2 - x1 + 1; - - r61581_data_mode(); - -#if LV_COLOR_DEPTH == 16 - uint16_t act_w = act_x2 - act_x1 + 1; - for(i = act_y1; i <= act_y2; i++) { - LV_DRV_DISP_PAR_WR_ARRAY((uint16_t *)color_p, act_w); - color_p += full_w; - } -#else - int16_t j; - for(i = act_y1; i <= act_y2; i++) { - for(j = 0; j <= act_x2 - act_x1 + 1; j++) { - LV_DRV_DISP_PAR_WR_WORD(lv_color_to16(color_p[j])); - color_p += full_w; - } - } -#endif -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -/** - * Io init - */ -static void r61581_io_init(void) -{ - LV_DRV_DISP_CMD_DATA(R61581_CMD_MODE) - cmd_mode = true; -} - -/** - * Reset - */ -static void r61581_reset(void) -{ - /*Hardware reset*/ - LV_DRV_DISP_RST(1); - LV_DRV_DELAY_MS(50); - LV_DRV_DISP_RST(0); - LV_DRV_DELAY_MS(50); - LV_DRV_DISP_RST(1); - LV_DRV_DELAY_MS(50); - - /*Chip enable*/ - LV_DRV_DISP_PAR_CS(1); - LV_DRV_DELAY_MS(10); - LV_DRV_DISP_PAR_CS(0); - LV_DRV_DELAY_MS(5); - - /*Software reset*/ - r61581_cmd(0x01); - LV_DRV_DELAY_MS(20); - - r61581_cmd(0x01); - LV_DRV_DELAY_MS(20); - - r61581_cmd(0x01); - LV_DRV_DELAY_MS(20); -} - -/** - * TFT specific initialization - */ -static void r61581_set_tft_spec(void) -{ - r61581_cmd(0xB0); - r61581_data(0x00); - - r61581_cmd(0xB3); - r61581_data(0x02); - r61581_data(0x00); - r61581_data(0x00); - r61581_data(0x10); - - r61581_cmd(0xB4); - r61581_data(0x00);//0X10 - - r61581_cmd(0xB9); //PWM - r61581_data(0x01); - r61581_data(0xFF); //FF brightness - r61581_data(0xFF); - r61581_data(0x18); - - /*Panel Driving Setting*/ - r61581_cmd(0xC0); - r61581_data(0x02); - r61581_data(0x3B); - r61581_data(0x00); - r61581_data(0x00); - r61581_data(0x00); - r61581_data(0x01); - r61581_data(0x00);//NW - r61581_data(0x43); - - /*Display Timing Setting for Normal Mode */ - r61581_cmd(0xC1); - r61581_data(0x08); - r61581_data(0x15); //CLOCK - r61581_data(R61581_VFP); - r61581_data(R61581_VBP); - - /*Source/VCOM/Gate Driving Timing Setting*/ - r61581_cmd(0xC4); - r61581_data(0x15); - r61581_data(0x03); - r61581_data(0x03); - r61581_data(0x01); - - /*Interface Setting*/ - r61581_cmd(0xC6); - r61581_data((R61581_DPL << 0) | - (R61581_EPL << 1) | - (R61581_HSPL << 4) | - (R61581_VSPL << 5)); - - /*Gamma Set*/ - r61581_cmd(0xC8); - r61581_data(0x0c); - r61581_data(0x05); - r61581_data(0x0A); - r61581_data(0x6B); - r61581_data(0x04); - r61581_data(0x06); - r61581_data(0x15); - r61581_data(0x10); - r61581_data(0x00); - r61581_data(0x31); - - - r61581_cmd(0x36); - if(R61581_ORI == 0) r61581_data(0xE0); - else r61581_data(0x20); - - r61581_cmd(0x0C); - r61581_data(0x55); - - r61581_cmd(0x3A); - r61581_data(0x55); - - r61581_cmd(0x38); - - r61581_cmd(0xD0); - r61581_data(0x07); - r61581_data(0x07); - r61581_data(0x14); - r61581_data(0xA2); - - r61581_cmd(0xD1); - r61581_data(0x03); - r61581_data(0x5A); - r61581_data(0x10); - - r61581_cmd(0xD2); - r61581_data(0x03); - r61581_data(0x04); - r61581_data(0x04); - - r61581_cmd(0x11); - LV_DRV_DELAY_MS(10); - - r61581_cmd(0x2A); - r61581_data(0x00); - r61581_data(0x00); - r61581_data(((R61581_HOR_RES - 1) >> 8) & 0XFF); - r61581_data((R61581_HOR_RES - 1) & 0XFF); - - r61581_cmd(0x2B); - r61581_data(0x00); - r61581_data(0x00); - r61581_data(((R61581_VER_RES - 1) >> 8) & 0XFF); - r61581_data((R61581_VER_RES - 1) & 0XFF); - - LV_DRV_DELAY_MS(10); - - r61581_cmd(0x29); - LV_DRV_DELAY_MS(5); - - r61581_cmd(0x2C); - LV_DRV_DELAY_MS(5); -} - -/** - * Command mode - */ -static inline void r61581_cmd_mode(void) -{ - if(cmd_mode == false) { - LV_DRV_DISP_CMD_DATA(R61581_CMD_MODE) - cmd_mode = true; - } -} - -/** - * Data mode - */ -static inline void r61581_data_mode(void) -{ - if(cmd_mode != false) { - LV_DRV_DISP_CMD_DATA(R61581_DATA_MODE); - cmd_mode = false; - } -} - -/** - * Write command - * @param cmd the command - */ -static inline void r61581_cmd(uint8_t cmd) -{ - r61581_cmd_mode(); - LV_DRV_DISP_PAR_WR_WORD(cmd); -} - -/** - * Write data - * @param data the data - */ -static inline void r61581_data(uint8_t data) -{ - r61581_data_mode(); - LV_DRV_DISP_PAR_WR_WORD(data); -} -#endif diff --git a/lib/lv_drivers/display/R61581.h b/lib/lv_drivers/display/R61581.h deleted file mode 100644 index 3ba4ff93..00000000 --- a/lib/lv_drivers/display/R61581.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file R61581.h - * - */ - -#ifndef R61581_H -#define R61581_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_R61581 - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void r61581_init(void); -void r61581_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); -void r61581_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); -void r61581_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); -/********************** - * MACROS - **********************/ - -#endif /* USE_R61581 */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* R61581_H */ diff --git a/lib/lv_drivers/display/SHARP_MIP.c b/lib/lv_drivers/display/SHARP_MIP.c deleted file mode 100644 index 129ac2f3..00000000 --- a/lib/lv_drivers/display/SHARP_MIP.c +++ /dev/null @@ -1,182 +0,0 @@ -/** - * @file SHARP_MIP.c - * - */ - -/*------------------------------------------------------------------------------------------------- - * SHARP memory in pixel monochrome display series - * LS012B7DD01 (184x38 pixels.) - * LS013B7DH03 (128x128 pixels.) - * LS013B7DH05 (144x168 pixels.) - * LS027B7DH01 (400x240 pixels.) (tested) - * LS032B7DD02 (336x536 pixels.) - * LS044Q7DH01 (320x240 pixels.) - * - * These displays need periodic com inversion, there are two ways : - * - software com inversion : - * define SHARP_MIP_SOFT_COM_INVERSION 1 and set EXTMODE display pin LOW, - * call sharp_mip_com_inversion() periodically - * - hardware com inversion with EXTCOMIN display pin : - * define SHARP_MIP_SOFT_COM_INVERSION 0, - * set EXTMODE display pin HIGH and handle - * EXTCOMIN waveform (for example with mcu pwm output), - * see datasheet pages 8-12 for details - * - * VDB size : (LV_VER_RES / X) * (2 + LV_HOR_RES / 8) + 2 bytes, structure : - * [FRAME_HEADER (1 byte)] [GATE_ADDR (1 byte )] [LINE_DATA (LV_HOR_RES / 8 bytes)] 1st line - * [DUMMY (1 byte)] [GATE_ADDR (1 byte )] [LINE_DATA (LV_HOR_RES / 8 bytes)] 2nd line - * ........................................................................................... - * [DUMMY (1 byte)] [GATE_ADDR (1 byte )] [LINE_DATA (LV_HOR_RES / 8 bytes)] last line - * [DUMMY (2 bytes)] - * - * Since extra bytes (dummy, addresses, header) are stored in VDB, we need to use - * an "oversized" VDB. Buffer declaration in "lv_port_disp.c" becomes for example : - * static lv_disp_buf_t disp_buf; - * static uint8_t buf[(LV_VER_RES_MAX / X) * (2 + (LV_HOR_RES_MAX / 8)) + 2]; - * lv_disp_buf_init(&disp_buf, buf, NULL, LV_VER_RES_MAX * LV_HOR_RES_MAX / X); - *-----------------------------------------------------------------------------------------------*/ - -/********************* - * INCLUDES - *********************/ - -#include "SHARP_MIP.h" - -#if USE_SHARP_MIP - -#include -#include LV_DRV_DISP_INCLUDE -#include LV_DRV_DELAY_INCLUDE - -/********************* - * DEFINES - *********************/ - -#define SHARP_MIP_HEADER 0 -#define SHARP_MIP_UPDATE_RAM_FLAG (1 << 7) /* (M0) Mode flag : H -> update memory, L -> maintain memory */ -#define SHARP_MIP_COM_INVERSION_FLAG (1 << 6) /* (M1) Frame inversion flag : relevant when EXTMODE = L, */ - /* H -> outputs VCOM = H, L -> outputs VCOM = L */ -#define SHARP_MIP_CLEAR_SCREEN_FLAG (1 << 5) /* (M2) All clear flag : H -> clear all pixels */ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ - -#if SHARP_MIP_SOFT_COM_INVERSION -static bool_t com_output_state = false; -#endif - -/********************** - * MACROS - **********************/ - -/* - * Return the VDB byte index corresponding to the pixel - * relatives coordinates (x, y) in the area. - * The area is rounded to a whole screen line. - */ -#define BUFIDX(x, y) (((x) >> 3) + ((y) * (2 + (SHARP_MIP_HOR_RES >> 3))) + 2) - -/* - * Return the byte bitmask of a pixel bit corresponding - * to VDB arrangement (8 pixels per byte on lines). - */ -#define PIXIDX(x) SHARP_MIP_REV_BYTE(1 << ((x) & 7)) - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -void sharp_mip_init(void) { - /* These displays have nothing to initialize */ -} - - -void sharp_mip_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) { - - /*Return if the area is out the screen*/ - if(area->y2 < 0) return; - if(area->y1 > SHARP_MIP_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - uint16_t act_y1 = area->y1 < 0 ? 0 : area->y1; - uint16_t act_y2 = area->y2 > SHARP_MIP_VER_RES - 1 ? SHARP_MIP_VER_RES - 1 : area->y2; - - uint8_t * buf = (uint8_t *) color_p; /*Get the buffer address*/ - uint16_t buf_h = (act_y2 - act_y1 + 1); /*Number of buffer lines*/ - uint16_t buf_size = buf_h * (2 + SHARP_MIP_HOR_RES / 8) + 2; /*Buffer size in bytes */ - - /* Set lines to flush dummy byte & gate address in VDB*/ - for(uint16_t act_y = 0 ; act_y < buf_h ; act_y++) { - buf[BUFIDX(0, act_y) - 1] = SHARP_MIP_REV_BYTE((act_y1 + act_y + 1)); - buf[BUFIDX(0, act_y) - 2] = 0; - } - - /* Set last dummy two bytes in VDB */ - buf[BUFIDX(0, buf_h) - 1] = 0; - buf[BUFIDX(0, buf_h) - 2] = 0; - - /* Set frame header in VDB */ - buf[0] = SHARP_MIP_HEADER | - SHARP_MIP_UPDATE_RAM_FLAG; - - /* Write the frame on display memory */ - LV_DRV_DISP_SPI_CS(1); - LV_DRV_DISP_SPI_WR_ARRAY(buf, buf_size); - LV_DRV_DISP_SPI_CS(0); - - lv_disp_flush_ready(disp_drv); -} - -void sharp_mip_set_px(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa) { - (void) disp_drv; - (void) buf_w; - (void) opa; - - if (lv_color_to1(color) != 0) { - buf[BUFIDX(x, y)] |= PIXIDX(x); /*Set VDB pixel bit to 1 for other colors than BLACK*/ - } else { - buf[BUFIDX(x, y)] &= ~PIXIDX(x); /*Set VDB pixel bit to 0 for BLACK color*/ - } -} - -void sharp_mip_rounder(lv_disp_drv_t * disp_drv, lv_area_t * area) { - (void) disp_drv; - - /* Round area to a whole line */ - area->x1 = 0; - area->x2 = SHARP_MIP_HOR_RES - 1; -} - -#if SHARP_MIP_SOFT_COM_INVERSION -void sharp_mip_com_inversion(void) { - uint8_t inversion_header[2] = {0}; - - /* Set inversion header */ - if (com_output_state) { - com_output_state = false; - } else { - inversion_header[0] |= SHARP_MIP_COM_INVERSION_FLAG; - com_output_state = true; - } - - /* Write inversion header on display memory */ - LV_DRV_DISP_SPI_CS(1); - LV_DRV_DISP_SPI_WR_ARRAY(inversion_header, 2); - LV_DRV_DISP_SPI_CS(0); -} -#endif - -/********************** - * STATIC FUNCTIONS - **********************/ - -#endif diff --git a/lib/lv_drivers/display/SHARP_MIP.h b/lib/lv_drivers/display/SHARP_MIP.h deleted file mode 100644 index c10d8459..00000000 --- a/lib/lv_drivers/display/SHARP_MIP.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @file SHARP_MIP.h - * - */ - -#ifndef SHARP_MIP_H -#define SHARP_MIP_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_SHARP_MIP - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void sharp_mip_init(void); -void sharp_mip_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); -void sharp_mip_rounder(lv_disp_drv_t * disp_drv, lv_area_t * area); -void sharp_mip_set_px(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa); -#if SHARP_MIP_SOFT_COM_INVERSION -void sharp_mip_com_inversion(void); -#endif - -/********************** - * MACROS - **********************/ - -#endif /* USE_SHARP_MIP */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* SHARP_MIP_H */ diff --git a/lib/lv_drivers/display/SSD1963.c b/lib/lv_drivers/display/SSD1963.c deleted file mode 100644 index c961066b..00000000 --- a/lib/lv_drivers/display/SSD1963.c +++ /dev/null @@ -1,292 +0,0 @@ -/** - * @file SSD1963.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "SSD1963.h" -#if USE_SSD1963 - -#include -#include LV_DRV_DISP_INCLUDE -#include LV_DRV_DELAY_INCLUDE - -/********************* - * DEFINES - *********************/ -#define SSD1963_CMD_MODE 0 -#define SSD1963_DATA_MODE 1 - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static inline void ssd1963_cmd_mode(void); -static inline void ssd1963_data_mode(void); -static inline void ssd1963_cmd(uint8_t cmd); -static inline void ssd1963_data(uint8_t data); -static void ssd1963_io_init(void); -static void ssd1963_reset(void); -static void ssd1963_set_clk(void); -static void ssd1963_set_tft_spec(void); -static void ssd1963_init_bl(void); - -/********************** - * STATIC VARIABLES - **********************/ -static bool cmd_mode = true; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -void ssd1963_init(void) -{ - - LV_DRV_DISP_CMD_DATA(SSD1963_CMD_MODE); - cmd_mode = true; - - LV_DRV_DELAY_MS(250); - - - ssd1963_cmd(0x00E2); //PLL multiplier, set PLL clock to 120M - ssd1963_data(0x0023); //N=0x36 for 6.5M, 0x23 for 10M crystal - ssd1963_data(0x0002); - ssd1963_data(0x0004); - ssd1963_cmd(0x00E0); // PLL enable - ssd1963_data(0x0001); - LV_DRV_DELAY_MS(1); - ssd1963_cmd(0x00E0); - ssd1963_data(0x0003); // now, use PLL output as system clock - LV_DRV_DELAY_MS(1); - ssd1963_cmd(0x0001); // software reset - LV_DRV_DELAY_MS(1); - ssd1963_cmd(0x00E6); //PLL setting for PCLK, depends on resolution - - ssd1963_data(0x0001); //HX8257C - ssd1963_data(0x0033); //HX8257C - ssd1963_data(0x0033); //HX8257C - - - ssd1963_cmd(0x00B0); //LCD SPECIFICATION - ssd1963_data(0x0020); - ssd1963_data(0x0000); - ssd1963_data(((SSD1963_HOR_RES - 1) >> 8) & 0X00FF); //Set HDP - ssd1963_data((SSD1963_HOR_RES - 1) & 0X00FF); - ssd1963_data(((SSD1963_VER_RES - 1) >> 8) & 0X00FF); //Set VDP - ssd1963_data((SSD1963_VER_RES - 1) & 0X00FF); - ssd1963_data(0x0000); - LV_DRV_DELAY_MS(1);//Delay10us(5); - ssd1963_cmd(0x00B4); //HSYNC - ssd1963_data((SSD1963_HT >> 8) & 0X00FF); //Set HT - ssd1963_data(SSD1963_HT & 0X00FF); - ssd1963_data((SSD1963_HPS >> 8) & 0X00FF); //Set HPS - ssd1963_data(SSD1963_HPS & 0X00FF); - ssd1963_data(SSD1963_HPW); //Set HPW - ssd1963_data((SSD1963_LPS >> 8) & 0X00FF); //SetLPS - ssd1963_data(SSD1963_LPS & 0X00FF); - ssd1963_data(0x0000); - - ssd1963_cmd(0x00B6); //VSYNC - ssd1963_data((SSD1963_VT >> 8) & 0X00FF); //Set VT - ssd1963_data(SSD1963_VT & 0X00FF); - ssd1963_data((SSD1963_VPS >> 8) & 0X00FF); //Set VPS - ssd1963_data(SSD1963_VPS & 0X00FF); - ssd1963_data(SSD1963_VPW); //Set VPW - ssd1963_data((SSD1963_FPS >> 8) & 0X00FF); //Set FPS - ssd1963_data(SSD1963_FPS & 0X00FF); - - ssd1963_cmd(0x00B8); - ssd1963_data(0x000f); //GPIO is controlled by host GPIO[3:0]=output GPIO[0]=1 LCD ON GPIO[0]=1 LCD OFF - ssd1963_data(0x0001); //GPIO0 normal - - ssd1963_cmd(0x00BA); - ssd1963_data(0x0001); //GPIO[0] out 1 --- LCD display on/off control PIN - - ssd1963_cmd(0x0036); //rotation - ssd1963_data(0x0008); //RGB=BGR - - ssd1963_cmd(0x003A); //Set the current pixel format for RGB image data - ssd1963_data(0x0050); //16-bit/pixel - - ssd1963_cmd(0x00F0); //Pixel Data Interface Format - ssd1963_data(0x0003); //16-bit(565 format) data - - ssd1963_cmd(0x00BC); - ssd1963_data(0x0040); //contrast value - ssd1963_data(0x0080); //brightness value - ssd1963_data(0x0040); //saturation value - ssd1963_data(0x0001); //Post Processor Enable - - LV_DRV_DELAY_MS(1); - - ssd1963_cmd(0x0029); //display on - - ssd1963_cmd(0x00BE); //set PWM for B/L - ssd1963_data(0x0006); - ssd1963_data(0x0080); - ssd1963_data(0x0001); - ssd1963_data(0x00f0); - ssd1963_data(0x0000); - ssd1963_data(0x0000); - - ssd1963_cmd(0x00d0); - ssd1963_data(0x000d); - - //DisplayBacklightOn(); - - LV_DRV_DELAY_MS(30); -} - -void ssd1963_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) -{ - - /*Return if the area is out the screen*/ - if(area->x2 < 0) return; - if(area->y2 < 0) return; - if(area->x1 > SSD1963_HOR_RES - 1) return; - if(area->y1 > SSD1963_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = area->x1 < 0 ? 0 : area->x1; - int32_t act_y1 = area->y1 < 0 ? 0 : area->y1; - int32_t act_x2 = area->x2 > SSD1963_HOR_RES - 1 ? SSD1963_HOR_RES - 1 : area->x2; - int32_t act_y2 = area->y2 > SSD1963_VER_RES - 1 ? SSD1963_VER_RES - 1 : area->y2; - - //Set the rectangular area - ssd1963_cmd(0x002A); - ssd1963_data(act_x1 >> 8); - ssd1963_data(0x00FF & act_x1); - ssd1963_data(act_x2 >> 8); - ssd1963_data(0x00FF & act_x2); - - ssd1963_cmd(0x002B); - ssd1963_data(act_y1 >> 8); - ssd1963_data(0x00FF & act_y1); - ssd1963_data(act_y2 >> 8); - ssd1963_data(0x00FF & act_y2); - - ssd1963_cmd(0x2c); - int16_t i; - uint16_t full_w = area->x2 - area->x1 + 1; - - ssd1963_data_mode(); - LV_DRV_DISP_PAR_CS(0); -#if LV_COLOR_DEPTH == 16 - uint16_t act_w = act_x2 - act_x1 + 1; - for(i = act_y1; i <= act_y2; i++) { - LV_DRV_DISP_PAR_WR_ARRAY((uint16_t *)color_p, act_w); - color_p += full_w; - } - LV_DRV_DISP_PAR_CS(1); -#else - int16_t j; - for(i = act_y1; i <= act_y2; i++) { - for(j = 0; j <= act_x2 - act_x1 + 1; j++) { - LV_DRV_DISP_PAR_WR_WORD(color_p[j]); - color_p += full_w; - } - } -#endif - - lv_disp_flush_ready(disp_drv); -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -static void ssd1963_io_init(void) -{ - LV_DRV_DISP_CMD_DATA(SSD1963_CMD_MODE); - cmd_mode = true; -} - -static void ssd1963_reset(void) -{ - /*Hardware reset*/ - LV_DRV_DISP_RST(1); - LV_DRV_DELAY_MS(50); - LV_DRV_DISP_RST(0); - LV_DRV_DELAY_MS(50); - LV_DRV_DISP_RST(1); - LV_DRV_DELAY_MS(50); - - /*Chip enable*/ - LV_DRV_DISP_PAR_CS(0); - LV_DRV_DELAY_MS(10); - LV_DRV_DISP_PAR_CS(1); - LV_DRV_DELAY_MS(5); - - /*Software reset*/ - ssd1963_cmd(0x01); - LV_DRV_DELAY_MS(20); - - ssd1963_cmd(0x01); - LV_DRV_DELAY_MS(20); - - ssd1963_cmd(0x01); - LV_DRV_DELAY_MS(20); - -} - -/** - * Command mode - */ -static inline void ssd1963_cmd_mode(void) -{ - if(cmd_mode == false) { - LV_DRV_DISP_CMD_DATA(SSD1963_CMD_MODE); - cmd_mode = true; - } -} - -/** - * Data mode - */ -static inline void ssd1963_data_mode(void) -{ - if(cmd_mode != false) { - LV_DRV_DISP_CMD_DATA(SSD1963_DATA_MODE); - cmd_mode = false; - } -} - -/** - * Write command - * @param cmd the command - */ -static inline void ssd1963_cmd(uint8_t cmd) -{ - - LV_DRV_DISP_PAR_CS(0); - ssd1963_cmd_mode(); - LV_DRV_DISP_PAR_WR_WORD(cmd); - LV_DRV_DISP_PAR_CS(1); - -} - -/** - * Write data - * @param data the data - */ -static inline void ssd1963_data(uint8_t data) -{ - - LV_DRV_DISP_PAR_CS(0); - ssd1963_data_mode(); - LV_DRV_DISP_PAR_WR_WORD(data); - LV_DRV_DISP_PAR_CS(1); - -} - -#endif diff --git a/lib/lv_drivers/display/SSD1963.h b/lib/lv_drivers/display/SSD1963.h deleted file mode 100644 index 49639f59..00000000 --- a/lib/lv_drivers/display/SSD1963.h +++ /dev/null @@ -1,150 +0,0 @@ -/** - * @file SSD1963.h - * - */ - -#ifndef SSD1963_H -#define SSD1963_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_SSD1963 - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ -// SSD1963 command table -#define CMD_NOP 0x00 //No operation -#define CMD_SOFT_RESET 0x01 //Software reset -#define CMD_GET_PWR_MODE 0x0A //Get the current power mode -#define CMD_GET_ADDR_MODE 0x0B //Get the frame memory to the display panel read order -#define CMD_GET_PIXEL_FORMAT 0x0C //Get the current pixel format -#define CMD_GET_DISPLAY_MODE 0x0D //Returns the display mode -#define CMD_GET_SIGNAL_MODE 0x0E // -#define CMD_GET_DIAGNOSTIC 0x0F -#define CMD_ENT_SLEEP 0x10 -#define CMD_EXIT_SLEEP 0x11 -#define CMD_ENT_PARTIAL_MODE 0x12 -#define CMD_ENT_NORMAL_MODE 0x13 -#define CMD_EXIT_INVERT_MODE 0x20 -#define CMD_ENT_INVERT_MODE 0x21 -#define CMD_SET_GAMMA 0x26 -#define CMD_BLANK_DISPLAY 0x28 -#define CMD_ON_DISPLAY 0x29 -#define CMD_SET_COLUMN 0x2A -#define CMD_SET_PAGE 0x2B -#define CMD_WR_MEMSTART 0x2C -#define CMD_RD_MEMSTART 0x2E -#define CMD_SET_PARTIAL_AREA 0x30 -#define CMD_SET_SCROLL_AREA 0x33 -#define CMD_SET_TEAR_OFF 0x34 //synchronization information is not sent from the display -#define CMD_SET_TEAR_ON 0x35 //sync. information is sent from the display -#define CMD_SET_ADDR_MODE 0x36 //set fram buffer read order to the display panel -#define CMD_SET_SCROLL_START 0x37 -#define CMD_EXIT_IDLE_MODE 0x38 -#define CMD_ENT_IDLE_MODE 0x39 -#define CMD_SET_PIXEL_FORMAT 0x3A //defines how many bits per pixel is used -#define CMD_WR_MEM_AUTO 0x3C -#define CMD_RD_MEM_AUTO 0x3E -#define CMD_SET_TEAR_SCANLINE 0x44 -#define CMD_GET_SCANLINE 0x45 -#define CMD_RD_DDB_START 0xA1 -#define CMD_RD_DDB_AUTO 0xA8 -#define CMD_SET_PANEL_MODE 0xB0 -#define CMD_GET_PANEL_MODE 0xB1 -#define CMD_SET_HOR_PERIOD 0xB4 -#define CMD_GET_HOR_PERIOD 0xB5 -#define CMD_SET_VER_PERIOD 0xB6 -#define CMD_GET_VER_PERIOD 0xB7 -#define CMD_SET_GPIO_CONF 0xB8 -#define CMD_GET_GPIO_CONF 0xB9 -#define CMD_SET_GPIO_VAL 0xBA -#define CMD_GET_GPIO_STATUS 0xBB -#define CMD_SET_POST_PROC 0xBC -#define CMD_GET_POST_PROC 0xBD -#define CMD_SET_PWM_CONF 0xBE -#define CMD_GET_PWM_CONF 0xBF -#define CMD_SET_LCD_GEN0 0xC0 -#define CMD_GET_LCD_GEN0 0xC1 -#define CMD_SET_LCD_GEN1 0xC2 -#define CMD_GET_LCD_GEN1 0xC3 -#define CMD_SET_LCD_GEN2 0xC4 -#define CMD_GET_LCD_GEN2 0xC5 -#define CMD_SET_LCD_GEN3 0xC6 -#define CMD_GET_LCD_GEN3 0xC7 -#define CMD_SET_GPIO0_ROP 0xC8 -#define CMD_GET_GPIO0_ROP 0xC9 -#define CMD_SET_GPIO1_ROP 0xCA -#define CMD_GET_GPIO1_ROP 0xCB -#define CMD_SET_GPIO2_ROP 0xCC -#define CMD_GET_GPIO2_ROP 0xCD -#define CMD_SET_GPIO3_ROP 0xCE -#define CMD_GET_GPIO3_ROP 0xCF -#define CMD_SET_ABC_DBC_CONF 0xD0 -#define CMD_GET_ABC_DBC_CONF 0xD1 -#define CMD_SET_DBC_HISTO_PTR 0xD2 -#define CMD_GET_DBC_HISTO_PTR 0xD3 -#define CMD_SET_DBC_THRES 0xD4 -#define CMD_GET_DBC_THRES 0xD5 -#define CMD_SET_ABM_TMR 0xD6 -#define CMD_GET_ABM_TMR 0xD7 -#define CMD_SET_AMB_LVL0 0xD8 -#define CMD_GET_AMB_LVL0 0xD9 -#define CMD_SET_AMB_LVL1 0xDA -#define CMD_GET_AMB_LVL1 0xDB -#define CMD_SET_AMB_LVL2 0xDC -#define CMD_GET_AMB_LVL2 0xDD -#define CMD_SET_AMB_LVL3 0xDE -#define CMD_GET_AMB_LVL3 0xDF -#define CMD_PLL_START 0xE0 //start the PLL -#define CMD_PLL_STOP 0xE1 //disable the PLL -#define CMD_SET_PLL_MN 0xE2 -#define CMD_GET_PLL_MN 0xE3 -#define CMD_GET_PLL_STATUS 0xE4 //get the current PLL status -#define CMD_ENT_DEEP_SLEEP 0xE5 -#define CMD_SET_PCLK 0xE6 //set pixel clock (LSHIFT signal) frequency -#define CMD_GET_PCLK 0xE7 //get pixel clock (LSHIFT signal) freq. settings -#define CMD_SET_DATA_INTERFACE 0xF0 -#define CMD_GET_DATA_INTERFACE 0xF1 - - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void ssd1963_init(void); -void ssd1963_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); - -/********************** - * MACROS - **********************/ - -#endif /* USE_SSD1963 */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* SSD1963_H */ diff --git a/lib/lv_drivers/display/ST7565.c b/lib/lv_drivers/display/ST7565.c deleted file mode 100644 index e4eac4b2..00000000 --- a/lib/lv_drivers/display/ST7565.c +++ /dev/null @@ -1,289 +0,0 @@ -/** - * @file ST7565.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "ST7565.h" -#if USE_ST7565 - -#include -#include -#include -#include "lvgl/lv_core/lv_vdb.h" -#include LV_DRV_DISP_INCLUDE -#include LV_DRV_DELAY_INCLUDE - -/********************* - * DEFINES - *********************/ -#define ST7565_BAUD 2000000 /*< 2,5 MHz (400 ns)*/ - -#define ST7565_CMD_MODE 0 -#define ST7565_DATA_MODE 1 - -#define ST7565_HOR_RES 128 -#define ST7565_VER_RES 64 - -#define CMD_DISPLAY_OFF 0xAE -#define CMD_DISPLAY_ON 0xAF - -#define CMD_SET_DISP_START_LINE 0x40 -#define CMD_SET_PAGE 0xB0 - -#define CMD_SET_COLUMN_UPPER 0x10 -#define CMD_SET_COLUMN_LOWER 0x00 - -#define CMD_SET_ADC_NORMAL 0xA0 -#define CMD_SET_ADC_REVERSE 0xA1 - -#define CMD_SET_DISP_NORMAL 0xA6 -#define CMD_SET_DISP_REVERSE 0xA7 - -#define CMD_SET_ALLPTS_NORMAL 0xA4 -#define CMD_SET_ALLPTS_ON 0xA5 -#define CMD_SET_BIAS_9 0xA2 -#define CMD_SET_BIAS_7 0xA3 - -#define CMD_RMW 0xE0 -#define CMD_RMW_CLEAR 0xEE -#define CMD_INTERNAL_RESET 0xE2 -#define CMD_SET_COM_NORMAL 0xC0 -#define CMD_SET_COM_REVERSE 0xC8 -#define CMD_SET_POWER_CONTROL 0x28 -#define CMD_SET_RESISTOR_RATIO 0x20 -#define CMD_SET_VOLUME_FIRST 0x81 -#define CMD_SET_VOLUME_SECOND 0x00 -#define CMD_SET_STATIC_OFF 0xAC -#define CMD_SET_STATIC_ON 0xAD -#define CMD_SET_STATIC_REG 0x00 -#define CMD_SET_BOOSTER_FIRST 0xF8 -#define CMD_SET_BOOSTER_234 0x00 -#define CMD_SET_BOOSTER_5 0x01 -#define CMD_SET_BOOSTER_6 0x03 -#define CMD_NOP 0xE3 -#define CMD_TEST 0xF0 - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static void st7565_sync(int32_t x1, int32_t y1, int32_t x2, int32_t y2); -static void st7565_command(uint8_t cmd); -static void st7565_data(uint8_t data); - -/********************** - * STATIC VARIABLES - **********************/ -static uint8_t lcd_fb[ST7565_HOR_RES * ST7565_VER_RES / 8] = {0xAA, 0xAA}; -static uint8_t pagemap[] = { 7, 6, 5, 4, 3, 2, 1, 0 }; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the ST7565 - */ -void st7565_init(void) -{ - LV_DRV_DISP_RST(1); - LV_DRV_DELAY_MS(10); - LV_DRV_DISP_RST(0); - LV_DRV_DELAY_MS(10); - LV_DRV_DISP_RST(1); - LV_DRV_DELAY_MS(10); - - LV_DRV_DISP_SPI_CS(0); - - st7565_command(CMD_SET_BIAS_7); - st7565_command(CMD_SET_ADC_NORMAL); - st7565_command(CMD_SET_COM_NORMAL); - st7565_command(CMD_SET_DISP_START_LINE); - st7565_command(CMD_SET_POWER_CONTROL | 0x4); - LV_DRV_DELAY_MS(50); - - st7565_command(CMD_SET_POWER_CONTROL | 0x6); - LV_DRV_DELAY_MS(50); - - st7565_command(CMD_SET_POWER_CONTROL | 0x7); - LV_DRV_DELAY_MS(10); - - st7565_command(CMD_SET_RESISTOR_RATIO | 0x6); // Defaulted to 0x26 (but could also be between 0x20-0x27 based on display's specs) - - st7565_command(CMD_DISPLAY_ON); - st7565_command(CMD_SET_ALLPTS_NORMAL); - - /*Set brightness*/ - st7565_command(CMD_SET_VOLUME_FIRST); - st7565_command(CMD_SET_VOLUME_SECOND | (0x18 & 0x3f)); - - LV_DRV_DISP_SPI_CS(1); - - memset(lcd_fb, 0x00, sizeof(lcd_fb)); -} - - -void st7565_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p) -{ - /*Return if the area is out the screen*/ - if(x2 < 0) return; - if(y2 < 0) return; - if(x1 > ST7565_HOR_RES - 1) return; - if(y1 > ST7565_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > ST7565_HOR_RES - 1 ? ST7565_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > ST7565_VER_RES - 1 ? ST7565_VER_RES - 1 : y2; - - int32_t x, y; - - /*Set the first row in */ - - /*Refresh frame buffer*/ - for(y = act_y1; y <= act_y2; y++) { - for(x = act_x1; x <= act_x2; x++) { - if(lv_color_to1(*color_p) != 0) { - lcd_fb[x + (y / 8)*ST7565_HOR_RES] &= ~(1 << (7 - (y % 8))); - } else { - lcd_fb[x + (y / 8)*ST7565_HOR_RES] |= (1 << (7 - (y % 8))); - } - color_p ++; - } - - color_p += x2 - act_x2; /*Next row*/ - } - - st7565_sync(act_x1, act_y1, act_x2, act_y2); - lv_flush_ready(); -} - - - -void st7565_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color) -{ - /*Return if the area is out the screen*/ - if(x2 < 0) return; - if(y2 < 0) return; - if(x1 > ST7565_HOR_RES - 1) return; - if(y1 > ST7565_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > ST7565_HOR_RES - 1 ? ST7565_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > ST7565_VER_RES - 1 ? ST7565_VER_RES - 1 : y2; - - int32_t x, y; - uint8_t white = lv_color_to1(color); - - /*Refresh frame buffer*/ - for(y = act_y1; y <= act_y2; y++) { - for(x = act_x1; x <= act_x2; x++) { - if(white != 0) { - lcd_fb[x + (y / 8)*ST7565_HOR_RES] |= (1 << (7 - (y % 8))); - } else { - lcd_fb[x + (y / 8)*ST7565_HOR_RES] &= ~(1 << (7 - (y % 8))); - } - } - } - - st7565_sync(act_x1, act_y1, act_x2, act_y2); -} - -void st7565_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p) -{ - /*Return if the area is out the screen*/ - if(x2 < 0) return; - if(y2 < 0) return; - if(x1 > ST7565_HOR_RES - 1) return; - if(y1 > ST7565_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > ST7565_HOR_RES - 1 ? ST7565_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > ST7565_VER_RES - 1 ? ST7565_VER_RES - 1 : y2; - - int32_t x, y; - - /*Set the first row in */ - - /*Refresh frame buffer*/ - for(y = act_y1; y <= act_y2; y++) { - for(x = act_x1; x <= act_x2; x++) { - if(lv_color_to1(*color_p) != 0) { - lcd_fb[x + (y / 8)*ST7565_HOR_RES] &= ~(1 << (7 - (y % 8))); - } else { - lcd_fb[x + (y / 8)*ST7565_HOR_RES] |= (1 << (7 - (y % 8))); - } - color_p ++; - } - - color_p += x2 - act_x2; /*Next row*/ - } - - st7565_sync(act_x1, act_y1, act_x2, act_y2); -} -/********************** - * STATIC FUNCTIONS - **********************/ -/** - * Flush a specific part of the buffer to the display - * @param x1 left coordinate of the area to flush - * @param y1 top coordinate of the area to flush - * @param x2 right coordinate of the area to flush - * @param y2 bottom coordinate of the area to flush - */ -static void st7565_sync(int32_t x1, int32_t y1, int32_t x2, int32_t y2) -{ - - LV_DRV_DISP_SPI_CS(0); - - uint8_t c, p; - for(p = y1 / 8; p <= y2 / 8; p++) { - st7565_command(CMD_SET_PAGE | pagemap[p]); - st7565_command(CMD_SET_COLUMN_LOWER | (x1 & 0xf)); - st7565_command(CMD_SET_COLUMN_UPPER | ((x1 >> 4) & 0xf)); - st7565_command(CMD_RMW); - - for(c = x1; c <= x2; c++) { - st7565_data(lcd_fb[(ST7565_HOR_RES * p) + c]); - } - } - - LV_DRV_DISP_SPI_CS(1); -} - -/** - * Write a command to the ST7565 - * @param cmd the command - */ -static void st7565_command(uint8_t cmd) -{ - LV_DRV_DISP_CMD_DATA(ST7565_CMD_MODE); - LV_DRV_DISP_SPI_WR_BYTE(cmd); -} - -/** - * Write data to the ST7565 - * @param data the data - */ -static void st7565_data(uint8_t data) -{ - LV_DRV_DISP_CMD_DATA(ST7565_DATA_MODE); - LV_DRV_DISP_SPI_WR_BYTE(data); -} - -#endif diff --git a/lib/lv_drivers/display/ST7565.h b/lib/lv_drivers/display/ST7565.h deleted file mode 100644 index 1a96df43..00000000 --- a/lib/lv_drivers/display/ST7565.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file ST7565.h - * - */ - -#ifndef ST7565_H -#define ST7565_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_ST7565 - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void st7565_init(void); -void st7565_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); -void st7565_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); -void st7565_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); - -/********************** - * MACROS - **********************/ - -#endif /* USE_ST7565 */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* ST7565_H */ diff --git a/lib/lv_drivers/display/UC1610.c b/lib/lv_drivers/display/UC1610.c deleted file mode 100644 index b678277c..00000000 --- a/lib/lv_drivers/display/UC1610.c +++ /dev/null @@ -1,206 +0,0 @@ -/** - * @file UC1610.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "UC1610.h" - -#if USE_UC1610 - -#include -#include LV_DRV_DISP_INCLUDE -#include LV_DRV_DELAY_INCLUDE - -/********************* - * DEFINES - *********************/ -#define UC1610_CMD_MODE 0 -#define UC1610_DATA_MODE 1 -#define UC1610_RESET_MODE 0 -#define UC1610_SET_MODE 1 - -/* hardware control commands */ -#define UC1610_SYSTEM_RESET 0xE2 /* software reset */ -#define UC1610_NOP 0xE3 -#define UC1610_SET_TEMP_COMP 0x24 /* set temperature compensation, default -0.05%/°C */ -#define UC1610_SET_PANEL_LOADING 0x29 /* set panel loading, default 16~21 nF */ -#define UC1610_SET_PUMP_CONTROL 0x2F /* default internal Vlcd (8x pump) */ -#define UC1610_SET_LCD_BIAS_RATIO 0xEB /* default 11 */ -#define UC1610_SET_VBIAS_POT 0x81 /* 1 byte (0~255) to follow setting the contrast, default 0x81 */ -#define UC1610_SET_LINE_RATE 0xA0 /* default 12,1 Klps */ -#define UC1610_SET_DISPLAY_ENABLE 0xAE /* + 1 / 0 : exit sleep mode / entering sleep mode */ -#define UC1610_SET_LCD_GRAY_SHADE 0xD0 /* default 24% between the two gray shade levels */ -#define UC1610_SET_COM_END 0xF1 /* set the number of used com electrodes (lines number -1) */ - -/* ram address control */ -#define UC1610_SET_AC 0x88 /* set ram address control */ -#define UC1610_AC_WA_FLAG 1 /* automatic column/page increment wrap around (1 : cycle increment) */ -#define UC1610_AC_AIO_FLAG (1 << 1) /* auto increment order (0/1 : column/page increment first) */ -#define UC1610_AC_PID_FLAG (1 << 2) /* page address auto increment order (0/1 : +1/-1) */ - -/* set cursor ram address */ -#define UC1610_SET_CA_LSB 0x00 /* + 4 LSB bits */ -#define UC1610_SET_CA_MSB 0x10 /* + 4 MSB bits // MSB + LSB values range : 0~159 */ -#define UC1610_SET_PA 0x60 /* + 5 bits // values range : 0~26 */ - -/* display control commands */ -#define UC1610_SET_FIXED_LINES 0x90 /* + 4 bits = 2xFL */ -#define UC1610_SET_SCROLL_LINES_LSB 0x40 /* + 4 LSB bits scroll up display by N (7 bits) lines */ -#define UC1610_SET_SCROLL_LINES_MSB 0x50 /* + 3 MSB bits */ -#define UC1610_SET_ALL_PIXEL_ON 0xA4 /* + 1 / 0 : set all pixel on, reverse */ -#define UC1610_SET_INVERSE_DISPLAY 0xA6 /* + 1 / 0 : inverse all data stored in ram, reverse */ -#define UC1610_SET_MAPPING_CONTROL 0xC0 /* control mirorring */ -#define UC1610_SET_MAPPING_CONTROL_LC_FLAG 1 -#define UC1610_SET_MAPPING_CONTROL_MX_FLAG (1 << 1) -#define UC1610_SET_MAPPING_CONTROL_MY_FLAG (1 << 2) - -/* window program mode */ -#define UC1610_SET_WINDOW_PROGRAM_ENABLE 0xF8 /* + 1 / 0 : enable / disable window programming mode, */ - /* reset before changing boundaries */ -#define UC1610_SET_WP_STARTING_CA 0xF4 /* 1 byte to follow for column address */ -#define UC1610_SET_WP_ENDING_CA 0xF6 /* 1 byte to follow for column address */ -#define UC1610_SET_WP_STARTING_PA 0xF5 /* 1 byte to follow for page address */ -#define UC1610_SET_WP_ENDING_PA 0xF7 /* 1 byte to follow for page address */ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ -static uint8_t cmd_buf[12]; - -/********************** - * MACROS - **********************/ - -/* Return the byte bitmask of a pixel color corresponding to VDB arrangement */ -#define PIXIDX(y, c) ((c) << (((y) & 3) << 1)) - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -void uc1610_init(void) { - LV_DRV_DELAY_MS(12); - - /* initialization sequence */ -#if UC1610_INIT_HARD_RST - LV_DRV_DISP_RST(UC1610_RESET_MODE); /* hardware reset */ - LV_DRV_DELAY_MS(1); - LV_DRV_DISP_RST(UC1610_SET_MODE); -#else - cmd_buf[0] = UC1610_SYSTEM_RESET; /* software reset */ - LV_DRV_DISP_CMD_DATA(UC1610_CMD_MODE); - LV_DRV_DISP_SPI_CS(0); - LV_DRV_DISP_SPI_WR_ARRAY(cmd_buf, 1); - LV_DRV_DISP_SPI_CS(1); -#endif - - LV_DRV_DELAY_MS(2); - cmd_buf[0] = UC1610_SET_COM_END; /* set com end value */ - cmd_buf[1] = UC1610_VER_RES - 1; - cmd_buf[2] = UC1610_SET_PANEL_LOADING; - cmd_buf[3] = UC1610_SET_LCD_BIAS_RATIO; - cmd_buf[4] = UC1610_SET_VBIAS_POT; /* set contrast */ - cmd_buf[5] = (UC1610_INIT_CONTRAST * 255) / 100; -#if UC1610_TOP_VIEW - cmd_buf[6] = UC1610_SET_MAPPING_CONTROL | /* top view */ - UC1610_SET_MAPPING_CONTROL_MY_FLAG | - UC1610_SET_MAPPING_CONTROL_MX_FLAG; -#else - cmd_buf[6] = UC1610_SET_MAPPING_CONTROL; /* bottom view */ -#endif - cmd_buf[7] = UC1610_SET_SCROLL_LINES_LSB | 0; /* set scroll line on line 0 */ - cmd_buf[8] = UC1610_SET_SCROLL_LINES_MSB | 0; - cmd_buf[9] = UC1610_SET_AC | UC1610_AC_WA_FLAG; /* set auto increment wrap around */ - cmd_buf[10] = UC1610_SET_INVERSE_DISPLAY | 1; /* invert colors to complies lv color system */ - cmd_buf[11] = UC1610_SET_DISPLAY_ENABLE | 1; /* turn display on */ - - LV_DRV_DISP_CMD_DATA(UC1610_CMD_MODE); - LV_DRV_DISP_SPI_CS(0); - LV_DRV_DISP_SPI_WR_ARRAY(cmd_buf, 12); - LV_DRV_DISP_SPI_CS(1); -} - - -void uc1610_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) { - /*Return if the area is out the screen*/ - if(area->x2 < 0) return; - if(area->y2 < 0) return; - if(area->x1 > UC1610_HOR_RES - 1) return; - if(area->y1 > UC1610_VER_RES - 1) return; - - /*Truncate the area to the screen*/ - uint8_t act_x1 = area->x1 < 0 ? 0 : area->x1; - uint8_t act_y1 = area->y1 < 0 ? 0 : area->y1; - uint8_t act_x2 = area->x2 > UC1610_HOR_RES - 1 ? UC1610_HOR_RES - 1 : area->x2; - uint8_t act_y2 = area->y2 > UC1610_VER_RES - 1 ? UC1610_VER_RES - 1 : area->y2; - - uint8_t * buf = (uint8_t *) color_p; - uint16_t buf_size = (act_x2 - act_x1 + 1) * (((act_y2 - act_y1) >> 2) + 1); - - /*Set display window to fill*/ - cmd_buf[0] = UC1610_SET_WINDOW_PROGRAM_ENABLE | 0; /* before changing boundaries */ - cmd_buf[1] = UC1610_SET_WP_STARTING_CA; - cmd_buf[2] = act_x1; - cmd_buf[3] = UC1610_SET_WP_ENDING_CA; - cmd_buf[4] = act_x2; - cmd_buf[5] = UC1610_SET_WP_STARTING_PA; - cmd_buf[6] = act_y1 >> 2; - cmd_buf[7] = UC1610_SET_WP_ENDING_PA; - cmd_buf[8] = act_y2 >> 2; - cmd_buf[9] = UC1610_SET_WINDOW_PROGRAM_ENABLE | 1; /* entering window programming */ - - LV_DRV_DISP_CMD_DATA(UC1610_CMD_MODE); - LV_DRV_DISP_SPI_CS(0); - LV_DRV_DISP_SPI_WR_ARRAY(cmd_buf, 10); - LV_DRV_DISP_SPI_CS(1); - - /*Flush VDB on display memory*/ - LV_DRV_DISP_CMD_DATA(UC1610_DATA_MODE); - LV_DRV_DISP_SPI_CS(0); - LV_DRV_DISP_SPI_WR_ARRAY(buf, buf_size); - LV_DRV_DISP_SPI_CS(1); - - lv_disp_flush_ready(disp_drv); -} - -void uc1610_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa) { - (void) disp_drv; - (void) opa; - - uint16_t idx = x + buf_w * (y >> 2); - - /* Convert color to depth 2 */ -#if LV_COLOR_DEPTH == 1 - uint8_t color2 = color.full * 3; -#else - uint8_t color2 = color.full >> (LV_COLOR_DEPTH - 2); -#endif - - buf[idx] &= ~PIXIDX(y, 3); /* reset pixel color */ - buf[idx] |= PIXIDX(y, color2); /* write new color */ -} - -void uc1610_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area) { - (void) disp_drv; - - /* Round y window to display memory page size */ - area->y1 = (area->y1 & (~3)); - area->y2 = (area->y2 & (~3)) + 3; -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -#endif diff --git a/lib/lv_drivers/display/UC1610.h b/lib/lv_drivers/display/UC1610.h deleted file mode 100644 index 38b1fa3c..00000000 --- a/lib/lv_drivers/display/UC1610.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file UC1610.h - * - */ - -#ifndef UC1610_H -#define UC1610_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_UC1610 - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void uc1610_init(void); -void uc1610_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); -void uc1610_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area); -void uc1610_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa); - -/********************** - * MACROS - **********************/ - -#endif /* USE_UC1610 */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* UC1610_H */ diff --git a/lib/lv_drivers/display/display.mk b/lib/lv_drivers/display/display.mk deleted file mode 100644 index d0255920..00000000 --- a/lib/lv_drivers/display/display.mk +++ /dev/null @@ -1,12 +0,0 @@ -CSRCS += fbdev.c -CSRCS += monitor.c -CSRCS += R61581.c -CSRCS += SSD1963.c -CSRCS += ST7565.c -CSRCS += UC1610.c -CSRCS += SHARP_MIP.c - -DEPPATH += --dep-path $(LVGL_DIR)/lv_drivers/display -VPATH += :$(LVGL_DIR)/lv_drivers/display - -CFLAGS += "-I$(LVGL_DIR)/lv_drivers/display" diff --git a/lib/lv_drivers/display/fbdev.c b/lib/lv_drivers/display/fbdev.c deleted file mode 100644 index 14c6cf14..00000000 --- a/lib/lv_drivers/display/fbdev.c +++ /dev/null @@ -1,241 +0,0 @@ -/** - * @file fbdev.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "fbdev.h" -#if USE_FBDEV || USE_BSD_FBDEV - -#include -#include -#include -#include -#include -#include -#include - -#if USE_BSD_FBDEV -#include -#include -#include -#include -#else /* USE_BSD_FBDEV */ -#include -#endif /* USE_BSD_FBDEV */ - -/********************* - * DEFINES - *********************/ -#ifndef FBDEV_PATH -#define FBDEV_PATH "/dev/fb0" -#endif - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STRUCTURES - **********************/ - -struct bsd_fb_var_info{ - uint32_t xoffset; - uint32_t yoffset; - uint32_t xres; - uint32_t yres; - int bits_per_pixel; - }; - -struct bsd_fb_fix_info{ - long int line_length; -}; - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ -#if USE_BSD_FBDEV -static struct bsd_fb_var_info vinfo; -static struct bsd_fb_fix_info finfo; -#else -static struct fb_var_screeninfo vinfo; -static struct fb_fix_screeninfo finfo; -#endif /* USE_BSD_FBDEV */ -static char *fbp = 0; -static long int screensize = 0; -static int fbfd = 0; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -void fbdev_init(void) -{ - // Open the file for reading and writing - fbfd = open(FBDEV_PATH, O_RDWR); - if(fbfd == -1) { - perror("Error: cannot open framebuffer device"); - return; - } - printf("The framebuffer device was opened successfully.\n"); - -#if USE_BSD_FBDEV - struct fbtype fb; - unsigned line_length; - - //Get fb type - if (ioctl(fbfd, FBIOGTYPE, &fb) != 0) { - perror("ioctl(FBIOGTYPE)"); - return; - } - - //Get screen width - if (ioctl(fbfd, FBIO_GETLINEWIDTH, &line_length) != 0) { - perror("ioctl(FBIO_GETLINEWIDTH)"); - return; - } - - vinfo.xres = (unsigned) fb.fb_width; - vinfo.yres = (unsigned) fb.fb_height; - vinfo.bits_per_pixel = fb.fb_depth + 8; - vinfo.xoffset = 0; - vinfo.yoffset = 0; - finfo.line_length = line_length; -#else /* USE_BSD_FBDEV */ - - // Get fixed screen information - if(ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) { - perror("Error reading fixed information"); - return; - } - - // Get variable screen information - if(ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) { - perror("Error reading variable information"); - return; - } -#endif /* USE_BSD_FBDEV */ - - printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); - - // Figure out the size of the screen in bytes - screensize = finfo.smem_len; //finfo.line_length * vinfo.yres; - - // Map the device to memory - fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); - if((intptr_t)fbp == -1) { - perror("Error: failed to map framebuffer device to memory"); - return; - } - memset(fbp, 0, screensize); - - printf("The framebuffer device was mapped to memory successfully.\n"); - -} - -void fbdev_exit(void) -{ - close(fbfd); -} - -/** - * Flush a buffer to the marked area - * @param drv pointer to driver where this function belongs - * @param area an area where to copy `color_p` - * @param color_p an array of pixel to copy to the `area` part of the screen - */ -void fbdev_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p) -{ - if(fbp == NULL || - area->x2 < 0 || - area->y2 < 0 || - area->x1 > (int32_t)vinfo.xres - 1 || - area->y1 > (int32_t)vinfo.yres - 1) { - lv_disp_flush_ready(drv); - return; - } - - /*Truncate the area to the screen*/ - int32_t act_x1 = area->x1 < 0 ? 0 : area->x1; - int32_t act_y1 = area->y1 < 0 ? 0 : area->y1; - int32_t act_x2 = area->x2 > (int32_t)vinfo.xres - 1 ? (int32_t)vinfo.xres - 1 : area->x2; - int32_t act_y2 = area->y2 > (int32_t)vinfo.yres - 1 ? (int32_t)vinfo.yres - 1 : area->y2; - - - lv_coord_t w = lv_area_get_width(area); - long int location = 0; - long int byte_location = 0; - unsigned char bit_location = 0; - - /*32 or 24 bit per pixel*/ - if(vinfo.bits_per_pixel == 32 || vinfo.bits_per_pixel == 24) { - uint32_t * fbp32 = (uint32_t *)fbp; - int32_t y; - for(y = act_y1; y <= act_y2; y++) { - location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length / 4; - memcpy(&fbp32[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4); - color_p += w; - } - } - /*16 bit per pixel*/ - else if(vinfo.bits_per_pixel == 16) { - uint16_t * fbp16 = (uint16_t *)fbp; - int32_t y; - for(y = act_y1; y <= act_y2; y++) { - location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length / 2; - memcpy(&fbp16[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 2); - color_p += w; - } - } - /*8 bit per pixel*/ - else if(vinfo.bits_per_pixel == 8) { - uint8_t * fbp8 = (uint8_t *)fbp; - int32_t y; - for(y = act_y1; y <= act_y2; y++) { - location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length; - memcpy(&fbp8[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1)); - color_p += w; - } - } - /*1 bit per pixel*/ - else if(vinfo.bits_per_pixel == 1) { - uint8_t * fbp8 = (uint8_t *)fbp; - int32_t x; - int32_t y; - for(y = act_y1; y <= act_y2; y++) { - for(x = act_x1; x <= act_x2; x++) { - location = (x + vinfo.xoffset) + (y + vinfo.yoffset) * vinfo.xres; - byte_location = location / 8; /* find the byte we need to change */ - bit_location = location % 8; /* inside the byte found, find the bit we need to change */ - fbp8[byte_location] &= ~(((uint8_t)(1)) << bit_location); - fbp8[byte_location] |= ((uint8_t)(color_p->full)) << bit_location; - color_p++; - } - - color_p += area->x2 - act_x2; - } - } else { - /*Not supported bit per pixel*/ - } - - //May be some direct update command is required - //ret = ioctl(state->fd, FBIO_UPDATE, (unsigned long)((uintptr_t)rect)); - - lv_disp_flush_ready(drv); -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -#endif diff --git a/lib/lv_drivers/display/fbdev.h b/lib/lv_drivers/display/fbdev.h deleted file mode 100644 index 9f0e2d5c..00000000 --- a/lib/lv_drivers/display/fbdev.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file fbdev.h - * - */ - -#ifndef FBDEV_H -#define FBDEV_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_FBDEV || USE_BSD_FBDEV - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void fbdev_init(void); -void fbdev_exit(void); -void fbdev_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p); - - -/********************** - * MACROS - **********************/ - -#endif /*USE_FBDEV*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*FBDEV_H*/ diff --git a/lib/lv_drivers/display/monitor.c b/lib/lv_drivers/display/monitor.c deleted file mode 100644 index 67af9944..00000000 --- a/lib/lv_drivers/display/monitor.c +++ /dev/null @@ -1,425 +0,0 @@ -/** - * @file monitor.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "monitor.h" -#if USE_MONITOR - -#ifndef MONITOR_SDL_INCLUDE_PATH -#define MONITOR_SDL_INCLUDE_PATH -#endif - -#include -#include -#include -#include MONITOR_SDL_INCLUDE_PATH -#include "../indev/mouse.h" -#include "../indev/keyboard.h" -#include "../indev/mousewheel.h" - -/********************* - * DEFINES - *********************/ -#define SDL_REFR_PERIOD 50 /*ms*/ - -#ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 -#endif - -#ifndef MONITOR_HOR_RES -#define MONITOR_HOR_RES LV_HOR_RES -#endif - -#ifndef MONITOR_VER_RES -#define MONITOR_VER_RES LV_VER_RES -#endif - -#if defined(__APPLE__) && defined(TARGET_OS_MAC) -#if __APPLE__ && TARGET_OS_MAC -#define MONITOR_APPLE -#endif -#endif - -#if defined(__EMSCRIPTEN__) -#define MONITOR_EMSCRIPTEN -#endif - -/********************** - * TYPEDEFS - **********************/ -typedef struct -{ - SDL_Window* window; - SDL_Renderer* renderer; - SDL_Texture* texture; - volatile bool sdl_refr_qry; -#if MONITOR_DOUBLE_BUFFERED - uint32_t* tft_fb_act; -#else - uint32_t tft_fb[LV_HOR_RES_MAX * LV_VER_RES_MAX]; -#endif - double rotation; -} monitor_t; - -/********************** - * STATIC PROTOTYPES - **********************/ -static int monitor_sdl_refr_thread(void* param); -static void window_create(monitor_t* m); -static void window_update(monitor_t* m); - -/*********************** - * GLOBAL PROTOTYPES - ***********************/ - -/********************** - * STATIC VARIABLES - **********************/ -monitor_t monitor; - -#if MONITOR_DUAL -monitor_t monitor2; -#endif - -static volatile bool sdl_inited = false; -static volatile bool sdl_quit_qry = false; - -int quit_filter(void* userdata, SDL_Event* event); -static void monitor_sdl_clean_up(void); -static void monitor_sdl_init(void); -#ifdef MONITOR_EMSCRIPTEN -void monitor_sdl_refr_core(void); /* called from Emscripten loop */ -#else -static void monitor_sdl_refr_core(void); -#endif - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the monitor - */ -void monitor_init(void) -{ - /*OSX needs to initialize SDL here*/ -#if defined(MONITOR_APPLE) || defined(MONITOR_EMSCRIPTEN) - monitor_sdl_init(); -#endif - -#ifndef MONITOR_EMSCRIPTEN - SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL); - while(sdl_inited == false) - ; /*Wait until 'sdl_refr' initializes the SDL*/ -#endif -} - -/** - * Flush a buffer to the marked area - * @param drv pointer to driver where this function belongs - * @param area an area where to copy `color_p` - * @param color_p an array of pixel to copy to the `area` part of the screen - */ -void monitor_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) -{ - lv_coord_t hres = disp_drv->rotated == 0 ? disp_drv->hor_res : disp_drv->ver_res; - lv_coord_t vres = disp_drv->rotated == 0 ? disp_drv->ver_res : disp_drv->hor_res; - - // printf("x1:%d,y1:%d,x2:%d,y2:%d\n", area->x1, area->y1, area->x2, area->y2); - - /*Return if the area is out the screen*/ - if(area->x2 < 0 || area->y2 < 0 || area->x1 > hres - 1 || area->y1 > vres - 1) { - - lv_disp_flush_ready(disp_drv); - return; - } - -#if MONITOR_DOUBLE_BUFFERED - monitor.tft_fb_act = (uint32_t*)color_p; - - monitor.sdl_refr_qry = true; - - /*IMPORTANT! It must be called to tell the system the flush is ready*/ - lv_disp_flush_ready(disp_drv); -#else - - int32_t y; -#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/ - int32_t x; - for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) { - for(x = area->x1; x <= area->x2; x++) { - monitor.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p); - color_p++; - } - } -#else - uint32_t w = lv_area_get_width(area); - for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) { - memcpy(&monitor.tft_fb[y * MONITOR_HOR_RES + area->x1], color_p, w * sizeof(lv_color_t)); - color_p += w; - } -#endif - - monitor.sdl_refr_qry = true; - - /*IMPORTANT! It must be called to tell the system the flush is ready*/ - lv_disp_flush_ready(disp_drv); -#endif -} - -#if MONITOR_DUAL - -/** - * Flush a buffer to the marked area - * @param drv pointer to driver where this function belongs - * @param area an area where to copy `color_p` - * @param color_p an array of pixel to copy to the `area` part of the screen - */ -void monitor_flush2(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) -{ - lv_coord_t hres = disp_drv->rotated == 0 ? disp_drv->hor_res : disp_drv->ver_res; - lv_coord_t vres = disp_drv->rotated == 0 ? disp_drv->ver_res : disp_drv->hor_res; - - /*Return if the area is out the screen*/ - if(area->x2 < 0 || area->y2 < 0 || area->x1 > hres - 1 || area->y1 > vres - 1) { - lv_disp_flush_ready(disp_drv); - return; - } - -#if MONITOR_DOUBLE_BUFFERED - monitor2.tft_fb_act = (uint32_t*)color_p; - - monitor2.sdl_refr_qry = true; - - /*IMPORTANT! It must be called to tell the system the flush is ready*/ - lv_disp_flush_ready(disp_drv); -#else - - int32_t y; -#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/ - int32_t x; - for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) { - for(x = area->x1; x <= area->x2; x++) { - monitor2.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p); - color_p++; - } - } -#else - uint32_t w = lv_area_get_width(area); - for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) { - memcpy(&monitor2.tft_fb[y * disp_drv->hor_res + area->x1], color_p, w * sizeof(lv_color_t)); - color_p += w; - } -#endif - - monitor2.sdl_refr_qry = true; - - /*IMPORTANT! It must be called to tell the system the flush is ready*/ - lv_disp_flush_ready(disp_drv); -#endif -} -#endif - -/********************** - * STATIC FUNCTIONS - **********************/ - -/** - * SDL main thread. All SDL related task have to be handled here! - * It initializes SDL, handles drawing and the mouse. - */ - -static int monitor_sdl_refr_thread(void* param) -{ - (void)param; - - /*If not OSX initialize SDL in the Thread*/ -#ifndef MONITOR_APPLE - monitor_sdl_init(); -#endif - /*Run until quit event not arrives*/ - while(sdl_quit_qry == false) { - /*Refresh handling*/ - monitor_sdl_refr_core(); - } - - monitor_sdl_clean_up(); - exit(0); - - return 0; -} - -int quit_filter(void* userdata, SDL_Event* event) -{ - (void)userdata; - - if(event->type == SDL_WINDOWEVENT) { - if(event->window.event == SDL_WINDOWEVENT_CLOSE) { - sdl_quit_qry = true; - } - } else if(event->type == SDL_QUIT) { - sdl_quit_qry = true; - } - - return 1; -} - -static void monitor_sdl_clean_up(void) -{ - SDL_DestroyTexture(monitor.texture); - SDL_DestroyRenderer(monitor.renderer); - SDL_DestroyWindow(monitor.window); - -#if MONITOR_DUAL - SDL_DestroyTexture(monitor2.texture); - SDL_DestroyRenderer(monitor2.renderer); - SDL_DestroyWindow(monitor2.window); - -#endif - - SDL_Quit(); -} - -void monitor_backlight(uint8_t level) -{ - SDL_SetTextureColorMod(monitor.texture, level, level, level); - // window_update(&monitor); - monitor.sdl_refr_qry = true; - monitor_sdl_refr_core(); -} - -void monitor_title(const char* title) -{ - SDL_SetWindowTitle(monitor.window, title); - // SDL_SetWindowFullscreen(monitor.window, SDL_WINDOW_FULLSCREEN_DESKTOP); -} - -static void monitor_sdl_init(void) -{ - /*Initialize the SDL*/ - SDL_Init(SDL_INIT_VIDEO); - - SDL_SetEventFilter(quit_filter, NULL); - - window_create(&monitor); -#if MONITOR_DUAL - window_create(&monitor2); - int x, y; - SDL_GetWindowPosition(monitor2.window, &x, &y); - SDL_SetWindowPosition(monitor.window, x + MONITOR_HOR_RES / 2 + 10, y); - SDL_SetWindowPosition(monitor2.window, x - MONITOR_HOR_RES / 2 - 10, y); -#endif - - sdl_inited = true; -} - -#ifdef MONITOR_EMSCRIPTEN -void monitor_sdl_refr_core(void) -#else -static void monitor_sdl_refr_core(void) -#endif -{ - - if(monitor.sdl_refr_qry != false) { - monitor.sdl_refr_qry = false; - window_update(&monitor); - } - -#if MONITOR_DUAL - if(monitor2.sdl_refr_qry != false) { - monitor2.sdl_refr_qry = false; - window_update(&monitor2); - } -#endif - -#if !defined(MONITOR_APPLE) && !defined(MONITOR_EMSCRIPTEN) - SDL_Event event; - while(SDL_PollEvent(&event)) { -#if USE_MOUSE != 0 - mouse_handler(&event); -#endif - -#if USE_MOUSEWHEEL != 0 - mousewheel_handler(&event); -#endif - -#if USE_KEYBOARD - keyboard_handler(&event); -#endif - if((&event)->type == SDL_WINDOWEVENT) { - switch((&event)->window.event) { -#if SDL_VERSION_ATLEAST(2, 0, 5) - case SDL_WINDOWEVENT_TAKE_FOCUS: -#endif - case SDL_WINDOWEVENT_EXPOSED: - window_update(&monitor); -#if MONITOR_DUAL - window_update(&monitor2); -#endif - break; - default: - break; - } - } - } -#endif /*MONITOR_APPLE*/ - - /*Sleep some time*/ - SDL_Delay(SDL_REFR_PERIOD); -} - -static void window_create(monitor_t* m) -{ - m->window = SDL_CreateWindow("TFT Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, - 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/ - -#if MONITOR_VIRTUAL_MACHINE || defined(MONITOR_EMSCRIPTEN) - m->renderer = SDL_CreateRenderer(m->window, -1, SDL_RENDERER_SOFTWARE); -#else - m->renderer = SDL_CreateRenderer(m->window, -1, 0); -#endif - m->texture = SDL_CreateTexture(m->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, - MONITOR_VER_RES); - SDL_SetTextureBlendMode(m->texture, SDL_BLENDMODE_BLEND); - - /*Initialize the frame buffer to gray (77 is an empirical value) */ -#if MONITOR_DOUBLE_BUFFERED - SDL_UpdateTexture(m->texture, NULL, m->tft_fb_act, MONITOR_HOR_RES * sizeof(uint32_t)); -#else - memset(m->tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t)); -#endif - - m->sdl_refr_qry = true; -} - -static void window_update(monitor_t* m) -{ -#if MONITOR_DOUBLE_BUFFERED == 0 - SDL_UpdateTexture(m->texture, NULL, m->tft_fb, MONITOR_HOR_RES * sizeof(uint32_t)); -#else - if(m->tft_fb_act == NULL) return; - SDL_UpdateTexture(m->texture, NULL, m->tft_fb_act, MONITOR_HOR_RES * sizeof(uint32_t)); -#endif - SDL_RenderClear(m->renderer); - /*Test: Draw a background to test transparent screens (LV_COLOR_SCREEN_TRANSP)*/ - // SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff); - // SDL_Rect r; - // r.x = 0; r.y = 0; r.w = MONITOR_HOR_RES; r.w = MONITOR_VER_RES; - // SDL_RenderDrawRect(renderer, &r); - - /*Update the renderer with the texture containing the rendered image*/ - // SDL_RenderCopy(m->renderer, m->texture, NULL, NULL); - SDL_RenderCopyEx(m->renderer, m->texture, NULL, NULL, m->rotation, NULL, SDL_FLIP_NONE); - SDL_RenderPresent(m->renderer); -} - -#endif /*USE_MONITOR*/ diff --git a/lib/lv_drivers/display/monitor.h b/lib/lv_drivers/display/monitor.h deleted file mode 100644 index b8f618de..00000000 --- a/lib/lv_drivers/display/monitor.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @file monitor.h - * - */ - -#ifndef MONITOR_H -#define MONITOR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_MONITOR - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void monitor_init(void); -void monitor_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p); -void monitor_flush2(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p); - -// HASP Customized functions -void monitor_backlight(uint8_t level); -void monitor_title(const char* title); - -/********************** - * MACROS - **********************/ - -#endif /* USE_MONITOR */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* MONITOR_H */ diff --git a/lib/lv_drivers/docs/astyle_c b/lib/lv_drivers/docs/astyle_c deleted file mode 100644 index 9b9d7f3c..00000000 --- a/lib/lv_drivers/docs/astyle_c +++ /dev/null @@ -1 +0,0 @@ ---style=kr --convert-tabs --indent=spaces=4 --indent-switches --pad-oper --unpad-paren --align-pointer=middle --suffix=.bak --lineend=linux --min-conditional-indent= diff --git a/lib/lv_drivers/docs/astyle_h b/lib/lv_drivers/docs/astyle_h deleted file mode 100644 index d9c76337..00000000 --- a/lib/lv_drivers/docs/astyle_h +++ /dev/null @@ -1 +0,0 @@ ---convert-tabs --indent=spaces=4 diff --git a/lib/lv_drivers/indev/AD_touch.c b/lib/lv_drivers/indev/AD_touch.c deleted file mode 100644 index c09c3593..00000000 --- a/lib/lv_drivers/indev/AD_touch.c +++ /dev/null @@ -1,383 +0,0 @@ -/** - * @file AD_touch.c - * - */ - -#include "AD_touch.h" - -#if USE_AD_TOUCH - -#include LV_DRV_INDEV_INCLUDE -#include LV_DRV_DELAY_INCLUDE - -#define SAMPLE_POINTS 4 - -#define CALIBRATIONINSET 20 // range 0 <= CALIBRATIONINSET <= 40 - -#define RESISTIVETOUCH_AUTO_SAMPLE_MODE -#define TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD 350 // between 0-0x03ff the lesser this value - - -// Current ADC values for X and Y channels -int16_t adcX = 0; -int16_t adcY = 0; -volatile unsigned int adcTC = 0; - -// coefficient values -volatile long _trA; -volatile long _trB; -volatile long _trC; -volatile long _trD; - -volatile int16_t xRawTouch[SAMPLE_POINTS] = {TOUCHCAL_ULX, TOUCHCAL_URX, TOUCHCAL_LRX, TOUCHCAL_LLX}; -volatile int16_t yRawTouch[SAMPLE_POINTS] = {TOUCHCAL_ULY, TOUCHCAL_URY, TOUCHCAL_LRY, TOUCHCAL_LLY}; - -#define TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR 8 - -// use this scale factor to avoid working in floating point numbers -#define SCALE_FACTOR (1 << TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR) - -typedef enum { - IDLE, //0 - SET_X, //1 - RUN_X, //2 - GET_X, //3 - RUN_CHECK_X, //4 - CHECK_X, //5 - SET_Y, //6 - RUN_Y, //7 - GET_Y, //8 - CHECK_Y, //9 - SET_VALUES, //10 - GET_POT, //11 - RUN_POT //12 -} TOUCH_STATES; - -volatile TOUCH_STATES state = IDLE; - -#define CAL_X_INSET (((GetMaxX() + 1) * (CALIBRATIONINSET >> 1)) / 100) -#define CAL_Y_INSET (((GetMaxY() + 1) * (CALIBRATIONINSET >> 1)) / 100) - -int stat; -int16_t temp_x, temp_y; - - -static int16_t TouchGetX(void); -static int16_t TouchGetRawX(void); -static int16_t TouchGetY(void); -static int16_t TouchGetRawY(void); -static int16_t TouchDetectPosition(void); -static void TouchCalculateCalPoints(void); - - -/********************************************************************/ -void ad_touch_init(void) -{ - // Initialize ADC for auto sampling mode - AD1CON1 = 0; // reset - AD1CON2 = 0; // AVdd, AVss, int every conversion, MUXA only - AD1CON3 = 0x1FFF; // 31 Tad auto-sample, Tad = 256*Tcy - AD1CON1 = 0x80E0; // Turn on A/D module, use auto-convert - - - ADPCFG_XPOS = RESISTIVETOUCH_ANALOG; - ADPCFG_YPOS = RESISTIVETOUCH_ANALOG; - - AD1CSSL = 0; // No scanned inputs - - state = SET_X; // set the state of the state machine to start the sampling - - /*Load calibration data*/ - xRawTouch[0] = TOUCHCAL_ULX; - yRawTouch[0] = TOUCHCAL_ULY; - xRawTouch[1] = TOUCHCAL_URX; - yRawTouch[1] = TOUCHCAL_URY; - xRawTouch[3] = TOUCHCAL_LLX; - yRawTouch[3] = TOUCHCAL_LLY; - xRawTouch[2] = TOUCHCAL_LRX; - yRawTouch[2] = TOUCHCAL_LRY; - - TouchCalculateCalPoints(); -} - -/*Use this in lv_indev_drv*/ -bool ad_touch_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) -{ - static int16_t last_x = 0; - static int16_t last_y = 0; - - int16_t x, y; - - x = TouchGetX(); - y = TouchGetY(); - - if((x > 0) && (y > 0)) { - data->point.x = x; - data->point.y = y; - last_x = data->point.x; - last_y = data->point.y; - data->state = LV_INDEV_STATE_PR; - } else { - data->point.x = last_x; - data->point.y = last_y; - data->state = LV_INDEV_STATE_REL; - } - - return false; -} - -/* Call periodically (e.g. in every 1 ms) to handle reading with ADC*/ -int16_t ad_touch_handler(void) -{ - static int16_t tempX, tempY; - int16_t temp; - - switch(state) { - case IDLE: - adcX = 0; - adcY = 0; - break; - - case SET_VALUES: - if(!TOUCH_ADC_DONE) - break; - if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD < (WORD)ADC1BUF0) { - adcX = 0; - adcY = 0; - } else { - adcX = tempX; - adcY = tempY; - } - state = SET_X; - return 1; // touch screen acquisition is done - - case SET_X: - TOUCH_ADC_INPUT_SEL = ADC_XPOS; - - ResistiveTouchScreen_XPlus_Config_As_Input(); - ResistiveTouchScreen_YPlus_Config_As_Input(); - ResistiveTouchScreen_XMinus_Config_As_Input(); - ResistiveTouchScreen_YMinus_Drive_Low(); - ResistiveTouchScreen_YMinus_Config_As_Output(); - - ADPCFG_YPOS = RESISTIVETOUCH_DIGITAL; // set to digital pin - ADPCFG_XPOS = RESISTIVETOUCH_ANALOG; // set to analog pin - - TOUCH_ADC_START = 1; // run conversion - state = CHECK_X; - break; - - case CHECK_X: - case CHECK_Y: - - if(TOUCH_ADC_DONE == 0) { - break; - } - - if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD > (WORD)ADC1BUF0) { - if(state == CHECK_X) { - ResistiveTouchScreen_YPlus_Drive_High(); - ResistiveTouchScreen_YPlus_Config_As_Output(); - tempX = 0; - state = RUN_X; - } else { - ResistiveTouchScreen_XPlus_Drive_High(); - ResistiveTouchScreen_XPlus_Config_As_Output(); - tempY = 0; - state = RUN_Y; - } - } else { - adcX = 0; - adcY = 0; - state = SET_X; - return 1; // touch screen acquisition is done - break; - } - - case RUN_X: - case RUN_Y: - TOUCH_ADC_START = 1; - state = (state == RUN_X) ? GET_X : GET_Y; - // no break needed here since the next state is either GET_X or GET_Y - break; - - case GET_X: - case GET_Y: - if(!TOUCH_ADC_DONE) - break; - - temp = ADC1BUF0; - if(state == GET_X) { - if(temp != tempX) { - tempX = temp; - state = RUN_X; - break; - } - } else { - if(temp != tempY) { - tempY = temp; - state = RUN_Y; - break; - } - } - - if(state == GET_X) - ResistiveTouchScreen_YPlus_Config_As_Input(); - else - ResistiveTouchScreen_XPlus_Config_As_Input(); - TOUCH_ADC_START = 1; - state = (state == GET_X) ? SET_Y : SET_VALUES; - break; - - case SET_Y: - if(!TOUCH_ADC_DONE) - break; - - if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD < (WORD)ADC1BUF0) { - adcX = 0; - adcY = 0; - state = SET_X; - return 1; // touch screen acquisition is done - break; - } - - TOUCH_ADC_INPUT_SEL = ADC_YPOS; - - ResistiveTouchScreen_XPlus_Config_As_Input(); - ResistiveTouchScreen_YPlus_Config_As_Input(); - ResistiveTouchScreen_XMinus_Drive_Low(); - ResistiveTouchScreen_XMinus_Config_As_Output(); - ResistiveTouchScreen_YMinus_Config_As_Input(); - - ADPCFG_YPOS = RESISTIVETOUCH_ANALOG; // set to analog pin - ADPCFG_XPOS = RESISTIVETOUCH_DIGITAL; // set to digital pin - TOUCH_ADC_START = 1; // run conversion - state = CHECK_Y; - break; - - default: - state = SET_X; - return 1; // touch screen acquisition is done - } - stat = state; - temp_x = adcX; - temp_y = adcY; - - return 0; // touch screen acquisition is not done -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -/********************************************************************/ -static int16_t TouchGetX(void) -{ - long result; - - result = TouchGetRawX(); - - if(result > 0) { - result = (long)((((long)_trC * result) + _trD) >> TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR); - - } - return ((int16_t)result); -} -/********************************************************************/ -static int16_t TouchGetRawX(void) -{ -#ifdef TOUCHSCREEN_RESISTIVE_SWAP_XY - return adcY; -#else - return adcX; -#endif -} - -/********************************************************************/ -static int16_t TouchGetY(void) -{ - - long result; - - result = TouchGetRawY(); - - if(result > 0) { - result = (long)((((long)_trA * result) + (long)_trB) >> TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR); - - } - return ((int16_t)result); -} - -/********************************************************************/ -static int16_t TouchGetRawY(void) -{ -#ifdef TOUCHSCREEN_RESISTIVE_SWAP_XY - return adcX; -#else - return adcY; -#endif -} - - -static void TouchCalculateCalPoints(void) -{ - long trA, trB, trC, trD; // variables for the coefficients - long trAhold, trBhold, trChold, trDhold; - long test1, test2; // temp variables (must be signed type) - - int16_t xPoint[SAMPLE_POINTS], yPoint[SAMPLE_POINTS]; - - yPoint[0] = yPoint[1] = CAL_Y_INSET; - yPoint[2] = yPoint[3] = (GetMaxY() - CAL_Y_INSET); - xPoint[0] = xPoint[3] = CAL_X_INSET; - xPoint[1] = xPoint[2] = (GetMaxX() - CAL_X_INSET); - - // calculate points transfer functiona - // based on two simultaneous equations solve for the - // constants - - // use sample points 1 and 4 - // Dy1 = aTy1 + b; Dy4 = aTy4 + b - // Dx1 = cTx1 + d; Dy4 = aTy4 + b - - test1 = (long)yPoint[0] - (long)yPoint[3]; - test2 = (long)yRawTouch[0] - (long)yRawTouch[3]; - - trA = ((long)((long)test1 * SCALE_FACTOR) / test2); - trB = ((long)((long)yPoint[0] * SCALE_FACTOR) - (trA * (long)yRawTouch[0])); - - test1 = (long)xPoint[0] - (long)xPoint[2]; - test2 = (long)xRawTouch[0] - (long)xRawTouch[2]; - - trC = ((long)((long)test1 * SCALE_FACTOR) / test2); - trD = ((long)((long)xPoint[0] * SCALE_FACTOR) - (trC * (long)xRawTouch[0])); - - trAhold = trA; - trBhold = trB; - trChold = trC; - trDhold = trD; - - // use sample points 2 and 3 - // Dy2 = aTy2 + b; Dy3 = aTy3 + b - // Dx2 = cTx2 + d; Dy3 = aTy3 + b - - test1 = (long)yPoint[1] - (long)yPoint[2]; - test2 = (long)yRawTouch[1] - (long)yRawTouch[2]; - - trA = ((long)(test1 * SCALE_FACTOR) / test2); - trB = ((long)((long)yPoint[1] * SCALE_FACTOR) - (trA * (long)yRawTouch[1])); - - test1 = (long)xPoint[1] - (long)xPoint[3]; - test2 = (long)xRawTouch[1] - (long)xRawTouch[3]; - - trC = ((long)((long)test1 * SCALE_FACTOR) / test2); - trD = ((long)((long)xPoint[1] * SCALE_FACTOR) - (trC * (long)xRawTouch[1])); - - // get the average and use the average - _trA = (trA + trAhold) >> 1; - _trB = (trB + trBhold) >> 1; - _trC = (trC + trChold) >> 1; - _trD = (trD + trDhold) >> 1; -} - -#endif diff --git a/lib/lv_drivers/indev/AD_touch.h b/lib/lv_drivers/indev/AD_touch.h deleted file mode 100644 index 7c07ab37..00000000 --- a/lib/lv_drivers/indev/AD_touch.h +++ /dev/null @@ -1,120 +0,0 @@ -/** - * @file AD_touch.h - * - */ - -#ifndef AD_TOUCH_H -#define AD_TOUCH_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_AD_TOUCH - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -#define _SUPPRESS_PLIB_WARNING -#include - -#include "GenericTypeDefs.h" - -#define DISP_ORIENTATION 0 -#define DISP_HOR_RESOLUTION 320 -#define DISP_VER_RESOLUTION 240 - -/*GetMaxX Macro*/ -#if (DISP_ORIENTATION == 90) || (DISP_ORIENTATION == 270) -#define GetMaxX() (DISP_VER_RESOLUTION - 1) -#elif (DISP_ORIENTATION == 0) || (DISP_ORIENTATION == 180) -#define GetMaxX() (DISP_HOR_RESOLUTION - 1) -#endif - -/*GetMaxY Macro*/ -#if (DISP_ORIENTATION == 90) || (DISP_ORIENTATION == 270) -#define GetMaxY() (DISP_HOR_RESOLUTION - 1) -#elif (DISP_ORIENTATION == 0) || (DISP_ORIENTATION == 180) -#define GetMaxY() (DISP_VER_RESOLUTION - 1) -#endif - -/********************************************************************* - * HARDWARE PROFILE FOR THE RESISTIVE TOUCHSCREEN - *********************************************************************/ - -#define TOUCH_ADC_INPUT_SEL AD1CHS - -// ADC Sample Start -#define TOUCH_ADC_START AD1CON1bits.SAMP - -// ADC Status -#define TOUCH_ADC_DONE AD1CON1bits.DONE - -#define RESISTIVETOUCH_ANALOG 1 -#define RESISTIVETOUCH_DIGITAL 0 - -// ADC channel constants -#define ADC_XPOS ADC_CH0_POS_SAMPLEA_AN12 -#define ADC_YPOS ADC_CH0_POS_SAMPLEA_AN13 - -// ADC Port Control Bits -#define ADPCFG_XPOS AD1PCFGbits.PCFG12 //XR -#define ADPCFG_YPOS AD1PCFGbits.PCFG13 //YD - -// X port definitions -#define ResistiveTouchScreen_XPlus_Drive_High() LATBbits.LATB12 = 1 -#define ResistiveTouchScreen_XPlus_Drive_Low() LATBbits.LATB12 = 0 //LAT_XPOS -#define ResistiveTouchScreen_XPlus_Config_As_Input() TRISBbits.TRISB12 = 1 //TRIS_XPOS -#define ResistiveTouchScreen_XPlus_Config_As_Output() TRISBbits.TRISB12 = 0 - -#define ResistiveTouchScreen_XMinus_Drive_High() LATFbits.LATF0 = 1 -#define ResistiveTouchScreen_XMinus_Drive_Low() LATFbits.LATF0 = 0 //LAT_XNEG -#define ResistiveTouchScreen_XMinus_Config_As_Input() TRISFbits.TRISF0 = 1 //TRIS_XNEG -#define ResistiveTouchScreen_XMinus_Config_As_Output() TRISFbits.TRISF0 = 0 - -// Y port definitions -#define ResistiveTouchScreen_YPlus_Drive_High() LATBbits.LATB13 = 1 -#define ResistiveTouchScreen_YPlus_Drive_Low() LATBbits.LATB13 = 0 //LAT_YPOS -#define ResistiveTouchScreen_YPlus_Config_As_Input() TRISBbits.TRISB13 = 1 //TRIS_YPOS -#define ResistiveTouchScreen_YPlus_Config_As_Output() TRISBbits.TRISB13 = 0 - -#define ResistiveTouchScreen_YMinus_Drive_High() LATFbits.LATF1 = 1 -#define ResistiveTouchScreen_YMinus_Drive_Low() LATFbits.LATF1 = 0 //LAT_YNEG -#define ResistiveTouchScreen_YMinus_Config_As_Input() TRISFbits.TRISF1 = 1 //TRIS_YNEG -#define ResistiveTouchScreen_YMinus_Config_As_Output() TRISFbits.TRISF1 = 0 - -// Default calibration points -#define TOUCHCAL_ULX 0x0348 -#define TOUCHCAL_ULY 0x00CC -#define TOUCHCAL_URX 0x00D2 -#define TOUCHCAL_URY 0x00CE -#define TOUCHCAL_LLX 0x034D -#define TOUCHCAL_LLY 0x0335 -#define TOUCHCAL_LRX 0x00D6 -#define TOUCHCAL_LRY 0x032D - -void ad_touch_init(void); -bool ad_touch_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); -int16_t ad_touch_handler(void); - -#endif /* USE_AD_TOUCH */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* AD_TOUCH_H */ diff --git a/lib/lv_drivers/indev/FT5406EE8.c b/lib/lv_drivers/indev/FT5406EE8.c deleted file mode 100644 index e753a183..00000000 --- a/lib/lv_drivers/indev/FT5406EE8.c +++ /dev/null @@ -1,179 +0,0 @@ -/** - * @file FT5406EE8.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "FT5406EE8.h" -#if USE_FT5406EE8 - -#include -#include -#include LV_DRV_INDEV_INCLUDE -#include LV_DRV_DELAY_INCLUDE - -/********************* - * DEFINES - *********************/ - -#define I2C_WR_BIT 0x00 -#define I2C_RD_BIT 0x01 - -/*DEVICE MODES*/ -#define OPERAT_MD 0x00 -#define TEST_MD 0x04 -#define SYS_INF_MD 0x01 - -/*OPERATING MODE*/ -#define DEVICE_MODE 0x00 -#define GEST_ID 0x01 -#define TD_STATUS 0x02 - -#define FT5406EE8_FINGER_MAX 10 - -/*Register adresses*/ -#define FT5406EE8_REG_DEVICE_MODE 0x00 -#define FT5406EE8_REG_GEST_ID 0x01 -#define FT5406EE8_REG_TD_STATUS 0x02 -#define FT5406EE8_REG_YH 0x03 -#define FT5406EE8_REG_YL 0x04 -#define FT5406EE8_REG_XH 0x05 -#define FT5406EE8_REG_XL 0x06 - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -static bool ft5406ee8_get_touch_num(void); -static bool ft5406ee8_read_finger1(int16_t * x, int16_t * y); - -/********************** - * STATIC VARIABLES - **********************/ - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * - */ -void ft5406ee8_init(void) -{ - -} - -/** - * Get the current position and state of the touchpad - * @param data store the read data here - * @return false: because no ore data to be read - */ -bool ft5406ee8_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) -{ - static int16_t x_last; - static int16_t y_last; - int16_t x; - int16_t y; - bool valid = true; - - valid = ft5406ee8_get_touch_num(); - if(valid == true) { - valid = ft5406ee8_read_finger1(&x, &y); - } - - if(valid == true) { - x = (uint32_t)((uint32_t)x * 320) / 2048; - y = (uint32_t)((uint32_t)y * 240) / 2048; - - - x_last = x; - y_last = y; - } else { - x = x_last; - y = y_last; - } - - data->point.x = x; - data->point.y = y; - data->state = valid == false ? LV_INDEV_STATE_REL : LV_INDEV_STATE_PR; - return false; -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -static bool ft5406ee8_get_touch_num(void) -{ - bool ok = true; - uint8_t t_num = 0; - - LV_DRV_INDEV_I2C_START; - LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_WR_BIT); - LV_DRV_INDEV_I2C_WR(FT5406EE8_REG_TD_STATUS) - LV_DRV_INDEV_I2C_RESTART; - LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_RD_BIT); - t_num = LV_DRV_INDEV_I2C_READ(0); - - /* Error if not touched or too much finger */ - if(t_num > FT5406EE8_FINGER_MAX || t_num == 0) { - ok = false; - } - - return ok; -} - -/** - * Read the x and y coordinated - * @param x store the x coordinate here - * @param y store the y coordinate here - * @return false: not valid point; true: valid point - */ -static bool ft5406ee8_read_finger1(int16_t * x, int16_t * y) -{ - uint8_t temp_xH = 0; - uint8_t temp_xL = 0; - uint8_t temp_yH = 0; - uint8_t temp_yL = 0; - - /*Read Y High and low byte*/ - LV_DRV_INDEV_I2C_START; - LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_WR_BIT); - LV_DRV_INDEV_I2C_WR(FT5406EE8_REG_YH) - LV_DRV_INDEV_I2C_RESTART; - LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_RD_BIT); - temp_yH = LV_DRV_INDEV_I2C_READ(1); - temp_yL = LV_DRV_INDEV_I2C_READ(1); - - /*The upper two bit must be 2 on valid press*/ - if(((temp_yH >> 6) & 0xFF) != 2) { - (void) LV_DRV_INDEV_I2C_READ(0); /*Dummy read to close read sequence*/ - *x = 0; - *y = 0; - return false; - } - - /*Read X High and low byte*/ - temp_xH = LV_DRV_INDEV_I2C_READ(1); - temp_xL = LV_DRV_INDEV_I2C_READ(0); - - /*Save the result*/ - *x = (temp_xH & 0x0F) << 8; - *x += temp_xL; - *y = (temp_yH & 0x0F) << 8; - *y += temp_yL; - - return true; -} - -#endif diff --git a/lib/lv_drivers/indev/FT5406EE8.h b/lib/lv_drivers/indev/FT5406EE8.h deleted file mode 100644 index 2d1eda7d..00000000 --- a/lib/lv_drivers/indev/FT5406EE8.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @file FT5406EE8.h - * - */ - -#ifndef FT5406EE8_H -#define FT5406EE8_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_FT5406EE8 - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void ft5406ee8_init(void); -bool ft5406ee8_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); - -/********************** - * MACROS - **********************/ - -#endif /* USE_FT5406EE8 */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* FT5406EE8_H */ diff --git a/lib/lv_drivers/indev/XPT2046.cpp b/lib/lv_drivers/indev/XPT2046.cpp deleted file mode 100644 index 3edafa7f..00000000 --- a/lib/lv_drivers/indev/XPT2046.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/** - * @file XPT2046.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "XPT2046.h" -#if USE_XPT2046 - -#include -#include LV_DRV_INDEV_INCLUDE -#include LV_DRV_DELAY_INCLUDE -#include -#include "XPT2046_Touchscreen.h" - -/********************* - * DEFINES - *********************/ -#define CMD_X_READ 0b10010000 -#define CMD_Y_READ 0b11010000 - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static void xpt2046_corr(int16_t * x, int16_t * y); -static void xpt2046_avg(int16_t * x, int16_t * y); - -/********************** - * STATIC VARIABLES - **********************/ -int16_t avg_buf_x[XPT2046_AVG]; -int16_t avg_buf_y[XPT2046_AVG]; -uint8_t avg_last; -#if defined(STM32F407ZG) -#include "SoftSPI.h" -SoftSPI xpt2046_spi(PF11, PB2, PB0); -XPT2046_Touchscreen ts(PC13); -#else -SPIClass xpt2046_spi(PB15, PB14, PB13, PB12); -XPT2046_Touchscreen ts(PB12); -#endif -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the XPT2046 - */ -void xpt2046_init(uint8_t rotation) -{ - ts.begin(); - ts.setRotation(rotation); -} - -/** - * Get the current position and state of the touchpad - * @param data store the read data here - * @return false: because no ore data to be read - */ -bool xpt2046_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) -{ - static int16_t last_x = 0; - static int16_t last_y = 0; - uint8_t buf; - - int16_t x = 0; - int16_t y = 0; - - // uint8_t irq = LV_DRV_INDEV_IRQ_READ; - data->state = ts.touched(); - - if(data->state) { - TS_Point p = ts.getPoint(); - x = p.x; - y = p.y; - xpt2046_corr(&x, &y); - -#if 0 - // LV_DRV_INDEV_SPI_CS(0); - xpt2046_spi.beginTransaction(SPI_SETTING); - digitalWrite(PB12, LOW); - - xpt2046_spi.transfer(CMD_X_READ); /*Start x read*/ - - buf = xpt2046_spi.transfer(0); /*Read x MSB*/ - x = buf << 8; - buf = xpt2046_spi.transfer(CMD_Y_READ); /*Until x LSB converted y command can be sent*/ - x += buf; - - buf = xpt2046_spi.transfer(0); /*Read y MSB*/ - y = buf << 8; - - buf = xpt2046_spi.transfer(0); /*Read y LSB*/ - y += buf; - - /*Normalize Data*/ - x = x >> 3; - y = y >> 3; - xpt2046_corr(&x, &y); - xpt2046_avg(&x, &y); - - last_x = x; - last_y = y; - data->state = LV_INDEV_STATE_PR; - - if(data->state) { - Serial.print(x); - Serial.print(" - "); - Serial.println(y); - } else { - Serial.print("."); - } - - // LV_DRV_INDEV_SPI_CS(1); - digitalWrite(PB12, HIGH); - xpt2046_spi.endTransaction(); -#endif - } else { - x = last_x; - y = last_y; - avg_last = 0; - data->state = LV_INDEV_STATE_REL; - } - - data->point.x = x; - data->point.y = y; - if(data->state) { - Serial.print(x); - Serial.print(" - "); - Serial.println(y); - } else { - // Serial.print("."); - } - - return false; -} - -/********************** - * STATIC FUNCTIONS - **********************/ -static void xpt2046_corr(int16_t * x, int16_t * y) -{ -#if XPT2046_XY_SWAP != 0 - int16_t swap_tmp; - swap_tmp = *x; - *x = *y; - *y = swap_tmp; -#endif - - if((*x) > XPT2046_X_MIN) - (*x) -= XPT2046_X_MIN; - else - (*x) = 0; - - if((*y) > XPT2046_Y_MIN) - (*y) -= XPT2046_Y_MIN; - else - (*y) = 0; - - (*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES) / (XPT2046_X_MAX - XPT2046_X_MIN); - - (*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES) / (XPT2046_Y_MAX - XPT2046_Y_MIN); - -#if XPT2046_X_INV != 0 - (*x) = XPT2046_HOR_RES - (*x); -#endif - -#if XPT2046_Y_INV != 0 - (*y) = XPT2046_VER_RES - (*y); -#endif -} - -static void xpt2046_avg(int16_t * x, int16_t * y) -{ - /*Shift out the oldest data*/ - uint8_t i; - for(i = XPT2046_AVG - 1; i > 0; i--) { - avg_buf_x[i] = avg_buf_x[i - 1]; - avg_buf_y[i] = avg_buf_y[i - 1]; - } - - /*Insert the new point*/ - avg_buf_x[0] = *x; - avg_buf_y[0] = *y; - if(avg_last < XPT2046_AVG) avg_last++; - - /*Sum the x and y coordinates*/ - int32_t x_sum = 0; - int32_t y_sum = 0; - for(i = 0; i < avg_last; i++) { - x_sum += avg_buf_x[i]; - y_sum += avg_buf_y[i]; - } - - /*Normalize the sums*/ - (*x) = (int32_t)x_sum / avg_last; - (*y) = (int32_t)y_sum / avg_last; -} - -#endif diff --git a/lib/lv_drivers/indev/XPT2046.h b/lib/lv_drivers/indev/XPT2046.h deleted file mode 100644 index 7a8c047f..00000000 --- a/lib/lv_drivers/indev/XPT2046.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @file XPT2046.h - * - */ - -#ifndef XPT2046_H -#define XPT2046_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_XPT2046 - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void xpt2046_init(uint8_t rotation); -bool xpt2046_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); - -/********************** - * MACROS - **********************/ - -#endif /* USE_XPT2046 */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* XPT2046_H */ diff --git a/lib/lv_drivers/indev/XPT2046_alt_drv.cpp b/lib/lv_drivers/indev/XPT2046_alt_drv.cpp deleted file mode 100644 index fab4ffcf..00000000 --- a/lib/lv_drivers/indev/XPT2046_alt_drv.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file XPT2046.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "XPT2046_alt_drv.h" -#if USE_XPT2046_ALT_DRV - -#include -#include LV_DRV_INDEV_INCLUDE -#include LV_DRV_DELAY_INCLUDE -#include - -/********************* - * DEFINES - *********************/ -#define CS_PIN PB12 - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ -XPT2046_Touchscreen ts(CS_PIN); - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the XPT2046 - */ -void xpt2046_alt_drv_init(uint8_t rotation) -{ - ts.begin(); - ts.setRotation(rotation); -} - -/** - * Get the current position and state of the touchpad - * @param data store the read data here - * @return false: because no more data to be read - */ -bool xpt2046_alt_drv_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) -{ - data->state = ts.touched(); - if(data->state) { - TS_Point p = ts.getPoint(); - data->point.x = p.x; - data->point.y = p.y; - Serial.print(p.x); - Serial.print(" - "); - Serial.println(p.y); - } - return false; -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -#endif diff --git a/lib/lv_drivers/indev/XPT2046_alt_drv.h b/lib/lv_drivers/indev/XPT2046_alt_drv.h deleted file mode 100644 index 7918ed68..00000000 --- a/lib/lv_drivers/indev/XPT2046_alt_drv.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @file XPT2046_alt_drv.h - * - */ - -#ifndef XPT2046_ALT_DRV_H -#define XPT2046_ALT_DRV_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_XPT2046_ALT_DRV - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void xpt2046_alt_drv_init(uint8_t rotation); -bool xpt2046_alt_drv_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); - -/********************** - * MACROS - **********************/ - -#endif /* USE_XPT2046_ALT_DRV */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* XPT2046_ALT_DRV_H */ diff --git a/lib/lv_drivers/indev/evdev.c b/lib/lv_drivers/indev/evdev.c deleted file mode 100644 index 9912e099..00000000 --- a/lib/lv_drivers/indev/evdev.c +++ /dev/null @@ -1,223 +0,0 @@ -/** - * @file evdev.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "evdev.h" -#if USE_EVDEV != 0 - -#include -#include -#include -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -int map(int x, int in_min, int in_max, int out_min, int out_max); - -/********************** - * STATIC VARIABLES - **********************/ -int evdev_fd; -int evdev_root_x; -int evdev_root_y; -int evdev_button; - -int evdev_key_val; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the evdev interface - */ -void evdev_init(void) -{ - evdev_fd = open(EVDEV_NAME, O_RDWR | O_NOCTTY | O_NDELAY); - if(evdev_fd == -1) { - perror("unable open evdev interface:"); - return; - } - - fcntl(evdev_fd, F_SETFL, O_ASYNC | O_NONBLOCK); - - evdev_root_x = 0; - evdev_root_y = 0; - evdev_key_val = 0; - evdev_button = LV_INDEV_STATE_REL; -} -/** - * reconfigure the device file for evdev - * @param dev_name set the evdev device filename - * @return true: the device file set complete - * false: the device file doesn't exist current system - */ -bool evdev_set_file(char* dev_name) -{ - if(evdev_fd != -1) { - close(evdev_fd); - } - evdev_fd = open(dev_name, O_RDWR | O_NOCTTY | O_NDELAY); - - if(evdev_fd == -1) { - perror("unable open evdev interface:"); - return false; - } - - fcntl(evdev_fd, F_SETFL, O_ASYNC | O_NONBLOCK); - - evdev_root_x = 0; - evdev_root_y = 0; - evdev_key_val = 0; - evdev_button = LV_INDEV_STATE_REL; - - return true; -} -/** - * Get the current position and state of the evdev - * @param data store the evdev data here - * @return false: because the points are not buffered, so no more data to be read - */ -bool evdev_read(lv_indev_drv_t * drv, lv_indev_data_t * data) -{ - struct input_event in; - - while(read(evdev_fd, &in, sizeof(struct input_event)) > 0) { - if(in.type == EV_REL) { - if(in.code == REL_X) - #if EVDEV_SWAP_AXES - evdev_root_y += in.value; - #else - evdev_root_x += in.value; - #endif - else if(in.code == REL_Y) - #if EVDEV_SWAP_AXES - evdev_root_x += in.value; - #else - evdev_root_y += in.value; - #endif - } else if(in.type == EV_ABS) { - if(in.code == ABS_X) - #if EVDEV_SWAP_AXES - evdev_root_y = in.value; - #else - evdev_root_x = in.value; - #endif - else if(in.code == ABS_Y) - #if EVDEV_SWAP_AXES - evdev_root_x = in.value; - #else - evdev_root_y = in.value; - #endif - else if(in.code == ABS_MT_POSITION_X) - #if EVDEV_SWAP_AXES - evdev_root_y = in.value; - #else - evdev_root_x = in.value; - #endif - else if(in.code == ABS_MT_POSITION_Y) - #if EVDEV_SWAP_AXES - evdev_root_x = in.value; - #else - evdev_root_y = in.value; - #endif - } else if(in.type == EV_KEY) { - if(in.code == BTN_MOUSE || in.code == BTN_TOUCH) { - if(in.value == 0) - evdev_button = LV_INDEV_STATE_REL; - else if(in.value == 1) - evdev_button = LV_INDEV_STATE_PR; - } else if(drv->type == LV_INDEV_TYPE_KEYPAD) { - data->state = (in.value) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; - switch(in.code) { - case KEY_BACKSPACE: - data->key = LV_KEY_BACKSPACE; - break; - case KEY_ENTER: - data->key = LV_KEY_ENTER; - break; - case KEY_UP: - data->key = LV_KEY_UP; - break; - case KEY_LEFT: - data->key = LV_KEY_PREV; - break; - case KEY_RIGHT: - data->key = LV_KEY_NEXT; - break; - case KEY_DOWN: - data->key = LV_KEY_DOWN; - break; - default: - data->key = 0; - break; - } - evdev_key_val = data->key; - evdev_button = data->state; - return false; - } - } - } - - if(drv->type == LV_INDEV_TYPE_KEYPAD) { - /* No data retrieved */ - data->key = evdev_key_val; - data->state = evdev_button; - return false; - } - if(drv->type != LV_INDEV_TYPE_POINTER) - return false; - /*Store the collected data*/ - -#if EVDEV_SCALE - data->point.x = map(evdev_root_x, 0, EVDEV_SCALE_HOR_RES, 0, lv_disp_get_hor_res(drv->disp)); - data->point.y = map(evdev_root_y, 0, EVDEV_SCALE_VER_RES, 0, lv_disp_get_ver_res(drv->disp)); -#endif -#if EVDEV_CALIBRATE - data->point.x = map(evdev_root_x, EVDEV_HOR_MIN, EVDEV_HOR_MAX, 0, lv_disp_get_hor_res(drv->disp)); - data->point.y = map(evdev_root_y, EVDEV_VER_MIN, EVDEV_VER_MAX, 0, lv_disp_get_ver_res(drv->disp)); -#else - data->point.x = evdev_root_x; - data->point.y = evdev_root_y; -#endif - - data->state = evdev_button; - - if(data->point.x < 0) - data->point.x = 0; - if(data->point.y < 0) - data->point.y = 0; - if(data->point.x >= lv_disp_get_hor_res(drv->disp)) - data->point.x = lv_disp_get_hor_res(drv->disp) - 1; - if(data->point.y >= lv_disp_get_ver_res(drv->disp)) - data->point.y = lv_disp_get_ver_res(drv->disp) - 1; - - return false; -} - -/********************** - * STATIC FUNCTIONS - **********************/ -int map(int x, int in_min, int in_max, int out_min, int out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - -#endif diff --git a/lib/lv_drivers/indev/evdev.h b/lib/lv_drivers/indev/evdev.h deleted file mode 100644 index 3a598dd4..00000000 --- a/lib/lv_drivers/indev/evdev.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @file evdev.h - * - */ - -#ifndef EVDEV_H -#define EVDEV_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_EVDEV - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the evdev - */ -void evdev_init(void); -/** - * reconfigure the device file for evdev - * @param dev_name set the evdev device filename - * @return true: the device file set complete - * false: the device file doesn't exist current system - */ -bool evdev_set_file(char* dev_name); -/** - * Get the current position and state of the evdev - * @param data store the evdev data here - * @return false: because the points are not buffered, so no more data to be read - */ -bool evdev_read(lv_indev_drv_t * drv, lv_indev_data_t * data); - - -/********************** - * MACROS - **********************/ - -#endif /* USE_EVDEV */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* EVDEV_H */ diff --git a/lib/lv_drivers/indev/indev.mk b/lib/lv_drivers/indev/indev.mk deleted file mode 100644 index 09ff47d0..00000000 --- a/lib/lv_drivers/indev/indev.mk +++ /dev/null @@ -1,12 +0,0 @@ -CSRCS += FT5406EE8.c -CSRCS += keyboard.c -CSRCS += mouse.c -CSRCS += mousewheel.c -CSRCS += evdev.c -CSRCS += libinput.c -CSRCS += XPT2046.c - -DEPPATH += --dep-path $(LVGL_DIR)/lv_drivers/indev -VPATH += :$(LVGL_DIR)/lv_drivers/indev - -CFLAGS += "-I$(LVGL_DIR)/lv_drivers/indev" diff --git a/lib/lv_drivers/indev/keyboard.c b/lib/lv_drivers/indev/keyboard.c deleted file mode 100644 index 2f4549af..00000000 --- a/lib/lv_drivers/indev/keyboard.c +++ /dev/null @@ -1,130 +0,0 @@ -/** - * @file sdl_kb.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "keyboard.h" -#if USE_KEYBOARD - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static uint32_t keycode_to_ascii(uint32_t sdl_key); - -/********************** - * STATIC VARIABLES - **********************/ -static uint32_t last_key; -static lv_indev_state_t state; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the keyboard - */ -void keyboard_init(void) -{ - /*Nothing to init*/ -} - -/** - * Get the last pressed or released character from the PC's keyboard - * @param indev_drv pointer to the related input device driver - * @param data store the read data here - * @return false: because the points are not buffered, so no more data to be read - */ -bool keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) -{ - (void) indev_drv; /*Unused*/ - data->state = state; - data->key = keycode_to_ascii(last_key); - - return false; -} - -/** - * It is called periodically from the SDL thread to check a key is pressed/released - * @param event describes the event - */ -void keyboard_handler(SDL_Event * event) -{ - /* We only care about SDL_KEYDOWN and SDL_KEYUP events */ - switch(event->type) { - case SDL_KEYDOWN: /*Button press*/ - last_key = event->key.keysym.sym; /*Save the pressed key*/ - state = LV_INDEV_STATE_PR; /*Save the key is pressed now*/ - break; - case SDL_KEYUP: /*Button release*/ - state = LV_INDEV_STATE_REL; /*Save the key is released but keep the last key*/ - break; - default: - break; - - } -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -/** - * Convert the key code LV_KEY_... "codes" or leave them if they are not control characters - * @param sdl_key the key code - * @return - */ -static uint32_t keycode_to_ascii(uint32_t sdl_key) -{ - /*Remap some key to LV_KEY_... to manage groups*/ - switch(sdl_key) { - case SDLK_RIGHT: - case SDLK_KP_PLUS: - return LV_KEY_RIGHT; - - case SDLK_LEFT: - case SDLK_KP_MINUS: - return LV_KEY_LEFT; - - case SDLK_UP: - return LV_KEY_UP; - - case SDLK_DOWN: - return LV_KEY_DOWN; - - case SDLK_ESCAPE: - return LV_KEY_ESC; - -#ifdef LV_KEY_BACKSPACE /*For backward compatibility*/ - case SDLK_BACKSPACE: - return LV_KEY_BACKSPACE; -#endif - -#ifdef LV_KEY_DEL /*For backward compatibility*/ - case SDLK_DELETE: - return LV_KEY_DEL; -#endif - case SDLK_KP_ENTER: - case '\r': - return LV_KEY_ENTER; - - default: - return sdl_key; - } -} -#endif diff --git a/lib/lv_drivers/indev/keyboard.h b/lib/lv_drivers/indev/keyboard.h deleted file mode 100644 index 03ca15b3..00000000 --- a/lib/lv_drivers/indev/keyboard.h +++ /dev/null @@ -1,78 +0,0 @@ -/** - * @file keyboard.h - * - */ - -#ifndef KEYBOARD_H -#define KEYBOARD_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_KEYBOARD - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -#ifndef MONITOR_SDL_INCLUDE_PATH -#define MONITOR_SDL_INCLUDE_PATH -#endif - -#include MONITOR_SDL_INCLUDE_PATH - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -/** - * Initialize the keyboard - */ -void keyboard_init(void); - -/** - * Get the last pressed or released character from the PC's keyboard - * @param indev_drv pointer to the related input device driver - * @param data store the read data here - * @return false: because the points are not buffered, so no more data to be read - */ -bool keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); - -/** - * It is called periodically from the SDL thread to check a key is pressed/released - * @param event describes the event - */ -void keyboard_handler(SDL_Event *event); - -/********************** - * MACROS - **********************/ - -#endif /*USE_KEYBOARD*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*KEYBOARD_H*/ diff --git a/lib/lv_drivers/indev/libinput.c b/lib/lv_drivers/indev/libinput.c deleted file mode 100644 index 98dfd7df..00000000 --- a/lib/lv_drivers/indev/libinput.c +++ /dev/null @@ -1,175 +0,0 @@ -/** - * @file libinput.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "libinput_drv.h" -#if USE_LIBINPUT != 0 - -#include -#include -#include -#include -#include -#include -#include -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static int open_restricted(const char *path, int flags, void *user_data); -static void close_restricted(int fd, void *user_data); - -/********************** - * STATIC VARIABLES - **********************/ -static int libinput_fd; -static int libinput_button; -static const int timeout = 0; // do not block -static const nfds_t nfds = 1; -static struct pollfd fds[1]; -static lv_point_t most_recent_touch_point = { .x = 0, .y = 0}; - -static struct libinput *libinput_context; -static struct libinput_device *libinput_device; -const static struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * reconfigure the device file for libinput - * @param dev_name set the libinput device filename - * @return true: the device file set complete - * false: the device file doesn't exist current system - */ -bool libinput_set_file(char* dev_name) -{ - // This check *should* not be necessary, yet applications crashes even on NULL handles. - // citing libinput.h:libinput_path_remove_device: - // > If no matching device exists, this function does nothing. - if (libinput_device) { - libinput_device = libinput_device_unref(libinput_device); - libinput_path_remove_device(libinput_device); - } - - libinput_device = libinput_path_add_device(libinput_context, dev_name); - if(!libinput_device) { - perror("unable to add device to libinput context:"); - return false; - } - libinput_device = libinput_device_ref(libinput_device); - if(!libinput_device) { - perror("unable to reference device within libinput context:"); - return false; - } - - libinput_button = LV_INDEV_STATE_REL; - - return true; -} - -/** - * Initialize the libinput interface - */ -void libinput_init(void) -{ - libinput_device = NULL; - libinput_context = libinput_path_create_context(&interface, NULL); - if(!libinput_set_file(LIBINPUT_NAME)) { - perror("unable to add device \"" LIBINPUT_NAME "\" to libinput context:"); - return; - } - libinput_fd = libinput_get_fd(libinput_context); - - /* prepare poll */ - fds[0].fd = libinput_fd; - fds[0].events = POLLIN; - fds[0].revents = 0; -} - -/** - * Get the current position and state of the libinput - * @param indev_drv driver object itself - * @param data store the libinput data here - * @return false: because the points are not buffered, so no more data to be read - */ -bool libinput_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) -{ - struct libinput_event *event; - struct libinput_event_touch *touch_event = NULL; - int rc = 0; - - rc = poll(fds, nfds, timeout); - switch (rc){ - case -1: - perror(NULL); - case 0: - goto report_most_recent_state; - default: - break; - } - libinput_dispatch(libinput_context); - while((event = libinput_get_event(libinput_context)) != NULL) { - enum libinput_event_type type = libinput_event_get_type(event); - switch (type) { - case LIBINPUT_EVENT_TOUCH_MOTION: - case LIBINPUT_EVENT_TOUCH_DOWN: - touch_event = libinput_event_get_touch_event(event); - most_recent_touch_point.x = libinput_event_touch_get_x_transformed(touch_event, LV_HOR_RES); - most_recent_touch_point.y = libinput_event_touch_get_y_transformed(touch_event, LV_VER_RES); - libinput_button = LV_INDEV_STATE_PR; - break; - case LIBINPUT_EVENT_TOUCH_UP: - libinput_button = LV_INDEV_STATE_REL; - break; - default: - break; - } - libinput_event_destroy(event); - } -report_most_recent_state: - data->point.x = most_recent_touch_point.x; - data->point.y = most_recent_touch_point.y; - data->state = libinput_button; - - return false; -} - - -/********************** - * STATIC FUNCTIONS - **********************/ - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd = open(path, flags); - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) -{ - close(fd); -} - -#endif diff --git a/lib/lv_drivers/indev/libinput_drv.h b/lib/lv_drivers/indev/libinput_drv.h deleted file mode 100644 index ae1ee42c..00000000 --- a/lib/lv_drivers/indev/libinput_drv.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @file libinput.h - * - */ - -#ifndef LVGL_LIBINPUT_H -#define LVGL_LIBINPUT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_LIBINPUT - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the libinput - */ -void libinput_init(void); -/** - * reconfigure the device file for libinput - * @param dev_name set the libinput device filename - * @return true: the device file set complete - * false: the device file doesn't exist current system - */ -bool libinput_set_file(char* dev_name); -/** - * Get the current position and state of the libinput - * @param indev_drv driver object itself - * @param data store the libinput data here - * @return false: because the points are not buffered, so no more data to be read - */ -bool libinput_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); - - -/********************** - * MACROS - **********************/ - -#endif /* USE_LIBINPUT */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* LVGL_LIBINPUT_H */ diff --git a/lib/lv_drivers/indev/mouse.c b/lib/lv_drivers/indev/mouse.c deleted file mode 100644 index e4d519b9..00000000 --- a/lib/lv_drivers/indev/mouse.c +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file mouse.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "mouse.h" -#if USE_MOUSE != 0 - -/********************* - * DEFINES - *********************/ -#ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 -#endif - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ -static bool left_button_down = false; -static int16_t last_x = 0; -static int16_t last_y = 0; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the mouse - */ -void mouse_init(void) -{} - -/** - * Get the current position and state of the mouse - * @param indev_drv pointer to the related input device driver - * @param data store the mouse data here - * @return false: because the points are not buffered, so no more data to be read - */ -bool mouse_read(lv_indev_drv_t* indev_drv, lv_indev_data_t* data) -{ - (void)indev_drv; /*Unused*/ - - /*Store the collected data*/ - data->point.x = last_x; - data->point.y = last_y; - data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; - - return false; -} - -/** - * It will be called from the main SDL thread - */ -void mouse_handler(SDL_Event* event) -{ - int x; - int y; - - SDL_Window* window = SDL_GetWindowFromID(event->window.windowID); - SDL_GetWindowSize(window, &x, &y); - - switch(event->type) { - case SDL_MOUSEBUTTONUP: - if(event->button.button == SDL_BUTTON_LEFT) left_button_down = false; - break; - case SDL_MOUSEBUTTONDOWN: - if(event->button.button == SDL_BUTTON_LEFT) { - left_button_down = true; - if(x != 0) last_x = event->motion.x * TFT_WIDTH / x; // / MONITOR_ZOOM; - if(y != 0) last_y = event->motion.y * TFT_HEIGHT / y; // / MONITOR_ZOOM; - } - break; - case SDL_MOUSEMOTION: - if(x != 0) last_x = event->motion.x * TFT_WIDTH / x; // / MONITOR_ZOOM; - if(y != 0) last_y = event->motion.y * TFT_HEIGHT / y; // / MONITOR_ZOOM; - - break; - } -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -#endif diff --git a/lib/lv_drivers/indev/mouse.h b/lib/lv_drivers/indev/mouse.h deleted file mode 100644 index bd04dee1..00000000 --- a/lib/lv_drivers/indev/mouse.h +++ /dev/null @@ -1,78 +0,0 @@ -/** - * @file mouse.h - * - */ - -#ifndef MOUSE_H -#define MOUSE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_MOUSE - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -#ifndef MONITOR_SDL_INCLUDE_PATH -#define MONITOR_SDL_INCLUDE_PATH -#endif - -#include MONITOR_SDL_INCLUDE_PATH - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the mouse - */ -void mouse_init(void); - -/** - * Get the current position and state of the mouse - * @param indev_drv pointer to the related input device driver - * @param data store the mouse data here - * @return false: because the points are not buffered, so no more data to be read - */ -bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); - -/** - * It will be called from the main SDL thread - */ -void mouse_handler(SDL_Event *event); - -/********************** - * MACROS - **********************/ - -#endif /* USE_MOUSE */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* MOUSE_H */ diff --git a/lib/lv_drivers/indev/mousewheel.c b/lib/lv_drivers/indev/mousewheel.c deleted file mode 100644 index 7ada72fd..00000000 --- a/lib/lv_drivers/indev/mousewheel.c +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file mousewheel.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "mousewheel.h" -#if USE_MOUSEWHEEL - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ -static int16_t enc_diff = 0; -static lv_indev_state_t state = LV_INDEV_STATE_REL; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the mousewheel - */ -void mousewheel_init(void) -{ - /*Nothing to init*/ -} - -/** - * Get encoder (i.e. mouse wheel) ticks difference and pressed state - * @param indev_drv pointer to the related input device driver - * @param data store the read data here - * @return false: all ticks and button state are handled - */ -bool mousewheel_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) -{ - (void) indev_drv; /*Unused*/ - - data->state = state; - data->enc_diff = enc_diff; - enc_diff = 0; - - return false; /*No more data to read so return false*/ -} - -/** - * It is called periodically from the SDL thread to check mouse wheel state - * @param event describes the event - */ -void mousewheel_handler(SDL_Event * event) -{ - switch(event->type) { - case SDL_MOUSEWHEEL: - // Scroll down (y = -1) means positive encoder turn, - // so invert it -#ifdef __EMSCRIPTEN__ - /*Escripten scales it wrong*/ - if(event->wheel.y < 0) enc_diff++; - if(event->wheel.y > 0) enc_diff--; -#else - enc_diff = -event->wheel.y; -#endif - break; - case SDL_MOUSEBUTTONDOWN: - if(event->button.button == SDL_BUTTON_MIDDLE) { - state = LV_INDEV_STATE_PR; - } - break; - case SDL_MOUSEBUTTONUP: - if(event->button.button == SDL_BUTTON_MIDDLE) { - state = LV_INDEV_STATE_REL; - } - break; - default: - break; - } -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -#endif diff --git a/lib/lv_drivers/indev/mousewheel.h b/lib/lv_drivers/indev/mousewheel.h deleted file mode 100644 index cbe1ed45..00000000 --- a/lib/lv_drivers/indev/mousewheel.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @file mousewheel.h - * - */ - -#ifndef MOUSEWHEEL_H -#define MOUSEWHEEL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../../lv_drv_conf.h" -#endif -#endif - -#if USE_MOUSEWHEEL - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -#ifndef MONITOR_SDL_INCLUDE_PATH -#define MONITOR_SDL_INCLUDE_PATH -#endif - -#include MONITOR_SDL_INCLUDE_PATH - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the encoder - */ -void mousewheel_init(void); - -/** - * Get encoder (i.e. mouse wheel) ticks difference and pressed state - * @param indev_drv pointer to the related input device driver - * @param data store the read data here - * @return false: all ticks and button state are handled - */ -bool mousewheel_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); - -/** - * It is called periodically from the SDL thread to check a key is pressed/released - * @param event describes the event - */ -void mousewheel_handler(SDL_Event *event); - -/********************** - * MACROS - **********************/ - -#endif /*USE_MOUSEWHEEL*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*MOUSEWHEEL_H*/ diff --git a/lib/lv_drivers/library.json b/lib/lv_drivers/library.json deleted file mode 100644 index cdb6e888..00000000 --- a/lib/lv_drivers/library.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "lv_drivers", - "version": "6.0.2", - "keywords": "littlevgl, lvgl, driver, display, touchpad", - "description": "Drivers for LittlevGL graphics library.", - "repository": { - "type": "git", - "url": "https://github.com/littlevgl/lv_drivers.git" - }, - "build": { - "includeDir": "." - } -} diff --git a/lib/lv_drivers/lv_drivers.mk b/lib/lv_drivers/lv_drivers.mk deleted file mode 100644 index 1bb786c1..00000000 --- a/lib/lv_drivers/lv_drivers.mk +++ /dev/null @@ -1,10 +0,0 @@ -include $(LVGL_DIR)/lv_drivers/display/display.mk -include $(LVGL_DIR)/lv_drivers/indev/indev.mk - - -CSRCS += win_drv.c - -DEPPATH += --dep-path $(LVGL_DIR)/lv_drivers -VPATH += :$(LVGL_DIR)/lv_drivers - -CFLAGS += "-I$(LVGL_DIR)/lv_drivers" diff --git a/lib/lv_drivers/lv_drv_conf_templ.h b/lib/lv_drivers/lv_drv_conf_templ.h deleted file mode 100644 index e3367d38..00000000 --- a/lib/lv_drivers/lv_drv_conf_templ.h +++ /dev/null @@ -1,357 +0,0 @@ -/** - * @file lv_drv_conf.h - * - */ - -/* - * COPY THIS FILE AS lv_drv_conf.h - */ - -#if 0 /*Set it to "1" to enable the content*/ - -#ifndef LV_DRV_CONF_H -#define LV_DRV_CONF_H - -#include "lv_conf.h" - -/********************* - * DELAY INTERFACE - *********************/ -#define LV_DRV_DELAY_INCLUDE /*Dummy include by default*/ -#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/ -#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/ - -/********************* - * DISPLAY INTERFACE - *********************/ - -/*------------ - * Common - *------------*/ -#define LV_DRV_DISP_INCLUDE /*Dummy include by default*/ -#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/ -#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/ - -/*--------- - * SPI - *---------*/ -#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/ -#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/ -#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/ - -/*------------------ - * Parallel port - *-----------------*/ -#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/ -#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/ -#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/ -#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/ -#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/ - -/*************************** - * INPUT DEVICE INTERFACE - ***************************/ - -/*---------- - * Common - *----------*/ -#define LV_DRV_INDEV_INCLUDE /*Dummy include by default*/ -#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/ -#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/ - -/*--------- - * SPI - *---------*/ -#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/ -#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/ - -/*--------- - * I2C - *---------*/ -#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/ -#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/ -#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/ -#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/ -#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/ - - -/********************* - * DISPLAY DRIVERS - *********************/ - -/*------------------- - * Monitor of PC - *-------------------*/ -#ifndef USE_MONITOR -# define USE_MONITOR 0 -#endif - -#if USE_MONITOR -# define MONITOR_HOR_RES LV_HOR_RES -# define MONITOR_VER_RES LV_VER_RES - -/* Scale window by this factor (useful when simulating small screens) */ -# define MONITOR_ZOOM 1 - -/* Used to test true double buffering with only address changing. - * Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */ -# define MONITOR_DOUBLE_BUFFERED 0 - -/*Eclipse: Visual Studio: */ -# define MONITOR_SDL_INCLUDE_PATH - -/*Different rendering might be used if running in a Virtual machine*/ -# define MONITOR_VIRTUAL_MACHINE 0 - -/*Open two windows to test multi display support*/ -# define MONITOR_DUAL 0 -#endif - -/*----------------------------------- - * Native Windows (including mouse) - *----------------------------------*/ -#ifndef USE_WINDOWS -# define USE_WINDOWS 0 -#endif - -#define USE_WINDOWS 0 -#if USE_WINDOWS -# define WINDOW_HOR_RES 480 -# define WINDOW_VER_RES 320 -#endif - -/*---------------- - * SSD1963 - *--------------*/ -#ifndef USE_SSD1963 -# define USE_SSD1963 0 -#endif - -#if USE_SSD1963 -# define SSD1963_HOR_RES LV_HOR_RES -# define SSD1963_VER_RES LV_VER_RES -# define SSD1963_HT 531 -# define SSD1963_HPS 43 -# define SSD1963_LPS 8 -# define SSD1963_HPW 10 -# define SSD1963_VT 288 -# define SSD1963_VPS 12 -# define SSD1963_FPS 4 -# define SSD1963_VPW 10 -# define SSD1963_HS_NEG 0 /*Negative hsync*/ -# define SSD1963_VS_NEG 0 /*Negative vsync*/ -# define SSD1963_ORI 0 /*0, 90, 180, 270*/ -# define SSD1963_COLOR_DEPTH 16 -#endif - -/*---------------- - * R61581 - *--------------*/ -#ifndef USE_R61581 -# define USE_R61581 0 -#endif - -#if USE_R61581 -# define R61581_HOR_RES LV_HOR_RES -# define R61581_VER_RES LV_VER_RES -# define R61581_HSPL 0 /*HSYNC signal polarity*/ -# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/ -# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/ -# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */ -# define R61581_VSPL 0 /*VSYNC signal polarity*/ -# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/ -# define R61581_VFP 8 /*Vertical Front poarch*/ -# define R61581_VBP 8 /*Vertical Back poarch */ -# define R61581_DPL 0 /*DCLK signal polarity*/ -# define R61581_EPL 1 /*ENABLE signal polarity*/ -# define R61581_ORI 0 /*0, 180*/ -# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/ -#endif - -/*------------------------------ - * ST7565 (Monochrome, low res.) - *-----------------------------*/ -#ifndef USE_ST7565 -# define USE_ST7565 0 -#endif - -#if USE_ST7565 -/*No settings*/ -#endif /*USE_ST7565*/ - -/*------------------------------------------ - * UC1610 (4 gray 160*[104|128]) - * (EA DOGXL160 160x104 tested) - *-----------------------------------------*/ -#ifndef USE_UC1610 -# define USE_UC1610 0 -#endif - -#if USE_UC1610 -# define UC1610_HOR_RES LV_HOR_RES -# define UC1610_VER_RES LV_VER_RES -# define UC1610_INIT_CONTRAST 33 /* init contrast, values in [%] */ -# define UC1610_INIT_HARD_RST 0 /* 1 : hardware reset at init, 0 : software reset */ -# define UC1610_TOP_VIEW 0 /* 0 : Bottom View, 1 : Top View */ -#endif /*USE_UC1610*/ - -/*------------------------------------------------- - * SHARP memory in pixel monochrome display series - * LS012B7DD01 (184x38 pixels.) - * LS013B7DH03 (128x128 pixels.) - * LS013B7DH05 (144x168 pixels.) - * LS027B7DH01 (400x240 pixels.) (tested) - * LS032B7DD02 (336x536 pixels.) - * LS044Q7DH01 (320x240 pixels.) - *------------------------------------------------*/ -#ifndef USE_SHARP_MIP -# define USE_SHARP_MIP 0 -#endif - -#if USE_SHARP_MIP -# define SHARP_MIP_HOR_RES LV_HOR_RES -# define SHARP_MIP_VER_RES LV_VER_RES -# define SHARP_MIP_SOFT_COM_INVERSION 0 -# define SHARP_MIP_REV_BYTE(b) /*((uint8_t) __REV(__RBIT(b)))*/ /*Architecture / compiler dependent byte bits order reverse*/ -#endif /*USE_SHARP_MIP*/ - -/*----------------------------------------- - * Linux frame buffer device (/dev/fbx) - *-----------------------------------------*/ -#ifndef USE_FBDEV -# define USE_FBDEV 0 -#endif - -#if USE_FBDEV -# define FBDEV_PATH "/dev/fb0" -#endif - -/*----------------------------------------- - * FreeBSD frame buffer device (/dev/fbx) - *.........................................*/ -#ifndef USE_BSD_FBDEV -# define USE_BSD_FBDEV 0 -#endif - -#if USE_BSD_FBDEV -# define FBDEV_PATH "/dev/fb0" -#endif - -/********************* - * INPUT DEVICES - *********************/ - -/*-------------- - * XPT2046 - *--------------*/ -#ifndef USE_XPT2046 -# define USE_XPT2046 0 -#endif - -#if USE_XPT2046 -# define XPT2046_HOR_RES 480 -# define XPT2046_VER_RES 320 -# define XPT2046_X_MIN 200 -# define XPT2046_Y_MIN 200 -# define XPT2046_X_MAX 3800 -# define XPT2046_Y_MAX 3800 -# define XPT2046_AVG 4 -# define XPT2046_INV 0 -#endif - -/*----------------- - * FT5406EE8 - *-----------------*/ -#ifndef USE_FT5406EE8 -# define USE_FT5406EE8 0 -#endif - -#if USE_FT5406EE8 -# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/ -#endif - -/*--------------- - * AD TOUCH - *--------------*/ -#ifndef USE_AD_TOUCH -# define USE_AD_TOUCH 0 -#endif - -#if USE_AD_TOUCH -/*No settings*/ -#endif - - -/*--------------------------------------- - * Mouse or touchpad on PC (using SDL) - *-------------------------------------*/ -#ifndef USE_MOUSE -# define USE_MOUSE 0 -#endif - -#if USE_MOUSE -/*No settings*/ -#endif - -/*------------------------------------------- - * Mousewheel as encoder on PC (using SDL) - *------------------------------------------*/ -#ifndef USE_MOUSEWHEEL -# define USE_MOUSEWHEEL 0 -#endif - -#if USE_MOUSEWHEEL -/*No settings*/ -#endif - -/*------------------------------------------------- - * Touchscreen as libinput interface (for Linux based systems) - *------------------------------------------------*/ -#ifndef USE_LIBINPUT -# define USE_LIBINPUT 0 -#endif - -#if USE_LIBINPUT -# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -#endif /*USE_LIBINPUT*/ - -/*------------------------------------------------- - * Mouse or touchpad as evdev interface (for Linux based systems) - *------------------------------------------------*/ -#ifndef USE_EVDEV -# define USE_EVDEV 0 -#endif - -#if USE_EVDEV -# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/ - -# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */ -# if EVDEV_SCALE -# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */ -# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */ -# endif /*EVDEV_SCALE*/ - -# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/ -# if EVDEV_CALIBRATE -# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/ -# define EVDEV_HOR_MAX 200 -# define EVDEV_VER_MIN 200 -# define EVDEV_VER_MAX 3800 -# endif /*EVDEV_SCALE*/ -#endif /*USE_EVDEV*/ - -/*------------------------------- - * Keyboard of a PC (using SDL) - *------------------------------*/ -#ifndef USE_KEYBOARD -# define USE_KEYBOARD 0 -#endif - -#if USE_KEYBOARD -/*No settings*/ -#endif - -#endif /*LV_DRV_CONF_H*/ - -#endif /*End of "Content enable"*/ diff --git a/lib/lv_drivers/win_drv.c b/lib/lv_drivers/win_drv.c deleted file mode 100644 index 3115f555..00000000 --- a/lib/lv_drivers/win_drv.c +++ /dev/null @@ -1,318 +0,0 @@ -/** - * @file win_drv.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "win_drv.h" -#if USE_WINDOWS - -#include -#include -#include "lvgl/lvgl.h" - -#if LV_COLOR_DEPTH < 16 -#error Windows driver only supports true RGB colors at this time -#endif - -/********************** - * DEFINES - **********************/ - - #define WINDOW_STYLE (WS_OVERLAPPEDWINDOW & ~(WS_SIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME)) - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static void do_register(void); -static void win_drv_flush(lv_disp_t *drv, lv_area_t *area, const lv_color_t * color_p); -static void win_drv_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); -static void win_drv_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); -static bool win_drv_read(lv_indev_t *drv, lv_indev_data_t * data); -static void msg_handler(void *param); - -static COLORREF lv_color_to_colorref(const lv_color_t color); - -static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); - - -/********************** - * GLOBAL VARIABLES - **********************/ - -bool lv_win_exit_flag = false; -lv_disp_t *lv_windows_disp; - -/********************** - * STATIC VARIABLES - **********************/ -static HWND hwnd; -static uint32_t *fbp = NULL; /* Raw framebuffer memory */ -static bool mouse_pressed; -static int mouse_x, mouse_y; - - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ -const char g_szClassName[] = "LittlevGL"; - -HWND windrv_init(void) -{ - WNDCLASSEX wc; - RECT winrect; - HICON lvgl_icon; - - //Step 1: Registering the Window Class - wc.cbSize = sizeof(WNDCLASSEX); - wc.style = 0; - wc.lpfnWndProc = WndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = GetModuleHandle(NULL); - lvgl_icon = (HICON) LoadImage( NULL, "lvgl_icon.bmp", IMAGE_ICON, 0, 0, LR_LOADFROMFILE); - - if(lvgl_icon == NULL) - lvgl_icon = LoadIcon(NULL, IDI_APPLICATION); - - wc.hIcon = lvgl_icon; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wc.lpszMenuName = NULL; - wc.lpszClassName = g_szClassName; - wc.hIconSm = lvgl_icon; - - if(!RegisterClassEx(&wc)) - { - return NULL; - } - - winrect.left = 0; - winrect.right = WINDOW_HOR_RES - 1; - winrect.top = 0; - winrect.bottom = WINDOW_VER_RES - 1; - AdjustWindowRectEx(&winrect, WINDOW_STYLE, FALSE, WS_EX_CLIENTEDGE); - OffsetRect(&winrect, -winrect.left, -winrect.top); - // Step 2: Creating the Window - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, - g_szClassName, - "LittlevGL Simulator", - WINDOW_STYLE, - CW_USEDEFAULT, CW_USEDEFAULT, winrect.right, winrect.bottom, - NULL, NULL, GetModuleHandle(NULL), NULL); - - if(hwnd == NULL) - { - return NULL; - } - - ShowWindow(hwnd, SW_SHOWDEFAULT); - UpdateWindow(hwnd); - - - lv_task_create(msg_handler, 0, LV_TASK_PRIO_HIGHEST, NULL); - lv_win_exit_flag = false; - do_register(); -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -static void do_register(void) -{ - /*----------------------------- - * Create a buffer for drawing - *----------------------------*/ - - /* LittlevGL requires a buffer where it draw the objects. The buffer's has to be greater than 1 display row - * - * There are three buffering configurations: - * 1. Create ONE buffer some rows: LittlevGL will draw the display's content here and writes it to your display - * 2. Create TWO buffer some rows: LittlevGL will draw the display's content to a buffer and writes it your display. - * You should use DMA to write the buffer's content to the display. - * It will enable LittlevGL to draw the next part of the screen to the other buffer while - * the data is being sent form the first buffer. It makes rendering and flushing parallel. - * 3. Create TWO screen buffer: Similar to 2) but the buffer have to be screen sized. When LittlevGL is ready it will give the - * whole frame to display. This way you only need to change the frame buffer's address instead of - * copying the pixels. - * */ - - /* Example for 1) */ - static lv_disp_buf_t disp_buf_1; - static lv_color_t buf1_1[WINDOW_HOR_RES * WINDOW_VER_RES]; /*A buffer for 10 rows*/ - lv_disp_buf_init(&disp_buf_1, buf1_1, NULL, WINDOW_HOR_RES * WINDOW_VER_RES); /*Initialize the display buffer*/ - - - /*----------------------------------- - * Register the display in LittlevGL - *----------------------------------*/ - - lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ - lv_disp_drv_init(&disp_drv); /*Basic initialization*/ - - /*Set up the functions to access to your display*/ - - /*Set the resolution of the display*/ - disp_drv.hor_res = WINDOW_HOR_RES; - disp_drv.ver_res = WINDOW_VER_RES; - - /*Used to copy the buffer's content to the display*/ - disp_drv.flush_cb = win_drv_flush; - - /*Set a display buffer*/ - disp_drv.buffer = &disp_buf_1; - - /*Finally register the driver*/ - lv_windows_disp = lv_disp_drv_register(&disp_drv); - lv_indev_drv_t indev_drv; - lv_indev_drv_init(&indev_drv); - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read_cb = win_drv_read; - lv_indev_drv_register(&indev_drv); -} - -static void msg_handler(void *param) -{ - (void)param; - - MSG msg; - BOOL bRet; - if( (bRet = PeekMessage( &msg, NULL, 0, 0, TRUE )) != 0) - { - if (bRet == -1) - { - return; - } - else - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - if(msg.message == WM_QUIT) - lv_win_exit_flag = true; -} - - static bool win_drv_read(lv_indev_t *drv, lv_indev_data_t * data) -{ - data->state = mouse_pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; - data->point.x = mouse_x; - data->point.y = mouse_y; - return false; -} - - static void on_paint(void) - { - HBITMAP bmp = CreateBitmap(WINDOW_HOR_RES, WINDOW_VER_RES, 1, 32, fbp); - PAINTSTRUCT ps; - - HDC hdc = BeginPaint(hwnd, &ps); - - HDC hdcMem = CreateCompatibleDC(hdc); - HBITMAP hbmOld = SelectObject(hdcMem, bmp); - - BitBlt(hdc, 0, 0, WINDOW_HOR_RES, WINDOW_VER_RES, hdcMem, 0, 0, SRCCOPY); - - SelectObject(hdcMem, hbmOld); - DeleteDC(hdcMem); - - EndPaint(hwnd, &ps); - DeleteObject(bmp); - -} -/** - * Flush a buffer to the marked area - * @param x1 left coordinate - * @param y1 top coordinate - * @param x2 right coordinate - * @param y2 bottom coordinate - * @param color_p an array of colors - */ -static void win_drv_flush(lv_disp_t *drv, lv_area_t *area, const lv_color_t * color_p) -{ - win_drv_map(area->x1, area->y1, area->x2, area->y2, color_p); - lv_disp_flush_ready(drv); -} - -/** - * Put a color map to the marked area - * @param x1 left coordinate - * @param y1 top coordinate - * @param x2 right coordinate - * @param y2 bottom coordinate - * @param color_p an array of colors - */ -static void win_drv_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p) -{ - for(int y = y1; y <= y2; y++) - { - for(int x = x1; x <= x2; x++) - { - fbp[y*WINDOW_HOR_RES+x] = lv_color_to32(*color_p); - color_p++; - } - } - InvalidateRect(hwnd, NULL, FALSE); - UpdateWindow(hwnd); -} - -static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - HDC hdc; - PAINTSTRUCT ps; - switch(msg) { - case WM_CREATE: - fbp = malloc(4*WINDOW_HOR_RES*WINDOW_VER_RES); - if(fbp == NULL) - return 1; - - return 0; - case WM_MOUSEMOVE: - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - mouse_x = GET_X_LPARAM(lParam); - mouse_y = GET_Y_LPARAM(lParam); - if(msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) { - mouse_pressed = (msg == WM_LBUTTONDOWN); - } - return 0; - case WM_CLOSE: - free(fbp); - fbp = NULL; - DestroyWindow(hwnd); - return 0; - case WM_PAINT: - on_paint(); - return 0; - case WM_DESTROY: - PostQuitMessage(0); - return 0; - default: - break; - } - return DefWindowProc(hwnd, msg, wParam, lParam); -} -static COLORREF lv_color_to_colorref(const lv_color_t color) -{ - uint32_t raw_color = lv_color_to32(color); - lv_color32_t tmp; - tmp.full = raw_color; - uint32_t colorref = RGB(tmp.ch.red, tmp.ch.green, tmp.ch.blue); - return colorref; -} -#endif - - - diff --git a/lib/lv_drivers/win_drv.h b/lib/lv_drivers/win_drv.h deleted file mode 100644 index 7a0f9b25..00000000 --- a/lib/lv_drivers/win_drv.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file fbdev.h - * - */ - -#ifndef WINDRV_H -#define WINDRV_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifndef LV_DRV_NO_CONF -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_drv_conf.h" -#else -#include "../lv_drv_conf.h" -#endif -#endif - -#if USE_WINDOWS - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -extern bool lv_win_exit_flag; -extern lv_disp_t *lv_windows_disp; - -HWND windrv_init(void); - -/********************** - * MACROS - **********************/ - -#endif /*USE_WINDOWS*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*WIN_DRV_H*/ From 3259bdcbe840e549f5264279664d3c0554a1f7b6 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 9 Mar 2021 20:26:37 +0100 Subject: [PATCH 166/236] Add Windows OS version --- src/dev/win32/hasp_win32.cpp | 2 +- src/dev/win32/hasp_win32.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 6142cdb8..2a30ec1d 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -52,7 +52,7 @@ void Win32Device::set_hostname(const char* hostname) } const char* Win32Device::get_core_version() { - return "win32"; + return _core_version.c_str(); } const char* Win32Device::get_display_driver() { diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index 75f72bac..f833b60f 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -35,6 +35,17 @@ class Win32Device : public BaseDevice { _hostname = "localhost"; } + // Get the Windows version. + DWORD dwBuild = 0; + DWORD dwVersion = GetVersion(); + DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); + DWORD dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); + if(dwVersion < 0x80000000) dwBuild = (DWORD)(HIWORD(dwVersion)); + + char version[128]; + snprintf(version, sizeof(version), "Windows %d.%d-%d", dwMajorVersion, dwMinorVersion, dwBuild); + _core_version = version; + // _backlight_pin = -1; _backlight_power = 1; _backlight_level = 100; @@ -63,6 +74,7 @@ class Win32Device : public BaseDevice { private: std::string _hostname; + std::string _core_version; uint8_t _backlight_pin; uint8_t _backlight_level; From e0993614a1cc540c7b5661fdb2d807f037be85e5 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 9 Mar 2021 20:27:29 +0100 Subject: [PATCH 167/236] Update configuration --- include/lv_conf_v7.h | 3 ++- user_setups/esp32/lanbon_l8.ini | 4 ++++ user_setups/esp32_partition_app1536k_spiffs1024k.csv | 6 ++++++ user_setups/esp32_partition_app2000k_spiffs4000k.csv | 6 ++++++ user_setups/lcd_config.ini | 1 - 5 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 user_setups/esp32_partition_app1536k_spiffs1024k.csv create mode 100644 user_setups/esp32_partition_app2000k_spiffs4000k.csv diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index 68955047..acba32d9 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -190,7 +190,8 @@ typedef void* lv_fs_drv_user_data_t; # define LV_FS_IF_PC '\0' # define LV_FS_IF_SPIFFS '\0' // internal esp Flash #else -# define LV_FS_IF_PC 'S' +# define LV_FS_IF_PC '\0' +# define LV_FS_IF_POSIX '\0' # define LV_FS_IF_SPIFFS '\0' // no internal esp Flash #endif #endif /*LV_USE_FS_IF*/ diff --git a/user_setups/esp32/lanbon_l8.ini b/user_setups/esp32/lanbon_l8.ini index 4328cc6e..cb7eccba 100644 --- a/user_setups/esp32/lanbon_l8.ini +++ b/user_setups/esp32/lanbon_l8.ini @@ -9,6 +9,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=8MB +board_upload.maximum_size = 8388608 +board_build.partitions = user_setups/esp32_partition_app2000k_spiffs4000k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32_partition_app1536k_spiffs1024k.csv b/user_setups/esp32_partition_app1536k_spiffs1024k.csv new file mode 100644 index 00000000..414702e0 --- /dev/null +++ b/user_setups/esp32_partition_app1536k_spiffs1024k.csv @@ -0,0 +1,6 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x180000, +app1, app, ota_1, 0x190000, 0x180000, +spiffs, data, spiffs, 0x310000, 0x0F0000, diff --git a/user_setups/esp32_partition_app2000k_spiffs4000k.csv b/user_setups/esp32_partition_app2000k_spiffs4000k.csv new file mode 100644 index 00000000..0ada1ac6 --- /dev/null +++ b/user_setups/esp32_partition_app2000k_spiffs4000k.csv @@ -0,0 +1,6 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x1F0000, +app1, app, ota_1, 0x200000, 0x1F0000, +spiffs, data, spiffs, 0x3F0000, 0x410000, diff --git a/user_setups/lcd_config.ini b/user_setups/lcd_config.ini index 2065f3c9..ee240560 100644 --- a/user_setups/lcd_config.ini +++ b/user_setups/lcd_config.ini @@ -75,7 +75,6 @@ st7789v = -D SPI_FREQUENCY=80000000 -D SPI_READ_FREQUENCY=6000000 -D USER_SETUP_LOADED=1 - ;-D TOUCH_DRIVER=6336 ; FT6336U Capacitive I2C touch panel driver -D SUPPORT_TRANSACTIONS wt32-sc01 = From e7c10e799144bca07ee0c164ce3310e132895b4b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 9 Mar 2021 20:27:56 +0100 Subject: [PATCH 168/236] Optimize theme size --- src/hasp/lv_theme_hasp.c | 233 +++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 134 deletions(-) diff --git a/src/hasp/lv_theme_hasp.c b/src/hasp/lv_theme_hasp.c index 5a736abe..38a94843 100644 --- a/src/hasp/lv_theme_hasp.c +++ b/src/hasp/lv_theme_hasp.c @@ -15,13 +15,15 @@ #include "src/lv_misc/lv_gc.h" #if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE +#include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* * DEFINES *********************/ +#define HASP_DPX(n) (n == 0 ? 0 : LV_MATH_MAX(((LV_DPI * (n) + 80) / 160), 1)) /*+80 for rounding*/ + /*SCREEN*/ #define COLOR_SCR (IS_LIGHT ? LV_COLOR_WHITE : lv_color_hex(0x545b6a)) @@ -74,15 +76,15 @@ #define COLOR_BG_SEC_TEXT_DIS (IS_LIGHT ? lv_color_hex(0xaaaaaa) : lv_color_hex(0xa5a8ad)) #define TRANSITION_TIME 0 /*((theme.flags & LV_THEME_HASP_FLAG_NO_TRANSITION) ? 0 : 150)*/ -#define BORDER_WIDTH LV_DPX(2) +#define BORDER_WIDTH HASP_DPX(2) #define BORDER_COLOR ((theme.flags & IS_LIGHT) ? lv_color_make(0x40, 0x40, 0x40) : lv_color_make(0xb0, 0xb0, 0xb0)) -#define OUTLINE_WIDTH ((theme.flags & LV_THEME_HASP_FLAG_NO_FOCUS) ? 0 : LV_DPX(3)) +#define OUTLINE_WIDTH ((theme.flags & LV_THEME_HASP_FLAG_NO_FOCUS) ? 0 : HASP_DPX(3)) #define OUTLINE_COLOR ((theme.flags & LV_THEME_HASP_FLAG_NO_FOCUS) ? BORDER_COLOR : theme.color_secondary) #define IS_LIGHT (theme.flags & LV_THEME_HASP_FLAG_LIGHT) #define NO_FOCUS (theme.flags & LV_THEME_HASP_FLAG_NO_FOCUS) -#define PAD_DEF (lv_disp_get_size_category(NULL) <= LV_DISP_SIZE_MEDIUM ? LV_DPX(15) : (LV_DPX(30))) +#define PAD_DEF (lv_disp_get_size_category(NULL) <= LV_DISP_SIZE_MEDIUM ? HASP_DPX(15) : (HASP_DPX(30))) /*SCROLLBAR*/ #define SCROLLBAR_COLOR \ @@ -162,9 +164,9 @@ typedef struct #if LV_USE_PAGE lv_style_t sb; - #if LV_USE_ANIMATION +#if LV_USE_ANIMATION lv_style_t edge_flash; - #endif +#endif #endif #if LV_USE_SLIDER @@ -196,14 +198,14 @@ typedef struct /********************** * STATIC PROTOTYPES **********************/ -static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name); -static void style_init_reset(lv_style_t * style); +static void theme_apply(lv_theme_t* th, lv_obj_t* obj, lv_theme_style_t name); +static void style_init_reset(lv_style_t* style); /********************** * STATIC VARIABLES **********************/ static lv_theme_t theme; -static theme_styles_t * styles; +static theme_styles_t* styles; static bool inited; @@ -217,6 +219,7 @@ static bool inited; static void basic_init(void) { + sizeof(lv_style_t); // Objects with transparent background, like Checkbox, container style_init_reset(&styles->transparent); @@ -245,7 +248,7 @@ static void basic_init(void) lv_style_set_scale_end_color(&styles->pretty, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_text_color(&styles->pretty, LV_STATE_DEFAULT, COLOR_SCR_TEXT); - //lv_style_set_text_font(&styles->pretty, LV_STATE_DEFAULT, theme.font_normal); + // lv_style_set_text_font(&styles->pretty, LV_STATE_DEFAULT, theme.font_normal); lv_style_set_value_color(&styles->pretty, LV_STATE_DEFAULT, COLOR_SCR_TEXT); lv_style_set_value_font(&styles->pretty, LV_STATE_DEFAULT, theme.font_subtitle); @@ -275,7 +278,7 @@ static void basic_init(void) lv_style_set_scale_end_color(&styles->pretty_color, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_text_color(&styles->pretty_color, LV_STATE_DEFAULT, COLOR_SCR_TEXT); lv_style_set_line_color(&styles->pretty_color, LV_STATE_DEFAULT, lv_color_make(0x20, 0x20, 0x20)); - //lv_style_set_text_font(&styles->pretty_color, LV_STATE_DEFAULT, theme.font_normal); + // lv_style_set_text_font(&styles->pretty_color, LV_STATE_DEFAULT, theme.font_normal); lv_style_set_value_font(&styles->pretty_color, LV_STATE_DEFAULT, theme.font_subtitle); lv_style_set_value_color(&styles->pretty_color, LV_STATE_DEFAULT, COLOR_SCR_TEXT); @@ -381,11 +384,9 @@ static void basic_init(void) lv_style_set_value_color(&styles->btn, LV_STATE_DISABLED, IS_LIGHT ? lv_color_hex(0x888888) : lv_color_hex(0x888888)); - lv_style_set_pad_left(&styles->btn, LV_STATE_DEFAULT, LV_DPX(40)); - lv_style_set_pad_right(&styles->btn, LV_STATE_DEFAULT, LV_DPX(40)); - lv_style_set_pad_top(&styles->btn, LV_STATE_DEFAULT, LV_DPX(15)); - lv_style_set_pad_bottom(&styles->btn, LV_STATE_DEFAULT, LV_DPX(15)); - lv_style_set_pad_inner(&styles->btn, LV_STATE_DEFAULT, LV_DPX(20)); + lv_style_set_pad_hor(&styles->btn, LV_STATE_DEFAULT, HASP_DPX(40)); + lv_style_set_pad_ver(&styles->btn, LV_STATE_DEFAULT, HASP_DPX(15)); + lv_style_set_pad_inner(&styles->btn, LV_STATE_DEFAULT, HASP_DPX(20)); lv_style_set_outline_width(&styles->btn, LV_STATE_DEFAULT, OUTLINE_WIDTH); if(!NO_FOCUS) { @@ -404,16 +405,17 @@ static void basic_init(void) style_init_reset(&styles->pad_inner); lv_style_set_pad_inner(&styles->pad_inner, LV_STATE_DEFAULT, - lv_disp_get_size_category(NULL) <= LV_DISP_MEDIUM_LIMIT ? LV_DPX(20) : LV_DPX(40)); + lv_disp_get_size_category(NULL) <= LV_DISP_MEDIUM_LIMIT ? HASP_DPX(20) : HASP_DPX(40)); style_init_reset(&styles->pad_small); - lv_style_int_t pad_small_value = lv_disp_get_size_category(NULL) <= LV_DISP_MEDIUM_LIMIT ? LV_DPX(10) : LV_DPX(20); + lv_style_int_t pad_small_value = + lv_disp_get_size_category(NULL) <= LV_DISP_MEDIUM_LIMIT ? HASP_DPX(10) : HASP_DPX(20); lv_style_set_pad_all(&styles->pad_small, LV_STATE_DEFAULT, pad_small_value); lv_style_set_pad_inner(&styles->pad_small, LV_STATE_DEFAULT, pad_small_value); #if LV_USE_DROPDOWN || LV_USE_ROLLER style_init_reset(&styles->line_space); - lv_style_set_text_line_space(&styles->line_space, LV_STATE_DEFAULT, LV_DPX(20)); + lv_style_set_text_line_space(&styles->line_space, LV_STATE_DEFAULT, HASP_DPX(20)); lv_style_set_clip_corner(&styles->line_space, LV_STATE_DEFAULT, true); style_init_reset(&styles->selected); @@ -495,10 +497,10 @@ static void led_init(void) lv_style_set_border_opa(&styles->led, LV_STATE_DEFAULT, LV_OPA_50); lv_style_set_border_color(&styles->led, LV_STATE_DEFAULT, lv_color_lighten(theme.color_primary, LV_OPA_30)); lv_style_set_radius(&styles->led, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_shadow_width(&styles->led, LV_STATE_DEFAULT, LV_DPX(15)); + lv_style_set_shadow_width(&styles->led, LV_STATE_DEFAULT, HASP_DPX(15)); lv_style_set_shadow_color(&styles->led, LV_STATE_DEFAULT, theme.color_primary); - lv_style_set_shadow_spread(&styles->led, LV_STATE_DEFAULT, LV_DPX(5)); - lv_style_set_margin_all(&styles->led, LV_STATE_DEFAULT, LV_DPX(5)); + lv_style_set_shadow_spread(&styles->led, LV_STATE_DEFAULT, HASP_DPX(5)); + lv_style_set_margin_all(&styles->led, LV_STATE_DEFAULT, HASP_DPX(5)); #endif } @@ -511,16 +513,10 @@ static void slider_init(void) // lv_style_set_value_color(&styles->slider_knob, LV_STATE_DEFAULT, // IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); // lv_style_set_radius(&styles->slider_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_pad_left(&styles->slider_knob, LV_STATE_DEFAULT, LV_DPX(7)); - lv_style_set_pad_right(&styles->slider_knob, LV_STATE_DEFAULT, LV_DPX(7)); - lv_style_set_pad_top(&styles->slider_knob, LV_STATE_DEFAULT, LV_DPX(7)); - lv_style_set_pad_bottom(&styles->slider_knob, LV_STATE_DEFAULT, LV_DPX(7)); + lv_style_set_pad_all(&styles->slider_knob, LV_STATE_DEFAULT, HASP_DPX(7)); style_init_reset(&styles->slider_bg); - lv_style_set_margin_left(&styles->slider_bg, LV_STATE_DEFAULT, LV_DPX(10)); - lv_style_set_margin_right(&styles->slider_bg, LV_STATE_DEFAULT, LV_DPX(10)); - lv_style_set_margin_top(&styles->slider_bg, LV_STATE_DEFAULT, LV_DPX(10)); - lv_style_set_margin_bottom(&styles->slider_bg, LV_STATE_DEFAULT, LV_DPX(10)); + lv_style_set_margin_all(&styles->slider_bg, LV_STATE_DEFAULT, HASP_DPX(10)); #endif } @@ -532,10 +528,7 @@ static void switch_init(void) // lv_style_set_bg_opa(&styles->sw_knob, LV_STATE_DEFAULT, LV_OPA_COVER); // lv_style_set_bg_color(&styles->sw_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); // lv_style_set_radius(&styles->sw_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_pad_top(&styles->sw_knob, LV_STATE_DEFAULT, LV_DPX(2)); - lv_style_set_pad_bottom(&styles->sw_knob, LV_STATE_DEFAULT, LV_DPX(2)); - lv_style_set_pad_left(&styles->sw_knob, LV_STATE_DEFAULT, LV_DPX(2)); - lv_style_set_pad_right(&styles->sw_knob, LV_STATE_DEFAULT, LV_DPX(2)); + lv_style_set_pad_all(&styles->sw_knob, LV_STATE_DEFAULT, HASP_DPX(2)); #endif } @@ -544,17 +537,16 @@ static void linemeter_init(void) #if LV_USE_LINEMETER != 0 style_init_reset(&styles->lmeter); lv_style_set_radius(&styles->lmeter, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_pad_left(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(20)); - lv_style_set_pad_right(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(20)); - lv_style_set_pad_top(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(20)); - lv_style_set_pad_inner(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(30)); - lv_style_set_scale_width(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(25)); + lv_style_set_pad_hor(&styles->lmeter, LV_STATE_DEFAULT, HASP_DPX(20)); + lv_style_set_pad_top(&styles->lmeter, LV_STATE_DEFAULT, HASP_DPX(20)); + lv_style_set_pad_inner(&styles->lmeter, LV_STATE_DEFAULT, HASP_DPX(30)); + lv_style_set_scale_width(&styles->lmeter, LV_STATE_DEFAULT, HASP_DPX(25)); lv_style_set_line_color(&styles->lmeter, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_scale_grad_color(&styles->lmeter, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_scale_end_color(&styles->lmeter, LV_STATE_DEFAULT, lv_color_hex3(0x888)); - lv_style_set_line_width(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(10)); - lv_style_set_scale_end_line_width(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(7)); + lv_style_set_line_width(&styles->lmeter, LV_STATE_DEFAULT, HASP_DPX(10)); + lv_style_set_scale_end_line_width(&styles->lmeter, LV_STATE_DEFAULT, HASP_DPX(7)); #endif } @@ -565,34 +557,33 @@ static void gauge_init(void) lv_style_set_line_color(&styles->gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_grad_color(&styles->gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_end_color(&styles->gauge_main, LV_STATE_DEFAULT, theme.color_primary); - lv_style_set_line_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(2)); // normal scale minor thick width + lv_style_set_line_width(&styles->gauge_main, LV_STATE_DEFAULT, HASP_DPX(2)); // normal scale minor thick width lv_style_set_scale_end_line_width(&styles->gauge_main, LV_STATE_DEFAULT, - LV_DPX(2)); // strong scale minor tick width - lv_style_set_scale_end_border_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(3)); - lv_style_set_pad_left(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20)); // left margin - lv_style_set_pad_right(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20)); // right margin - lv_style_set_pad_top(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20)); // top margin - lv_style_set_pad_inner(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(15)); // position of the labels - lv_style_set_scale_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(10)); // minor thick length + HASP_DPX(2)); // strong scale minor tick width + lv_style_set_scale_end_border_width(&styles->gauge_main, LV_STATE_DEFAULT, HASP_DPX(3)); + lv_style_set_pad_hor(&styles->gauge_main, LV_STATE_DEFAULT, HASP_DPX(20)); // left margin + lv_style_set_pad_top(&styles->gauge_main, LV_STATE_DEFAULT, HASP_DPX(20)); // top margin + lv_style_set_pad_inner(&styles->gauge_main, LV_STATE_DEFAULT, HASP_DPX(15)); // position of the labels + lv_style_set_scale_width(&styles->gauge_main, LV_STATE_DEFAULT, HASP_DPX(10)); // minor thick length lv_style_set_radius(&styles->gauge_main, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); style_init_reset(&styles->gauge_strong); lv_style_set_line_color(&styles->gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_grad_color(&styles->gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_end_color(&styles->gauge_strong, LV_STATE_DEFAULT, theme.color_primary); - lv_style_set_line_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(8)); // strong scale arc width - lv_style_set_scale_end_line_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(8)); - lv_style_set_scale_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(20)); // major thick length + lv_style_set_line_width(&styles->gauge_strong, LV_STATE_DEFAULT, HASP_DPX(8)); // strong scale arc width + lv_style_set_scale_end_line_width(&styles->gauge_strong, LV_STATE_DEFAULT, HASP_DPX(8)); + lv_style_set_scale_width(&styles->gauge_strong, LV_STATE_DEFAULT, HASP_DPX(20)); // major thick length style_init_reset(&styles->gauge_needle); lv_style_set_line_color(&styles->gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE); - lv_style_set_line_width(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(8)); + lv_style_set_line_width(&styles->gauge_needle, LV_STATE_DEFAULT, HASP_DPX(8)); lv_style_set_bg_opa(&styles->gauge_needle, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE); lv_style_set_radius(&styles->gauge_needle, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_size(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(30)); - lv_style_set_pad_inner(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(10)); + lv_style_set_size(&styles->gauge_needle, LV_STATE_DEFAULT, HASP_DPX(30)); + lv_style_set_pad_inner(&styles->gauge_needle, LV_STATE_DEFAULT, HASP_DPX(10)); #endif } @@ -601,15 +592,15 @@ static void arc_init(void) #if LV_USE_ARC != 0 style_init_reset(&styles->arc_indic); lv_style_set_line_color(&styles->arc_indic, LV_STATE_DEFAULT, theme.color_primary); - lv_style_set_line_width(&styles->arc_indic, LV_STATE_DEFAULT, LV_DPX(25)); + lv_style_set_line_width(&styles->arc_indic, LV_STATE_DEFAULT, HASP_DPX(25)); lv_style_set_line_rounded(&styles->arc_indic, LV_STATE_DEFAULT, true); style_init_reset(&styles->arc_bg); lv_style_set_line_color(&styles->arc_bg, LV_STATE_DEFAULT, lv_color_mix(BORDER_COLOR, COLOR_SCR_GRAD, 128)); - lv_style_set_line_width(&styles->arc_bg, LV_STATE_DEFAULT, LV_DPX(25)); + lv_style_set_line_width(&styles->arc_bg, LV_STATE_DEFAULT, HASP_DPX(25)); lv_style_set_line_rounded(&styles->arc_bg, LV_STATE_DEFAULT, true); lv_style_set_radius(&styles->arc_bg, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_border_width(&styles->arc_bg, LV_STATE_DEFAULT, LV_DPX(25)); + lv_style_set_border_width(&styles->arc_bg, LV_STATE_DEFAULT, HASP_DPX(25)); /* lv_style_set_border_opa(&styles->pretty_color, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_border_opa(&styles->pretty_color, LV_STATE_FOCUSED, LV_OPA_30); @@ -619,10 +610,7 @@ static void arc_init(void) */ style_init_reset(&styles->arc_knob); lv_style_set_radius(&styles->arc_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_pad_top(&styles->arc_knob, LV_STATE_DEFAULT, LV_DPX(0)); - lv_style_set_pad_bottom(&styles->arc_knob, LV_STATE_DEFAULT, LV_DPX(0)); - lv_style_set_pad_left(&styles->arc_knob, LV_STATE_DEFAULT, LV_DPX(0)); - lv_style_set_pad_right(&styles->arc_knob, LV_STATE_DEFAULT, LV_DPX(0)); + lv_style_set_pad_all(&styles->arc_knob, LV_STATE_DEFAULT, HASP_DPX(0)); #endif } @@ -640,16 +628,16 @@ static void chart_init(void) lv_style_set_text_color(&styles->chart_bg, LV_STATE_DEFAULT, IS_LIGHT ? COLOR_BG_TEXT_DIS : lv_color_hex(0xa1adbd)); style_init_reset(&styles->chart_series_bg); - lv_style_set_line_width(&styles->chart_series_bg, LV_STATE_DEFAULT, LV_DPX(1)); - lv_style_set_line_dash_width(&styles->chart_series_bg, LV_STATE_DEFAULT, LV_DPX(10)); - lv_style_set_line_dash_gap(&styles->chart_series_bg, LV_STATE_DEFAULT, LV_DPX(10)); + lv_style_set_line_width(&styles->chart_series_bg, LV_STATE_DEFAULT, HASP_DPX(1)); + lv_style_set_line_dash_width(&styles->chart_series_bg, LV_STATE_DEFAULT, HASP_DPX(10)); + lv_style_set_line_dash_gap(&styles->chart_series_bg, LV_STATE_DEFAULT, HASP_DPX(10)); lv_style_set_line_color(&styles->chart_series_bg, LV_STATE_DEFAULT, COLOR_BG_BORDER); style_init_reset(&styles->chart_series); - lv_style_set_line_width(&styles->chart_series, LV_STATE_DEFAULT, LV_DPX(3)); - lv_style_set_size(&styles->chart_series, LV_STATE_DEFAULT, LV_DPX(4)); - lv_style_set_pad_inner(&styles->chart_series, LV_STATE_DEFAULT, LV_DPX(2)); /*Space between columns*/ - lv_style_set_radius(&styles->chart_series, LV_STATE_DEFAULT, LV_DPX(1)); + lv_style_set_line_width(&styles->chart_series, LV_STATE_DEFAULT, HASP_DPX(3)); + lv_style_set_size(&styles->chart_series, LV_STATE_DEFAULT, HASP_DPX(4)); + lv_style_set_pad_inner(&styles->chart_series, LV_STATE_DEFAULT, HASP_DPX(2)); /*Space between columns*/ + lv_style_set_radius(&styles->chart_series, LV_STATE_DEFAULT, HASP_DPX(1)); #endif } @@ -658,7 +646,7 @@ static void calendar_init(void) { #if LV_USE_CALENDAR style_init_reset(&styles->calendar_date_nums); - lv_style_set_radius(&styles->calendar_date_nums, LV_STATE_DEFAULT, LV_DPX(4)); + lv_style_set_radius(&styles->calendar_date_nums, LV_STATE_DEFAULT, HASP_DPX(4)); lv_style_set_text_color(&styles->calendar_date_nums, LV_STATE_CHECKED, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); lv_style_set_text_color(&styles->calendar_date_nums, LV_STATE_DISABLED, LV_COLOR_GRAY); @@ -673,9 +661,8 @@ static void calendar_init(void) lv_style_set_border_width(&styles->calendar_date_nums, LV_STATE_CHECKED, 2); lv_style_set_border_side(&styles->calendar_date_nums, LV_STATE_CHECKED, LV_BORDER_SIDE_LEFT); lv_style_set_border_color(&styles->calendar_date_nums, LV_STATE_CHECKED, theme.color_primary); - lv_style_set_pad_inner(&styles->calendar_date_nums, LV_STATE_DEFAULT, LV_DPX(3)); - lv_style_set_pad_left(&styles->calendar_date_nums, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_right(&styles->calendar_date_nums, LV_STATE_DEFAULT, PAD_DEF); + lv_style_set_pad_inner(&styles->calendar_date_nums, LV_STATE_DEFAULT, HASP_DPX(3)); + lv_style_set_pad_hor(&styles->calendar_date_nums, LV_STATE_DEFAULT, PAD_DEF); lv_style_set_pad_bottom(&styles->calendar_date_nums, LV_STATE_DEFAULT, PAD_DEF); #endif } @@ -684,10 +671,10 @@ static void cpicker_init(void) { #if LV_USE_CPICKER style_init_reset(&styles->cpicker_bg); - lv_style_set_scale_width(&styles->cpicker_bg, LV_STATE_DEFAULT, LV_DPX(30)); + lv_style_set_scale_width(&styles->cpicker_bg, LV_STATE_DEFAULT, HASP_DPX(30)); lv_style_set_bg_opa(&styles->cpicker_bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->cpicker_bg, LV_STATE_DEFAULT, COLOR_SCR); - lv_style_set_pad_inner(&styles->cpicker_bg, LV_STATE_DEFAULT, LV_DPX(20)); + lv_style_set_pad_inner(&styles->cpicker_bg, LV_STATE_DEFAULT, HASP_DPX(20)); lv_style_set_radius(&styles->cpicker_bg, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); style_init_reset(&styles->cpicker_indic); @@ -698,10 +685,7 @@ static void cpicker_init(void) lv_style_set_border_color(&styles->cpicker_indic, LV_STATE_DEFAULT, LV_COLOR_GRAY); lv_style_set_border_color(&styles->cpicker_indic, LV_STATE_FOCUSED, theme.color_primary); lv_style_set_border_color(&styles->cpicker_indic, LV_STATE_EDITED, theme.color_secondary); - lv_style_set_pad_left(&styles->cpicker_indic, LV_STATE_DEFAULT, LV_DPX(13)); - lv_style_set_pad_right(&styles->cpicker_indic, LV_STATE_DEFAULT, LV_DPX(13)); - lv_style_set_pad_top(&styles->cpicker_indic, LV_STATE_DEFAULT, LV_DPX(13)); - lv_style_set_pad_bottom(&styles->cpicker_indic, LV_STATE_DEFAULT, LV_DPX(13)); + lv_style_set_pad_all(&styles->cpicker_indic, LV_STATE_DEFAULT, HASP_DPX(13)); #endif } @@ -709,29 +693,26 @@ static void checkbox_init(void) { #if LV_USE_CHECKBOX != 0 /* style_init_reset(&styles->cb_bg); - lv_style_set_radius(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(4)); - lv_style_set_pad_inner(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(10)); + lv_style_set_radius(&styles->cb_bg, LV_STATE_DEFAULT, HASP_DPX(4)); + lv_style_set_pad_inner(&styles->cb_bg, LV_STATE_DEFAULT, HASP_DPX(10)); lv_style_set_outline_color(&styles->cb_bg, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_outline_opa(&styles->cb_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_outline_opa(&styles->cb_bg, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_width(&styles->cb_bg, LV_STATE_DEFAULT, OUTLINE_WIDTH); - lv_style_set_outline_pad(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(10)); + lv_style_set_outline_pad(&styles->cb_bg, LV_STATE_DEFAULT, HASP_DPX(10)); lv_style_set_transition_time(&styles->cb_bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&styles->cb_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); */ style_init_reset(&styles->cb_bullet); lv_style_set_outline_opa(&styles->cb_bullet, LV_STATE_FOCUSED, LV_OPA_TRANSP); - lv_style_set_radius(&styles->cb_bullet, LV_STATE_DEFAULT, LV_DPX(4)); + lv_style_set_radius(&styles->cb_bullet, LV_STATE_DEFAULT, HASP_DPX(4)); lv_style_set_pattern_image(&styles->cb_bullet, LV_STATE_CHECKED, LV_SYMBOL_OK); lv_style_set_pattern_recolor(&styles->cb_bullet, LV_STATE_CHECKED, LV_COLOR_WHITE); lv_style_set_pattern_opa(&styles->cb_bullet, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_pattern_opa(&styles->cb_bullet, LV_STATE_CHECKED, LV_OPA_COVER); lv_style_set_transition_prop_3(&styles->cb_bullet, LV_STATE_DEFAULT, LV_STYLE_PATTERN_OPA); lv_style_set_text_font(&styles->cb_bullet, LV_STATE_CHECKED, theme.font_small); - lv_style_set_pad_left(&styles->cb_bullet, LV_STATE_DEFAULT, LV_DPX(3)); - lv_style_set_pad_right(&styles->cb_bullet, LV_STATE_DEFAULT, LV_DPX(3)); - lv_style_set_pad_top(&styles->cb_bullet, LV_STATE_DEFAULT, LV_DPX(3)); - lv_style_set_pad_bottom(&styles->cb_bullet, LV_STATE_DEFAULT, LV_DPX(3)); + lv_style_set_pad_all(&styles->cb_bullet, LV_STATE_DEFAULT, HASP_DPX(3)); lv_style_set_bg_color(&styles->cb_bullet, LV_STATE_PRESSED, COLOR_BTN_PR); lv_style_set_bg_grad_color(&styles->cb_bullet, LV_STATE_PRESSED, COLOR_BTN_CHK_GRAD); @@ -758,15 +739,12 @@ static void keyboard_init(void) #if LV_USE_KEYBOARD style_init_reset(&styles->kb_bg); lv_style_set_radius(&styles->kb_bg, LV_STATE_DEFAULT, 0); - lv_style_set_border_width(&styles->kb_bg, LV_STATE_DEFAULT, LV_DPX(4)); + lv_style_set_border_width(&styles->kb_bg, LV_STATE_DEFAULT, HASP_DPX(4)); lv_style_set_border_side(&styles->kb_bg, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP); lv_style_set_border_color(&styles->kb_bg, LV_STATE_DEFAULT, IS_LIGHT ? COLOR_BG_TEXT : LV_COLOR_BLACK); lv_style_set_border_color(&styles->kb_bg, LV_STATE_EDITED, theme.color_secondary); - lv_style_set_pad_left(&styles->kb_bg, LV_STATE_DEFAULT, LV_DPX(5)); - lv_style_set_pad_right(&styles->kb_bg, LV_STATE_DEFAULT, LV_DPX(5)); - lv_style_set_pad_top(&styles->kb_bg, LV_STATE_DEFAULT, LV_DPX(5)); - lv_style_set_pad_bottom(&styles->kb_bg, LV_STATE_DEFAULT, LV_DPX(5)); - lv_style_set_pad_inner(&styles->kb_bg, LV_STATE_DEFAULT, LV_DPX(3)); + lv_style_set_pad_all(&styles->kb_bg, LV_STATE_DEFAULT, HASP_DPX(5)); + lv_style_set_pad_inner(&styles->kb_bg, LV_STATE_DEFAULT, HASP_DPX(3)); #endif } @@ -774,7 +752,7 @@ static void msgbox_init(void) { #if LV_USE_MSGBOX style_init_reset(&styles->mbox_bg); - lv_style_set_shadow_width(&styles->mbox_bg, LV_STATE_DEFAULT, LV_DPX(50)); + lv_style_set_shadow_width(&styles->mbox_bg, LV_STATE_DEFAULT, HASP_DPX(50)); lv_style_set_shadow_color(&styles->mbox_bg, LV_STATE_DEFAULT, IS_LIGHT ? LV_COLOR_SILVER : lv_color_hex3(0x777)); #endif @@ -787,15 +765,15 @@ static void page_init(void) lv_style_set_bg_opa(&styles->sb, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->sb, LV_STATE_DEFAULT, SCROLLBAR_COLOR); lv_style_set_radius(&styles->sb, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_size(&styles->sb, LV_STATE_DEFAULT, LV_DPX(7)); - lv_style_set_pad_right(&styles->sb, LV_STATE_DEFAULT, LV_DPX(7)); - lv_style_set_pad_bottom(&styles->sb, LV_STATE_DEFAULT, LV_DPX(7)); + lv_style_set_size(&styles->sb, LV_STATE_DEFAULT, HASP_DPX(7)); + lv_style_set_pad_right(&styles->sb, LV_STATE_DEFAULT, HASP_DPX(7)); + lv_style_set_pad_bottom(&styles->sb, LV_STATE_DEFAULT, HASP_DPX(7)); - #if LV_USE_ANIMATION +#if LV_USE_ANIMATION style_init_reset(&styles->edge_flash); lv_style_set_bg_opa(&styles->edge_flash, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->edge_flash, LV_STATE_DEFAULT, lv_color_hex3(0x888)); - #endif +#endif #endif } @@ -805,7 +783,7 @@ static void textarea_init(void) style_init_reset(&styles->ta_cursor); lv_style_set_border_color(&styles->ta_cursor, LV_STATE_DEFAULT, COLOR_BG_SEC_TEXT); lv_style_set_border_width(&styles->ta_cursor, LV_STATE_DEFAULT, BORDER_WIDTH); - lv_style_set_pad_left(&styles->ta_cursor, LV_STATE_DEFAULT, LV_DPX(1)); + lv_style_set_pad_left(&styles->ta_cursor, LV_STATE_DEFAULT, HASP_DPX(1)); lv_style_set_border_side(&styles->ta_cursor, LV_STATE_DEFAULT, LV_BORDER_SIDE_LEFT); style_init_reset(&styles->ta_placeholder); @@ -822,8 +800,7 @@ static void spinbox_init(void) lv_style_set_bg_opa(&styles->spinbox_cursor, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->spinbox_cursor, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_text_color(&styles->spinbox_cursor, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_style_set_pad_top(&styles->spinbox_cursor, LV_STATE_DEFAULT, LV_DPX(100)); - lv_style_set_pad_bottom(&styles->spinbox_cursor, LV_STATE_DEFAULT, LV_DPX(100)); + lv_style_set_pad_ver(&styles->spinbox_cursor, LV_STATE_DEFAULT, HASP_DPX(100)); #endif } @@ -865,10 +842,7 @@ static void list_init(void) // lv_style_set_outline_width(&styles->list_btn, LV_STATE_FOCUSED, OUTLINE_WIDTH); lv_style_set_outline_pad(&styles->list_btn, LV_STATE_FOCUSED, -BORDER_WIDTH); - lv_style_set_pad_left(&styles->list_btn, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_right(&styles->list_btn, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_top(&styles->list_btn, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_bottom(&styles->list_btn, LV_STATE_DEFAULT, PAD_DEF); + lv_style_set_pad_all(&styles->list_btn, LV_STATE_DEFAULT, PAD_DEF); lv_style_set_pad_inner(&styles->list_btn, LV_STATE_DEFAULT, PAD_DEF); lv_style_set_transform_width(&styles->list_btn, LV_STATE_DEFAULT, -PAD_DEF); @@ -888,7 +862,7 @@ static void ddlist_init(void) #if LV_USE_DROPDOWN != 0 /* style_init_reset(&styles->ddlist_page); - lv_style_set_text_line_space(&styles->ddlist_page, LV_STATE_DEFAULT, LV_DPX(20)); + lv_style_set_text_line_space(&styles->ddlist_page, LV_STATE_DEFAULT, HASP_DPX(20)); lv_style_set_clip_corner(&styles->ddlist_page, LV_STATE_DEFAULT, true); style_init_reset(&styles->ddlist_sel); @@ -907,7 +881,7 @@ static void roller_init(void) { #if LV_USE_ROLLER != 0 /* style_init_reset(&styles->roller_bg); - lv_style_set_text_line_space(&styles->roller_bg, LV_STATE_DEFAULT, LV_DPX(25)); + lv_style_set_text_line_space(&styles->roller_bg, LV_STATE_DEFAULT, HASP_DPX(25)); style_init_reset(&styles->roller_sel); lv_style_set_bg_opa(&styles->roller_sel, LV_STATE_DEFAULT, LV_OPA_COVER); @@ -935,11 +909,7 @@ static void table_init(void) lv_style_set_border_color(&styles->table_cell, LV_STATE_DEFAULT, COLOR_BG_BORDER); lv_style_set_border_width(&styles->table_cell, LV_STATE_DEFAULT, 1); lv_style_set_border_side(&styles->table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); - lv_style_set_pad_left(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_right(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_top(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_bottom(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF); - + lv_style_set_pad_all(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF); #endif } @@ -957,16 +927,14 @@ static void tabview_win_shared_init(void) lv_style_set_bg_color(&styles->tabview_btns_bg, LV_STATE_DEFAULT, COLOR_SCR_GRAD); lv_style_set_text_color(&styles->tabview_btns_bg, LV_STATE_DEFAULT, COLOR_SCR_TEXT); lv_style_set_image_recolor(&styles->tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f)); - lv_style_set_pad_top(&styles->tabview_btns_bg, LV_STATE_DEFAULT, LV_DPX(7)); - lv_style_set_pad_left(&styles->tabview_btns_bg, LV_STATE_DEFAULT, LV_DPX(7)); - lv_style_set_pad_right(&styles->tabview_btns_bg, LV_STATE_DEFAULT, LV_DPX(7)); + lv_style_set_pad_top(&styles->tabview_btns_bg, LV_STATE_DEFAULT, HASP_DPX(7)); + lv_style_set_pad_hor(&styles->tabview_btns_bg, LV_STATE_DEFAULT, HASP_DPX(7)); style_init_reset(&styles->tabview_btns); lv_style_set_bg_opa(&styles->tabview_btns, LV_STATE_PRESSED, LV_OPA_50); lv_style_set_bg_color(&styles->tabview_btns, LV_STATE_PRESSED, lv_color_hex3(0x888)); lv_style_set_text_color(&styles->tabview_btns, LV_STATE_CHECKED, COLOR_SCR_TEXT); - lv_style_set_pad_top(&styles->tabview_btns, LV_STATE_DEFAULT, LV_DPX(20)); - lv_style_set_pad_bottom(&styles->tabview_btns, LV_STATE_DEFAULT, LV_DPX(20)); + lv_style_set_pad_ver(&styles->tabview_btns, LV_STATE_DEFAULT, HASP_DPX(20)); lv_style_set_text_color(&styles->tabview_btns, LV_STATE_FOCUSED, theme.color_primary); lv_style_set_text_color(&styles->tabview_btns, LV_STATE_EDITED, theme.color_secondary); @@ -974,14 +942,11 @@ static void tabview_win_shared_init(void) lv_style_set_bg_opa(&styles->tabview_indic, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->tabview_indic, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_bg_color(&styles->tabview_indic, LV_STATE_EDITED, theme.color_secondary); - lv_style_set_size(&styles->tabview_indic, LV_STATE_DEFAULT, LV_DPX(5)); + lv_style_set_size(&styles->tabview_indic, LV_STATE_DEFAULT, HASP_DPX(5)); lv_style_set_radius(&styles->tabview_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); style_init_reset(&styles->tabview_page_scrl); - lv_style_set_pad_top(&styles->tabview_page_scrl, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_bottom(&styles->tabview_page_scrl, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_left(&styles->tabview_page_scrl, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_right(&styles->tabview_page_scrl, LV_STATE_DEFAULT, PAD_DEF); + lv_style_set_pad_all(&styles->tabview_page_scrl, LV_STATE_DEFAULT, PAD_DEF); lv_style_set_pad_inner(&styles->tabview_page_scrl, LV_STATE_DEFAULT, PAD_DEF); #endif } @@ -1001,9 +966,9 @@ static void tabview_win_shared_init(void) * @param font_title pointer to a extra large font * @return a pointer to reference this theme later */ -lv_theme_t * lv_theme_hasp_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, - const lv_font_t * font_small, const lv_font_t * font_normal, - const lv_font_t * font_subtitle, const lv_font_t * font_title) +lv_theme_t* lv_theme_hasp_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, + const lv_font_t* font_small, const lv_font_t* font_normal, + const lv_font_t* font_subtitle, const lv_font_t* font_title) { /* This trick is required only to avoid the garbage collection of @@ -1011,7 +976,7 @@ lv_theme_t * lv_theme_hasp_init(lv_color_t color_primary, lv_color_t color_secon * In a general case styles could be simple `static lv_style_t my style` variables*/ if(!inited) { LV_GC_ROOT(_lv_theme_material_styles) = lv_mem_alloc(sizeof(theme_styles_t)); - styles = (theme_styles_t *)LV_GC_ROOT(_lv_theme_material_styles); + styles = (theme_styles_t*)LV_GC_ROOT(_lv_theme_material_styles); } theme.color_primary = color_primary; @@ -1065,11 +1030,11 @@ lv_theme_t * lv_theme_hasp_init(lv_color_t color_primary, lv_color_t color_secon return &theme; } -static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) +static void theme_apply(lv_theme_t* th, lv_obj_t* obj, lv_theme_style_t name) { LV_UNUSED(th); - lv_style_list_t * list; + lv_style_list_t* list; switch(name) { case LV_THEME_NONE: @@ -1267,10 +1232,10 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCROLLBAR); _lv_style_list_add_style(list, &styles->sb); - #if LV_USE_ANIMATION +#if LV_USE_ANIMATION list = lv_obj_get_style_list(obj, LV_PAGE_PART_EDGE_FLASH); _lv_style_list_add_style(list, &styles->edge_flash); - #endif +#endif break; #endif #if LV_USE_TABVIEW @@ -1303,10 +1268,10 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_SCROLLBAR); _lv_style_list_add_style(list, &styles->sb); - #if LV_USE_ANIMATION +#if LV_USE_ANIMATION list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_EDGE_FLASH); _lv_style_list_add_style(list, &styles->edge_flash); - #endif +#endif break; #endif @@ -1518,7 +1483,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) * STATIC FUNCTIONS **********************/ -static void style_init_reset(lv_style_t * style) +static void style_init_reset(lv_style_t* style) { if(inited) lv_style_reset(style); From ce91bc72790ef1cd2741bf8eec22f3cb5baa71e8 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 9 Mar 2021 20:28:21 +0100 Subject: [PATCH 169/236] Add https to webUpdate --- src/sys/svc/hasp_ota.cpp | 56 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/sys/svc/hasp_ota.cpp b/src/sys/svc/hasp_ota.cpp index 9e82b11e..fd113e26 100644 --- a/src/sys/svc/hasp_ota.cpp +++ b/src/sys/svc/hasp_ota.cpp @@ -15,14 +15,48 @@ #include #include #include -#else +#include +#endif + +#if defined(ARDUINO_ARCH_ESP32) #include #include #include -#endif - #include +/** + * This is lets-encrypt-x3-cross-signed.pem + */ +const char* rootCACertificate = "-----BEGIN CERTIFICATE-----\n" + "MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" + "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" + "DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" + "SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n" + "GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" + "AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n" + "q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n" + "SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n" + "Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n" + "a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj\n" + "/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T\n" + "AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n" + "CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n" + "bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n" + "c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n" + "VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n" + "ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n" + "MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n" + "Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n" + "AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n" + "uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" + "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" + "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" + "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" + "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" + "-----END CERTIFICATE-----\n"; + +#endif + static WiFiClient otaClient; std::string otaUrl = "http://ota.netwize.be"; int16_t otaPort = HASP_OTA_PORT; @@ -188,13 +222,21 @@ void otaHttpUpdate(const char* espOtaUrl) // ESPhttpUpdate.onProgress(update_progress); // ESPhttpUpdate.onError(update_error); ESP8266HTTPUpdate httpUpdate; -#else - HTTPUpdate httpUpdate; -#endif - httpUpdate.rebootOnUpdate(false); // We do that ourselves t_httpUpdate_return returnCode = httpUpdate.update(otaClient, espOtaUrl); +#else + HTTPUpdate httpUpdate; + WiFiClientSecure secClient; + secClient.setCACert(rootCACertificate); + + // Reading data over SSL may be slow, use an adequate timeout + secClient.setTimeout(12000 / 1000); // timeout argument is defined in seconds for setTimeout + httpUpdate.rebootOnUpdate(false); // We do that ourselves + t_httpUpdate_return returnCode = httpUpdate.update(secClient, espOtaUrl); + +#endif + switch(returnCode) { case HTTP_UPDATE_FAILED: LOG_ERROR(TAG_FWUP, F("HTTP_UPDATE_FAILED error %i %s"), httpUpdate.getLastError(), From 9a3ea4def031be180be5d0ee82505cf7cd84f07e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 9 Mar 2021 20:31:28 +0100 Subject: [PATCH 170/236] File formatting --- .vscode/extensions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index f23ef0dc..9a44568a 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -5,4 +5,4 @@ "ms-vscode.cpptools", "platformio.platformio-ide" ] -} \ No newline at end of file +} From 51981a56db0d72f48d0aebde21a431e34872d7dc Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 20:43:50 +0100 Subject: [PATCH 171/236] Fix monitor_title and monitor_backlight --- src/dev/posix/hasp_posix.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index 96e46630..1e5b086e 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -11,7 +11,7 @@ #include "display/monitor.h" -extern monitor_t monitor; +// extern monitor_t monitor; namespace dev { @@ -44,7 +44,8 @@ const char* PosixDevice::get_hostname() void PosixDevice::set_hostname(const char* hostname) { _hostname = hostname; - SDL_SetWindowTitle(monitor.window, hostname); + monitor_title(hostname); + // SDL_SetWindowTitle(monitor.window, hostname); } const char* PosixDevice::get_core_version() { @@ -91,12 +92,12 @@ bool PosixDevice::get_backlight_power() void PosixDevice::update_backlight() { uint8_t level = _backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0; - - SDL_SetTextureColorMod(monitor.texture, level, level, level); + monitor_backlight(level); + // SDL_SetTextureColorMod(monitor.texture, level, level, level); // window_update(&monitor); - monitor.sdl_refr_qry = true; + // monitor.sdl_refr_qry = true; // monitor_sdl_refr(NULL); - const lv_area_t area = {1,1,0,0}; + // const lv_area_t area = {1,1,0,0}; //monitor_flush(NULL,&area,NULL); } From 5b21c715ff2dcdc589fb1e6f468d87588c28d361 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 22:19:27 +0100 Subject: [PATCH 172/236] Initialize default device info --- src/dev/posix/hasp_posix.cpp | 27 +++++++++++++++++++++++++-- src/dev/posix/hasp_posix.h | 10 ++++------ src/main_sdl2.cpp | 26 ++------------------------ 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index 1e5b086e..1515b315 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -15,11 +15,34 @@ namespace dev { +PosixDevice::PosixDevice() { + struct utsname uts; + + if (uname(&uts) < 0) { + LOG_ERROR(0,"uname() error"); + _hostname = "localhost"; + _core_version = "unknown"; + } else { + // LOG_VERBOSE(0,"Sysname: %s", uts.sysname); + // LOG_VERBOSE(0,"Nodename: %s", uts.nodename); + // LOG_VERBOSE(0,"Release: %s", uts.release); + // LOG_VERBOSE(0,"Version: %s", uts.version); + // LOG_VERBOSE(0,"Machine: %s", uts.machine); + + char version[128]; + snprintf(version, sizeof(version), "%s %s", uts.sysname, uts.release); + _core_version = version; + _hostname = uts.nodename; + } + + _backlight_power = 1; + _backlight_level = 100; + } + void PosixDevice::reboot() {} void PosixDevice::show_info() { - struct utsname uts; if (uname(&uts) < 0) { @@ -49,7 +72,7 @@ void PosixDevice::set_hostname(const char* hostname) } const char* PosixDevice::get_core_version() { - return "posix"; + return _core_version.c_str(); } const char* PosixDevice::get_display_driver() { diff --git a/src/dev/posix/hasp_posix.h b/src/dev/posix/hasp_posix.h index eebcfd7c..687aa8ea 100644 --- a/src/dev/posix/hasp_posix.h +++ b/src/dev/posix/hasp_posix.h @@ -6,11 +6,13 @@ #include #include + extern "C" { #include #include #include +#include } #include "hasp_conf.h" @@ -28,12 +30,7 @@ namespace dev { class PosixDevice : public BaseDevice { public: - PosixDevice() - { - _hostname = "localhost"; - _backlight_power = 1; - _backlight_level = 100; - } + PosixDevice(); void reboot() override; void show_info() override; @@ -58,6 +55,7 @@ class PosixDevice : public BaseDevice { private: std::string _hostname; + std::string _core_version; uint8_t _backlight_pin; uint8_t _backlight_level; diff --git a/src/main_sdl2.cpp b/src/main_sdl2.cpp index 80ef08a9..096906fb 100644 --- a/src/main_sdl2.cpp +++ b/src/main_sdl2.cpp @@ -112,7 +112,8 @@ void setup() lv_log_register_print_cb(debugLvglLogEvent); lv_init(); - haspDevice.init(); // hardware setup + haspDevice.init(); // hardware setup + haspDevice.show_info(); // debug info // hal_setup(); guiSetup(); @@ -204,29 +205,6 @@ int main(int argc, char* argv[]) InitializeConsoleOutput(); #endif - haspDevice.show_info(); - - char hostbuffer[256]; - char* IPbuffer; - struct hostent* host_entry; - int hostname; - - // To retrieve hostname - hostname = gethostname(hostbuffer, sizeof(hostbuffer)); - // checkHostName(hostname); - - // To retrieve host information - host_entry = gethostbyname(hostbuffer); - // checkHostEntry(host_entry); - haspDevice.set_hostname(hostbuffer); - - // To convert an Internet network - // address into ASCII string - // IPbuffer = inet_ntoa(*((struct in_addr*)host_entry->h_addr_list[0])); - - printf("Hostname: %s", hostbuffer); - // printf("Host IP: %s", IPbuffer); - // Display each command-line argument. std::cout << "\nCommand-line arguments:\n"; for(count = 0; count < argc; count++) From aff19396fead207f191e64270db1447659cee741 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 9 Mar 2021 23:12:08 +0100 Subject: [PATCH 173/236] Rename Windows SDL environment --- src/dev/win32/hasp_win32.cpp | 6 ++++-- tools/windows_build_extra.py | 2 ++ ...ator_64bits.ini => windows_sdl_64bits.ini} | 21 ++++++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) rename user_setups/win32/{emulator_64bits.ini => windows_sdl_64bits.ini} (79%) diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index a1992dce..7aa1c93a 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -49,7 +49,8 @@ const char* Win32Device::get_hostname() void Win32Device::set_hostname(const char* hostname) { _hostname = hostname; - SDL_SetWindowTitle(monitor.window, hostname); + monitor_title(hostname); + // SDL_SetWindowTitle(monitor.window, hostname); } const char* Win32Device::get_core_version() { @@ -94,7 +95,8 @@ bool Win32Device::get_backlight_power() void Win32Device::update_backlight() { - monitor_backlight(_backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0); + uint8_t level = _backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0; + monitor_backlight(level); } size_t Win32Device::get_free_max_block() diff --git a/tools/windows_build_extra.py b/tools/windows_build_extra.py index 4f1c18e4..72e4d78f 100644 --- a/tools/windows_build_extra.py +++ b/tools/windows_build_extra.py @@ -1,3 +1,5 @@ +Import("env", "projenv") + env.Append( LINKFLAGS=[ "-static", diff --git a/user_setups/win32/emulator_64bits.ini b/user_setups/win32/windows_sdl_64bits.ini similarity index 79% rename from user_setups/win32/emulator_64bits.ini rename to user_setups/win32/windows_sdl_64bits.ini index d05cbad2..9245c7ca 100644 --- a/user_setups/win32/emulator_64bits.ini +++ b/user_setups/win32/windows_sdl_64bits.ini @@ -1,4 +1,4 @@ -[env:emulator_64bits] +[env:windows_sdl_64bits] platform = native@^1.1.3 extra_scripts = tools/sdl2_build_extra.py @@ -41,8 +41,8 @@ build_flags = -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE ;-D NO_PERSISTENCE - -I.pio/libdeps/emulator_64bits/paho/src - -I.pio/libdeps/emulator_64bits/ArduinoJson/src + -I.pio/libdeps/windows_sdl_64bits/paho/src + -I.pio/libdeps/windows_sdl_64bits/ArduinoJson/src -I lib/ArduinoJson/src -I lib/lv_fs_if !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/sdl2')]))" @@ -77,6 +77,7 @@ lib_deps = ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/7d71907c1d6b02797d066f50984b866e080ebeed.zip https://github.com/eclipse/paho.mqtt.c.git bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser + https://github.com/fvanroie/lv_drivers lib_ignore = paho @@ -87,12 +88,12 @@ src_filter = +<*> -<*.h> +<../hal/sdl2> - +<../.pio/libdeps/emulator_64bits/paho/src/*.c> - +<../.pio/libdeps/emulator_64bits/paho/src/MQTTClient.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTAsync.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTAsyncUtils.c> - -<../.pio/libdeps/emulator_64bits/paho/src/MQTTVersion.c> - -<../.pio/libdeps/emulator_64bits/paho/src/SSLSocket.c> + +<../.pio/libdeps/windows_sdl_64bits/paho/src/*.c> + +<../.pio/libdeps/windows_sdl_64bits/paho/src/MQTTClient.c> + -<../.pio/libdeps/windows_sdl_64bits/paho/src/MQTTAsync.c> + -<../.pio/libdeps/windows_sdl_64bits/paho/src/MQTTAsyncUtils.c> + -<../.pio/libdeps/windows_sdl_64bits/paho/src/MQTTVersion.c> + -<../.pio/libdeps/windows_sdl_64bits/paho/src/SSLSocket.c> + - - @@ -112,4 +113,4 @@ src_filter = + - + - +<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h> + +<../.pio/libdeps/windows_sdl_64bits/ArduinoJson/src/ArduinoJson.h> From 787b91910d384569281df193e4104f1c3f2aabbc Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 10 Mar 2021 01:08:39 +0100 Subject: [PATCH 174/236] Add chip_model --- src/dev/device.h | 2 +- src/dev/esp32/esp32.cpp | 29 +++++++++++++++-- src/dev/esp32/esp32.h | 2 +- src/dev/esp8266/esp8266.cpp | 4 +-- src/dev/esp8266/esp8266.h | 2 +- src/dev/posix/hasp_posix.cpp | 63 ++++++++++++++++++------------------ src/dev/posix/hasp_posix.h | 10 +++--- src/dev/stm32f4/stm32f4.cpp | 22 ++++++++++--- src/dev/stm32f4/stm32f4.h | 2 +- src/dev/win32/hasp_win32.cpp | 2 +- src/dev/win32/hasp_win32.h | 2 +- src/sys/svc/hasp_http.cpp | 4 +-- 12 files changed, 90 insertions(+), 54 deletions(-) diff --git a/src/dev/device.h b/src/dev/device.h index 3e49d271..4f6ae713 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -37,7 +37,7 @@ class BaseDevice { { return ""; } - virtual const char* get_display_driver() + virtual const char* get_chip_model() { return ""; } diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index ede2dbdb..837a6bad 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -43,11 +43,34 @@ void Esp32Device::set_hostname(const char* hostname) } const char* Esp32Device::get_core_version() { - return ESP.getSdkVersion(); + return esp_get_idf_version(); // == ESP.getSdkVersion(); } -const char* Esp32Device::get_display_driver() +const char* Esp32Device::get_chip_model() { - return Utilities::tft_driver_name().c_str(); + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); + + // model = chip_info.cores; + // model += F("core "); + switch(chip_info.model) { + case CHIP_ESP32: + return "ESP32"; + +#ifdef CHIP_ESP32S2 + case CHIP_ESP32S2: + return "ESP32-S2"; +#endif + +#ifdef CHIP_ESP32S3 + case CHIP_ESP32S3: + return "ESP32-S3"; +#endif + + default: + return "Unknown ESP32"; + } + // model += F(" rev"); + // model += chip_info.revision; } void Esp32Device::set_backlight_pin(uint8_t pin) diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 90f7485a..7c2b6797 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -30,7 +30,7 @@ class Esp32Device : public BaseDevice { const char* get_hostname(); void set_hostname(const char*); const char* get_core_version(); - const char* get_display_driver(); + const char* get_chip_model(); void set_backlight_pin(uint8_t pin) override; void set_backlight_level(uint8_t val) override; diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index bcd9a850..7435133e 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -42,9 +42,9 @@ const char* Esp8266Device::get_core_version() return ESP.getCoreVersion().c_str(); } -const char* Esp8266Device::get_display_driver() +const char* Esp8266Device::get_chip_model() { - return Utilities::tft_driver_name().c_str(); + return "ESP8266"; } void Esp8266Device::set_backlight_pin(uint8_t pin) diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 458add99..460cb264 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -32,7 +32,7 @@ class Esp8266Device : public BaseDevice { const char* get_hostname(); void set_hostname(const char*); const char* get_core_version(); - const char* get_display_driver(); + const char* get_chip_model(); void set_backlight_pin(uint8_t pin) override; void set_backlight_level(uint8_t val) override; diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index 1515b315..8884861a 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -15,51 +15,53 @@ namespace dev { -PosixDevice::PosixDevice() { - struct utsname uts; +PosixDevice::PosixDevice() +{ + struct utsname uts; - if (uname(&uts) < 0) { - LOG_ERROR(0,"uname() error"); - _hostname = "localhost"; - _core_version = "unknown"; - } else { + if(uname(&uts) < 0) { + LOG_ERROR(0, "uname() error"); + _hostname = "localhost"; + _core_version = "unknown"; + _chip_model = "unknown"; + } else { // LOG_VERBOSE(0,"Sysname: %s", uts.sysname); // LOG_VERBOSE(0,"Nodename: %s", uts.nodename); // LOG_VERBOSE(0,"Release: %s", uts.release); // LOG_VERBOSE(0,"Version: %s", uts.version); // LOG_VERBOSE(0,"Machine: %s", uts.machine); - char version[128]; - snprintf(version, sizeof(version), "%s %s", uts.sysname, uts.release); - _core_version = version; - _hostname = uts.nodename; - } - - _backlight_power = 1; - _backlight_level = 100; + char version[128]; + snprintf(version, sizeof(version), "%s %s", uts.sysname, uts.release); + _core_version = version; + _chip_model = uts.machine; + _hostname = uts.nodename; } + _backlight_power = 1; + _backlight_level = 100; +} + void PosixDevice::reboot() {} void PosixDevice::show_info() { - struct utsname uts; + struct utsname uts; - if (uname(&uts) < 0) { - LOG_ERROR(0,"uname() error"); - } else { - LOG_VERBOSE(0,"Sysname: %s", uts.sysname); - LOG_VERBOSE(0,"Nodename: %s", uts.nodename); - LOG_VERBOSE(0,"Release: %s", uts.release); - LOG_VERBOSE(0,"Version: %s", uts.version); - LOG_VERBOSE(0,"Machine: %s", uts.machine); - } + if(uname(&uts) < 0) { + LOG_ERROR(0, "uname() error"); + } else { + LOG_VERBOSE(0, "Sysname: %s", uts.sysname); + LOG_VERBOSE(0, "Nodename: %s", uts.nodename); + LOG_VERBOSE(0, "Release: %s", uts.release); + LOG_VERBOSE(0, "Version: %s", uts.version); + LOG_VERBOSE(0, "Machine: %s", uts.machine); + } LOG_VERBOSE(0, "Processor : %s", "unknown"); LOG_VERBOSE(0, "CPU freq. : %i MHz", 0); } - const char* PosixDevice::get_hostname() { return _hostname.c_str(); @@ -74,9 +76,9 @@ const char* PosixDevice::get_core_version() { return _core_version.c_str(); } -const char* PosixDevice::get_display_driver() +const char* PosixDevice::get_chip_model() { - return "SDL2"; + return _chip_model.c_str(); } void PosixDevice::set_backlight_pin(uint8_t pin) @@ -89,8 +91,7 @@ void PosixDevice::set_backlight_level(uint8_t level) uint8_t new_level = level >= 0 ? level : 0; new_level = new_level <= 100 ? new_level : 100; - if(_backlight_level != new_level) - { + if(_backlight_level != new_level) { _backlight_level = new_level; update_backlight(); } @@ -121,7 +122,7 @@ void PosixDevice::update_backlight() // monitor.sdl_refr_qry = true; // monitor_sdl_refr(NULL); // const lv_area_t area = {1,1,0,0}; - //monitor_flush(NULL,&area,NULL); + // monitor_flush(NULL,&area,NULL); } size_t PosixDevice::get_free_max_block() diff --git a/src/dev/posix/hasp_posix.h b/src/dev/posix/hasp_posix.h index 687aa8ea..962bd45d 100644 --- a/src/dev/posix/hasp_posix.h +++ b/src/dev/posix/hasp_posix.h @@ -7,8 +7,7 @@ #include #include -extern "C" -{ +extern "C" { #include #include #include @@ -19,9 +18,9 @@ extern "C" #include "../device.h" #if defined(POSIX) -static inline void itoa(int i, char *out, int unused_) +static inline void itoa(int i, char* out, int unused_) { - (void) unused_; + (void)unused_; sprintf(out, "%d", i); } @@ -38,7 +37,7 @@ class PosixDevice : public BaseDevice { const char* get_hostname(); void set_hostname(const char*); const char* get_core_version(); - const char* get_display_driver(); + const char* get_chip_model(); void set_backlight_pin(uint8_t pin); void set_backlight_level(uint8_t val); @@ -56,6 +55,7 @@ class PosixDevice : public BaseDevice { private: std::string _hostname; std::string _core_version; + std::string _chip_model; uint8_t _backlight_pin; uint8_t _backlight_level; diff --git a/src/dev/stm32f4/stm32f4.cpp b/src/dev/stm32f4/stm32f4.cpp index 78e84484..41df3ad3 100644 --- a/src/dev/stm32f4/stm32f4.cpp +++ b/src/dev/stm32f4/stm32f4.cpp @@ -41,11 +41,6 @@ const char* Stm32f4Device::get_core_version() // return ESP.getCoreVersion().c_str(); } -const char* Stm32f4Device::get_display_driver() -{ - return Utilities::tft_driver_name().c_str(); -} - void Stm32f4Device::set_backlight_pin(uint8_t pin) { _backlight_pin = pin; @@ -57,6 +52,23 @@ void Stm32f4Device::set_backlight_pin(uint8_t pin) } } +const char* Stm32f4Device::get_chip_model() +{ +#if defined(STM32F407ZG) + return "STM32F407ZG"; +#elif defined(STM32F407ZE) + return "STM32F407ZE"; +#elif defined(STM32F407VE) + return "STM32F407VE"; +#elif defined(STM32F407VG) + return "STM32F407VG"; +#elif defined(STM32F4xx) || defined(ARDUINO_ARCH_STM32F4) + return "STM32F4"; +#else + return "Unknown STM32"; +#endif +} + void Stm32f4Device::set_backlight_level(uint8_t level) { _backlight_level = level >= 0 ? level : 0; diff --git a/src/dev/stm32f4/stm32f4.h b/src/dev/stm32f4/stm32f4.h index fcd76eba..30513dc0 100644 --- a/src/dev/stm32f4/stm32f4.h +++ b/src/dev/stm32f4/stm32f4.h @@ -32,7 +32,7 @@ class Stm32f4Device : public BaseDevice { const char* get_hostname(); void set_hostname(const char*); const char* get_core_version(); - const char* get_display_driver(); + const char* get_chip_model(); void set_backlight_pin(uint8_t pin) override; void set_backlight_level(uint8_t val) override; diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 7aa1c93a..56e25f1a 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -56,7 +56,7 @@ const char* Win32Device::get_core_version() { return _core_version.c_str(); } -const char* Win32Device::get_display_driver() +const char* Win32Device::get_chip_model() { return "SDL2"; } diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index f833b60f..7aaa9ae3 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -57,7 +57,7 @@ class Win32Device : public BaseDevice { const char* get_hostname(); void set_hostname(const char*); const char* get_core_version(); - const char* get_display_driver(); + const char* get_chip_model(); void set_backlight_pin(uint8_t pin); void set_backlight_level(uint8_t val); diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 071eee2f..fff180e3 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -646,7 +646,7 @@ void webHandleInfo() /* ESP Stats */ httpMessage += F("

MCU Model: "); - httpMessage += halGetChipModel(); + httpMessage += haspDevice.get_chip_model(); httpMessage += F("
CPU Frequency: "); httpMessage += String(haspDevice.get_cpu_frequency()); httpMessage += F("MHz"); @@ -670,7 +670,7 @@ void webHandleInfo() // httpMessage += String(ESP.getSdkVersion()); //#else httpMessage += F("
Core version: "); - httpMessage += halGetCoreVersion(); + httpMessage += haspDevice.get_core_version(); //#endif httpMessage += F("
Last Reset: "); httpMessage += halGetResetInfo(); From 5e3d49ff84e41c1737cb57353cec267bf49d3fdb Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 10 Mar 2021 01:09:52 +0100 Subject: [PATCH 175/236] Obsolete CoreVersion, ChipModel, DisplayDriverName --- src/hal/hasp_hal.cpp | 20 ++++++++++---------- src/hal/hasp_hal.h | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/hal/hasp_hal.cpp b/src/hal/hasp_hal.cpp index 316f6ddf..0b2bc579 100644 --- a/src/hal/hasp_hal.cpp +++ b/src/hal/hasp_hal.cpp @@ -116,16 +116,16 @@ String halGetResetInfo() #endif } -String halGetCoreVersion() -{ -#if defined(ARDUINO_ARCH_ESP32) - return String(ESP.getSdkVersion()); -#elif defined(ARDUINO_ARCH_ESP8266) - return String(ESP.getCoreVersion()); -#else - return String(STM32_CORE_VERSION_MAJOR) + "." + STM32_CORE_VERSION_MINOR + "." + STM32_CORE_VERSION_PATCH; -#endif -} +// String halGetCoreVersion() +// { +// #if defined(ARDUINO_ARCH_ESP32) +// return String(ESP.getSdkVersion()); +// #elif defined(ARDUINO_ARCH_ESP8266) +// return String(ESP.getCoreVersion()); +// #else +// return String(STM32_CORE_VERSION_MAJOR) + "." + STM32_CORE_VERSION_MINOR + "." + STM32_CORE_VERSION_PATCH; +// #endif +// } String halGetChipModel() { diff --git a/src/hal/hasp_hal.h b/src/hal/hasp_hal.h index 3a8d5860..61cfa2a5 100644 --- a/src/hal/hasp_hal.h +++ b/src/hal/hasp_hal.h @@ -11,11 +11,11 @@ String halGetResetInfo(void); // uint8_t halGetHeapFragmentation(void); // size_t halGetMaxFreeBlock(void); // size_t halGetFreeHeap(void); -String halGetCoreVersion(void); -String halGetChipModel(); +// String halGetCoreVersion(void); +// String halGetChipModel(); String halGetMacAddress(int start, const char* seperator); // uint16_t halGetCpuFreqMHz(void); -String halDisplayDriverName(void); +// String halDisplayDriverName(void); String halGpioName(uint8_t gpio); #endif \ No newline at end of file From e80fb7960aef97297e5d510dcd223450cb8824a6 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 10 Mar 2021 01:10:16 +0100 Subject: [PATCH 176/236] Resize ESP32 partition --- platformio.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index e2dfa89a..865de0e2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -93,7 +93,7 @@ extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py [esp32] framework = arduino platform = espressif32 -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv +board_build.partitions = user_setups/esp32_partition_app1536k_spiffs1024k.csv ; ----- crash reporter monitor_filters = esp32_exception_decoder @@ -148,7 +148,6 @@ extra_scripts = tools/copy_partitions.py tools/analyze_elf.py - ; -- The ESP32 has 2 SPI Hardware Busses available to use: vspi = -D TFT_MISO=19 From a6b062ee197f0052c2860295d02b6f469003d180 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 10 Mar 2021 01:46:57 +0100 Subject: [PATCH 177/236] Add get_tft_model --- src/drv/tft_driver.h | 4 ++++ src/drv/tft_driver_sdl2.h | 4 ++++ src/drv/tft_driver_tftespi.cpp | 38 +++++++++++++++++++++++++++++++++- src/drv/tft_driver_tftespi.h | 2 ++ src/hasp/hasp_dispatch.cpp | 3 ++- src/hasp/hasp_utilities.cpp | 35 ------------------------------- src/hasp/hasp_utilities.h | 1 - 7 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/drv/tft_driver.h b/src/drv/tft_driver.h index 0488a2f3..07d79b7a 100644 --- a/src/drv/tft_driver.h +++ b/src/drv/tft_driver.h @@ -27,6 +27,10 @@ class BaseTft { { return false; } + virtual const char* get_tft_model() + { + return ""; + } }; } // namespace dev diff --git a/src/drv/tft_driver_sdl2.h b/src/drv/tft_driver_sdl2.h index 2b443fad..fdab19bb 100644 --- a/src/drv/tft_driver_sdl2.h +++ b/src/drv/tft_driver_sdl2.h @@ -87,6 +87,10 @@ class TftSdl2 : BaseTft { { return false; } + const char* get_tft_model() + { + return "SDL2"; + } }; } // namespace dev diff --git a/src/drv/tft_driver_tftespi.cpp b/src/drv/tft_driver_tftespi.cpp index e015b567..c0dfcdd1 100644 --- a/src/drv/tft_driver_tftespi.cpp +++ b/src/drv/tft_driver_tftespi.cpp @@ -28,7 +28,7 @@ void TftEspi::show_info() if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch { - LOG_VERBOSE(TAG_TFT, F("Driver : %s"), halDisplayDriverName().c_str()); // tftSetup.tft_driver); + LOG_VERBOSE(TAG_TFT, F("Driver : %s"), haspTft.get_tft_model()); // tftSetup.tft_driver); LOG_VERBOSE(TAG_TFT, F("Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height); } else if(tftSetup.tft_driver == 0xE9D) LOG_VERBOSE(TAG_TFT, F("Driver = ePaper")); @@ -228,6 +228,42 @@ bool TftEspi::is_driver_pin(uint8_t pin) return false; } + +const char* TftEspi::get_tft_model() +{ +#if defined(ILI9341_DRIVER) + return "ILI9341"; +#elif defined(ST7735_DRIVER) + return "ST7735"; +#elif defined(ILI9163_DRIVER) + return "ILI9163"; +#elif defined(S6D02A1_DRIVER) + return "S6D02A1"; +#elif defined(ST7796_DRIVER) + return "ST7796"; +#elif defined(ILI9486_DRIVER) + return "ILI9486"; +#elif defined(ILI9481_DRIVER) + return "ILI9481"; +#elif defined(ILI9488_DRIVER) + return "ILI9488"; +#elif defined(HX8357D_DRIVER) + return "HX8357D"; +#elif defined(EPD_DRIVER) + return "EPD"; +#elif defined(ST7789_DRIVER) + return "ST7789"; +#elif defined(R61581_DRIVER) + return "R61581"; +#elif defined(ST7789_2_DRIVER) + return "ST7789_2"; +#elif defined(RM68140_DRIVER) + return "RM68140"; +#else + return "Other"; +#endif +} + } // namespace dev dev::TftEspi haspTft; diff --git a/src/drv/tft_driver_tftespi.h b/src/drv/tft_driver_tftespi.h index 40da4274..7bc88004 100644 --- a/src/drv/tft_driver_tftespi.h +++ b/src/drv/tft_driver_tftespi.h @@ -35,6 +35,8 @@ class TftEspi : BaseTft { void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); bool is_driver_pin(uint8_t pin); + const char* get_tft_model(); + private: void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset) { diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index ce337b65..3f6a7da7 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -7,6 +7,7 @@ #include "hasplib.h" #include "dev/device.h" +#include "drv/tft_driver.h" //#include "hasp_gui.h" @@ -1050,7 +1051,7 @@ void dispatch_output_statusupdate(const char*, const char*) #endif snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), - Utilities::tft_driver_name().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); + haspTft.get_tft_model(), (TFT_WIDTH), (TFT_HEIGHT)); strcat(data, buffer); } diff --git a/src/hasp/hasp_utilities.cpp b/src/hasp/hasp_utilities.cpp index 5ae92422..1787c2a2 100644 --- a/src/hasp/hasp_utilities.cpp +++ b/src/hasp/hasp_utilities.cpp @@ -54,41 +54,6 @@ int Utilities::format_bytes(size_t filesize, char* buf, size_t len) return snprintf_P(buf, len, PSTR("%d.%d %ciB"), filesize / 10, filesize % 10, labels[unit]); } -std::string Utilities::tft_driver_name() -{ -#if defined(ILI9341_DRIVER) - return "ILI9341"; -#elif defined(ST7735_DRIVER) - return "ST7735"; -#elif defined(ILI9163_DRIVER) - return "ILI9163"; -#elif defined(S6D02A1_DRIVER) - return "S6D02A1"; -#elif defined(ST7796_DRIVER) - return "ST7796"; -#elif defined(ILI9486_DRIVER) - return "ILI9486"; -#elif defined(ILI9481_DRIVER) - return "ILI9481"; -#elif defined(ILI9488_DRIVER) - return "ILI9488"; -#elif defined(HX8357D_DRIVER) - return "HX8357D"; -#elif defined(EPD_DRIVER) - return "EPD"; -#elif defined(ST7789_DRIVER) - return "ST7789"; -#elif defined(R61581_DRIVER) - return "R61581"; -#elif defined(ST7789_2_DRIVER) - return "ST7789_2"; -#elif defined(RM68140_DRIVER) - return "RM68140"; -#else - return "Other"; -#endif -} - #ifndef ARDUINO long map(long x, long in_min, long in_max, long out_min, long out_max) { diff --git a/src/hasp/hasp_utilities.h b/src/hasp/hasp_utilities.h index d8793f93..a94a6f80 100644 --- a/src/hasp/hasp_utilities.h +++ b/src/hasp/hasp_utilities.h @@ -13,7 +13,6 @@ class Utilities { static bool is_true(const char* s); static bool is_only_digits(const char* s); static int format_bytes(size_t filesize, char* buf, size_t len); - static std::string tft_driver_name(); }; #ifndef ARDUINO From fff06f5b30cca942e634239b943adfd2f548dc14 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 10 Mar 2021 04:33:38 +0100 Subject: [PATCH 178/236] Move STMPE610 to Feather environments --- platformio.ini | 5 ++--- user_setups/esp32/huzzah32-featherwing-24.ini | 1 + user_setups/esp32/huzzah32-featherwing-35.ini | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 865de0e2..7237de15 100644 --- a/platformio.ini +++ b/platformio.ini @@ -39,8 +39,8 @@ monitor_speed = 115200 build_flags = -D PIOENV=\"${PIOENV}\" - ;-Os ; Code Size Optimization - -Og ; Code Debug Optimization + -Os ; Code Size Optimization + ;-Og ; Code Debug Optimization ;-w ; Suppress warnings -D CORE_DEBUG_LEVEL=0 ; 0=Silent, 1=Errors, 2=Warnings -I include ; include lv_conf.h and hasp_conf.h @@ -83,7 +83,6 @@ lib_deps = ;AsyncTCP ;https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip ;https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip - adafruit/Adafruit STMPE610@^1.1.3 ;STMPE610 touch controller src_filter = +<*> -<.git/> - - - - - diff --git a/user_setups/esp32/huzzah32-featherwing-24.ini b/user_setups/esp32/huzzah32-featherwing-24.ini index 79b57552..2c1d23fc 100644 --- a/user_setups/esp32/huzzah32-featherwing-24.ini +++ b/user_setups/esp32/huzzah32-featherwing-24.ini @@ -27,6 +27,7 @@ build_flags = lib_deps = ${env.lib_deps} ${esp32.lib_deps} + adafruit/Adafruit STMPE610@^1.1.3 ;STMPE610 touch controller lib_ignore = ${env.lib_ignore} diff --git a/user_setups/esp32/huzzah32-featherwing-35.ini b/user_setups/esp32/huzzah32-featherwing-35.ini index db9e512f..0555d4b4 100644 --- a/user_setups/esp32/huzzah32-featherwing-35.ini +++ b/user_setups/esp32/huzzah32-featherwing-35.ini @@ -27,6 +27,7 @@ build_flags = lib_deps = ${env.lib_deps} ${esp32.lib_deps} + adafruit/Adafruit STMPE610@^1.1.3 ;STMPE610 touch controller lib_ignore = ${env.lib_ignore} From dbb160ac94b2d1bba672c34469cd52718dbcdf6d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 10 Mar 2021 14:53:52 +0100 Subject: [PATCH 179/236] Fix merge issue --- src/sys/svc/hasp_telnet.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/sys/svc/hasp_telnet.cpp b/src/sys/svc/hasp_telnet.cpp index e8c823a6..52de8836 100644 --- a/src/sys/svc/hasp_telnet.cpp +++ b/src/sys/svc/hasp_telnet.cpp @@ -84,16 +84,11 @@ void telnetAcceptClient() // telnetClient.print((char)0xFD); // telnetClient.print((char)0x1B); -<<<<<<< HEAD:src/sys/svc/hasp_telnet.cpp -#if HASP_USE_HTTP > 0 == == == = #if HASP_USE_HTTP > 0 ->>>>>>> master:src/svc/hasp_telnet.cpp - if(strlen(http_config.user) != 0 || strlen(http_config.password) != 0) - { + if(strlen(http_config.user) != 0 || strlen(http_config.password) != 0) { telnetClient.println(F("\r\n" D_USERNAME " ")); telnetLoginState = TELNET_UNAUTHENTICATED; - } - else + } else #endif { telnetClientLogon(); From 93f09dc7df1d8dec8f86a60ee9de59df656e3b19 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Wed, 10 Mar 2021 16:19:46 +0100 Subject: [PATCH 180/236] Update touch drivers --- .vscode/extensions.json | 16 +++--- src/drv/hasp_drv_display.cpp | 31 ------------ src/drv/hasp_drv_display.h | 19 ------- src/drv/tft_driver.h | 11 ++-- src/drv/tft_driver_sdl2.cpp | 96 +++++++++++++++++++++++++++++++++++ src/drv/tft_driver_sdl2.h | 97 ++++++------------------------------ src/drv/tft_driver_tftespi.h | 5 +- src/hasp_gui.cpp | 5 +- 8 files changed, 129 insertions(+), 151 deletions(-) delete mode 100644 src/drv/hasp_drv_display.cpp delete mode 100644 src/drv/hasp_drv_display.h create mode 100644 src/drv/tft_driver_sdl2.cpp diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 9a44568a..d304a5ef 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,8 +1,8 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "ms-vscode.cpptools", - "platformio.platformio-ide" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "ms-vscode.cpptools", + "platformio.platformio-ide" + ] +} diff --git a/src/drv/hasp_drv_display.cpp b/src/drv/hasp_drv_display.cpp deleted file mode 100644 index 5cf555da..00000000 --- a/src/drv/hasp_drv_display.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* MIT License - Copyright (c) 2019-2021 Francis Van Roie - For full license information read the LICENSE file in the project folder */ - -// #include "hasp_drv_display.h" -// #include "tft_espi_drv.h" -// //#include "fsmc_ili9341.h" - -// void drv_display_init(lv_disp_drv_t* disp_drv, uint8_t rotation, bool invert_display) -// { -// /* TFT init */ -// #if defined(USE_FSMC) -// fsmc_ili9341_init(rotation, invert_display); -// disp_drv->flush_cb = fsmc_ili9341_flush; // Normal callback when flushing -// // xpt2046_init(rotation); -// #else -// tft_espi_init(rotation, invert_display); -// disp_drv->flush_cb = tft_espi_flush; // Normal callback when flushing -// #endif -// } - -// /* Callback used for screenshots only: */ - -// /* indirect callback to flush screenshot data to the screen */ -// void drv_display_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) -// { -// #if defined(USE_FSMC) -// fsmc_ili9341_flush(disp, area, color_p); -// #else -// tft_espi_flush(disp, area, color_p); -// #endif -// } \ No newline at end of file diff --git a/src/drv/hasp_drv_display.h b/src/drv/hasp_drv_display.h deleted file mode 100644 index 1a9b0a37..00000000 --- a/src/drv/hasp_drv_display.h +++ /dev/null @@ -1,19 +0,0 @@ -/* MIT License - Copyright (c) 2019-2021 Francis Van Roie - For full license information read the LICENSE file in the project folder */ - -#if 0 // ndef HASP_DRV_DISPLAY_H -#define HASP_DRV_DISPLAY_H - -#include "lvgl.h" - -// Select Display Driver -#if defined(USE_FSMC) -#include "fsmc_ili9341.h" -#else -#include "tft_espi_drv.h" -#endif - -void drv_display_init(lv_disp_drv_t* disp_drv, uint8_t rotation, bool invert_display); -void drv_display_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); - -#endif \ No newline at end of file diff --git a/src/drv/tft_driver.h b/src/drv/tft_driver.h index 07d79b7a..52a25f5d 100644 --- a/src/drv/tft_driver.h +++ b/src/drv/tft_driver.h @@ -7,6 +7,7 @@ #ifdef ARDUINO #include "Arduino.h" #endif + #include "lvgl.h" namespace dev { @@ -36,19 +37,19 @@ class BaseTft { } // namespace dev #if defined(ESP32) -#warning Building for ESP32 Devices +#warning Building for ESP32 Tfts #include "tft_driver_tftespi.h" #elif defined(ESP8266) -#warning Building for ESP8266 Devices +#warning Building for ESP8266 Tfts #include "tft_driver_tftespi.h" #elif defined(STM32F4) -#warning Building for STM32F4xx Devices +#warning Building for STM32F4xx Tfts #include "tft_driver_tftespi.h" #elif defined(WINDOWS) || defined(POSIX) -#warning Building for Win32 Devices +#warning Building for SDL2 #include "tft_driver_sdl2.h" #else -#warning Building for Generic Devices +#warning Building for Generic Tfts using dev::BaseTft; extern dev::BaseTft haspTft; #endif diff --git a/src/drv/tft_driver_sdl2.cpp b/src/drv/tft_driver_sdl2.cpp new file mode 100644 index 00000000..b0079ec2 --- /dev/null +++ b/src/drv/tft_driver_sdl2.cpp @@ -0,0 +1,96 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#if defined(WINDOWS) || defined(POSIX) + +#include "lvgl.h" +#include + +#include "display/monitor.h" +#include "indev/mouse.h" + +#include "tft_driver_sdl2.h" + +#include "dev/device.h" +#include "hasp_debug.h" + +//#include "bootscreen.h" // Sketch tab header for xbm images + +namespace dev { + +/** + * A task to measure the elapsed time for LittlevGL + * @param data unused + * @return never return + */ +static int tick_thread(void* data) +{ + (void)data; + + while(1) { + SDL_Delay(5); /*Sleep for 5 millisecond*/ + lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/ + } + + return 0; +} + + void TftSdl2::init(int w, int h) + { + +// Workaround for sdl2 `-m32` crash +// https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7 +#ifndef WIN32 + setenv("DBUS_FATAL_WARNINGS", "0", 1); +#endif + + /* Add a display + * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ + monitor_init(); + monitor_title(haspDevice.get_hostname()); + + /* Add the mouse as input device + * Use the 'mouse' driver which reads the PC's mouse*/ + mouse_init(); + + /* Tick init. + * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed + * Create an SDL thread to do this*/ + SDL_CreateThread(tick_thread, "tick", NULL); + } + void TftSdl2::show_info() + { + SDL_version linked; + SDL_GetVersion(&linked); + LOG_VERBOSE(TAG_TFT, F("SDL2 : v%d.%d.%d"), linked.major, linked.minor, linked.patch); + LOG_VERBOSE(TAG_TFT, F("Driver : SDL2")); + } + + void TftSdl2::splashscreen() + { + // tft.fillScreen(TFT_DARKCYAN); + // int x = (tft.width() - logoWidth) / 2; + // int y = (tft.height() - logoHeight) / 2; + // tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE); + } + void TftSdl2::set_rotation(uint8_t rotation) + {} + void set_invert(bool invert) + {} + static void TftSdl2::flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) + { + monitor_flush(disp, area, color_p); + } + bool TftSdl2:is_driver_pin(uint8_t pin) + { + return false; + } + const char* TftSdl2::get_tft_model() + { + return "SDL2"; + } + +} // namespace dev + +dev::TftSdl2 haspTft; +#endif \ No newline at end of file diff --git a/src/drv/tft_driver_sdl2.h b/src/drv/tft_driver_sdl2.h index fdab19bb..47cfe712 100644 --- a/src/drv/tft_driver_sdl2.h +++ b/src/drv/tft_driver_sdl2.h @@ -1,96 +1,27 @@ -/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ #ifndef HASP_SDL2_DRIVER_H #define HASP_SDL2_DRIVER_H +#if defined(WINDOWS) || defined(POSIX) + #include "lvgl.h" -#include - -#include "display/monitor.h" -#include "indev/mouse.h" - #include "tft_driver.h" -#include "dev/device.h" -#include "hasp_debug.h" - -//#include "bootscreen.h" // Sketch tab header for xbm images +#include "indev/mouse.h" namespace dev { -/** - * A task to measure the elapsed time for LittlevGL - * @param data unused - * @return never return - */ -static int tick_thread(void* data) -{ - (void)data; - - while(1) { - SDL_Delay(5); /*Sleep for 5 millisecond*/ - lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/ - } - - return 0; -} - class TftSdl2 : BaseTft { public: - void init(int w, int h) - { - -// Workaround for sdl2 `-m32` crash -// https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7 -#ifndef WIN32 - setenv("DBUS_FATAL_WARNINGS", "0", 1); -#endif - - /* Add a display - * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ - monitor_init(); - monitor_title(haspDevice.get_hostname()); - - /* Add the mouse as input device - * Use the 'mouse' driver which reads the PC's mouse*/ - mouse_init(); - - /* Tick init. - * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed - * Create an SDL thread to do this*/ - SDL_CreateThread(tick_thread, "tick", NULL); - } - void show_info() - { - SDL_version linked; - SDL_GetVersion(&linked); - LOG_VERBOSE(TAG_TFT, F("SDL2 : v%d.%d.%d"), linked.major, linked.minor, linked.patch); - LOG_VERBOSE(TAG_TFT, F("Driver : SDL2")); - } - - void splashscreen() - { - // tft.fillScreen(TFT_DARKCYAN); - // int x = (tft.width() - logoWidth) / 2; - // int y = (tft.height() - logoHeight) / 2; - // tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE); - } - void set_rotation(uint8_t rotation) - {} - void set_invert(bool invert) - {} - static void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) - { - monitor_flush(disp, area, color_p); - } - bool is_driver_pin(uint8_t pin) - { - return false; - } - const char* get_tft_model() - { - return "SDL2"; - } + void init(int w, int h); + void show_info(); + void splashscreen(); + void set_rotation(uint8_t rotation); + void set_invert(bool invert); + static void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); + bool is_driver_pin(uint8_t pin); + const char* get_tft_model(); }; } // namespace dev @@ -98,4 +29,6 @@ class TftSdl2 : BaseTft { using dev::TftSdl2; extern dev::TftSdl2 haspTft; -#endif +#endif // defined(WINDOWS) || defined(POSIX) + +#endif // HASP_SDL2_DRIVER_H diff --git a/src/drv/tft_driver_tftespi.h b/src/drv/tft_driver_tftespi.h index 7bc88004..05e21792 100644 --- a/src/drv/tft_driver_tftespi.h +++ b/src/drv/tft_driver_tftespi.h @@ -6,7 +6,6 @@ #ifdef ARDUINO #include "Arduino.h" -#endif #include "lvgl.h" #include "TFT_eSPI.h" @@ -64,4 +63,6 @@ class TftEspi : BaseTft { using dev::TftEspi; extern dev::TftEspi haspTft; -#endif \ No newline at end of file +#endif // ARDUINO + +#endif // HASP_TFTESPI_DRIVER_H \ No newline at end of file diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index a714124c..ad9e7ba2 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -26,10 +26,7 @@ #include "hasplib.h" -#if defined(WINDOWS) || defined(POSIX) -#include "display/monitor.h" -#include "indev/mouse.h" -#endif + //#include "tpcal.h" From a06942e44676ef4b39355d73645201f30a81f78b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 10 Mar 2021 20:03:39 +0100 Subject: [PATCH 181/236] Update driver includes --- src/dev/device.cpp | 10 --- src/drv/tft_driver_sdl2.cpp | 98 +++++++++++----------- src/drv/tft_driver_sdl2.h | 20 +++-- src/drv/tft_espi_drv.cpp | 4 +- src/hasp_gui.cpp | 2 - tools/windows_build_extra.py | 2 +- user_setups/linux_sdl/linux_sdl_64bits.ini | 2 +- user_setups/win32/windows_sdl_64bits.ini | 2 +- 8 files changed, 68 insertions(+), 72 deletions(-) diff --git a/src/dev/device.cpp b/src/dev/device.cpp index dd5b7531..395a6e43 100644 --- a/src/dev/device.cpp +++ b/src/dev/device.cpp @@ -1,12 +1,2 @@ /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ - -#include "device.h" - -#if defined(LANBONL8) -#warning Lanbon L8 -#elif defined(M5STACK) -#warning M5 Stack -#else -#warning Generic Device -#endif \ No newline at end of file diff --git a/src/drv/tft_driver_sdl2.cpp b/src/drv/tft_driver_sdl2.cpp index b0079ec2..86acce44 100644 --- a/src/drv/tft_driver_sdl2.cpp +++ b/src/drv/tft_driver_sdl2.cpp @@ -9,11 +9,14 @@ #include "display/monitor.h" #include "indev/mouse.h" +#include "drv/tft_driver.h" #include "tft_driver_sdl2.h" #include "dev/device.h" #include "hasp_debug.h" +#include "tft_driver_sdl2.h" + //#include "bootscreen.h" // Sketch tab header for xbm images namespace dev { @@ -35,62 +38,63 @@ static int tick_thread(void* data) return 0; } - void TftSdl2::init(int w, int h) - { +void TftSdl::init(int w, int h) +{ // Workaround for sdl2 `-m32` crash // https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7 #ifndef WIN32 - setenv("DBUS_FATAL_WARNINGS", "0", 1); + setenv("DBUS_FATAL_WARNINGS", "0", 1); #endif - /* Add a display - * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ - monitor_init(); - monitor_title(haspDevice.get_hostname()); + /* Add a display + * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ + monitor_init(); + monitor_title(haspDevice.get_hostname()); - /* Add the mouse as input device - * Use the 'mouse' driver which reads the PC's mouse*/ - mouse_init(); + /* Add the mouse as input device + * Use the 'mouse' driver which reads the PC's mouse*/ + mouse_init(); - /* Tick init. - * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed - * Create an SDL thread to do this*/ - SDL_CreateThread(tick_thread, "tick", NULL); - } - void TftSdl2::show_info() - { - SDL_version linked; - SDL_GetVersion(&linked); - LOG_VERBOSE(TAG_TFT, F("SDL2 : v%d.%d.%d"), linked.major, linked.minor, linked.patch); - LOG_VERBOSE(TAG_TFT, F("Driver : SDL2")); - } + /* Tick init. + * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed + * Create an SDL thread to do this*/ + SDL_CreateThread(tick_thread, "tick", NULL); +} +void TftSdl::show_info() +{ + SDL_version linked; + SDL_GetVersion(&linked); + LOG_VERBOSE(TAG_TFT, F("SDL2 : v%d.%d.%d"), linked.major, linked.minor, linked.patch); + LOG_VERBOSE(TAG_TFT, F("Driver : SDL2")); +} - void TftSdl2::splashscreen() - { - // tft.fillScreen(TFT_DARKCYAN); - // int x = (tft.width() - logoWidth) / 2; - // int y = (tft.height() - logoHeight) / 2; - // tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE); - } - void TftSdl2::set_rotation(uint8_t rotation) - {} - void set_invert(bool invert) - {} - static void TftSdl2::flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) - { - monitor_flush(disp, area, color_p); - } - bool TftSdl2:is_driver_pin(uint8_t pin) - { - return false; - } - const char* TftSdl2::get_tft_model() - { - return "SDL2"; - } +void TftSdl::splashscreen() +{ + // tft.fillScreen(TFT_DARKCYAN); + // int x = (tft.width() - logoWidth) / 2; + // int y = (tft.height() - logoHeight) / 2; + // tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE); +} +void TftSdl::set_rotation(uint8_t rotation) +{} +void TftSdl::set_invert(bool invert) +{} +void TftSdl::flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) +{ + monitor_flush(disp, area, color_p); +} +bool TftSdl::is_driver_pin(uint8_t pin) +{ + return false; +} +const char* TftSdl::get_tft_model() +{ + return "SDL2"; +} } // namespace dev -dev::TftSdl2 haspTft; -#endif \ No newline at end of file +dev::TftSdl haspTft; + +#endif // WINDOWS || POSIX \ No newline at end of file diff --git a/src/drv/tft_driver_sdl2.h b/src/drv/tft_driver_sdl2.h index 47cfe712..d4c453eb 100644 --- a/src/drv/tft_driver_sdl2.h +++ b/src/drv/tft_driver_sdl2.h @@ -1,34 +1,38 @@ - /* MIT License - Copyright (c) 2019-2021 Francis Van Roie - For full license information read the LICENSE file in the project folder */ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ #ifndef HASP_SDL2_DRIVER_H #define HASP_SDL2_DRIVER_H +#include "tft_driver.h" + #if defined(WINDOWS) || defined(POSIX) +#warning Building H driver TFT SDL2 #include "lvgl.h" -#include "tft_driver.h" #include "indev/mouse.h" namespace dev { -class TftSdl2 : BaseTft { +class TftSdl : BaseTft { public: void init(int w, int h); void show_info(); void splashscreen(); + void set_rotation(uint8_t rotation); void set_invert(bool invert); - static void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); + + void flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); bool is_driver_pin(uint8_t pin); + const char* get_tft_model(); }; } // namespace dev -using dev::TftSdl2; -extern dev::TftSdl2 haspTft; - #endif // defined(WINDOWS) || defined(POSIX) #endif // HASP_SDL2_DRIVER_H +using dev::TftSdl; +extern dev::TftSdl haspTft; diff --git a/src/drv/tft_espi_drv.cpp b/src/drv/tft_espi_drv.cpp index 9fdc66c6..5d1bd236 100644 --- a/src/drv/tft_espi_drv.cpp +++ b/src/drv/tft_espi_drv.cpp @@ -6,6 +6,8 @@ *********************/ #include "hasp_conf.h" +#if defined(TOUCH_CS) + #include "hal/hasp_hal.h" // for halGpioName() #include "dev/device.h" #include "drv/tft_driver.h" @@ -14,8 +16,6 @@ #include "ArduinoLog.h" #include "hasp_macro.h" -#if defined(TOUCH_CS) - void tft_espi_calibrate(uint16_t* calData) { haspTft.tft.fillScreen(TFT_BLACK); diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index ad9e7ba2..51942d63 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -26,8 +26,6 @@ #include "hasplib.h" - - //#include "tpcal.h" //#include "Ticker.h" diff --git a/tools/windows_build_extra.py b/tools/windows_build_extra.py index 72e4d78f..9d7c5810 100644 --- a/tools/windows_build_extra.py +++ b/tools/windows_build_extra.py @@ -1,4 +1,4 @@ -Import("env", "projenv") +Import("env") env.Append( LINKFLAGS=[ diff --git a/user_setups/linux_sdl/linux_sdl_64bits.ini b/user_setups/linux_sdl/linux_sdl_64bits.ini index 7587733c..33fb9537 100644 --- a/user_setups/linux_sdl/linux_sdl_64bits.ini +++ b/user_setups/linux_sdl/linux_sdl_64bits.ini @@ -80,7 +80,7 @@ src_filter = - - - - - + + - - + diff --git a/user_setups/win32/windows_sdl_64bits.ini b/user_setups/win32/windows_sdl_64bits.ini index 9245c7ca..a679a63d 100644 --- a/user_setups/win32/windows_sdl_64bits.ini +++ b/user_setups/win32/windows_sdl_64bits.ini @@ -101,7 +101,7 @@ src_filter = - - - - - + + - - + From 9c7c25503921dabcd1c8f730c5c7906894eaa6e9 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Wed, 10 Mar 2021 21:15:05 +0100 Subject: [PATCH 182/236] Add drv directory --- user_setups/darwin_sdl/darwin_sdl_64bits.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_setups/darwin_sdl/darwin_sdl_64bits.ini b/user_setups/darwin_sdl/darwin_sdl_64bits.ini index 1b16060d..65b99594 100644 --- a/user_setups/darwin_sdl/darwin_sdl_64bits.ini +++ b/user_setups/darwin_sdl/darwin_sdl_64bits.ini @@ -85,7 +85,7 @@ src_filter = - - - - - + + - - + From 898667425c691e672b1a772ee066532548058fe3 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 11 Mar 2021 00:22:00 +0100 Subject: [PATCH 183/236] Optimize theme size --- src/hasp/lv_theme_hasp.c | 161 ++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 77 deletions(-) diff --git a/src/hasp/lv_theme_hasp.c b/src/hasp/lv_theme_hasp.c index 38a94843..cedb3444 100644 --- a/src/hasp/lv_theme_hasp.c +++ b/src/hasp/lv_theme_hasp.c @@ -22,7 +22,7 @@ * DEFINES *********************/ -#define HASP_DPX(n) (n == 0 ? 0 : LV_MATH_MAX(((LV_DPI * (n) + 80) / 160), 1)) /*+80 for rounding*/ +#define HASP_DPX(n) hasp_dpx(n) /*SCREEN*/ @@ -62,10 +62,10 @@ #define COLOR_BG_BORDER_CHK_PR (IS_LIGHT ? lv_color_hex(0x3b3e42) : lv_color_hex(0x5f656e)) #define COLOR_BG_BORDER_DIS (IS_LIGHT ? lv_color_hex(0xd6dde3) : lv_color_hex(0x5f656e)) -#define COLOR_BG_TEXT (IS_LIGHT ? lv_color_hex(0xeeeeee) : lv_color_hex(0xeeeeee)) -#define COLOR_BG_TEXT_PR (IS_LIGHT ? lv_color_hex(0xffffff) : lv_color_hex(0xffffff)) -#define COLOR_BG_TEXT_CHK (IS_LIGHT ? lv_color_hex(0xffffff) : lv_color_hex(0xffffff)) -#define COLOR_BG_TEXT_CHK_PR (IS_LIGHT ? lv_color_hex(0xffffff) : lv_color_hex(0xffffff)) +#define COLOR_BG_TEXT lv_color_hex(0xeeeeee) +#define COLOR_BG_TEXT_PR LV_COLOR_WHITE +#define COLOR_BG_TEXT_CHK LV_COLOR_WHITE +#define COLOR_BG_TEXT_CHK_PR LV_COLOR_WHITE #define COLOR_BG_TEXT_DIS (IS_LIGHT ? lv_color_hex3(0xaaa) : lv_color_hex3(0x999)) /*SECONDARY BACKGROUND*/ @@ -217,7 +217,13 @@ static bool inited; * STATIC FUNCTIONS **********************/ -static void basic_init(void) +static lv_style_int_t hasp_dpx(lv_style_int_t n) +{ + return (n == 0 ? 0 : LV_MATH_MAX(((LV_DPI * (n) + 80) / 160), 1)); /*+80 for rounding*/ +} + +static void basic_init(lv_style_int_t border_width, lv_style_int_t outline_width, lv_color_t value_color, + lv_color_t color_scr_text) { sizeof(lv_style_t); @@ -226,10 +232,10 @@ static void basic_init(void) lv_style_set_bg_opa(&styles->transparent, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_border_opa(&styles->transparent, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_outline_opa(&styles->transparent, LV_STATE_DEFAULT, LV_OPA_TRANSP); - lv_style_set_value_color(&styles->transparent, LV_STATE_DEFAULT, COLOR_SCR_TEXT); + lv_style_set_value_color(&styles->transparent, LV_STATE_DEFAULT, color_scr_text); lv_style_set_value_font(&styles->transparent, LV_STATE_DEFAULT, theme.font_subtitle); - if(!NO_FOCUS) lv_style_set_outline_width(&styles->transparent, LV_STATE_DEFAULT, OUTLINE_WIDTH); + if(!NO_FOCUS) lv_style_set_outline_width(&styles->transparent, LV_STATE_DEFAULT, outline_width); // Background gradient style_init_reset(&styles->pretty); @@ -247,22 +253,22 @@ static void basic_init(void) lv_style_set_scale_end_line_width(&styles->pretty, LV_STATE_DEFAULT, 1); lv_style_set_scale_end_color(&styles->pretty, LV_STATE_DEFAULT, theme.color_primary); - lv_style_set_text_color(&styles->pretty, LV_STATE_DEFAULT, COLOR_SCR_TEXT); + lv_style_set_text_color(&styles->pretty, LV_STATE_DEFAULT, color_scr_text); // lv_style_set_text_font(&styles->pretty, LV_STATE_DEFAULT, theme.font_normal); - lv_style_set_value_color(&styles->pretty, LV_STATE_DEFAULT, COLOR_SCR_TEXT); + lv_style_set_value_color(&styles->pretty, LV_STATE_DEFAULT, color_scr_text); lv_style_set_value_font(&styles->pretty, LV_STATE_DEFAULT, theme.font_subtitle); lv_style_set_border_opa(&styles->pretty, LV_STATE_DEFAULT, LV_OPA_30); - lv_style_set_border_width(&styles->pretty, LV_STATE_DEFAULT, BORDER_WIDTH); + lv_style_set_border_width(&styles->pretty, LV_STATE_DEFAULT, border_width); lv_style_set_border_color(&styles->pretty, LV_STATE_DEFAULT, BORDER_COLOR); lv_style_set_border_color(&styles->pretty, LV_STATE_EDITED, lv_color_darken(theme.color_secondary, LV_OPA_30)); - lv_style_set_outline_width(&styles->pretty, LV_STATE_DEFAULT, OUTLINE_WIDTH); + lv_style_set_outline_width(&styles->pretty, LV_STATE_DEFAULT, outline_width); if(!NO_FOCUS) { lv_style_set_border_color(&styles->pretty, LV_STATE_FOCUSED, theme.color_secondary); - lv_style_set_border_width(&styles->pretty, LV_STATE_FOCUSED, OUTLINE_WIDTH); + lv_style_set_border_width(&styles->pretty, LV_STATE_FOCUSED, outline_width); } // Primary Colored gradient @@ -276,23 +282,23 @@ static void basic_init(void) lv_style_set_line_width(&styles->pretty_color, LV_STATE_DEFAULT, 1); lv_style_set_scale_end_line_width(&styles->pretty_color, LV_STATE_DEFAULT, 1); lv_style_set_scale_end_color(&styles->pretty_color, LV_STATE_DEFAULT, theme.color_primary); - lv_style_set_text_color(&styles->pretty_color, LV_STATE_DEFAULT, COLOR_SCR_TEXT); + lv_style_set_text_color(&styles->pretty_color, LV_STATE_DEFAULT, color_scr_text); lv_style_set_line_color(&styles->pretty_color, LV_STATE_DEFAULT, lv_color_make(0x20, 0x20, 0x20)); // lv_style_set_text_font(&styles->pretty_color, LV_STATE_DEFAULT, theme.font_normal); lv_style_set_value_font(&styles->pretty_color, LV_STATE_DEFAULT, theme.font_subtitle); - lv_style_set_value_color(&styles->pretty_color, LV_STATE_DEFAULT, COLOR_SCR_TEXT); + lv_style_set_value_color(&styles->pretty_color, LV_STATE_DEFAULT, color_scr_text); lv_style_set_border_opa(&styles->pretty_color, LV_STATE_DEFAULT, LV_OPA_50); - lv_style_set_border_width(&styles->pretty_color, LV_STATE_DEFAULT, BORDER_WIDTH); + lv_style_set_border_width(&styles->pretty_color, LV_STATE_DEFAULT, border_width); lv_style_set_border_color(&styles->pretty_color, LV_STATE_DEFAULT, BORDER_COLOR); lv_style_set_border_color(&styles->pretty_color, LV_STATE_EDITED, lv_color_darken(theme.color_secondary, LV_OPA_30)); - lv_style_set_outline_width(&styles->pretty_color, LV_STATE_DEFAULT, OUTLINE_WIDTH); + lv_style_set_outline_width(&styles->pretty_color, LV_STATE_DEFAULT, outline_width); if(!NO_FOCUS) { lv_style_set_border_color(&styles->pretty_color, LV_STATE_FOCUSED, theme.color_secondary); - lv_style_set_border_width(&styles->pretty_color, LV_STATE_FOCUSED, OUTLINE_WIDTH); + lv_style_set_border_width(&styles->pretty_color, LV_STATE_FOCUSED, outline_width); } /* style_init_reset(&styles->bg_sec); @@ -356,7 +362,7 @@ static void basic_init(void) lv_style_set_border_color(&styles->btn, LV_STATE_DEFAULT, COLOR_BTN_BORDER); lv_style_set_border_color(&styles->btn, LV_STATE_CHECKED, COLOR_BTN_BORDER_CHK); lv_style_set_border_color(&styles->btn, LV_STATE_DISABLED, COLOR_BTN_BORDER_INA); - lv_style_set_border_width(&styles->btn, LV_STATE_DEFAULT, BORDER_WIDTH); + lv_style_set_border_width(&styles->btn, LV_STATE_DEFAULT, border_width); lv_style_set_border_opa(&styles->btn, LV_STATE_DEFAULT, LV_OPA_50); // lv_style_set_border_opa(&styles->btn, LV_STATE_CHECKED, LV_OPA_40); @@ -366,21 +372,17 @@ static void basic_init(void) lv_style_set_text_color(&styles->btn, LV_STATE_CHECKED | LV_STATE_PRESSED, COLOR_BG_TEXT_CHK_PR); lv_style_set_text_color(&styles->btn, LV_STATE_DISABLED, COLOR_BG_TEXT_DIS); - lv_style_set_image_recolor(&styles->btn, LV_STATE_DEFAULT, - IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xffffff)); - lv_style_set_image_recolor(&styles->btn, LV_STATE_PRESSED, - IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xffffff)); - lv_style_set_image_recolor(&styles->btn, LV_STATE_PRESSED, lv_color_hex(0xffffff)); - lv_style_set_image_recolor(&styles->btn, LV_STATE_CHECKED | LV_STATE_PRESSED, lv_color_hex(0xffffff)); + lv_style_set_image_recolor(&styles->btn, LV_STATE_DEFAULT, value_color); + lv_style_set_image_recolor(&styles->btn, LV_STATE_PRESSED, value_color); + lv_style_set_image_recolor(&styles->btn, LV_STATE_PRESSED, LV_COLOR_WHITE); + lv_style_set_image_recolor(&styles->btn, LV_STATE_CHECKED | LV_STATE_PRESSED, LV_COLOR_WHITE); lv_style_set_image_recolor(&styles->btn, LV_STATE_DISABLED, IS_LIGHT ? lv_color_hex(0x888888) : lv_color_hex(0x888888)); - lv_style_set_value_color(&styles->btn, LV_STATE_DEFAULT, - IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xffffff)); - lv_style_set_value_color(&styles->btn, LV_STATE_PRESSED, - IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xffffff)); - lv_style_set_value_color(&styles->btn, LV_STATE_CHECKED, lv_color_hex(0xffffff)); - lv_style_set_value_color(&styles->btn, LV_STATE_CHECKED | LV_STATE_PRESSED, lv_color_hex(0xffffff)); + lv_style_set_value_color(&styles->btn, LV_STATE_DEFAULT, value_color); + lv_style_set_value_color(&styles->btn, LV_STATE_PRESSED, value_color); + lv_style_set_value_color(&styles->btn, LV_STATE_CHECKED, LV_COLOR_WHITE); + lv_style_set_value_color(&styles->btn, LV_STATE_CHECKED | LV_STATE_PRESSED, LV_COLOR_WHITE); lv_style_set_value_color(&styles->btn, LV_STATE_DISABLED, IS_LIGHT ? lv_color_hex(0x888888) : lv_color_hex(0x888888)); @@ -388,7 +390,7 @@ static void basic_init(void) lv_style_set_pad_ver(&styles->btn, LV_STATE_DEFAULT, HASP_DPX(15)); lv_style_set_pad_inner(&styles->btn, LV_STATE_DEFAULT, HASP_DPX(20)); - lv_style_set_outline_width(&styles->btn, LV_STATE_DEFAULT, OUTLINE_WIDTH); + lv_style_set_outline_width(&styles->btn, LV_STATE_DEFAULT, outline_width); if(!NO_FOCUS) { lv_style_set_outline_opa(&styles->btn, LV_STATE_DEFAULT, LV_OPA_0); lv_style_set_outline_opa(&styles->btn, LV_STATE_FOCUSED, LV_OPA_50); @@ -420,8 +422,7 @@ static void basic_init(void) style_init_reset(&styles->selected); lv_style_set_radius(&styles->selected, LV_STATE_DEFAULT, 0); - lv_style_set_text_color(&styles->selected, LV_STATE_DEFAULT, - IS_LIGHT ? lv_color_hex3(0xfff) : lv_color_hex3(0xfff)); + lv_style_set_text_color(&styles->selected, LV_STATE_DEFAULT, IS_LIGHT ? LV_COLOR_WHITE : LV_COLOR_WHITE); lv_style_set_bg_color(&styles->selected, LV_STATE_PRESSED, COLOR_BG_PR); lv_style_set_text_color(&styles->selected, LV_STATE_PRESSED, COLOR_BG_TEXT_PR); #endif @@ -455,11 +456,11 @@ static void bar_init(void) lv_style_set_radius(&styles->bar_bg, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_bg_opa(&styles->bar_bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->bar_bg, LV_STATE_DEFAULT, COLOR_BG_SEC); - lv_style_set_value_color(&styles->bar_bg, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); + lv_style_set_value_color(&styles->bar_bg, LV_STATE_DEFAULT, value_color); lv_style_set_outline_color(&styles->bar_bg, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_outline_color(&styles->bar_bg, LV_STATE_EDITED, theme.color_secondary); lv_style_set_outline_opa(&styles->bar_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP); - lv_style_set_outline_width(&styles->bar_bg, LV_STATE_DEFAULT, OUTLINE_WIDTH); + lv_style_set_outline_width(&styles->bar_bg, LV_STATE_DEFAULT, outline_width); lv_style_set_transition_time(&styles->bar_bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&styles->bar_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); @@ -511,7 +512,7 @@ static void slider_init(void) // lv_style_set_bg_opa(&styles->slider_knob, LV_STATE_DEFAULT, LV_OPA_COVER); // lv_style_set_bg_color(&styles->slider_knob, LV_STATE_DEFAULT, IS_LIGHT ? theme.color_primary : LV_COLOR_WHITE); // lv_style_set_value_color(&styles->slider_knob, LV_STATE_DEFAULT, - // IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); + // value_color); // lv_style_set_radius(&styles->slider_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_pad_all(&styles->slider_knob, LV_STATE_DEFAULT, HASP_DPX(7)); @@ -642,13 +643,12 @@ static void chart_init(void) #endif } -static void calendar_init(void) +static void calendar_init(lv_style_int_t pad_def, lv_color_t value_color) { #if LV_USE_CALENDAR style_init_reset(&styles->calendar_date_nums); lv_style_set_radius(&styles->calendar_date_nums, LV_STATE_DEFAULT, HASP_DPX(4)); - lv_style_set_text_color(&styles->calendar_date_nums, LV_STATE_CHECKED, - IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); + lv_style_set_text_color(&styles->calendar_date_nums, LV_STATE_CHECKED, value_color); lv_style_set_text_color(&styles->calendar_date_nums, LV_STATE_DISABLED, LV_COLOR_GRAY); lv_style_set_bg_opa(&styles->calendar_date_nums, LV_STATE_CHECKED, IS_LIGHT ? LV_OPA_20 : LV_OPA_40); lv_style_set_bg_opa(&styles->calendar_date_nums, LV_STATE_PRESSED, LV_OPA_20); @@ -662,8 +662,8 @@ static void calendar_init(void) lv_style_set_border_side(&styles->calendar_date_nums, LV_STATE_CHECKED, LV_BORDER_SIDE_LEFT); lv_style_set_border_color(&styles->calendar_date_nums, LV_STATE_CHECKED, theme.color_primary); lv_style_set_pad_inner(&styles->calendar_date_nums, LV_STATE_DEFAULT, HASP_DPX(3)); - lv_style_set_pad_hor(&styles->calendar_date_nums, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_bottom(&styles->calendar_date_nums, LV_STATE_DEFAULT, PAD_DEF); + lv_style_set_pad_hor(&styles->calendar_date_nums, LV_STATE_DEFAULT, pad_def); + lv_style_set_pad_bottom(&styles->calendar_date_nums, LV_STATE_DEFAULT, pad_def); #endif } @@ -698,7 +698,7 @@ static void checkbox_init(void) lv_style_set_outline_color(&styles->cb_bg, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_outline_opa(&styles->cb_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_outline_opa(&styles->cb_bg, LV_STATE_FOCUSED, LV_OPA_50); - lv_style_set_outline_width(&styles->cb_bg, LV_STATE_DEFAULT, OUTLINE_WIDTH); + lv_style_set_outline_width(&styles->cb_bg, LV_STATE_DEFAULT, outline_width); lv_style_set_outline_pad(&styles->cb_bg, LV_STATE_DEFAULT, HASP_DPX(10)); lv_style_set_transition_time(&styles->cb_bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&styles->cb_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); @@ -758,16 +758,16 @@ static void msgbox_init(void) #endif } -static void page_init(void) +static void page_init(lv_style_int_t dpx7) { #if LV_USE_PAGE style_init_reset(&styles->sb); lv_style_set_bg_opa(&styles->sb, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->sb, LV_STATE_DEFAULT, SCROLLBAR_COLOR); lv_style_set_radius(&styles->sb, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_size(&styles->sb, LV_STATE_DEFAULT, HASP_DPX(7)); - lv_style_set_pad_right(&styles->sb, LV_STATE_DEFAULT, HASP_DPX(7)); - lv_style_set_pad_bottom(&styles->sb, LV_STATE_DEFAULT, HASP_DPX(7)); + lv_style_set_size(&styles->sb, LV_STATE_DEFAULT, dpx7); + lv_style_set_pad_right(&styles->sb, LV_STATE_DEFAULT, dpx7); + lv_style_set_pad_bottom(&styles->sb, LV_STATE_DEFAULT, dpx7); #if LV_USE_ANIMATION style_init_reset(&styles->edge_flash); @@ -777,12 +777,12 @@ static void page_init(void) #endif } -static void textarea_init(void) +static void textarea_init(lv_style_int_t border_width) { #if LV_USE_TEXTAREA style_init_reset(&styles->ta_cursor); lv_style_set_border_color(&styles->ta_cursor, LV_STATE_DEFAULT, COLOR_BG_SEC_TEXT); - lv_style_set_border_width(&styles->ta_cursor, LV_STATE_DEFAULT, BORDER_WIDTH); + lv_style_set_border_width(&styles->ta_cursor, LV_STATE_DEFAULT, border_width); lv_style_set_pad_left(&styles->ta_cursor, LV_STATE_DEFAULT, HASP_DPX(1)); lv_style_set_border_side(&styles->ta_cursor, LV_STATE_DEFAULT, LV_BORDER_SIDE_LEFT); @@ -805,7 +805,7 @@ static void spinbox_init(void) #endif } -static void list_init(void) +static void list_init(lv_style_int_t pad_def, lv_style_int_t border_width) { #if LV_USE_LIST != 0 /* style_init_reset(&styles->list_bg); @@ -836,20 +836,20 @@ static void list_init(void) lv_style_set_border_side(&styles->list_btn, LV_STATE_DEFAULT, LV_BORDER_SIDE_BOTTOM); lv_style_set_border_color(&styles->list_btn, LV_STATE_DEFAULT, COLOR_BG_BORDER); lv_style_set_border_color(&styles->list_btn, LV_STATE_FOCUSED, theme.color_primary); - lv_style_set_border_width(&styles->list_btn, LV_STATE_DEFAULT, BORDER_WIDTH); + lv_style_set_border_width(&styles->list_btn, LV_STATE_DEFAULT, border_width); lv_style_set_outline_color(&styles->list_btn, LV_STATE_FOCUSED, theme.color_secondary); - // lv_style_set_outline_width(&styles->list_btn, LV_STATE_FOCUSED, OUTLINE_WIDTH); - lv_style_set_outline_pad(&styles->list_btn, LV_STATE_FOCUSED, -BORDER_WIDTH); + // lv_style_set_outline_width(&styles->list_btn, LV_STATE_FOCUSED, outline_width); + lv_style_set_outline_pad(&styles->list_btn, LV_STATE_FOCUSED, -border_width); - lv_style_set_pad_all(&styles->list_btn, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_inner(&styles->list_btn, LV_STATE_DEFAULT, PAD_DEF); + lv_style_set_pad_all(&styles->list_btn, LV_STATE_DEFAULT, pad_def); + lv_style_set_pad_inner(&styles->list_btn, LV_STATE_DEFAULT, pad_def); - lv_style_set_transform_width(&styles->list_btn, LV_STATE_DEFAULT, -PAD_DEF); - lv_style_set_transform_width(&styles->list_btn, LV_STATE_PRESSED, -BORDER_WIDTH); - lv_style_set_transform_width(&styles->list_btn, LV_STATE_CHECKED, -BORDER_WIDTH); - lv_style_set_transform_width(&styles->list_btn, LV_STATE_DISABLED, -BORDER_WIDTH); - lv_style_set_transform_width(&styles->list_btn, LV_STATE_FOCUSED, -BORDER_WIDTH); + lv_style_set_transform_width(&styles->list_btn, LV_STATE_DEFAULT, -pad_def); + lv_style_set_transform_width(&styles->list_btn, LV_STATE_PRESSED, -border_width); + lv_style_set_transform_width(&styles->list_btn, LV_STATE_CHECKED, -border_width); + lv_style_set_transform_width(&styles->list_btn, LV_STATE_DISABLED, -border_width); + lv_style_set_transform_width(&styles->list_btn, LV_STATE_FOCUSED, -border_width); lv_style_set_transition_time(&styles->list_btn, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&styles->list_btn, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); @@ -870,7 +870,7 @@ static void ddlist_init(void) // lv_style_set_bg_opa(&styles->ddlist_sel, LV_STATE_DEFAULT, LV_OPA_COVER); // lv_style_set_bg_color(&styles->ddlist_sel, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_text_color(&styles->ddlist_sel, LV_STATE_DEFAULT, - IS_LIGHT ? lv_color_hex3(0xfff) : lv_color_hex3(0xfff)); + IS_LIGHT ?LV_COLOR_WHITE :LV_COLOR_WHITE); lv_style_set_bg_color(&styles->ddlist_sel, LV_STATE_PRESSED, COLOR_BG_PR); lv_style_set_text_color(&styles->ddlist_sel, LV_STATE_PRESSED, COLOR_BG_TEXT_PR); */ @@ -902,14 +902,14 @@ static void tileview_init(void) #endif } -static void table_init(void) +static void table_init(lv_style_int_t pad_def) { #if LV_USE_TABLE != 0 style_init_reset(&styles->table_cell); lv_style_set_border_color(&styles->table_cell, LV_STATE_DEFAULT, COLOR_BG_BORDER); lv_style_set_border_width(&styles->table_cell, LV_STATE_DEFAULT, 1); lv_style_set_border_side(&styles->table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); - lv_style_set_pad_all(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF); + lv_style_set_pad_all(&styles->table_cell, LV_STATE_DEFAULT, pad_def); #endif } @@ -919,21 +919,21 @@ static void win_init(void) #endif } -static void tabview_win_shared_init(void) +static void tabview_win_shared_init(lv_style_int_t pad_def, lv_style_int_t dpx7, lv_color_t color_scr_text) { #if LV_USE_TABVIEW || LV_USE_WIN style_init_reset(&styles->tabview_btns_bg); lv_style_set_bg_opa(&styles->tabview_btns_bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->tabview_btns_bg, LV_STATE_DEFAULT, COLOR_SCR_GRAD); - lv_style_set_text_color(&styles->tabview_btns_bg, LV_STATE_DEFAULT, COLOR_SCR_TEXT); + lv_style_set_text_color(&styles->tabview_btns_bg, LV_STATE_DEFAULT, color_scr_text); lv_style_set_image_recolor(&styles->tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f)); - lv_style_set_pad_top(&styles->tabview_btns_bg, LV_STATE_DEFAULT, HASP_DPX(7)); - lv_style_set_pad_hor(&styles->tabview_btns_bg, LV_STATE_DEFAULT, HASP_DPX(7)); + lv_style_set_pad_top(&styles->tabview_btns_bg, LV_STATE_DEFAULT, dpx7); + lv_style_set_pad_hor(&styles->tabview_btns_bg, LV_STATE_DEFAULT, dpx7); style_init_reset(&styles->tabview_btns); lv_style_set_bg_opa(&styles->tabview_btns, LV_STATE_PRESSED, LV_OPA_50); lv_style_set_bg_color(&styles->tabview_btns, LV_STATE_PRESSED, lv_color_hex3(0x888)); - lv_style_set_text_color(&styles->tabview_btns, LV_STATE_CHECKED, COLOR_SCR_TEXT); + lv_style_set_text_color(&styles->tabview_btns, LV_STATE_CHECKED, color_scr_text); lv_style_set_pad_ver(&styles->tabview_btns, LV_STATE_DEFAULT, HASP_DPX(20)); lv_style_set_text_color(&styles->tabview_btns, LV_STATE_FOCUSED, theme.color_primary); lv_style_set_text_color(&styles->tabview_btns, LV_STATE_EDITED, theme.color_secondary); @@ -946,8 +946,8 @@ static void tabview_win_shared_init(void) lv_style_set_radius(&styles->tabview_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); style_init_reset(&styles->tabview_page_scrl); - lv_style_set_pad_all(&styles->tabview_page_scrl, LV_STATE_DEFAULT, PAD_DEF); - lv_style_set_pad_inner(&styles->tabview_page_scrl, LV_STATE_DEFAULT, PAD_DEF); + lv_style_set_pad_all(&styles->tabview_page_scrl, LV_STATE_DEFAULT, pad_def); + lv_style_set_pad_inner(&styles->tabview_page_scrl, LV_STATE_DEFAULT, pad_def); #endif } @@ -987,7 +987,14 @@ lv_theme_t* lv_theme_hasp_init(lv_color_t color_primary, lv_color_t color_second theme.font_title = font_title; theme.flags = flags; - basic_init(); + lv_style_int_t border_width = BORDER_WIDTH; + lv_style_int_t outline_width = OUTLINE_WIDTH; + lv_style_int_t pad_def = PAD_DEF; + lv_style_int_t dpx7 = HASP_DPX(7); + lv_color_t value_color = IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE; + lv_color_t color_scr_text = COLOR_SCR_TEXT; + + basic_init(border_width, outline_width, value_color, color_scr_text); cont_init(); btn_init(); label_init(); @@ -1002,23 +1009,23 @@ lv_theme_t* lv_theme_hasp_init(lv_color_t color_primary, lv_color_t color_second arc_init(); spinner_init(); chart_init(); - calendar_init(); + calendar_init(pad_def, value_color); cpicker_init(); checkbox_init(); btnmatrix_init(); keyboard_init(); msgbox_init(); - page_init(); - textarea_init(); + page_init(dpx7); + textarea_init(border_width); spinbox_init(); - list_init(); + list_init(pad_def, border_width); ddlist_init(); roller_init(); tabview_init(); tileview_init(); - table_init(); + table_init(pad_def); win_init(); - tabview_win_shared_init(); + tabview_win_shared_init(pad_def, dpx7, color_scr_text); theme.apply_xcb = NULL; theme.apply_cb = theme_apply; From 81b6614520bf56625ebdd398ccac935242a8a97e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 11 Mar 2021 21:06:19 +0100 Subject: [PATCH 184/236] Add bootscreen and pages.jsonl --- hal/sdl2/app_hal.c | 2 +- src/drv/tft_driver_sdl2.cpp | 2 +- src/hasp/hasp.cpp | 15 +++++++++++++++ src/hasp/hasp_dispatch.cpp | 2 +- src/hasp/hasp_dispatch.h | 2 +- src/main_sdl2.cpp | 37 ++++++++++++++++++++++++------------- 6 files changed, 43 insertions(+), 17 deletions(-) diff --git a/hal/sdl2/app_hal.c b/hal/sdl2/app_hal.c index 72ba9bba..fd062ada 100644 --- a/hal/sdl2/app_hal.c +++ b/hal/sdl2/app_hal.c @@ -33,7 +33,7 @@ void hal_setup(void) /* Add a display * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ - monitor_init(); + monitor_init(MONITOR_HOR_RES, MONITOR_VER_RES); /* Add the mouse as input device * Use the 'mouse' driver which reads the PC's mouse*/ diff --git a/src/drv/tft_driver_sdl2.cpp b/src/drv/tft_driver_sdl2.cpp index 86acce44..eb02c0ad 100644 --- a/src/drv/tft_driver_sdl2.cpp +++ b/src/drv/tft_driver_sdl2.cpp @@ -49,7 +49,7 @@ void TftSdl::init(int w, int h) /* Add a display * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ - monitor_init(); + monitor_init(MONITOR_HOR_RES, MONITOR_VER_RES); monitor_title(haspDevice.get_hostname()); /* Add the mouse as input device diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 63635ecd..eaecd32d 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -5,6 +5,12 @@ #include "ArduinoLog.h" #endif +#if defined(WINDOWS) || defined(POSIX) +#include +#include +#include +#endif + #include "ArduinoJson.h" #if HASP_USE_EEPROM > 0 @@ -601,6 +607,15 @@ void haspLoadPage(const char* pagesfile) LOG_INFO(TAG_HASP, F("Loaded jsonl from EEPROM")); #endif + std::ifstream ifs("pages.json", std::ifstream::in); + if(ifs) { + LOG_TRACE(TAG_HASP, F("Loading file %s"), pagesfile); + dispatch_parse_jsonl(ifs); + LOG_INFO(TAG_HASP, F("File %s loaded"), pagesfile); + } else { + LOG_ERROR(TAG_HASP, F("Non existing file %s"), pagesfile); + } + #endif } diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 3f6a7da7..aa409c3e 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -768,7 +768,7 @@ void dispatch_parse_json(const char*, const char* payload) #ifdef ARDUINO void dispatch_parse_jsonl(Stream& stream) #else -void dispatch_parse_jsonl(std::istringstream& stream) +void dispatch_parse_jsonl(std::istream& stream) #endif { uint8_t savedPage = haspGetPage(); diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 5f6b837b..2a9e44ee 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -41,7 +41,7 @@ void dispatch_text_line(const char* cmnd); #ifdef ARDUINO void dispatch_parse_jsonl(Stream& stream); #else -void dispatch_parse_jsonl(std::istringstream& stream); +void dispatch_parse_jsonl(std::istream& stream); #endif void dispatch_clear_page(const char* page); diff --git a/src/main_sdl2.cpp b/src/main_sdl2.cpp index 096906fb..cc181187 100644 --- a/src/main_sdl2.cpp +++ b/src/main_sdl2.cpp @@ -4,11 +4,19 @@ #if defined(WINDOWS) || defined(POSIX) #if defined(WINDOWS) + #include +#include +// MSDN recommends against using getcwd & chdir names +#define cwd _getcwd +#define cd _chdir #endif + #if defined(POSIX) #include #include +#define cwd getcwd +#define cd chdir #endif #include @@ -170,7 +178,6 @@ void loop() // delay(6); } - void usage(char* progName) { std::cout << progName << " [options]" << std::endl @@ -201,16 +208,9 @@ int main(int argc, char* argv[]) { bool showhelp = false; int count; -#ifdef WINDOWS - InitializeConsoleOutput(); -#endif - - // Display each command-line argument. - std::cout << "\nCommand-line arguments:\n"; - for(count = 0; count < argc; count++) - std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; #if defined(WINDOWS) + InitializeConsoleOutput(); SetConsoleCP(65001); // 65001 = UTF-8 static const char s[] = "tränenüberströmt™\n"; DWORD slen = lstrlen(s); @@ -218,13 +218,25 @@ int main(int argc, char* argv[]) HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); if(std_out == INVALID_HANDLE_VALUE) { - // return 66; + return 66; } - if(!WriteConsole(std_out, "Hello World!", 12, NULL, NULL)) { - // return 67; + if(!WriteConsole(std_out, "Hello World!\n", 13, NULL, NULL)) { + return 67; } #endif + SDL_Init(0); // Needs to be initialized for GetPerfPath + char buf[4096]; // never know how much is needed + std::cout << "CWD: " << cwd(buf, sizeof buf) << std::endl; + cd(SDL_GetPrefPath("hasp", "hasp")); + std::cout << "CWD changed to: " << cwd(buf, sizeof buf) << std::endl; + SDL_Quit(); // We'll properly init later + + // Change to preferences dir + std::cout << "\nCommand-line arguments:\n"; + for(count = 0; count < argc; count++) + std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; + for(count = 0; count < argc; count++) { if(argv[count][0] == '-') { @@ -272,5 +284,4 @@ int main(int argc, char* argv[]) return 0; } - #endif From f383ecc15eded369addd5cd63b14cdf1cf12e6e2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 12 Mar 2021 04:10:10 +0100 Subject: [PATCH 185/236] Update README --- include/README | 37 +------------------------------------ lib/README | 2 +- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/include/README b/include/README index 194dcd43..794e54d7 100644 --- a/include/README +++ b/include/README @@ -1,39 +1,4 @@ This directory is intended for project header files. -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html +The header files in this folder configure the different components of HASP, LVGL and paho. \ No newline at end of file diff --git a/lib/README b/lib/README index 6debab1e..79cec710 100644 --- a/lib/README +++ b/lib/README @@ -1,5 +1,5 @@ -This directory is intended for project specific (private) libraries. +This directory is intended for project specific (customized) libraries. PlatformIO will compile them to static libraries and link into executable file. The source code of each library should be placed in a an own separate directory From 4d6f59bb19dbfe4dd0cfa4dfe4bf37ea9bb7dfc3 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 12 Mar 2021 04:13:16 +0100 Subject: [PATCH 186/236] Xplatform debug --- src/dev/win32/hasp_win32.cpp | 2 +- src/drv/tft_driver_sdl2.cpp | 2 +- src/hasp_debug.cpp | 407 +++++++++++++++++++++++++++++++++++ src/hasp_debug.h | 71 +++++- src/log/hasp_debug.cpp | 371 +------------------------------ src/main_sdl2.cpp | 7 +- 6 files changed, 472 insertions(+), 388 deletions(-) create mode 100644 src/hasp_debug.cpp diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 56e25f1a..be465952 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -31,7 +31,7 @@ void Win32Device::show_info() unsigned int eax, ebx, ecx, edx; eax = 0; native_cpuid(&eax, &ebx, &ecx, &edx); - printf("EAX: %08X EBX: %08X ECX: %08X EDX: %08X\n", eax, ebx, ecx, edx); + // printf("EAX: %08X EBX: %08X ECX: %08X EDX: %08X\n", eax, ebx, ecx, edx); char vendor[13]; memcpy(vendor, &ebx, 4); memcpy(vendor + 4, &edx, 4); diff --git a/src/drv/tft_driver_sdl2.cpp b/src/drv/tft_driver_sdl2.cpp index eb02c0ad..0c8801a1 100644 --- a/src/drv/tft_driver_sdl2.cpp +++ b/src/drv/tft_driver_sdl2.cpp @@ -65,8 +65,8 @@ void TftSdl::show_info() { SDL_version linked; SDL_GetVersion(&linked); - LOG_VERBOSE(TAG_TFT, F("SDL2 : v%d.%d.%d"), linked.major, linked.minor, linked.patch); LOG_VERBOSE(TAG_TFT, F("Driver : SDL2")); + LOG_VERBOSE(TAG_TFT, F("SDL Version: v%d.%d.%d"), linked.major, linked.minor, linked.patch); } void TftSdl::splashscreen() diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp new file mode 100644 index 00000000..72b68333 --- /dev/null +++ b/src/hasp_debug.cpp @@ -0,0 +1,407 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#include "ArduinoJson.h" +#include "lvgl.h" +#include + +#include "lang/lang.h" +#include "hasp_conf.h" +#include "hasp_debug.h" +#include "hasp_macro.h" +#include "hasp/hasp.h" + +#if(!defined(WINDOWS)) && (!defined(POSIX)) +#include "ArduinoLog.h" + +#define debug_print(io, ...) io->print(__VA_ARGS__) +#define debug_newline(io) io->println() + +bool debugSerialStarted = false; +#else +#include +#include +#include + +#define debug_print(io, ...) fprintf(stdout, __VA_ARGS__) +#define debug_newline(io) fprintf(stdout, "\n") + +bool debugSerialStarted = true; +#endif + +bool debugAnsiCodes = true; + +inline void debugSendAnsiCode(const __FlashStringHelper* code, Print* _logOutput) +{ + if(debugAnsiCodes) debug_print(_logOutput, code); +} + +void debug_timestamp() +{ + timeval curTime; + gettimeofday(&curTime, NULL); + int milli = curTime.tv_usec / 1000; + + char currentTime[80]; + time_t t = curTime.tv_sec; + // strftime(currentTime, 80, "%Y-%m-%d %H:%M.%S", localtime(&t)); + strftime(currentTime, 80, "%H:%M:%S", localtime(&t)); + printf("[%s.%03d] ", currentTime, milli); +} + +static void debugPrintTimestamp(int level, Print* _logOutput) +{ /* Print Current Time */ + + timeval curTime; + int rslt = gettimeofday(&curTime, NULL); + time_t t = curTime.tv_sec; + tm* timeinfo = localtime(&t); + int milli = curTime.tv_usec / 1000; + + debugSendAnsiCode(F(TERM_COLOR_CYAN), _logOutput); + + if(timeinfo->tm_year >= 120) { + char buffer[24]; + strftime(buffer, sizeof(buffer), "[%b %d %H:%M:%S", timeinfo); // Literal String + // strftime(buffer, sizeof(buffer), "[%H:%M:%S.", timeinfo); // Literal String + debug_print(_logOutput, PSTR("%s.%03lu]"), buffer, curTime.tv_usec / 1000); + } else { + uint32_t msecs = millis(); + debug_print(_logOutput, PSTR("[%15d.%03d]"), msecs / 1000, msecs % 1000); + } +} + +/* ===== Default Event Processors ===== */ +// void debugPreSetup(JsonObject settings); +// void debugSetup(); + +static inline void debug_flush() +{ +#if defined(ARDUINO) + Serial.flush(); +#endif + +#if defined(WINDOWS) || defined(POSIX) + fflush(stdout); +#endif +} + +void debugEverySecond() +{ + // if(debugTelePeriod > 0 && (millis() - debugLastMillis) >= debugTelePeriod * 1000) { + // dispatch_output_statusupdate(NULL, NULL); + // debugLastMillis = millis(); + // } + // printLocalTime(); +} + +void debugStart() +{ + +#if defined(WINDOWS) || defined(POSIX) + debug_newline(); + debugPrintHaspHeader(NULL); + debug_newline(); + + LOG_INFO(TAG_DEBG, F("Console started")); + LOG_INFO(TAG_DEBG, F("Environment: " PIOENV)); +#endif + + if(debugSerialStarted) { + debug_flush; + + // Serial.println(); + // Serial.println(debugHaspHeader()); + // debug_flush(); + } + + // prepare syslog configuration here (can be anywhere before first call of + // log/logf method) +} + +void debugStop() +{ + if(debugSerialStarted) debug_flush(); +} + +/* ===== Special Event Processors ===== */ + +void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr) +{ +#if LV_USE_LOG != 0 + /* used for duplicate detection */ + static uint32_t lastDbgLine; + static uint32_t lastDbgFreeMem; + + lv_mem_monitor_t mem_mon; + lv_mem_monitor(&mem_mon); + + /* Reduce the number of repeated debug message */ + if(line != lastDbgLine || mem_mon.free_biggest_size != lastDbgFreeMem) { + switch(level) { + case LV_LOG_LEVEL_TRACE: + LOG_VERBOSE(TAG_LVGL, descr); + break; + case LV_LOG_LEVEL_WARN: + LOG_WARNING(TAG_LVGL, descr); + break; + case LV_LOG_LEVEL_ERROR: + LOG_ERROR(TAG_LVGL, descr); + break; + default: + LOG_TRACE(TAG_LVGL, descr); + } + lastDbgLine = line; + lastDbgFreeMem = mem_mon.free_biggest_size; + } +#endif +} + +// Send the HASP header and version to the output device specified +void debugPrintHaspHeader(Print* output) +{ + // if(debugAnsiCodes) debug_print(output,TERM_COLOR_YELLOW); + debug_newline(output); + debug_print(output, F("" + " _____ _____ _____ _____\r\n" + " | | | _ | __| _ |\r\n" + " | | |__ | __|\r\n" + " |__|__|__|__|_____|__|\r\n" + " Home Automation Switch Plate\r\n" + " Open Hardware edition v")); + char buffer[32]; + haspGetVersion(buffer, sizeof(buffer)); + debug_print(output, buffer); + debug_newline(output); +} + +void debug_get_tag(uint8_t tag, char* buffer) +{ + switch(tag) { + case TAG_MAIN: + memcpy_P(buffer, PSTR("MAIN"), 5); + break; + + case TAG_HASP: + memcpy_P(buffer, PSTR("HASP"), 5); + break; + + case TAG_DRVR: + memcpy_P(buffer, PSTR("DRVR"), 5); + break; + + case TAG_ATTR: + memcpy_P(buffer, PSTR("ATTR"), 5); + break; + + case TAG_MSGR: + memcpy_P(buffer, PSTR("MSGR"), 5); + break; + + case TAG_OOBE: + memcpy_P(buffer, PSTR("OOBE"), 5); + break; + case TAG_HAL: + memcpy_P(buffer, PSTR("HAL "), 5); + break; + + case TAG_DEBG: + memcpy_P(buffer, PSTR("DBUG"), 5); + break; + case TAG_TELN: + memcpy_P(buffer, PSTR("TELN"), 5); + break; + case TAG_SYSL: + memcpy_P(buffer, PSTR("SYSL"), 5); + break; + case TAG_TASM: + memcpy_P(buffer, PSTR("TASM"), 5); + break; + + case TAG_CONF: + memcpy_P(buffer, PSTR("CONF"), 5); + break; + case TAG_GUI: + memcpy_P(buffer, PSTR("GUI "), 5); + break; + case TAG_TFT: + memcpy_P(buffer, PSTR("TFT "), 5); + break; + + case TAG_EPRM: + memcpy_P(buffer, PSTR("EPRM"), 5); + break; + case TAG_FILE: + memcpy_P(buffer, PSTR("FILE"), 5); + break; + case TAG_GPIO: + memcpy_P(buffer, PSTR("GPIO"), 5); + break; + + case TAG_ETH: + memcpy_P(buffer, PSTR("ETH "), 5); + break; + case TAG_WIFI: + memcpy_P(buffer, PSTR("WIFI"), 5); + break; + case TAG_HTTP: + memcpy_P(buffer, PSTR("HTTP"), 5); + break; + case TAG_MDNS: + memcpy_P(buffer, PSTR("MDNS"), 5); + break; + case TAG_MQTT: + memcpy_P(buffer, PSTR("MQTT"), 5); + break; + case TAG_MQTT_PUB: + memcpy_P(buffer, PSTR("MQTT PUB"), 9); + break; + case TAG_MQTT_RCV: + memcpy_P(buffer, PSTR("MQTT RCV"), 9); + break; + + case TAG_OTA: + memcpy_P(buffer, PSTR("OTA "), 5); + break; + case TAG_FWUP: + memcpy_P(buffer, PSTR("FWUP"), 5); + break; + + case TAG_LVGL: + memcpy_P(buffer, PSTR("LVGL"), 5); + break; + case TAG_LVFS: + memcpy_P(buffer, PSTR("LVFS"), 5); + break; + case TAG_FONT: + memcpy_P(buffer, PSTR("FONT"), 5); + break; + + default: + memcpy_P(buffer, PSTR("----"), 5); + break; + } +} + +static void debugPrintHaspMemory(int level, Print* _logOutput) +{ + size_t maxfree = haspDevice.get_free_max_block(); + size_t totalfree = haspDevice.get_free_heap(); + uint8_t frag = haspDevice.get_heap_fragmentation(); + + /* Print HASP Memory Info */ + if(debugAnsiCodes) { + if(maxfree > (1024u * 5) && (totalfree > 1024u * 6) && (frag <= 10)) + debugSendAnsiCode(F(TERM_COLOR_GREEN), _logOutput); + else if(maxfree > (1024u * 3) && (totalfree > 1024u * 5) && (frag <= 20)) + debugSendAnsiCode(F(TERM_COLOR_ORANGE), _logOutput); + else + debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); + } + debug_print(_logOutput, PSTR("[%5u/%5u%3u]"), maxfree, totalfree, frag); +} + +static void debugPrintLvglMemory(int level, Print* _logOutput) +{ +#if LV_MEM_CUSTOM == 0 + lv_mem_monitor_t mem_mon; + lv_mem_monitor(&mem_mon); + + /* Print LVGL Memory Info */ + if(debugAnsiCodes) { + if(mem_mon.free_biggest_size > (1024u * 2) && (mem_mon.free_size > 1024u * 2.5) && (mem_mon.frag_pct <= 10)) + debugSendAnsiCode(F(TERM_COLOR_GREEN), _logOutput); + else if(mem_mon.free_biggest_size > (1024u * 1) && (mem_mon.free_size > 1024u * 1.5) && + (mem_mon.frag_pct <= 25)) + debugSendAnsiCode(F(TERM_COLOR_ORANGE), _logOutput); + else + debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); + } + debug_print(_logOutput, PSTR("[%5u/%5u%3u]"), mem_mon.free_biggest_size, mem_mon.free_size, mem_mon.frag_pct); +#endif +} + +static void debugPrintPriority(int level, Print* _logOutput) +{ + // if(_logOutput == &syslogClient) { + // } + + switch(level) { + case LOG_LEVEL_FATAL ... LOG_LEVEL_ERROR: + debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); + break; + case LOG_LEVEL_WARNING: + debugSendAnsiCode(F(TERM_COLOR_YELLOW), _logOutput); + break; + case LOG_LEVEL_NOTICE: + debugSendAnsiCode(F(TERM_COLOR_WHITE), _logOutput); + break; + case LOG_LEVEL_TRACE: + debugSendAnsiCode(F(TERM_COLOR_GRAY), _logOutput); + break; + case LOG_LEVEL_VERBOSE: + debugSendAnsiCode(F(TERM_COLOR_CYAN), _logOutput); + break; + case LOG_LEVEL_DEBUG: + debugSendAnsiCode(F(TERM_COLOR_BLUE), _logOutput); + break; + case LOG_LEVEL_OUTPUT: + default: + debugSendAnsiCode(F(TERM_COLOR_RESET), _logOutput); + } +} + +void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput) +{ + char buffer[10]; + +#if HASP_USE_SYSLOG > 0 + + if(_logOutput == syslogClient && syslogClient) { + if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) { + + // IETF Doc: https://tools.ietf.org/html/rfc5424 - The Syslog Protocol + // BSD Doc: https://tools.ietf.org/html/rfc3164 - The BSD syslog Protocol + + syslogClient->print(F("<")); + syslogClient->print((16 + debugSyslogFacility) * 8 + level); + syslogClient->print(F(">")); + + if(debugSyslogProtocol == SYSLOG_PROTO_IETF) { + syslogClient->print(F("1 - ")); + } + + debug_get_tag(tag, buffer); + syslogClient->print(F("%s %s"), haspDevice.get_hostname(), buffer); + + if(debugSyslogProtocol == SYSLOG_PROTO_IETF) { + syslogClient->print(F(" - - - \xEF\xBB\xBF")); // include UTF-8 BOM + } else { + syslogClient->print(F(": ")); + } + + debugPrintHaspMemory(level, _logOutput); +#if LV_MEM_CUSTOM == 0 + debugPrintLvglMemory(level, _logOutput); +#endif + } + return; + } +#endif // HASP_USE_SYSLOG + + debugSendAnsiCode(F(TERM_CLEAR_LINE), _logOutput); + debugPrintTimestamp(level, _logOutput); + debugPrintHaspMemory(level, _logOutput); + debugPrintLvglMemory(level, _logOutput); + + if(tag == TAG_MQTT_PUB && level == LOG_LEVEL_NOTICE) { + debugSendAnsiCode(F(TERM_COLOR_GREEN), _logOutput); + } else if(tag == TAG_MQTT_RCV && level == LOG_LEVEL_NOTICE) { + debugSendAnsiCode(F(TERM_COLOR_ORANGE), _logOutput); + } else { + debugPrintPriority(level, _logOutput); + } + + debug_get_tag(tag, buffer); + debug_print(_logOutput, F(" %s: "), buffer); +} \ No newline at end of file diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 9218ba37..006acb6c 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -10,55 +10,77 @@ #include "lang/lang.h" -#if (!defined(WINDOWS)) && (!defined(POSIX)) +#if(!defined(WINDOWS)) && (!defined(POSIX)) #include "ArduinoLog.h" /* ===== Default Event Processors ===== */ void debugPreSetup(JsonObject settings); void debugSetup(); -void debugLoop(void); -void debugEverySecond(void); -void debugStart(void); -void debugStop(void); /* ===== Special Event Processors ===== */ -void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr); -void debugPrintHaspHeader(Print* output); + void debugStartSyslog(void); void debugStopSyslog(void); // void syslogSend(uint8_t log, const char * debugText); + #else + +#define Print void + #include +#include + +#define LOG_LEVEL_SILENT -1 + +#define LOG_LEVEL_FATAL 0 +#define LOG_LEVEL_ALERT 1 +#define LOG_LEVEL_CRITICAL 2 +#define LOG_LEVEL_ERROR 3 +#define LOG_LEVEL_WARNING 4 +#define LOG_LEVEL_NOTICE 5 +#define LOG_LEVEL_INFO 5 +#define LOG_LEVEL_TRACE 6 +#define LOG_LEVEL_VERBOSE 7 +#define LOG_LEVEL_DEBUG 8 +#define LOG_LEVEL_OUTPUT 9 #define LOG_FATAL(x, ...) \ + debugPrintPrefix(x, LOG_LEVEL_FATAL, NULL); \ printf(__VA_ARGS__); \ std::cout << std::endl; \ fflush(stdout) #define LOG_ERROR(x, ...) \ + debugPrintPrefix(x, LOG_LEVEL_ERROR, NULL); \ printf(__VA_ARGS__); \ std::cout << std::endl; \ fflush(stdout) #define LOG_WARNING(x, ...) \ + debugPrintPrefix(x, LOG_LEVEL_WARNING, NULL); \ printf(__VA_ARGS__); \ std::cout << std::endl; \ fflush(stdout) #define LOG_NOTICE(x, ...) \ + debugPrintPrefix(x, LOG_LEVEL_NOTICE, NULL); \ printf(__VA_ARGS__); \ std::cout << std::endl; \ fflush(stdout) #define LOG_TRACE(x, ...) \ + debugPrintPrefix(x, LOG_LEVEL_TRACE, NULL); \ printf(__VA_ARGS__); \ std::cout << std::endl; \ fflush(stdout) #define LOG_VERBOSE(x, ...) \ + debugPrintPrefix(x, LOG_LEVEL_VERBOSE, NULL); \ printf(__VA_ARGS__); \ std::cout << std::endl; \ fflush(stdout) #define LOG_DEBUG(x, ...) \ + debugPrintPrefix(x, LOG_LEVEL_DEBUG, NULL); \ printf(__VA_ARGS__); \ std::cout << std::endl; \ fflush(stdout) #define LOG_INFO(x, ...) \ + debugPrintPrefix(x, LOG_LEVEL_INFO, NULL); \ printf(__VA_ARGS__); \ std::cout << std::endl; \ fflush(stdout) @@ -105,16 +127,30 @@ void debugStopSyslog(void); #endif +#ifdef __cplusplus +extern "C" { +#endif + +// Functions used by ANDROID, WINDOWS and POSSIX +void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr); +void debugLoop(void); +void debugEverySecond(void); +void debugStart(void); +void debugStop(void); +void debugPrintHaspHeader(Print* output); +void debugPrintTag(uint8_t tag, Print* _logOutput); +void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput); + +#ifdef __cplusplus +} +#endif + /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 bool debugGetConfig(const JsonObject& settings); bool debugSetConfig(const JsonObject& settings); #endif -// void debugPrintPrefix(int level, Print * _logOutput); -// void debugPrintSuffix(int level, Print * _logOutput); -// void debugSendOuput(const char * buffer); - enum { TAG_MAIN = 0, TAG_HASP = 1, @@ -154,4 +190,17 @@ enum { TAG_FONT = 92 }; +//#define TERM_COLOR_Black "\u001b[30m" +#define TERM_COLOR_GRAY "\e[37m" +#define TERM_COLOR_RED "\e[91m" +#define TERM_COLOR_GREEN "\e[92m" +#define TERM_COLOR_ORANGE "\e[38;5;214m" +#define TERM_COLOR_YELLOW "\e[93m" +#define TERM_COLOR_BLUE "\e[94m" +#define TERM_COLOR_MAGENTA "\e[35m" +#define TERM_COLOR_CYAN "\e[96m" +#define TERM_COLOR_WHITE "\e[97m" +#define TERM_COLOR_RESET "\e[0m" +#define TERM_CLEAR_LINE "\e[1000D\e[0K" + #endif diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index 4f6d36b0..e9418628 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -89,58 +89,14 @@ WiFiUDP* syslogClient; // char serialInputBuffer[220] = ""; // uint16_t historyIndex = sizeof(serialInputBuffer) - 1; // Empty buffer uint16_t debugSerialBaud = SERIAL_SPEED / 10; // Multiplied by 10 -bool debugSerialStarted = false; -bool debugAnsiCodes = true; +extern bool debugSerialStarted; +extern bool debugAnsiCodes; ConsoleInput debugConsole(&Serial, HASP_CONSOLE_BUFFER); -//#define TERM_COLOR_Black "\u001b[30m" -#define TERM_COLOR_GRAY "\e[37m" -#define TERM_COLOR_RED "\e[91m" -#define TERM_COLOR_GREEN "\e[92m" -#define TERM_COLOR_ORANGE "\e[38;5;214m" -#define TERM_COLOR_YELLOW "\e[93m" -#define TERM_COLOR_BLUE "\e[94m" -#define TERM_COLOR_MAGENTA "\e[35m" -#define TERM_COLOR_CYAN "\e[96m" -#define TERM_COLOR_WHITE "\e[97m" -#define TERM_COLOR_RESET "\e[0m" -#define TERM_CLEAR_LINE "\e[1000D\e[0K" - unsigned long debugLastMillis = 0; uint16_t debugTelePeriod = 300; -// Send the HASP header and version to the output device specified -void debugPrintHaspHeader(Print* output) -{ - if(debugAnsiCodes) output->print(TERM_COLOR_YELLOW); - output->println(); - output->print(F("" - " _____ _____ _____ _____\r\n" - " | | | _ | __| _ |\r\n" - " | | |__ | __|\r\n" - " |__|__|__|__|_____|__|\r\n" - " Home Automation Switch Plate\r\n" - " Open Hardware edition v")); - char buffer[32]; - haspGetVersion(buffer, sizeof(buffer)); - output->println(buffer); - output->println(); -} - -void debugStart() -{ - if(debugSerialStarted) { - Serial.flush(); - // Serial.println(); - // Serial.println(debugHaspHeader()); - // Serial.flush(); - } - - // prepare syslog configuration here (can be anywhere before first call of - // log/logf method) -} - // #if HASP_USE_SYSLOG > 0 // void syslogSend(uint8_t priority, const char * debugText) // { @@ -194,11 +150,6 @@ void debugStopSyslog() #endif } -void debugStop() -{ - if(debugSerialStarted) Serial.flush(); -} - #if HASP_USE_CONFIG > 0 bool debugGetConfig(const JsonObject& settings) { @@ -262,10 +213,6 @@ bool debugSetConfig(const JsonObject& settings) } #endif // HASP_USE_CONFIG -inline void debugSendAnsiCode(const __FlashStringHelper* code, Print* _logOutput) -{ - if(debugAnsiCodes) _logOutput->print(code); -} /* size_t debugHistorycount() { @@ -331,280 +278,6 @@ void debugGetHistoryLine(size_t num) } */ -static void debugPrintTimestamp(int level, Print* _logOutput) -{ /* Print Current Time */ - - struct timeval tval; - struct tm* timeinfo; - int rslt; - - /* rslt = gettimeofday(&tval, NULL); - if(rslt) { - // uint32_t msecs = millis(); - // _logOutput->printf(PSTR("[%9d.%03d]"), msecs / 1000, msecs % 1000); - } else */ - { - timeinfo = localtime(&tval.tv_sec); - } - - /* - time_t rawtime; - struct tm * timeinfo; - - time(&rawtime); - timeinfo = localtime(&rawtime); - - // strftime(buffer, sizeof(buffer), "%b %d %H:%M:%S.", timeinfo); - // Serial.println(buffer); -*/ - debugSendAnsiCode(F(TERM_COLOR_CYAN), _logOutput); - - if(timeinfo->tm_year >= 120) { - char buffer[24]; - strftime(buffer, sizeof(buffer), "[%b %d %H:%M:%S.", timeinfo); // Literal String - // strftime(buffer, sizeof(buffer), "[%H:%M:%S.", timeinfo); // Literal String - _logOutput->print(buffer); - _logOutput->printf(PSTR("%03lu]"), tval.tv_usec / 1000); - } else { - uint32_t msecs = millis(); - _logOutput->printf(PSTR("[%15d.%03d]"), msecs / 1000, msecs % 1000); - } -} - -static void debugPrintHaspMemory(int level, Print* _logOutput) -{ - size_t maxfree = haspDevice.get_free_max_block(); - size_t totalfree = haspDevice.get_free_heap(); - uint8_t frag = haspDevice.get_heap_fragmentation(); - - /* Print HASP Memory Info */ - if(debugAnsiCodes) { - if(maxfree > (1024u * 5) && (totalfree > 1024u * 6) && (frag <= 10)) - debugSendAnsiCode(F(TERM_COLOR_GREEN), _logOutput); - else if(maxfree > (1024u * 3) && (totalfree > 1024u * 5) && (frag <= 20)) - debugSendAnsiCode(F(TERM_COLOR_ORANGE), _logOutput); - else - debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); - } - _logOutput->printf(PSTR("[%5u/%5u%3u]"), maxfree, totalfree, frag); -} - -#if LV_MEM_CUSTOM == 0 -static void debugPrintLvglMemory(int level, Print* _logOutput) -{ - lv_mem_monitor_t mem_mon; - lv_mem_monitor(&mem_mon); - - /* Print LVGL Memory Info */ - if(debugAnsiCodes) { - if(mem_mon.free_biggest_size > (1024u * 2) && (mem_mon.free_size > 1024u * 2.5) && (mem_mon.frag_pct <= 10)) - debugSendAnsiCode(F(TERM_COLOR_GREEN), _logOutput); - else if(mem_mon.free_biggest_size > (1024u * 1) && (mem_mon.free_size > 1024u * 1.5) && - (mem_mon.frag_pct <= 25)) - debugSendAnsiCode(F(TERM_COLOR_ORANGE), _logOutput); - else - debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); - } - _logOutput->printf(PSTR("[%5u/%5u%3u]"), mem_mon.free_biggest_size, mem_mon.free_size, mem_mon.frag_pct); -} -#endif - -static void debugPrintPriority(int level, Print* _logOutput) -{ - // if(_logOutput == &syslogClient) { - // } - - switch(level) { - case LOG_LEVEL_FATAL ... LOG_LEVEL_ERROR: - debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); - break; - case LOG_LEVEL_WARNING: - debugSendAnsiCode(F(TERM_COLOR_YELLOW), _logOutput); - break; - case LOG_LEVEL_NOTICE: - debugSendAnsiCode(F(TERM_COLOR_WHITE), _logOutput); - break; - case LOG_LEVEL_TRACE: - debugSendAnsiCode(F(TERM_COLOR_GRAY), _logOutput); - break; - case LOG_LEVEL_VERBOSE: - debugSendAnsiCode(F(TERM_COLOR_CYAN), _logOutput); - break; - case LOG_LEVEL_DEBUG: - debugSendAnsiCode(F(TERM_COLOR_BLUE), _logOutput); - break; - case LOG_LEVEL_OUTPUT: - default: - debugSendAnsiCode(F(TERM_COLOR_RESET), _logOutput); - } -} - -static void debugPrintTag(uint8_t tag, Print* _logOutput) -{ - switch(tag) { - case TAG_MAIN: - _logOutput->print(F("MAIN")); - break; - - case TAG_HASP: - _logOutput->print(F("HASP")); - break; - - case TAG_DRVR: - _logOutput->print(F("DRVR")); - break; - - case TAG_ATTR: - _logOutput->print(F("ATTR")); - break; - - case TAG_MSGR: - _logOutput->print(F("MSGR")); - break; - - case TAG_OOBE: - _logOutput->print(F("OOBE")); - break; - case TAG_HAL: - _logOutput->print(F("HAL ")); - break; - - case TAG_DEBG: - _logOutput->print(F("DEBG")); - break; - case TAG_TELN: - _logOutput->print(F("TELN")); - break; - case TAG_SYSL: - _logOutput->print(F("SYSL")); - break; - case TAG_TASM: - _logOutput->print(F("TASM")); - break; - - case TAG_CONF: - _logOutput->print(F("CONF")); - break; - case TAG_GUI: - _logOutput->print(F("GUI ")); - break; - case TAG_TFT: - _logOutput->print(F("TFT ")); - break; - - case TAG_EPRM: - _logOutput->print(F("EPRM")); - break; - case TAG_FILE: - _logOutput->print(F("FILE")); - break; - case TAG_GPIO: - _logOutput->print(F("GPIO")); - break; - - case TAG_ETH: - _logOutput->print(F("ETH ")); - break; - case TAG_WIFI: - _logOutput->print(F("WIFI")); - break; - case TAG_HTTP: - _logOutput->print(F("HTTP")); - break; - case TAG_MDNS: - _logOutput->print(F("MDNS")); - break; - case TAG_MQTT: - _logOutput->print(F("MQTT")); - break; - case TAG_MQTT_PUB: - _logOutput->print(F("MQTT PUB")); - break; - case TAG_MQTT_RCV: - _logOutput->print(F("MQTT RCV")); - break; - - case TAG_OTA: - _logOutput->print(F("OTA")); - break; - case TAG_FWUP: - _logOutput->print(F("FWUP")); - break; - - case TAG_LVGL: - _logOutput->print(F("LVGL")); - break; - case TAG_LVFS: - _logOutput->print(F("LVFS")); - break; - case TAG_FONT: - _logOutput->print(F("FONT")); - break; - - default: - _logOutput->print(F("----")); - break; - } -} - -void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput) -{ -#if HASP_USE_SYSLOG > 0 - - if(_logOutput == syslogClient && syslogClient) { - if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) { - - // IETF Doc: https://tools.ietf.org/html/rfc5424 - The Syslog Protocol - // BSD Doc: https://tools.ietf.org/html/rfc3164 - The BSD syslog Protocol - - syslogClient->print(F("<")); - syslogClient->print((16 + debugSyslogFacility) * 8 + level); - syslogClient->print(F(">")); - - if(debugSyslogProtocol == SYSLOG_PROTO_IETF) { - syslogClient->print(F("1 - ")); - } - - syslogClient->print(haspDevice.get_hostname()); - syslogClient->print(F(" ")); - debugPrintTag(tag, _logOutput); - - if(debugSyslogProtocol == SYSLOG_PROTO_IETF) { - syslogClient->print(F(" - - - \xEF\xBB\xBF")); // include UTF-8 BOM - } else { - syslogClient->print(F(": ")); - } - - debugPrintHaspMemory(level, _logOutput); -#if LV_MEM_CUSTOM == 0 - debugPrintLvglMemory(level, _logOutput); -#endif - } - return; - } -#endif // HASP_USE_SYSLOG - - debugSendAnsiCode(F(TERM_CLEAR_LINE), _logOutput); - debugPrintTimestamp(level, _logOutput); - debugPrintHaspMemory(level, _logOutput); - -#if LV_MEM_CUSTOM == 0 - debugPrintLvglMemory(level, _logOutput); -#endif - - if(tag == TAG_MQTT_PUB && level == LOG_LEVEL_NOTICE) { - debugSendAnsiCode(F(TERM_COLOR_GREEN), _logOutput); - } else if(tag == TAG_MQTT_RCV && level == LOG_LEVEL_NOTICE) { - debugSendAnsiCode(F(TERM_COLOR_ORANGE), _logOutput); - } else { - debugPrintPriority(level, _logOutput); - } - - _logOutput->print(F(" ")); - debugPrintTag(tag, _logOutput); - _logOutput->print(F(": ")); -} - void debugPrintSuffix(uint8_t tag, int level, Print* _logOutput) { #if HASP_USE_SYSLOG > 0 @@ -660,37 +333,6 @@ void debugPreSetup(JsonObject settings) } } -#if LV_USE_LOG != 0 -void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr) -{ - /* used for duplicate detection */ - static uint32_t lastDbgLine; - static uint16_t lastDbgFreeMem; - - lv_mem_monitor_t mem_mon; - lv_mem_monitor(&mem_mon); - - /* Reduce the number of repeated debug message */ - if(line != lastDbgLine || mem_mon.free_biggest_size != lastDbgFreeMem) { - switch(level) { - case LV_LOG_LEVEL_TRACE: - LOG_VERBOSE(TAG_LVGL, descr); - break; - case LV_LOG_LEVEL_WARN: - LOG_WARNING(TAG_LVGL, descr); - break; - case LV_LOG_LEVEL_ERROR: - LOG_ERROR(TAG_LVGL, descr); - break; - default: - LOG_TRACE(TAG_LVGL, descr); - } - lastDbgLine = line; - lastDbgFreeMem = mem_mon.free_biggest_size; - } -} -#endif - void debugLoop(void) { int16_t keypress; @@ -748,12 +390,3 @@ void printLocalTime() } #endif } - -void debugEverySecond() -{ - if(debugTelePeriod > 0 && (millis() - debugLastMillis) >= debugTelePeriod * 1000) { - dispatch_output_statusupdate(NULL, NULL); - debugLastMillis = millis(); - } - // printLocalTime(); -} diff --git a/src/main_sdl2.cpp b/src/main_sdl2.cpp index cc181187..cb031b78 100644 --- a/src/main_sdl2.cpp +++ b/src/main_sdl2.cpp @@ -104,11 +104,6 @@ void InitializeConsoleOutput() } #endif -void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, const char* funcname, const char* descr) -{ - printf("%s %d\n", file, line); -} - void setup() { // Load Settings @@ -117,8 +112,8 @@ void setup() // debug_init(); // Initialize lvgl environment - lv_log_register_print_cb(debugLvglLogEvent); lv_init(); + lv_log_register_print_cb(debugLvglLogEvent); haspDevice.init(); // hardware setup haspDevice.show_info(); // debug info From b57a5a69316918c0b423b598aa565478b46e20d1 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 12 Mar 2021 04:14:21 +0100 Subject: [PATCH 187/236] Reduce verbosity --- src/mqtt/hasp_mqtt_paho_single.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index 5acf5de9..d65802d1 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -226,7 +226,7 @@ int mqttPublish(const char* topic, const char* payload, size_t len, bool retain) LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " '%s' => %s"), topic, payload); return MQTT_ERR_PUB_FAIL; } else { - LOG_TRACE(TAG_MQTT_PUB, F("'%s' => %s OK"), topic, payload); + // LOG_TRACE(TAG_MQTT_PUB, F("'%s' => %s OK"), topic, payload); return MQTT_ERR_OK; } } From 7a1afc5ac77868c5eabfa9241dae8dc6d21cf52a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 12 Mar 2021 22:29:14 +0100 Subject: [PATCH 188/236] Add ESP32-Touchdown --- user_setups/esp32/esp32-touchdown.ini | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 user_setups/esp32/esp32-touchdown.ini diff --git a/user_setups/esp32/esp32-touchdown.ini b/user_setups/esp32/esp32-touchdown.ini new file mode 100644 index 00000000..0b5bd792 --- /dev/null +++ b/user_setups/esp32/esp32-touchdown.ini @@ -0,0 +1,46 @@ +[env:esp32dev-touchdown] +extends = esp32 +board = esp32dev + +build_flags = + ${env.build_flags} + ${esp32.build_flags} + ${esp32.vspi} ; Use VSPI hardware SPI bus + +;region -- TFT_eSPI build options ------------------------ + -D USER_SETUP_LOADED=1 + -D ILI9488_DRIVER=1 + -D TFT_ROTATION=0 ; 0=0, 1=90, 2=180 or 3=270 degree + -D TFT_WIDTH=320 + -D TFT_HEIGHT=480 + -D TFT_CS=15 ;// Chip select control pin + -D TFT_DC=2 ;// Data Command control pin + -D TFT_RST=4 ;// Reset pin (could connect to RST pin) + -D TFT_BCKL=5 ;None, configurable via web UI (e.g. 2 for D4) + -D SUPPORT_TRANSACTIONS + -D TOUCH_DRIVER=6336 ; XPT2606 Resistive touch panel driver + -D TOUCH_SDA=21 + -D TOUCH_SCL=22 + -D TOUCH_IRQ=27 ; not connected + -D TOUCH_RST=-1 ; not used, connected to 3.3V + -D TOUCH_FREQUENCY=400000 + -D SPI_FREQUENCY=27000000 + -D SPI_READ_FREQUENCY=16000000 +;endregion + +; GPIO18 -> SPI Clock +; GPIO23 -> SDI (MOSI) + +; -- Debugging options ----------------------------- +; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG + +;region -- Library options ------------------------------- +lib_deps = + ${env.lib_deps} + ${esp32.lib_deps} + git+https://github.com/aselectroworks/Arduino-FT6336U.git + +lib_ignore = + ${env.lib_ignore} + ${esp32.lib_ignore} +;endregion \ No newline at end of file From 3bf531db7cb82150abcaf233e1c74219bffbd181 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 14 Mar 2021 00:04:52 +0100 Subject: [PATCH 189/236] Temporarily disable Syslog --- src/hasp_debug.cpp | 60 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 72b68333..2782dcdb 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -14,7 +14,7 @@ #if(!defined(WINDOWS)) && (!defined(POSIX)) #include "ArduinoLog.h" -#define debug_print(io, ...) io->print(__VA_ARGS__) +#define debug_print(io, ...) io->printf(__VA_ARGS__) #define debug_newline(io) io->println() bool debugSerialStarted = false; @@ -33,7 +33,11 @@ bool debugAnsiCodes = true; inline void debugSendAnsiCode(const __FlashStringHelper* code, Print* _logOutput) { +#ifdef ARDUINO + if(debugAnsiCodes) _logOutput->print(code); +#else if(debugAnsiCodes) debug_print(_logOutput, code); +#endif } void debug_timestamp() @@ -64,10 +68,21 @@ static void debugPrintTimestamp(int level, Print* _logOutput) char buffer[24]; strftime(buffer, sizeof(buffer), "[%b %d %H:%M:%S", timeinfo); // Literal String // strftime(buffer, sizeof(buffer), "[%H:%M:%S.", timeinfo); // Literal String + +#ifdef ARDUINO + _logOutput->printf(PSTR("%03lu]"), curTime.tv_usec / 1000); +#else debug_print(_logOutput, PSTR("%s.%03lu]"), buffer, curTime.tv_usec / 1000); +#endif + } else { + uint32_t msecs = millis(); +#ifdef ARDUINO + _logOutput->printf(PSTR("[%15d.%03d]"), msecs / 1000, msecs % 1000); +#else debug_print(_logOutput, PSTR("[%15d.%03d]"), msecs / 1000, msecs % 1000); +#endif } } @@ -161,18 +176,23 @@ void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, co void debugPrintHaspHeader(Print* output) { // if(debugAnsiCodes) debug_print(output,TERM_COLOR_YELLOW); - debug_newline(output); - debug_print(output, F("" - " _____ _____ _____ _____\r\n" - " | | | _ | __| _ |\r\n" - " | | |__ | __|\r\n" - " |__|__|__|__|_____|__|\r\n" - " Home Automation Switch Plate\r\n" - " Open Hardware edition v")); + + // debug_newline(output); + // debug_print(output, F("" + // " _____ _____ _____ _____\r\n" + // " | | | _ | __| _ |\r\n" + // " | | |__ | __|\r\n" + // " |__|__|__|__|_____|__|\r\n" + // " Home Automation Switch Plate\r\n" + // " Open Hardware edition v")); char buffer[32]; haspGetVersion(buffer, sizeof(buffer)); +#ifdef ARDUINO + output->println(buffer); +#else debug_print(output, buffer); debug_newline(output); +#endif } void debug_get_tag(uint8_t tag, char* buffer) @@ -285,6 +305,7 @@ void debug_get_tag(uint8_t tag, char* buffer) static void debugPrintHaspMemory(int level, Print* _logOutput) { +#ifdef ARDUINO size_t maxfree = haspDevice.get_free_max_block(); size_t totalfree = haspDevice.get_free_heap(); uint8_t frag = haspDevice.get_heap_fragmentation(); @@ -298,7 +319,8 @@ static void debugPrintHaspMemory(int level, Print* _logOutput) else debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); } - debug_print(_logOutput, PSTR("[%5u/%5u%3u]"), maxfree, totalfree, frag); + _logOutput->printf(PSTR("[%5u/%5u%3u]"), maxfree, totalfree, frag); +#endif } static void debugPrintLvglMemory(int level, Print* _logOutput) @@ -317,8 +339,14 @@ static void debugPrintLvglMemory(int level, Print* _logOutput) else debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); } + +#ifdef ARDUINO + _logOutput->printf(PSTR("[%5u/%5u%3u]"), mem_mon.free_biggest_size, mem_mon.free_size, mem_mon.frag_pct); +#else debug_print(_logOutput, PSTR("[%5u/%5u%3u]"), mem_mon.free_biggest_size, mem_mon.free_size, mem_mon.frag_pct); -#endif +#endif // ARDUINO + +#endif // LV_MEM_CUSTOM } static void debugPrintPriority(int level, Print* _logOutput) @@ -355,7 +383,7 @@ void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput) { char buffer[10]; -#if HASP_USE_SYSLOG > 0 +#if 0 && HASP_USE_SYSLOG > 0 if(_logOutput == syslogClient && syslogClient) { if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) { @@ -381,9 +409,7 @@ void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput) } debugPrintHaspMemory(level, _logOutput); -#if LV_MEM_CUSTOM == 0 debugPrintLvglMemory(level, _logOutput); -#endif } return; } @@ -403,5 +429,9 @@ void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput) } debug_get_tag(tag, buffer); - debug_print(_logOutput, F(" %s: "), buffer); +#ifdef ARDUINO + _logOutput->printf(PSTR(" %s: "), buffer); +#else + debug_print(_logOutput, PSTR(" %s: "), buffer); +#endif } \ No newline at end of file From 228148b92db13cf02b39f33f251210cda1457867 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 14 Mar 2021 00:05:10 +0100 Subject: [PATCH 190/236] Update config --- user_setups/esp32/esp32-touchdown.ini | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/user_setups/esp32/esp32-touchdown.ini b/user_setups/esp32/esp32-touchdown.ini index 0b5bd792..61ae1322 100644 --- a/user_setups/esp32/esp32-touchdown.ini +++ b/user_setups/esp32/esp32-touchdown.ini @@ -1,4 +1,10 @@ -[env:esp32dev-touchdown] +;***************************************************; +; ESP32-Touchdown custom PCB with 3.5" TFT ; +; - ili9488 TFT SPI 4-WIRE ; +; - ft6336 touch controller ; +;***************************************************; + +[env:esp32-touchdown] extends = esp32 board = esp32dev @@ -16,21 +22,18 @@ build_flags = -D TFT_CS=15 ;// Chip select control pin -D TFT_DC=2 ;// Data Command control pin -D TFT_RST=4 ;// Reset pin (could connect to RST pin) - -D TFT_BCKL=5 ;None, configurable via web UI (e.g. 2 for D4) + -D TFT_BCKL=32 ;None, configurable via web UI (e.g. 2 for D4) -D SUPPORT_TRANSACTIONS - -D TOUCH_DRIVER=6336 ; XPT2606 Resistive touch panel driver + -D TOUCH_DRIVER=6336 ; FT6336 Capacitive touch panel driver -D TOUCH_SDA=21 -D TOUCH_SCL=22 - -D TOUCH_IRQ=27 ; not connected - -D TOUCH_RST=-1 ; not used, connected to 3.3V + -D TOUCH_IRQ=27 + -D TOUCH_RST=-1 ; not used -D TOUCH_FREQUENCY=400000 -D SPI_FREQUENCY=27000000 -D SPI_READ_FREQUENCY=16000000 ;endregion -; GPIO18 -> SPI Clock -; GPIO23 -> SDI (MOSI) - ; -- Debugging options ----------------------------- ; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG From 86fb12a752f53e8aeb2327d87b5a8e76791f73dc Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 14 Mar 2021 18:15:08 +0100 Subject: [PATCH 191/236] Update build.yaml --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 47de5a2e..b76a7530 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,6 @@ name: Build 0.4.0-dev branch -on: [push] +on: [push, workflow_dispatch] jobs: build: From edfaae429909b2897a0f42e5b4c656c012240608 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 15 Mar 2021 23:47:23 +0100 Subject: [PATCH 192/236] Additional logging --- lib/lv_lib_zifont/README.md | 2 +- lib/lv_lib_zifont/lv_zifont.cpp | 93 +++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 34 deletions(-) diff --git a/lib/lv_lib_zifont/README.md b/lib/lv_lib_zifont/README.md index 380987b3..1b374cd1 100644 --- a/lib/lv_lib_zifont/README.md +++ b/lib/lv_lib_zifont/README.md @@ -15,7 +15,7 @@ Obtain or create a font file: lv_zifont_init(); static lv_font_t font1; - lv_zifont_font_init(&font1, "./notosans_32.zi", 0); + lv_zifont_font_init(&font1, "/notosans_32.zi", 0); static lv_style_t ft_style; lv_style_copy(&ft_style, &lv_style_plain); diff --git a/lib/lv_lib_zifont/lv_zifont.cpp b/lib/lv_lib_zifont/lv_zifont.cpp index 29955d7a..996313ff 100644 --- a/lib/lv_lib_zifont/lv_zifont.cpp +++ b/lib/lv_lib_zifont/lv_zifont.cpp @@ -2,7 +2,7 @@ * INCLUDES *********************/ -#if !(defined(WINDOWS)||defined(POSIX)) +#if !(defined(WINDOWS) || defined(POSIX)) #include #include @@ -55,8 +55,8 @@ enum zifont_codepage_t8_t { ASCII = 0x01, ISO_8859_1 = 0x03, UTF_8 = 0x18 }; /********************** * STATIC PROTOTYPES **********************/ -const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t unicode_letter); -bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, +const uint8_t* IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t* font, uint32_t unicode_letter); +bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t* font, lv_font_glyph_dsc_t* dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next); /********************** @@ -68,12 +68,12 @@ lv_zifont_char_t lastCharInfo; // Holds the last Glyph DSC #if ESP32 // static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache -#define CHAR_CACHE_SIZE 224 +#define CHAR_CACHE_SIZE 95 #else #define CHAR_CACHE_SIZE 95 // static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache #endif -static uint8_t * charBitmap_p; +static uint8_t* charBitmap_p; /********************** * MACROS @@ -83,18 +83,19 @@ static uint8_t * charBitmap_p; * GLOBAL FUNCTIONS **********************/ -static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos); -static void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos); +static void IRAM_ATTR blackAdd(uint8_t* charBitmap_p, uint16_t pos); +static void IRAM_ATTR colorsAdd(uint8_t* charBitmap_p, uint8_t color1, uint16_t pos); // static uint16_t unicode2codepoint(uint32_t unicode, uint8_t codepage); // static void printBuffer(uint8_t * charBitmap_p, uint8_t w, uint8_t h); int lv_zifont_init(void) { + FS.begin(true); // charBitmap_p = (uint8_t *)lv_mem_alloc(32 * 32); return LV_RES_OK; // OK } -static inline bool openFont(File & file, const char * filename) +static inline bool openFont(File& file, const char* filename) { if(*filename != '/') return false; @@ -103,6 +104,7 @@ static inline bool openFont(File & file, const char * filename) LOG_ERROR(TAG_FONT, F("Opening font: %s"), filename); return false; } + LOG_TRACE(TAG_FONT, F("Opening font: %s"), filename); return file; } @@ -110,7 +112,7 @@ static inline bool initCharacterFrame(size_t size) { if(size > _lv_mem_get_size(charBitmap_p)) { lv_mem_free(charBitmap_p); - charBitmap_p = (uint8_t *)lv_mem_alloc(size); + charBitmap_p = (uint8_t*)lv_mem_alloc(size); LOG_WARNING(TAG_FONT, F("Pixel buffer is %d bytes"), _lv_mem_get_size(charBitmap_p)); } @@ -123,29 +125,33 @@ static inline bool initCharacterFrame(size_t size) } } -int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size) +int lv_zifont_font_init(lv_font_t** font, const char* font_path, uint16_t size) { charInBuffer = 0; // invalidate any previous cache if(!*font) { - *font = (lv_font_t *)lv_mem_alloc(sizeof(lv_font_t)); + LOG_TRACE(TAG_FONT, F("File %s - Line %d - init font"), __FILE__, __LINE__); + *font = (lv_font_t*)lv_mem_alloc(sizeof(lv_font_t)); LV_ASSERT_MEM(*font); _lv_memset_00(*font, sizeof(lv_font_t)); // lv_mem_alloc might be dirty } - lv_font_fmt_zifont_dsc_t * dsc; + lv_font_fmt_zifont_dsc_t* dsc; if(!(*font)->dsc) { - dsc = (lv_font_fmt_zifont_dsc_t *)lv_mem_alloc(sizeof(lv_font_fmt_zifont_dsc_t)); + LOG_TRACE(TAG_FONT, F("File %s - Line %d - init font dsc"), __FILE__, __LINE__); + dsc = (lv_font_fmt_zifont_dsc_t*)lv_mem_alloc(sizeof(lv_font_fmt_zifont_dsc_t)); LV_ASSERT_MEM(dsc); _lv_memset_00(dsc, sizeof(lv_font_fmt_zifont_dsc_t)); // lv_mem_alloc might be dirty + dsc->ascii_glyph_dsc = NULL; } else { - dsc = (lv_font_fmt_zifont_dsc_t *)(*font)->dsc; + LOG_TRACE(TAG_FONT, F("File %s - Line %d - reuse font dsc"), __FILE__, __LINE__); + dsc = (lv_font_fmt_zifont_dsc_t*)(*font)->dsc; } LV_ASSERT_MEM(dsc); if(!dsc) return ZIFONT_ERROR_OUT_OF_MEMORY; /* Initialize Last Glyph DSC */ - dsc->last_glyph_dsc = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t)); + dsc->last_glyph_dsc = (lv_zifont_char_t*)lv_mem_alloc(sizeof(lv_zifont_char_t)); _lv_memset_00(dsc->last_glyph_dsc, sizeof(lv_zifont_char_t)); // lv_mem_alloc might be dirty if(dsc->last_glyph_dsc == NULL) return ZIFONT_ERROR_OUT_OF_MEMORY; @@ -158,7 +164,9 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size /* Read file header as dsc */ zi_font_header_t header; - size_t readSize = file.readBytes((char *)&header, sizeof(zi_font_header_t)); + size_t readSize = file.readBytes((char*)&header, sizeof(zi_font_header_t)); + + LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__); /* Check that we read the correct size */ if(readSize != sizeof(zi_font_header_t)) { @@ -167,6 +175,8 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size return ZIFONT_ERROR_READING_DATA; } + LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__); + /* Check ziFile Header Format */ if(header.Password != 4 || header.Version != 5) { LOG_ERROR(TAG_FONT, F("Unknown font file format")); @@ -174,6 +184,8 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size return ZIFONT_ERROR_UNKNOWN_HEADER; } + LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__); + dsc->CharHeight = header.CharHeight; dsc->CharWidth = header.CharWidth; dsc->Maximumnumchars = header.Maximumnumchars; @@ -182,20 +194,33 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size dsc->Startdataaddress = header.Startdataaddress + header.Descriptionlength; dsc->Fontdataadd8byte = header.Fontdataadd8byte; - if(!dsc->ascii_glyph_dsc) { - dsc->ascii_glyph_dsc = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE); + LOG_TRACE(TAG_FONT, F("File %s - Line %d - %d"), __FILE__, __LINE__, dsc->ascii_glyph_dsc); + + if(dsc->ascii_glyph_dsc == NULL) { + LOG_TRACE(TAG_FONT, F("File %s - Line %d - ascii_glyph_dsc init"), __FILE__, __LINE__); + dsc->ascii_glyph_dsc = (lv_zifont_char_t*)lv_mem_alloc(sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE); LV_ASSERT_MEM(dsc->ascii_glyph_dsc); _lv_memset_00(dsc->ascii_glyph_dsc, sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE); // lv_mem_alloc might be dirty } + + LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__); + if(dsc->ascii_glyph_dsc == NULL) { file.close(); return ZIFONT_ERROR_OUT_OF_MEMORY; } + LOG_TRACE(TAG_FONT, F("File %s - Line %d - Seerkset: %d"), __FILE__, __LINE__, dsc->Startdataaddress); + /* read charmap into cache */ file.seek(0 * sizeof(zi_font_header_t) + dsc->Startdataaddress, SeekSet); + + LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__); + //* read and fill charmap cache - readSize = file.readBytes((char *)dsc->ascii_glyph_dsc, sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE); + readSize = file.readBytes((char*)dsc->ascii_glyph_dsc, sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE); + + LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__); //* Check that we read the correct size if(readSize != sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE) { @@ -236,9 +261,11 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size /* header data struct */ /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */ (*font)->subpx = 0; - if((*font)->user_data != (char *)font_path) { + LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__); + + if((*font)->user_data != (char*)font_path) { if((*font)->user_data) free((*font)->user_data); - (*font)->user_data = (char *)font_path; + (*font)->user_data = (char*)font_path; } return ZIFONT_NO_ERROR; @@ -254,7 +281,7 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size * @param unicode_letter an unicode letter which bitmap should be get * @return pointer to the bitmap or NULL if not found */ -const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t unicode_letter) +const uint8_t* IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t* font, uint32_t unicode_letter) { /* Bitmap still in buffer */ if(charInBuffer == unicode_letter && charBitmap_p) { @@ -263,8 +290,8 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, return charBitmap_p; } - lv_font_fmt_zifont_dsc_t * fdsc = (lv_font_fmt_zifont_dsc_t *)font->dsc; /* header data struct */ - lv_zifont_char_t * charInfo; + lv_font_fmt_zifont_dsc_t* fdsc = (lv_font_fmt_zifont_dsc_t*)font->dsc; /* header data struct */ + lv_zifont_char_t* charInfo; /* Space */ if(unicode_letter == 0x20) { @@ -289,7 +316,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, charmap_position = 25 + sizeof(zi_font_header_t); glyphID = unicode_letter - 0xf000; // start of fontawesome } else { - strcpy(filename, (char *)font->user_data); + strcpy(filename, (char*)font->user_data); charmap_position = fdsc->Startdataaddress; glyphID = unicode_letter - 0x20; // simple unicode to ascii - space is charNum=0 } @@ -303,11 +330,11 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, } else { Serial.print("%"); /* Read Character Table */ - charInfo = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t)); + charInfo = (lv_zifont_char_t*)lv_mem_alloc(sizeof(lv_zifont_char_t)); // lv_memset(charInfo, 0x00, sizeof(lv_zifont_char_t)); // lv_mem_alloc might be dirty uint32_t char_position = glyphID * sizeof(lv_zifont_char_t) + charmap_position; file.seek(char_position, SeekSet); - size_t readSize = file.readBytes((char *)charInfo, sizeof(lv_zifont_char_t)); + size_t readSize = file.readBytes((char*)charInfo, sizeof(lv_zifont_char_t)); /* Check that we read the correct size */ if(readSize != sizeof(lv_zifont_char_t)) { @@ -441,7 +468,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, * @return true: descriptor is successfully loaded into `dsc_out`. * false: the letter was not found, no data is loaded to `dsc_out` */ -bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, +bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t* font, lv_font_glyph_dsc_t* dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { /* Only ascii characteres supported for now */ @@ -452,7 +479,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_ // if(unicode_letter > 0xff) Serial.printf("Char# %u\n", unicode_letter); // ulong startMillis = millis(); - lv_font_fmt_zifont_dsc_t * fdsc = (lv_font_fmt_zifont_dsc_t *)font->dsc; /* header data struct */ + lv_font_fmt_zifont_dsc_t* fdsc = (lv_font_fmt_zifont_dsc_t*)font->dsc; /* header data struct */ uint16_t glyphID; File file; @@ -482,7 +509,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_ snprintf_P(filename, sizeof(filename), PSTR("/fontawesome%u.zi"), fdsc->CharHeight); if(!openFont(file, filename)) return false; } else { - if(!openFont(file, (char *)font->user_data)) return false; + if(!openFont(file, (char*)font->user_data)) return false; } /* read 10 bytes charmap */ @@ -490,7 +517,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_ lv_zifont_char_t myCharIndex; uint32_t char_position = glyphID * sizeof(lv_zifont_char_t) + charmap_position; file.seek(char_position, SeekSet); - size_t readSize = file.readBytes((char *)&myCharIndex, sizeof(lv_zifont_char_t)); + size_t readSize = file.readBytes((char*)&myCharIndex, sizeof(lv_zifont_char_t)); file.close(); /* Check that we read the correct size */ @@ -536,7 +563,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_ return true; } -static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos) +static void IRAM_ATTR blackAdd(uint8_t* charBitmap_p, uint16_t pos) { uint8_t col = pos & 0x0001; // remainder uint16_t map_p = pos >> 1; // devide by 2 @@ -548,7 +575,7 @@ static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos) } } -static inline void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos) +static inline void IRAM_ATTR colorsAdd(uint8_t* charBitmap_p, uint8_t color1, uint16_t pos) { uint32_t col = pos & 0x0001; // remainder uint32_t map_p = pos >> 1; // devide by 2 From 74a1c34f90641986184d94ce3bbf91e2b2de282e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 00:52:36 +0100 Subject: [PATCH 193/236] Use custom logging function again --- include/hasp_macro.h | 16 +++++++--------- include/lv_conf_v7.h | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/hasp_macro.h b/include/hasp_macro.h index f9199099..d3b6bdcc 100644 --- a/include/hasp_macro.h +++ b/include/hasp_macro.h @@ -7,16 +7,14 @@ #define LOG_OUTPUT(...) Log.output(...) #if HASP_LOG_LEVEL > LOG_LEVEL_FATAL -#define LOG_FATAL(...) \ - Log.fatal(__VA_ARGS__); \ - while (true) \ - { \ +#define LOG_FATAL(...) \ + Log.fatal(__VA_ARGS__); \ + while(true) { \ } #else -#define LOG_FATAL(...) \ - do \ - { \ - } while (0) +#define LOG_FATAL(...) \ + do { \ + } while(0) #endif #if HASP_LOG_LEVEL > LOG_LEVEL_ALERT @@ -69,4 +67,4 @@ #endif -#endif +#endif // HASP_MACRO_H diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index 1f659742..83012a90 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -289,7 +289,7 @@ typedef void* lv_indev_drv_user_data_t; /*Type of user data in the in /* 1: Print the log with 'printf'; * 0: user need to register a callback with `lv_log_register_print_cb`*/ -# define LV_LOG_PRINTF 1 +# define LV_LOG_PRINTF 0 #endif /*LV_USE_LOG*/ /*================= From dfb3c1323825812c9d70ac7998963579244e993c Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 00:52:52 +0100 Subject: [PATCH 194/236] Use custom logging function again --- src/hasp_gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 51942d63..1c3b9ea8 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -102,7 +102,7 @@ void guiSetup(void) { // Register logger to capture lvgl_init output LOG_TRACE(TAG_LVGL, F(D_SERVICE_STARTING)); -#if LV_USE_LOG != 0 && defined(ARDUINO) +#if LV_USE_LOG != 0 lv_log_register_print_cb(debugLvglLogEvent); #endif From 984f8d918da56b18db2f987c95048b53c5568207 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 15:27:19 +0100 Subject: [PATCH 195/236] Fix for zifont crash --- lib/lv_lib_zifont/lv_zifont.cpp | 5 +++-- src/hasp/hasp.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/lv_lib_zifont/lv_zifont.cpp b/lib/lv_lib_zifont/lv_zifont.cpp index 996313ff..bc9893af 100644 --- a/lib/lv_lib_zifont/lv_zifont.cpp +++ b/lib/lv_lib_zifont/lv_zifont.cpp @@ -68,7 +68,7 @@ lv_zifont_char_t lastCharInfo; // Holds the last Glyph DSC #if ESP32 // static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache -#define CHAR_CACHE_SIZE 95 +#define CHAR_CACHE_SIZE 224 #else #define CHAR_CACHE_SIZE 95 // static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache @@ -104,7 +104,7 @@ static inline bool openFont(File& file, const char* filename) LOG_ERROR(TAG_FONT, F("Opening font: %s"), filename); return false; } - LOG_TRACE(TAG_FONT, F("Opening font: %s"), filename); + // LOG_TRACE(TAG_FONT, F("Opening font: %s"), filename); return file; } @@ -128,6 +128,7 @@ static inline bool initCharacterFrame(size_t size) int lv_zifont_font_init(lv_font_t** font, const char* font_path, uint16_t size) { charInBuffer = 0; // invalidate any previous cache + LOG_TRACE(TAG_FONT, F("File %s - Line %d - lv_zifont_font_init"), __FILE__, __LINE__); if(!*font) { LOG_TRACE(TAG_FONT, F("File %s - Line %d - init font"), __FILE__, __LINE__); diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index eaecd32d..d980a743 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -93,8 +93,8 @@ lv_obj_t* kb; // lv_font_t * defaultFont; lv_obj_t* pages[HASP_NUM_PAGES]; -static lv_font_t* haspFonts[4] = {nullptr, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, - LV_THEME_DEFAULT_FONT_TITLE}; +static lv_font_t* haspFonts[4] = {LV_THEME_DEFAULT_FONT_SMALL, LV_THEME_DEFAULT_FONT_NORMAL, + LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE}; uint8_t current_page = 1; /** @@ -365,13 +365,16 @@ void haspSetup(void) #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + lv_font_t* hasp_font = nullptr; // required or font init will crash lv_zifont_init(); - if(lv_zifont_font_init(&haspFonts[1], haspZiFontPath, 32) != 0) { + // WARNING: hasp_font needs to be null ! + if(lv_zifont_font_init(&hasp_font, haspZiFontPath, 32) != 0) { LOG_ERROR(TAG_HASP, F("Failed to set font to %s"), haspZiFontPath); haspFonts[1] = LV_FONT_DEFAULT; } else { // defaultFont = haspFonts[0]; + haspFonts[1] = hasp_font; // save it } #endif #endif From 66efad3aa8e850f9647c83e76273db508c541bfb Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 16:02:28 +0100 Subject: [PATCH 196/236] Fix ziFont for ESP8266 --- lib/lv_lib_zifont/lv_zifont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lv_lib_zifont/lv_zifont.cpp b/lib/lv_lib_zifont/lv_zifont.cpp index bc9893af..176c26a4 100644 --- a/lib/lv_lib_zifont/lv_zifont.cpp +++ b/lib/lv_lib_zifont/lv_zifont.cpp @@ -90,7 +90,7 @@ static void IRAM_ATTR colorsAdd(uint8_t* charBitmap_p, uint8_t color1, uint16_t int lv_zifont_init(void) { - FS.begin(true); + // FS.begin(true); // charBitmap_p = (uint8_t *)lv_mem_alloc(32 * 32); return LV_RES_OK; // OK } From 793682161c5370df40398c4d170640c7f819ed0c Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 17:37:37 +0100 Subject: [PATCH 197/236] Make driver pointers static for v8 --- lib/lv_fs_if/lv_fs_fatfs.c | 170 ++++++++++++++++++---------------- lib/lv_fs_if/lv_fs_pc.c | 2 +- lib/lv_fs_if/lv_fs_spiffs.cpp | 156 +++++++++++++++---------------- src/hasp_gui.cpp | 4 +- 4 files changed, 171 insertions(+), 161 deletions(-) diff --git a/lib/lv_fs_if/lv_fs_fatfs.c b/lib/lv_fs_if/lv_fs_fatfs.c index 4279b2b7..3448b707 100644 --- a/lib/lv_fs_if/lv_fs_fatfs.c +++ b/lib/lv_fs_if/lv_fs_fatfs.c @@ -21,30 +21,30 @@ **********************/ /* Create a type to store the required data about your file.*/ -typedef FIL file_t; +typedef FIL file_t; /*Similarly to `file_t` create a type for directory reading too */ -typedef DIR dir_t; +typedef DIR dir_t; /********************** * STATIC PROTOTYPES **********************/ static void fs_init(void); -static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode); -static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p); -static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br); -static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw); -static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos); -static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p); -static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p); -static lv_fs_res_t fs_remove (lv_fs_drv_t * drv, const char *path); -static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p); -static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const char * newname); -static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p); -static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *path); -static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * dir_p, char *fn); -static lv_fs_res_t fs_dir_close (lv_fs_drv_t * drv, void * dir_p); +static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode); +static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p); +static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br); +static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw); +static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos); +static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p); +static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p); +static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path); +static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p); +static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname); +static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p); +static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path); +static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn); +static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p); /********************** * STATIC VARIABLES @@ -70,28 +70,28 @@ void lv_fs_if_fatfs_init(void) *--------------------------------------------------*/ /* Add a simple drive to open images */ - lv_fs_drv_t fs_drv; /*A driver descriptor*/ - lv_fs_drv_init(&fs_drv); + static lv_fs_drv_t fs_drv; /*A driver descriptor*/ + lv_fs_drv_init(&fs_drv); /*Set up fields...*/ - fs_drv.file_size = sizeof(file_t); - fs_drv.letter = LV_FS_IF_FATFS; - fs_drv.open_cb = fs_open; - fs_drv.close_cb = fs_close; - fs_drv.read_cb = fs_read; - fs_drv.write_cb = fs_write; - fs_drv.seek_cb = fs_seek; - fs_drv.tell_cb = fs_tell; + fs_drv.file_size = sizeof(file_t); + fs_drv.letter = LV_FS_IF_FATFS; + fs_drv.open_cb = fs_open; + fs_drv.close_cb = fs_close; + fs_drv.read_cb = fs_read; + fs_drv.write_cb = fs_write; + fs_drv.seek_cb = fs_seek; + fs_drv.tell_cb = fs_tell; fs_drv.free_space_cb = fs_free; - fs_drv.size_cb = fs_size; - fs_drv.remove_cb = fs_remove; - fs_drv.rename_cb = fs_rename; - fs_drv.trunc_cb = fs_trunc; + fs_drv.size_cb = fs_size; + fs_drv.remove_cb = fs_remove; + fs_drv.rename_cb = fs_rename; + fs_drv.trunc_cb = fs_trunc; - fs_drv.rddir_size = sizeof(dir_t); + fs_drv.rddir_size = sizeof(dir_t); fs_drv.dir_close_cb = fs_dir_close; - fs_drv.dir_open_cb = fs_dir_open; - fs_drv.dir_read_cb = fs_dir_read; + fs_drv.dir_open_cb = fs_dir_open; + fs_drv.dir_read_cb = fs_dir_read; lv_fs_drv_register(&fs_drv); } @@ -115,25 +115,27 @@ static void fs_init(void) * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) +static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode) { uint8_t flags = 0; - if(mode == LV_FS_MODE_WR) flags = FA_WRITE | FA_OPEN_ALWAYS; - else if(mode == LV_FS_MODE_RD) flags = FA_READ; - else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = FA_READ | FA_WRITE | FA_OPEN_ALWAYS; + if(mode == LV_FS_MODE_WR) + flags = FA_WRITE | FA_OPEN_ALWAYS; + else if(mode == LV_FS_MODE_RD) + flags = FA_READ; + else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) + flags = FA_READ | FA_WRITE | FA_OPEN_ALWAYS; FRESULT res = f_open(file_p, path, flags); if(res == FR_OK) { - f_lseek(file_p, 0); - return LV_FS_RES_OK; + f_lseek(file_p, 0); + return LV_FS_RES_OK; } else { - return LV_FS_RES_UNKNOWN; + return LV_FS_RES_UNKNOWN; } } - /** * Close an opened file * @param drv pointer to a driver where this function belongs @@ -141,7 +143,7 @@ static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p) +static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p) { f_close(file_p); return LV_FS_RES_OK; @@ -157,11 +159,13 @@ static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br) +static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br) { FRESULT res = f_read(file_p, buf, btr, (UINT*)br); - if(res == FR_OK) return LV_FS_RES_OK; - else return LV_FS_RES_UNKNOWN; + if(res == FR_OK) + return LV_FS_RES_OK; + else + return LV_FS_RES_UNKNOWN; } /** @@ -173,11 +177,13 @@ static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32 * @param br the number of real written bytes (Bytes Written). NULL if unused. * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw) +static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw) { - FRESULT res = f_write(file_p, buf, btw, (UINT*)bw); - if(res == FR_OK) return LV_FS_RES_OK; - else return LV_FS_RES_UNKNOWN; + FRESULT res = f_write(file_p, buf, btw, (UINT*)bw); + if(res == FR_OK) + return LV_FS_RES_OK; + else + return LV_FS_RES_UNKNOWN; } /** @@ -188,7 +194,7 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos) +static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos) { f_lseek(file_p, pos); return LV_FS_RES_OK; @@ -201,9 +207,9 @@ static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos) * @param size pointer to a variable to store the size * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p) +static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p) { - (*size_p) = f_size(((file_t *)file_p)); + (*size_p) = f_size(((file_t*)file_p)); return LV_FS_RES_OK; } @@ -215,9 +221,9 @@ static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) +static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p) { - *pos_p = f_tell(((file_t *)file_p)); + *pos_p = f_tell(((file_t*)file_p)); return LV_FS_RES_OK; } @@ -227,7 +233,7 @@ static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) * @param path path of the file to delete * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_remove (lv_fs_drv_t * drv, const char *path) +static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path) { lv_fs_res_t res = LV_FS_RES_NOT_IMP; @@ -243,9 +249,9 @@ static lv_fs_res_t fs_remove (lv_fs_drv_t * drv, const char *path) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p) +static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p) { - f_sync(file_p); /*If not syncronized fclose can write the truncated part*/ + f_sync(file_p); /*If not syncronized fclose can write the truncated part*/ f_truncate(file_p); return LV_FS_RES_OK; } @@ -257,13 +263,15 @@ static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p) * @param newname path with the new name * @return LV_FS_RES_OK or any error from 'fs_res_t' */ -static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const char * newname) +static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname) { - + FRESULT res = f_rename(oldname, newname); - if(res == FR_OK) return LV_FS_RES_OK; - else return LV_FS_RES_UNKNOWN; + if(res == FR_OK) + return LV_FS_RES_OK; + else + return LV_FS_RES_UNKNOWN; } /** @@ -274,7 +282,7 @@ static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const cha * @param free_p pointer to store the free size [kB] * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p) +static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p) { lv_fs_res_t res = LV_FS_RES_NOT_IMP; @@ -290,11 +298,13 @@ static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fr * @param path path to a directory * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *path) +static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path) { FRESULT res = f_opendir(dir_p, path); - if(res == FR_OK) return LV_FS_RES_OK; - else return LV_FS_RES_UNKNOWN; + if(res == FR_OK) + return LV_FS_RES_OK; + else + return LV_FS_RES_UNKNOWN; } /** @@ -305,21 +315,21 @@ static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *pat * @param fn pointer to a buffer to store the filename * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * dir_p, char *fn) +static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn) { - FRESULT res; - FILINFO fno; - fn[0] = '\0'; + FRESULT res; + FILINFO fno; + fn[0] = '\0'; do { - res = f_readdir(dir_p, &fno); - if(res != FR_OK) return LV_FS_RES_UNKNOWN; + res = f_readdir(dir_p, &fno); + if(res != FR_OK) return LV_FS_RES_UNKNOWN; - if(fno.fattrib & AM_DIR) { - fn[0] = '/'; - strcpy(&fn[1], fno.fname); - } - else strcpy(fn, fno.fname); + if(fno.fattrib & AM_DIR) { + fn[0] = '/'; + strcpy(&fn[1], fno.fname); + } else + strcpy(fn, fno.fname); } while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0); @@ -332,11 +342,11 @@ static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * dir_p, char *fn) * @param dir_p pointer to an initialized 'fs_read_dir_t' variable * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_close (lv_fs_drv_t * drv, void * dir_p) +static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p) { - f_closedir(dir_p); + f_closedir(dir_p); return LV_FS_RES_OK; } -#endif /*LV_USE_FS_IF*/ -#endif /*LV_FS_IF_FATFS*/ +#endif /*LV_USE_FS_IF*/ +#endif /*LV_FS_IF_FATFS*/ diff --git a/lib/lv_fs_if/lv_fs_pc.c b/lib/lv_fs_if/lv_fs_pc.c index e3dd160d..6bdca94d 100644 --- a/lib/lv_fs_if/lv_fs_pc.c +++ b/lib/lv_fs_if/lv_fs_pc.c @@ -87,7 +87,7 @@ void lv_fs_if_pc_init(void) *--------------------------------------------------*/ /* Add a simple drive to open images */ - lv_fs_drv_t fs_drv; /*A driver descriptor*/ + static lv_fs_drv_t fs_drv; /*A driver descriptor*/ lv_fs_drv_init(&fs_drv); /*Set up fields...*/ diff --git a/lib/lv_fs_if/lv_fs_spiffs.cpp b/lib/lv_fs_if/lv_fs_spiffs.cpp index c8e8fb95..c33fb2c1 100644 --- a/lib/lv_fs_if/lv_fs_spiffs.cpp +++ b/lib/lv_fs_if/lv_fs_spiffs.cpp @@ -14,27 +14,27 @@ #include "ArduinoLog.h" #if LV_USE_FS_IF - #if LV_FS_IF_SPIFFS != '\0' +#if LV_FS_IF_SPIFFS != '\0' - #if defined(ARDUINO_ARCH_ESP32) - #if HASP_USE_SPIFFS > 0 - #include "SPIFFS.h" - #define LV_FS_SPIFFS SPIFFS - #elif HASP_USE_LITTLEFS > 0 - #include "LITTLEFS.h" - #define LV_FS_SPIFFS LITTLEFS - #endif - #elif defined(ARDUINO_ARCH_ESP8266) - #include "LittleFS.h" - #define LV_FS_SPIFFS LittleFS - #endif // ARDUINO_ARCH +#if defined(ARDUINO_ARCH_ESP32) +#if HASP_USE_SPIFFS > 0 +#include "SPIFFS.h" +#define LV_FS_SPIFFS SPIFFS +#elif HASP_USE_LITTLEFS > 0 +#include "LITTLEFS.h" +#define LV_FS_SPIFFS LITTLEFS +#endif +#elif defined(ARDUINO_ARCH_ESP8266) +#include "LittleFS.h" +#define LV_FS_SPIFFS LittleFS +#endif // ARDUINO_ARCH - #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - #include - #include - #endif // ARDUINO_ARCH +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#include +#include +#endif // ARDUINO_ARCH - #define TAG_LVFS 91 +#define TAG_LVFS 91 /********************* * DEFINES @@ -47,34 +47,34 @@ /* Create a type to store the required data about your file.*/ typedef File lv_spiffs_file_t; - /*Similarly to `file_t` create a type for directory reading too */ - #if defined(ARDUINO_ARCH_ESP32) +/*Similarly to `file_t` create a type for directory reading too */ +#if defined(ARDUINO_ARCH_ESP32) typedef File lv_spiffs_dir_t; - #elif defined(ARDUINO_ARCH_ESP8266) +#elif defined(ARDUINO_ARCH_ESP8266) typedef Dir lv_spiffs_dir_t; - #define FILE_READ "r" - #define FILE_WRITE "r+" - #endif +#define FILE_READ "r" +#define FILE_WRITE "r+" +#endif /********************** * STATIC PROTOTYPES **********************/ static void fs_init(void); -static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode); -static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p); -static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br); -static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw); -static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos); -static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p); -static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p); -static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path); -static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p); -static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * newname); -static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p); -static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * path); -static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn); -static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p); +static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode); +static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p); +static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br); +static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw); +static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos); +static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p); +static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p); +static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path); +static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p); +static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname); +static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p); +static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path); +static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn); +static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p); /********************** * STATIC VARIABLES @@ -100,7 +100,7 @@ void lv_fs_if_spiffs_init(void) *--------------------------------------------------*/ /* Add a simple drive to open images */ - lv_fs_drv_t fs_drv; /*A driver descriptor*/ + static lv_fs_drv_t fs_drv; /*A driver descriptor*/ lv_fs_drv_init(&fs_drv); /*Set up fields...*/ @@ -144,14 +144,14 @@ static void fs_init(void) * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) +static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode) { (void)drv; /*Unused*/ char filename[32]; snprintf_P(filename, sizeof(filename), PSTR("/%s"), path); - lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; + lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; if(fp == NULL) return LV_FS_RES_INV_PARAM; LOG_VERBOSE(TAG_LVFS, F("Opening %s"), filename); @@ -186,10 +186,10 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p) +static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p) { (void)drv; /*Unused*/ - lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; + lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; if(fp == NULL) return LV_FS_RES_INV_PARAM; lv_spiffs_file_t file = *fp; @@ -217,10 +217,10 @@ static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br) +static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br) { (void)drv; /*Unused*/ - lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; + lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; if(fp == NULL) return LV_FS_RES_INV_PARAM; lv_spiffs_file_t file = *fp; @@ -232,7 +232,7 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_ } else { // LOG_VERBOSE(TAG_LVFS, F("Reading %u bytes from %s at position %u"), btr, file.name(), file.position()); uint32_t len = 0; - char * chp = (char *)buf; + char* chp = (char*)buf; if(chp != NULL && btr > 0) len = file.readBytes(chp, btr); else @@ -257,10 +257,10 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_ * @param br the number of real written bytes (Bytes Written). NULL if unused. * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw) +static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw) { (void)drv; /*Unused*/ - lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p; + lv_spiffs_file_t file = *(lv_spiffs_file_t*)file_p; // File file = fp; if(!file) { @@ -268,7 +268,7 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, return LV_FS_RES_NOT_EX; } else { - *bw = (uint32_t)file.write((byte *)buf, btw); + *bw = (uint32_t)file.write((byte*)buf, btw); return LV_FS_RES_OK; } } @@ -281,10 +281,10 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos) +static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos) { (void)drv; /*Unused*/ - lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p; + lv_spiffs_file_t file = *(lv_spiffs_file_t*)file_p; // File file = fp; if(!file) { @@ -304,10 +304,10 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos) * @param size pointer to a variable to store the size * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p) +static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p) { (void)drv; /*Unused*/ - lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p; + lv_spiffs_file_t file = *(lv_spiffs_file_t*)file_p; // File file = fp; if(!file) { @@ -328,10 +328,10 @@ static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) +static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p) { (void)drv; /*Unused*/ - lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p; + lv_spiffs_file_t file = *(lv_spiffs_file_t*)file_p; // File file = fp; if(!file) { @@ -350,7 +350,7 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) * @param path path of the file to delete * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path) +static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path) { (void)drv; /*Unused*/ @@ -375,7 +375,7 @@ static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path) * @return LV_FS_RES_OK: no error, the file is read * any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p) +static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p) { return LV_FS_RES_NOT_IMP; } @@ -387,7 +387,7 @@ static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p) * @param newname path with the new name * @return LV_FS_RES_OK or any error from 'fs_res_t' */ -static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * newname) +static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname) { (void)drv; /*Unused*/ char fromname[32]; @@ -411,23 +411,23 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * @param free_p pointer to store the free size [kB] * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p) +static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p) { (void)drv; /*Unused*/ - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) FSInfo fs_info; LV_FS_SPIFFS.info(fs_info); *total_p = (uint32_t)fs_info.totalBytes; *free_p = (uint32_t)fs_info.totalBytes - fs_info.usedBytes; return LV_FS_RES_OK; - #elif defined(ARDUINO_ARCH_ESP32) +#elif defined(ARDUINO_ARCH_ESP32) *total_p = (uint32_t)LV_FS_SPIFFS.totalBytes(); *free_p = (uint32_t)LV_FS_SPIFFS.totalBytes() - LV_FS_SPIFFS.usedBytes(); return LV_FS_RES_OK; - #endif +#endif return LV_FS_RES_NOT_IMP; } @@ -439,23 +439,23 @@ static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fre * @param path path to a directory * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * path) +static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path) { lv_spiffs_dir_t dir; - #if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) dir = LV_FS_SPIFFS.open(path); if(!dir) { return LV_FS_RES_UNKNOWN; } - #endif +#endif - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) dir = LV_FS_SPIFFS.openDir(path); - #endif +#endif - lv_spiffs_dir_t * dp = (lv_spiffs_dir_t *)dir_p; /*Just avoid the confusing casings*/ - *dp = dir; + lv_spiffs_dir_t* dp = (lv_spiffs_dir_t*)dir_p; /*Just avoid the confusing casings*/ + *dp = dir; return LV_FS_RES_OK; } @@ -467,11 +467,11 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat * @param fn pointer to a buffer to store the filename * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn) +static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn) { - lv_spiffs_dir_t dir = *(lv_spiffs_dir_t *)dir_p; /*Convert type*/ + lv_spiffs_dir_t dir = *(lv_spiffs_dir_t*)dir_p; /*Convert type*/ - #if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) File file = dir.openNextFile(); if(file) { strcpy(fn, file.name()); @@ -479,16 +479,16 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn) } else { return LV_FS_RES_UNKNOWN; } - #endif +#endif - #if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) if(dir.next()) { strcpy(fn, dir.fileName().c_str()); return LV_FS_RES_OK; } else { return LV_FS_RES_UNKNOWN; } - #endif +#endif return LV_FS_RES_NOT_IMP; } @@ -499,12 +499,12 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn) * @param dir_p pointer to an initialized 'fs_read_dir_t' variable * @return LV_FS_RES_OK or any error from lv_fs_res_t enum */ -static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p) +static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p) { return LV_FS_RES_OK; } - #endif /*LV_USE_FS_IF*/ -#endif /*LV_FS_IF_SPIFFS*/ +#endif /*LV_USE_FS_IF*/ +#endif /*LV_FS_IF_SPIFFS*/ #endif /*ARDUINO*/ \ No newline at end of file diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 1c3b9ea8..1ae15dd1 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -168,7 +168,7 @@ void guiSetup(void) } /* Initialize the display driver */ - lv_disp_drv_t disp_drv; + static lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); disp_drv.buffer = &disp_buf; disp_drv.flush_cb = gui_flush_cb; @@ -220,7 +220,7 @@ void guiSetup(void) LOG_VERBOSE(TAG_LVGL, F("VFB size : %d"), (size_t)sizeof(lv_color_t) * guiVDBsize); /* Initialize the touch pad */ - lv_indev_drv_t indev_drv; + static lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; #if defined(WINDOWS) || defined(POSIX) From 1f4abb215fcf04e55d858a23b99790031b5e0800 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 17:38:53 +0100 Subject: [PATCH 198/236] Set lvgl version to 7.11.0 --- platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7237de15..2bfe140c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -73,8 +73,8 @@ lib_deps = git+https://github.com/fvanroie/ConsoleInput.git ;git+https://github.com/andrethomas/TasmotaSlave.git ;git+https://github.com/fvanroie/lv_components.git - git+https://github.com/lvgl/lvgl.git - ;lvgl/lvgl @^7.11.0 ; from PIO library + ;git+https://github.com/lvgl/lvgl.git + lvgl/lvgl @^7.11.0 ; from PIO library ;bodmer/TFT_eSPI @ 2.3.4 ; Tft SPI drivers EXACT version 2.3.5 has compile error git+https://github.com/Bodmer/TFT_eSPI.git ; ------ Unused / Test libraries From 147414f953b6f7503b1d832fbfd5dadca59c592d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 19:43:49 +0100 Subject: [PATCH 199/236] Increase flash partitions --- user_setups/esp32/lolin-d32-pro_ili9341.ini | 4 ++++ user_setups/esp32/m5stack_core2.ini | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/user_setups/esp32/lolin-d32-pro_ili9341.ini b/user_setups/esp32/lolin-d32-pro_ili9341.ini index 47a82dc2..236bee89 100644 --- a/user_setups/esp32/lolin-d32-pro_ili9341.ini +++ b/user_setups/esp32/lolin-d32-pro_ili9341.ini @@ -11,6 +11,10 @@ extends = esp32 board = lolin_d32_pro +board_upload.flash_size=16MB +board_upload.maximum_size = 16777216 +board_build.partitions = user_setups/esp32_partition_app2000k_spiffs4000k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/m5stack_core2.ini b/user_setups/esp32/m5stack_core2.ini index c14e5d78..36833db5 100644 --- a/user_setups/esp32/m5stack_core2.ini +++ b/user_setups/esp32/m5stack_core2.ini @@ -9,6 +9,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=16MB +board_upload.maximum_size = 16777216 +board_build.partitions = user_setups/esp32_partition_app2000k_spiffs4000k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} From 57fb7bb9f499e170ff76735f6b9f44cba9f0cc7a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:08:51 +0100 Subject: [PATCH 200/236] Increase flash partitions --- user_setups/esp32/ttgo-esp32-lilygo-pi.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini index 2d687549..fa27a3aa 100644 --- a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini +++ b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini @@ -9,6 +9,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=16MB +board_upload.maximum_size = 16777216 +board_build.partitions = user_setups/esp32_partition_app2000k_spiffs4000k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} From 72b36f54b9d081c5ca23c5562abc5f835b53b3ab Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:55:17 +0100 Subject: [PATCH 201/236] Adjust partitions --- platformio.ini | 2 +- platformio_override-template.ini | 2 +- user_setups/esp32/lanbon_l8.ini | 2 +- user_setups/esp32/lolin-d32-pro_ili9341.ini | 2 +- user_setups/esp32/m5stack_core2.ini | 2 +- .../partition_app1280k_spiffs1472k.csv} | 0 .../partition_app1300k_spiffs1216k.csv} | 0 .../partition_app1536k_spiffs1024k.csv} | 0 .../partition_app2000k_spiffs4000k.csv} | 0 user_setups/esp32/ttgo-esp32-lilygo-pi.ini | 2 +- 10 files changed, 6 insertions(+), 6 deletions(-) rename user_setups/{esp32_partition_app1280k_spiffs1472k.csv => esp32/partition_app1280k_spiffs1472k.csv} (100%) rename user_setups/{esp32_partition_app1300k_spiffs1216k.csv => esp32/partition_app1300k_spiffs1216k.csv} (100%) rename user_setups/{esp32_partition_app1536k_spiffs1024k.csv => esp32/partition_app1536k_spiffs1024k.csv} (100%) rename user_setups/{esp32_partition_app2000k_spiffs4000k.csv => esp32/partition_app2000k_spiffs4000k.csv} (100%) diff --git a/platformio.ini b/platformio.ini index 2bfe140c..0cdb3c59 100644 --- a/platformio.ini +++ b/platformio.ini @@ -92,7 +92,7 @@ extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py [esp32] framework = arduino platform = espressif32 -board_build.partitions = user_setups/esp32_partition_app1536k_spiffs1024k.csv +board_build.partitions = user_setups/esp32/partition_app1536k_spiffs1024k.csv ; ----- crash reporter monitor_filters = esp32_exception_decoder diff --git a/platformio_override-template.ini b/platformio_override-template.ini index 226f7038..8ab9c7ab 100644 --- a/platformio_override-template.ini +++ b/platformio_override-template.ini @@ -75,7 +75,7 @@ board = nodemcu-32s upload_port = COM12 ; To change the port, use platform_override.ini monitor_port = COM12 ; To change the port, use platform_override.ini -board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv ; default.csv +board_build.partitions = user_setups/esp32/partition_app1536k_spiffs1024k.csv ; default.csv debug_tool = esp-prog debug_init_break = tbreak setup diff --git a/user_setups/esp32/lanbon_l8.ini b/user_setups/esp32/lanbon_l8.ini index c2653856..b5f44da9 100644 --- a/user_setups/esp32/lanbon_l8.ini +++ b/user_setups/esp32/lanbon_l8.ini @@ -11,7 +11,7 @@ board = esp32dev board_upload.flash_size=8MB board_upload.maximum_size = 8388608 -board_build.partitions = user_setups/esp32_partition_app2000k_spiffs4000k.csv +board_build.partitions = user_setups/esp32/partition_app2000k_spiffs4000k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32/lolin-d32-pro_ili9341.ini b/user_setups/esp32/lolin-d32-pro_ili9341.ini index 236bee89..f31e7639 100644 --- a/user_setups/esp32/lolin-d32-pro_ili9341.ini +++ b/user_setups/esp32/lolin-d32-pro_ili9341.ini @@ -13,7 +13,7 @@ board = lolin_d32_pro board_upload.flash_size=16MB board_upload.maximum_size = 16777216 -board_build.partitions = user_setups/esp32_partition_app2000k_spiffs4000k.csv +board_build.partitions = user_setups/esp32/partition_app2000k_spiffs4000k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32/m5stack_core2.ini b/user_setups/esp32/m5stack_core2.ini index 36833db5..a379ef26 100644 --- a/user_setups/esp32/m5stack_core2.ini +++ b/user_setups/esp32/m5stack_core2.ini @@ -11,7 +11,7 @@ board = esp32dev board_upload.flash_size=16MB board_upload.maximum_size = 16777216 -board_build.partitions = user_setups/esp32_partition_app2000k_spiffs4000k.csv +board_build.partitions = user_setups/esp32/partition_app2000k_spiffs4000k.csv build_flags = ${env.build_flags} diff --git a/user_setups/esp32_partition_app1280k_spiffs1472k.csv b/user_setups/esp32/partition_app1280k_spiffs1472k.csv similarity index 100% rename from user_setups/esp32_partition_app1280k_spiffs1472k.csv rename to user_setups/esp32/partition_app1280k_spiffs1472k.csv diff --git a/user_setups/esp32_partition_app1300k_spiffs1216k.csv b/user_setups/esp32/partition_app1300k_spiffs1216k.csv similarity index 100% rename from user_setups/esp32_partition_app1300k_spiffs1216k.csv rename to user_setups/esp32/partition_app1300k_spiffs1216k.csv diff --git a/user_setups/esp32_partition_app1536k_spiffs1024k.csv b/user_setups/esp32/partition_app1536k_spiffs1024k.csv similarity index 100% rename from user_setups/esp32_partition_app1536k_spiffs1024k.csv rename to user_setups/esp32/partition_app1536k_spiffs1024k.csv diff --git a/user_setups/esp32_partition_app2000k_spiffs4000k.csv b/user_setups/esp32/partition_app2000k_spiffs4000k.csv similarity index 100% rename from user_setups/esp32_partition_app2000k_spiffs4000k.csv rename to user_setups/esp32/partition_app2000k_spiffs4000k.csv diff --git a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini index fa27a3aa..396c61a7 100644 --- a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini +++ b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini @@ -11,7 +11,7 @@ board = esp32dev board_upload.flash_size=16MB board_upload.maximum_size = 16777216 -board_build.partitions = user_setups/esp32_partition_app2000k_spiffs4000k.csv +board_build.partitions = user_setups/esp32/partition_app2000k_spiffs4000k.csv build_flags = ${env.build_flags} From 0523c37598e14d9d08fa3a1803431a09076e2464 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Mar 2021 23:35:19 +0100 Subject: [PATCH 202/236] Set higher touch treshold for XPT2046 --- src/drv/hasp_drv_touch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drv/hasp_drv_touch.cpp b/src/drv/hasp_drv_touch.cpp index da3a80ee..77f5f512 100644 --- a/src/drv/hasp_drv_touch.cpp +++ b/src/drv/hasp_drv_touch.cpp @@ -75,7 +75,7 @@ static inline bool drv_touchpad_getXY(int16_t* touchX, int16_t* touchY) int16_t normal_x; int16_t normal_y; #if TOUCH_DRIVER == 2046 // XPT2046 Resistive touch panel driver - touched = haspTft.tft.getTouch((uint16_t*)&normal_x, (uint16_t*)&normal_y, 20); + touched = haspTft.tft.getTouch((uint16_t*)&normal_x, (uint16_t*)&normal_y, 300); #elif TOUCH_DRIVER == 0x2046B touched = XPT2046_getXY(&normal_x, &normal_y, true); From b1089039fdbad7b9ae0f5c7c0c5349757634a026 Mon Sep 17 00:00:00 2001 From: arovak Date: Wed, 17 Mar 2021 12:21:58 +0100 Subject: [PATCH 203/236] update TOUCH_IRQ pin --- user_setups/esp32/ttgo-esp32-lilygo-pi.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini index fa27a3aa..577fd374 100644 --- a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini +++ b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini @@ -35,7 +35,7 @@ build_flags = -D TFT_RST=-1 ; RST -D TFT_BCKL=12 ; None, configurable via web UI (e.g. 21) -D TOUCH_DRIVER=911 ; GT911 Capacitive I2C touch panel driver - -D TOUCH_IRQ=39 + -D TOUCH_IRQ=34 -D TOUCH_RST=-1 -D TOUCH_SDA=21 -D TOUCH_SCL=22 From eef386950f49c2a865c010615dc5680873cce345 Mon Sep 17 00:00:00 2001 From: arovak Date: Wed, 17 Mar 2021 12:23:00 +0100 Subject: [PATCH 204/236] Allow for timezone setting in user_config_override.h --- src/sys/net/hasp_network.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sys/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp index 3adfced0..ae69d02e 100644 --- a/src/sys/net/hasp_network.cpp +++ b/src/sys/net/hasp_network.cpp @@ -3,8 +3,12 @@ #include #include +#ifdef USE_CONFIG_OVERRIDE +#include "user_config_override.h" +#endif +#ifndef MYTZ #define MYTZ "EST5EDT,M3.2.0/2,M11.1.0" - +#endif #include #include "ArduinoLog.h" @@ -20,6 +24,7 @@ void networkStart(void) { #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + LOG_WARNING(TAG_MAIN, F("TIMEZONE: %s"), MYTZ); configTzTime(MYTZ, "pool.ntp.org", "time.nist.gov", NULL); // literal string #endif From e4ea6e69ce68178043b74a1d11f3fd14ccb3cb7b Mon Sep 17 00:00:00 2001 From: arovak Date: Wed, 17 Mar 2021 12:24:27 +0100 Subject: [PATCH 205/236] fix date/time entry in console --- src/hasp_debug.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 2782dcdb..9946f969 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -70,7 +70,7 @@ static void debugPrintTimestamp(int level, Print* _logOutput) // strftime(buffer, sizeof(buffer), "[%H:%M:%S.", timeinfo); // Literal String #ifdef ARDUINO - _logOutput->printf(PSTR("%03lu]"), curTime.tv_usec / 1000); + _logOutput->printf(PSTR("%s.%03lu]"), buffer, curTime.tv_usec / 1000); #else debug_print(_logOutput, PSTR("%s.%03lu]"), buffer, curTime.tv_usec / 1000); #endif From bc5f93dd91fe22475acb7acb2a4dbe0d1374b040 Mon Sep 17 00:00:00 2001 From: arovak Date: Wed, 17 Mar 2021 12:25:52 +0100 Subject: [PATCH 206/236] modify GT911 driver to allow smoother touch --- src/drv/touch/hasp_drv_gt911.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/drv/touch/hasp_drv_gt911.cpp b/src/drv/touch/hasp_drv_gt911.cpp index 1d2ee59f..eebba5b1 100644 --- a/src/drv/touch/hasp_drv_gt911.cpp +++ b/src/drv/touch/hasp_drv_gt911.cpp @@ -19,11 +19,11 @@ void GT911_setXY(int8_t contacts, GTPoint * points) GT911_num_touches = contacts; GT911_points = points; - LOG_VERBOSE(TAG_GUI, F("Contacts: %d"), contacts); - for(int i = 0; i < contacts; i++) { - LOG_VERBOSE(TAG_GUI, F("C%d: #%d %d,%d s:%d"), i, points[i].trackId, points[i].x, points[i].y, points[i].area); - yield(); - } + // LOG_VERBOSE(TAG_GUI, F("Contacts: %d"), contacts); + // for(int i = 0; i < contacts; i++) { + // LOG_VERBOSE(TAG_GUI, F("C%d: #%d %d,%d s:%d"), i, points[i].trackId, points[i].x, points[i].y, points[i].area); + // yield(); + // } } // Read touch points from global variable From d1f1b70bddc8dd8e93642c2924e24be633c6e621 Mon Sep 17 00:00:00 2001 From: arovak Date: Wed, 17 Mar 2021 12:26:30 +0100 Subject: [PATCH 207/236] intermediate tweak to have ZI font as font 0 --- src/hasp/hasp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index d980a743..44197267 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -374,7 +374,7 @@ void haspSetup(void) haspFonts[1] = LV_FONT_DEFAULT; } else { // defaultFont = haspFonts[0]; - haspFonts[1] = hasp_font; // save it + haspFonts[0] = hasp_font; // save it } #endif #endif From 496a4af2ecc8b189eb3ce801da09f97f05b7b0b6 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Mar 2021 13:34:18 +0100 Subject: [PATCH 208/236] Add logging --- src/hasp/hasp_attribute.cpp | 19 +++++------ src/hasp_oobe.cpp | 64 ++++++++++++++++++------------------- src/main_arduino.cpp | 1 + 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index a9444c5c..14455651 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -13,7 +13,6 @@ #include "hasplib.h" LV_FONT_DECLARE(unscii_8_icon); -extern lv_font_t* haspFonts[8]; extern const char** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map #if 0 @@ -454,10 +453,8 @@ static lv_font_t* haspPayloadToFont(const char* payload) uint8_t var = atoi(payload); switch(var) { - case 0: - case 1: - case 2: - case 3: + case 0 ... 7: + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_12_nokern); return hasp_get_font(var); case 8: @@ -467,22 +464,25 @@ static lv_font_t* haspPayloadToFont(const char* payload) #ifdef LV_FONT_CUSTOM_12 case 12: - return LV_THEME_DEFAULT_FONT_SMALL; + return &robotocondensed_regular_12_nokern; #endif #ifdef LV_FONT_CUSTOM_16 case 16: - return LV_THEME_DEFAULT_FONT_NORMAL; + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_16_nokern); + return &robotocondensed_regular_16_nokern; #endif #ifdef LV_FONT_CUSTOM_22 case 22: - return LV_THEME_DEFAULT_FONT_SUBTITLE; + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_22_nokern); + return &robotocondensed_regular_22_nokern; #endif #ifdef LV_FONT_CUSTOM_28 case 28: - return LV_THEME_DEFAULT_FONT_TITLE; + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_28_nokern); + return &robotocondensed_regular_28_nokern; #endif #endif @@ -885,6 +885,7 @@ static void hasp_local_style_attr(lv_obj_t* obj, const char* attr_p, uint16_t at case ATTR_TEXT_FONT: { lv_font_t* font = haspPayloadToFont(payload); if(font) { + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, *font); uint8_t count = 3; if(check_obj_type(obj, LV_HASP_ROLLER)) count = my_roller_get_visible_row_count(obj); lv_obj_set_style_local_text_font(obj, part, state, font); diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index 74481ba0..562753a0 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -26,11 +26,9 @@ static bool oobeAutoCalibrate = true; #include "lv_qrcode.h" #endif -static lv_obj_t * oobepage[2]; -static lv_obj_t * oobekb; -extern lv_font_t * defaultFont; - -lv_obj_t * pwd_ta; +static lv_obj_t* oobepage[2]; +static lv_obj_t* oobekb; +lv_obj_t* pwd_ta; static inline void oobeSetPage(uint8_t pageid) { @@ -38,7 +36,7 @@ static inline void oobeSetPage(uint8_t pageid) lv_obj_invalidate(lv_disp_get_layer_sys(NULL)); } -void gotoPage1_cb(lv_obj_t * event_kb, lv_event_t event) +void gotoPage1_cb(lv_obj_t* event_kb, lv_event_t event) { if(event == LV_EVENT_RELEASED) { lv_obj_set_click(lv_disp_get_layer_sys(NULL), false); @@ -46,7 +44,7 @@ void gotoPage1_cb(lv_obj_t * event_kb, lv_event_t event) } } -static void peek_password_cb(lv_obj_t * obj, lv_event_t event) +static void peek_password_cb(lv_obj_t* obj, lv_event_t event) { if(event == LV_EVENT_VALUE_CHANGED) { lv_obj_set_style_local_value_str(obj, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, @@ -55,13 +53,13 @@ static void peek_password_cb(lv_obj_t * obj, lv_event_t event) } } -static void kb_event_cb(lv_obj_t * event_kb, lv_event_t event) +static void kb_event_cb(lv_obj_t* event_kb, lv_event_t event) { if(event == LV_EVENT_APPLY) { StaticJsonDocument<256> settings; char ssid[32] = ""; char pass[32] = ""; - lv_obj_t * obj; + lv_obj_t* obj; obj = hasp_find_obj_from_parent_id(oobepage[1], (uint8_t)10); if(obj) { @@ -92,7 +90,7 @@ static void kb_event_cb(lv_obj_t * event_kb, lv_event_t event) // lv_kb_def_event_cb(event_kb, event); } } -static void ta_event_cb(lv_obj_t * ta, lv_event_t event) +static void ta_event_cb(lv_obj_t* ta, lv_event_t event) { if(event == LV_EVENT_CLICKED) { /* Focus on the clicked text area */ @@ -100,9 +98,9 @@ static void ta_event_cb(lv_obj_t * ta, lv_event_t event) } else if(event == LV_EVENT_INSERT) { - const char * str = (const char *)lv_event_get_data(); + const char* str = (const char*)lv_event_get_data(); if(str[0] == '\n') { - lv_obj_t * obj; + lv_obj_t* obj; obj = hasp_find_obj_from_parent_id(oobepage[1], (uint8_t)10); if(ta == obj) { // now ssid, goto pass @@ -119,12 +117,12 @@ static void ta_event_cb(lv_obj_t * ta, lv_event_t event) } } -static void oobeSetupQR(const char * ssid, const char * pass) +static void oobeSetupQR(const char* ssid, const char* pass) { - lv_disp_t * disp = lv_disp_get_default(); - oobepage[0] = lv_obj_create(NULL, NULL); + lv_disp_t* disp = lv_disp_get_default(); + oobepage[0] = lv_obj_create(NULL, NULL); char buffer[128]; - lv_obj_t * container = lv_cont_create(oobepage[0], NULL); + lv_obj_t* container = lv_cont_create(oobepage[0], NULL); lv_obj_set_pos(container, 5, 5); // lv_obj_set_style_local_bg_opa(container, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); // lv_obj_set_style_local_border_opa(container, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); @@ -132,10 +130,10 @@ static void oobeSetupQR(const char * ssid, const char * pass) #if HASP_USE_QRCODE > 0 snprintf_P(buffer, sizeof(buffer), PSTR("WIFI:S:%s;T:WPA;P:%s;;"), ssid, pass); - lv_obj_t * qr = lv_qrcode_create(oobepage[0], 120, LV_COLOR_BLACK, LV_COLOR_WHITE); + lv_obj_t* qr = lv_qrcode_create(oobepage[0], 120, LV_COLOR_BLACK, LV_COLOR_WHITE); lv_qrcode_update(qr, buffer, strlen(buffer)); - lv_obj_t * qrlabel = lv_label_create(oobepage[0], NULL); + lv_obj_t* qrlabel = lv_label_create(oobepage[0], NULL); snprintf_P(buffer, sizeof(buffer), PSTR(D_OOBE_SCAN_TO_CONNECT)); lv_label_set_text(qrlabel, buffer); @@ -154,7 +152,7 @@ static void oobeSetupQR(const char * ssid, const char * pass) lv_obj_set_size(container, disp->driver.hor_res, disp->driver.ver_res); #endif - lv_obj_t * aplabel = lv_label_create(container, NULL); + lv_obj_t* aplabel = lv_label_create(container, NULL); snprintf_P(buffer, sizeof(buffer), PSTR(D_OOBE_MSG)); lv_label_set_text(aplabel, buffer); lv_label_set_long_mode(aplabel, LV_LABEL_LONG_BREAK); @@ -164,28 +162,28 @@ static void oobeSetupQR(const char * ssid, const char * pass) lv_obj_align(aplabel, container, LV_ALIGN_IN_TOP_MID, 0, 0); - lv_obj_t * panel = lv_cont_create(container, NULL); + lv_obj_t* panel = lv_cont_create(container, NULL); lv_obj_align(panel, aplabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); lv_cont_set_fit(panel, LV_FIT_TIGHT); lv_cont_set_layout(panel, LV_LAYOUT_COLUMN_MID); - String txt((char *)0); + String txt((char*)0); txt.reserve(64); - txt = String(LV_SYMBOL_WIFI) + " " + String(ssid); - lv_obj_t * network = lv_label_create(panel, NULL); + txt = String(LV_SYMBOL_WIFI) + " " + String(ssid); + lv_obj_t* network = lv_label_create(panel, NULL); lv_label_set_text(network, txt.c_str()); - lv_obj_t * password = lv_label_create(panel, NULL); - txt = String(F("\xef\x80\xA3")) + " " + String(pass); + lv_obj_t* password = lv_label_create(panel, NULL); + txt = String(F("\xef\x80\xA3")) + " " + String(pass); lv_label_set_text(password, txt.c_str()); } static void oobeSetupSsid(void) { - lv_font_t * defaultfont; + lv_font_t* defaultfont; // #if defined(ARDUINO_ARCH_ESP32) // defaultfont = &lv_font_montserrat_12; // #else @@ -196,7 +194,7 @@ static void oobeSetupSsid(void) lv_align_t labelpos; lv_obj_user_data_t udata = {0, 0, 0}; - lv_disp_t * disp = lv_disp_get_default(); + lv_disp_t* disp = lv_disp_get_default(); if(disp->driver.hor_res <= disp->driver.ver_res) { leftmargin = 0; topmargin = -35; @@ -227,7 +225,7 @@ static void oobeSetupSsid(void) lv_obj_set_event_cb(pwd_ta, ta_event_cb); lv_obj_align(pwd_ta, NULL, LV_ALIGN_CENTER, leftmargin / 2 - lv_obj_get_height(pwd_ta) / 2, topmargin - voffset); - lv_obj_t * pwd_icon = lv_btn_create(oobepage[1], NULL); + lv_obj_t* pwd_icon = lv_btn_create(oobepage[1], NULL); lv_obj_set_size(pwd_icon, lv_obj_get_height(pwd_ta), lv_obj_get_height(pwd_ta)); lv_obj_set_pos(pwd_icon, lv_obj_get_x(pwd_ta) + lv_obj_get_width(pwd_ta), lv_obj_get_y(pwd_ta)); lv_obj_set_style_local_value_str(pwd_icon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_EYE_CLOSE); @@ -237,7 +235,7 @@ static void oobeSetupSsid(void) lv_btn_set_checkable(pwd_icon, true); /* Create the one-line mode text area */ - lv_obj_t * oneline_ta = lv_textarea_create(oobepage[1], pwd_ta); + lv_obj_t* oneline_ta = lv_textarea_create(oobepage[1], pwd_ta); lv_obj_set_style_local_text_font(oneline_ta, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, defaultfont); @@ -247,13 +245,13 @@ static void oobeSetupSsid(void) lv_obj_align(oneline_ta, pwd_ta, LV_ALIGN_OUT_TOP_MID, 0, topmargin); /* Create a label and position it above the text box */ - lv_obj_t * pwd_label = lv_label_create(oobepage[1], NULL); + lv_obj_t* pwd_label = lv_label_create(oobepage[1], NULL); snprintf_P(buffer, sizeof(buffer), PSTR(D_PASSWORD)); lv_label_set_text(pwd_label, buffer); lv_obj_align(pwd_label, pwd_ta, labelpos, 0, 0); /* Create a label and position it above the text box */ - lv_obj_t * oneline_label = lv_label_create(oobepage[1], NULL); + lv_obj_t* oneline_label = lv_label_create(oobepage[1], NULL); snprintf_P(buffer, sizeof(buffer), PSTR(D_SSID)); lv_label_set_text(oneline_label, buffer); lv_obj_align(oneline_label, oneline_ta, labelpos, 0, 0); @@ -286,7 +284,7 @@ static void oobeSetupSsid(void) lv_keyboard_set_cursor_manage(oobekb, true); /* Automatically show/hide cursors on text areas */ } -static void oobe_calibrate_cb(lv_obj_t * ta, lv_event_t event) +static void oobe_calibrate_cb(lv_obj_t* ta, lv_event_t event) { if(event == LV_EVENT_CLICKED) { if(oobeAutoCalibrate) { @@ -340,7 +338,7 @@ bool oobeSetup() } // Thist is used for testing only !! -void oobeFakeSetup(const char *, const char *) +void oobeFakeSetup(const char*, const char*) { #if HASP_USE_WIFI > 0 char ssid[32] = "HASP-ABCDEF"; diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 08339b71..fd30a849 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -56,6 +56,7 @@ void setup() #if HASP_USE_CONFIG > 0 configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart() #endif + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, &robotocondensed_regular_16_nokern); guiSetup(); debugSetup(); // Init the console From c8ad24e29a939d393a788c1c3ceff86a9f6c8e4e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Mar 2021 13:34:44 +0100 Subject: [PATCH 209/236] Add logging --- src/hasp/hasp.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index d980a743..dfb09fb1 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -93,8 +93,7 @@ lv_obj_t* kb; // lv_font_t * defaultFont; lv_obj_t* pages[HASP_NUM_PAGES]; -static lv_font_t* haspFonts[4] = {LV_THEME_DEFAULT_FONT_SMALL, LV_THEME_DEFAULT_FONT_NORMAL, - LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE}; +static lv_font_t* haspFonts[4] = {nullptr, nullptr, nullptr, nullptr}; uint8_t current_page = 1; /** @@ -363,6 +362,10 @@ void haspSetup(void) /* ********** Font Initializations ********** */ + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, &robotocondensed_regular_16_nokern); + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, nullptr); + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, haspFonts[1]); + #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) lv_font_t* hasp_font = nullptr; // required or font init will crash @@ -379,6 +382,14 @@ void haspSetup(void) #endif #endif + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_16_nokern); + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, *hasp_font); + + if(haspFonts[0] == nullptr) haspFonts[0] = LV_THEME_DEFAULT_FONT_SMALL; + // if(haspFonts[1] == nullptr) haspFonts[1] = LV_THEME_DEFAULT_FONT_NORMAL; + if(haspFonts[2] == nullptr) haspFonts[2] = LV_THEME_DEFAULT_FONT_SUBTITLE; + if(haspFonts[3] == nullptr) haspFonts[3] = LV_THEME_DEFAULT_FONT_TITLE; + // haspFonts[0] = lv_font_load("E:/font_1.fnt"); // haspFonts[2] = lv_font_load("E:/font_2.fnt"); // haspFonts[3] = lv_font_load("E:/font_3.fnt"); From 3ad2dd7b3c1309bff7e924f68395046eccbfce60 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Mar 2021 18:27:54 +0100 Subject: [PATCH 210/236] Reset default fonts --- src/hasp/hasp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index cbc06149..b5414fde 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -93,7 +93,8 @@ lv_obj_t* kb; // lv_font_t * defaultFont; lv_obj_t* pages[HASP_NUM_PAGES]; -static lv_font_t* haspFonts[4] = {nullptr, nullptr, nullptr, nullptr}; +static lv_font_t* haspFonts[4] = {LV_THEME_DEFAULT_FONT_SMALL, LV_THEME_DEFAULT_FONT_NORMAL, + LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE}; uint8_t current_page = 1; /** From 6c69a235c1bf4e1675d8bdcef1ee909e52bca46e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Mar 2021 19:47:19 +0100 Subject: [PATCH 211/236] Update tests --- test/test_colors.tavern.yaml | 2 +- test/test_obj.tavern.yaml | 10 +++++++ test/test_value_str.tavern.yaml | 52 ++++++++++++++++----------------- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/test/test_colors.tavern.yaml b/test/test_colors.tavern.yaml index 8db18eaf..32e07ac0 100644 --- a/test/test_colors.tavern.yaml +++ b/test/test_colors.tavern.yaml @@ -63,12 +63,12 @@ marks: - ["purple", "#830083", 131, 0, 131, 32784] - ["salmon", "#ff8173", 255, 129, 115, 64526] - ["sienna", "#a45029", 164, 80, 41, 41605] - - ["silver", "#c5c2c5", 197, 194, 197, 50712] - ["tomato", "#ff6141", 255, 97, 65, 64264] - ["violet", "#ee81ee", 238, 129, 238, 60445] - ["yellow", "#ffff00", 255, 255, 0, 65504] - ["fuchsia", "#ff00ff", 255, 0, 255, 63519] - ["magenta", "#ff00ff", 255, 0, 255, 63519] + - ["silver", "#c5c2c5", 197, 194, 197, 50712] - parametrize: key: obj diff --git a/test/test_obj.tavern.yaml b/test/test_obj.tavern.yaml index 684e7fd5..5b0a4dd7 100644 --- a/test/test_obj.tavern.yaml +++ b/test/test_obj.tavern.yaml @@ -242,3 +242,13 @@ stages: json: value_str: "{str1}{str2}" timeout: 1 + + - name: Get obj type + mqtt_publish: + topic: hasp/{plate}/command + payload: "p1b1.obj" + mqtt_response: + topic: hasp/{plate}/state/p1b1 + json: + obj: "{obj}" + timeout: 1 diff --git a/test/test_value_str.tavern.yaml b/test/test_value_str.tavern.yaml index f22688e8..ec85b53d 100644 --- a/test/test_value_str.tavern.yaml +++ b/test/test_value_str.tavern.yaml @@ -19,26 +19,27 @@ paho-mqtt: marks: - parametrize: - key: objid + key: obj vals: - - 10 - - 12 - - 20 - - 22 - - 30 - - 31 - - 32 - # - 33 - # - 40 - - 41 - - 50 - - 51 - - 91 - # - 90 - # - 1 - - 2 - - 71 - - 80 + - cpicker + - table + - tabview + - chart + - gauge + - btn + - label + - slider + - checkbox + - switch + - bar + - arc + - led + - obj + - lmeter + - dropdown + - spinner + - roller + - btnmatrix - parametrize: key: str1 @@ -51,8 +52,6 @@ marks: - "She opened the door." - "Aaron made a picture." - "I'm sorry." - - Test - - ABC - huey - dewey - "" @@ -61,7 +60,6 @@ marks: key: str2 vals: - louie - - fred - " I danced." - " Oak is strong and also gives shade." - " Cats and dogs each hate the other." @@ -90,17 +88,19 @@ stages: mqtt_publish: topic: hasp/{plate}/command/jsonl json: - objid: "{objid}" + obj: "{obj}" id: 1 - x: 128 - y: 128 + x: 0 + y: 0 + w: 240 + h: 240 delay_after: 0 - name: Set value_str mqtt_publish: topic: "hasp/{plate}/command/p[1].b[1].value_str" payload: "{str1}{str2}" - delay_after: 0.05 + delay_after: 0 - name: Get value_str mqtt_publish: topic: hasp/{plate}/command From b8bbf0c642310ed951617eda5ed9738e743777bc Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Mar 2021 19:52:52 +0100 Subject: [PATCH 212/236] Add get_obj_type_name --- src/hasp/hasp_attribute.cpp | 12 +++++++----- src/hasp/hasp_attribute.h | 1 + src/hasp/hasp_object.cpp | 23 +++++++++++++++++++---- src/hasp/hasp_object.h | 1 + 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 14455651..22330ed0 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1407,12 +1407,14 @@ void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* p update ? (void)(obj->user_data.groupid = (uint8_t)val) : hasp_out_int(obj, attr, obj->user_data.groupid); break; // attribute_found + case ATTR_OBJ: + if(update) LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_READ_ONLY), attr_p); + hasp_out_str(obj, attr, get_obj_type_name(obj)); + break; // attribute_found + case ATTR_OBJID: - if(update) { - LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_READ_ONLY), attr_p); - } else { - hasp_out_int(obj, attr, obj->user_data.objid); - } + if(update) LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_READ_ONLY), attr_p); + hasp_out_int(obj, attr, obj->user_data.objid); break; // attribute_found case ATTR_X: diff --git a/src/hasp/hasp_attribute.h b/src/hasp/hasp_attribute.h index ff8ccf50..3cc9d3c2 100644 --- a/src/hasp/hasp_attribute.h +++ b/src/hasp/hasp_attribute.h @@ -314,5 +314,6 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t) /* hasp user data */ #define ATTR_GROUPID 48986 #define ATTR_OBJID 41010 +#define ATTR_OBJ 53623 #endif diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 690dccbb..25348977 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -152,6 +152,20 @@ bool hasp_find_id_from_obj(lv_obj_t* obj, uint8_t* pageid, uint8_t* objid) // } // } +/** + * Get the object type name of an object + * @param obj an lv_obj_t* of the object to check its type + * @return name of the object type + * @note + */ +const char* get_obj_type_name(lv_obj_t* obj) +{ + lv_obj_type_t list; + lv_obj_get_type(obj, &list); + const char* objtype = list.type[0]; + return objtype + 3; // skip lv_ +} + /** * Check if an lvgl objecttype name corresponds to a given HASP object ID * @param obj an lv_obj_t* of the object to check its type @@ -352,7 +366,8 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) hasp_update_sleep_state(); // wakeup? dispatch_object_generic_event(obj, eventid); // send object event - dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(dispatch_get_event_state(eventid), 0, 1), obj); + dispatch_normalized_group_value(obj->user_data.groupid, obj, dispatch_get_event_state(eventid), HASP_EVENT_OFF, + HASP_EVENT_ON); } /** @@ -390,7 +405,7 @@ void toggle_event_handler(lv_obj_t* obj, lv_event_t event) hasp_update_sleep_state(); // wakeup? dispatch_object_toggle_event(obj, val); - dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(val, 0, 1), obj); + dispatch_normalized_group_value(obj->user_data.groupid, obj, val, HASP_EVENT_OFF, HASP_EVENT_ON); } else if(event == LV_EVENT_DELETE) { LOG_VERBOSE(TAG_HASP, F(D_OBJECT_DELETED)); @@ -454,7 +469,7 @@ static void selector_event_handler(lv_obj_t* obj, lv_event_t event) // hasp_send_obj_attribute_str(obj, property, buffer); dispatch_object_selection_changed(obj, val, buffer); - if(max > 0) dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(val, 0, max), obj); + if(max > 0) dispatch_normalized_group_value(obj->user_data.groupid, obj, val, 0, max); } else if(event == LV_EVENT_DELETE) { LOG_VERBOSE(TAG_HASP, F(D_OBJECT_DELETED)); @@ -500,7 +515,7 @@ void slider_event_handler(lv_obj_t* obj, lv_event_t event) return; } dispatch_object_value_changed(obj, val); - dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(val, min, max), obj); + dispatch_normalized_group_value(obj->user_data.groupid, obj, val, min, max); } else if(event == LV_EVENT_DELETE) { LOG_VERBOSE(TAG_HASP, F(D_OBJECT_DELETED)); diff --git a/src/hasp/hasp_object.h b/src/hasp/hasp_object.h index e280883a..ad88cdf0 100644 --- a/src/hasp/hasp_object.h +++ b/src/hasp/hasp_object.h @@ -66,6 +66,7 @@ lv_obj_t* hasp_find_obj_from_parent_id(lv_obj_t* parent, uint8_t objid); // lv_obj_t * hasp_find_obj_from_page_id(uint8_t pageid, uint8_t objid); bool hasp_find_id_from_obj(lv_obj_t* obj, uint8_t* pageid, uint8_t* objid); // bool check_obj_type_str(const char * lvobjtype, lv_hasp_obj_type_t haspobjtype); +const char* get_obj_type_name(lv_obj_t* obj); bool check_obj_type(lv_obj_t* obj, lv_hasp_obj_type_t haspobjtype); void hasp_object_tree(lv_obj_t* parent, uint8_t pageid, uint16_t level); void hasp_object_delete(lv_obj_t* obj); From 33aaa68f74283af4058d25b04a39910b33c852e2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Mar 2021 19:53:17 +0100 Subject: [PATCH 213/236] Change normalized functions to use val, min & max --- src/hasp/hasp_dispatch.cpp | 8 ++++---- src/hasp/hasp_dispatch.h | 2 +- src/sys/gpio/hasp_gpio.cpp | 40 ++++++++++++++++++++++++-------------- src/sys/gpio/hasp_gpio.h | 2 +- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index aa409c3e..41430165 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -251,7 +251,7 @@ void dispatch_command(const char* topic, const char* payload) if(strlen(topic) == 7 && topic == strstr_P(topic, PSTR("output"))) { int16_t state = atoi(payload); - dispatch_normalized_group_value(atoi(topic + 6), state, NULL); // + 6 => trim 'output' from the topic + dispatch_normalized_group_value(atoi(topic + 6), NULL, state, 0, 1); // + 6 => trim 'output' from the topic // } else if(strcasecmp_P(topic, PSTR("screenshot")) == 0) { // guiTakeScreenshot("/screenshot.bmp"); // Literal String @@ -684,12 +684,12 @@ static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const // // dispatch_output_group_state(groupid, payload); // } -void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t* obj) +void dispatch_normalized_group_value(uint8_t groupid, lv_obj_t* obj, int16_t val, int16_t min, int16_t max) { if(groupid > 0) { - LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d"), groupid, value); + LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d (%d-%d)"), groupid, val, min, max); #if HASP_USE_GPIO > 0 - gpio_set_normalized_group_value(groupid, value); + gpio_set_normalized_group_value(groupid, val, min, max); #endif // object_set_group_state(groupid, value, obj); } diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 2a9e44ee..83288ca9 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -66,7 +66,7 @@ bool dispatch_get_event_state(uint8_t eventid); void dispatch_get_event_name(uint8_t eventid, char* buffer, size_t size); void dispatch_object_value_changed(lv_obj_t* obj, int16_t state); -void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t* obj); +void dispatch_normalized_group_value(uint8_t groupid, lv_obj_t* obj, int16_t val, int16_t min, int16_t max); void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char* attribute, const char* data); void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char* attribute, int32_t val); diff --git a/src/sys/gpio/hasp_gpio.cpp b/src/sys/gpio/hasp_gpio.cpp index b4be2746..d2575f43 100644 --- a/src/sys/gpio/hasp_gpio.cpp +++ b/src/sys/gpio/hasp_gpio.cpp @@ -90,7 +90,7 @@ static void gpio_event_handler(AceButton* button, uint8_t eventType, uint8_t but dispatch_gpio_input_event(gpioConfig[btnid].pin, gpioConfig[btnid].group, eventid); if(eventid != HASP_EVENT_LONG) // do not repeat DOWN + LONG - dispatch_normalized_group_value(gpioConfig[btnid].group, NORMALIZE(state, 0, 1), NULL); + dispatch_normalized_group_value(gpioConfig[btnid].group, NULL, state, HASP_EVENT_OFF, HASP_EVENT_ON); } void aceButtonSetup(void) @@ -279,15 +279,20 @@ void gpioSetup() } /* ********************************* State Setters *************************************** */ -void gpio_set_normalized_value(hasp_gpio_config_t gpio, uint16_t state) +void gpio_set_normalized_value(hasp_gpio_config_t gpio, int16_t val, int16_t min, int16_t max) { + if(min == max) { + LOG_ERROR(TAG_GPIO, F("Invalid value range")); + return; + } + switch(gpio.type) { case HASP_GPIO_RELAY: - gpio.val = state >= 0x8000U ? HIGH : LOW; + gpio.val = map(val, min, max, 0, 1) ? HIGH : LOW; digitalWrite(gpio.pin, gpio.val); break; case HASP_GPIO_RELAY_INVERTED: - gpio.val = state >= 0x8000U ? LOW : HIGH; + gpio.val = map(val, min, max, 0, 1) ? LOW : HIGH; digitalWrite(gpio.pin, gpio.val); break; case HASP_GPIO_LED: @@ -295,19 +300,19 @@ void gpio_set_normalized_value(hasp_gpio_config_t gpio, uint16_t state) case HASP_GPIO_LED_G: case HASP_GPIO_LED_B: #if defined(ARDUINO_ARCH_ESP32) - gpio.val = map(state, 0, 0xFFFFU, 0, 4095); + gpio.val = map(val, min, max, 0, 4095); ledcWrite(gpio.group, gpio.val); // ledChannel and value #else - gpio.val = map(state, 0, 0xFFFFU, 0, 1023); + gpio.val = map(val, min, max, 0, 1023); analogWrite(gpio.pin, gpio.val); #endif break; case HASP_GPIO_PWM: #if defined(ARDUINO_ARCH_ESP32) - gpio.val = map(state, 0, 0xFFFFU, 0, 4095); + gpio.val = map(val, min, max, 0, 4095); ledcWrite(gpio.group, gpio.val); // ledChannel and value #else - gpio.val = map(state, 0, 0xFFFFU, 0, 1023); + gpio.val = map(val, min, max, 0, 1023); analogWrite(gpio.pin, gpio.val); #endif break; @@ -317,10 +322,10 @@ void gpio_set_normalized_value(hasp_gpio_config_t gpio, uint16_t state) case HASP_GPIO_LED_B_INVERTED: case HASP_GPIO_PWM_INVERTED: #if defined(ARDUINO_ARCH_ESP32) - gpio.val = map(0xFFFFU - state, 0, 0xFFFFU, 0, 4095); + gpio.val = map(val, min, max, 0, 4095); ledcWrite(gpio.group, gpio.val); // ledChannel and value #else - gpio.val = map(0xFFFFU - state, 0, 0xFFFFU, 0, 1023); + gpio.val = map(val, min, max, 0, 1023); analogWrite(gpio.pin, gpio.val); #endif break; @@ -340,12 +345,17 @@ void gpio_set_normalized_value(hasp_gpio_config_t gpio, uint16_t state) // } // } -void gpio_set_normalized_group_value(uint8_t groupid, uint16_t state) +void gpio_set_normalized_group_value(uint8_t groupid, int16_t val, int16_t min, int16_t max) { + if(min == max) { + LOG_ERROR(TAG_GPIO, F("Invalid value range")); + return; + } + // bool state = dispatch_get_event_state(eventid); for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) { if(gpioConfig[i].group == groupid) { - gpio_set_normalized_value(gpioConfig[i], state); + gpio_set_normalized_value(gpioConfig[i], val, min, max); } } } @@ -359,15 +369,15 @@ void gpio_set_moodlight(uint8_t r, uint8_t g, uint8_t b) switch(gpioConfig[i].type) { case HASP_GPIO_LED_R: case HASP_GPIO_LED_R_INVERTED: - gpio_set_normalized_value(gpioConfig[i], map(r, 0, 0xFF, 0, max_level)); + gpio_set_normalized_value(gpioConfig[i], r, 0, 0xFF); break; case HASP_GPIO_LED_G: case HASP_GPIO_LED_G_INVERTED: - gpio_set_normalized_value(gpioConfig[i], map(g, 0, 0xFF, 0, max_level)); + gpio_set_normalized_value(gpioConfig[i], g, 0, 0xFF); break; case HASP_GPIO_LED_B: case HASP_GPIO_LED_B_INVERTED: - gpio_set_normalized_value(gpioConfig[i], map(b, 0, 0xFF, 0, max_level)); + gpio_set_normalized_value(gpioConfig[i], b, 0, 0xFF); break; } } diff --git a/src/sys/gpio/hasp_gpio.h b/src/sys/gpio/hasp_gpio.h index 1419e1b5..a19674e0 100644 --- a/src/sys/gpio/hasp_gpio.h +++ b/src/sys/gpio/hasp_gpio.h @@ -24,7 +24,7 @@ void gpioLoop(void); void gpioEvery5Seconds(void); // void gpio_set_group_onoff(uint8_t groupid, bool ison); -void gpio_set_normalized_group_value(uint8_t groupid, uint16_t state); +void gpio_set_normalized_group_value(uint8_t groupid, int16_t val, int16_t min, int16_t max); // void gpio_set_gpio_state(uint8_t pin, uint16_t state); void gpio_set_moodlight(uint8_t r, uint8_t g, uint8_t b); From 1d3eab7e8536d582bcd7a81efeeca276a52b6ffd Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 17 Mar 2021 20:56:07 +0100 Subject: [PATCH 214/236] Fix build error for native and esp8266 --- src/hasp/hasp.cpp | 5 +++-- user_setups/esp32/esp32-dev_ili9488.ini | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index b5414fde..3e8ed004 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -380,12 +380,13 @@ void haspSetup(void) // defaultFont = haspFonts[0]; haspFonts[0] = hasp_font; // save it } -#endif -#endif LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_16_nokern); LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, *hasp_font); +#endif +#endif + if(haspFonts[0] == nullptr) haspFonts[0] = LV_THEME_DEFAULT_FONT_SMALL; // if(haspFonts[1] == nullptr) haspFonts[1] = LV_THEME_DEFAULT_FONT_NORMAL; if(haspFonts[2] == nullptr) haspFonts[2] = LV_THEME_DEFAULT_FONT_SUBTITLE; diff --git a/user_setups/esp32/esp32-dev_ili9488.ini b/user_setups/esp32/esp32-dev_ili9488.ini index 5747e110..6fbcbba4 100644 --- a/user_setups/esp32/esp32-dev_ili9488.ini +++ b/user_setups/esp32/esp32-dev_ili9488.ini @@ -30,7 +30,7 @@ build_flags = -D TOUCH_DRIVER=2046 ; XPT2606 Resistive touch panel driver -D SPI_FREQUENCY=27000000 -D SPI_TOUCH_FREQUENCY=2500000 - -D SPI_READ_FREQUENCY=16000000 + -D SPI_READ_FREQUENCY=20000000 ;endregion ; -- Debugging options ----------------------------- From 6b5c3c1d12d47edb58c28a9de9f8db36a45cc254 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 18 Mar 2021 01:49:52 +0100 Subject: [PATCH 215/236] Gpio fixes --- src/main_arduino.cpp | 4 ++++ src/sys/gpio/hasp_gpio.cpp | 4 ++-- src/sys/net/hasp_network.cpp | 4 ---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index fd30a849..db06a6a1 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -116,6 +116,10 @@ void loop() haspLoop(); networkLoop(); +#if HASP_USE_GPIO > 0 + gpioLoop(); +#endif // GPIO + #if HASP_USE_MQTT > 0 mqttLoop(); #endif // MQTT diff --git a/src/sys/gpio/hasp_gpio.cpp b/src/sys/gpio/hasp_gpio.cpp index d2575f43..31762e7c 100644 --- a/src/sys/gpio/hasp_gpio.cpp +++ b/src/sys/gpio/hasp_gpio.cpp @@ -288,11 +288,11 @@ void gpio_set_normalized_value(hasp_gpio_config_t gpio, int16_t val, int16_t min switch(gpio.type) { case HASP_GPIO_RELAY: - gpio.val = map(val, min, max, 0, 1) ? HIGH : LOW; + gpio.val = val > min ? HIGH : LOW; digitalWrite(gpio.pin, gpio.val); break; case HASP_GPIO_RELAY_INVERTED: - gpio.val = map(val, min, max, 0, 1) ? LOW : HIGH; + gpio.val = val > min ? LOW : HIGH; digitalWrite(gpio.pin, gpio.val); break; case HASP_GPIO_LED: diff --git a/src/sys/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp index ae69d02e..ba6dd8b0 100644 --- a/src/sys/net/hasp_network.cpp +++ b/src/sys/net/hasp_network.cpp @@ -75,10 +75,6 @@ void networkLoop(void) httpLoop(); #endif // HTTP -#if HASP_USE_GPIO > 0 - gpioLoop(); -#endif // GPIO - #if HASP_USE_OTA > 0 otaLoop(); #endif // OTA From 0f52d808ea8aadf1a8c80820016dccb68dd4ed07 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 18 Mar 2021 01:53:48 +0100 Subject: [PATCH 216/236] Remove some font logging for esp8266 --- src/hasp/hasp.cpp | 8 ++++---- src/hasp/hasp_attribute.cpp | 2 +- src/main_arduino.cpp | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 3e8ed004..1ede4354 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -93,8 +93,7 @@ lv_obj_t* kb; // lv_font_t * defaultFont; lv_obj_t* pages[HASP_NUM_PAGES]; -static lv_font_t* haspFonts[4] = {LV_THEME_DEFAULT_FONT_SMALL, LV_THEME_DEFAULT_FONT_NORMAL, - LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE}; +static lv_font_t* haspFonts[4] = {nullptr, nullptr, nullptr, nullptr}; uint8_t current_page = 1; /** @@ -363,12 +362,13 @@ void haspSetup(void) /* ********** Font Initializations ********** */ - LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, &robotocondensed_regular_16_nokern); LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, nullptr); LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, haspFonts[1]); + // LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, &robotocondensed_regular_16_nokern); #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + lv_font_t* hasp_font = nullptr; // required or font init will crash lv_zifont_init(); @@ -381,7 +381,7 @@ void haspSetup(void) haspFonts[0] = hasp_font; // save it } - LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_16_nokern); + // LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_16_nokern); LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, *hasp_font); #endif diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 22330ed0..37482e5a 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -454,7 +454,7 @@ static lv_font_t* haspPayloadToFont(const char* payload) switch(var) { case 0 ... 7: - LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_12_nokern); + // LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, robotocondensed_regular_12_nokern); return hasp_get_font(var); case 8: diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index db06a6a1..c863a28a 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -56,7 +56,6 @@ void setup() #if HASP_USE_CONFIG > 0 configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart() #endif - LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, &robotocondensed_regular_16_nokern); guiSetup(); debugSetup(); // Init the console From 83bf62d9d6efbb700d04c9719cc2beab470c3df4 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 18 Mar 2021 23:01:17 +0100 Subject: [PATCH 217/236] Use int16_t type in hasp_process_obj_attribute_val --- src/hasp/hasp_attribute.cpp | 12 ++++++------ src/hasp/hasp_attribute.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 37482e5a..c476165c 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1262,9 +1262,9 @@ static void hasp_process_obj_attribute_txt(lv_obj_t* obj, const char* attr, cons LOG_WARNING(TAG_ATTR, F(D_ATTRIBUTE_UNKNOWN), attr); } -bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, const char* payload, bool update) +bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, int16_t intval, bool boolval, bool update) { - int16_t intval = atoi(payload); + // int16_t intval = atoi(payload); if(check_obj_type(obj, LV_HASP_BUTTON)) { if(lv_btn_get_checkable(obj)) { @@ -1280,11 +1280,10 @@ bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, const char* return false; // not checkable } } else if(check_obj_type(obj, LV_HASP_CHECKBOX)) { - update ? lv_checkbox_set_checked(obj, Utilities::is_true(payload)) - : hasp_out_int(obj, attr, lv_checkbox_is_checked(obj)); + update ? lv_checkbox_set_checked(obj, boolval) : hasp_out_int(obj, attr, lv_checkbox_is_checked(obj)); } else if(check_obj_type(obj, LV_HASP_SWITCH)) { if(update) - Utilities::is_true(payload) ? lv_switch_on(obj, LV_ANIM_ON) : lv_switch_off(obj, LV_ANIM_ON); + boolval ? lv_switch_on(obj, LV_ANIM_ON) : lv_switch_off(obj, LV_ANIM_ON); else hasp_out_int(obj, attr, lv_switch_get_state(obj)); } else if(check_obj_type(obj, LV_HASP_DROPDOWN)) { @@ -1483,7 +1482,8 @@ void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* p break; // attribute_found case ATTR_VAL: - if(!hasp_process_obj_attribute_val(obj, attr, payload, update)) goto attribute_not_found; + if(!hasp_process_obj_attribute_val(obj, attr, atoi(payload), Utilities::is_true(payload), update)) + goto attribute_not_found; break; // attribute_found case ATTR_MIN: diff --git a/src/hasp/hasp_attribute.h b/src/hasp/hasp_attribute.h index 3cc9d3c2..9ca12662 100644 --- a/src/hasp/hasp_attribute.h +++ b/src/hasp/hasp_attribute.h @@ -25,7 +25,7 @@ void my_btnmatrix_map_clear(lv_obj_t* obj); void line_clear_points(lv_obj_t* obj); void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* payload, bool update); -bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, const char* payload, bool update); +bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, int16_t intval, bool booval, bool update); #ifdef __cplusplus } /* extern "C" */ From a5d19a2283573b145ad4e4b26141aa512fce3e8f Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 18 Mar 2021 23:02:06 +0100 Subject: [PATCH 218/236] Testing the use of object_set_group_state --- src/hasp/hasp_object.cpp | 53 +++++++++++++++++++++------------------- src/hasp/hasp_object.h | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 25348977..1e8eb7fe 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -546,24 +546,7 @@ static void cpicker_event_handler(lv_obj_t* obj, lv_event_t event) // ##################### State Changers ######################################################## -// TODO make this a recursive function that goes over all objects only ONCE -void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t* src_obj) -{ - if(groupid == 0) return; - bool state = dispatch_get_event_state(eventid); - - for(uint8_t page = 0; page < HASP_NUM_PAGES; page++) { - uint8_t startid = 1; - for(uint8_t objid = startid; objid < 20; objid++) { - lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(page), objid); - if(obj && obj != src_obj && obj->user_data.groupid == groupid) { // skip source object, if set - lv_obj_set_state(obj, state ? LV_STATE_PRESSED | LV_STATE_CHECKED : LV_STATE_DEFAULT); - } - } - } -} - -void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* payload) +void object_set_group_value(lv_obj_t* parent, uint8_t groupid, int16_t intval) { if(groupid == 0 || parent == nullptr) return; @@ -571,10 +554,10 @@ void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* paylo child = lv_obj_get_child(parent, NULL); while(child) { /* child found, update it */ - if(groupid == child->user_data.groupid) hasp_process_obj_attribute_val(child, NULL, payload, true); + if(groupid == child->user_data.groupid) hasp_process_obj_attribute_val(child, NULL, intval, intval, true); /* update grandchildren */ - object_set_group_value(child, groupid, payload); + object_set_group_value(child, groupid, intval); /* check tabs */ if(check_obj_type(child, LV_HASP_TABVIEW)) { @@ -584,10 +567,10 @@ void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* paylo lv_obj_t* tab = lv_tabview_get_tab(child, i); LOG_VERBOSE(TAG_HASP, F("Found tab %i"), i); if(tab->user_data.groupid && groupid == tab->user_data.groupid) - hasp_process_obj_attribute_val(tab, NULL, payload, true); /* tab found, update it */ + hasp_process_obj_attribute_val(tab, NULL, intval, intval, true); /* tab found, update it */ /* check grandchildren */ - object_set_group_value(tab, groupid, payload); + object_set_group_value(tab, groupid, intval); } //#endif } @@ -597,10 +580,30 @@ void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* paylo } } -void object_set_group_value(uint8_t groupid, int16_t state) +// TODO make this a recursive function that goes over all objects only ONCE +void object_set_group_state(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max) { - char payload[16]; - itoa(state, payload, DEC); + if(groupid == 0) return; + if(min == max) return; + + for(uint8_t page = 0; page < HASP_NUM_PAGES; page++) { + object_set_group_value(get_page_obj(page), groupid, val); + // uint8_t startid = 1; + // for(uint8_t objid = startid; objid < 20; objid++) { + // lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(page), objid); + // if(obj && obj != src_obj && obj->user_data.groupid == groupid) { // skip source object, if set + // LOG_VERBOSE(TAG_HASP, F("Found p%db%d in group %d"), page, objid, groupid); + // lv_obj_set_state(obj, val > 0 ? LV_STATE_PRESSED | LV_STATE_CHECKED : LV_STATE_DEFAULT); + // switch(obj->user_data.objid) { + // case HASP_OBJ_ARC: + // case HASP_OBJ_SLIDER: + // case HASP_OBJ_CHECKBOX: + // hasp_process_obj_attribute_val(); + // default: + // } + // } + // } + } } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/hasp/hasp_object.h b/src/hasp/hasp_object.h index ad88cdf0..7bc486bb 100644 --- a/src/hasp/hasp_object.h +++ b/src/hasp/hasp_object.h @@ -76,7 +76,7 @@ void hasp_send_obj_attribute_int(lv_obj_t* obj, const char* attribute, int32_t v void hasp_send_obj_attribute_color(lv_obj_t* obj, const char* attribute, lv_color_t color); void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload); -void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t* src_obj); +void object_set_group_state(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max); void generic_event_handler(lv_obj_t* obj, lv_event_t event); void toggle_event_handler(lv_obj_t* obj, lv_event_t event); From 7e588181b8ce14898ff436c51df49c20f0adc7a4 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 18 Mar 2021 23:16:55 +0100 Subject: [PATCH 219/236] Add object_set_normalized_group_value --- src/hasp/hasp_dispatch.cpp | 25 +++++++++++++++---------- src/hasp/hasp_object.cpp | 2 +- src/hasp/hasp_object.h | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 41430165..ba16c45b 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -250,8 +250,13 @@ void dispatch_command(const char* topic, const char* payload) /* =============================== Not standard payload commands ===================================== */ if(strlen(topic) == 7 && topic == strstr_P(topic, PSTR("output"))) { - int16_t state = atoi(payload); - dispatch_normalized_group_value(atoi(topic + 6), NULL, state, 0, 1); // + 6 => trim 'output' from the topic + + if(strlen(payload) == 0) { + // reply state + } else { + int16_t state = atoi(payload); + dispatch_normalized_group_value(atoi(topic + 6), NULL, state, 0, 1); // + 6 => trim 'output' from the topic + } // } else if(strcasecmp_P(topic, PSTR("screenshot")) == 0) { // guiTakeScreenshot("/screenshot.bmp"); // Literal String @@ -270,7 +275,7 @@ void dispatch_command(const char* topic, const char* payload) #if HASP_USE_MQTT > 0 } else if(!strcmp_P(topic, PSTR("mqtthost")) || !strcmp_P(topic, PSTR("mqttport")) || - !strcmp_P(topic, PSTR("mqttport")) || !strcmp_P(topic, PSTR("mqttuser")) || + !strcmp_P(topic, PSTR("mqttuser")) || !strcmp_P(topic, PSTR("mqttpass")) || !strcmp_P(topic, PSTR("hostname"))) { // char item[5]; // memset(item, 0, sizeof(item)); @@ -665,7 +670,7 @@ static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const // if(groupid >= 0) { // bool state = dispatch_get_event_state(eventid); // gpio_set_group_onoff(groupid, state); -// object_set_group_state(groupid, eventid, obj); +// object_set_normalized_group_value(groupid, eventid, obj); // } // char payload[8]; @@ -677,7 +682,7 @@ static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const // { // if(groupid >= 0) { // gpio_set_group_value(groupid, state); -// object_set_group_state(groupid, state, obj); +// object_set_normalized_group_value(groupid, state, obj); // } // char payload[8]; @@ -686,13 +691,13 @@ static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const void dispatch_normalized_group_value(uint8_t groupid, lv_obj_t* obj, int16_t val, int16_t min, int16_t max) { - if(groupid > 0) { - LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d (%d-%d)"), groupid, val, min, max); + if(groupid == 0) return; + + LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d (%d-%d)"), groupid, val, min, max); #if HASP_USE_GPIO > 0 - gpio_set_normalized_group_value(groupid, val, min, max); + gpio_set_normalized_group_value(groupid, val, min, max); // Update GPIO states #endif - // object_set_group_state(groupid, value, obj); - } + object_set_normalized_group_value(groupid, obj, val, min, max); // Update onsreen objects } /********************************************** Native Commands ****************************************/ diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 1e8eb7fe..55ee726b 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -581,7 +581,7 @@ void object_set_group_value(lv_obj_t* parent, uint8_t groupid, int16_t intval) } // TODO make this a recursive function that goes over all objects only ONCE -void object_set_group_state(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max) +void object_set_normalized_group_value(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max) { if(groupid == 0) return; if(min == max) return; diff --git a/src/hasp/hasp_object.h b/src/hasp/hasp_object.h index 7bc486bb..dd6c594e 100644 --- a/src/hasp/hasp_object.h +++ b/src/hasp/hasp_object.h @@ -76,7 +76,7 @@ void hasp_send_obj_attribute_int(lv_obj_t* obj, const char* attribute, int32_t v void hasp_send_obj_attribute_color(lv_obj_t* obj, const char* attribute, lv_color_t color); void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload); -void object_set_group_state(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max); +void object_set_normalized_group_value(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max); void generic_event_handler(lv_obj_t* obj, lv_event_t event); void toggle_event_handler(lv_obj_t* obj, lv_event_t event); From bdbff875dc43c4c69b37038d629eabdfb5ea4da4 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 19 Mar 2021 00:18:44 +0100 Subject: [PATCH 220/236] Merge branch '0.4.0-dev' into feature-pagenav --- src/hasp/hasp.cpp | 9 ++------- src/hasp/hasp_object.cpp | 7 +------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 1d2f0bff..a07c62de 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -92,13 +92,8 @@ lv_style_t style_mbox_bg; /*Black bg. style with opacity*/ lv_obj_t* kb; // lv_font_t * defaultFont; -<<<<<<< HEAD -static lv_font_t* haspFonts[4] = {nullptr, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, - LV_THEME_DEFAULT_FONT_TITLE}; -== == == = lv_obj_t * pages[HASP_NUM_PAGES]; static lv_font_t* haspFonts[4] = {nullptr, nullptr, nullptr, nullptr}; uint8_t current_page = 1; ->>>>>>> 0.4.0-dev /** * Get Font ID @@ -529,7 +524,7 @@ void haspGetVersion(char* version, size_t len) void haspClearPage(uint16_t pageid) { - lv_obj_t* page = get_page_obj(pageid); + lv_obj_t* page = haspPages.get_obj(pageid); if(!page || (pageid > HASP_NUM_PAGES)) { LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_PAGE), pageid); } else if(page == lv_layer_sys() /*|| page == lv_layer_top()*/) { @@ -547,7 +542,7 @@ uint8_t haspGetPage() void haspSetPage(uint8_t pageid) { - lv_obj_t* page = get_page_obj(pageid); + lv_obj_t* page = haspPages.get_obj(pageid); if(!page || pageid == 0 || pageid > HASP_NUM_PAGES) { LOG_WARNING(TAG_HASP, F(D_HASP_INVALID_PAGE), pageid); } else { diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 41b3a7fe..743468fc 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -364,7 +364,6 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) return; } -<<<<<<< HEAD hasp_update_sleep_state(); // wakeup? /* If an actionid is attached, perform that action on UP event only */ @@ -377,12 +376,8 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) } else { dispatch_object_generic_event(obj, eventid); // send object event } - dispatch_normalized_group_value(obj->user_data.groupid, NORMALIZE(dispatch_get_event_state(eventid), 0, 1), obj); - == == == = hasp_update_sleep_state(); // wakeup? - dispatch_object_generic_event(obj, eventid); // send object event dispatch_normalized_group_value(obj->user_data.groupid, obj, dispatch_get_event_state(eventid), HASP_EVENT_OFF, HASP_EVENT_ON); ->>>>>>> 0.4.0-dev } /** @@ -602,7 +597,7 @@ void object_set_normalized_group_value(uint8_t groupid, lv_obj_t* src_obj, int16 if(min == max) return; for(uint8_t page = 0; page < HASP_NUM_PAGES; page++) { - object_set_group_value(get_page_obj(page), groupid, val); + object_set_group_value(haspPages.get_obj(page), groupid, val); // uint8_t startid = 1; // for(uint8_t objid = startid; objid < 20; objid++) { // lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(page), objid); From 608fc738526837696784fe1f7501f4a2ba3db2d4 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 19 Mar 2021 01:00:58 +0100 Subject: [PATCH 221/236] Faster transitions --- src/hasp/hasp_page.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hasp/hasp_page.cpp b/src/hasp/hasp_page.cpp index 7a36b9eb..72cf2b95 100644 --- a/src/hasp/hasp_page.cpp +++ b/src/hasp/hasp_page.cpp @@ -56,7 +56,7 @@ void Page::set(uint8_t pageid, lv_scr_load_anim_t animation) } else { LOG_TRACE(TAG_HASP, F(D_HASP_CHANGE_PAGE), pageid); _current_page = pageid; - lv_scr_load_anim(page, animation, 1000, 0, false); + lv_scr_load_anim(page, animation, 500, 0, false); hasp_object_tree(page, pageid, 0); } } From b608e29696ef3661847a5a75d8eb1813cecb02aa Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 19 Mar 2021 01:01:26 +0100 Subject: [PATCH 222/236] Add back/next/prev options --- src/hasp/hasp_dispatch.h | 1 + src/hasp/hasp_object.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 4409dd95..1cae7f74 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -62,6 +62,7 @@ void dispatch_reboot(bool saveConfig); void dispatch_output_idle_state(uint8_t state); void dispatch_output_statusupdate(const char*, const char*); void dispatch_current_state(); +void dispatch_output_current_page(); void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid); bool dispatch_get_event_state(uint8_t eventid); diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 743468fc..75d628fa 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -370,11 +370,19 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) if(obj->user_data.actionid) { if(eventid == HASP_EVENT_UP || eventid == HASP_EVENT_SHORT) { lv_scr_load_anim_t transitionid = (lv_scr_load_anim_t)obj->user_data.transitionid; - haspPages.set(obj->user_data.actionid, transitionid); - dispatch_set_page(obj->user_data.actionid, transitionid); + if(obj->user_data.actionid == HASP_NUM_PAGES + 1) { + haspPages.prev(transitionid); + } else if(obj->user_data.actionid == HASP_NUM_PAGES + 2) { + haspPages.back(transitionid); + } else if(obj->user_data.actionid == HASP_NUM_PAGES + 3) { + haspPages.next(transitionid); + } else { + haspPages.set(obj->user_data.actionid, transitionid); + } + dispatch_output_current_page(); } } else { - dispatch_object_generic_event(obj, eventid); // send object event + dispatch_object_generic_event(obj, eventid); // send normal object event } dispatch_normalized_group_value(obj->user_data.groupid, obj, dispatch_get_event_state(eventid), HASP_EVENT_OFF, HASP_EVENT_ON); @@ -670,7 +678,7 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) /* Page selection */ uint8_t pageid = saved_page_id; if(!config[FPSTR(FP_PAGE)].isNull()) { - config[FPSTR(FP_PAGE)].as(); + pageid = config[FPSTR(FP_PAGE)].as(); config.remove(FPSTR(FP_PAGE)); } From 3f0835821f2f897d5a9f7e582060380eb5c153e0 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Mar 2021 13:53:08 +0100 Subject: [PATCH 223/236] Modify some translations --- src/lang/en_US.h | 2 +- src/lang/nl_NL.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lang/en_US.h b/src/lang/en_US.h index 02a73ae1..9b01a3a1 100644 --- a/src/lang/en_US.h +++ b/src/lang/en_US.h @@ -92,7 +92,7 @@ #define D_OTA_CHECK_UPDATE "Checking updates URL: %s" #define D_OTA_CHECK_COMPLETE "Update check complete" #define D_OTA_CHECK_FAILED "Update check failed: %s" -#define D_OTA_UPDATE_FIRMWARE "OTA Update firmware" +#define D_OTA_UPDATE_FIRMWARE "OTA Firmware Update" #define D_OTA_UPDATE_COMPLETE "OTA Update complete" #define D_OTA_UPDATE_APPLY "Applying Firmware & Reboot" #define D_OTA_UPDATE_FAILED "OTA Update failed" diff --git a/src/lang/nl_NL.h b/src/lang/nl_NL.h index be8d2202..e2b26fc7 100644 --- a/src/lang/nl_NL.h +++ b/src/lang/nl_NL.h @@ -89,13 +89,13 @@ #define D_JSONL_FAILED "JSONL verwerking mislukt op lijn %d" #define D_JSONL_SUCCEEDED "Jsonl volledig verwerkt" -#define D_OTA_CHECK_UPDATE "Checking updates URL: %s" -#define D_OTA_CHECK_COMPLETE "Update check complete" +#define D_OTA_CHECK_UPDATE "Controle update URL: %s" +#define D_OTA_CHECK_COMPLETE "Update controle klaar" #define D_OTA_CHECK_FAILED "Update check failed: %s" -#define D_OTA_UPDATE_FIRMWARE "OTA Update firmware" -#define D_OTA_UPDATE_COMPLETE "OTA Update complete" -#define D_OTA_UPDATE_APPLY "Applying Firmware & Reboot" -#define D_OTA_UPDATE_FAILED "OTA Update failed" +#define D_OTA_UPDATE_FIRMWARE "OTA Firmware bijwerken" +#define D_OTA_UPDATE_COMPLETE "OTA Firmware bijgewerkt" +#define D_OTA_UPDATE_APPLY "Firmware Schrijven & Herstart" +#define D_OTA_UPDATE_FAILED "OTA Update mislukt" #define D_HTTP_HASP_DESIGN "HASP Ontwerp" #define D_HTTP_INFORMATION "Informatie" From 56b0e49bada126a24130bd7a4e130cf8fd74a33f Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Mar 2021 14:38:36 +0100 Subject: [PATCH 224/236] Fix teleperiod setting --- src/log/hasp_debug.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index d95bd3a1..f30989fc 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -95,7 +95,7 @@ extern bool debugAnsiCodes; ConsoleInput debugConsole(&Serial, HASP_CONSOLE_BUFFER); unsigned long debugLastMillis = 0; -uint16_t debugTelePeriod = 300; +extern dispatch_conf_t dispatch_setings; // #if HASP_USE_SYSLOG > 0 // void syslogSend(uint8_t priority, const char * debugText) @@ -158,8 +158,8 @@ bool debugGetConfig(const JsonObject& settings) if(debugSerialBaud != settings[FPSTR(FP_CONFIG_BAUD)].as()) changed = true; settings[FPSTR(FP_CONFIG_BAUD)] = debugSerialBaud; - if(debugTelePeriod != settings[FPSTR(FP_DEBUG_TELEPERIOD)].as()) changed = true; - settings[FPSTR(FP_DEBUG_TELEPERIOD)] = debugTelePeriod; + if(dispatch_setings.teleperiod != settings[FPSTR(FP_DEBUG_TELEPERIOD)].as()) changed = true; + settings[FPSTR(FP_DEBUG_TELEPERIOD)] = dispatch_setings.teleperiod; #if HASP_USE_SYSLOG > 0 if(strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)].as().c_str()) != 0) changed = true; @@ -196,7 +196,7 @@ bool debugSetConfig(const JsonObject& settings) changed |= configSet(debugSerialBaud, settings[FPSTR(FP_CONFIG_BAUD)], F("debugSerialBaud")); /* Teleperiod Settings*/ - changed |= configSet(debugTelePeriod, settings[FPSTR(FP_DEBUG_TELEPERIOD)], F("debugTelePeriod")); + changed |= configSet(dispatch_setings.teleperiod, settings[FPSTR(FP_DEBUG_TELEPERIOD)], F("debugTelePeriod")); /* Syslog Settings*/ #if HASP_USE_SYSLOG > 0 @@ -353,6 +353,7 @@ void debugLoop(void) } } while(keypress != 0); } + void printLocalTime() { char buffer[128]; From a80b3343cc3a7b8aaddc535e19414ee313fcc795 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Mar 2021 14:50:57 +0100 Subject: [PATCH 225/236] Fix teleperiod not saved --- src/sys/svc/hasp_http.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 89b7bdd5..8dd4ebcf 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1605,7 +1605,7 @@ void webHandleDebugConfig() httpMessage += getOption(7488, F("74880"), baudrate == 7488); httpMessage += getOption(11520, F("115200"), baudrate == 11520); httpMessage += F("

Telemetry Period (Seconds, 0=disable) " - "

"); From ec838d6f21864b243176e46ff33d82f6450295e9 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Mar 2021 16:18:41 +0100 Subject: [PATCH 226/236] Code clean-up --- src/hasp/hasp.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index c67e2f21..a84749cb 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -19,8 +19,6 @@ #include "dev/device.h" #endif -#define NORMALIZE(a, b, c) map(a, b, c, 0, 0xFFFFU) - #ifdef __cplusplus extern "C" { #endif From 1c9b2c5d5f98fc79d8156e3dd07712dc273b747d Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 20 Mar 2021 17:44:44 +0100 Subject: [PATCH 227/236] Update partition scheme --- user_setups/esp32/d1-mini-esp32_ili9341.ini | 4 ++++ user_setups/esp32/d132-unoshield_ili9486_parallel.ini | 4 ++++ user_setups/esp32/esp32-dev_ili9488.ini | 4 ++++ user_setups/esp32/esp32-dev_ili9488_parallel.ini | 4 ++++ user_setups/esp32/esp32-touchdown.ini | 4 ++++ user_setups/esp32/huzzah32-featherwing-24.ini | 4 ++++ user_setups/esp32/huzzah32-featherwing-35.ini | 4 ++++ user_setups/esp32/partition_app1704k_spiffs720k.csv | 6 ++++++ user_setups/esp32/ttgo-esp32-poe_ili9341.ini | 4 ++++ user_setups/esp32/wt32-sc01.ini | 4 ++++ 10 files changed, 42 insertions(+) create mode 100644 user_setups/esp32/partition_app1704k_spiffs720k.csv diff --git a/user_setups/esp32/d1-mini-esp32_ili9341.ini b/user_setups/esp32/d1-mini-esp32_ili9341.ini index a3a04a8a..0aa478e1 100644 --- a/user_setups/esp32/d1-mini-esp32_ili9341.ini +++ b/user_setups/esp32/d1-mini-esp32_ili9341.ini @@ -9,6 +9,10 @@ extends = esp32 board = wemos_d1_mini32 +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/d132-unoshield_ili9486_parallel.ini b/user_setups/esp32/d132-unoshield_ili9486_parallel.ini index b1c84d76..9d7deb39 100644 --- a/user_setups/esp32/d132-unoshield_ili9486_parallel.ini +++ b/user_setups/esp32/d132-unoshield_ili9486_parallel.ini @@ -8,6 +8,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/esp32-dev_ili9488.ini b/user_setups/esp32/esp32-dev_ili9488.ini index 6fbcbba4..2046ff56 100644 --- a/user_setups/esp32/esp32-dev_ili9488.ini +++ b/user_setups/esp32/esp32-dev_ili9488.ini @@ -8,6 +8,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/esp32-dev_ili9488_parallel.ini b/user_setups/esp32/esp32-dev_ili9488_parallel.ini index 995ba4a5..6634edac 100644 --- a/user_setups/esp32/esp32-dev_ili9488_parallel.ini +++ b/user_setups/esp32/esp32-dev_ili9488_parallel.ini @@ -9,6 +9,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/esp32-touchdown.ini b/user_setups/esp32/esp32-touchdown.ini index 61ae1322..db075cb8 100644 --- a/user_setups/esp32/esp32-touchdown.ini +++ b/user_setups/esp32/esp32-touchdown.ini @@ -8,6 +8,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/huzzah32-featherwing-24.ini b/user_setups/esp32/huzzah32-featherwing-24.ini index 2c1d23fc..d0accad0 100644 --- a/user_setups/esp32/huzzah32-featherwing-24.ini +++ b/user_setups/esp32/huzzah32-featherwing-24.ini @@ -9,6 +9,10 @@ extends = esp32 board = featheresp32 +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/huzzah32-featherwing-35.ini b/user_setups/esp32/huzzah32-featherwing-35.ini index 0555d4b4..e6195047 100644 --- a/user_setups/esp32/huzzah32-featherwing-35.ini +++ b/user_setups/esp32/huzzah32-featherwing-35.ini @@ -9,6 +9,10 @@ extends = esp32 board = featheresp32 +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/partition_app1704k_spiffs720k.csv b/user_setups/esp32/partition_app1704k_spiffs720k.csv new file mode 100644 index 00000000..cd96d227 --- /dev/null +++ b/user_setups/esp32/partition_app1704k_spiffs720k.csv @@ -0,0 +1,6 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x1A0000, +app1, app, ota_1, 0x1B0000, 0x1A0000, +spiffs, data, spiffs, 0x350000, 0x0B0000, diff --git a/user_setups/esp32/ttgo-esp32-poe_ili9341.ini b/user_setups/esp32/ttgo-esp32-poe_ili9341.ini index 0031aae4..630154fe 100644 --- a/user_setups/esp32/ttgo-esp32-poe_ili9341.ini +++ b/user_setups/esp32/ttgo-esp32-poe_ili9341.ini @@ -10,6 +10,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/wt32-sc01.ini b/user_setups/esp32/wt32-sc01.ini index e63852ff..6a1999a8 100644 --- a/user_setups/esp32/wt32-sc01.ini +++ b/user_setups/esp32/wt32-sc01.ini @@ -9,6 +9,10 @@ extends = esp32 board = esp32dev +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv + build_flags = ${env.build_flags} ${esp32.build_flags} From 68406b2a9b9698eea7cd5d27d8b3eef916631d1f Mon Sep 17 00:00:00 2001 From: arovak Date: Mon, 22 Mar 2021 01:05:03 +0100 Subject: [PATCH 228/236] fix esp8266 core status message --- src/dev/esp8266/esp8266.cpp | 2 +- src/dev/esp8266/esp8266.h | 2 ++ src/hasp/hasp_dispatch.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index 7435133e..9b8c5ec3 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -39,7 +39,7 @@ void Esp8266Device::set_hostname(const char* hostname) const char* Esp8266Device::get_core_version() { - return ESP.getCoreVersion().c_str(); + return _core_version.c_str(); } const char* Esp8266Device::get_chip_model() diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 460cb264..4c48d1ae 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -19,6 +19,7 @@ class Esp8266Device : public BaseDevice { _hostname = "plate"; _backlight_power = 1; _backlight_level = 100; + _core_version = ESP.getCoreVersion().c_str(); #ifdef TFT_BCKL _backlight_pin = TFT_BCKL; #else @@ -49,6 +50,7 @@ class Esp8266Device : public BaseDevice { private: std::string _hostname; + std::string _core_version; uint8_t _backlight_pin; uint8_t _backlight_level; diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index ba16c45b..d177edd3 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -1050,10 +1050,10 @@ void dispatch_output_statusupdate(const char*, const char*) (HASP_NUM_PAGES)); strcat(data, buffer); -#if defined(ARDUINO_ARCH_ESP8266) - snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000); - strcat(data, buffer); -#endif +// #if defined(ARDUINO_ARCH_ESP8266) +// snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000); +// strcat(data, buffer); +// #endif snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), haspTft.get_tft_model(), (TFT_WIDTH), (TFT_HEIGHT)); From 4c26b9ee3afed948bc7ee6ce7211347c93745a7b Mon Sep 17 00:00:00 2001 From: arovak Date: Mon, 22 Mar 2021 01:07:49 +0100 Subject: [PATCH 229/236] update setting min/max attributes --- src/hasp/hasp_attribute.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index c476165c..1ac5d9ea 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1323,7 +1323,7 @@ static void hasp_process_obj_attribute_range(lv_obj_t* obj, const char* attr, co if(check_obj_type(obj, LV_HASP_SLIDER)) { int16_t min = lv_slider_get_min_value(obj); int16_t max = lv_slider_get_max_value(obj); - if(update && (set_min ? val : min) >= (set_max ? val : max)) return; // prevent setting min>=max + if(update && (set_min ? val : min) == (set_max ? val : max)) return; // prevent setting min=max return update ? lv_slider_set_range(obj, set_min ? val : min, set_max ? val : max) : hasp_out_int(obj, attr, set_min ? min : max); } @@ -1331,7 +1331,7 @@ static void hasp_process_obj_attribute_range(lv_obj_t* obj, const char* attr, co if(check_obj_type(obj, LV_HASP_GAUGE)) { int32_t min = lv_gauge_get_min_value(obj); int32_t max = lv_gauge_get_max_value(obj); - if(update && (set_min ? val32 : min) >= (set_max ? val32 : max)) return; // prevent setting min>=max + if(update && (set_min ? val32 : min) == (set_max ? val32 : max)) return; // prevent setting min=max return update ? lv_gauge_set_range(obj, set_min ? val32 : min, set_max ? val32 : max) : hasp_out_int(obj, attr, set_min ? min : max); } @@ -1339,7 +1339,7 @@ static void hasp_process_obj_attribute_range(lv_obj_t* obj, const char* attr, co if(check_obj_type(obj, LV_HASP_ARC)) { int16_t min = lv_arc_get_min_value(obj); int16_t max = lv_arc_get_max_value(obj); - if(update && (set_min ? val : min) >= (set_max ? val : max)) return; // prevent setting min>=max + if(update && (set_min ? val : min) == (set_max ? val : max)) return; // prevent setting min=max return update ? lv_arc_set_range(obj, set_min ? val : min, set_max ? val : max) : hasp_out_int(obj, attr, set_min ? min : max); } @@ -1347,7 +1347,7 @@ static void hasp_process_obj_attribute_range(lv_obj_t* obj, const char* attr, co if(check_obj_type(obj, LV_HASP_BAR)) { int16_t min = lv_bar_get_min_value(obj); int16_t max = lv_bar_get_max_value(obj); - if(update && (set_min ? val : min) >= (set_max ? val : max)) return; // prevent setting min>=max + if(update && (set_min ? val : min) == (set_max ? val : max)) return; // prevent setting min=max return update ? lv_bar_set_range(obj, set_min ? val : min, set_max ? val : max) : hasp_out_int(obj, attr, set_min ? min : max); } @@ -1355,7 +1355,7 @@ static void hasp_process_obj_attribute_range(lv_obj_t* obj, const char* attr, co if(check_obj_type(obj, LV_HASP_LMETER)) { int32_t min = lv_linemeter_get_min_value(obj); int32_t max = lv_linemeter_get_max_value(obj); - if(update && (set_min ? val32 : min) >= (set_max ? val32 : max)) return; // prevent setting min>=max + if(update && (set_min ? val32 : min) == (set_max ? val32 : max)) return; // prevent setting min=max return update ? lv_linemeter_set_range(obj, set_min ? val32 : min, set_max ? val32 : max) : hasp_out_int(obj, attr, set_min ? min : max); } @@ -1363,7 +1363,7 @@ static void hasp_process_obj_attribute_range(lv_obj_t* obj, const char* attr, co if(check_obj_type(obj, LV_HASP_CHART)) { int16_t min = my_chart_get_min_value(obj); int16_t max = my_chart_get_max_value(obj); - if(update && (set_min ? val : min) >= (set_max ? val : max)) return; // prevent setting min>=max + if(update && (set_min ? val : min) == (set_max ? val : max)) return; // prevent setting min=max return update ? lv_chart_set_range(obj, set_min ? val : min, set_max ? val : max) : hasp_out_int(obj, attr, set_min ? min : max); } From 2bf1541f4837f5d283c4f3b5b66644d3b6c0dbd0 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 22 Mar 2021 14:42:34 +0100 Subject: [PATCH 230/236] Font tweaks --- src/hasp/hasp.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index a07c62de..d2be0930 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -326,7 +326,7 @@ void haspSetup(void) /* ********** Font Initializations ********** */ LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, nullptr); - LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, haspFonts[1]); + LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, haspFonts[0]); // LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, &robotocondensed_regular_16_nokern); #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 @@ -338,7 +338,7 @@ void haspSetup(void) // WARNING: hasp_font needs to be null ! if(lv_zifont_font_init(&hasp_font, haspZiFontPath, 32) != 0) { LOG_ERROR(TAG_HASP, F("Failed to set font to %s"), haspZiFontPath); - haspFonts[1] = LV_FONT_DEFAULT; + haspFonts[0] = LV_THEME_DEFAULT_FONT_SMALL; } else { // defaultFont = haspFonts[0]; haspFonts[0] = hasp_font; // save it @@ -351,7 +351,7 @@ void haspSetup(void) #endif if(haspFonts[0] == nullptr) haspFonts[0] = LV_THEME_DEFAULT_FONT_SMALL; - // if(haspFonts[1] == nullptr) haspFonts[1] = LV_THEME_DEFAULT_FONT_NORMAL; + if(haspFonts[1] == nullptr) haspFonts[1] = LV_THEME_DEFAULT_FONT_NORMAL; if(haspFonts[2] == nullptr) haspFonts[2] = LV_THEME_DEFAULT_FONT_SUBTITLE; if(haspFonts[3] == nullptr) haspFonts[3] = LV_THEME_DEFAULT_FONT_TITLE; From 184234bdd0f2ff78e0bb79d3f852e8b1f04e0ede Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Mar 2021 01:00:01 +0100 Subject: [PATCH 231/236] Update config files, add merge_bin firmware --- platformio.ini | 14 +- platformio_override-template.ini | 25 +- tools/esp_merge_bin.py | 97 + tools/esptool_with_merge_bin.py | 4422 +++++++++++++++++ user_setups/esp32/d1-mini-esp32_ili9341.ini | 8 - .../esp32/d132-unoshield_ili9486_parallel.ini | 4 - user_setups/esp32/esp32-dev_ili9488.ini | 4 - .../esp32/esp32-dev_ili9488_parallel.ini | 5 - user_setups/esp32/esp32-touchdown.ini | 4 - user_setups/esp32/esp32cam_st7796.ini | 3 +- user_setups/esp32/huzzah32-featherwing-24.ini | 4 - user_setups/esp32/huzzah32-featherwing-35.ini | 4 - user_setups/esp32/lanbon_l8.ini | 4 - user_setups/esp32/lolin-d32-pro_ili9341.ini | 6 +- user_setups/esp32/m5stack_core2.ini | 4 - user_setups/esp32/ttgo-esp32-poe_ili9341.ini | 6 +- user_setups/esp32/wt32-sc01.ini | 8 - 17 files changed, 4545 insertions(+), 77 deletions(-) create mode 100644 tools/esp_merge_bin.py create mode 100644 tools/esptool_with_merge_bin.py diff --git a/platformio.ini b/platformio.ini index 0cdb3c59..03fc69ac 100644 --- a/platformio.ini +++ b/platformio.ini @@ -86,13 +86,15 @@ lib_deps = src_filter = +<*> -<.git/> - - - - - -extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py ; -- Platform specific build flags [esp32] framework = arduino platform = espressif32 -board_build.partitions = user_setups/esp32/partition_app1536k_spiffs1024k.csv + +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv ; ----- crash reporter monitor_filters = esp32_exception_decoder @@ -143,9 +145,10 @@ ps_ram = -mfix-esp32-psram-cache-issue extra_scripts = - ${env.extra_scripts} - tools/copy_partitions.py + tools/esp_merge_bin.py tools/analyze_elf.py +; ${env.extra_scripts} +; tools/copy_partitions.py ; -- The ESP32 has 2 SPI Hardware Busses available to use: vspi = @@ -191,6 +194,8 @@ build_flags= -D HASP_USE_ETHERNET=0 -D HASP_USE_CONFIG=1 ; Native application, not library +extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py + lib_ignore = ESP32 BLE Arduino GxTFT @@ -200,6 +205,7 @@ lib_ignore = lib_deps = + [stm32f4] framework = arduino platform = ststm32 diff --git a/platformio_override-template.ini b/platformio_override-template.ini index 8ab9c7ab..7202556b 100644 --- a/platformio_override-template.ini +++ b/platformio_override-template.ini @@ -6,11 +6,11 @@ [platformio] extra_configs = ; Uncomment or edit the lines to show more User Setups in the PIO sidebar + ; user_setups/darwin_sdl/*.ini ; user_setups/esp32/*.ini ; user_setups/esp8266/*.ini - ; user_setups/stm32f4xx/*.ini - ; user_setups/darwin_sdl/*.ini ; user_setups/linux_sdl/*.ini + ; user_setups/stm32f4xx/*.ini ; user_setups/win32/*.ini [override] @@ -24,15 +24,16 @@ extra_default_envs = ; Comment unneeded environments or create extra ; d1-mini-esp32_ili9341 ; d1-mini-esp8266_ili9341 - ; lolind32pro-lolintft24 - ; esp32dev-mrb3511 - ; esp12e-st7735 ; d132-unoshield - ; nodemcu32s-raspi + ; esp12e-st7735 + ; esp32dev-mrb3511 ; esp32dev-ili9488 ; lanbon_l8 - ; wt32-sc01 + ; lolin-d32-pro_ili9341 ; my_custom_build + ; nodemcu32s-raspi + ; wt32-sc01 + ; ttgo_esp32_poe-ili9341 ;endregion ;region -- Define your local COM ports for each environment --- @@ -55,16 +56,16 @@ upload_port = 192.168.4.4 ; IP of the ESP upload_protocol = espota ; Use ArduinoOTA after flashing over serial upload_flags = --port=3232 ; --auth=haspadmin ; OTA password -[env:ttgo_esp32_poe-lolintft24] +[env:ttgo_esp32_poe-ili9341] monitor_port = COM9 ; Change to the correct port -;upload_port = ${env:ttgo_esp32_poe-lolintft24.monitor_port} +;upload_port = ${env:ttgo_esp32_poe-ili9341.monitor_port} upload_port = 192.168.4.5 ; IP of the ESP upload_protocol = espota ; Use ArduinoOTA after flashing over serial upload_flags = --port=3232 ; --auth=haspadmin ; OTA password -[env:lolind32pro-lolintft24] -monitor_port = COM3 ; Change to the correct port -upload_port = ${env:lolind32pro-lolintft24.monitor_port} +[env:lolin-d32-pro_ili9341] +monitor_port = COM5 ; Change to the correct port +upload_port = ${env:lolin-d32-pro_ili9341.monitor_port} ;endregion ;region -- Custom Environment configuration example ----------------- diff --git a/tools/esp_merge_bin.py b/tools/esp_merge_bin.py new file mode 100644 index 00000000..1bc1a9c4 --- /dev/null +++ b/tools/esp_merge_bin.py @@ -0,0 +1,97 @@ +Import('env') +import os +import sys +import shutil +import subprocess + +buildFlags = env.ParseFlags(env['BUILD_FLAGS']) +OUTPUT_DIR = "build_output{}".format(os.path.sep) + +platform = env.PioPlatform() +FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") +FRAMEWORK_DIR = "{}{}".format(FRAMEWORK_DIR, os.path.sep) + + +def get_fw_version(source, target, env): + global HASP_VER_MAJ + global HASP_VER_MIN + global HASP_VER_REV + + for item in buildFlags.get("CPPDEFINES"): + if (type(item) is list): + if (item[0]=="HASP_VER_MAJ"): HASP_VER_MAJ = item[1] + if (item[0]=="HASP_VER_MIN"): HASP_VER_MIN = item[1] + if (item[0]=="HASP_VER_REV"): HASP_VER_REV = item[1] + print(" * %s = %s" % (item[0],item[1])) + else: + print(" * %s" % item) + + +def copy_merge_bins(source, target, env): + version = 'v' + str(HASP_VER_MAJ) + '.' + str(HASP_VER_MIN) + '.' + str(HASP_VER_REV) + name =str(target[0]).split(os.path.sep)[2] + flash_size = env.GetProjectOption("board_upload.flash_size") + + bootloader = "{}tools{}sdk{}bin{}bootloader_dio_40m.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, os.path.sep, os.path.sep) + partitions = "{}{}partitions.bin".format(env.subst("$BUILD_DIR"), os.path.sep) + boot_app0 = "{}tools{}partitions{}boot_app0.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, os.path.sep) + firmware_dst ="{}firmware{}{}_full_{}_{}.bin".format(OUTPUT_DIR, os.path.sep, name, flash_size, version) + firmware_src = str(target[0]) + + # check if output directories exist and create if necessary + if not os.path.isdir(OUTPUT_DIR): + os.mkdir(OUTPUT_DIR) + + for d in ['firmware', 'map']: + if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)): + os.mkdir("{}{}".format(OUTPUT_DIR, d)) + + # check if new target files exist and remove if necessary + for f in [firmware_dst]: + if os.path.isfile(f): + os.remove(f) + + print(bootloader) + print(partitions) + print(boot_app0) + print(firmware_src) + print(firmware_dst) + print(flash_size) + + process = subprocess.Popen(['python', 'tools/esptool_with_merge_bin.py', '--chip', 'esp32', 'merge_bin', '--output', firmware_dst, '--flash_mode', 'dio', '--flash_size', flash_size, '0x1000', bootloader, '0x8000', partitions, '0xe000', boot_app0, '0x10000', firmware_src], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + stdout, stderr + print(stdout) + print(stderr) + +def copy_ota(source, target, env): + version = 'v' + str(HASP_VER_MAJ) + '.' + str(HASP_VER_MIN) + '.' + str(HASP_VER_REV) + name =str(target[0]).split(os.path.sep)[2] + + firmware_src = str(target[0]) + firmware_dst ="{}firmware{}{}_ota_{}.bin".format(OUTPUT_DIR, os.path.sep, name, version) + + # check if output directories exist and create if necessary + if not os.path.isdir(OUTPUT_DIR): + os.mkdir(OUTPUT_DIR) + + for d in ['firmware', 'map']: + if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)): + os.mkdir("{}{}".format(OUTPUT_DIR, d)) + + # check if new target files exist and remove if necessary + for f in [firmware_dst]: + if os.path.isfile(f): + os.remove(f) + + print(firmware_src) + print(firmware_dst) + + # copy firmware.bin to firmware/.bin + shutil.copy(firmware_src, firmware_dst) + +env.AddPreAction("$BUILD_DIR/${PROGNAME}.bin", [get_fw_version]) +env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [copy_merge_bins]) +env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [copy_ota]) diff --git a/tools/esptool_with_merge_bin.py b/tools/esptool_with_merge_bin.py new file mode 100644 index 00000000..df16da4c --- /dev/null +++ b/tools/esptool_with_merge_bin.py @@ -0,0 +1,4422 @@ +#!/usr/bin/env python +# +# ESP8266 & ESP32 family ROM Bootloader Utility +# Copyright (C) 2014-2016 Fredrik Ahlberg, Angus Gratton, Espressif Systems (Shanghai) PTE LTD, other contributors as noted. +# https://github.com/espressif/esptool +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +# Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from __future__ import division, print_function + +import argparse +import base64 +import binascii +import copy +import hashlib +import inspect +import io +import itertools +import os +import shlex +import string +import struct +import sys +import time +import zlib + +try: + import serial +except ImportError: + print("Pyserial is not installed for %s. Check the README for installation instructions." % (sys.executable)) + raise + +# check 'serial' is 'pyserial' and not 'serial' https://github.com/espressif/esptool/issues/269 +try: + if "serialization" in serial.__doc__ and "deserialization" in serial.__doc__: + raise ImportError(""" +esptool.py depends on pyserial, but there is a conflict with a currently installed package named 'serial'. + +You may be able to work around this by 'pip uninstall serial; pip install pyserial' \ +but this may break other installed Python software that depends on 'serial'. + +There is no good fix for this right now, apart from configuring virtualenvs. \ +See https://github.com/espressif/esptool/issues/269#issuecomment-385298196 for discussion of the underlying issue(s).""") +except TypeError: + pass # __doc__ returns None for pyserial + +try: + import serial.tools.list_ports as list_ports +except ImportError: + print("The installed version (%s) of pyserial appears to be too old for esptool.py (Python interpreter %s). " + "Check the README for installation instructions." % (sys.VERSION, sys.executable)) + raise +except Exception: + if sys.platform == "darwin": + # swallow the exception, this is a known issue in pyserial+macOS Big Sur preview ref https://github.com/espressif/esptool/issues/540 + list_ports = None + else: + raise + + +__version__ = "3.1-dev" + +MAX_UINT32 = 0xffffffff +MAX_UINT24 = 0xffffff + +DEFAULT_TIMEOUT = 3 # timeout for most flash operations +START_FLASH_TIMEOUT = 20 # timeout for starting flash (may perform erase) +CHIP_ERASE_TIMEOUT = 120 # timeout for full chip erase +MAX_TIMEOUT = CHIP_ERASE_TIMEOUT * 2 # longest any command can run +SYNC_TIMEOUT = 0.1 # timeout for syncing with bootloader +MD5_TIMEOUT_PER_MB = 8 # timeout (per megabyte) for calculating md5sum +ERASE_REGION_TIMEOUT_PER_MB = 30 # timeout (per megabyte) for erasing a region +ERASE_WRITE_TIMEOUT_PER_MB = 40 # timeout (per megabyte) for erasing and writing data +MEM_END_ROM_TIMEOUT = 0.05 # special short timeout for ESP_MEM_END, as it may never respond +DEFAULT_SERIAL_WRITE_TIMEOUT = 10 # timeout for serial port write +DEFAULT_CONNECT_ATTEMPTS = 7 # default number of times to try connection + + +def timeout_per_mb(seconds_per_mb, size_bytes): + """ Scales timeouts which are size-specific """ + result = seconds_per_mb * (size_bytes / 1e6) + if result < DEFAULT_TIMEOUT: + return DEFAULT_TIMEOUT + return result + + +def _chip_to_rom_loader(chip): + return { + 'esp8266': ESP8266ROM, + 'esp32': ESP32ROM, + 'esp32s2': ESP32S2ROM, + 'esp32s3beta2': ESP32S3BETA2ROM, + 'esp32s3beta3': ESP32S3BETA3ROM, + 'esp32c3': ESP32C3ROM, + }[chip] + + +def get_default_connected_device(serial_list, port, connect_attempts, initial_baud, chip='auto', trace=False, + before='default_reset'): + _esp = None + for each_port in reversed(serial_list): + print("Serial port %s" % each_port) + try: + if chip == 'auto': + _esp = ESPLoader.detect_chip(each_port, initial_baud, before, trace, + connect_attempts) + else: + chip_class = _chip_to_rom_loader(chip) + _esp = chip_class(each_port, initial_baud, trace) + _esp.connect(before, connect_attempts) + break + except (FatalError, OSError) as err: + if port is not None: + raise + print("%s failed to connect: %s" % (each_port, err)) + _esp = None + return _esp + + +DETECTED_FLASH_SIZES = {0x12: '256KB', 0x13: '512KB', 0x14: '1MB', + 0x15: '2MB', 0x16: '4MB', 0x17: '8MB', 0x18: '16MB'} + + +def check_supported_function(func, check_func): + """ + Decorator implementation that wraps a check around an ESPLoader + bootloader function to check if it's supported. + + This is used to capture the multidimensional differences in + functionality between the ESP8266 & ESP32/32S2/32S3/32C3 ROM loaders, and the + software stub that runs on both. Not possible to do this cleanly + via inheritance alone. + """ + def inner(*args, **kwargs): + obj = args[0] + if check_func(obj): + return func(*args, **kwargs) + else: + raise NotImplementedInROMError(obj, func) + return inner + + +def stub_function_only(func): + """ Attribute for a function only supported in the software stub loader """ + return check_supported_function(func, lambda o: o.IS_STUB) + + +def stub_and_esp32_function_only(func): + """ Attribute for a function only supported by software stubs or ESP32/32S2/32S3/32C3 ROM """ + return check_supported_function(func, lambda o: o.IS_STUB or isinstance(o, ESP32ROM)) + + +PYTHON2 = sys.version_info[0] < 3 # True if on pre-Python 3 + +# Function to return nth byte of a bitstring +# Different behaviour on Python 2 vs 3 +if PYTHON2: + def byte(bitstr, index): + return ord(bitstr[index]) +else: + def byte(bitstr, index): + return bitstr[index] + +# Provide a 'basestring' class on Python 3 +try: + basestring +except NameError: + basestring = str + + +def print_overwrite(message, last_line=False): + """ Print a message, overwriting the currently printed line. + + If last_line is False, don't append a newline at the end (expecting another subsequent call will overwrite this one.) + + After a sequence of calls with last_line=False, call once with last_line=True. + + If output is not a TTY (for example redirected a pipe), no overwriting happens and this function is the same as print(). + """ + if sys.stdout.isatty(): + print("\r%s" % message, end='\n' if last_line else '') + else: + print(message) + + +def _mask_to_shift(mask): + """ Return the index of the least significant bit in the mask """ + shift = 0 + while mask & 0x1 == 0: + shift += 1 + mask >>= 1 + return shift + + +def esp8266_function_only(func): + """ Attribute for a function only supported on ESP8266 """ + return check_supported_function(func, lambda o: o.CHIP_NAME == "ESP8266") + + +class ESPLoader(object): + """ Base class providing access to ESP ROM & software stub bootloaders. + Subclasses provide ESP8266 & ESP32 specific functionality. + + Don't instantiate this base class directly, either instantiate a subclass or + call ESPLoader.detect_chip() which will interrogate the chip and return the + appropriate subclass instance. + + """ + CHIP_NAME = "Espressif device" + IS_STUB = False + + DEFAULT_PORT = "/dev/ttyUSB0" + + # Commands supported by ESP8266 ROM bootloader + ESP_FLASH_BEGIN = 0x02 + ESP_FLASH_DATA = 0x03 + ESP_FLASH_END = 0x04 + ESP_MEM_BEGIN = 0x05 + ESP_MEM_END = 0x06 + ESP_MEM_DATA = 0x07 + ESP_SYNC = 0x08 + ESP_WRITE_REG = 0x09 + ESP_READ_REG = 0x0a + + # Some comands supported by ESP32 ROM bootloader (or -8266 w/ stub) + ESP_SPI_SET_PARAMS = 0x0B + ESP_SPI_ATTACH = 0x0D + ESP_READ_FLASH_SLOW = 0x0e # ROM only, much slower than the stub flash read + ESP_CHANGE_BAUDRATE = 0x0F + ESP_FLASH_DEFL_BEGIN = 0x10 + ESP_FLASH_DEFL_DATA = 0x11 + ESP_FLASH_DEFL_END = 0x12 + ESP_SPI_FLASH_MD5 = 0x13 + + # Commands supported by ESP32-S2/S3/C3 ROM bootloader only + ESP_GET_SECURITY_INFO = 0x14 + + # Some commands supported by stub only + ESP_ERASE_FLASH = 0xD0 + ESP_ERASE_REGION = 0xD1 + ESP_READ_FLASH = 0xD2 + ESP_RUN_USER_CODE = 0xD3 + + # Flash encryption encrypted data command + ESP_FLASH_ENCRYPT_DATA = 0xD4 + + # Response code(s) sent by ROM + ROM_INVALID_RECV_MSG = 0x05 # response if an invalid message is received + + # Maximum block sized for RAM and Flash writes, respectively. + ESP_RAM_BLOCK = 0x1800 + + FLASH_WRITE_SIZE = 0x400 + + # Default baudrate. The ROM auto-bauds, so we can use more or less whatever we want. + ESP_ROM_BAUD = 115200 + + # First byte of the application image + ESP_IMAGE_MAGIC = 0xe9 + + # Initial state for the checksum routine + ESP_CHECKSUM_MAGIC = 0xef + + # Flash sector size, minimum unit of erase. + FLASH_SECTOR_SIZE = 0x1000 + + UART_DATE_REG_ADDR = 0x60000078 + + CHIP_DETECT_MAGIC_REG_ADDR = 0x40001000 # This ROM address has a different value on each chip model + + UART_CLKDIV_MASK = 0xFFFFF + + # Memory addresses + IROM_MAP_START = 0x40200000 + IROM_MAP_END = 0x40300000 + + # The number of bytes in the UART response that signify command status + STATUS_BYTES_LENGTH = 2 + + def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD, trace_enabled=False): + """Base constructor for ESPLoader bootloader interaction + + Don't call this constructor, either instantiate ESP8266ROM + or ESP32ROM, or use ESPLoader.detect_chip(). + + This base class has all of the instance methods for bootloader + functionality supported across various chips & stub + loaders. Subclasses replace the functions they don't support + with ones which throw NotImplementedInROMError(). + + """ + self.secure_download_mode = False # flag is set to True if esptool detects the ROM is in Secure Download Mode + + if isinstance(port, basestring): + self._port = serial.serial_for_url(port) + else: + self._port = port + self._slip_reader = slip_reader(self._port, self.trace) + # setting baud rate in a separate step is a workaround for + # CH341 driver on some Linux versions (this opens at 9600 then + # sets), shouldn't matter for other platforms/drivers. See + # https://github.com/espressif/esptool/issues/44#issuecomment-107094446 + self._set_port_baudrate(baud) + self._trace_enabled = trace_enabled + # set write timeout, to prevent esptool blocked at write forever. + try: + self._port.write_timeout = DEFAULT_SERIAL_WRITE_TIMEOUT + except NotImplementedError: + # no write timeout for RFC2217 ports + # need to set the property back to None or it will continue to fail + self._port.write_timeout = None + + @property + def serial_port(self): + return self._port.port + + def _set_port_baudrate(self, baud): + try: + self._port.baudrate = baud + except IOError: + raise FatalError("Failed to set baud rate %d. The driver may not support this rate." % baud) + + @staticmethod + def detect_chip(port=DEFAULT_PORT, baud=ESP_ROM_BAUD, connect_mode='default_reset', trace_enabled=False, + connect_attempts=DEFAULT_CONNECT_ATTEMPTS): + """ Use serial access to detect the chip type. + + We use the UART's datecode register for this, it's mapped at + the same address on ESP8266 & ESP32 so we can use one + memory read and compare to the datecode register for each chip + type. + + This routine automatically performs ESPLoader.connect() (passing + connect_mode parameter) as part of querying the chip. + """ + detect_port = ESPLoader(port, baud, trace_enabled=trace_enabled) + detect_port.connect(connect_mode, connect_attempts, detecting=True) + try: + print('Detecting chip type...', end='') + sys.stdout.flush() + chip_magic_value = detect_port.read_reg(ESPLoader.CHIP_DETECT_MAGIC_REG_ADDR) + + for cls in [ESP8266ROM, ESP32ROM, ESP32S2ROM, ESP32S3BETA2ROM, ESP32S3BETA3ROM, ESP32C3ROM]: + if chip_magic_value == cls.CHIP_DETECT_MAGIC_VALUE: + # don't connect a second time + inst = cls(detect_port._port, baud, trace_enabled=trace_enabled) + inst._post_connect() + print(' %s' % inst.CHIP_NAME, end='') + return inst + except UnsupportedCommandError: + raise FatalError("Unsupported Command Error received. Probably this means Secure Download Mode is enabled, " + "autodetection will not work. Need to manually specify the chip.") + finally: + print('') # end line + raise FatalError("Unexpected CHIP magic value 0x%08x. Failed to autodetect chip type." % (chip_magic_value)) + + """ Read a SLIP packet from the serial port """ + def read(self): + return next(self._slip_reader) + + """ Write bytes to the serial port while performing SLIP escaping """ + def write(self, packet): + buf = b'\xc0' \ + + (packet.replace(b'\xdb', b'\xdb\xdd').replace(b'\xc0', b'\xdb\xdc')) \ + + b'\xc0' + self.trace("Write %d bytes: %s", len(buf), HexFormatter(buf)) + self._port.write(buf) + + def trace(self, message, *format_args): + if self._trace_enabled: + now = time.time() + try: + + delta = now - self._last_trace + except AttributeError: + delta = 0.0 + self._last_trace = now + prefix = "TRACE +%.3f " % delta + print(prefix + (message % format_args)) + + """ Calculate checksum of a blob, as it is defined by the ROM """ + @staticmethod + def checksum(data, state=ESP_CHECKSUM_MAGIC): + for b in data: + if type(b) is int: # python 2/3 compat + state ^= b + else: + state ^= ord(b) + + return state + + """ Send a request and read the response """ + def command(self, op=None, data=b"", chk=0, wait_response=True, timeout=DEFAULT_TIMEOUT): + saved_timeout = self._port.timeout + new_timeout = min(timeout, MAX_TIMEOUT) + if new_timeout != saved_timeout: + self._port.timeout = new_timeout + + try: + if op is not None: + self.trace("command op=0x%02x data len=%s wait_response=%d timeout=%.3f data=%s", + op, len(data), 1 if wait_response else 0, timeout, HexFormatter(data)) + pkt = struct.pack(b' self.STATUS_BYTES_LENGTH: + return data[:-self.STATUS_BYTES_LENGTH] + else: # otherwise, just return the 'val' field which comes from the reply header (this is used by read_reg) + return val + + def flush_input(self): + self._port.flushInput() + self._slip_reader = slip_reader(self._port, self.trace) + + def sync(self): + self.command(self.ESP_SYNC, b'\x07\x07\x12\x20' + 32 * b'\x55', + timeout=SYNC_TIMEOUT) + for i in range(7): + self.command() + + def _setDTR(self, state): + self._port.setDTR(state) + + def _setRTS(self, state): + self._port.setRTS(state) + # Work-around for adapters on Windows using the usbser.sys driver: + # generate a dummy change to DTR so that the set-control-line-state + # request is sent with the updated RTS state and the same DTR state + self._port.setDTR(self._port.dtr) + + def _connect_attempt(self, mode='default_reset', esp32r0_delay=False): + """ A single connection attempt, with esp32r0 workaround options """ + # esp32r0_delay is a workaround for bugs with the most common auto reset + # circuit and Windows, if the EN pin on the dev board does not have + # enough capacitance. + # + # Newer dev boards shouldn't have this problem (higher value capacitor + # on the EN pin), and ESP32 revision 1 can't use this workaround as it + # relies on a silicon bug. + # + # Details: https://github.com/espressif/esptool/issues/136 + last_error = None + + # If we're doing no_sync, we're likely communicating as a pass through + # with an intermediate device to the ESP32 + if mode == "no_reset_no_sync": + return last_error + + # issue reset-to-bootloader: + # RTS = either CH_PD/EN or nRESET (both active low = chip in reset + # DTR = GPIO0 (active low = boot to flasher) + # + # DTR & RTS are active low signals, + # ie True = pin @ 0V, False = pin @ VCC. + if mode != 'no_reset': + self._setDTR(False) # IO0=HIGH + self._setRTS(True) # EN=LOW, chip in reset + time.sleep(0.1) + if esp32r0_delay: + # Some chips are more likely to trigger the esp32r0 + # watchdog reset silicon bug if they're held with EN=LOW + # for a longer period + time.sleep(1.2) + self._setDTR(True) # IO0=LOW + self._setRTS(False) # EN=HIGH, chip out of reset + if esp32r0_delay: + # Sleep longer after reset. + # This workaround only works on revision 0 ESP32 chips, + # it exploits a silicon bug spurious watchdog reset. + time.sleep(0.4) # allow watchdog reset to occur + time.sleep(0.05) + self._setDTR(False) # IO0=HIGH, done + + for _ in range(5): + try: + self.flush_input() + self._port.flushOutput() + self.sync() + return None + except FatalError as e: + if esp32r0_delay: + print('_', end='') + else: + print('.', end='') + sys.stdout.flush() + time.sleep(0.05) + last_error = e + return last_error + + def get_memory_region(self, name): + """ Returns a tuple of (start, end) for the memory map entry with the given name, or None if it doesn't exist + """ + try: + return [(start, end) for (start, end, n) in self.MEMORY_MAP if n == name][0] + except IndexError: + return None + + def connect(self, mode='default_reset', attempts=DEFAULT_CONNECT_ATTEMPTS, detecting=False): + """ Try connecting repeatedly until successful, or giving up """ + print('Connecting...', end='') + sys.stdout.flush() + last_error = None + + try: + for _ in range(attempts) if attempts > 0 else itertools.count(): + last_error = self._connect_attempt(mode=mode, esp32r0_delay=False) + if last_error is None: + break + last_error = self._connect_attempt(mode=mode, esp32r0_delay=True) + if last_error is None: + break + finally: + print('') # end 'Connecting...' line + + if last_error is not None: + raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error)) + + if not detecting: + try: + # check the date code registers match what we expect to see + chip_magic_value = self.read_reg(ESPLoader.CHIP_DETECT_MAGIC_REG_ADDR) + if chip_magic_value != self.CHIP_DETECT_MAGIC_VALUE: + actually = None + for cls in [ESP8266ROM, ESP32ROM, ESP32S2ROM, ESP32S3BETA2ROM, ESP32S3BETA3ROM, ESP32C3ROM]: + if chip_magic_value == cls.CHIP_DETECT_MAGIC_VALUE: + actually = cls + break + if actually is None: + print(("WARNING: This chip doesn't appear to be a %s (chip magic value 0x%08x). " + "Probably it is unsupported by this version of esptool.") % (self.CHIP_NAME, chip_magic_value)) + else: + raise FatalError("This chip is %s not %s. Wrong --chip argument?" % (actually.CHIP_NAME, self.CHIP_NAME)) + except UnsupportedCommandError: + self.secure_download_mode = True + self._post_connect() + + def _post_connect(self): + """ + Additional initialization hook, may be overridden by the chip-specific class. + Gets called after connect, and after auto-detection. + """ + pass + + def read_reg(self, addr, timeout=DEFAULT_TIMEOUT): + """ Read memory address in target """ + # we don't call check_command here because read_reg() function is called + # when detecting chip type, and the way we check for success (STATUS_BYTES_LENGTH) is different + # for different chip types (!) + val, data = self.command(self.ESP_READ_REG, struct.pack(' 0: + # add a dummy write to a date register as an excuse to have a delay + command += struct.pack(' start: + raise FatalError(("Software loader is resident at 0x%08x-0x%08x. " + "Can't load binary at overlapping address range 0x%08x-0x%08x. " + "Either change binary loading address, or use the --no-stub " + "option to disable the software loader.") % (start, end, load_start, load_end)) + + return self.check_command("enter RAM download mode", self.ESP_MEM_BEGIN, + struct.pack(' length: + raise FatalError('Read more than expected') + + digest_frame = self.read() + if len(digest_frame) != 16: + raise FatalError('Expected digest, got: %s' % hexify(digest_frame)) + expected_digest = hexify(digest_frame).upper() + digest = hashlib.md5(data).hexdigest().upper() + if digest != expected_digest: + raise FatalError('Digest mismatch: expected %s, got %s' % (expected_digest, digest)) + return data + + def flash_spi_attach(self, hspi_arg): + """Send SPI attach command to enable the SPI flash pins + + ESP8266 ROM does this when you send flash_begin, ESP32 ROM + has it as a SPI command. + """ + # last 3 bytes in ESP_SPI_ATTACH argument are reserved values + arg = struct.pack(' 0: + self.write_reg(SPI_MOSI_DLEN_REG, mosi_bits - 1) + if miso_bits > 0: + self.write_reg(SPI_MISO_DLEN_REG, miso_bits - 1) + else: + + def set_data_lengths(mosi_bits, miso_bits): + SPI_DATA_LEN_REG = SPI_USR1_REG + SPI_MOSI_BITLEN_S = 17 + SPI_MISO_BITLEN_S = 8 + mosi_mask = 0 if (mosi_bits == 0) else (mosi_bits - 1) + miso_mask = 0 if (miso_bits == 0) else (miso_bits - 1) + self.write_reg(SPI_DATA_LEN_REG, + (miso_mask << SPI_MISO_BITLEN_S) | ( + mosi_mask << SPI_MOSI_BITLEN_S)) + + # SPI peripheral "command" bitmasks for SPI_CMD_REG + SPI_CMD_USR = (1 << 18) + + # shift values + SPI_USR2_COMMAND_LEN_SHIFT = 28 + + if read_bits > 32: + raise FatalError("Reading more than 32 bits back from a SPI flash operation is unsupported") + if len(data) > 64: + raise FatalError("Writing more than 64 bytes of data with one SPI command is unsupported") + + data_bits = len(data) * 8 + old_spi_usr = self.read_reg(SPI_USR_REG) + old_spi_usr2 = self.read_reg(SPI_USR2_REG) + flags = SPI_USR_COMMAND + if read_bits > 0: + flags |= SPI_USR_MISO + if data_bits > 0: + flags |= SPI_USR_MOSI + set_data_lengths(data_bits, read_bits) + self.write_reg(SPI_USR_REG, flags) + self.write_reg(SPI_USR2_REG, + (7 << SPI_USR2_COMMAND_LEN_SHIFT) | spiflash_command) + if data_bits == 0: + self.write_reg(SPI_W0_REG, 0) # clear data register before we read it + else: + data = pad_to(data, 4, b'\00') # pad to 32-bit multiple + words = struct.unpack("I" * (len(data) // 4), data) + next_reg = SPI_W0_REG + for word in words: + self.write_reg(next_reg, word) + next_reg += 4 + self.write_reg(SPI_CMD_REG, SPI_CMD_USR) + + def wait_done(): + for _ in range(10): + if (self.read_reg(SPI_CMD_REG) & SPI_CMD_USR) == 0: + return + raise FatalError("SPI command did not complete in time") + wait_done() + + status = self.read_reg(SPI_W0_REG) + # restore some SPI controller registers + self.write_reg(SPI_USR_REG, old_spi_usr) + self.write_reg(SPI_USR2_REG, old_spi_usr2) + return status + + def read_status(self, num_bytes=2): + """Read up to 24 bits (num_bytes) of SPI flash status register contents + via RDSR, RDSR2, RDSR3 commands + + Not all SPI flash supports all three commands. The upper 1 or 2 + bytes may be 0xFF. + """ + SPIFLASH_RDSR = 0x05 + SPIFLASH_RDSR2 = 0x35 + SPIFLASH_RDSR3 = 0x15 + + status = 0 + shift = 0 + for cmd in [SPIFLASH_RDSR, SPIFLASH_RDSR2, SPIFLASH_RDSR3][0:num_bytes]: + status += self.run_spiflash_command(cmd, read_bits=8) << shift + shift += 8 + return status + + def write_status(self, new_status, num_bytes=2, set_non_volatile=False): + """Write up to 24 bits (num_bytes) of new status register + + num_bytes can be 1, 2 or 3. + + Not all flash supports the additional commands to write the + second and third byte of the status register. When writing 2 + bytes, esptool also sends a 16-byte WRSR command (as some + flash types use this instead of WRSR2.) + + If the set_non_volatile flag is set, non-volatile bits will + be set as well as volatile ones (WREN used instead of WEVSR). + + """ + SPIFLASH_WRSR = 0x01 + SPIFLASH_WRSR2 = 0x31 + SPIFLASH_WRSR3 = 0x11 + SPIFLASH_WEVSR = 0x50 + SPIFLASH_WREN = 0x06 + SPIFLASH_WRDI = 0x04 + + enable_cmd = SPIFLASH_WREN if set_non_volatile else SPIFLASH_WEVSR + + # try using a 16-bit WRSR (not supported by all chips) + # this may be redundant, but shouldn't hurt + if num_bytes == 2: + self.run_spiflash_command(enable_cmd) + self.run_spiflash_command(SPIFLASH_WRSR, struct.pack(">= 8 + + self.run_spiflash_command(SPIFLASH_WRDI) + + def get_crystal_freq(self): + # Figure out the crystal frequency from the UART clock divider + # Returns a normalized value in integer MHz (40 or 26 are the only supported values) + # + # The logic here is: + # - We know that our baud rate and the ESP UART baud rate are roughly the same, or we couldn't communicate + # - We can read the UART clock divider register to know how the ESP derives this from the APB bus frequency + # - Multiplying these two together gives us the bus frequency which is either the crystal frequency (ESP32) + # or double the crystal frequency (ESP8266). See the self.XTAL_CLK_DIVIDER parameter for this factor. + uart_div = self.read_reg(self.UART_CLKDIV_REG) & self.UART_CLKDIV_MASK + est_xtal = (self._port.baudrate * uart_div) / 1e6 / self.XTAL_CLK_DIVIDER + norm_xtal = 40 if est_xtal > 33 else 26 + if abs(norm_xtal - est_xtal) > 1: + print("WARNING: Detected crystal freq %.2fMHz is quite different to normalized freq %dMHz. Unsupported crystal in use?" % (est_xtal, norm_xtal)) + return norm_xtal + + def hard_reset(self): + self._setRTS(True) # EN->LOW + time.sleep(0.1) + self._setRTS(False) + + def soft_reset(self, stay_in_bootloader): + if not self.IS_STUB: + if stay_in_bootloader: + return # ROM bootloader is already in bootloader! + else: + # 'run user code' is as close to a soft reset as we can do + self.flash_begin(0, 0) + self.flash_finish(False) + else: + if stay_in_bootloader: + # soft resetting from the stub loader + # will re-load the ROM bootloader + self.flash_begin(0, 0) + self.flash_finish(True) + elif self.CHIP_NAME != "ESP8266": + raise FatalError("Soft resetting is currently only supported on ESP8266") + else: + # running user code from stub loader requires some hacks + # in the stub loader + self.command(self.ESP_RUN_USER_CODE, wait_response=False) + + +class ESP8266ROM(ESPLoader): + """ Access class for ESP8266 ROM bootloader + """ + CHIP_NAME = "ESP8266" + IS_STUB = False + + CHIP_DETECT_MAGIC_VALUE = 0xfff0c101 + + # OTP ROM addresses + ESP_OTP_MAC0 = 0x3ff00050 + ESP_OTP_MAC1 = 0x3ff00054 + ESP_OTP_MAC3 = 0x3ff0005c + + SPI_REG_BASE = 0x60000200 + SPI_USR_OFFS = 0x1c + SPI_USR1_OFFS = 0x20 + SPI_USR2_OFFS = 0x24 + SPI_MOSI_DLEN_OFFS = None + SPI_MISO_DLEN_OFFS = None + SPI_W0_OFFS = 0x40 + + UART_CLKDIV_REG = 0x60000014 + + XTAL_CLK_DIVIDER = 2 + + FLASH_SIZES = { + '512KB': 0x00, + '256KB': 0x10, + '1MB': 0x20, + '2MB': 0x30, + '4MB': 0x40, + '2MB-c1': 0x50, + '4MB-c1': 0x60, + '8MB': 0x80, + '16MB': 0x90, + } + + BOOTLOADER_FLASH_OFFSET = 0 + + MEMORY_MAP = [[0x3FF00000, 0x3FF00010, "DPORT"], + [0x3FFE8000, 0x40000000, "DRAM"], + [0x40100000, 0x40108000, "IRAM"], + [0x40201010, 0x402E1010, "IROM"]] + + def get_efuses(self): + # Return the 128 bits of ESP8266 efuse as a single Python integer + result = self.read_reg(0x3ff0005c) << 96 + result |= self.read_reg(0x3ff00058) << 64 + result |= self.read_reg(0x3ff00054) << 32 + result |= self.read_reg(0x3ff00050) + return result + + def _get_flash_size(self, efuses): + # rX_Y = EFUSE_DATA_OUTX[Y] + r0_4 = (efuses & (1 << 4)) != 0 + r3_25 = (efuses & (1 << 121)) != 0 + r3_26 = (efuses & (1 << 122)) != 0 + r3_27 = (efuses & (1 << 123)) != 0 + + if r0_4 and not r3_25: + if not r3_27 and not r3_26: + return 1 + elif not r3_27 and r3_26: + return 2 + if not r0_4 and r3_25: + if not r3_27 and not r3_26: + return 2 + elif not r3_27 and r3_26: + return 4 + return -1 + + def get_chip_description(self): + efuses = self.get_efuses() + is_8285 = (efuses & ((1 << 4) | 1 << 80)) != 0 # One or the other efuse bit is set for ESP8285 + if is_8285: + flash_size = self._get_flash_size(efuses) + max_temp = (efuses & (1 << 5)) != 0 # This efuse bit identifies the max flash temperature + chip_name = { + 1: "ESP8285H08" if max_temp else "ESP8285N08", + 2: "ESP8285H16" if max_temp else "ESP8285N16" + }.get(flash_size, "ESP8285") + return chip_name + return "ESP8266EX" + + def get_chip_features(self): + features = ["WiFi"] + if "ESP8285" in self.get_chip_description(): + features += ["Embedded Flash"] + return features + + def flash_spi_attach(self, hspi_arg): + if self.IS_STUB: + super(ESP8266ROM, self).flash_spi_attach(hspi_arg) + else: + # ESP8266 ROM has no flash_spi_attach command in serial protocol, + # but flash_begin will do it + self.flash_begin(0, 0) + + def flash_set_parameters(self, size): + # not implemented in ROM, but OK to silently skip for ROM + if self.IS_STUB: + super(ESP8266ROM, self).flash_set_parameters(size) + + def chip_id(self): + """ Read Chip ID from efuse - the equivalent of the SDK system_get_chip_id() function """ + id0 = self.read_reg(self.ESP_OTP_MAC0) + id1 = self.read_reg(self.ESP_OTP_MAC1) + return (id0 >> 24) | ((id1 & MAX_UINT24) << 8) + + def read_mac(self): + """ Read MAC from OTP ROM """ + mac0 = self.read_reg(self.ESP_OTP_MAC0) + mac1 = self.read_reg(self.ESP_OTP_MAC1) + mac3 = self.read_reg(self.ESP_OTP_MAC3) + if (mac3 != 0): + oui = ((mac3 >> 16) & 0xff, (mac3 >> 8) & 0xff, mac3 & 0xff) + elif ((mac1 >> 16) & 0xff) == 0: + oui = (0x18, 0xfe, 0x34) + elif ((mac1 >> 16) & 0xff) == 1: + oui = (0xac, 0xd0, 0x74) + else: + raise FatalError("Unknown OUI") + return oui + ((mac1 >> 8) & 0xff, mac1 & 0xff, (mac0 >> 24) & 0xff) + + def get_erase_size(self, offset, size): + """ Calculate an erase size given a specific size in bytes. + + Provides a workaround for the bootloader erase bug.""" + + sectors_per_block = 16 + sector_size = self.FLASH_SECTOR_SIZE + num_sectors = (size + sector_size - 1) // sector_size + start_sector = offset // sector_size + + head_sectors = sectors_per_block - (start_sector % sectors_per_block) + if num_sectors < head_sectors: + head_sectors = num_sectors + + if num_sectors < 2 * head_sectors: + return (num_sectors + 1) // 2 * sector_size + else: + return (num_sectors - head_sectors) * sector_size + + def override_vddsdio(self, new_voltage): + raise NotImplementedInROMError("Overriding VDDSDIO setting only applies to ESP32") + + +class ESP8266StubLoader(ESP8266ROM): + """ Access class for ESP8266 stub loader, runs on top of ROM. + """ + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.flush_input() # resets _slip_reader + + def get_erase_size(self, offset, size): + return size # stub doesn't have same size bug as ROM loader + + +ESP8266ROM.STUB_CLASS = ESP8266StubLoader + + +class ESP32ROM(ESPLoader): + """Access class for ESP32 ROM bootloader + + """ + CHIP_NAME = "ESP32" + IMAGE_CHIP_ID = 0 + IS_STUB = False + + CHIP_DETECT_MAGIC_VALUE = 0x00f01d83 + + IROM_MAP_START = 0x400d0000 + IROM_MAP_END = 0x40400000 + + DROM_MAP_START = 0x3F400000 + DROM_MAP_END = 0x3F800000 + + # ESP32 uses a 4 byte status reply + STATUS_BYTES_LENGTH = 4 + + SPI_REG_BASE = 0x3ff42000 + SPI_USR_OFFS = 0x1c + SPI_USR1_OFFS = 0x20 + SPI_USR2_OFFS = 0x24 + SPI_MOSI_DLEN_OFFS = 0x28 + SPI_MISO_DLEN_OFFS = 0x2c + EFUSE_RD_REG_BASE = 0x3ff5a000 + + EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT_REG = EFUSE_RD_REG_BASE + 0x18 + EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT = (1 << 7) # EFUSE_RD_DISABLE_DL_ENCRYPT + + DR_REG_SYSCON_BASE = 0x3ff66000 + + SPI_W0_OFFS = 0x80 + + UART_CLKDIV_REG = 0x3ff40014 + + XTAL_CLK_DIVIDER = 1 + + FLASH_SIZES = { + '1MB': 0x00, + '2MB': 0x10, + '4MB': 0x20, + '8MB': 0x30, + '16MB': 0x40 + } + + BOOTLOADER_FLASH_OFFSET = 0x1000 + + OVERRIDE_VDDSDIO_CHOICES = ["1.8V", "1.9V", "OFF"] + + MEMORY_MAP = [[0x00000000, 0x00010000, "PADDING"], + [0x3F400000, 0x3F800000, "DROM"], + [0x3F800000, 0x3FC00000, "EXTRAM_DATA"], + [0x3FF80000, 0x3FF82000, "RTC_DRAM"], + [0x3FF90000, 0x40000000, "BYTE_ACCESSIBLE"], + [0x3FFAE000, 0x40000000, "DRAM"], + [0x3FFE0000, 0x3FFFFFFC, "DIRAM_DRAM"], + [0x40000000, 0x40070000, "IROM"], + [0x40070000, 0x40078000, "CACHE_PRO"], + [0x40078000, 0x40080000, "CACHE_APP"], + [0x40080000, 0x400A0000, "IRAM"], + [0x400A0000, 0x400BFFFC, "DIRAM_IRAM"], + [0x400C0000, 0x400C2000, "RTC_IRAM"], + [0x400D0000, 0x40400000, "IROM"], + [0x50000000, 0x50002000, "RTC_DATA"]] + + FLASH_ENCRYPTED_WRITE_ALIGN = 32 + + """ Try to read the BLOCK1 (encryption key) and check if it is valid """ + + def is_flash_encryption_key_valid(self): + + """ Bit 0 of efuse_rd_disable[3:0] is mapped to BLOCK1 + this bit is at position 16 in EFUSE_BLK0_RDATA0_REG """ + word0 = self.read_efuse(0) + rd_disable = (word0 >> 16) & 0x1 + + # reading of BLOCK1 is NOT ALLOWED so we assume valid key is programmed + if rd_disable: + return True + else: + # reading of BLOCK1 is ALLOWED so we will read and verify for non-zero. + # When ESP32 has not generated AES/encryption key in BLOCK1, the contents will be readable and 0. + # If the flash encryption is enabled it is expected to have a valid non-zero key. We break out on + # first occurance of non-zero value + key_word = [0] * 7 + for i in range(len(key_word)): + key_word[i] = self.read_efuse(14 + i) + # key is non-zero so break & return + if key_word[i] != 0: + return True + return False + + def get_flash_crypt_config(self): + """ For flash encryption related commands we need to make sure + user has programmed all the relevant efuse correctly so before + writing encrypted write_flash_encrypt esptool will verify the values + of flash_crypt_config to be non zero if they are not read + protected. If the values are zero a warning will be printed + + bit 3 in efuse_rd_disable[3:0] is mapped to flash_crypt_config + this bit is at position 19 in EFUSE_BLK0_RDATA0_REG """ + word0 = self.read_efuse(0) + rd_disable = (word0 >> 19) & 0x1 + + if rd_disable == 0: + """ we can read the flash_crypt_config efuse value + so go & read it (EFUSE_BLK0_RDATA5_REG[31:28]) """ + word5 = self.read_efuse(5) + word5 = (word5 >> 28) & 0xF + return word5 + else: + # if read of the efuse is disabled we assume it is set correctly + return 0xF + + def get_encrypted_download_disabled(self): + if self.read_reg(self.EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT_REG) & self.EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT: + return True + else: + return False + + def get_pkg_version(self): + word3 = self.read_efuse(3) + pkg_version = (word3 >> 9) & 0x07 + pkg_version += ((word3 >> 2) & 0x1) << 3 + return pkg_version + + def get_chip_revision(self): + word3 = self.read_efuse(3) + word5 = self.read_efuse(5) + apb_ctl_date = self.read_reg(self.DR_REG_SYSCON_BASE + 0x7C) + + rev_bit0 = (word3 >> 15) & 0x1 + rev_bit1 = (word5 >> 20) & 0x1 + rev_bit2 = (apb_ctl_date >> 31) & 0x1 + if rev_bit0: + if rev_bit1: + if rev_bit2: + return 3 + else: + return 2 + else: + return 1 + return 0 + + def get_chip_description(self): + pkg_version = self.get_pkg_version() + chip_revision = self.get_chip_revision() + rev3 = (chip_revision == 3) + single_core = self.read_efuse(3) & (1 << 0) # CHIP_VER DIS_APP_CPU + + chip_name = { + 0: "ESP32-S0WDQ6" if single_core else "ESP32-D0WDQ6", + 1: "ESP32-S0WD" if single_core else "ESP32-D0WD", + 2: "ESP32-D2WD", + 4: "ESP32-U4WDH", + 5: "ESP32-PICO-V3" if rev3 else "ESP32-PICO-D4", + 6: "ESP32-PICO-V3-02", + }.get(pkg_version, "unknown ESP32") + + # ESP32-D0WD-V3, ESP32-D0WDQ6-V3 + if chip_name.startswith("ESP32-D0WD") and rev3: + chip_name += "-V3" + + return "%s (revision %d)" % (chip_name, chip_revision) + + def get_chip_features(self): + features = ["WiFi"] + word3 = self.read_efuse(3) + + # names of variables in this section are lowercase + # versions of EFUSE names as documented in TRM and + # ESP-IDF efuse_reg.h + + chip_ver_dis_bt = word3 & (1 << 1) + if chip_ver_dis_bt == 0: + features += ["BT"] + + chip_ver_dis_app_cpu = word3 & (1 << 0) + if chip_ver_dis_app_cpu: + features += ["Single Core"] + else: + features += ["Dual Core"] + + chip_cpu_freq_rated = word3 & (1 << 13) + if chip_cpu_freq_rated: + chip_cpu_freq_low = word3 & (1 << 12) + if chip_cpu_freq_low: + features += ["160MHz"] + else: + features += ["240MHz"] + + pkg_version = self.get_pkg_version() + if pkg_version in [2, 4, 5, 6]: + features += ["Embedded Flash"] + + if pkg_version == 6: + features += ["Embedded PSRAM"] + + word4 = self.read_efuse(4) + adc_vref = (word4 >> 8) & 0x1F + if adc_vref: + features += ["VRef calibration in efuse"] + + blk3_part_res = word3 >> 14 & 0x1 + if blk3_part_res: + features += ["BLK3 partially reserved"] + + word6 = self.read_efuse(6) + coding_scheme = word6 & 0x3 + features += ["Coding Scheme %s" % { + 0: "None", + 1: "3/4", + 2: "Repeat (UNSUPPORTED)", + 3: "Invalid"}[coding_scheme]] + + return features + + def read_efuse(self, n): + """ Read the nth word of the ESP3x EFUSE region. """ + return self.read_reg(self.EFUSE_RD_REG_BASE + (4 * n)) + + def chip_id(self): + raise NotSupportedError(self, "chip_id") + + def read_mac(self): + """ Read MAC from EFUSE region """ + words = [self.read_efuse(2), self.read_efuse(1)] + bitstring = struct.pack(">II", *words) + bitstring = bitstring[2:8] # trim the 2 byte CRC + try: + return tuple(ord(b) for b in bitstring) + except TypeError: # Python 3, bitstring elements are already bytes + return tuple(bitstring) + + def get_erase_size(self, offset, size): + return size + + def override_vddsdio(self, new_voltage): + new_voltage = new_voltage.upper() + if new_voltage not in self.OVERRIDE_VDDSDIO_CHOICES: + raise FatalError("The only accepted VDDSDIO overrides are '1.8V', '1.9V' and 'OFF'") + RTC_CNTL_SDIO_CONF_REG = 0x3ff48074 + RTC_CNTL_XPD_SDIO_REG = (1 << 31) + RTC_CNTL_DREFH_SDIO_M = (3 << 29) + RTC_CNTL_DREFM_SDIO_M = (3 << 27) + RTC_CNTL_DREFL_SDIO_M = (3 << 25) + # RTC_CNTL_SDIO_TIEH = (1 << 23) # not used here, setting TIEH=1 would set 3.3V output, not safe for esptool.py to do + RTC_CNTL_SDIO_FORCE = (1 << 22) + RTC_CNTL_SDIO_PD_EN = (1 << 21) + + reg_val = RTC_CNTL_SDIO_FORCE # override efuse setting + reg_val |= RTC_CNTL_SDIO_PD_EN + if new_voltage != "OFF": + reg_val |= RTC_CNTL_XPD_SDIO_REG # enable internal LDO + if new_voltage == "1.9V": + reg_val |= (RTC_CNTL_DREFH_SDIO_M | RTC_CNTL_DREFM_SDIO_M | RTC_CNTL_DREFL_SDIO_M) # boost voltage + self.write_reg(RTC_CNTL_SDIO_CONF_REG, reg_val) + print("VDDSDIO regulator set to %s" % new_voltage) + + def read_flash_slow(self, offset, length, progress_fn): + BLOCK_LEN = 64 # ROM read limit per command (this limit is why it's so slow) + + data = b'' + while len(data) < length: + block_len = min(BLOCK_LEN, length - len(data)) + r = self.check_command("read flash block", self.ESP_READ_FLASH_SLOW, + struct.pack('> 21) & 0x0F + return pkg_version + + def get_chip_description(self): + chip_name = { + 0: "ESP32-S2", + 1: "ESP32-S2FH16", + 2: "ESP32-S2FH32", + }.get(self.get_pkg_version(), "unknown ESP32-S2") + + return "%s" % (chip_name) + + def get_chip_features(self): + features = ["WiFi"] + + if self.secure_download_mode: + features += ["Secure Download Mode Enabled"] + + pkg_version = self.get_pkg_version() + + if pkg_version in [1, 2]: + if pkg_version == 1: + features += ["Embedded 2MB Flash"] + elif pkg_version == 2: + features += ["Embedded 4MB Flash"] + features += ["105C temp rating"] + + num_word = 4 + block2_addr = self.EFUSE_BASE + 0x05C + word4 = self.read_reg(block2_addr + (4 * num_word)) + block2_version = (word4 >> 4) & 0x07 + + if block2_version == 1: + features += ["ADC and temperature sensor calibration in BLK2 of efuse"] + return features + + def get_crystal_freq(self): + # ESP32-S2 XTAL is fixed to 40MHz + return 40 + + def override_vddsdio(self, new_voltage): + raise NotImplementedInROMError("VDD_SDIO overrides are not supported for ESP32-S2") + + def read_mac(self): + mac0 = self.read_reg(self.MAC_EFUSE_REG) + mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC + bitstring = struct.pack(">II", mac1, mac0)[2:] + try: + return tuple(ord(b) for b in bitstring) + except TypeError: # Python 3, bitstring elements are already bytes + return tuple(bitstring) + + def get_flash_crypt_config(self): + return None # doesn't exist on ESP32-S2 + + def get_key_block_purpose(self, key_block): + if key_block < 0 or key_block > 5: + raise FatalError("Valid key block numbers must be in range 0-5") + + reg, shift = [(self.EFUSE_PURPOSE_KEY0_REG, self.EFUSE_PURPOSE_KEY0_SHIFT), + (self.EFUSE_PURPOSE_KEY1_REG, self.EFUSE_PURPOSE_KEY1_SHIFT), + (self.EFUSE_PURPOSE_KEY2_REG, self.EFUSE_PURPOSE_KEY2_SHIFT), + (self.EFUSE_PURPOSE_KEY3_REG, self.EFUSE_PURPOSE_KEY3_SHIFT), + (self.EFUSE_PURPOSE_KEY4_REG, self.EFUSE_PURPOSE_KEY4_SHIFT), + (self.EFUSE_PURPOSE_KEY5_REG, self.EFUSE_PURPOSE_KEY5_SHIFT)][key_block] + return (self.read_reg(reg) >> shift) & 0xF + + def is_flash_encryption_key_valid(self): + # Need to see either an AES-128 key or two AES-256 keys + purposes = [self.get_key_block_purpose(b) for b in range(6)] + + if any(p == self.PURPOSE_VAL_XTS_AES128_KEY for p in purposes): + return True + + return any(p == self.PURPOSE_VAL_XTS_AES256_KEY_1 for p in purposes) \ + and any(p == self.PURPOSE_VAL_XTS_AES256_KEY_2 for p in purposes) + + def uses_usb(self, _cache=[]): + if self.secure_download_mode: + return False # can't detect native USB in secure download mode + if not _cache: + buf_no = self.read_reg(self.UARTDEV_BUF_NO) & 0xff + _cache.append(buf_no == self.UARTDEV_BUF_NO_USB) + return _cache[0] + + def _post_connect(self): + if self.uses_usb(): + self.ESP_RAM_BLOCK = self.USB_RAM_BLOCK + + def _check_if_can_reset(self): + """ + Check the strapping register to see if we can reset out of download mode. + """ + if os.getenv("ESPTOOL_TESTING") is not None: + print("ESPTOOL_TESTING is set, ignoring strapping mode check") + # Esptool tests over USB CDC run with GPIO0 strapped low, don't complain in this case. + return + strap_reg = self.read_reg(self.GPIO_STRAP_REG) + force_dl_reg = self.read_reg(self.RTC_CNTL_OPTION1_REG) + if strap_reg & self.GPIO_STRAP_SPI_BOOT_MASK == 0 and force_dl_reg & self.RTC_CNTL_FORCE_DOWNLOAD_BOOT_MASK == 0: + print("ERROR: {} chip was placed into download mode using GPIO0.\n" + "esptool.py can not exit the download mode over USB. " + "To run the app, reset the chip manually.\n" + "To suppress this error, set --after option to 'no_reset'.".format(self.get_chip_description())) + raise SystemExit(1) + + def hard_reset(self): + if self.uses_usb(): + self._check_if_can_reset() + + self._setRTS(True) # EN->LOW + if self.uses_usb(): + # Give the chip some time to come out of reset, to be able to handle further DTR/RTS transitions + time.sleep(0.2) + self._setRTS(False) + time.sleep(0.2) + else: + self._setRTS(False) + + +class ESP32S3BETA2ROM(ESP32ROM): + CHIP_NAME = "ESP32-S3(beta2)" + IMAGE_CHIP_ID = 4 + + IROM_MAP_START = 0x42000000 + IROM_MAP_END = 0x44000000 + DROM_MAP_START = 0x3c000000 + DROM_MAP_END = 0x3e000000 + + UART_DATE_REG_ADDR = 0x60000080 + + CHIP_DETECT_MAGIC_VALUE = 0xeb004136 + + SPI_REG_BASE = 0x60002000 + SPI_USR_OFFS = 0x18 + SPI_USR1_OFFS = 0x1c + SPI_USR2_OFFS = 0x20 + SPI_MOSI_DLEN_OFFS = 0x24 + SPI_MISO_DLEN_OFFS = 0x28 + SPI_W0_OFFS = 0x58 + + EFUSE_REG_BASE = 0x6001A030 # BLOCK0 read base address + + MAC_EFUSE_REG = 0x6001A000 # ESP32S3 has special block for MAC efuses + + UART_CLKDIV_REG = 0x60000014 + + GPIO_STRAP_REG = 0x60004038 + + MEMORY_MAP = [[0x00000000, 0x00010000, "PADDING"], + [0x3C000000, 0x3D000000, "DROM"], + [0x3D000000, 0x3E000000, "EXTRAM_DATA"], + [0x600FE000, 0x60100000, "RTC_DRAM"], + [0x3FC88000, 0x3FD00000, "BYTE_ACCESSIBLE"], + [0x3FC88000, 0x403E2000, "MEM_INTERNAL"], + [0x3FC88000, 0x3FD00000, "DRAM"], + [0x40000000, 0x4001A100, "IROM_MASK"], + [0x40370000, 0x403E0000, "IRAM"], + [0x600FE000, 0x60100000, "RTC_IRAM"], + [0x42000000, 0x42800000, "IROM"], + [0x50000000, 0x50002000, "RTC_DATA"]] + + def get_chip_description(self): + return "ESP32-S3(beta2)" + + def get_chip_features(self): + return ["WiFi", "BLE"] + + def get_crystal_freq(self): + # ESP32S3 XTAL is fixed to 40MHz + return 40 + + def override_vddsdio(self, new_voltage): + raise NotImplementedInROMError("VDD_SDIO overrides are not supported for ESP32-S3") + + def read_mac(self): + mac0 = self.read_reg(self.MAC_EFUSE_REG) + mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC + bitstring = struct.pack(">II", mac1, mac0)[2:] + try: + return tuple(ord(b) for b in bitstring) + except TypeError: # Python 3, bitstring elements are already bytes + return tuple(bitstring) + + +class ESP32S3BETA3ROM(ESP32ROM): + CHIP_NAME = "ESP32-S3(beta3)" + IMAGE_CHIP_ID = 6 + + IROM_MAP_START = 0x42000000 + IROM_MAP_END = 0x44000000 + DROM_MAP_START = 0x3c000000 + DROM_MAP_END = 0x3e000000 + + UART_DATE_REG_ADDR = 0x60000080 + + CHIP_DETECT_MAGIC_VALUE = 0x9 + + SPI_REG_BASE = 0x60002000 + SPI_USR_OFFS = 0x18 + SPI_USR1_OFFS = 0x1c + SPI_USR2_OFFS = 0x20 + SPI_MOSI_DLEN_OFFS = 0x24 + SPI_MISO_DLEN_OFFS = 0x28 + SPI_W0_OFFS = 0x58 + + EFUSE_BASE = 0x6001A000 # BLOCK0 read base address + + MAC_EFUSE_REG = EFUSE_BASE + 0x044 # ESP32S3 has special block for MAC efuses + + UART_CLKDIV_REG = 0x60000014 + + GPIO_STRAP_REG = 0x60004038 + + MEMORY_MAP = [[0x00000000, 0x00010000, "PADDING"], + [0x3C000000, 0x3D000000, "DROM"], + [0x3D000000, 0x3E000000, "EXTRAM_DATA"], + [0x600FE000, 0x60100000, "RTC_DRAM"], + [0x3FC88000, 0x3FD00000, "BYTE_ACCESSIBLE"], + [0x3FC88000, 0x403E2000, "MEM_INTERNAL"], + [0x3FC88000, 0x3FD00000, "DRAM"], + [0x40000000, 0x4001A100, "IROM_MASK"], + [0x40370000, 0x403E0000, "IRAM"], + [0x600FE000, 0x60100000, "RTC_IRAM"], + [0x42000000, 0x42800000, "IROM"], + [0x50000000, 0x50002000, "RTC_DATA"]] + + def get_chip_description(self): + return "ESP32-S3(beta3)" + + def get_chip_features(self): + return ["WiFi", "BLE"] + + def get_crystal_freq(self): + # ESP32S3 XTAL is fixed to 40MHz + return 40 + + def override_vddsdio(self, new_voltage): + raise NotImplementedInROMError("VDD_SDIO overrides are not supported for ESP32-S3") + + def read_mac(self): + mac0 = self.read_reg(self.MAC_EFUSE_REG) + mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC + bitstring = struct.pack(">II", mac1, mac0)[2:] + try: + return tuple(ord(b) for b in bitstring) + except TypeError: # Python 3, bitstring elements are already bytes + return tuple(bitstring) + + +class ESP32C3ROM(ESP32ROM): + CHIP_NAME = "ESP32-C3" + IMAGE_CHIP_ID = 5 + + IROM_MAP_START = 0x42000000 + IROM_MAP_END = 0x42800000 + DROM_MAP_START = 0x3c000000 + DROM_MAP_END = 0x3c800000 + + SPI_REG_BASE = 0x60002000 + SPI_USR_OFFS = 0x18 + SPI_USR1_OFFS = 0x1C + SPI_USR2_OFFS = 0x20 + SPI_MOSI_DLEN_OFFS = 0x24 + SPI_MISO_DLEN_OFFS = 0x28 + SPI_W0_OFFS = 0x58 + + BOOTLOADER_FLASH_OFFSET = 0x0 + + CHIP_DETECT_MAGIC_VALUE = 0x6921506f + + UART_DATE_REG_ADDR = 0x60000000 + 0x7c + + EFUSE_BASE = 0x60008800 + MAC_EFUSE_REG = EFUSE_BASE + 0x044 + + EFUSE_RD_REG_BASE = EFUSE_BASE + 0x030 # BLOCK0 read base address + + EFUSE_PURPOSE_KEY0_REG = EFUSE_BASE + 0x34 + EFUSE_PURPOSE_KEY0_SHIFT = 24 + EFUSE_PURPOSE_KEY1_REG = EFUSE_BASE + 0x34 + EFUSE_PURPOSE_KEY1_SHIFT = 28 + EFUSE_PURPOSE_KEY2_REG = EFUSE_BASE + 0x38 + EFUSE_PURPOSE_KEY2_SHIFT = 0 + EFUSE_PURPOSE_KEY3_REG = EFUSE_BASE + 0x38 + EFUSE_PURPOSE_KEY3_SHIFT = 4 + EFUSE_PURPOSE_KEY4_REG = EFUSE_BASE + 0x38 + EFUSE_PURPOSE_KEY4_SHIFT = 8 + EFUSE_PURPOSE_KEY5_REG = EFUSE_BASE + 0x38 + EFUSE_PURPOSE_KEY5_SHIFT = 12 + + EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT_REG = EFUSE_RD_REG_BASE + EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT = 1 << 20 + + PURPOSE_VAL_XTS_AES128_KEY = 4 + + GPIO_STRAP_REG = 0x3f404038 + + FLASH_ENCRYPTED_WRITE_ALIGN = 16 + + MEMORY_MAP = [[0x00000000, 0x00010000, "PADDING"], + [0x3C000000, 0x3C800000, "DROM"], + [0x3FC80000, 0x3FCE0000, "DRAM"], + [0x3FC88000, 0x3FD00000, "BYTE_ACCESSIBLE"], + [0x3FF00000, 0x3FF20000, "DROM_MASK"], + [0x40000000, 0x40060000, "IROM_MASK"], + [0x42000000, 0x42800000, "IROM"], + [0x4037C000, 0x403E0000, "IRAM"], + [0x50000000, 0x50002000, "RTC_IRAM"], + [0x50000000, 0x50002000, "RTC_DRAM"], + [0x600FE000, 0x60100000, "MEM_INTERNAL2"]] + + def get_pkg_version(self): + num_word = 3 + block1_addr = self.EFUSE_BASE + 0x044 + word3 = self.read_reg(block1_addr + (4 * num_word)) + pkg_version = (word3 >> 21) & 0x0F + return pkg_version + + def get_chip_revision(self): + # reads WAFER_VERSION field from EFUSE_RD_MAC_SPI_SYS_3_REG + block1_addr = self.EFUSE_BASE + 0x044 + num_word = 3 + pos = 18 + return (self.read_reg(block1_addr + (4 * num_word)) & (0x7 << pos)) >> pos + + def get_chip_description(self): + chip_name = { + 0: "ESP32-C3", + }.get(self.get_pkg_version(), "unknown ESP32-C3") + chip_revision = self.get_chip_revision() + + return "%s (revision %d)" % (chip_name, chip_revision) + + def get_chip_features(self): + return ["Wi-Fi"] + + def get_crystal_freq(self): + # ESP32C3 XTAL is fixed to 40MHz + return 40 + + def override_vddsdio(self, new_voltage): + raise NotImplementedInROMError("VDD_SDIO overrides are not supported for ESP32-C3") + + def read_mac(self): + mac0 = self.read_reg(self.MAC_EFUSE_REG) + mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC + bitstring = struct.pack(">II", mac1, mac0)[2:] + try: + return tuple(ord(b) for b in bitstring) + except TypeError: # Python 3, bitstring elements are already bytes + return tuple(bitstring) + + def get_flash_crypt_config(self): + return None # doesn't exist on ESP32-C3 + + def get_key_block_purpose(self, key_block): + if key_block < 0 or key_block > 5: + raise FatalError("Valid key block numbers must be in range 0-5") + + reg, shift = [(self.EFUSE_PURPOSE_KEY0_REG, self.EFUSE_PURPOSE_KEY0_SHIFT), + (self.EFUSE_PURPOSE_KEY1_REG, self.EFUSE_PURPOSE_KEY1_SHIFT), + (self.EFUSE_PURPOSE_KEY2_REG, self.EFUSE_PURPOSE_KEY2_SHIFT), + (self.EFUSE_PURPOSE_KEY3_REG, self.EFUSE_PURPOSE_KEY3_SHIFT), + (self.EFUSE_PURPOSE_KEY4_REG, self.EFUSE_PURPOSE_KEY4_SHIFT), + (self.EFUSE_PURPOSE_KEY5_REG, self.EFUSE_PURPOSE_KEY5_SHIFT)][key_block] + return (self.read_reg(reg) >> shift) & 0xF + + def is_flash_encryption_key_valid(self): + # Need to see an AES-128 key + purposes = [self.get_key_block_purpose(b) for b in range(6)] + + return any(p == self.PURPOSE_VAL_XTS_AES128_KEY for p in purposes) + + +class ESP32StubLoader(ESP32ROM): + """ Access class for ESP32 stub loader, runs on top of ROM. + """ + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + STATUS_BYTES_LENGTH = 2 # same as ESP8266, different to ESP32 ROM + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.flush_input() # resets _slip_reader + + +ESP32ROM.STUB_CLASS = ESP32StubLoader + + +class ESP32S2StubLoader(ESP32S2ROM): + """ Access class for ESP32-S2 stub loader, runs on top of ROM. + + (Basically the same as ESP32StubLoader, but different base class. + Can possibly be made into a mixin.) + """ + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + STATUS_BYTES_LENGTH = 2 # same as ESP8266, different to ESP32 ROM + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.flush_input() # resets _slip_reader + + if rom_loader.uses_usb(): + self.ESP_RAM_BLOCK = self.USB_RAM_BLOCK + self.FLASH_WRITE_SIZE = self.USB_RAM_BLOCK + + +ESP32S2ROM.STUB_CLASS = ESP32S2StubLoader + + +class ESP32S3BETA2StubLoader(ESP32S3BETA2ROM): + """ Access class for ESP32S3 stub loader, runs on top of ROM. + + (Basically the same as ESP32StubLoader, but different base class. + Can possibly be made into a mixin.) + """ + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + STATUS_BYTES_LENGTH = 2 # same as ESP8266, different to ESP32 ROM + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.flush_input() # resets _slip_reader + + +ESP32S3BETA2ROM.STUB_CLASS = ESP32S3BETA2StubLoader + + +class ESP32S3BETA3StubLoader(ESP32S3BETA3ROM): + """ Access class for ESP32S3 stub loader, runs on top of ROM. + + (Basically the same as ESP32StubLoader, but different base class. + Can possibly be made into a mixin.) + """ + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + STATUS_BYTES_LENGTH = 2 # same as ESP8266, different to ESP32 ROM + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.flush_input() # resets _slip_reader + + +ESP32S3BETA3ROM.STUB_CLASS = ESP32S3BETA3StubLoader + + +class ESP32C3StubLoader(ESP32C3ROM): + """ Access class for ESP32C3 stub loader, runs on top of ROM. + + (Basically the same as ESP32StubLoader, but different base class. + Can possibly be made into a mixin.) + """ + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + STATUS_BYTES_LENGTH = 2 # same as ESP8266, different to ESP32 ROM + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.flush_input() # resets _slip_reader + + +ESP32C3ROM.STUB_CLASS = ESP32C3StubLoader + + +class ESPBOOTLOADER(object): + """ These are constants related to software ESP8266 bootloader, working with 'v2' image files """ + + # First byte of the "v2" application image + IMAGE_V2_MAGIC = 0xea + + # First 'segment' value in a "v2" application image, appears to be a constant version value? + IMAGE_V2_SEGMENT = 4 + + +def LoadFirmwareImage(chip, filename): + """ Load a firmware image. Can be for any supported SoC. + + ESP8266 images will be examined to determine if they are original ROM firmware images (ESP8266ROMFirmwareImage) + or "v2" OTA bootloader images. + + Returns a BaseFirmwareImage subclass, either ESP8266ROMFirmwareImage (v1) or ESP8266V2FirmwareImage (v2). + """ + chip = chip.lower().replace("-", "") + with open(filename, 'rb') as f: + if chip == 'esp32': + return ESP32FirmwareImage(f) + elif chip == "esp32s2": + return ESP32S2FirmwareImage(f) + elif chip == "esp32s3beta2": + return ESP32S3BETA2FirmwareImage(f) + elif chip == "esp32s3beta3": + return ESP32S3BETA3FirmwareImage(f) + elif chip == 'esp32c3': + return ESP32C3FirmwareImage(f) + else: # Otherwise, ESP8266 so look at magic to determine the image type + magic = ord(f.read(1)) + f.seek(0) + if magic == ESPLoader.ESP_IMAGE_MAGIC: + return ESP8266ROMFirmwareImage(f) + elif magic == ESPBOOTLOADER.IMAGE_V2_MAGIC: + return ESP8266V2FirmwareImage(f) + else: + raise FatalError("Invalid image magic number: %d" % magic) + + +class ImageSegment(object): + """ Wrapper class for a segment in an ESP image + (very similar to a section in an ELFImage also) """ + def __init__(self, addr, data, file_offs=None): + self.addr = addr + self.data = data + self.file_offs = file_offs + self.include_in_checksum = True + if self.addr != 0: + self.pad_to_alignment(4) # pad all "real" ImageSegments 4 byte aligned length + + def copy_with_new_addr(self, new_addr): + """ Return a new ImageSegment with same data, but mapped at + a new address. """ + return ImageSegment(new_addr, self.data, 0) + + def split_image(self, split_len): + """ Return a new ImageSegment which splits "split_len" bytes + from the beginning of the data. Remaining bytes are kept in + this segment object (and the start address is adjusted to match.) """ + result = copy.copy(self) + result.data = self.data[:split_len] + self.data = self.data[split_len:] + self.addr += split_len + self.file_offs = None + result.file_offs = None + return result + + def __repr__(self): + r = "len 0x%05x load 0x%08x" % (len(self.data), self.addr) + if self.file_offs is not None: + r += " file_offs 0x%08x" % (self.file_offs) + return r + + def get_memory_type(self, image): + """ + Return a list describing the memory type(s) that is covered by this + segment's start address. + """ + return [map_range[2] for map_range in image.ROM_LOADER.MEMORY_MAP if map_range[0] <= self.addr < map_range[1]] + + def pad_to_alignment(self, alignment): + self.data = pad_to(self.data, alignment, b'\x00') + + +class ELFSection(ImageSegment): + """ Wrapper class for a section in an ELF image, has a section + name as well as the common properties of an ImageSegment. """ + def __init__(self, name, addr, data): + super(ELFSection, self).__init__(addr, data) + self.name = name.decode("utf-8") + + def __repr__(self): + return "%s %s" % (self.name, super(ELFSection, self).__repr__()) + + +class BaseFirmwareImage(object): + SEG_HEADER_LEN = 8 + SHA256_DIGEST_LEN = 32 + + """ Base class with common firmware image functions """ + def __init__(self): + self.segments = [] + self.entrypoint = 0 + self.elf_sha256 = None + self.elf_sha256_offset = 0 + + def load_common_header(self, load_file, expected_magic): + (magic, segments, self.flash_mode, self.flash_size_freq, self.entrypoint) = struct.unpack(' 16: + raise FatalError('Invalid segment count %d (max 16). Usually this indicates a linker script problem.' % len(self.segments)) + + def load_segment(self, f, is_irom_segment=False): + """ Load the next segment from the image file """ + file_offs = f.tell() + (offset, size) = struct.unpack(' 0x40200000 or offset < 0x3ffe0000 or size > 65536: + print('WARNING: Suspicious segment 0x%x, length %d' % (offset, size)) + + def maybe_patch_segment_data(self, f, segment_data): + """If SHA256 digest of the ELF file needs to be inserted into this segment, do so. Returns segment data.""" + segment_len = len(segment_data) + file_pos = f.tell() # file_pos is position in the .bin file + if self.elf_sha256_offset >= file_pos and self.elf_sha256_offset < file_pos + segment_len: + # SHA256 digest needs to be patched into this binary segment, + # calculate offset of the digest inside the binary segment. + patch_offset = self.elf_sha256_offset - file_pos + # Sanity checks + if patch_offset < self.SEG_HEADER_LEN or patch_offset + self.SHA256_DIGEST_LEN > segment_len: + raise FatalError('Cannot place SHA256 digest on segment boundary' + '(elf_sha256_offset=%d, file_pos=%d, segment_size=%d)' % + (self.elf_sha256_offset, file_pos, segment_len)) + # offset relative to the data part + patch_offset -= self.SEG_HEADER_LEN + if segment_data[patch_offset:patch_offset + self.SHA256_DIGEST_LEN] != b'\x00' * self.SHA256_DIGEST_LEN: + raise FatalError('Contents of segment at SHA256 digest offset 0x%x are not all zero. Refusing to overwrite.' % + self.elf_sha256_offset) + assert(len(self.elf_sha256) == self.SHA256_DIGEST_LEN) + segment_data = segment_data[0:patch_offset] + self.elf_sha256 + \ + segment_data[patch_offset + self.SHA256_DIGEST_LEN:] + return segment_data + + def save_segment(self, f, segment, checksum=None): + """ Save the next segment to the image file, return next checksum value if provided """ + segment_data = self.maybe_patch_segment_data(f, segment.data) + f.write(struct.pack(' 0: + if len(irom_segments) != 1: + raise FatalError('Found %d segments that could be irom0. Bad ELF file?' % len(irom_segments)) + return irom_segments[0] + return None + + def get_non_irom_segments(self): + irom_segment = self.get_irom_segment() + return [s for s in self.segments if s != irom_segment] + + def merge_adjacent_segments(self): + if not self.segments: + return # nothing to merge + + segments = [] + # The easiest way to merge the sections is the browse them backward. + for i in range(len(self.segments) - 1, 0, -1): + # elem is the previous section, the one `next_elem` may need to be + # merged in + elem = self.segments[i - 1] + next_elem = self.segments[i] + if all((elem.get_memory_type(self) == next_elem.get_memory_type(self), + elem.include_in_checksum == next_elem.include_in_checksum, + next_elem.addr == elem.addr + len(elem.data))): + # Merge any segment that ends where the next one starts, without spanning memory types + # + # (don't 'pad' any gaps here as they may be excluded from the image due to 'noinit' + # or other reasons.) + elem.data += next_elem.data + else: + # The section next_elem cannot be merged into the previous one, + # which means it needs to be part of the final segments. + # As we are browsing the list backward, the elements need to be + # inserted at the beginning of the final list. + segments.insert(0, next_elem) + + # The first segment will always be here as it cannot be merged into any + # "previous" section. + segments.insert(0, self.segments[0]) + + # note: we could sort segments here as well, but the ordering of segments is sometimes + # important for other reasons (like embedded ELF SHA-256), so we assume that the linker + # script will have produced any adjacent sections in linear order in the ELF, anyhow. + self.segments = segments + + +class ESP8266ROMFirmwareImage(BaseFirmwareImage): + """ 'Version 1' firmware image, segments loaded directly by the ROM bootloader. """ + + ROM_LOADER = ESP8266ROM + + def __init__(self, load_file=None): + super(ESP8266ROMFirmwareImage, self).__init__() + self.flash_mode = 0 + self.flash_size_freq = 0 + self.version = 1 + + if load_file is not None: + segments = self.load_common_header(load_file, ESPLoader.ESP_IMAGE_MAGIC) + + for _ in range(segments): + self.load_segment(load_file) + self.checksum = self.read_checksum(load_file) + + self.verify() + + def default_output_name(self, input_file): + """ Derive a default output name from the ELF name. """ + return input_file + '-' + + def save(self, basename): + """ Save a set of V1 images for flashing. Parameter is a base filename. """ + # IROM data goes in its own plain binary file + irom_segment = self.get_irom_segment() + if irom_segment is not None: + with open("%s0x%05x.bin" % (basename, irom_segment.addr - ESP8266ROM.IROM_MAP_START), "wb") as f: + f.write(irom_segment.data) + + # everything but IROM goes at 0x00000 in an image file + normal_segments = self.get_non_irom_segments() + with open("%s0x00000.bin" % basename, 'wb') as f: + self.write_common_header(f, normal_segments) + checksum = ESPLoader.ESP_CHECKSUM_MAGIC + for segment in normal_segments: + checksum = self.save_segment(f, segment, checksum) + self.append_checksum(f, checksum) + + +ESP8266ROM.BOOTLOADER_IMAGE = ESP8266ROMFirmwareImage + + +class ESP8266V2FirmwareImage(BaseFirmwareImage): + """ 'Version 2' firmware image, segments loaded by software bootloader stub + (ie Espressif bootloader or rboot) + """ + + ROM_LOADER = ESP8266ROM + + def __init__(self, load_file=None): + super(ESP8266V2FirmwareImage, self).__init__() + self.version = 2 + if load_file is not None: + segments = self.load_common_header(load_file, ESPBOOTLOADER.IMAGE_V2_MAGIC) + if segments != ESPBOOTLOADER.IMAGE_V2_SEGMENT: + # segment count is not really segment count here, but we expect to see '4' + print('Warning: V2 header has unexpected "segment" count %d (usually 4)' % segments) + + # irom segment comes before the second header + # + # the file is saved in the image with a zero load address + # in the header, so we need to calculate a load address + irom_segment = self.load_segment(load_file, True) + irom_segment.addr = 0 # for actual mapped addr, add ESP8266ROM.IROM_MAP_START + flashing_addr + 8 + irom_segment.include_in_checksum = False + + first_flash_mode = self.flash_mode + first_flash_size_freq = self.flash_size_freq + first_entrypoint = self.entrypoint + # load the second header + + segments = self.load_common_header(load_file, ESPLoader.ESP_IMAGE_MAGIC) + + if first_flash_mode != self.flash_mode: + print('WARNING: Flash mode value in first header (0x%02x) disagrees with second (0x%02x). Using second value.' + % (first_flash_mode, self.flash_mode)) + if first_flash_size_freq != self.flash_size_freq: + print('WARNING: Flash size/freq value in first header (0x%02x) disagrees with second (0x%02x). Using second value.' + % (first_flash_size_freq, self.flash_size_freq)) + if first_entrypoint != self.entrypoint: + print('WARNING: Entrypoint address in first header (0x%08x) disagrees with second header (0x%08x). Using second value.' + % (first_entrypoint, self.entrypoint)) + + # load all the usual segments + for _ in range(segments): + self.load_segment(load_file) + self.checksum = self.read_checksum(load_file) + + self.verify() + + def default_output_name(self, input_file): + """ Derive a default output name from the ELF name. """ + irom_segment = self.get_irom_segment() + if irom_segment is not None: + irom_offs = irom_segment.addr - ESP8266ROM.IROM_MAP_START + else: + irom_offs = 0 + return "%s-0x%05x.bin" % (os.path.splitext(input_file)[0], + irom_offs & ~(ESPLoader.FLASH_SECTOR_SIZE - 1)) + + def save(self, filename): + with open(filename, 'wb') as f: + # Save first header for irom0 segment + f.write(struct.pack(b' 0: + last_addr = flash_segments[0].addr + for segment in flash_segments[1:]: + if segment.addr // self.IROM_ALIGN == last_addr // self.IROM_ALIGN: + raise FatalError(("Segment loaded at 0x%08x lands in same 64KB flash mapping as segment loaded at 0x%08x. " + "Can't generate binary. Suggest changing linker script or ELF to merge sections.") % + (segment.addr, last_addr)) + last_addr = segment.addr + + def get_alignment_data_needed(segment): + # Actual alignment (in data bytes) required for a segment header: positioned so that + # after we write the next 8 byte header, file_offs % IROM_ALIGN == segment.addr % IROM_ALIGN + # + # (this is because the segment's vaddr may not be IROM_ALIGNed, more likely is aligned + # IROM_ALIGN+0x18 to account for the binary file header + align_past = (segment.addr % self.IROM_ALIGN) - self.SEG_HEADER_LEN + pad_len = (self.IROM_ALIGN - (f.tell() % self.IROM_ALIGN)) + align_past + if pad_len == 0 or pad_len == self.IROM_ALIGN: + return 0 # already aligned + + # subtract SEG_HEADER_LEN a second time, as the padding block has a header as well + pad_len -= self.SEG_HEADER_LEN + if pad_len < 0: + pad_len += self.IROM_ALIGN + return pad_len + + # try to fit each flash segment on a 64kB aligned boundary + # by padding with parts of the non-flash segments... + while len(flash_segments) > 0: + segment = flash_segments[0] + pad_len = get_alignment_data_needed(segment) + if pad_len > 0: # need to pad + if len(ram_segments) > 0 and pad_len > self.SEG_HEADER_LEN: + pad_segment = ram_segments[0].split_image(pad_len) + if len(ram_segments[0].data) == 0: + ram_segments.pop(0) + else: + pad_segment = ImageSegment(0, b'\x00' * pad_len, f.tell()) + checksum = self.save_segment(f, pad_segment, checksum) + total_segments += 1 + else: + # write the flash segment + assert (f.tell() + 8) % self.IROM_ALIGN == segment.addr % self.IROM_ALIGN + checksum = self.save_flash_segment(f, segment, checksum) + flash_segments.pop(0) + total_segments += 1 + + # flash segments all written, so write any remaining RAM segments + for segment in ram_segments: + checksum = self.save_segment(f, segment, checksum) + total_segments += 1 + + if self.secure_pad: + # pad the image so that after signing it will end on a a 64KB boundary. + # This ensures all mapped flash content will be verified. + if not self.append_digest: + raise FatalError("secure_pad only applies if a SHA-256 digest is also appended to the image") + align_past = (f.tell() + self.SEG_HEADER_LEN) % self.IROM_ALIGN + # 16 byte aligned checksum (force the alignment to simplify calculations) + checksum_space = 16 + if self.secure_pad == '1': + # after checksum: SHA-256 digest + (to be added by signing process) version, signature + 12 trailing bytes due to alignment + space_after_checksum = 32 + 4 + 64 + 12 + elif self.secure_pad == '2': # Secure Boot V2 + # after checksum: SHA-256 digest + signature sector, but we place signature sector after the 64KB boundary + space_after_checksum = 32 + pad_len = (self.IROM_ALIGN - align_past - checksum_space - space_after_checksum) % self.IROM_ALIGN + pad_segment = ImageSegment(0, b'\x00' * pad_len, f.tell()) + + checksum = self.save_segment(f, pad_segment, checksum) + total_segments += 1 + + # done writing segments + self.append_checksum(f, checksum) + image_length = f.tell() + + if self.secure_pad: + assert ((image_length + space_after_checksum) % self.IROM_ALIGN) == 0 + + # kinda hacky: go back to the initial header and write the new segment count + # that includes padding segments. This header is not checksummed + f.seek(1) + try: + f.write(chr(total_segments)) + except TypeError: # Python 3 + f.write(bytes([total_segments])) + + if self.append_digest: + # calculate the SHA256 of the whole file and append it + f.seek(0) + digest = hashlib.sha256() + digest.update(f.read(image_length)) + f.write(digest.digest()) + + with open(filename, 'wb') as real_file: + real_file.write(f.getvalue()) + + def save_flash_segment(self, f, segment, checksum=None): + """ Save the next segment to the image file, return next checksum value if provided """ + segment_end_pos = f.tell() + len(segment.data) + self.SEG_HEADER_LEN + segment_len_remainder = segment_end_pos % self.IROM_ALIGN + if segment_len_remainder < 0x24: + # Work around a bug in ESP-IDF 2nd stage bootloader, that it didn't map the + # last MMU page, if an IROM/DROM segment was < 0x24 bytes over the page boundary. + segment.data += b'\x00' * (0x24 - segment_len_remainder) + return self.save_segment(f, segment, checksum) + + def load_extended_header(self, load_file): + def split_byte(n): + return (n & 0x0F, (n >> 4) & 0x0F) + + fields = list(struct.unpack(self.EXTENDED_HEADER_STRUCT_FMT, load_file.read(16))) + + self.wp_pin = fields[0] + + # SPI pin drive stengths are two per byte + self.clk_drv, self.q_drv = split_byte(fields[1]) + self.d_drv, self.cs_drv = split_byte(fields[2]) + self.hd_drv, self.wp_drv = split_byte(fields[3]) + + chip_id = fields[4] + if chip_id != self.ROM_LOADER.IMAGE_CHIP_ID: + print(("Unexpected chip id in image. Expected %d but value was %d. " + "Is this image for a different chip model?") % (self.ROM_LOADER.IMAGE_CHIP_ID, chip_id)) + + # reserved fields in the middle should all be zero + if any(f for f in fields[6:-1] if f != 0): + print("Warning: some reserved header fields have non-zero values. This image may be from a newer esptool.py?") + + append_digest = fields[-1] # last byte is append_digest + if append_digest in [0, 1]: + self.append_digest = (append_digest == 1) + else: + raise RuntimeError("Invalid value for append_digest field (0x%02x). Should be 0 or 1.", append_digest) + + def save_extended_header(self, save_file): + def join_byte(ln, hn): + return (ln & 0x0F) + ((hn & 0x0F) << 4) + + append_digest = 1 if self.append_digest else 0 + + fields = [self.wp_pin, + join_byte(self.clk_drv, self.q_drv), + join_byte(self.d_drv, self.cs_drv), + join_byte(self.hd_drv, self.wp_drv), + self.ROM_LOADER.IMAGE_CHIP_ID, + self.min_rev] + fields += [0] * 8 # padding + fields += [append_digest] + + packed = struct.pack(self.EXTENDED_HEADER_STRUCT_FMT, *fields) + save_file.write(packed) + + +ESP32ROM.BOOTLOADER_IMAGE = ESP32FirmwareImage + + +class ESP32S2FirmwareImage(ESP32FirmwareImage): + """ ESP32S2 Firmware Image almost exactly the same as ESP32FirmwareImage """ + ROM_LOADER = ESP32S2ROM + + +ESP32S2ROM.BOOTLOADER_IMAGE = ESP32S2FirmwareImage + + +class ESP32S3BETA2FirmwareImage(ESP32FirmwareImage): + """ ESP32S3 Firmware Image almost exactly the same as ESP32FirmwareImage """ + ROM_LOADER = ESP32S3BETA2ROM + + +ESP32S3BETA2ROM.BOOTLOADER_IMAGE = ESP32S3BETA2FirmwareImage + + +class ESP32S3BETA3FirmwareImage(ESP32FirmwareImage): + """ ESP32S3 Firmware Image almost exactly the same as ESP32FirmwareImage """ + ROM_LOADER = ESP32S3BETA3ROM + + +ESP32S3BETA3ROM.BOOTLOADER_IMAGE = ESP32S3BETA3FirmwareImage + + +class ESP32C3FirmwareImage(ESP32FirmwareImage): + """ ESP32C3 Firmware Image almost exactly the same as ESP32FirmwareImage """ + ROM_LOADER = ESP32C3ROM + + +ESP32C3ROM.BOOTLOADER_IMAGE = ESP32C3FirmwareImage + + +class ELFFile(object): + SEC_TYPE_PROGBITS = 0x01 + SEC_TYPE_STRTAB = 0x03 + + LEN_SEC_HEADER = 0x28 + + SEG_TYPE_LOAD = 0x01 + LEN_SEG_HEADER = 0x20 + + def __init__(self, name): + # Load sections from the ELF file + self.name = name + with open(self.name, 'rb') as f: + self._read_elf_file(f) + + def get_section(self, section_name): + for s in self.sections: + if s.name == section_name: + return s + raise ValueError("No section %s in ELF file" % section_name) + + def _read_elf_file(self, f): + # read the ELF file header + LEN_FILE_HEADER = 0x34 + try: + (ident, _type, machine, _version, + self.entrypoint, _phoff, shoff, _flags, + _ehsize, _phentsize, _phnum, shentsize, + shnum, shstrndx) = struct.unpack("<16sHHLLLLLHHHHHH", f.read(LEN_FILE_HEADER)) + except struct.error as e: + raise FatalError("Failed to read a valid ELF header from %s: %s" % (self.name, e)) + + if byte(ident, 0) != 0x7f or ident[1:4] != b'ELF': + raise FatalError("%s has invalid ELF magic header" % self.name) + if machine not in [0x5e, 0xf3]: + raise FatalError("%s does not appear to be an Xtensa or an RISCV ELF file. e_machine=%04x" % (self.name, machine)) + if shentsize != self.LEN_SEC_HEADER: + raise FatalError("%s has unexpected section header entry size 0x%x (not 0x%x)" % (self.name, shentsize, self.LEN_SEC_HEADER)) + if shnum == 0: + raise FatalError("%s has 0 section headers" % (self.name)) + self._read_sections(f, shoff, shnum, shstrndx) + self._read_segments(f, _phoff, _phnum, shstrndx) + + def _read_sections(self, f, section_header_offs, section_header_count, shstrndx): + f.seek(section_header_offs) + len_bytes = section_header_count * self.LEN_SEC_HEADER + section_header = f.read(len_bytes) + if len(section_header) == 0: + raise FatalError("No section header found at offset %04x in ELF file." % section_header_offs) + if len(section_header) != (len_bytes): + raise FatalError("Only read 0x%x bytes from section header (expected 0x%x.) Truncated ELF file?" % (len(section_header), len_bytes)) + + # walk through the section header and extract all sections + section_header_offsets = range(0, len(section_header), self.LEN_SEC_HEADER) + + def read_section_header(offs): + name_offs, sec_type, _flags, lma, sec_offs, size = struct.unpack_from(" 0] + self.sections = prog_sections + + def _read_segments(self, f, segment_header_offs, segment_header_count, shstrndx): + f.seek(segment_header_offs) + len_bytes = segment_header_count * self.LEN_SEG_HEADER + segment_header = f.read(len_bytes) + if len(segment_header) == 0: + raise FatalError("No segment header found at offset %04x in ELF file." % segment_header_offs) + if len(segment_header) != (len_bytes): + raise FatalError("Only read 0x%x bytes from segment header (expected 0x%x.) Truncated ELF file?" % (len(segment_header), len_bytes)) + + # walk through the segment header and extract all segments + segment_header_offsets = range(0, len(segment_header), self.LEN_SEG_HEADER) + + def read_segment_header(offs): + seg_type, seg_offs, _vaddr, lma, size, _memsize, _flags, _align = struct.unpack_from(" 0] + self.segments = prog_segments + + def sha256(self): + # return SHA256 hash of the input ELF file + sha256 = hashlib.sha256() + with open(self.name, 'rb') as f: + sha256.update(f.read()) + return sha256.digest() + + +def slip_reader(port, trace_function): + """Generator to read SLIP packets from a serial port. + Yields one full SLIP packet at a time, raises exception on timeout or invalid data. + + Designed to avoid too many calls to serial.read(1), which can bog + down on slow systems. + """ + partial_packet = None + in_escape = False + while True: + waiting = port.inWaiting() + read_bytes = port.read(1 if waiting == 0 else waiting) + if read_bytes == b'': + waiting_for = "header" if partial_packet is None else "content" + trace_function("Timed out waiting for packet %s", waiting_for) + raise FatalError("Timed out waiting for packet %s" % waiting_for) + trace_function("Read %d bytes: %s", len(read_bytes), HexFormatter(read_bytes)) + for b in read_bytes: + if type(b) is int: + b = bytes([b]) # python 2/3 compat + + if partial_packet is None: # waiting for packet header + if b == b'\xc0': + partial_packet = b"" + else: + trace_function("Read invalid data: %s", HexFormatter(read_bytes)) + trace_function("Remaining data in serial buffer: %s", HexFormatter(port.read(port.inWaiting()))) + raise FatalError('Invalid head of packet (0x%s)' % hexify(b)) + elif in_escape: # part-way through escape sequence + in_escape = False + if b == b'\xdc': + partial_packet += b'\xc0' + elif b == b'\xdd': + partial_packet += b'\xdb' + else: + trace_function("Read invalid data: %s", HexFormatter(read_bytes)) + trace_function("Remaining data in serial buffer: %s", HexFormatter(port.read(port.inWaiting()))) + raise FatalError('Invalid SLIP escape (0xdb, 0x%s)' % (hexify(b))) + elif b == b'\xdb': # start of escape sequence + in_escape = True + elif b == b'\xc0': # end of packet + trace_function("Received full packet: %s", HexFormatter(partial_packet)) + yield partial_packet + partial_packet = None + else: # normal byte in packet + partial_packet += b + + +def arg_auto_int(x): + return int(x, 0) + + +def div_roundup(a, b): + """ Return a/b rounded up to nearest integer, + equivalent result to int(math.ceil(float(int(a)) / float(int(b))), only + without possible floating point accuracy errors. + """ + return (int(a) + int(b) - 1) // int(b) + + +def align_file_position(f, size): + """ Align the position in the file to the next block of specified size """ + align = (size - 1) - (f.tell() % size) + f.seek(align, 1) + + +def flash_size_bytes(size): + """ Given a flash size of the type passed in args.flash_size + (ie 512KB or 1MB) then return the size in bytes. + """ + if "MB" in size: + return int(size[:size.index("MB")]) * 1024 * 1024 + elif "KB" in size: + return int(size[:size.index("KB")]) * 1024 + else: + raise FatalError("Unknown size %s" % size) + + +def hexify(s, uppercase=True): + format_str = '%02X' if uppercase else '%02x' + if not PYTHON2: + return ''.join(format_str % c for c in s) + else: + return ''.join(format_str % ord(c) for c in s) + + +class HexFormatter(object): + """ + Wrapper class which takes binary data in its constructor + and returns a hex string as it's __str__ method. + + This is intended for "lazy formatting" of trace() output + in hex format. Avoids overhead (significant on slow computers) + of generating long hex strings even if tracing is disabled. + + Note that this doesn't save any overhead if passed as an + argument to "%", only when passed to trace() + + If auto_split is set (default), any long line (> 16 bytes) will be + printed as separately indented lines, with ASCII decoding at the end + of each line. + """ + def __init__(self, binary_string, auto_split=True): + self._s = binary_string + self._auto_split = auto_split + + def __str__(self): + if self._auto_split and len(self._s) > 16: + result = "" + s = self._s + while len(s) > 0: + line = s[:16] + ascii_line = "".join(c if (c == ' ' or (c in string.printable and c not in string.whitespace)) + else '.' for c in line.decode('ascii', 'replace')) + s = s[16:] + result += "\n %-16s %-16s | %s" % (hexify(line[:8], False), hexify(line[8:], False), ascii_line) + return result + else: + return hexify(self._s, False) + + +def pad_to(data, alignment, pad_character=b'\xFF'): + """ Pad to the next alignment boundary """ + pad_mod = len(data) % alignment + if pad_mod != 0: + data += pad_character * (alignment - pad_mod) + return data + + +class FatalError(RuntimeError): + """ + Wrapper class for runtime errors that aren't caused by internal bugs, but by + ESP8266 responses or input content. + """ + def __init__(self, message): + RuntimeError.__init__(self, message) + + @staticmethod + def WithResult(message, result): + """ + Return a fatal error object that appends the hex values of + 'result' as a string formatted argument. + """ + message += " (result was %s)" % hexify(result) + return FatalError(message) + + +class NotImplementedInROMError(FatalError): + """ + Wrapper class for the error thrown when a particular ESP bootloader function + is not implemented in the ROM bootloader. + """ + def __init__(self, bootloader, func): + FatalError.__init__(self, "%s ROM does not support function %s." % (bootloader.CHIP_NAME, func.__name__)) + + +class NotSupportedError(FatalError): + def __init__(self, esp, function_name): + FatalError.__init__(self, "Function %s is not supported for %s." % (function_name, esp.CHIP_NAME)) + +# "Operation" commands, executable at command line. One function each +# +# Each function takes either two args (, ) or a single +# argument. + + +class UnsupportedCommandError(RuntimeError): + """ + Wrapper class for when ROM loader returns an invalid command response. + + Usually this indicates the loader is running in Secure Download Mode. + """ + def __init__(self, esp, op): + if esp.secure_download_mode: + msg = "This command (0x%x) is not supported in Secure Download Mode" % op + else: + msg = "Invalid (unsupported) command 0x%x" % op + RuntimeError.__init__(self, msg) + + +def load_ram(esp, args): + image = LoadFirmwareImage(esp.CHIP_NAME, args.filename) + + print('RAM boot...') + for seg in image.segments: + size = len(seg.data) + print('Downloading %d bytes at %08x...' % (size, seg.addr), end=' ') + sys.stdout.flush() + esp.mem_begin(size, div_roundup(size, esp.ESP_RAM_BLOCK), esp.ESP_RAM_BLOCK, seg.addr) + + seq = 0 + while len(seg.data) > 0: + esp.mem_block(seg.data[0:esp.ESP_RAM_BLOCK], seq) + seg.data = seg.data[esp.ESP_RAM_BLOCK:] + seq += 1 + print('done!') + + print('All segments done, executing at %08x' % image.entrypoint) + esp.mem_finish(image.entrypoint) + + +def read_mem(esp, args): + print('0x%08x = 0x%08x' % (args.address, esp.read_reg(args.address))) + + +def write_mem(esp, args): + esp.write_reg(args.address, args.value, args.mask, 0) + print('Wrote %08x, mask %08x to %08x' % (args.value, args.mask, args.address)) + + +def dump_mem(esp, args): + with open(args.filename, 'wb') as f: + for i in range(args.size // 4): + d = esp.read_reg(args.address + (i * 4)) + f.write(struct.pack(b'> 16 + args.flash_size = DETECTED_FLASH_SIZES.get(size_id) + if args.flash_size is None: + print('Warning: Could not auto-detect Flash size (FlashID=0x%x, SizeID=0x%x), defaulting to 4MB' % (flash_id, size_id)) + args.flash_size = '4MB' + else: + print('Auto-detected Flash size:', args.flash_size) + + +def _update_image_flash_params(esp, address, args, image): + """ Modify the flash mode & size bytes if this looks like an executable bootloader image """ + if len(image) < 8: + return image # not long enough to be a bootloader image + + # unpack the (potential) image header + magic, _, flash_mode, flash_size_freq = struct.unpack("BBBB", image[:4]) + if address != esp.BOOTLOADER_FLASH_OFFSET: + return image # not flashing bootloader offset, so don't modify this + + if (args.flash_mode, args.flash_freq, args.flash_size) == ('keep',) * 3: + return image # all settings are 'keep', not modifying anything + + # easy check if this is an image: does it start with a magic byte? + if magic != esp.ESP_IMAGE_MAGIC: + print("Warning: Image file at 0x%x doesn't look like an image file, so not changing any flash settings." % address) + return image + + # make sure this really is an image, and not just data that + # starts with esp.ESP_IMAGE_MAGIC (mostly a problem for encrypted + # images that happen to start with a magic byte + try: + test_image = esp.BOOTLOADER_IMAGE(io.BytesIO(image)) + test_image.verify() + except Exception: + print("Warning: Image file at 0x%x is not a valid %s image, so not changing any flash settings." % (address, esp.CHIP_NAME)) + return image + + if args.flash_mode != 'keep': + flash_mode = {'qio': 0, 'qout': 1, 'dio': 2, 'dout': 3}[args.flash_mode] + + flash_freq = flash_size_freq & 0x0F + if args.flash_freq != 'keep': + flash_freq = {'40m': 0, '26m': 1, '20m': 2, '80m': 0xf}[args.flash_freq] + + flash_size = flash_size_freq & 0xF0 + if args.flash_size != 'keep': + flash_size = esp.parse_flash_size_arg(args.flash_size) + + flash_params = struct.pack(b'BB', flash_mode, flash_size + flash_freq) + if flash_params != image[2:4]: + print('Flash params set to 0x%04x' % struct.unpack(">H", flash_params)) + image = image[0:2] + flash_params + image[4:] + return image + + +def write_flash(esp, args): + # set args.compress based on default behaviour: + # -> if either --compress or --no-compress is set, honour that + # -> otherwise, set --compress unless --no-stub is set + if args.compress is None and not args.no_compress: + args.compress = not args.no_stub + + # In case we have encrypted files to write, we first do few sanity checks before actual flash + if args.encrypt or args.encrypt_files is not None: + do_write = True + + if not esp.secure_download_mode: + if esp.get_encrypted_download_disabled(): + raise FatalError("This chip has encrypt functionality in UART download mode disabled. " + "This is the Flash Encryption configuration for Production mode instead of Development mode.") + + crypt_cfg_efuse = esp.get_flash_crypt_config() + + if crypt_cfg_efuse is not None and crypt_cfg_efuse != 0xF: + print('Unexpected FLASH_CRYPT_CONFIG value: 0x%x' % (crypt_cfg_efuse)) + do_write = False + + enc_key_valid = esp.is_flash_encryption_key_valid() + + if not enc_key_valid: + print('Flash encryption key is not programmed') + do_write = False + + # Determine which files list contain the ones to encrypt + files_to_encrypt = args.addr_filename if args.encrypt else args.encrypt_files + + for address, argfile in files_to_encrypt: + if address % esp.FLASH_ENCRYPTED_WRITE_ALIGN: + print("File %s address 0x%x is not %d byte aligned, can't flash encrypted" % + (argfile.name, address, esp.FLASH_ENCRYPTED_WRITE_ALIGN)) + do_write = False + + if not do_write and not args.ignore_flash_encryption_efuse_setting: + raise FatalError("Can't perform encrypted flash write, consult Flash Encryption documentation for more information") + + # verify file sizes fit in flash + if args.flash_size != 'keep': # TODO: check this even with 'keep' + flash_end = flash_size_bytes(args.flash_size) + for address, argfile in args.addr_filename: + argfile.seek(0, 2) # seek to end + if address + argfile.tell() > flash_end: + raise FatalError(("File %s (length %d) at offset %d will not fit in %d bytes of flash. " + "Use --flash-size argument, or change flashing address.") + % (argfile.name, argfile.tell(), address, flash_end)) + argfile.seek(0) + + if args.erase_all: + erase_flash(esp, args) + + """ Create a list describing all the files we have to flash. Each entry holds an "encrypt" flag + marking whether the file needs encryption or not. This list needs to be sorted. + + First, append to each entry of our addr_filename list the flag args.encrypt + For example, if addr_filename is [(0x1000, "partition.bin"), (0x8000, "bootloader")], + all_files will be [(0x1000, "partition.bin", args.encrypt), (0x8000, "bootloader", args.encrypt)], + where, of course, args.encrypt is either True or False + """ + all_files = [(offs, filename, args.encrypt) for (offs, filename) in args.addr_filename] + + """Now do the same with encrypt_files list, if defined. + In this case, the flag is True + """ + if args.encrypt_files is not None: + encrypted_files_flag = [(offs, filename, True) for (offs, filename) in args.encrypt_files] + + # Concatenate both lists and sort them. + # As both list are already sorted, we could simply do a merge instead, + # but for the sake of simplicity and because the lists are very small, + # let's use sorted. + all_files = sorted(all_files + encrypted_files_flag, key=lambda x: x[0]) + + for address, argfile, encrypted in all_files: + compress = args.compress + + # Check whether we can compress the current file before flashing + if compress and encrypted: + print('\nWARNING: - compress and encrypt options are mutually exclusive ') + print('Will flash %s uncompressed' % argfile.name) + compress = False + + if args.no_stub: + print('Erasing flash...') + image = pad_to(argfile.read(), esp.FLASH_ENCRYPTED_WRITE_ALIGN if encrypted else 4) + if len(image) == 0: + print('WARNING: File %s is empty' % argfile.name) + continue + image = _update_image_flash_params(esp, address, args, image) + calcmd5 = hashlib.md5(image).hexdigest() + uncsize = len(image) + if compress: + uncimage = image + image = zlib.compress(uncimage, 9) + # Decompress the compressed binary a block at a time, to dynamically calculate the + # timeout based on the real write size + decompress = zlib.decompressobj() + blocks = esp.flash_defl_begin(uncsize, len(image), address) + else: + blocks = esp.flash_begin(uncsize, address, begin_rom_encrypted=encrypted) + argfile.seek(0) # in case we need it again + seq = 0 + bytes_sent = 0 # bytes sent on wire + bytes_written = 0 # bytes written to flash + t = time.time() + + timeout = DEFAULT_TIMEOUT + + while len(image) > 0: + print_overwrite('Writing at 0x%08x... (%d %%)' % (address + bytes_written, 100 * (seq + 1) // blocks)) + sys.stdout.flush() + block = image[0:esp.FLASH_WRITE_SIZE] + if compress: + # feeding each compressed block into the decompressor lets us see block-by-block how much will be written + block_uncompressed = len(decompress.decompress(block)) + bytes_written += block_uncompressed + block_timeout = max(DEFAULT_TIMEOUT, timeout_per_mb(ERASE_WRITE_TIMEOUT_PER_MB, block_uncompressed)) + if not esp.IS_STUB: + timeout = block_timeout # ROM code writes block to flash before ACKing + esp.flash_defl_block(block, seq, timeout=timeout) + if esp.IS_STUB: + timeout = block_timeout # Stub ACKs when block is received, then writes to flash while receiving the block after it + else: + # Pad the last block + block = block + b'\xff' * (esp.FLASH_WRITE_SIZE - len(block)) + if encrypted: + esp.flash_encrypt_block(block, seq) + else: + esp.flash_block(block, seq) + bytes_written += len(block) + bytes_sent += len(block) + image = image[esp.FLASH_WRITE_SIZE:] + seq += 1 + + if esp.IS_STUB: + # Stub only writes each block to flash after 'ack'ing the receive, so do a final dummy operation which will + # not be 'ack'ed until the last block has actually been written out to flash + esp.read_reg(ESPLoader.CHIP_DETECT_MAGIC_REG_ADDR, timeout=timeout) + + t = time.time() - t + speed_msg = "" + if compress: + if t > 0.0: + speed_msg = " (effective %.1f kbit/s)" % (uncsize / t * 8 / 1000) + print_overwrite('Wrote %d bytes (%d compressed) at 0x%08x in %.1f seconds%s...' % (uncsize, + bytes_sent, + address, t, speed_msg), last_line=True) + else: + if t > 0.0: + speed_msg = " (%.1f kbit/s)" % (bytes_written / t * 8 / 1000) + print_overwrite('Wrote %d bytes at 0x%08x in %.1f seconds%s...' % (bytes_written, address, t, speed_msg), last_line=True) + + if not encrypted and not esp.secure_download_mode: + try: + res = esp.flash_md5sum(address, uncsize) + if res != calcmd5: + print('File md5: %s' % calcmd5) + print('Flash md5: %s' % res) + print('MD5 of 0xFF is %s' % (hashlib.md5(b'\xFF' * uncsize).hexdigest())) + raise FatalError("MD5 of file does not match data in flash!") + else: + print('Hash of data verified.') + except NotImplementedInROMError: + pass + + print('\nLeaving...') + + if esp.IS_STUB: + # skip sending flash_finish to ROM loader here, + # as it causes the loader to exit and run user code + esp.flash_begin(0, 0) + + # Get the "encrypted" flag for the last file flashed + # Note: all_files list contains triplets like: + # (address: Integer, filename: String, encrypted: Boolean) + last_file_encrypted = all_files[-1][2] + + # Check whether the last file flashed was compressed or not + if args.compress and not last_file_encrypted: + esp.flash_defl_finish(False) + else: + esp.flash_finish(False) + + if args.verify: + print('Verifying just-written flash...') + print('(This option is deprecated, flash contents are now always read back after flashing.)') + # If some encrypted files have been flashed print a warning saying that we won't check them + if args.encrypt or args.encrypt_files is not None: + print('WARNING: - cannot verify encrypted files, they will be ignored') + # Call verify_flash function only if there at least one non-encrypted file flashed + if not args.encrypt: + verify_flash(esp, args) + + +def image_info(args): + image = LoadFirmwareImage(args.chip, args.filename) + print('Image version: %d' % image.version) + print('Entry point: %08x' % image.entrypoint if image.entrypoint != 0 else 'Entry point not set') + print('%d segments' % len(image.segments)) + print() + idx = 0 + for seg in image.segments: + idx += 1 + segs = seg.get_memory_type(image) + seg_name = ",".join(segs) + print('Segment %d: %r [%s]' % (idx, seg, seg_name)) + calc_checksum = image.calculate_checksum() + print('Checksum: %02x (%s)' % (image.checksum, + 'valid' if image.checksum == calc_checksum else 'invalid - calculated %02x' % calc_checksum)) + try: + digest_msg = 'Not appended' + if image.append_digest: + is_valid = image.stored_digest == image.calc_digest + digest_msg = "%s (%s)" % (hexify(image.calc_digest).lower(), + "valid" if is_valid else "invalid") + print('Validation Hash: %s' % digest_msg) + except AttributeError: + pass # ESP8266 image has no append_digest field + + +def make_image(args): + image = ESP8266ROMFirmwareImage() + if len(args.segfile) == 0: + raise FatalError('No segments specified') + if len(args.segfile) != len(args.segaddr): + raise FatalError('Number of specified files does not match number of specified addresses') + for (seg, addr) in zip(args.segfile, args.segaddr): + with open(seg, 'rb') as f: + data = f.read() + image.segments.append(ImageSegment(addr, data)) + image.entrypoint = args.entrypoint + image.save(args.output) + + +def elf2image(args): + e = ELFFile(args.input) + if args.chip == 'auto': # Default to ESP8266 for backwards compatibility + print("Creating image for ESP8266...") + args.chip = 'esp8266' + + if args.chip == 'esp32': + image = ESP32FirmwareImage() + if args.secure_pad: + image.secure_pad = '1' + elif args.secure_pad_v2: + image.secure_pad = '2' + elif args.chip == 'esp32s2': + image = ESP32S2FirmwareImage() + if args.secure_pad_v2: + image.secure_pad = '2' + elif args.chip == 'esp32s3beta2': + image = ESP32S3BETA2FirmwareImage() + if args.secure_pad_v2: + image.secure_pad = '2' + elif args.chip == 'esp32s3beta3': + image = ESP32S3BETA3FirmwareImage() + if args.secure_pad_v2: + image.secure_pad = '2' + elif args.chip == 'esp32c3': + image = ESP32C3FirmwareImage() + if args.secure_pad_v2: + image.secure_pad = '2' + elif args.version == '1': # ESP8266 + image = ESP8266ROMFirmwareImage() + else: + image = ESP8266V2FirmwareImage() + image.entrypoint = e.entrypoint + image.flash_mode = {'qio': 0, 'qout': 1, 'dio': 2, 'dout': 3}[args.flash_mode] + + if args.chip != 'esp8266': + image.min_rev = int(args.min_rev) + + # ELFSection is a subclass of ImageSegment, so can use interchangeably + image.segments = e.segments if args.use_segments else e.sections + + image.flash_size_freq = image.ROM_LOADER.FLASH_SIZES[args.flash_size] + image.flash_size_freq += {'40m': 0, '26m': 1, '20m': 2, '80m': 0xf}[args.flash_freq] + + if args.elf_sha256_offset: + image.elf_sha256 = e.sha256() + image.elf_sha256_offset = args.elf_sha256_offset + + before = len(image.segments) + image.merge_adjacent_segments() + if len(image.segments) != before: + delta = before - len(image.segments) + print("Merged %d ELF section%s" % (delta, "s" if delta > 1 else "")) + + image.verify() + + if args.output is None: + args.output = image.default_output_name(args.input) + image.save(args.output) + + +def read_mac(esp, args): + mac = esp.read_mac() + + def print_mac(label, mac): + print('%s: %s' % (label, ':'.join(map(lambda x: '%02x' % x, mac)))) + print_mac("MAC", mac) + + +def chip_id(esp, args): + try: + chipid = esp.chip_id() + print('Chip ID: 0x%08x' % chipid) + except NotSupportedError: + print('Warning: %s has no Chip ID. Reading MAC instead.' % esp.CHIP_NAME) + read_mac(esp, args) + + +def erase_flash(esp, args): + print('Erasing flash (this may take a while)...') + t = time.time() + esp.erase_flash() + print('Chip erase completed successfully in %.1fs' % (time.time() - t)) + + +def erase_region(esp, args): + print('Erasing region (may be slow depending on size)...') + t = time.time() + esp.erase_region(args.address, args.size) + print('Erase completed successfully in %.1f seconds.' % (time.time() - t)) + + +def run(esp, args): + esp.run() + + +def flash_id(esp, args): + flash_id = esp.flash_id() + print('Manufacturer: %02x' % (flash_id & 0xff)) + flid_lowbyte = (flash_id >> 16) & 0xFF + print('Device: %02x%02x' % ((flash_id >> 8) & 0xff, flid_lowbyte)) + print('Detected flash size: %s' % (DETECTED_FLASH_SIZES.get(flid_lowbyte, "Unknown"))) + + +def read_flash(esp, args): + if args.no_progress: + flash_progress = None + else: + def flash_progress(progress, length): + msg = '%d (%d %%)' % (progress, progress * 100.0 / length) + padding = '\b' * len(msg) + if progress == length: + padding = '\n' + sys.stdout.write(msg + padding) + sys.stdout.flush() + t = time.time() + data = esp.read_flash(args.address, args.size, flash_progress) + t = time.time() - t + print_overwrite('Read %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...' + % (len(data), args.address, t, len(data) / t * 8 / 1000), last_line=True) + with open(args.filename, 'wb') as f: + f.write(data) + + +def verify_flash(esp, args): + differences = False + + for address, argfile in args.addr_filename: + image = pad_to(argfile.read(), 4) + argfile.seek(0) # rewind in case we need it again + + image = _update_image_flash_params(esp, address, args, image) + + image_size = len(image) + print('Verifying 0x%x (%d) bytes @ 0x%08x in flash against %s...' % (image_size, image_size, address, argfile.name)) + # Try digest first, only read if there are differences. + digest = esp.flash_md5sum(address, image_size) + expected_digest = hashlib.md5(image).hexdigest() + if digest == expected_digest: + print('-- verify OK (digest matched)') + continue + else: + differences = True + if getattr(args, 'diff', 'no') != 'yes': + print('-- verify FAILED (digest mismatch)') + continue + + flash = esp.read_flash(address, image_size) + assert flash != image + diff = [i for i in range(image_size) if flash[i] != image[i]] + print('-- verify FAILED: %d differences, first @ 0x%08x' % (len(diff), address + diff[0])) + for d in diff: + flash_byte = flash[d] + image_byte = image[d] + if PYTHON2: + flash_byte = ord(flash_byte) + image_byte = ord(image_byte) + print(' %08x %02x %02x' % (address + d, flash_byte, image_byte)) + if differences: + raise FatalError("Verify failed.") + + +def read_flash_status(esp, args): + print('Status value: 0x%04x' % esp.read_status(args.bytes)) + + +def write_flash_status(esp, args): + fmt = "0x%%0%dx" % (args.bytes * 2) + args.value = args.value & ((1 << (args.bytes * 8)) - 1) + print(('Initial flash status: ' + fmt) % esp.read_status(args.bytes)) + print(('Setting flash status: ' + fmt) % args.value) + esp.write_status(args.value, args.bytes, args.non_volatile) + print(('After flash status: ' + fmt) % esp.read_status(args.bytes)) + + +def get_security_info(esp, args): + (flags, flash_crypt_cnt, key_purposes) = esp.get_security_info() + # TODO: better display + print('Flags: 0x%08x (%s)' % (flags, bin(flags))) + print('Flash_Crypt_Cnt: 0x%x' % flash_crypt_cnt) + print('Key_Purposes: %s' % (key_purposes,)) + + +def merge_bin(args): + chip_class = _chip_to_rom_loader(args.chip) + + # sort the files by offset. The AddrFilenamePairAction has already checked for overlap + input_files = sorted(args.addr_filename, key=lambda x: x[0]) + if not input_files: + raise FatalError("No input files specified") + first_addr = input_files[0][0] + if first_addr < args.target_offset: + raise FatalError("Output file target offset is 0x%x. Input file offset 0x%x is before this." % (args.target_offset, first_addr)) + + if args.format != 'raw': + raise FatalError("This version of esptool only supports the 'raw' output format") + + with open(args.output, 'wb') as of: + def pad_to(flash_offs): + # account for output file offset if there is any + of.write(b'\xFF' * (flash_offs - args.target_offset - of.tell())) + for addr, argfile in input_files: + pad_to(addr) + image = argfile.read() + image = _update_image_flash_params(chip_class, addr, args, image) + of.write(image) + if args.fill_flash_size: + pad_to(flash_size_bytes(args.fill_flash_size)) + print("Wrote 0x%x bytes to file %s, ready to flash to offset 0x%x" % (of.tell(), args.output, args.target_offset)) + + +def version(args): + print(__version__) + +# +# End of operations functions +# + + +def main(argv=None, esp=None): + """ + Main function for esptool + + argv - Optional override for default arguments parsing (that uses sys.argv), can be a list of custom arguments + as strings. Arguments and their values need to be added as individual items to the list e.g. "-b 115200" thus + becomes ['-b', '115200']. + + esp - Optional override of the connected device previously returned by get_default_connected_device() + """ + + external_esp = esp is not None + + parser = argparse.ArgumentParser(description='esptool.py v%s - ESP8266 ROM Bootloader Utility' % __version__, prog='esptool') + + parser.add_argument('--chip', '-c', + help='Target chip type', + type=lambda c: c.lower().replace('-', ''), # support ESP32-S2, etc. + choices=['auto', 'esp8266', 'esp32', 'esp32s2', 'esp32s3beta2', 'esp32s3beta3', 'esp32c3'], + default=os.environ.get('ESPTOOL_CHIP', 'auto')) + + parser.add_argument( + '--port', '-p', + help='Serial port device', + default=os.environ.get('ESPTOOL_PORT', None)) + + parser.add_argument( + '--baud', '-b', + help='Serial port baud rate used when flashing/reading', + type=arg_auto_int, + default=os.environ.get('ESPTOOL_BAUD', ESPLoader.ESP_ROM_BAUD)) + + parser.add_argument( + '--before', + help='What to do before connecting to the chip', + choices=['default_reset', 'no_reset', 'no_reset_no_sync'], + default=os.environ.get('ESPTOOL_BEFORE', 'default_reset')) + + parser.add_argument( + '--after', '-a', + help='What to do after esptool.py is finished', + choices=['hard_reset', 'soft_reset', 'no_reset'], + default=os.environ.get('ESPTOOL_AFTER', 'hard_reset')) + + parser.add_argument( + '--no-stub', + help="Disable launching the flasher stub, only talk to ROM bootloader. Some features will not be available.", + action='store_true') + + parser.add_argument( + '--trace', '-t', + help="Enable trace-level output of esptool.py interactions.", + action='store_true') + + parser.add_argument( + '--override-vddsdio', + help="Override ESP32 VDDSDIO internal voltage regulator (use with care)", + choices=ESP32ROM.OVERRIDE_VDDSDIO_CHOICES, + nargs='?') + + parser.add_argument( + '--connect-attempts', + help=('Number of attempts to connect, negative or 0 for infinite. ' + 'Default: %d.' % DEFAULT_CONNECT_ATTEMPTS), + type=int, + default=os.environ.get('ESPTOOL_CONNECT_ATTEMPTS', DEFAULT_CONNECT_ATTEMPTS)) + + subparsers = parser.add_subparsers( + dest='operation', + help='Run esptool {command} -h for additional help') + + def add_spi_connection_arg(parent): + parent.add_argument('--spi-connection', '-sc', help='ESP32-only argument. Override default SPI Flash connection. ' + 'Value can be SPI, HSPI or a comma-separated list of 5 I/O numbers to use for SPI flash (CLK,Q,D,HD,CS).', + action=SpiConnectionAction) + + parser_load_ram = subparsers.add_parser( + 'load_ram', + help='Download an image to RAM and execute') + parser_load_ram.add_argument('filename', help='Firmware image') + + parser_dump_mem = subparsers.add_parser( + 'dump_mem', + help='Dump arbitrary memory to disk') + parser_dump_mem.add_argument('address', help='Base address', type=arg_auto_int) + parser_dump_mem.add_argument('size', help='Size of region to dump', type=arg_auto_int) + parser_dump_mem.add_argument('filename', help='Name of binary dump') + + parser_read_mem = subparsers.add_parser( + 'read_mem', + help='Read arbitrary memory location') + parser_read_mem.add_argument('address', help='Address to read', type=arg_auto_int) + + parser_write_mem = subparsers.add_parser( + 'write_mem', + help='Read-modify-write to arbitrary memory location') + parser_write_mem.add_argument('address', help='Address to write', type=arg_auto_int) + parser_write_mem.add_argument('value', help='Value', type=arg_auto_int) + parser_write_mem.add_argument('mask', help='Mask of bits to write', type=arg_auto_int, nargs='?', default='0xFFFFFFFF') + + def add_spi_flash_subparsers(parent, allow_keep, auto_detect): + """ Add common parser arguments for SPI flash properties """ + extra_keep_args = ['keep'] if allow_keep else [] + + if auto_detect and allow_keep: + extra_fs_message = ", detect, or keep" + elif auto_detect: + extra_fs_message = ", or detect" + elif allow_keep: + extra_fs_message = ", or keep" + else: + extra_fs_message = "" + + parent.add_argument('--flash_freq', '-ff', help='SPI Flash frequency', + choices=extra_keep_args + ['40m', '26m', '20m', '80m'], + default=os.environ.get('ESPTOOL_FF', 'keep' if allow_keep else '40m')) + parent.add_argument('--flash_mode', '-fm', help='SPI Flash mode', + choices=extra_keep_args + ['qio', 'qout', 'dio', 'dout'], + default=os.environ.get('ESPTOOL_FM', 'keep' if allow_keep else 'qio')) + parent.add_argument('--flash_size', '-fs', help='SPI Flash size in MegaBytes (1MB, 2MB, 4MB, 8MB, 16M)' + ' plus ESP8266-only (256KB, 512KB, 2MB-c1, 4MB-c1)' + extra_fs_message, + action=FlashSizeAction, auto_detect=auto_detect, + default=os.environ.get('ESPTOOL_FS', 'keep' if allow_keep else '1MB')) + add_spi_connection_arg(parent) + + parser_write_flash = subparsers.add_parser( + 'write_flash', + help='Write a binary blob to flash') + + parser_write_flash.add_argument('addr_filename', metavar='
', help='Address followed by binary filename, separated by space', + action=AddrFilenamePairAction) + parser_write_flash.add_argument('--erase-all', '-e', + help='Erase all regions of flash (not just write areas) before programming', + action="store_true") + + add_spi_flash_subparsers(parser_write_flash, allow_keep=True, auto_detect=True) + parser_write_flash.add_argument('--no-progress', '-p', help='Suppress progress output', action="store_true") + parser_write_flash.add_argument('--verify', help='Verify just-written data on flash ' + '(mostly superfluous, data is read back during flashing)', action='store_true') + parser_write_flash.add_argument('--encrypt', help='Apply flash encryption when writing data (required correct efuse settings)', + action='store_true') + # In order to not break backward compatibility, our list of encrypted files to flash is a new parameter + parser_write_flash.add_argument('--encrypt-files', metavar='
', + help='Files to be encrypted on the flash. Address followed by binary filename, separated by space.', + action=AddrFilenamePairAction) + parser_write_flash.add_argument('--ignore-flash-encryption-efuse-setting', help='Ignore flash encryption efuse settings ', + action='store_true') + + compress_args = parser_write_flash.add_mutually_exclusive_group(required=False) + compress_args.add_argument('--compress', '-z', help='Compress data in transfer (default unless --no-stub is specified)', + action="store_true", default=None) + compress_args.add_argument('--no-compress', '-u', help='Disable data compression during transfer (default if --no-stub is specified)', + action="store_true") + + subparsers.add_parser( + 'run', + help='Run application code in flash') + + parser_image_info = subparsers.add_parser( + 'image_info', + help='Dump headers from an application image') + parser_image_info.add_argument('filename', help='Image file to parse') + + parser_make_image = subparsers.add_parser( + 'make_image', + help='Create an application image from binary files') + parser_make_image.add_argument('output', help='Output image file') + parser_make_image.add_argument('--segfile', '-f', action='append', help='Segment input file') + parser_make_image.add_argument('--segaddr', '-a', action='append', help='Segment base address', type=arg_auto_int) + parser_make_image.add_argument('--entrypoint', '-e', help='Address of entry point', type=arg_auto_int, default=0) + + parser_elf2image = subparsers.add_parser( + 'elf2image', + help='Create an application image from ELF file') + parser_elf2image.add_argument('input', help='Input ELF file') + parser_elf2image.add_argument('--output', '-o', help='Output filename prefix (for version 1 image), or filename (for version 2 single image)', type=str) + parser_elf2image.add_argument('--version', '-e', help='Output image version', choices=['1', '2'], default='1') + parser_elf2image.add_argument('--min-rev', '-r', help='Minimum chip revision', choices=['0', '1', '2', '3'], default='0') + parser_elf2image.add_argument('--secure-pad', action='store_true', + help='Pad image so once signed it will end on a 64KB boundary. For Secure Boot v1 images only.') + parser_elf2image.add_argument('--secure-pad-v2', action='store_true', + help='Pad image to 64KB, so once signed its signature sector will start at the next 64K block. ' + 'For Secure Boot v2 images only.') + parser_elf2image.add_argument('--elf-sha256-offset', help='If set, insert SHA256 hash (32 bytes) of the input ELF file at specified offset in the binary.', + type=arg_auto_int, default=None) + parser_elf2image.add_argument('--use_segments', help='If set, ELF segments will be used instead of ELF sections to genereate the image.', + action='store_true') + + add_spi_flash_subparsers(parser_elf2image, allow_keep=False, auto_detect=False) + + subparsers.add_parser( + 'read_mac', + help='Read MAC address from OTP ROM') + + subparsers.add_parser( + 'chip_id', + help='Read Chip ID from OTP ROM') + + parser_flash_id = subparsers.add_parser( + 'flash_id', + help='Read SPI flash manufacturer and device ID') + add_spi_connection_arg(parser_flash_id) + + parser_read_status = subparsers.add_parser( + 'read_flash_status', + help='Read SPI flash status register') + + add_spi_connection_arg(parser_read_status) + parser_read_status.add_argument('--bytes', help='Number of bytes to read (1-3)', type=int, choices=[1, 2, 3], default=2) + + parser_write_status = subparsers.add_parser( + 'write_flash_status', + help='Write SPI flash status register') + + add_spi_connection_arg(parser_write_status) + parser_write_status.add_argument('--non-volatile', help='Write non-volatile bits (use with caution)', action='store_true') + parser_write_status.add_argument('--bytes', help='Number of status bytes to write (1-3)', type=int, choices=[1, 2, 3], default=2) + parser_write_status.add_argument('value', help='New value', type=arg_auto_int) + + parser_read_flash = subparsers.add_parser( + 'read_flash', + help='Read SPI flash content') + add_spi_connection_arg(parser_read_flash) + parser_read_flash.add_argument('address', help='Start address', type=arg_auto_int) + parser_read_flash.add_argument('size', help='Size of region to dump', type=arg_auto_int) + parser_read_flash.add_argument('filename', help='Name of binary dump') + parser_read_flash.add_argument('--no-progress', '-p', help='Suppress progress output', action="store_true") + + parser_verify_flash = subparsers.add_parser( + 'verify_flash', + help='Verify a binary blob against flash') + parser_verify_flash.add_argument('addr_filename', help='Address and binary file to verify there, separated by space', + action=AddrFilenamePairAction) + parser_verify_flash.add_argument('--diff', '-d', help='Show differences', + choices=['no', 'yes'], default='no') + add_spi_flash_subparsers(parser_verify_flash, allow_keep=True, auto_detect=True) + + parser_erase_flash = subparsers.add_parser( + 'erase_flash', + help='Perform Chip Erase on SPI flash') + add_spi_connection_arg(parser_erase_flash) + + parser_erase_region = subparsers.add_parser( + 'erase_region', + help='Erase a region of the flash') + add_spi_connection_arg(parser_erase_region) + parser_erase_region.add_argument('address', help='Start address (must be multiple of 4096)', type=arg_auto_int) + parser_erase_region.add_argument('size', help='Size of region to erase (must be multiple of 4096)', type=arg_auto_int) + + parser_merge_bin = subparsers.add_parser( + 'merge_bin', + help='Merge multiple raw binary files into a single file for later flashing') + + parser_merge_bin.add_argument('--output', '-o', help='Output filename', type=str, required=True) + parser_merge_bin.add_argument('--format', '-f', help='Format of the output file', choices='raw', default='raw') # for future expansion + add_spi_flash_subparsers(parser_merge_bin, allow_keep=True, auto_detect=False) + + parser_merge_bin.add_argument('--target-offset', '-t', help='Target offset where the output file will be flashed', + type=arg_auto_int, default=0) + parser_merge_bin.add_argument('--fill-flash-size', help='If set, the final binary file will be padded with FF ' + 'bytes up to this flash size.', action=FlashSizeAction) + parser_merge_bin.add_argument('addr_filename', metavar='
', + help='Address followed by binary filename, separated by space', + action=AddrFilenamePairAction) + + subparsers.add_parser( + 'version', help='Print esptool version') + + subparsers.add_parser('get_security_info', help='Get some security-related data') + + # internal sanity check - every operation matches a module function of the same name + for operation in subparsers.choices.keys(): + assert operation in globals(), "%s should be a module function" % operation + + argv = expand_file_arguments(argv or sys.argv[1:]) + + args = parser.parse_args(argv) + print('esptool.py v%s' % __version__) + + # operation function can take 1 arg (args), 2 args (esp, arg) + # or be a member function of the ESPLoader class. + + if args.operation is None: + parser.print_help() + sys.exit(1) + + # Forbid the usage of both --encrypt, which means encrypt all the given files, + # and --encrypt-files, which represents the list of files to encrypt. + # The reason is that allowing both at the same time increases the chances of + # having contradictory lists (e.g. one file not available in one of list). + if args.operation == "write_flash" and args.encrypt and args.encrypt_files is not None: + raise FatalError("Options --encrypt and --encrypt-files must not be specified at the same time.") + + operation_func = globals()[args.operation] + + if PYTHON2: + # This function is depreciated in Python3 + operation_args = inspect.getargspec(operation_func).args + else: + operation_args = inspect.getfullargspec(operation_func).args + + if operation_args[0] == 'esp': # operation function takes an ESPLoader connection object + if args.before != "no_reset_no_sync": + initial_baud = min(ESPLoader.ESP_ROM_BAUD, args.baud) # don't sync faster than the default baud rate + else: + initial_baud = args.baud + + if args.port is None: + ser_list = get_port_list() + print("Found %d serial ports" % len(ser_list)) + else: + ser_list = [args.port] + esp = esp or get_default_connected_device(ser_list, port=args.port, connect_attempts=args.connect_attempts, + initial_baud=initial_baud, chip=args.chip, trace=args.trace, + before=args.before) + if esp is None: + raise FatalError("Could not connect to an Espressif device on any of the %d available serial ports." % len(ser_list)) + + if esp.secure_download_mode: + print("Chip is %s in Secure Download Mode" % esp.CHIP_NAME) + else: + print("Chip is %s" % (esp.get_chip_description())) + print("Features: %s" % ", ".join(esp.get_chip_features())) + print("Crystal is %dMHz" % esp.get_crystal_freq()) + read_mac(esp, args) + + if not args.no_stub: + if esp.secure_download_mode: + print("WARNING: Stub loader is not supported in Secure Download Mode, setting --no-stub") + args.no_stub = True + else: + esp = esp.run_stub() + + if args.override_vddsdio: + esp.override_vddsdio(args.override_vddsdio) + + if args.baud > initial_baud: + try: + esp.change_baud(args.baud) + except NotImplementedInROMError: + print("WARNING: ROM doesn't support changing baud rate. Keeping initial baud rate %d" % initial_baud) + + # override common SPI flash parameter stuff if configured to do so + if hasattr(args, "spi_connection") and args.spi_connection is not None: + if esp.CHIP_NAME != "ESP32": + raise FatalError("Chip %s does not support --spi-connection option." % esp.CHIP_NAME) + print("Configuring SPI flash mode...") + esp.flash_spi_attach(args.spi_connection) + elif args.no_stub: + print("Enabling default SPI flash mode...") + # ROM loader doesn't enable flash unless we explicitly do it + esp.flash_spi_attach(0) + + if hasattr(args, "flash_size"): + print("Configuring flash size...") + detect_flash_size(esp, args) + if args.flash_size != 'keep': # TODO: should set this even with 'keep' + esp.flash_set_parameters(flash_size_bytes(args.flash_size)) + + try: + operation_func(esp, args) + finally: + try: # Clean up AddrFilenamePairAction files + for address, argfile in args.addr_filename: + argfile.close() + except AttributeError: + pass + + # Handle post-operation behaviour (reset or other) + if operation_func == load_ram: + # the ESP is now running the loaded image, so let it run + print('Exiting immediately.') + elif args.after == 'hard_reset': + print('Hard resetting via RTS pin...') + esp.hard_reset() + elif args.after == 'soft_reset': + print('Soft resetting...') + # flash_finish will trigger a soft reset + esp.soft_reset(False) + else: + print('Staying in bootloader.') + if esp.IS_STUB: + esp.soft_reset(True) # exit stub back to ROM loader + + if not external_esp: + esp._port.close() + + else: + operation_func(args) + + +def get_port_list(): + if list_ports is None: + raise FatalError("Listing all serial ports is currently not available. Please try to specify the port when " + "running esptool.py or update the pyserial package to the latest version") + return sorted(ports.device for ports in list_ports.comports()) + + +def expand_file_arguments(argv): + """ Any argument starting with "@" gets replaced with all values read from a text file. + Text file arguments can be split by newline or by space. + Values are added "as-is", as if they were specified in this order on the command line. + """ + new_args = [] + expanded = False + for arg in argv: + if arg.startswith("@"): + expanded = True + with open(arg[1:], "r") as f: + for line in f.readlines(): + new_args += shlex.split(line) + else: + new_args.append(arg) + if expanded: + print("esptool.py %s" % (" ".join(new_args[1:]))) + return new_args + return argv + + +class FlashSizeAction(argparse.Action): + """ Custom flash size parser class to support backwards compatibility with megabit size arguments. + + (At next major relase, remove deprecated sizes and this can become a 'normal' choices= argument again.) + """ + def __init__(self, option_strings, dest, nargs=1, auto_detect=False, **kwargs): + super(FlashSizeAction, self).__init__(option_strings, dest, nargs, **kwargs) + self._auto_detect = auto_detect + + def __call__(self, parser, namespace, values, option_string=None): + try: + value = { + '2m': '256KB', + '4m': '512KB', + '8m': '1MB', + '16m': '2MB', + '32m': '4MB', + '16m-c1': '2MB-c1', + '32m-c1': '4MB-c1', + }[values[0]] + print("WARNING: Flash size arguments in megabits like '%s' are deprecated." % (values[0])) + print("Please use the equivalent size '%s'." % (value)) + print("Megabit arguments may be removed in a future release.") + except KeyError: + value = values[0] + + known_sizes = dict(ESP8266ROM.FLASH_SIZES) + known_sizes.update(ESP32ROM.FLASH_SIZES) + if self._auto_detect: + known_sizes['detect'] = 'detect' + known_sizes['keep'] = 'keep' + if value not in known_sizes: + raise argparse.ArgumentError(self, '%s is not a known flash size. Known sizes: %s' % (value, ", ".join(known_sizes.keys()))) + setattr(namespace, self.dest, value) + + +class SpiConnectionAction(argparse.Action): + """ Custom action to parse 'spi connection' override. Values are SPI, HSPI, or a sequence of 5 pin numbers separated by commas. + """ + def __call__(self, parser, namespace, value, option_string=None): + if value.upper() == "SPI": + value = 0 + elif value.upper() == "HSPI": + value = 1 + elif "," in value: + values = value.split(",") + if len(values) != 5: + raise argparse.ArgumentError(self, '%s is not a valid list of comma-separate pin numbers. Must be 5 numbers - CLK,Q,D,HD,CS.' % value) + try: + values = tuple(int(v, 0) for v in values) + except ValueError: + raise argparse.ArgumentError(self, '%s is not a valid argument. All pins must be numeric values' % values) + if any([v for v in values if v > 33 or v < 0]): + raise argparse.ArgumentError(self, 'Pin numbers must be in the range 0-33.') + # encode the pin numbers as a 32-bit integer with packed 6-bit values, the same way ESP32 ROM takes them + # TODO: make this less ESP32 ROM specific somehow... + clk, q, d, hd, cs = values + value = (hd << 24) | (cs << 18) | (d << 12) | (q << 6) | clk + else: + raise argparse.ArgumentError(self, '%s is not a valid spi-connection value. ' + 'Values are SPI, HSPI, or a sequence of 5 pin numbers CLK,Q,D,HD,CS).' % value) + setattr(namespace, self.dest, value) + + +class AddrFilenamePairAction(argparse.Action): + """ Custom parser class for the address/filename pairs passed as arguments """ + def __init__(self, option_strings, dest, nargs='+', **kwargs): + super(AddrFilenamePairAction, self).__init__(option_strings, dest, nargs, **kwargs) + + def __call__(self, parser, namespace, values, option_string=None): + # validate pair arguments + pairs = [] + for i in range(0, len(values), 2): + try: + address = int(values[i], 0) + except ValueError: + raise argparse.ArgumentError(self, 'Address "%s" must be a number' % values[i]) + try: + argfile = open(values[i + 1], 'rb') + except IOError as e: + raise argparse.ArgumentError(self, e) + except IndexError: + raise argparse.ArgumentError(self, 'Must be pairs of an address and the binary filename to write there') + pairs.append((address, argfile)) + + # Sort the addresses and check for overlapping + end = 0 + for address, argfile in sorted(pairs, key=lambda x: x[0]): + argfile.seek(0, 2) # seek to end + size = argfile.tell() + argfile.seek(0) + sector_start = address & ~(ESPLoader.FLASH_SECTOR_SIZE - 1) + sector_end = ((address + size + ESPLoader.FLASH_SECTOR_SIZE - 1) & ~(ESPLoader.FLASH_SECTOR_SIZE - 1)) - 1 + if sector_start < end: + message = 'Detected overlap at address: 0x%x for file: %s' % (address, argfile.name) + raise argparse.ArgumentError(self, message) + end = sector_end + setattr(namespace, self.dest, pairs) + + +# Binary stub code (see flasher_stub dir for source & details) +ESP8266ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +eNq9PGtj1Da2f8V2QpIZJkWyPR6bR5lMkikUKJAuge6md+MnvdwCYcg22W7Y3359XpLsmSTQ14fAyJalo3OOzlv6z+ZpfX66edsrNo/O8/ToXKujc6Wm7T/66Lxp4G9+Co/sX9b+pfj2fvsgla5tI1X0Jz3T2G1P\ +p/LrwQ5/kMVmKPg3oyl1eHReQlt5Hswd5u0/0f7ReQ0/4G0OgNXt98kCXj1vWzF8C+Mm8EPLk3YENQYovn3RDqo8mP4n+GbWzjNGsBT11cUuQAg/ud/sBfx7OzEPgl38V75sJ6kLmgS+m7TwhPf99qGAQD9aoGpc\ +2e2wC8Jz6XG0CUuhhadJF9vyxx8O2n8shD/AMHNAUafTD51O8EnUQlMhrLdb8FUJj0yH8ICnAVII8ltGWAAJ6FWOLcMBqcsBwg71/acPdh4SG+Ulv81j09hql6tg4BbLuu3T5NxAcHDoY+G57tr1CnwA9lc9S8su\ +D9IMvY52kt5LXgjhzzTa+TedEeNV4DLIncWr1Bmk6Lzp7JR00NtdjTtAxA3AgmnASGa0rOQt0dyHESrZjql5TDTTRQ8VqV2J2eTP2n9qp6FDadx1wCyUM38RO40KGjk27jgfNB2pUbqQwVC1I0JU0SW9eYk9ZXUr\ +GUB1IaR9ygDoLmNlLj2wkctySqHnlJBoGrltvEIqTvfm+N/oMf53/sDw1Lf8q4gf8q+y/Ip/VWmGv9relQwNa6txSdPHGzI3f+sTTAB9BtKPtid+ojVs4yBfC3CT0urCvBVUZZi3Mq4Kc5A/YQ6iLcwZbzVL2tLg\ +C6YIWWwVEWOqpH2gEhfbAFL4KJhAb2DPMaFaaYYANqAqd4ftiCB584j35ZhIrrR/wZPrX3nCHCXTcGQkUvsDMBT6hHILDD7V7tMDGr5aWhH0QukaEMaUNsMDlSJv3euKSITf4+Gi/nD8PPzc5x9kI7ZSPqtZD9AP\ +LT8Khkzx8kKGslpBnQwZQBOm1gzkKX2mk4/yDSOw4jc9WZ/ZpzoMdoDHAhTtAEe5jk/Gs+e7YR5sILe1ckGX0QS6e6ydUnej0ddRiP+B/kL9qFXgNaBi9da2mXsLegR50OUoXQbB811mkMhlJFDKOaurFPR/xp81\ +NFsU2EnbScBy0KCJS6/F14QFczMhztYRD4tYbefKtDNXXRMAGdOzHPN20u3+rkpXcjjoAj6Z0J5EpCb8u1UX0XdAXXhagv3AMrRJFl4TyvNGHs4AqcCn9PwRPJ+TGlYK0EijX2DzgJfcDpvzsPC7qCwjZX2o0glD\ +hRMtLGBZ44yAdG3sl/Awm9hhCzvs/FeGsYiFiu6caZLxhFsNoZ+e7kpn5MkWnHc0cuOMvM0TJiSepb/ujv9Y3qzZLyuGKUeYQ6JgpZF3RzDbqTxTE9JrYIaUDiLtV2FnthvuKwfW9h0sdDynzS6IAnhL+L+Bj/9J\ +/Ibckck8G6TlDR0SoYP01v9aljRgMcG4WRnwZ6G7Fb3RDny46H94COtZw22D+qZBdTyiLmV5C6b9iadVHprDh4BwsrFrQGDT8N6PsA/sMgTyzYq5MhDbtbJvzFzN5Gsy4p2hCOZyxTgocFbAfCj2//wHAZrFXE07\ +jXa5g2GV/LfXC4hVzy8cahQN2f4q+YeL04beEJ1mQknHI5IJld6wXRX6JSoAXo5BxsDi6tCqaANmCJYlKFya4QRl+o9b2/unLIiS284i1UwmQ7hUiBO06NbZVXNM7B4sk9coiu+B8munTUOYbZajhv4AI2siTdPM\ +fLQUYJgqugkqec37jkxQxB9YyISsFoCmIm4hDIeOSyJQtCSvYedEsqn+jmsF9ZAeEKFLQ2hUWEZg8zAZiHCYWqf3YJCCZXdDo5NCmQlngbkbTVsfcleYbx2MQFId4wP8j3UfSEj4CNdO+uvZrjcNPXo9sYyD2k2B\ +dvM2YFhZnGZ0ZtF831HadfyFWCkTNB7T0OmSUhcdCW99TWPU4YwHA/yp5K4VlmloQWaBtEniiEbIrNTH1SF/NU9Jpi2Ey0VpKS9etcEYLJKEobXyyxgszorJDAZLdUF+OVKpdLfX1v0iH1t12pUB6a0tAPoV2Nze\ +Gti8hT/eQPouOrbcWCVqCvRridc16sbk9IB6FwYDy7kEQVTmVos2Da2e9Y52bM7OmltBr6sl2TBncci2skb985yMWEv+B4zXkmWrYfhtmqVRa8AI06/hX+TCVYwSfpcTq6FsRiyf07SmK8w6mUAsxLirK4gHuoM2\ +k8NfNdtmSKTbA7TYHkUYdHi0J2ajIoOCNlVEUOgkAI58SGtErcgET9EIb6w0hgfo6cRWWxoAk2XHbpVMY1P3dP/oiD0ahaGiMbX3f4Z/D8kZKcOOydaQMavRGtJjMa/QDECxJoYb2kTAEfFGaPsosfQTkrrGUXUs\ +ER4N2CB2DQodfuMYM1psiKZEbSbj+ew5AH1B0FUo5cU3YJbq+gaFPLQ+ATwGh7amnQMYCkgwVAqF/5jNQo2ydJtpoAnH3SkCssxrjvUVTb8D82fJ7I7PDmDI8Qw1FA4fgSuQjl8zKRIasKmXjXkUxV7khczpKrCs\ +moKxZQZAUA/k7UG+frk7EvDKWmd5yIyHRs1HVqHgQzT1B7KJYRlFCLJe5XeomQobtpBu0uCtpTOEFzkqccZCi5XNzOHuHCQM9QjBIU3HgsbQTz78ggvw1wt/ePKILbJ8780LioKk8UF+A2e4ydSKhb/AAI7P2lGQ\ +W+eP6B3EMWA75oBxjTTQ4623AGq+hYBsHOSDu9+D0vgE+NsmAQGefKvCHVsEd2mFoUOQTTVp4y16iXhAka8fuSJOJARFGECpwf8pCJAK/kEuamEgewH61wgX22MsfNTCRwzjRjmBmG98AWrleBfGfItxgOJHwNDC\ +X59zDIV1fhr660iYG/5djhFPyLWpcG+mYhqcZ0RS1IFsfechT7ym3gD6LmibICDx8T6sxJ2dPoZQgYpaSA7aOTHY97KdcALx1gNWr4pDJeEPJCFSdYuMDbR7o78Hrf11AJFS4hDQWBWq5V+s2NJRa48d+DHxzSGL\ +D/JfPe8FgHtIPqzobGH41Btz4BBN+x1Wyo0QC+SUbFvdoP1xADrwZWLDmqrB2Lhit7kknDWIg6jVzuCTzO2uUivEeNVSxqeQXFOPdg0O0S9CfcMPiuRuwHTpxIGBK4AizBIC/vGa0AWNnoh1cOKMWCFTlCsi68iG\ +CbLNDdph4EdDMAmJAG+L7cDabSTppyIUNeGyLD2wMTyEHaw+gKb5wFPUqJ3WB8AVnr8zAPODHKQ62iEagVPXVIck0DTptvWjzbtbczFKya2i9UOY4ioUfO9z9qPKik9i4KKFGbmrd5AzX8ZIjhjJBSP6t2KEV0Iq\ +Hxsco5wyDpCnAvbpUo89Z0UGkuh9LUzCBkXXivw8zuDPa3ZnYd2yjTvUxyTFZ61V1kgrBuqTxVGDPqliQqahL6Y80DdGmxiCeMaER0ykO6sWx5S3hiMTn0RiLEsE0pYfictx6u4SgZw+cR4AZehatXNWIOCrUDI8\ +TR58GwhgggjNIqNJnlr9QIExn6xfY+UD3TC4AlEK/FF5jTqGZEn8mkNOEzagKisbENARruB+L5LPaAVFhPipP4/odyM24hD2q9m9JwCK3y4AhAXekvxC/lanooENoTtsgUCYPN7dXUYvG5MGO/5Ho6XH5Pe2ZAWV\ +XLyHn/tCshe0Yci9O2Q6pfRAl26ckE0WjApfhSD/fzsz567evJ4Qo5LDVVk3BXPpFgSOzPT/0OwVZEtL9QwEp3rNNrnGgV+zB4at5glBBPbtsxteq1DRtySdioat7EjDW60/aVTqGyD3mxfH7zHGBKyeQQy2ZpMf\ +0bDBJgSqktguAqy/f3ic14r8MyN755yDcgUvZpc2jP3vWXESvAZxPxKDFMz3agbPQhGFY1rVAgwpuzBMkHUWtvAjWhWtEEz8CYdTMhNESme74FsXAYZKDg8kWaJOhD3AX0Grn/qcUR9ioixeANCvgFI/MoLK87m7\ +VX4NwAlBtwPFyTZhQhcwLjBfo32IVlYYs6w40t/JOM2MHArYvYKAfpocYybpPQee8sBuUdA1upr3rQe27liB5lcqULaCk7/1xKhfmfkK/8brVbLiXtilNssKmBKdsNpzokAkOiaoHH3wXJtWHB+ZOZyeYlbjkJEV\ +P9OnTEsgUE1BA0WCxTBD1NG0DzAkifJ6uK4gk6yCkq1RI+PvOzIeM1X+U+RFVnqUU3IsVqVP+hxIhgfyutli825Glu11Q5T0GqLUbNtRLHNhZEeGsgPt/Imo7zN8tflFyhtNN/8OkQEdtyXmakdX68M9P+3p9haX\ +HVUOhh2h0+doTwXeZOv33yePQZcRxC/hFTLOBCXYnOUzsv5jJ3yAMJd6zxVqC8qWPVq59yHVrpDKuNhjLs6BvRPuoP813MK1CTXZW0AXO8R8iN7tj4zkCn1feAHLey4fB0ML/REgcwthLxgJPIghcmBAHIgiD9Va\ +vh3kXz1h7mmFmBFoLHwjxomC8KAwriYnNQyEnwnHOvS/mt4CMCBpXYuFFQ7g3YBFaOUkRsFLVbs0CIbJ9N63VJ6UYQHAtzvDAYcleJ4BudEQccnBkAX5UY81Rx5LKLpJeQs3yfCmz/uqnFGSulLTb9gdhenSVxBW\ +SFlgF+VwHYkyQvBOwcyKZnkWUFxwd8nR6ZcQke4aRf0cFIrEEc75TsgLhiHaDinZWRpc/lydc5q5IPnbZI5WTG32mlES5OnMT088jLDntwi2ppkG3smHncN/2ogBzJZOJndOzhnZ6gzV4Rk0T070zFcL/B4DKa1D\ +VdQULsPNnHLxDhRu5BpQFp8Q5BmHorHECJRLHjk5LCMQZv4t+DqYvbL5tfbzTRIkmKhNPNpSmUc7CCvWctpJOW/OQrW7vdAEWY5jTAWOBfMMZgRfhzBR+YkiVBzF9QY7ZEhiFUTJfk9sAkpIGp5dxXYfly342QXr\ +Q3ymGLSYq21SepGrlcCcETDqowmzYZDLn7BBRoJgMvM5/VGkrfNKUwMSytRD+npnAMoFygA/O/lV/boIBP7hmU+pzaaEbhn6Mi9huBnwHXBThq723iwfLfyvSIhj+JxjqAWXQrRwbW9sOWn2zIYdU6eEAvznspPu\ +sj7UDdhnA5JGeSIyPdngIKqgv8buGCYB+VkO16Zgxih2Zsg5CzGo6GleHnKUGoAswKzJGK2Q1rhbt4kWHXZtQGBJBDXao6gKxrXLCzLVHc19DK/BfWqRvaWGG2hTGZgyEVpF6xxUCed+kpsl2nyvqXIIVMxSoOsz\ +TCEtxSPJL25o1zGJHDuoDsSD1MW96/WtkAvVH+LCiZ1XrAjUJfUm6Hfd7dhDWBjFINzkYfsgrHkmLBFKoMH/1KF7/pKIfowIDl2iRx2ip0T0TMOYsOdKB9YU0/e8yjzmbaqlWkLFSFko+9JYFht7R5sKxXweHHdJ\ ++4TQkwHHGhJ0bTpj8QXgYlKS42gT4v6xD0q8XPhbFHx4TVBJGdFiJsUWsdHvWLGREu3BcczI3jcerBvbcxw4SmugYYQ8nEBSokx2XL7RaNy2yLWxeBHHQb5BljtFVRdfyqdrAFhCk61gzstiOgt/4zqf/oxjVy1q\ +NvRDwl9GbncpcUajjBr6PkPTrGhMAgMg2MAMZs8ZTDuEHDYgYhsuYSWaDm8ZGxAokx0tNEdRgc5gpqRkaJW3Y+N8oCvc94AP6Ju++8s1HGygd93UD0B3MFMgfdwiEP4L31Sv3VKHf9tCKyxjmTg+YIdBvuekIEcB\ +GlDZTenfhH/voam3bN1+3Ye5NQR9zllQ8YTWBF14G4sbs/4Hrh+scWecN8UWEaZ1mwZMIs1/xTnZpxUUShTpHADTBSgPI7BUIkoEbK96h82S4lksz9cEN49F/n/Fss3oJqlzcjqjsoDcORC3wKgxSKSO+ilWqJ/a\ +VT8ssEQDwdxrtqJKh6sU0C4rncyxPH6rAipWaZ+5VT2fF63VEMrEYE7CQaDLo7V/kNqxAU0W5ZM/TeXs4D6+hsaBlDMqUTgYz/AGWopkltUOkRW1TWFJqYu1Dj1JZ7A5iUNN2PhtIhQGU6415iA8RmyRotBIbjki\ +vRvF94wesln6hg1lp7qlb4ZzzQr7J1XUEx0Y9SzcqGdDoU6OsOrixZyC6l0rENgoo6i2NjwiyeU17zJWYUJaamkyeB1qodOglq1CIpnSSCPgXFOzUxI1dLF+mQGgMnUbjU5mjDSPphGbIJi7QUMgZIMz4thE5aiT\ +S2hxBqi94FoprLGYAGT5bAkzewj+unf5Jqq4ZkSFHXb+dRk7xNAzFzs4/NTT04eCndDBDuY9Rf8kS3Jn0Mqd/L2gpm8jveXsN9viTRXuO5os7iBm6iBGcTwXQ+aIzHDe5cwWATCUvvkCjkEhQwNcadxQssMUikhA\ +gg4rDCHug2lWxAuWJr8JuAB6wxcyt+bHm4INfk5aYsHt+OwuJ0cS9zTGl4XMNEf4VfLjkgx1QmZXZrxaA2zj+qRHTiHMAvu6kcrE/caNUR73YpRJ1wyy6emuQzdnBYKuHEiEji/Hdbo791aLVkynNH+yGwdZruIv\ +8eG+hA0QyGSbeXw5+9Jlhz/Ik5vLkbO/xI3LOWlsCX/cJfxvd+XYHPtrXTl9UxaDWmUYpRg1yjcgYtlQRndjuMYiZQuFxztO3cN21FhOU3++wUUyDFbeZDbIdn2qrrpMdmSfJTuyCftXLGpc8ZHbzwrKc1oJMqTs\ +zrsO9ri6ERFY5FsfWFPm5Nie/EsqH/2b2gYIUyNJSJ2r28EiH9yj/U9GBxfJ7VDEEi2lHDGHp0sw1WtEg0/VEk0++j5DYxgDeHehKAOSiU3+6WiBL8qN+c/X1WHIwZ/cmD+EqUGLj4V/83iIrMLxkvyEMLPmEAFI\ +06rjfRHn+YC1nSreH1KtiaTAbdmBSTwVzBCsT+W5xqZR3+GdAB+Ed0CLghcOmRotssr0UzQK5D7VWGDUpF/fvHBLTySuekHMmBq/ZCEnpubsdNU+HwmELYBKYsIOkUQKU3EIsQ7FcxKDnydBR2xiJazby8+rn+mJ\ +1OzPrZ+5gNWY2hlKPHcKsCAh5pYctDy0DtWDOQfuuWyh0T6fvQZI6McTPGaXxybpvO8cPIEdCf5165a3/rVHCQ9t4gfABo8vK9v5AgpkTAEi3R+f+pOiDXSPTruocmtz3n1JXGqExQCQGc2zYnVFWydONZEixYns\ +3bOdN5zEQEW6JTk3qWkd0AMqyuGamgpD5jK0j9JjtJYVtmwvNRE86YUBuw0OH8SP4GhDicZ4dAn7pMw+aZ99QF/+AFOKjYscnfHZpexcmEmKGCjXSBGqkusUJdEocTbWDMBqEPevMVLhD5gyIR8SDn+CH5gnBOY2\ +SefCH7NKA1piL3AV8Aef8qu4mh0zLmOubJd9DLWWqta/sNyHStJUqqXHF/bYA554ip9IIoz/xp+4a3mOgGCU7Ua/vss1uEWoUpkN1tGGtv4bngESINOIucWcKwylT0Tv5A/9+JwOnJo+8RXvxle8S654N+m+A9hq\ +bqdFcBtW8U0GqJ2uQfgDWLhglGfquON1ha76gk/tYMOMTzqG30CGtYHykybHAxSz1khYYqr9jxh3PiBE0XGJbdqG5XhBOUBtcsvTM6I9MN8O5NVzYh45ywJRisk2V6liHZBUvifLlxZgQhrEKSZ9cyZnQyStQsth\ +VXkoMpk5qeaUWs31Y5jii5Y8UydQy/6BkvQhqnUMnuYH/nBrrYC8cIVFBHj+8QX/gI5Y24n2w2AtRcO7uHWQDz/YWxrK/Hvvllfk6z8cLTxIx45PxnJ6EMCeUdQmxbphPJ42vUFbWTuHFPE4ayP0KnGrbZrT3gtE\ ++5CNJ7ZCUaakW/dooMIcMrql5VQALAL9P0kGsrFemYCZnCKbDEDUJRPnhGHbYQGDo9YM5//gQgY5dWXz6PIwgzHK5CXaG9s2p69ASKDMw3I+SE7qG4y7zknxreWHafKcH6YCCpbLPRVonJMXaK71vi+Vo1dB2TZ4\ +S4rf7+lx3YWUAVTcExcLriFM36iRB04QeDeMFWOBtjBhgJwOcwR8KCUda+dwrD0BK+cLIwh0N8X5p5/evvrxwZP03ta25VnUQunymmq3GiOkTVBKICxhBwg/DldgWQaHwDd2RJsctcCDH9Pth3w8Bs/4Z5mVbShL\ +4bx+xZfR0J0DKUlFex5PUSlhCokIPKuf3bOz6hLPQOEkpqM9FwbwdDKdDQe4y0RCesLueLgFe60zqULI5rk3QJShj3c8+HjHg493PPj3SQJr7V7g0r/uw9aBQsPKk2P3tpVjn7NMnUt5SII51ykwf4ZHp3hAyWdz\ +V8t2cK8lKNliQOGBZbElHRwCnKNzBVWXKnZhMpf5dG4SaB3iBd4PhLQ3hgrwrcSOuEyVPvY5dtzwRTcWeGaBMvXp2gSoRDE7buV1OEbGyyULBm+hi9FwCb0wt4NU98CWUuuHu1JPncltRnmno1x/0Uw6jx92rnjA\ +2y0OT5cQZqqbqHBDBUtLSpeuUZnaG26MfovdNTtcUYbsTJT6k5QI4c1NwYi+0ngqerJvl2XSVRNCHyY8yrFzFVQiRXR11LnXqX+hhYvJQ7wLI33M+lBO8IQ7/4GBIR8Bj4p09CzibVRCvZ6YK7gzwnSUc/apmX4v\ +96yYORJDLXPNE541hVOfmL7rAggyslKfR7P0sYfPs8fpaLg2GAm7pv5qbnwsN83ISxSWIAFK/ZIxCZGRJgUnMts5Ov0AG/S5lbIYxOBrWiSjoMVZiXlPlBRkgLNWsJKq3Fl9zAeph7TaesxhfTQ5t0ag7NFVD0lN\ +o/naWBsB/Rs8EaWegoemvubLWKRjR2vCqU6Sx/Hg6Ai/fHCXVWYDuYYSan1aaQzhxfQDIBDAT5+zM9fYy648QaZ7kZNSz+8R9hweP5XDWPEMQxnq8c7DG2abQt/xYIwp5/jbYLjmjXYG+1IdF9Rys8N7Grejs1It\ +6mXsrZGiu0r0qDs9oiNw5nQvl0prud6kYnXZFH1MSodySeq6V14UcrRVbntLLhun4g7xinty0mvlaUecWEVCigW59Taou44lHFjzRzxUucFFxAz4dxlVxZDqx52HP0Ir8i8D7ZWrEk+6t5GBhYwldUiLEm9umcbO\ +M/TvMrnjySHB0m6FrYk71exPe7+T7NWArXXF6JBNO15xVwip/wwtC76vQlwEzFc0fHNRRUcnFljowEfRlbYbojNoGT6BYbXSngMLbtJquXvFjmBlgrKHYJ9WvgjJ0I5BN/2w5l26/agOHdkcYe99Wfe2jWx0hRHy\ +ZElor2rrm+KJus8UCV2utFcInfKNUkXxGxj9Z5eJfnIbp27j3G1cdBkv7V2Ll/Xb7rVlaXlnhY7ItDVESENUvD1KMS8AW8CKwJLIny5LtjQw9giSZ8SphDxC5bZjeajqEHrPuTVFHVSyd9+SG7qa93LRz3KyDjZt\ +3sC1Nclrt97zAR004exSMVl10Vksihv5Z7hjYZ7fc+mUU3wC+1ZsAsmk+A3biRHfNyN3YhA0oMNCL5eI3D02KPMGrq1JnsilD7dYy+WrbjCrUpk1ekUTpSUHidA3mb1lX8FcyNLLUEKtiVxOZgycfA9viNyXS/EA\ +tHqbt8+Yry1p2JlGBCC0vIJKbTPIWbmCTGVuZ0MXMscbPDCVMRYAKBWOSQ2IvwJvYBVW82wkzEUJL5v6tXsYj6bjLHKSSc2e/OxTNNucA0jlKi+14m4husUhl0+CowXuSRic7Lt95+g2ZxQ0Kr7vpOQrNMgEaOJg\ +1yZcar7JgrBr7iudyGmCje8GWHXayGUMHYDTJYD3RSr650tikDSd1MuiXTVxNqPBQNqPOsi1Lzlay3hTQN7dU+D0pi/vWgfZXLKXOL6UJN70bxGwEJIJZyJV0a37hvgEK1VKJwbg5r7N+Q0FxU50g0Sj5EzdeIMP\ +ZmAat3DuTaoKvJQCp4Cvy2BgszvkHhuDCC9lHdvzDZrmw/ssrEiXgfHwayiwF51PrBFmPruQS+yazjnXNaxpCp8Bo+GB+wjOhRTjwbM9Sz4d2yNlgooJHkhUzDW6CMxZDKXBUC/2Dvn8Yz1hPQmdHABSqhbBJ5PE\ +iWeEqww1+tt7eGivLuRe7SK2AP7QhR9iH5ctgYIhFMxrgZ0xnM0h16c1bgeZpcRi0isB6YOLc4Kr1g5/6skRKU66LX0Tuti1rzdHHt6Y/M+Pp/kC7k3WahKn8WQSx+2b+t3p4t/uw7R9WOWnOV+w3LkPFnff2LG6\ +pXhXIpRyYJ8L2zLe2nihbVk4DTDyTANvAMGLnKc7XKqAfWrz+G8U8sDHuTIN27sg8YodqtppYO+i19v+SimS05sZol51I8NVTgPDy+rS4YhxljpwShetiek9Pm6uphdk3re/7vB9znK1cDO+dIpVv26Te9N5psyv\ +93zdkZr+n0Hof80clFK0yCtXYJf5OxEIi8+E68t/2SxS27jvwIXFTgLx0j26/RxD1Gv3vcTeiU5bN4t/3cvDF7092ZvbvVAJTbVOELBj1HSstP4Vzp2AhF5xcbTu9de992GvHfXaca+d9Nppr11227oHj+7099xG\ +p6d7W7U+vvr+4z/0T1/TDr+Qh67jqet4rN9OrmlPrmmnV7ZPr2i9u6LVucl6Zbu8sr24au9c+/el+zb5IhydfsG6+5A310iBHuS6B0n/GnPdGW/Nbdx0G51h77iNXbfRsSw6BPnYkzQ9OPNeu+y162jFLtF/4S7+\ +s6XA75USv1eK/F4p83ul0HXtL/zTygYmzQ6c4M6jSiRxNWJzzTffeicxPLPTVum4S1e6yVara+RGk1DFafrp/wG5amLt\ +"""))) +ESP32ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +eNqNWntz3LYR/yoUrXfkDMDjkaDHre8uyunhtJGcRJYyN01JkIwzcTWyfKnOqtzPXuyLAHmXpH9QAkE8dhe7v33g/rO3bFbLvRdRtbdYKeMetVi16avFStvgBRrdS5kuVk3lXmoY5r9kU2huuXbpnnaxsiqCHlg1\ +cd/aote97/6kUbRcrAq3VZO418w9Y7+bUjBrTLOMdv+z3gqOFFjbkWMMUV9Cn3JLNsqzo6q4BRJcb+6GwhoprAOU6t6CBQ3TtetVAdcmYtZbE7LqKIf59YAoR4yjAEYatX11Sl9xZPn/jBzuDo9WUXcS0eBM8DFC\ +UQPissJeRUsqS9LwGzOnSFUVCLgYUFgk76jhe1DUV5/WWXErPrneBLiJVRTR0WxiR6kJ0dsIsW6cO5ei9KQ0dSA4OySrGDDUp2rznvxo3zbKz7aKNRoWkAcHptFAvZGaJGb+sq9Aa4ET4zlpSvpajkXAZkbnAKPg\ +v04vRRFzVuTKxEDTiKzK2tEliRMXtaLp8cSN1XrH9Y+Ck1PcBrZwhaCzf+4j96VOel/e2N4pX8Ooq9+I7MkI+ouZic+/Oov7wi1UIDhlJtwygWxx2zR8n0ykdUrdOKdIu6VElystQo3QrB3L1Yg3FhmP+8hQBO0O\ +DAo+YhPqcZUcBDbMkixYk3sjC4AE4xkuFB2cdudqC6Lacl83ySbXPMNRWVQhZiVnQ5MKNkDVLz01spmIFNs5WMCcB6ee84axsoQ2ayPuH5qKRdCpgqm4HqgkrAmwoNQTLQBftFug0XOYFNpRqFO3oVyLxbJbpt9/\ +25+1JKLrgFBDxrHsCYcF2Tfqi+fgLxhGpqQYbXudXowsWyBoyugaDO3H7y4WiylBP812mtQwphhz7ASW8QmghW0T42i7Cf0XUYUoBTarU+BxBGBXJRHrIttW6IOMfRGTRtr04Pt9mPgiPoB/+ymIyhnYECtNH+jR\ +aO7IUbblq9Nt5B/GxySJktXLUVszdpY14Z0JMNRT9Rc4EISihMTRyAlo0sky8UoP/VoQRDdMh1hc4vVOTGng5EpsRWF/8otY4haTDjrZrmNaKMhSPWOAGzppgGuBbCUQAsvAWSKlCZFB7J3CAGDOTsXNJaGbxh59\ +YJDCFE49Phypl1P2psnBdXHKOoIK/BykaUCapZz0eEjlERHRuT8QAo9VfFoJmyMMa+gI4HtdsUiqDSKRMZZVfNRfG+fKmobXyf9gnZrHpOtj1j0rcfJCwrfEf0P14XddxQxPFXs8oKZNfy/ckfZ1+OJAqUbMnwBq\ +fMkGAMjVdYObBH7dS7a1RTTUmlU3CMF6tpl5bLv07qNC47n4yq1oa/bmckKBlwlXau2hH1yx8a2RMBpOPI/Jx15ZiibRDthcq2A2IHFZMuw3Gw4Q+osgXqhkzo7XUlKPrB8IKYU6a3//gL16WObD2j9Tj/fh4b0L\ +X+7Cl2X4sgpfQKI/M/jVqjMe2O8dm9FW6aPWMILVZXtGfGpEtcqLEe03PVrc3sBCs5aHbDzTS58jIM+1rP4DeKXxW3dAhrU8y1lONe2L4zeYqw9uPwTHhUQ+XiJJ851gJB7b5CPJXTNCS75DOna3Eh3NIVASP2Q3\ ++iE3qfxAnV1qMH6Dru3xAwOIDXIJDCnceVW4di3oj4e/49Mz2l4o+ie4VCajMkMyHuPH45xQtWY2a5T8xXIzmyYHd5yTXMUrKDrKW+B4/p6X0aE44cu+F6V89IRccazVUDxUMqUIXNl7Wqaq3Nec9wPgwrAT2M++\ +Xix/BMHAjNeCcz9wijny9lu2vEdOwYM17ddAwptd2AIkAUlv8pZEAlSAJReoI06SFUgSFBdtn5kp2g32P/ZpE65gNmEBnWsjKDSWwzxCB6bpCP/IsDHWta++PZ2eEbVcDICYETClAhxOeT68KF9KwBQhfTXIsDak\ +Z6CopucSJr38cRiMIkkEvN2Lk9lesEIa1DBEiYSEgA3JLHmRyqc4T+9464ZR6Vpiysn7Q/RGJmGnpB2+UMtaan1D/yDAHPMygKAFsbMib6YoAHLe67pDu2/IkwPauSmak9C66ez3Ni4RyDi6Ub/nIGAWwo0mh4nT\ +O0cwA6+pXsc5oEa+Q2dJO7wmk7A64vASg4dGQAQ2A41vtqQxlQTz8NmwtlJ1huhGAyrDOqgg+Px45j1svabiU0HgN6TgQHlYTXIqfBH7GPOAA3r9380oXJsNIrLZWpUqoaOqSjIlm04gDQaXiRDbJfQR1cYgOlVs\ +cptxh5xKxfzV+py3DDoRjyyJB0LtUoeIt9n/OuorG8L64QhCIDhz0O06+aLHFgTR2f0atyNhp+sFpzSaTYHnGTs7jYP2sFPfXy6WN5e7lMODE9A2f6AVwFegjiGBMnt0zw2sFR3DGnfHUYuN07jbF0L09Oxy3o9V\ +tN2eXULEBtAldQygGLSJ9BQobSg5b9s/3vQDWY1zcXcADSeE0joJ4x1YKvWuATqbZkc6d8iLte3cq6xS9z1BoeEVOT1IQEYQrtRD8ff2ZwkhSCdRQbKHqOXBNvsgnScgyhZhLZm/ZaFku9BoT7BT8KV96xetEPrm\ +cadCWEAL6QGtx7ajB7d48P3ondScnICCHItmzUm3ZMmqt+RcUIuDsEIOb7Cxyma062FLoqddv5XhiyUSxAAB0R14OCj79MXJqT3QqztFoX37273ttOgk7P5Xlwug3UpZBvOhZCirRASlw2GKhuh8O+jU0qmJOJX2\ +PVc3cDTk6CxIxGFAOhxwylEayuNe9HhOMYecis6vto8AMJabcukloRVwjaFdR9guFe2QWlyFjrFE0cxAkZJ7+Du6A6uPfK2qSq9IFQC4wFmUGALfHZM7xzJTyYGcCfwvPJCJG/1uLUp7Ad73nv0O5A4le3kHgXs+\ +2O7yzq5UdkVVnbaZe8GX/LRYOVxLB68OKUc1+rUUVB8k5znnUJi2fzBUFrJByj1g5XojK8U6K1cU3oLMbHbH+EHgIyfBoGFseOpsGTlRYUo+OrB34M9mNlhLaf7UrZVJASYmFkpsJAStle5ChC493rRSKP5Co/dE\ +BUkvYJ1IGElOSC9oymfe2YAnh7I3aRnrDFVvfyPltNkqUGcAzSo9OoVoRx+xfEMLoI1K2QhJXyV+q7slIRMgYMM10xK9yJRwHw4BIudG39QzsLsvPm3T0gWozOgziiP7tase37OX5hNxiy3DE8ywangLer+6gaXj\ +GbsOiAELLiCH2XWhHt2fkTh7QQCIDM2wxlKSuaPJV6TuUJfGfrwoUSeHXMaUcsxYPCKXlWGs1hNoRDN/pp2Gka9kxU67ITm7UaxxqOOoY4YDUXDDBZbfEWG+C+/z6gDGE7HNvsCWFEAUJpV+c0XlRw1QmRzjwX4P\ +tH4TBgc0JjQPzaipU8FvQU6MPw2YIyiHhRC6wqoZXsRostoharqlbzv1nM9CqN09lh1eSVoRc0o89kYyXBD9YxtkNiXIo6/UgBBo3s0E9H9K0U6R/G1x+0S1XdSMJtAMEIMoORgenAd431oHpcSmTwrpPeXsVq8O\ +uMhdYFzCVVwAKryfSrYW97ukCBgiSWG3SZ5jjecJ2oCeGoGuDIu/LnC4B009JgWw7EurPKWgWnV19vY4iJjMJoNX82e9Q/DQZLOIta7OxbDfrGK+PwQpYt2h+QRvn1ljMn/3XclNWeM1CQO0qjNhytOx9ojeeQSB\ +wG/QuKNt9NBF2+zqxisERvGNfCrwesYdx8nL8wn16TTUAfSdjlSp3LfdVcsjSbIwv7x+wJ1vmbT2EZz7HaX5Vp3kRI/ODihexRiuolIUZr7Zo4+pNVQ+wP/ofMqVgWbF0IGfO+O8CaKFcioxwB0BuhnddHSTMO7k\ +oj4pQRMAhQ3XwhpQLNJLN6SRDw0BcNteSaWpS0bELbWYdUxO0NhJceafMGatfThLtZzdwA82nGeZwBCdCuw9cEaDwz5CP6yMMIu8B99V9oKDZMqAAzyrE6TqW3lN8fXjnK9Qmn48SPgjBZ4GlFWMF9SlXDPaLQqq\ +UDxSNWqG6SvZc3QMMQHkrRqxGbPYaDsiVwEuBDeX86kqskXDRewhWKDLGvFFYUfxOrZh/huwWWOUAaTIHboPQEwM59BwIGutn1mJ+xrNwjyOyET3VVURDcOqKxNo+W61Gd/6igfm+M2fJIa/gp8K7RzvUNSx3C+m\ +VNgDTNJc2ANtKOROKbwOKZKSQLIZ38hl1FZ3w7PHtwuZ2DfC7h5BLZgnZO/N+HLDFSRNBu5tKtwzx3j1teHYdHbeFfzxOvItXEfm53gdme/nE+BZnXFMWQo+kajYX3fSehBdeoC4gLZ2g23O5ULLYJrJbS6G983W\ +rxwE0CX8fUkm3WBNRWE9K9vfFTQBHjE1xGT6hXdrJVtGg26teePvZa3e+olzkIImgpaCJpb6H1yN5XsaKyUDS3EStg1dg1Ep6ud1IVoMAiqzC9t98I6zZIW0eOMNXyV9qMiBlnDbbLgQCyMBTkDIlDZEdIHOr1gK\ +jPyKWDAsySfhrZ6IuKH0s2z4blR+HRHcKorMKATY+YnVkOm2KJ0D/DmS/hIOZ98QxIMOYlDaam5wxFpnB1xDB62Dq5Oa9YXqawdsP6hl+dn1PPg9iH1JqEWY/ETy1WwwRTvdhrmioebge0BxAQKjt8KvxcH1/N/y\ +dT++SggDyy7oOt6AXOCUEfH1X9e/Gj0dds5vux1AxaEAAL/p8Ju8/DN4zNYHYLurkbCS9W/Qut+ZiS52WQJX6uinIHTzbTFw4vt8DAdzHxcptLTRE3kdHyzu0nCV78Z0AmaQzq7dJKuDZ7IvWmgsC7dQ9KE94+5G\ +es//WItIw9HP+V5n0211LT8iE9ay3tTYk9KX1d5RhD9m/OnjsryHnzRqlafjxAkxdV+a2+X9p65Tp0XmOutyWQa/feSa/x5/CRcaZWo8TtPP/wO9arcm\ +"""))) +ESP32S2ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +eNqNW3t31LYS/yobQ5INgVvJ67Vl2p5soN0ToA+S0jTl5JzGku2EHm5usg2wodDPfjUvS951uPcPE68sjUajefxmJP7evmmWN9uPR3b7dKmMfxQ8Z6dL7aIf9MI/Krd7umybPd8nNOf78GfDf6j8054unRpBC5BM\ +/be27DWP/T/ZyL+WmX/8VE3qW3L/TOPZYOCUBhrt/+Y9Ip4VIO8pGEPcV9Cmbjw5FS3HJi1w4VsL3xVoZEAHmNU9giV107Vv7Xh4NZrtvVKzPVqh5xbG1CuMeAb8rAbe1P3jA/qKPav/p2d/Rnge+lnhL/+JHiOM\ +NCAZJyuxREk5WniYjxeFzNhIluUKY2V6QS+hBaV6fLu+Ak/xk29NYRGJgn2EXVhfBTwz4rcRZn0/vwVlFVhp6khebpWtcmVBfa6G5+RHh3ejotGK9RcIyIMds5Hs84awkia8uPwpaCcsw4RlNBV9raYiXfOENgF6\ +wV+dHYrCFayw1iTA0IQMyLnJIckSiTrR6GTm+2q96dsn0bYpfoc1IYWosb/pE/+lTntfjlxvi0+g1/E7Yns2gfbyiUmeP32W9CVbqkhqsBswfVvviSJHcs7i37OZvB0AcR4DNs/URJetFrmO2IJBojWzW4qkp30/\ +UEbvnemXvMsmVmWb7kTWy/IsWZl7PUtwACYsGx7YPu1315W0Csdt3SCXnvAIz2VpYw+VPlu1qmgC1P4qcCOTiVTxvQAjmHPnLKy8Yc9YwTvrJM4fW4tDd2OjoUgPFBNogmdQ6hMRgC/aE2j0HAbFphRr1mUs1/L0\ +piPTb7/sj7ohpuuIUUMmctMTDgty1a5ROdAgQekymE/PeCfQzP0Pm0U/SkV9SMMiT1y6hO1w0veEccyoUnpkk8Tme3ElJ1Md7J8P0IznnK5/j5fcKomxtnszTkcr2gi+MtYiZ2g3Ko6INlq5iUJAbyEcM8xK/NOZ\ +RLq92W40NVNir21SodSOMbTpEFclLhtHOl9NA9d+1su7N4B4GPenrWpgcEMsOBHFaxMOcBDged4bMNnxjuhdk0fxEeJWRaGls09YBggPhYzmASa4A152BG+gpQ79sh/Uzh74fyvyOiA2cMWwSFBvtEtmBHUkXQ9N\ +uGXNl3WAnk7kKc3mOjmwKaenC9Y//6W2TdjvrtHNSfN6HHQjOjoc3sqV0TUvyQxFXGLvcbq+VDQH/q1t0sV/nqvNhkmFiXGl02BLce/KiFVUmbwpJV6hYUvBNXv1qdjJwf72ZDd55DtWbBJuBX6KvaI2+MfWBClQ\ +ZYv1vTM6CZIT7CEWcKcjmKwTAl0FPwyS90xdxhsHOjXZYj2GiM1MKbebVl/WLYQ+zD/FC4wsqD7IZUvTKhPZSxTInvYBmWyHc9eRke4joj3JXk4cIySQ4OQEvMnrX16enu4TBKfVeC7rzlV85yfJOTYiArpPu4Q6\ +kJISunIdQgLzOgNOJoBEbTpi0aYDe+QeJ6xd2c6rMQx8nOzAn3EGWuEBUE8vrygzaSvEPREYnwncsaxzFb/lVUDnDjmIPJxGqDMCcU6Ey2qVyx9xx0F8sGhQPImVmkxHAo3gFy2ID8CiKyJslAaE0KaDiQg6MDNa\ +i9WW50NzYV1t2oGgpu4zEF0N2KCp7ZoX04SkkEO2c1rWAXSARbl9yUXSOIXCFr1jEF1A0lglDybqm31x6Tsn5UEHzh9haAERVrLd0+FcIaSwJ/GPt0e8ycYteIONkzblfqHEZmODNgN0WKu79hMVvsNTh8GhkUN5\ ++dSxGWeRd7oDQ7TuQegsDmmNhTWf8jwhdH/sKG4jZOQ4bKPRYP4Q1u5yITiujDIVG8aAwjeKpE9+M++nYErhXrihjXgbC/8i/nEV/7iJfyzjHwyZ0A9tVCuprhXrw8TpCWrl/g/BJCkJsEEOgE0Wgu5+59pCiv6x\ +PYVKSb5JcGA9xj8kVPNwVXiHYj/eWzoWra5+Bbg7/c3vQkFEXP51hHVyWoDM1I82/rdlguKtNXqKj4dsFBmyPt+MRmASMPuLoqtmxyJBihTqaikKWfQV0k2GHCr4p2sKVh3Amh6hj/54zc7eibNH53QFyx0xbQ3N\ +kslAzieBhxkgnqDslLPHtGtw8WPy8buC3ELNC62R15c3wws1heTiecieGQpfwlbP3/KSm1iw8GUchOnqVUaOGYg3BLyrCEqp/C2RsXYTkAcrbYEjFmDt359eviZFqNIXgpt+5YrVJPAIBlu1PEtBcdAV7ffAxNEW\ +TAKyACCT/kZCgQYw3bKJHE/eN/dKrS4GVLwNAUTCbWf3igdLsEMlbURmGlweYfQJYXTaT7T/ytO2A+ZD0G8UaXfzv/Axy7He+/lg/xnASoKDn4iGSmcH36BbqClM+YYo8TFnlOVgxQK/hKqnmc32VspDA7UlL4Vt\ +aR3DnKv1OsNGYnpBZ9arkA2uJySX+ENnUQlWVFY4awMINtEYG5VtTgkC4Gx1nDVXcdZcc2Z9IlAa1KLJhMvsipuVeidh0VDWQ9FSPRMIbqYdGP9aunayw2ai9fZaSDp5M9kOvi3fS1/1gd/K7H3HAcnuoqOZc/IG\ +qbGgSrDnBDHtEwYb4gjXguuGqHBk2SGEPQF0p14kBcCoAtS3kRlekN46Peq0uiEb87Q+g/Q38N99QiFt++Bev+K8cQ8+P+PcFtaABLr8qd21ADQm1O6k4NewC0vZqKYR7G3WM/zSfUOGGxJvkVLc1UYe1qVBaJyV\ +3fT94pdqJmW1zghSzwJu70JLdUe9hL8DKl+l1Ru/lo/ts5NcOXN4mQSsu8Mm1kuxbJQRojfA5zWHnnpoGoScR+QlQVvi+TwcGJgSaJmBJeEcZkAzK722lJT0FZIDcMkum0HRFjAWph1d+XlEJm44kwUNwGkG9r6N\ +3DxCId5lF7VbPWa+U16xilWqcgPc09j9LRj4YHIEbmZ3TkncUGHEsuPnxVqhdHYG+C9/z1A5UjfumRwIkT8H1AVkHqHCsh0GVevt1+Tl2pbrpDzbBSMkTWkqVeUZUXKXN9QFyZZ3TLe23bBhksOWA3WGSAcmLMSU\ +8o7+F9xtibh59/UWvtp94NOy98D6wRjbYDHp4enN7eEW1d2BgnbFB6Kha66TFLIzMH6y4JdURKCv2lELW6wukp7A8jeH/cxAuy3r52vYwbHVwUaRUwUaTTAAI15xYuM5OREGnOiz2eocOp+dhQK6zSmdjmtLAFpK\ +1y92QdJTxe3TgIyA67oLuj3ZAbL9wPJKCbFVWEk6L37C7qmXRd2wleXvR23X8500zrEEsyVpwIkUmbcwBMyZCOb5qj3m2XNyAErNk8jTx7zAbpU18YIzvA/tFoPanLYVa0s0ak6+U+jZQG9O4pTyty5lE+MpFR6V\ ++fl2W5I8zXcofUF9zovgXlt5b3sy5HmAUcnzYKzur+5192W7x8J1l3pT0EMKCy5ppr2JJp10WumgUN/vyU+NPzMml62Sm/TIvQKtkE9ZEN0PUbVdJmphY20ZvugCcgjzCDQdNrYBP7A/4DqgpoiwfQm+Hah0Bd4t\ +TnQyIcmKghZnsWq+QFx+BeyOwnGTzY45/oAdkCO84sNGPDKqOGMyAXriuRvUbIxeO9M4fgxAdMF5H6TyVc4naI7S6LgYyMUohLPHVAdsm3l0xsJPi0DnX2uTPaBMH2F/I/74A83nGxecehILHwzhWnRmkz4LvJzN\ +weWU68s5pgwLQxbZ80K8jGwFO4UyjXXgM1XI0EJl41D6kE3lF7FS8BcxXMNpisUqvklswGlN5LEq9Z4CP44xEWdKRxRNtA1GzuAbywffbQcCZVXp+crYVLg5Qm4k5DQh6kksQo5K5OhzOA4ljsBZGCXTdsdIzZdZ\ +mC+xFpSG6a/eE0swdw0QpkSsX72j2pecdkHgBZBjStCaOt+93SLieHg8+Yznknmv+F79JyLBFUyMZR1fOXmzshTp/IncHUMUlBOmVnGUdNHynTq7BcnwTkKpyKwcqECEh+7+uSHz6CqpCmkWX5GoSomR0yhecpYL\ +nGGQx/dR1CEP61JdPJXj9LhjEQKu0lKFHkVr6o6q9NmSdtvkxyi/Y/YHIivTCZAFaxiqGM7Lu+qROEwUYMGnBGgNP8t51pxEPf8xxAoTLwoN6Twe+lzOlhfgc0ELQIUc5IpiWVEBbgVPen4vBfm26qMY2tMVTEvm\ +eyBTziR3Sfpw3E0GsjaIfG2/lFCJVw8S4TISOud0/lj61vsEo0AbjOf1E7lHL/aF8FASnmi0GAvFIseHRHYggeusBuPPcoePX0q5aYD+s+CTDjxO3UKVWUQnDFgucFd/d4EWXWkVH0JA5QxFZ2kqWASc/Wh1DkQp\ +a1uWGHHag8jBRhgyktD8/p3OdAMVk3E4RFtztEwYZ8FZDiLw5jYyEA6nhJk4OeLdE11rTEA3EH6D6f+bOhh1TqNAtgWY8OQKU4dVR5L/ToHbQObZyNeShYhnt9/+xOaMR/YrWlGW3zMbAx6lrOxF+wI6vTm9ZM4g\ +V6vAaarPbM1FSVe0wDABt0Kll/bnlrEVpGS9Ihkum8//dVX9A7wvWWw5Fcwie+aiK0n8lisbZZC4zjnUlt4rX4qUr/i+T4s4yQHiPuOqGJRREFjSnaBNbN/E3P0YkgEbgXdxVoqvxuj86Tl6n3YuavUPgmOB8Qbh\ +yJbAYTwaB73J7w0iUZcvO3hpBxHsfrD2msu6faSq8z/W4SSMHDF8rysZFifScMBRd8mzZBagA1hjR13HHP4X+EURqoOc7arpb/xGLaU+6WXnXIogfwDHrxmgFyhDUPTAosRoF+MDB0Gs+xdnVOJyWMGpB/L1lFJC\ +vJmkX693ABtx0/7Ka7yuh0evjCNsyiVo73Kb25DJSZlNKuqDSSUoCiaV1o6YXctqxaxrs3kWrg/YtY34cooMKztaXdk1V3CcZT+AARajbsupPCaYju2roNssiMSw2LzfL6p3u1pNv5IkeoNavFvd5mqKZHMZusJt\ +cnzg26EM75V8+46Dd9hH1ETbSQRW9XSguOWed2fvyTlsE5y/F3/i+XsxLs7w3twbrJd8OxwN8QBD7IPkGgGTlAE/4ZsPIysMLbhAqMLVHkWOPzqVRo2X+iveSMajnkVFLr/ByprCYnI+3uwobfPZHdYBBgJqwwE1\ +iJBC6AY71IZrSppqHNImRzSIJLmqi8UQQw5YsbSxzeEStgeiNWIUazZhs67jrJF02+FVPfgqiZKVm9QVbjAfEKHDtOSVMcIDcrRldOkarGo6ClQBMeHBVMpXjET2dbjCZLh8hchFd2UvUdfSvyyan8NNskaL8KCM\ +asYZJUIANxCEtjrciYA56nzMh3Kgmy07PqqgMM52xZtX/RyUNPUZn2wiPr0MRq3zJ3DBMwnBK4yVxnIHSb6BUePkmApPZSV30yo5hq2j22/1emFQZUM24FYdzDgVrvB+3TSqZ3XOkzOplUnwPe3KJKfrMWT4flYp\ +R8Jd6sIFRyOZD3hDl4ZLLKarGHa3NWDEJyoi49eG81+NGcZWEvzcFy+uqZ17Mi9eikqEcIvpQBHtS40lB7m9RKxh70d8JhzN1c1RyzV3WVreG5oEVvqy2n44wv9Z8cdfN9UC/n+FVsWkVNM8z/yX5vJmcds1FlOd\ ++8a6uqlW/iNGW+9t85ceoTxNlco+/xcolYoO\ +"""))) +ESP32S3BETA2ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +eNqNWntz2zYS/yqKYtmRm84QfIKezkVSHVlOrlc7TRQnVadHguT1pjmP7Ki17HO++2FfBEip7f1BmwTBxWIfv31A/z3a1NvN0cmgPFptA22vAK5/rrbKeA90ww9F/NVqa8oXdo4bTqfw78lq2xT2auyEYAAjQDK0\ +75q8M/zM/okH9jaP7WWXqkM7ktor8VeDDxP6UCv7P+0QsawAeUtBa+K+gLFgY8kF3nbKYQNc2NHMTgUaMdABZlWHYE7TVGVHWx7e4qt/vvX3aXmGL6seO5YNu7aGu+BguaC3OLP4f2Z214Xr+aBVwGBHFbBDYacG\ +KRnZVUn0AkNCcKvyBpGl0pNr3mMvD3+hGzeCEl7e7+7DUny0oyFsZRiATkEju3uBa0L81sKsnWfVkReOlbrypGb6bOW9DXW52r8mX8rd68D7OmBbBgJy4cR40DNs5CYc8v7Sb8FYYSfa7aQu6G2RiID1jPQAs+C/\ +ii/F/jK231IPgaeI/MmY6JLEiUSNGPhwYucqNbLjkae5gO9hW0jBG+zqPbJvqrDz5o3paPkKZi1/I7YnEYznMz189e35sCvcPPAEBwqB5U3xQizaE3XsP08mcrcA4vwNQABTE3Mulch1wA4NEi15Yi6STrqwkHv3\ +LRLkrGjtW3MZjj03ZnnmbM+dmTnggXbbhgvUp6x2Tc674LH2IxNe8ReWy7z0ASs87zuWtwA6QOG4kcVEqnifgR/MeXLsdl4zUBZwzzaJ6/sOYxB3Su9TpAeGCTQBHILgkQjAG2UJ1GoOH/ne5FvWtS/XfLVpyXTH\ +r7tfbYjpymNUk4tsOsJhQfZdu5aQETOk2D8l6vEqvogMe2MEBn0FTvfxh4vVakroTzRGRARFoE+t2FLWA3rbAW0f/Tik/yIwH7HAf1UMO40A+MpwwBbJfuaHIW1OhmSXJh6/fQYfngzH8O9ZDAKzztbBzTXtsCnQ\ +x7rwP2F3rUgE2/YuLdjOLMMVQqkH7wo9awCvI2G06DP6HWgKkSokCZWiGkXGWoTOG2BcCcCwDdbK88bQ2WQT7o2BBd4Ndqyj5CWLCpTI5t7sirUIDhj6eiaCQC5gHgiyABkteBHS8rSzBUyAfZmpBMDQj944osYa\ +7RmylmJ4HAXfTDnOhuOrfNGGg69BihqkWIjSkz6LA45AYsL2A2YIAAX3HbJ/gshrEj28r0rWXrlHHjLHsLVHXdr4rdDUTCf7EzoVz4l35+wGXNrJiSRzoXuHZsPPqhwyXpUcCIGb5g/SBpdlXvkPwN7vsL8JBE32\ +9hgeeHhyh//SJ09o9Uqxse61e5RWC3OXLpKUoAh18a1dwlQc3kU3XsDxKTXm2E2m7/ewEPU/fDWkoLs0lFsikjNGld7XAMpFwS5R71EdjOdeAlHKNyNnn2QYaTczCgK0VvPHqnWGYXgfxvyVYXzy1faL/7D2Hzb+\ +w9Z/WCxYtQDQmATGk7cLdp0nhUM4P5lVRXNOO1SIYKUTIDps/Hx1/QFYnjU8Za82L12VgLuthPo7CE3Je0YqtPiMJVTRujh/j4u6PPfGUxQy+XCJLM1H3kxU2OQzSVwxGkvFQ9a13op1ZpAwSRgye8MQQPoNDbZV\ +QvIGI9vDDYOG8coKzCuspkqkjevVYpgjV6DR8sIR1Ikps1HqPhsPw4fTjGC04m1WKPmLzf5t6gyicUZylfw2IFVew47nn5iM8sUJb545UcpLx8iSE66akqKCOUWwSj8RmbKkeCp5LOAVpp8ggfTlavMRZAMfvRZ4\ +e8dBJnLOWzS8TEbpg9HNS+DizSGsAsKAyjd8T1IBRsCNczQTK8wShAm2i47P+8n3xcPEFVFIQe8DAg7VAkGJ6PM5xi1FWvwruLfZ+/eL6TlwSx2BR/g2Az/FpBXuAtdG0BPOYTpl1p4aDUxUdwLApFNE7n6JdUQQ\ +ew9WVEcehdjrX4j5CAvCvdsoUij9IqfR3yHcaEKdTycMSOgkCh8gX0t5GHJFHt62iSpxyA8LemvRME/4Lei9oYRgtaIQhePgITz+/C2GtIs2cwC9/UhAaDlVXKpWpnXt62GBGMeZjmDKDmbDVxnni5KUu+gwK+Hv\ +62EWkvmjkbX48ZocxqjBSKiQTVUNU0RDq5/IzZQ31Rw/7fdewAtNw40McGDwGTQivD6eu8hb7ZjoVPD2Ddk+MO83nKx1XwxdqjnmbF897sfoKt0jJRPvNLJCCoKQKIOXmXgC9TKEUgTgtvIH+IwpWQ3YG3W73V4G\ +4blgpbg/ZLxBRKucxAMmVSgfD5FssYf7EgenhKVNfRxBVIR+HuWw7bYWlB+odNPZ7RWnDYZcypNjNJvCnmfcwVM46QgH1e3lajO+PORKH6pKk90RBYgkaGbIoHwd3fINNpVOgcb6dNDgzWLUYTI+v5x3cxhlDmZ2\ +wdp1O4BdCP9kpASjYJ4G7fzPF7UBMccUa72GDPWMAFyF3TwIqUUudsA4ZGaFP56IqufiGcDwbUdi28rqNM/oQk5SgvkguMv/0fxLMg1yUrSU9G7Q8GST3sjgGci0QQwM5+9ZOukh3DRnOGhpY6+1ee+IUodlPmxt\ +CbMtnx+T8r3lB5e4c+MYwYI5BYoAai/6ak6mKiTLDsk5lSbEH7QhRIu9hYN0RqseN6QDWvV7mb7aIEOMFJAE1pyld8XJDQDgV7UWQ+t2l3vfmtOZP/yftlhAB5YWDpZKYV9WoQhK+dMCmqKyA29QyaAi5oK4G+La\ +iVF/R3/3anOYEPcnLDhOoTxuaRZaYRk6rahsefAckON2X429IdiCXWMG2DJ2SD0+5BapkBoLFM1shCvC32gN7j9wfa0yXpIpIIIllJRYNzul2I8tqYLzPe0Fa7igQtdqBzaXJ1A33XIMguKiiLlDZ9ATOCd39aO0\ +1ZZUWjT13Am+4KvBLuPPO4sdU/mq1bm0YO9osZzwul0e9A8JgfGq8d5Wlnu3ku9uZSnIDeTWjB+EQqIJBg1tfK2zZ2TEhS5YdZhyAC6lxqMVKH7V0kqlbTqiLRR4E3LWzLlCWzzvI+PLPlcYQ9E6wCTqcCC7CM/I\ +KOiTL7ysfgdZ2siZGNpLLJ3eWzJOk249cwbQLOPni5cQG49Zvr4H0FqFrIXcbxO32npDyAQIWCvuvmDsDDiVhxysVuNqhjH0/oDogh/q6AuKI/21bTNfs6WzOiyxja++FBuL12D02w9AejTjXAPy3Zw7zX7MyYMH\ ++yeSkC/uDz0y3e+9FATO6O8l2To0sHEcz1WCs2PudIYcjxKJi9x/hrlKTeBmIK9Sz7woYrJVx+2UjIMpdkCC00G7Gc5IIR7n2KdHePlBTv1CaoG0GB6KY3YFtqE0ItexjOsltSMV4GR4ilqFrBlh0gN8nXd9QzFk\ +qljAW2BTY1fvNwi572CBl2AjCVsk2vSeFpAlfd3a5nzm4+zhqazwQgqQEZfN0lOq2Vj8U0zYcOPVQAVWEx2LBnhA366xnJhS2pMn362uH+kACy2j9iwDxEAWTo4H+oDQC/Go7ab0WCG7p7reqO2Y++A5JiXc0gWU\ +wuOs8Mnq9pAMARZuu7x1+DV2gB7hHqBTIcoVfifYZg23YKmnZACGA2mZxZRaB20rvjn10iW9z9uD+dOOEhw0mXTAVlcl4tjvtiPpNE0ppDb1PTx9cXAmJ+QAgVjO1M6SMDsrWxemQj4IJxyaI/jiFm7WtIzqx2eT\ +Lj+4Ey7M5Wt5lVPqGuizb15NaEzFvg1g4LSsSie/ac9kHqjezPW/X9/hytfMWvMAkX1NpaEJzjLiR6VjSlYxgSupXYVHsOmDS65V1lDwUdmU+iVNvWXowNetc469VKGYUiLX1GvCHR2NW75JGGs5zg+x31KT26Jy\ +rV0hmbo98k+4YOTiM8f4sJSmVFuZSHRqsASZnKHPk/3MHzFvrVxKS6npoRcLsXSu6V780VrC0R2XNzgNGtAoQ0RbFEHn/TecKEPDAM1GYK0Kkavv5THGx89zPguqezkhwpC0ieqrkfNl7deHfoGcc7sL+0clpxJe\ +PSXuPdlAXiCoTgVRMDnDDO6UjxNQUBfkSYaxqwh2AQPDVsSnii27u/hWqe4eK0wzgA+8if0MBDATVV5xMmuM+7iUKBbN/KKObBOjWFkOaBo2DJhHPKPRo2vX/jCooD8vEflQqenv6QZGKh8D8NwlOOXjSXAY6AqC\ +vBV3BfHnMHIIpb3uvOi1SK748IpB2PJ9xKcSqXg+AvIRgXDBca5OLvacX9LHIBATi0ASShBwU3uUqdJXvdMqcPP8PZ8GZq+4c5vTrrTOJnjafw4P6qFPcM6Zf83OtitnJqzWeFA48zgMuYYXVAdzSAe77cFcoaHf\ +QFitrvCXN/nNBabr98X2UPDozp06BuaEtoB1mcge4+Po0p39GnXzI/Fe8AlooT5yn5ePfxDI+BgZmw+aOleYi8sYRGa1E/R/AiAs9SGsdUNSqJSnebZngwfsh3KUygMUiQs42dbc8oXJATezMUYnAzqy50ew+WTt\ +iIJHgaVAXYvHhiLnmgJeUfPJq/weQ84+sj2yS37q2i3t5p5+CPAMFLPNKVwUGvqbjbpweW+VjrlbbzI6pIHeXIH9hsun7GZoi9n5u7n38xMwlbytfO5Jwgq6IzljIIq9/VyfX81/dzgCp79oO+2E/PzD/LNMWIyW\ +G6LvTgSne+BPfSWYuyeb0upvOz7xa7tCwk040INbJP8rjFW7E/BemgopI3C3pd/+uE0WasuNZ3wIn3FWBC1BE7ofCiBUZS7BCvAHNtEjxS2XdR7S9CA7HDII9orinaPqYPxU1kVHHQrhBlpHtOawPfI+cj8SI9Zw\ +9td8iLTvOLySH6/J1tLOp0PHSldWR88H+NvJnz9vilv4BaUKsizK8iAL7Zv6enN7L4M6SFRqB6tiU/R+ammKF0f8xicUhFme5OGX/wGbX9rc\ +"""))) +ESP32S3BETA3ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +eNqNWntz2zYS/yqKYtmWm84QfDPTuUiqI9tJe7XTRHFy7rQgSLY37XlkR61ln/PdD/siQIpt7w9KJAgsFovd3z7A/x5s6u3m4PmoPLjaBrm9Arh+utoq4z3QDT/o+IurrSlf2D6uOZ3D35OrbaPt1dgOwQhagGRo\ +3zVFp/nQ/sQje1vE9rJT1aFtSe2V+LPBwIQG5sr+px0ilhUgbynkOXGvoS3YWHKBt5xy3AAXtjWzXYFGDHSAWdUhWFA3VdnWloe3+Oqnt/46Lc8wsuqxY9mwc+dwF+ytTukt9tT/T8/uvHA9G7UbMNrZClihsFOD\ +lIysqiR6gSEhuFl5gchS6cm16LFXhL/QjWtBCa/ud9dhKT7a1hCWMg5gT2FHdtcC14z4rYVZ289uR6EdK3XlSc302Sp6C+pyNTwnX8rd54E3OmBdBgJyYcd41FNs5CYc8/rSr0FZYSW5W0mt6a1ORMD5gvYBesG/\ +ii9E/zLW3zIfA08R2ZMx0QWJE4kaUfDxzPZVamLbI2/nAr6HZSEFr7G775F9U4WdN29MZ5cvodfqd2J7FkF7scjHr74+G3eFWwSe4GBDYHqjX4hGe6KO/efZTO5OgTiPAQhgaqLOpRK5jtigQaIldyxE0kkXFgrv\ +vkWCgjc697W5DKeeGbM8C9bnTs8C8CB3y4YLtk/Z3TUFr4Lb2kEmvOQRlsui9AErPOsbljcBGoB23MhkIlW8z8AOltw5diuvGSg13LNO4vy+wRjEndIbivRAMYEmgEMQPBIBeKMsgVotYZBvTb5mXftyLa42LZlu\ ++3V31IaYrjxGczKRTUc4LMi+aVc5scSAYn9K3MXL+DwybIsRqPMlmNzH78+vruaE/UTBmlHN6JLnx1ZoKe8C2toeLR6tOKR/EZePV2C9KoZ1RgB7ZThifWQr851Qbp6PSStNPH17CAOfj6fwdxiDuKypdVBzTS6x\ +0WhhXfBHK/oFJGrvN/yfatYwy2yFIOoBu0KbGsHrSJjUfSa/RUogvZCkU8qmKFJTHTo7gHYl0MLaVyvPDkOnjU046P003o129KLkKXUFG8iK3uyKVAd7DHo95UAIFxgPBFOATC5IEdL0tLJT6ADrMnNxfaHvt7FF\ +TXPUZIhX9PgoCr6as4cNp5fFaesIvgQp5iBFLRue9Fk85VhH1NcOYIYASnDdIVsmiLwm0cP7quTdKwfkIX0Ma3rUpY1jhWbOdLK/oFNxn3i3z66rpZU8lzAudO9QbfhZlWNGqpJdIHDT/EnA4OLLS/8BbIigCW3B\ +muaGb6vAa69M+5A+eUJ8VIrVdtACUG4t1F04b1LClqjzry1FU7GLl13ynI5PqTFHrjONH2Ah6g98NSbHuzIUXyKaM1KV3mhYmNZsHPXAJkJ74QURpYyZOE0lFUm70VEQoN6aP99kpyKG12HM36nIb/4G/uI/rP2H\ +jf+w7W56jV4K9/On1oBoMdyczp9oB3p+ZKt0c0ZjFIJa6SSJNhw/u7r+ALwvGu4yuK0XLmXAZVdC/R34qeQ9gxcaQcaiqmhe7D9gtS7ovfF2DJl8uECWlhOvJ+7c7BOJXjFAS/pDarbeippmED2JVzKDXglQ/oYa\ +25QheYOO7uGGccR4OQYGGXbLSqSN89WioROXrdH0whEkjSmzUeZ9Nh7GD8cZIWvFy6xQ8ueb4WXmGTjnjOQqwW5AW3kNK17+xmSUL054c+hEKS8dIyuOvmqKkDRziviV/kZkypJcrAS1AGEYi4IE0pdXm48gGxj0\ +WhDvHfudyFmxbniajKIJkzcvgYs3+zALCAPS4PA9SQUYAXsuUE2sMEsQJuguIgCvpxhykYnLqJBCPoQI7L0FixLZz2foyhTt4t95ABvKf3c6PwNuqTzwCGOzGYQ4wCTcBa6mkM84pOnkXAMJG6ho3vEJs05GuTsS\ +k4og9h6sqA48CrFXzBD1ERaEe7dQpFD6GQ+yk4n3CVr4YZdT8YOOOTTDWcRFlc5bGeNuXQdkTcANE0R5KFz/3FHREgofCs8zztBkXOWI2F+jOKGtTGvz12ON4MdRkYDNDqrDqIxjSwndnf9YlPD7epyFZBeofS2w\ +vCZLMmo0ESqkbFXDFFED6ydyMyc8aJqjp/0KDZinabjcAZYNxoTahdfHM+ebqx3dnQsQvyGjAOb9spRV+/OxC0unnBWox2HwrtIBKZl4p9wVkpuEoBrMz8QzyKrB2SIyt/WBEWoOBrYBm2neLrcXY3i2WSmuIhmv\ +EWGsIPFAOqGVD5RIVg9wX2LjnEC2qY8icJdQ9aN4t13WKUUQKt10VnvJgYUhW/PkGC3msOYF1/kUdjrARnV7cbWZXuxzPQByT5PdEQVwMahmyKCMjm75BktPx0BjfTxq8OZ00mEyPrtYdqMcZfYWdsLa1USAXYgL\ +SEkJX0E9Der5X09qPWWBQdh6DdHsCSG7CruRElKLnFOBdojdtN+eyFYvxTKA4duOxLaV3dMiows5SQn/g+Cu+Gfzs4QgbPqgKendqOHOJr2RxhOQaYPgGC7fC/bsw01zgo2WNlZkm/eOKNVhluNWl7Aw5/NjUr63\ +/OAUd64dXVuwFKBsZNSSVFVIlh2SS0pjBBtVIbvYmzhIFzTrUUN7QLN+J92vNsgQIwVEhzXH8V1xcqEA+FWtxtC83enet+p04jf/p00n0ICl0INpVdiXVSiCUn63gLqobM9rVNKoiLkg7vq+tmPUX9E3Xh4PHeJ+\ +h1OO8lAet9QLtbAM3a6obLX3DJDjdigf3xBswaoxNGwZ26dKIHKLVGgbNYpmMcEZ4Tdag/mPXPWrjFekCohgCUUr1syOyQsXkuKlrg5LrNgLsvlc7cDm6jlkVrfsgyD90DHX8QxaAgfrbfraFt9WVCNq6qUTvOar\ +wVrkjzuTHVGqm6szKdTe0WQF4XU7Pew/FJmMl7n3lrIaXEqxu5SVIDeQWzN+EArJTjBo5MbfdbaMjLjINW8d2Dusz6TGoxUoftXSSqW4OqElaLwJOZzmWKFNr4fI+LIvFPpQ1A5QiTocySrCE1IKGvKZp83fQTA0\ +cSqG+hJLPfiWlNOkW0+dATTL+NnpS/CNRyxf3wJoLi1zIffbxM223hAyAQLWiis16DsDjvEh5q7VtFqgD73fI7pgh3n0GcWR/toWo69Z03k7LLGNv30pFiCvQem3H4D0ZMGxBgZ9XI/2fU4RPNifSFy+mD/U0/J+\ +nUYTOKO9l6TrUObGdjx9CU6OuCIasj9KxC9ylRr6KgVRqR7Jq9RTL/KYrNVx2yVjZ4o1kuB41C6GI1LwxwVW8xFevpezwZCKJC2Gh2KYXYFtKIwo8lja8xWVLhXgZHiMu/oWeP3GDxGoj28biiFTxQLeAps5VgB/\ +B5f7DiZ4CTqSsEaiTg8UiSzp61Y3lwsfZ/ePZYYXkplMOJ+WqlPNyuKfdcKCGy850iCPrkYDPKBt15iOzCnsKZJvr64f6ZgLNaP2NAPEQBpOhgf7Aa4X/FFbZumxQnpPCb9R2ynXywsp3qMKZHzoFT65ut3nrKr2\ +KsJ1+CXWiB7hHqBTIcppv2pso4Zb0NRjUgDDjrTMYgqtg7Zk3xx74VI+ZO3B8mlnExw0mXTEWlclYtjvthM+lAQpgktt6nt4+uzgTM7RAQIxnamdJmF0VrYmTBl+EM7YNUcw4hZu1jSN6vtnk64+uHMwjOVreVVQ\ +6BrkJ1+9mlGbin0dQMdpWZWqf9Oe3ABkJLDAf7++w5mvmbXmATz7mlJDE5xkxI9KpxSsYgBXUh0LD2rTBxdcq6wh56OyORVSmnrL0IGvW+OceqGCnlMg19Rrwp08mrZ8kzDWcugfYiGmJrPFzbV6hWTq9sOAhBNG\ +Tj4L9A8rqVa1mYl4pwZTkNkJ2jzpz/IR49bKhbQUmu57vhBT55ruxR6tJhzccXqD3f6AdqCMaIsi6Lz/igPlOmW1EVirQuTqO3mM8fHTks+M6l5MiDAk9aP6cuJsOffzQz9BLrgOhoWlkkMJL58S855tIC4QVKeE\ +KJidYAR3zEcPKKhzsiTD2KWDXcBAtxXx2WPL7i6+Vaq7xgrDDOADb2I/AgHMxC2vOJg1xg0uxYtFCz+pI91EL1aWI+qGBQPmEc9z8sm1K38Y3KC/ThH5AKrpr+kGWiofA/CMJjjmY0wwGCgXgrwVlwvxoxk5sMq9\ ++r3sq04u+aCLQdjyfcDnFqlYPgLyAYGwZj9XJ+cD55w0GARiYhFIQgECLmpgM1X6qneyBWZevOeTw+wVl3QLWlWeZzP8JuAMHtRDn+CSI/+ajW1XzkxYrfFQceFxGHIOL6gO6pCOduuGhUJFvwG3Wl3i9znFzTmG\ +6/d6uy94dOdOKAPznJaAeZnIHv3j5MKdERt18y/iXfNpqVYfuQDMB0QIZHzcjMWHnCpXGItLG3hmteP0fwAgLPN9mOuGpFApb+dZnw0ew+/LsSs3kCfWcAKecy0YOgdc5UYfnYzoYJ8fQeeTtSMKFgWaAnktHjGK\ +nGtyeLrmU1r5akMORbIB2SU/dPWWVnNPnwscwsZsC3IXOj+Hmoc6d3FvlU65jG8yOr2B2pzGesPFUzYz1MXs7N3S+0gFVKVoM597krCC6kjBGIhib4fnZ5fLPxyOwEkx6k7boTj7sPwkHU4nqw3Rd2eG8wH4U18I\ +5g5EU7n6x45N/NrOkHARDvbBTVL8Hcaq3Q54L0WFlBG4W+tvP4GTidp045AP7DOOiqAkaEL3UQFCVeYCrAA/w4keyW+5qHOfugfZ/phBsJcU7xxrB9OnMi8a6lgIN1A6ojnH7fH4gfuUjFjD3l/y6dLQ0Xkln7jJ\ +0tLO0LFjpSurg2cj/MLyx08bfQvfWaogy6KsCLLQvqmvN7f30pgHiUptY6U3uvdBptEvDviNTygIsyIpws//Ay4v6A0=\ +"""))) +ESP32C3ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +eNrFWmt328YR/SuypEix29PugngqtUw6lChKlmvnpFGcA6UGdgHVSatTyVQtt+V/7955ECAl0vnWD3wBi93ZmTt3Hsv/7M+a+9n+wVa9X94bW97b8Kqz8B0v8/60vHd5+DYo76uivM/p6l64WL0Ob+l34S0Ol9Lw\ +2WyHNydPx/R0ed/6dxnN8SK8mVdh/sEsXMXttrwt7xsTfkXDerwTFsh3WYY6mpb3Phq/nG6HZ01ShYWj8Apj83wY3gblfnmNFTDfXZghofloVJHNw9WwQBNktkX40oY7Lghft1m5T3L99yyM82F8zc+2bZatuaFL\ +j1g1tNPw8j6jnfJ8ED4VnUUL5YVXUF0RXm6Az2/nIkt+gT0OIfxRt44Jn3kxYhU8vmjxYi5L8wrDngy6Uvfbum9hAJ49rLc0tVqbjJaNoaFgomLAUwejBjMV7kxtSyYnQ75mWerwtMvOsyfhIwjubYbtsOX5aZuf\ +hGF+EiDhw4hGYGHdGJdZx8BUMxhNaR8zkcvIIAgD+znRZpWwzu/bTDRmus020F5bllDBzlYm2+trwDrIMyAQ70OzjrEd1joMCxU7uwI/wqMAUMC4hEGTLOQ1okcnXmMHPeM7aHAU3m3N8uFqblkVeTLBbTz6BNAH\ +hAyDAMPa4uIQg/qrQpNwwEYWyItjXAnb83Kl9Re8X8gC9cEqNKXtZKsNHA8S02QDxhjkaxtMOlFv6cEhPIJ9pOJqRsBmuyG649Z2qwM6nlYjwWipiNHQuodTQLB/8MJ1dkSIFAfAiDw5Io2TL7x94aayM2Axm/Tw\ +i10pZPJBzzOFxzxG40ePOl5iyIjHW5GcdGdwJ8WdKFioiGTqPAXR7Agudfv9yQt71YlDy8fdItBlwzgmvsCcRJFqowXkMUtdYTEh4d5miGhT2fl6HdBvYRATY+mg4AY/jPAWb0kQ6PUHNstLPeE7AZNsRCM4gBFX\ +eUWm9P0pGxHYCzK/xDxENvg6UfrpM0+fZQA4sISAsgKAY6YVRxZ5OpY78N9iD36OGd4xxplqTtxfwjQd87hL7BWmKWfPiXBPhnuiw4adshDdgj/ALeTRhsNZ44QTEt3VkFyjpOHlkBUUZihJyHIsrBTj4nDMEfUL\ +HHSb3LGjaMjuReC7b4RpXfPi7xok8fiYZV0nOxTW1MJMNmFKqKMJ74Kwmm0dsg0a+00/zkwUjMNH1vPMzMy3cPPoaJ0Q4HFQTwhizIaaHQgX9lQw0lRFYW8SRUsaYJc3Hex6DjFj2YBO1ycyosmrOTs9khhEbCd3\ +gIXcHzDMACR8Iv6By3MMrnf4BhPhCIGgYG5jTbxhblz1lZXwvhw84KhG4kakEyl7b7KhH3SjHY3u1rVCI/zclUwCjUSrAYLYOu8Cw8YlbbckEz60W2cj9fMYLh3pVp8x2mtx5Jos4Vi6IuZlgszbyAGi8WragpzJ\ +yCiKAPER4hhxy90NmMLOP+LWB6yc7IkxwxZ8wxv1SElAUpVIlM0BDFi2C0czVkYu5KusA8Hb6pAFZVbZZnAq+axTVIW8eXlyk/zSrUAkUE3CduuCmSRAshdg6QVBC9E0i7JGxEJEXH68txpMmmx/ic52ZISzR/gC\ +P8M3k7hOYXU1fAZTVePyOvBUm75rf4KCf5ouvBX0WbiPGKSG+3DKlApD5MnrL/MqQAYgNH7pyY1beM/RDtGkKJRnd0efe9laAmnShulUQazZzFp/cdHNzfzjD/D9n0BAPwNFtbAKxb9tMN8e3PEUsiN4tSiXPOQZ\ +/ML00AgqKzGjqnRJjugPnCzXUGWdMueAE1y0ad9greTKwYM/8Yx54hU/uRZpmyG+UblbIIj5v9dPSNhzB8ygBDj3cHBY9ZYfIZ7VXMdOD6UUS1YTqWzFZyhNsJLseUQdrNNGIZc0tbthfzKDG6TZUkVwHAcqk7fw\ +pCR7zZiqvowpflnhlAKFcFG42QdGSq0kWiDzR1aRZ/07vxuxxXOScfBJKl66siTDD1/AtYsuOaP6rQpCjHKs9zZH8JoirJ2HqxhT6J32Cyav47mkR9BAEvOPpuLHvE/dnzvsIog00XMppNcLShfJ7N9xYn3NaTUJ\ +moAuta5YJKEo8TUJtXbCF/OcMwhqMPx/2XNYzpqkz54+VPvJqmtvpjwwyQrVvnn2PUD3fXn9DvJPfwG7VKenZ7h59uwVbr4qr8/Bw5fnvaq1zi5G03c3nQWQ0WGzgdAPxSOEVCvEyFgS+Yjp0xse4ySGOomhdK9i\ +8YFryg4jTmJRZICjAA5nrnnApjyicprR5S+yTyv1jKZGmqbgWo0nGqmJbZTAGvbob5z3VRhpk4SBs6ixluujJ1eHhLgtSXG1rkryoTbC8I0fmnBKZOyx1qRqy0WTyyZHNJfEubVu1LquyVaWk4e4qGlKVQDtL6OU\ +sGTRN+GmrTYQh6lFydw0cn+VvVRsTFHx9aLBJs0ByAd/I7mBR0sXE/7CrY2jTdkPyBmucJWdycbQqbArXRPkvHnSjlq1Q9dkocwjiDpD1KVukf81e6VWXadocD4Rda0BicG7aA9ksu+c94f4TNfj7nooibiuvZaq\ +lqjSsqEwGEqxnJPOMJTKJ7lfDZbH4+XTp9TNcdoXO6efqfxMBbyVPfqaVVIkVhg3izvZXbYrMLPtNnR4yaXWwmXAH6i72rrXgPsNlcR7LnKWy4hNpi16ExNzNZsRSs2pAjG5zrT1pf0Ky9+J8RPdaNz1WBa7rqRD\ +4QupMDUMoHWB1cgPqJXovj2E1j9wmucKNRIbZcqXly2ZUHcNXpF9DSC0KW/LctsNG8uixY28vKXLtU7hfpU7cTmjO+Q725TadNGG2g6t9qKoLf4h1Z8Isu3b9HMhsppVEZ8TamizQ4c2ZxaRFhbQeg1xJ9IlbLI3\ +5a1qSDhlMWfyGKyscByHCVF4ImmHlwoXpQ+12T3bq7C03ZjK7GsA6VjWlL4QrOJgKpMcSXeUqNeJsXx+srOrFIoCpKm0G8aZcsWmQQTKtpxQXirh1B93O/SaQgy+OqXKHHzjNAfYddIUpO12VnkvsiSMiortnUtS\ +Xy0WiGQB6odAyWSkjDsd3iEU568QSU/CN3MC2hljovFmV8pb1McFmJV7IFIuU/zPzlUYQVmtKBsdC4PQjXQBP4T+BzoBLbHIUF22J/s3diydX8cqbqSTF08VN1kfNxNlYjTTfN0j1EJK+oL0u73DroPQo23YKqYF\ +vxL+oLbiFrWZc+lCWkwAFl3YVnqPhtvRyFm9sJzesoveRSF9cbTjeK9GgUZZ1dEzxfVU+vdep5HpAfTspV4cLiYWpVDK26kA4ETrJUB41BWOsktxiKafwsRdmZnbSbcFogRI7bw80Sjvfd/30bFGxmmf+vmeF3hF\ +D+7IoUWzQp2UPIsbNXknoRUJq4QVZJLxufRc12S94W0QK3TfSpdywME/lz07Q03PK2YR1UhBSYkdyfz2AO7kR2jjFH7OFW3r55q/+yFfanJJDWrK9KQvVwhIXbYU1+Y0xzUHrEZSw3rw6Ss5+iEPHn3o1nDXUhyZ\ ++efu6mew1MaVwEqhNLZg5eKU12u1Kbbpscp8lsfYBrsjgWcrrKlxUSh0LOWQl3Mx0+cZXxyI7doHDyTdA4U7cewpGuQcDstoCpNEbCZOx/Rp8aWmWTwd9Z6GfXUK6W1TPoLwVERcic70BCKW9oacjtWZHFi0i5h/\ +zBeoyE+kvrbS5PUCTOKv5EjmgC9LiBGB5byFvBb7WmSrj9vu7rkegX0S1jByjlkDrZeTXoSMO2STGK2/xKJ3cr6ZnIzXr5SDlawb/wg0x8M53FHO+fSopDBCQq539gkU5K3me7n4eiiVR+y4Xo/w7OSJnLfi1JwS\ +GmLmJumSzbBJPXBSzhl8rWOl3iGOqtU0lJaLP7T50HHZrfzWSJ5NnbAGIdxzMN+VPrkRZxismNqa110CWCiDUQIh+6mWrSonE0Rng91OZCsnQIuqnngsrH8tSQV9IsbykbP4VC8L2OItIP5Q/6ifteXCiu6xm4Xp\ +PWlXbpr+k3Y6kRSTyjvnNEDFRyuJLPWH1ubBSyC0D/NiKge8ZNWtHGA/CNXBs24lA4fyBm6MBp91P/JhvpZp/yRFsh2borM3R3o5rRx0FjRIkavF8YKEeK1HnF4f9uM2bVnyBBc/zEwR8OJLTgEfd6ytn7s/rfAO\ +R5QufaRUb5s5nWBKwRtd1S5cG+JrKw7KeppRGP+hOyhU/XFwcG8IxAFVTdtl9d7ccbJMcyc6d5527QO12fpw8I4SrOXDRNF/W/RlmUpwreRsGkpfHqG64Ibf/oiK2qebBWjMxVMC4KzpNSmSm55+1UBmA885M136\ +YxEC6Fl3ht3/I4Ul9VxIV9cSmO8Yyfq/EUW2/p2DheEsYCBHjlnXX3tcsafdfnJzuDZlOJb+dfx4Kq/2Llo2Jnl23F2v5Pwht/rXhn/piaUiKGWv2dClYp/M20Nuvi2wR2ETf3gKE15zk4776SF31E5/3K1gkhM5\ +MW8577o9eYmW3YH060jkP1KdOolO5D8YDKSA1VJaEZKnahPF6msgxIyItk7rjP/ogna/L4kFsOOGYk3kMZTaedkw9WGjC8QOCvZUD+mBQiInsKb3DwKRiw4PPM729SiZ/k1BHFNw/GlS6XYvOW2x0/U0yDMSDg6S\ +Rsy4sdmIbrFkFXXLS6TpOygsr8UtLe/kMaNNrcc57PlDn3t85LDY5Hh/YoeoK0nMiPZyCVbNRhEg48FvchMQhZZpMR/WEabTN3toWKcoXVK0rNNpi5Z1enoM90/P9lAnp69wG5VFdNksmtb7v9+ivyf+9eOsusWf\ +FK3JstjaPDbhTnM9u/28uDgYRLjoq1ml/2YEpIIv7cvl/izGpnFh4vn/AOixonk=\ +"""))) + + +def _main(): + try: + main() + except FatalError as e: + print('\nA fatal error occurred: %s' % e) + sys.exit(2) + + +if __name__ == '__main__': + _main() diff --git a/user_setups/esp32/d1-mini-esp32_ili9341.ini b/user_setups/esp32/d1-mini-esp32_ili9341.ini index 0aa478e1..8746bd98 100644 --- a/user_setups/esp32/d1-mini-esp32_ili9341.ini +++ b/user_setups/esp32/d1-mini-esp32_ili9341.ini @@ -9,10 +9,6 @@ extends = esp32 board = wemos_d1_mini32 -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} @@ -36,7 +32,3 @@ lib_ignore = ${env.lib_ignore} ${esp32.lib_ignore} ;endregion - -extra_scripts = - ${env.extra_scripts} - ${esp32.extra_scripts} \ No newline at end of file diff --git a/user_setups/esp32/d132-unoshield_ili9486_parallel.ini b/user_setups/esp32/d132-unoshield_ili9486_parallel.ini index 9d7deb39..b1c84d76 100644 --- a/user_setups/esp32/d132-unoshield_ili9486_parallel.ini +++ b/user_setups/esp32/d132-unoshield_ili9486_parallel.ini @@ -8,10 +8,6 @@ extends = esp32 board = esp32dev -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/esp32-dev_ili9488.ini b/user_setups/esp32/esp32-dev_ili9488.ini index 2046ff56..6fbcbba4 100644 --- a/user_setups/esp32/esp32-dev_ili9488.ini +++ b/user_setups/esp32/esp32-dev_ili9488.ini @@ -8,10 +8,6 @@ extends = esp32 board = esp32dev -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/esp32-dev_ili9488_parallel.ini b/user_setups/esp32/esp32-dev_ili9488_parallel.ini index 6634edac..0cfde697 100644 --- a/user_setups/esp32/esp32-dev_ili9488_parallel.ini +++ b/user_setups/esp32/esp32-dev_ili9488_parallel.ini @@ -9,10 +9,6 @@ extends = esp32 board = esp32dev -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} @@ -55,5 +51,4 @@ lib_ignore = ${env.lib_ignore} ; ${esp32.lib_ignore} lv_drv_fsmc_ili9341 - ;endregion diff --git a/user_setups/esp32/esp32-touchdown.ini b/user_setups/esp32/esp32-touchdown.ini index db075cb8..61ae1322 100644 --- a/user_setups/esp32/esp32-touchdown.ini +++ b/user_setups/esp32/esp32-touchdown.ini @@ -8,10 +8,6 @@ extends = esp32 board = esp32dev -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/esp32cam_st7796.ini b/user_setups/esp32/esp32cam_st7796.ini index fd51c356..d85b7810 100644 --- a/user_setups/esp32/esp32cam_st7796.ini +++ b/user_setups/esp32/esp32cam_st7796.ini @@ -13,8 +13,7 @@ board = esp32cam build_flags = ${env.build_flags} ${esp32.build_flags} - -DBOARD_HAS_PSRAM - -mfix-esp32-psram-cache-issue + ${esp32.ps_ram} ;region -- TFT_eSPI build options ------------------------ ${lcd.raspberrypi} diff --git a/user_setups/esp32/huzzah32-featherwing-24.ini b/user_setups/esp32/huzzah32-featherwing-24.ini index d0accad0..2c1d23fc 100644 --- a/user_setups/esp32/huzzah32-featherwing-24.ini +++ b/user_setups/esp32/huzzah32-featherwing-24.ini @@ -9,10 +9,6 @@ extends = esp32 board = featheresp32 -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/huzzah32-featherwing-35.ini b/user_setups/esp32/huzzah32-featherwing-35.ini index e6195047..0555d4b4 100644 --- a/user_setups/esp32/huzzah32-featherwing-35.ini +++ b/user_setups/esp32/huzzah32-featherwing-35.ini @@ -9,10 +9,6 @@ extends = esp32 board = featheresp32 -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/lanbon_l8.ini b/user_setups/esp32/lanbon_l8.ini index b5f44da9..780fb0ab 100644 --- a/user_setups/esp32/lanbon_l8.ini +++ b/user_setups/esp32/lanbon_l8.ini @@ -54,7 +54,3 @@ lib_ignore = ${esp32.lib_ignore} ESP32 BLE Arduino ;endregion - -extra_scripts = - ${env.extra_scripts} - ${esp32.extra_scripts} diff --git a/user_setups/esp32/lolin-d32-pro_ili9341.ini b/user_setups/esp32/lolin-d32-pro_ili9341.ini index f31e7639..a3fb65ce 100644 --- a/user_setups/esp32/lolin-d32-pro_ili9341.ini +++ b/user_setups/esp32/lolin-d32-pro_ili9341.ini @@ -7,7 +7,7 @@ ; !! This board already defines TFT_CS, TFT_DC and TFT_RST !! -[env:lolind32pro-lolintft24] +[env:lolin-d32-pro_ili9341] extends = esp32 board = lolin_d32_pro @@ -41,7 +41,3 @@ lib_ignore = ${env.lib_ignore} ${esp32.lib_ignore} ;endregion - -extra_scripts = - ${env.extra_scripts} - ${esp32.extra_scripts} \ No newline at end of file diff --git a/user_setups/esp32/m5stack_core2.ini b/user_setups/esp32/m5stack_core2.ini index a379ef26..7eaa0427 100644 --- a/user_setups/esp32/m5stack_core2.ini +++ b/user_setups/esp32/m5stack_core2.ini @@ -53,7 +53,3 @@ lib_ignore = lv_drv_fsmc_ili9341 lv_drivers ;endregion - -extra_scripts = - ${env.extra_scripts} - ${esp32.extra_scripts} \ No newline at end of file diff --git a/user_setups/esp32/ttgo-esp32-poe_ili9341.ini b/user_setups/esp32/ttgo-esp32-poe_ili9341.ini index 630154fe..30b0f53e 100644 --- a/user_setups/esp32/ttgo-esp32-poe_ili9341.ini +++ b/user_setups/esp32/ttgo-esp32-poe_ili9341.ini @@ -6,14 +6,10 @@ ; - xpt2046 touch controller ; ;***************************************************; -[env:ttgo_esp32_poe-lolintft24] +[env:ttgo_esp32_poe-ili9341] extends = esp32 board = esp32dev -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} diff --git a/user_setups/esp32/wt32-sc01.ini b/user_setups/esp32/wt32-sc01.ini index 6a1999a8..7b489c3f 100644 --- a/user_setups/esp32/wt32-sc01.ini +++ b/user_setups/esp32/wt32-sc01.ini @@ -9,10 +9,6 @@ extends = esp32 board = esp32dev -board_upload.flash_size=4MB -board_upload.maximum_size = 4194304 -board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv - build_flags = ${env.build_flags} ${esp32.build_flags} @@ -46,7 +42,3 @@ lib_ignore = ${env.lib_ignore} ${esp32.lib_ignore} ;endregion - -extra_scripts = - ${env.extra_scripts} - ${esp32.extra_scripts} \ No newline at end of file From de62f90fe77910725ecea9702c0468056340d443 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Mar 2021 01:14:31 +0100 Subject: [PATCH 232/236] Add esp32-touchdown and m5stack-core2 --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b76a7530..67e7beb1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -44,7 +44,7 @@ jobs: run: | cat platformio_override.ini - name: Run PlatformIO - run: pio run -e d1-mini-esp32_ili9341 -e lanbon_l8 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits + run: pio run -e d1-mini-esp32_ili9341 -e esp32-touchdown -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits - name: Upload output file uses: actions/upload-artifact@v2 with: From 036a47f772c0af7cf1b53a25a413483743983f84 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:32:52 +0100 Subject: [PATCH 233/236] Decode std output --- tools/esp_merge_bin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/esp_merge_bin.py b/tools/esp_merge_bin.py index 1bc1a9c4..58fa2c46 100644 --- a/tools/esp_merge_bin.py +++ b/tools/esp_merge_bin.py @@ -63,8 +63,8 @@ def copy_merge_bins(source, target, env): stderr=subprocess.PIPE) stdout, stderr = process.communicate() stdout, stderr - print(stdout) - print(stderr) + print(stdout.decode("utf-8") ) + print(stderr.decode("utf-8") ) def copy_ota(source, target, env): version = 'v' + str(HASP_VER_MAJ) + '.' + str(HASP_VER_MIN) + '.' + str(HASP_VER_REV) From 57435c6c3311d86833f61cd61a92dfd84a5a4824 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:33:10 +0100 Subject: [PATCH 234/236] Add Adafruit Featherwings --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 67e7beb1..3bbac949 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -44,7 +44,7 @@ jobs: run: | cat platformio_override.ini - name: Run PlatformIO - run: pio run -e d1-mini-esp32_ili9341 -e esp32-touchdown -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits + run: pio run -e d1-mini-esp32_ili9341 -e esp32-touchdown -e huzzah32-featherwing-24 -e huzzah32-featherwing-32 -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits - name: Upload output file uses: actions/upload-artifact@v2 with: From e07857533aeb2baaaa9d3bc1a3955141024ea33a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:33:19 +0100 Subject: [PATCH 235/236] Tidy up code --- src/hasp/hasp_object.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 75d628fa..ddd12286 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -24,6 +24,10 @@ #include "hasplib.h" +#define HASP_NUM_PAGE_PREV (HASP_NUM_PAGES + 1) +#define HASP_NUM_PAGE_BACK (HASP_NUM_PAGES + 2) +#define HASP_NUM_PAGE_NEXT (HASP_NUM_PAGES + 3) + const char** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map // static unsigned long last_change_event = 0; static bool last_press_was_short = false; // Avoid SHORT + UP double events @@ -370,14 +374,18 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) if(obj->user_data.actionid) { if(eventid == HASP_EVENT_UP || eventid == HASP_EVENT_SHORT) { lv_scr_load_anim_t transitionid = (lv_scr_load_anim_t)obj->user_data.transitionid; - if(obj->user_data.actionid == HASP_NUM_PAGES + 1) { - haspPages.prev(transitionid); - } else if(obj->user_data.actionid == HASP_NUM_PAGES + 2) { - haspPages.back(transitionid); - } else if(obj->user_data.actionid == HASP_NUM_PAGES + 3) { - haspPages.next(transitionid); - } else { - haspPages.set(obj->user_data.actionid, transitionid); + switch(obj->user_data.actionid) { + case HASP_NUM_PAGE_PREV: + haspPages.prev(transitionid); + break; + case HASP_NUM_PAGE_BACK: + haspPages.back(transitionid); + break; + case HASP_NUM_PAGE_NEXT: + haspPages.next(transitionid); + break; + default: + haspPages.set(obj->user_data.actionid, transitionid); } dispatch_output_current_page(); } From 44be606e782a71b159768e86f0ce740b2e75dc1b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:44:51 +0100 Subject: [PATCH 236/236] Correct huzzah32-featherwing-35 --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3bbac949..190e2497 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -44,7 +44,7 @@ jobs: run: | cat platformio_override.ini - name: Run PlatformIO - run: pio run -e d1-mini-esp32_ili9341 -e esp32-touchdown -e huzzah32-featherwing-24 -e huzzah32-featherwing-32 -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits + run: pio run -e d1-mini-esp32_ili9341 -e esp32-touchdown -e huzzah32-featherwing-24 -e huzzah32-featherwing-35 -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits - name: Upload output file uses: actions/upload-artifact@v2 with: