diff --git a/include/hasp_conf.h b/include/hasp_conf.h index a5619c46..59ef00c1 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -33,6 +33,11 @@ #define HASP_USE_APP 1 +/* Validate that build target was specified */ +#if HASP_TARGET_ARDUINO + HASP_TARGET_PC != 1 +#error "Build target invalid! Set *one* of: HASP_TARGET_ARDUINO, HASP_TARGET_PC" +#endif + #ifndef HASP_USE_DEBUG #define HASP_USE_DEBUG 1 #endif @@ -190,6 +195,41 @@ #define HASP_OBJECT_NOTATION "p%ub%u" +#ifndef HASP_ATTRIBUTE_FAST_MEM +#define HASP_ATTRIBUTE_FAST_MEM +#endif + +#ifndef IRAM_ATTR +#define IRAM_ATTR +#endif + +#ifndef FPSTR +#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) +#endif + +#ifndef PGM_P +#define PGM_P const char* +#endif + +/* Workarounds for PC build */ +#if HASP_TARGET_PC +#ifndef __FlashStringHelper +#define __FlashStringHelper char +#endif + +#ifndef F +#define F(x) (x) +#endif + +#ifndef PSTR +#define PSTR(x) x +#endif + +#ifndef PROGMEM +#define PROGMEM +#endif +#endif + /* Includes */ #ifdef WINDOWS #include "winsock2.h" @@ -281,7 +321,7 @@ static WiFiSpiClass WiFi; #if HASP_USE_MQTT > 0 #include "mqtt/hasp_mqtt.h" -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC #define HASP_USE_PAHO #else #define HASP_USE_ESP_MQTT @@ -326,51 +366,20 @@ static WiFiSpiClass WiFi; #include "sys/svc/hasp_slave.h" #endif -#ifndef HASP_ATTRIBUTE_FAST_MEM -#define HASP_ATTRIBUTE_FAST_MEM -#endif - -#ifndef IRAM_ATTR -#define IRAM_ATTR -#endif - -#ifndef FPSTR -#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) -#endif - -#ifndef PGM_P -#define PGM_P const char* -#endif - -#if defined(WINDOWS) || defined(POSIX) -#ifndef __FlashStringHelper -#define __FlashStringHelper char -#endif - -#ifndef F -#define F(x) (x) -#endif - -#ifndef PSTR -#define PSTR(x) x -#endif - -#ifndef PROGMEM -#define PROGMEM -#endif -#endif - #if defined(WINDOWS) #include #define delay Sleep #endif + #if defined(POSIX) #define delay SDL_Delay #endif -#if defined(WINDOWS) || defined(POSIX) + +#if HASP_TARGET_PC #include #include #include + #if USE_MONITOR #include #endif diff --git a/include/hasp_macro.h b/include/hasp_macro.h index f1f937b9..7dc1f82b 100644 --- a/include/hasp_macro.h +++ b/include/hasp_macro.h @@ -12,15 +12,15 @@ #include "user_config_override.h" #endif -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC #define HASP_RANDOM(x) rand() % x -#elif defined(ARDUINO) +#elif HASP_TARGET_ARDUINO #define HASP_RANDOM(x) random(x) #else #define HASP_RANDOM(x) random() % x #endif -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC #define LOG_OUTPUT(x, ...) printf(__VA_ARGS__) #else diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index 14ec75fa..e2adf67e 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -227,7 +227,7 @@ typedef void* lv_fs_drv_user_data_t; //# define LV_FS_IF_SPIFFS '\0' // no internal esp Flash #endif #endif /*LV_USE_FS_IF*/ -#if !(defined(WINDOWS) || defined(POSIX)) +#if HASP_TARGET_ARDUINO #define LV_FS_PC_PATH "/littlefs" #endif diff --git a/lib/lv_lib_zifont/lv_zifont.cpp b/lib/lv_lib_zifont/lv_zifont.cpp index 43f7e340..3db55627 100644 --- a/lib/lv_lib_zifont/lv_zifont.cpp +++ b/lib/lv_lib_zifont/lv_zifont.cpp @@ -5,7 +5,7 @@ * INCLUDES *********************/ -#if !(defined(WINDOWS) || defined(POSIX) || defined(STM32F7xx)) +#if !(HASP_TARGET_PC || defined(STM32F7xx)) #include #include diff --git a/src/dev/device.h b/src/dev/device.h index 32ad1dc7..75039f34 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -8,7 +8,7 @@ #include "Arduino.h" #endif -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC #include #endif #if defined(POSIX) diff --git a/src/drv/tft/tft_driver.h b/src/drv/tft/tft_driver.h index 18eaa756..914597a8 100644 --- a/src/drv/tft/tft_driver.h +++ b/src/drv/tft/tft_driver.h @@ -77,10 +77,10 @@ class BaseTft { #elif defined(STM32F7) #warning Building for STM32F7xx Tfts #include "tft_driver_tftespi.h" -#elif USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) +#elif USE_MONITOR && HASP_TARGET_PC // #warning Building for SDL2 #include "tft_driver_sdl2.h" -#elif USE_WIN32DRV && (defined(WINDOWS) || defined(POSIX)) +#elif USE_WIN32DRV && HASP_TARGET_PC // #warning Building for Win32Drv #include "tft_driver_win32drv.h" #else diff --git a/src/drv/tft/tft_driver_sdl2.cpp b/src/drv/tft/tft_driver_sdl2.cpp index 98461f5b..82ca964d 100644 --- a/src/drv/tft/tft_driver_sdl2.cpp +++ b/src/drv/tft/tft_driver_sdl2.cpp @@ -1,7 +1,7 @@ /* MIT License - Copyright (c) 2019-2022 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#if USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) +#if USE_MONITOR && HASP_TARGET_PC #include "hasplib.h" #include "lvgl.h" diff --git a/src/drv/tft/tft_driver_sdl2.h b/src/drv/tft/tft_driver_sdl2.h index d0aaa114..32ce9e6d 100644 --- a/src/drv/tft/tft_driver_sdl2.h +++ b/src/drv/tft/tft_driver_sdl2.h @@ -6,7 +6,7 @@ #include "tft_driver.h" -#if USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) +#if USE_MONITOR && HASP_TARGET_PC // #warning Building H driver TFT SDL2 #include "lvgl.h" @@ -40,6 +40,6 @@ class TftSdl : BaseTft { using dev::TftSdl; extern dev::TftSdl haspTft; -#endif // defined(WINDOWS) || defined(POSIX) +#endif // HASP_TARGET_PC #endif // HASP_SDL2_DRIVER_H diff --git a/src/drv/tft/tft_driver_win32drv.cpp b/src/drv/tft/tft_driver_win32drv.cpp index 709ed054..911cae2e 100644 --- a/src/drv/tft/tft_driver_win32drv.cpp +++ b/src/drv/tft/tft_driver_win32drv.cpp @@ -1,7 +1,7 @@ /* MIT License - Copyright (c) 2019-2022 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#if USE_WIN32DRV && (defined(WINDOWS) || defined(POSIX)) +#if USE_WIN32DRV && HASP_TARGET_PC #include "hasplib.h" #include "lvgl.h" diff --git a/src/drv/tft/tft_driver_win32drv.h b/src/drv/tft/tft_driver_win32drv.h index 89dd4223..eefcd4eb 100644 --- a/src/drv/tft/tft_driver_win32drv.h +++ b/src/drv/tft/tft_driver_win32drv.h @@ -6,7 +6,7 @@ #include "tft_driver.h" -#if USE_WIN32DRV && (defined(WINDOWS) || defined(POSIX)) +#if USE_WIN32DRV && HASP_TARGET_PC // #warning Building H driver WIN32DRV #include "lvgl.h" @@ -39,6 +39,6 @@ class TftWin32Drv : BaseTft { using dev::TftWin32Drv; extern dev::TftWin32Drv haspTft; -#endif // defined(WINDOWS) || defined(POSIX) +#endif // HASP_TARGET_PC -#endif // HASP_SDL2_DRIVER_H +#endif // HASP_WIN32DRV_DRIVER_H diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index e2e49f0f..35388570 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -11,7 +11,7 @@ #include "ArduinoLog.h" #endif -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC #include #include #include diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index f478fa62..80c699ab 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -16,7 +16,7 @@ #include "../hasp_debug.h" #include "hasp_gui.h" // for screenshot -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC #include #include #include @@ -1113,7 +1113,7 @@ void dispatch_reboot(bool saveConfig) LOG_VERBOSE(TAG_MSGR, F("-------------------------------------")); LOG_TRACE(TAG_MSGR, F(D_DISPATCH_REBOOT)); -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC fflush(stdout); #else Serial.flush(); @@ -1217,7 +1217,7 @@ void dispatch_send_discovery(const char*, const char*, uint8_t source) #if HASP_USE_HTTP > 0 network_get_ipaddress(buffer, sizeof(buffer)); doc[F("uri")] = String(F("http://")) + String(buffer); -#elif defined(WINDOWS) || defined(POSIX) +#elif HASP_TARGET_PC doc[F("uri")] = "http://google.pt"; #endif diff --git a/src/hasp/hasp_font.cpp b/src/hasp/hasp_font.cpp index 98a20c46..d86a4f14 100644 --- a/src/hasp/hasp_font.cpp +++ b/src/hasp/hasp_font.cpp @@ -68,7 +68,7 @@ void font_setup() } else { LOG_ERROR(TAG_FONT, F("FreeType " D_SERVICE_START_FAILED)); } -#elif defined(WINDOWS) || defined(POSIX) +#elif HASP_TARGET_PC #else #endif diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 08fd170e..f7e436cf 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -179,7 +179,7 @@ int hasp_parse_json_attributes(lv_obj_t* obj, const JsonObject& doc) { int i = 0; -#if defined(WINDOWS) || defined(POSIX) || defined(ESP32) +#if HASP_TARGET_PC || defined(ESP32) std::string v; v.reserve(64); diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 672c0ba2..fa2f5406 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -99,7 +99,7 @@ static inline void debug_flush() HASP_SERIAL.flush(); #endif -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC fflush(stdout); #endif } @@ -116,7 +116,7 @@ void debugEverySecond() void debugStart(void) { -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC debug_newline(); debugPrintHaspHeader(NULL); debug_newline(); diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 425a7d97..c025ff99 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -17,7 +17,7 @@ #include "lang/lang.h" -#if(!defined(WINDOWS)) && (!defined(POSIX)) +#if HASP_TARGET_ARDUINO /* ===== Default Event Processors ===== */ void debugSetup(JsonObject settings); diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 5fc3eb74..68a51d1c 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -309,7 +309,7 @@ void guiSetup() static lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; -#if USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) +#if USE_MONITOR && HASP_TARGET_PC indev_drv.read_cb = mouse_read; #else indev_drv.read_cb = gui_touch_read; @@ -345,7 +345,7 @@ void guiSetup() gui_hide_pointer(false); lv_indev_set_cursor(mouse_indev, cursor); /*Connect the image object to the driver*/ -#if !(defined(WINDOWS) || defined(POSIX)) +#if HASP_TARGET_ARDUINO // drv_touch_init(gui_settings.rotation); // Touch driver haspTouch.init(tft_width, tft_height); haspTouch.set_calibration(gui_settings.cal_data); @@ -386,7 +386,7 @@ IRAM_ATTR void guiLoop(void) // tick.update(); #endif -#if !(defined(WINDOWS) || defined(POSIX)) +#if HASP_TARGET_ARDUINO // haspTouch.loop(); #endif } diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 8fc378b2..b383531c 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -1,7 +1,7 @@ /* MIT License - Copyright (c) 2019-2024 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#if !(defined(WINDOWS) || defined(POSIX)) +#if HASP_TARGET_ARDUINO /* #ifdef CORE_DEBUG_LEVEL diff --git a/src/main_pc.cpp b/src/main_pc.cpp index 322fb24b..c4988771 100644 --- a/src/main_pc.cpp +++ b/src/main_pc.cpp @@ -1,7 +1,7 @@ /* MIT License - Copyright (c) 2019-2022 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC #if defined(WINDOWS) diff --git a/src/mqtt/hasp_mqtt_ha.cpp b/src/mqtt/hasp_mqtt_ha.cpp index bf6edb1c..f7040e07 100644 --- a/src/mqtt/hasp_mqtt_ha.cpp +++ b/src/mqtt/hasp_mqtt_ha.cpp @@ -16,7 +16,7 @@ #define RETAINED true -#if defined(WINDOWS) || defined(POSIX) +#if HASP_TARGET_PC extern std::string mqttNodeTopic; extern std::string mqttGroupTopic; #else @@ -35,7 +35,7 @@ const char FP_MQTT_HA_NAME[] PROGMEM = "name"; const char FP_MQTT_HA_MODEL[] PROGMEM = "mdl"; const char FP_MQTT_HA_MANUFACTURER[] PROGMEM = "mf"; -#if !(defined(WINDOWS) || defined(POSIX)) +#if HASP_TARGET_ARDUINO #include "hal/hasp_hal.h" diff --git a/user_setups/darwin_sdl/darwin_sdl_64bits.ini b/user_setups/darwin_sdl/darwin_sdl_64bits.ini index a1e64062..1cae860e 100644 --- a/user_setups/darwin_sdl/darwin_sdl_64bits.ini +++ b/user_setups/darwin_sdl/darwin_sdl_64bits.ini @@ -6,7 +6,8 @@ extra_scripts = tools/linux_build_extra.py build_flags = ${env.build_flags} - -D HASP_MODEL="MacOS X App" + -D HASP_MODEL="MacOS X App" + -D HASP_TARGET_PC=1 ; ----- Monitor -D TFT_WIDTH=240 diff --git a/user_setups/esp32/_esp32.ini b/user_setups/esp32/_esp32.ini index a7440eae..1a12c95d 100644 --- a/user_setups/esp32/_esp32.ini +++ b/user_setups/esp32/_esp32.ini @@ -35,6 +35,7 @@ files = build_flags = ${env.build_flags} + -D HASP_TARGET_ARDUINO=1 -D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages -D HASP_CONSOLE_BUFFER=256 ; maximum length of a console/telnet command diff --git a/user_setups/esp8266/_esp8266.ini b/user_setups/esp8266/_esp8266.ini index ad231166..e9ffe212 100644 --- a/user_setups/esp8266/_esp8266.ini +++ b/user_setups/esp8266/_esp8266.ini @@ -12,6 +12,7 @@ board_build.f_cpu = 160000000L ; set frequency to 160MHz monitor_filters = esp8266_exception_decoder build_flags= + -D HASP_TARGET_ARDUINO=1 -D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer -D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages -D HASP_CONSOLE_BUFFER=160 ; maximum length of a console/telnet command diff --git a/user_setups/linux_sdl/linux_sdl_64bits.ini b/user_setups/linux_sdl/linux_sdl_64bits.ini index e68c716b..dbe7f24c 100644 --- a/user_setups/linux_sdl/linux_sdl_64bits.ini +++ b/user_setups/linux_sdl/linux_sdl_64bits.ini @@ -6,6 +6,7 @@ extra_scripts = build_flags = ${env.build_flags} -D HASP_MODEL="Linux App" + -D HASP_TARGET_PC=1 ; ----- Monitor -D TFT_WIDTH=240 diff --git a/user_setups/stm32f4xx/_stm32f4.ini b/user_setups/stm32f4xx/_stm32f4.ini index 20a755d3..7ec27e01 100644 --- a/user_setups/stm32f4xx/_stm32f4.ini +++ b/user_setups/stm32f4xx/_stm32f4.ini @@ -3,6 +3,7 @@ framework = arduino platform = ststm32 build_flags= + -D HASP_TARGET_ARDUINO=1 -I include/stm32f4 -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages -D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command @@ -21,4 +22,4 @@ build_flags= lib_deps = stm32duino/STM32duino LwIP @ ^2.1.2 - ;https://github.com/stm32duino/LwIP.git \ No newline at end of file + ;https://github.com/stm32duino/LwIP.git diff --git a/user_setups/stm32f7xx/_stm32f7.ini b/user_setups/stm32f7xx/_stm32f7.ini index 192119d5..17fa84a6 100644 --- a/user_setups/stm32f7xx/_stm32f7.ini +++ b/user_setups/stm32f7xx/_stm32f7.ini @@ -3,6 +3,7 @@ framework = arduino platform = ststm32 build_flags= + -D HASP_TARGET_ARDUINO=1 ; -I include/stm32f4 -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages -D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command diff --git a/user_setups/win32/windows_gdi_64bits.ini b/user_setups/win32/windows_gdi_64bits.ini index 38d8b4c3..87a24f4e 100644 --- a/user_setups/win32/windows_gdi_64bits.ini +++ b/user_setups/win32/windows_gdi_64bits.ini @@ -6,6 +6,7 @@ extra_scripts = build_flags = ${env.build_flags} -D HASP_MODEL="Windows App" + -D HASP_TARGET_PC=1 ; ----- Monitor -D TFT_WIDTH=240 diff --git a/user_setups/win32/windows_sdl_64bits.ini b/user_setups/win32/windows_sdl_64bits.ini index babadf77..e7b7b082 100644 --- a/user_setups/win32/windows_sdl_64bits.ini +++ b/user_setups/win32/windows_sdl_64bits.ini @@ -6,6 +6,7 @@ extra_scripts = build_flags = ${env.build_flags} -D HASP_MODEL="Windows App" + -D HASP_TARGET_PC=1 ; ----- Monitor -D TFT_WIDTH=240