Add HASP_TARGET_ARDUINO and HASP_TARGET_PC macros

This commit is contained in:
Kuba Szczodrzyński 2024-02-07 11:11:15 +01:00
parent b738c22c67
commit 96bfbf397b
No known key found for this signature in database
GPG Key ID: 43037AC62A600562
28 changed files with 86 additions and 69 deletions

View File

@ -33,6 +33,11 @@
#define HASP_USE_APP 1 #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 #ifndef HASP_USE_DEBUG
#define HASP_USE_DEBUG 1 #define HASP_USE_DEBUG 1
#endif #endif
@ -190,6 +195,41 @@
#define HASP_OBJECT_NOTATION "p%ub%u" #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<const __FlashStringHelper*>(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 */ /* Includes */
#ifdef WINDOWS #ifdef WINDOWS
#include "winsock2.h" #include "winsock2.h"
@ -281,7 +321,7 @@ static WiFiSpiClass WiFi;
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
#include "mqtt/hasp_mqtt.h" #include "mqtt/hasp_mqtt.h"
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
#define HASP_USE_PAHO #define HASP_USE_PAHO
#else #else
#define HASP_USE_ESP_MQTT #define HASP_USE_ESP_MQTT
@ -326,51 +366,20 @@ static WiFiSpiClass WiFi;
#include "sys/svc/hasp_slave.h" #include "sys/svc/hasp_slave.h"
#endif #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<const __FlashStringHelper*>(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) #if defined(WINDOWS)
#include <Windows.h> #include <Windows.h>
#define delay Sleep #define delay Sleep
#endif #endif
#if defined(POSIX) #if defined(POSIX)
#define delay SDL_Delay #define delay SDL_Delay
#endif #endif
#if defined(WINDOWS) || defined(POSIX)
#if HASP_TARGET_PC
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <stdio.h> #include <stdio.h>
#if USE_MONITOR #if USE_MONITOR
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#endif #endif

View File

@ -12,15 +12,15 @@
#include "user_config_override.h" #include "user_config_override.h"
#endif #endif
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
#define HASP_RANDOM(x) rand() % x #define HASP_RANDOM(x) rand() % x
#elif defined(ARDUINO) #elif HASP_TARGET_ARDUINO
#define HASP_RANDOM(x) random(x) #define HASP_RANDOM(x) random(x)
#else #else
#define HASP_RANDOM(x) random() % x #define HASP_RANDOM(x) random() % x
#endif #endif
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
#define LOG_OUTPUT(x, ...) printf(__VA_ARGS__) #define LOG_OUTPUT(x, ...) printf(__VA_ARGS__)
#else #else

View File

@ -227,7 +227,7 @@ typedef void* lv_fs_drv_user_data_t;
//# define LV_FS_IF_SPIFFS '\0' // no internal esp Flash //# define LV_FS_IF_SPIFFS '\0' // no internal esp Flash
#endif #endif
#endif /*LV_USE_FS_IF*/ #endif /*LV_USE_FS_IF*/
#if !(defined(WINDOWS) || defined(POSIX)) #if HASP_TARGET_ARDUINO
#define LV_FS_PC_PATH "/littlefs" #define LV_FS_PC_PATH "/littlefs"
#endif #endif

View File

@ -5,7 +5,7 @@
* INCLUDES * INCLUDES
*********************/ *********************/
#if !(defined(WINDOWS) || defined(POSIX) || defined(STM32F7xx)) #if !(HASP_TARGET_PC || defined(STM32F7xx))
#include <Arduino.h> #include <Arduino.h>
#include <stdio.h> #include <stdio.h>

View File

@ -8,7 +8,7 @@
#include "Arduino.h" #include "Arduino.h"
#endif #endif
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
#include <cstdint> #include <cstdint>
#endif #endif
#if defined(POSIX) #if defined(POSIX)

View File

@ -77,10 +77,10 @@ class BaseTft {
#elif defined(STM32F7) #elif defined(STM32F7)
#warning Building for STM32F7xx Tfts #warning Building for STM32F7xx Tfts
#include "tft_driver_tftespi.h" #include "tft_driver_tftespi.h"
#elif USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) #elif USE_MONITOR && HASP_TARGET_PC
// #warning Building for SDL2 // #warning Building for SDL2
#include "tft_driver_sdl2.h" #include "tft_driver_sdl2.h"
#elif USE_WIN32DRV && (defined(WINDOWS) || defined(POSIX)) #elif USE_WIN32DRV && HASP_TARGET_PC
// #warning Building for Win32Drv // #warning Building for Win32Drv
#include "tft_driver_win32drv.h" #include "tft_driver_win32drv.h"
#else #else

View File

@ -1,7 +1,7 @@
/* MIT License - Copyright (c) 2019-2022 Francis Van Roie /* MIT License - Copyright (c) 2019-2022 Francis Van Roie
For full license information read the LICENSE file in the project folder */ 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 "hasplib.h"
#include "lvgl.h" #include "lvgl.h"

View File

@ -6,7 +6,7 @@
#include "tft_driver.h" #include "tft_driver.h"
#if USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) #if USE_MONITOR && HASP_TARGET_PC
// #warning Building H driver TFT SDL2 // #warning Building H driver TFT SDL2
#include "lvgl.h" #include "lvgl.h"
@ -40,6 +40,6 @@ class TftSdl : BaseTft {
using dev::TftSdl; using dev::TftSdl;
extern dev::TftSdl haspTft; extern dev::TftSdl haspTft;
#endif // defined(WINDOWS) || defined(POSIX) #endif // HASP_TARGET_PC
#endif // HASP_SDL2_DRIVER_H #endif // HASP_SDL2_DRIVER_H

View File

@ -1,7 +1,7 @@
/* MIT License - Copyright (c) 2019-2022 Francis Van Roie /* MIT License - Copyright (c) 2019-2022 Francis Van Roie
For full license information read the LICENSE file in the project folder */ 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 "hasplib.h"
#include "lvgl.h" #include "lvgl.h"

View File

@ -6,7 +6,7 @@
#include "tft_driver.h" #include "tft_driver.h"
#if USE_WIN32DRV && (defined(WINDOWS) || defined(POSIX)) #if USE_WIN32DRV && HASP_TARGET_PC
// #warning Building H driver WIN32DRV // #warning Building H driver WIN32DRV
#include "lvgl.h" #include "lvgl.h"
@ -39,6 +39,6 @@ class TftWin32Drv : BaseTft {
using dev::TftWin32Drv; using dev::TftWin32Drv;
extern dev::TftWin32Drv haspTft; extern dev::TftWin32Drv haspTft;
#endif // defined(WINDOWS) || defined(POSIX) #endif // HASP_TARGET_PC
#endif // HASP_SDL2_DRIVER_H #endif // HASP_WIN32DRV_DRIVER_H

View File

@ -11,7 +11,7 @@
#include "ArduinoLog.h" #include "ArduinoLog.h"
#endif #endif
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>

View File

@ -16,7 +16,7 @@
#include "../hasp_debug.h" #include "../hasp_debug.h"
#include "hasp_gui.h" // for screenshot #include "hasp_gui.h" // for screenshot
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -1113,7 +1113,7 @@ void dispatch_reboot(bool saveConfig)
LOG_VERBOSE(TAG_MSGR, F("-------------------------------------")); LOG_VERBOSE(TAG_MSGR, F("-------------------------------------"));
LOG_TRACE(TAG_MSGR, F(D_DISPATCH_REBOOT)); LOG_TRACE(TAG_MSGR, F(D_DISPATCH_REBOOT));
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
fflush(stdout); fflush(stdout);
#else #else
Serial.flush(); Serial.flush();
@ -1217,7 +1217,7 @@ void dispatch_send_discovery(const char*, const char*, uint8_t source)
#if HASP_USE_HTTP > 0 #if HASP_USE_HTTP > 0
network_get_ipaddress(buffer, sizeof(buffer)); network_get_ipaddress(buffer, sizeof(buffer));
doc[F("uri")] = String(F("http://")) + String(buffer); doc[F("uri")] = String(F("http://")) + String(buffer);
#elif defined(WINDOWS) || defined(POSIX) #elif HASP_TARGET_PC
doc[F("uri")] = "http://google.pt"; doc[F("uri")] = "http://google.pt";
#endif #endif

View File

@ -68,7 +68,7 @@ void font_setup()
} else { } else {
LOG_ERROR(TAG_FONT, F("FreeType " D_SERVICE_START_FAILED)); LOG_ERROR(TAG_FONT, F("FreeType " D_SERVICE_START_FAILED));
} }
#elif defined(WINDOWS) || defined(POSIX) #elif HASP_TARGET_PC
#else #else
#endif #endif

View File

@ -179,7 +179,7 @@ int hasp_parse_json_attributes(lv_obj_t* obj, const JsonObject& doc)
{ {
int i = 0; int i = 0;
#if defined(WINDOWS) || defined(POSIX) || defined(ESP32) #if HASP_TARGET_PC || defined(ESP32)
std::string v; std::string v;
v.reserve(64); v.reserve(64);

View File

@ -99,7 +99,7 @@ static inline void debug_flush()
HASP_SERIAL.flush(); HASP_SERIAL.flush();
#endif #endif
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
fflush(stdout); fflush(stdout);
#endif #endif
} }
@ -116,7 +116,7 @@ void debugEverySecond()
void debugStart(void) void debugStart(void)
{ {
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
debug_newline(); debug_newline();
debugPrintHaspHeader(NULL); debugPrintHaspHeader(NULL);
debug_newline(); debug_newline();

View File

@ -17,7 +17,7 @@
#include "lang/lang.h" #include "lang/lang.h"
#if(!defined(WINDOWS)) && (!defined(POSIX)) #if HASP_TARGET_ARDUINO
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void debugSetup(JsonObject settings); void debugSetup(JsonObject settings);

View File

@ -309,7 +309,7 @@ void guiSetup()
static lv_indev_drv_t indev_drv; static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER; 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; indev_drv.read_cb = mouse_read;
#else #else
indev_drv.read_cb = gui_touch_read; indev_drv.read_cb = gui_touch_read;
@ -345,7 +345,7 @@ void guiSetup()
gui_hide_pointer(false); gui_hide_pointer(false);
lv_indev_set_cursor(mouse_indev, cursor); /*Connect the image object to the driver*/ 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 // drv_touch_init(gui_settings.rotation); // Touch driver
haspTouch.init(tft_width, tft_height); haspTouch.init(tft_width, tft_height);
haspTouch.set_calibration(gui_settings.cal_data); haspTouch.set_calibration(gui_settings.cal_data);
@ -386,7 +386,7 @@ IRAM_ATTR void guiLoop(void)
// tick.update(); // tick.update();
#endif #endif
#if !(defined(WINDOWS) || defined(POSIX)) #if HASP_TARGET_ARDUINO
// haspTouch.loop(); // haspTouch.loop();
#endif #endif
} }

View File

@ -1,7 +1,7 @@
/* MIT License - Copyright (c) 2019-2024 Francis Van Roie /* MIT License - Copyright (c) 2019-2024 Francis Van Roie
For full license information read the LICENSE file in the project folder */ 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 #ifdef CORE_DEBUG_LEVEL

View File

@ -1,7 +1,7 @@
/* MIT License - Copyright (c) 2019-2022 Francis Van Roie /* MIT License - Copyright (c) 2019-2022 Francis Van Roie
For full license information read the LICENSE file in the project folder */ For full license information read the LICENSE file in the project folder */
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
#if defined(WINDOWS) #if defined(WINDOWS)

View File

@ -16,7 +16,7 @@
#define RETAINED true #define RETAINED true
#if defined(WINDOWS) || defined(POSIX) #if HASP_TARGET_PC
extern std::string mqttNodeTopic; extern std::string mqttNodeTopic;
extern std::string mqttGroupTopic; extern std::string mqttGroupTopic;
#else #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_MODEL[] PROGMEM = "mdl";
const char FP_MQTT_HA_MANUFACTURER[] PROGMEM = "mf"; const char FP_MQTT_HA_MANUFACTURER[] PROGMEM = "mf";
#if !(defined(WINDOWS) || defined(POSIX)) #if HASP_TARGET_ARDUINO
#include "hal/hasp_hal.h" #include "hal/hasp_hal.h"

View File

@ -6,7 +6,8 @@ extra_scripts =
tools/linux_build_extra.py tools/linux_build_extra.py
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
-D HASP_MODEL="MacOS X App" -D HASP_MODEL="MacOS X App"
-D HASP_TARGET_PC=1
; ----- Monitor ; ----- Monitor
-D TFT_WIDTH=240 -D TFT_WIDTH=240

View File

@ -35,6 +35,7 @@ files =
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
-D HASP_TARGET_ARDUINO=1
-D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer -D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
-D HASP_CONSOLE_BUFFER=256 ; maximum length of a console/telnet command -D HASP_CONSOLE_BUFFER=256 ; maximum length of a console/telnet command

View File

@ -12,6 +12,7 @@ board_build.f_cpu = 160000000L ; set frequency to 160MHz
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
build_flags= build_flags=
-D HASP_TARGET_ARDUINO=1
-D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer -D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer
-D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages -D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages
-D HASP_CONSOLE_BUFFER=160 ; maximum length of a console/telnet command -D HASP_CONSOLE_BUFFER=160 ; maximum length of a console/telnet command

View File

@ -6,6 +6,7 @@ extra_scripts =
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
-D HASP_MODEL="Linux App" -D HASP_MODEL="Linux App"
-D HASP_TARGET_PC=1
; ----- Monitor ; ----- Monitor
-D TFT_WIDTH=240 -D TFT_WIDTH=240

View File

@ -3,6 +3,7 @@
framework = arduino framework = arduino
platform = ststm32 platform = ststm32
build_flags= build_flags=
-D HASP_TARGET_ARDUINO=1
-I include/stm32f4 -I include/stm32f4
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
-D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command -D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command

View File

@ -3,6 +3,7 @@
framework = arduino framework = arduino
platform = ststm32 platform = ststm32
build_flags= build_flags=
-D HASP_TARGET_ARDUINO=1
; -I include/stm32f4 ; -I include/stm32f4
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
-D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command -D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command

View File

@ -6,6 +6,7 @@ extra_scripts =
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
-D HASP_MODEL="Windows App" -D HASP_MODEL="Windows App"
-D HASP_TARGET_PC=1
; ----- Monitor ; ----- Monitor
-D TFT_WIDTH=240 -D TFT_WIDTH=240

View File

@ -6,6 +6,7 @@ extra_scripts =
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
-D HASP_MODEL="Windows App" -D HASP_MODEL="Windows App"
-D HASP_TARGET_PC=1
; ----- Monitor ; ----- Monitor
-D TFT_WIDTH=240 -D TFT_WIDTH=240