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