diff --git a/Platformio/include/OmoteUI/HardwareInterface.h b/Platformio/HAL/Interface/HardwareInterface.h similarity index 100% rename from Platformio/include/OmoteUI/HardwareInterface.h rename to Platformio/HAL/Interface/HardwareInterface.h diff --git a/Platformio/src/HardwareRevX.cpp b/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp similarity index 100% rename from Platformio/src/HardwareRevX.cpp rename to Platformio/HAL/Targets/ESP32/HardwareRevX.cpp diff --git a/Platformio/src/HardwareRevX.hpp b/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp similarity index 99% rename from Platformio/src/HardwareRevX.hpp rename to Platformio/HAL/Targets/ESP32/HardwareRevX.hpp index f618880..0ff2c68 100644 --- a/Platformio/src/HardwareRevX.hpp +++ b/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp @@ -2,7 +2,7 @@ #include "SparkFunLIS3DH.h" #include "HardwareInterface.h" -#include "WiFi.h" +#include #include "Wire.h" #include "lvgl.h" #include diff --git a/Platformio/HAL/Targets/ESP32/omoteconfig.h b/Platformio/HAL/Targets/ESP32/omoteconfig.h new file mode 100644 index 0000000..48f227e --- /dev/null +++ b/Platformio/HAL/Targets/ESP32/omoteconfig.h @@ -0,0 +1,55 @@ +#pragma once + +#define IS_SIMULATOR false + +// Comment out to disable connected features +#define ENABLE_WIFI +#define WIFI_SSID "YOUR_WIFI_SSID" +#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD" +#define MQTT_SERVER "YOUR_MQTT_SERVER_IP" + +// time until device enters sleep mode in milliseconds +#define SLEEP_TIMEOUT 20000 + +// motion above threshold keeps device awake +#define MOTION_THRESHOLD 50 + +// IO34+IO35+IO37+IO38+IO39(+IO13) +#define BUTTON_PIN_BITMASK 0b1110110000000000000000000010000000000000 + +#define SCREEN_WIDTH 240 +#define SCREEN_HEIGHT 360 + +// Pin assignment +// ----------------------------------------------------------------------------------------------------------------------- + +#define LCD_DC 9 // defined in TFT_eSPI User_Setup.h +#define LCD_CS 5 +#define LCD_MOSI 23 +#define LCD_SCK 18 +#define LCD_BL 4 +#define LCD_EN 10 + +#define USER_LED 2 + +#define SW_1 32 // 1...5: Output +#define SW_2 26 +#define SW_3 27 +#define SW_4 14 +#define SW_5 12 +#define SW_A 37 // A...E: Input +#define SW_B 38 +#define SW_C 39 +#define SW_D 34 +#define SW_E 35 + +#define IR_RX 15 // IR receiver input +#define ADC_BAT 36 // Battery voltage sense input (1/2 divider) +#define IR_VCC 25 // IR receiver power +#define IR_LED 33 // IR LED output + +#define SCL 22 +#define SDA 19 +#define ACC_INT 20 + +#define CRG_STAT 21 // battery charger feedback \ No newline at end of file diff --git a/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp b/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp new file mode 100644 index 0000000..1ef3390 --- /dev/null +++ b/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp @@ -0,0 +1 @@ +#include "HardwareSimulator.hpp" diff --git a/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp b/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp new file mode 100644 index 0000000..a7d564c --- /dev/null +++ b/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp @@ -0,0 +1,29 @@ +#pragma once +#include "HardwareInterface.h" +#include +#include + +class HardwareSimulator : public HardwareInterface { +public: + HardwareSimulator() = default; + + virtual void debugPrint(std::string message) override { + std::cout << message; + } + + virtual void sendIR() override {} + + virtual void MQTTPublish(const char *topic, const char *payload) override{ + + }; + + virtual void init() override { lv_init(); } + + virtual batteryStatus getBatteryPercentage() { + batteryStatus fakeStatus; + fakeStatus.isCharging = false; + fakeStatus.percentage = 100; + fakeStatus.voltage = 4200; + return fakeStatus; + } +}; diff --git a/Platformio/HAL/Targets/Simulator/omoteconfig.h b/Platformio/HAL/Targets/Simulator/omoteconfig.h new file mode 100644 index 0000000..4f8b2f6 --- /dev/null +++ b/Platformio/HAL/Targets/Simulator/omoteconfig.h @@ -0,0 +1,6 @@ +#pragma once + +#define IS_SIMULATOR true + +#define SCREEN_WIDTH 240 +#define SCREEN_HEIGHT 360 diff --git a/Platformio/include/OmoteUI/Images.hpp b/Platformio/OmoteUI/Images.hpp similarity index 100% rename from Platformio/include/OmoteUI/Images.hpp rename to Platformio/OmoteUI/Images.hpp diff --git a/Platformio/src/OmoteUI.cpp b/Platformio/OmoteUI/OmoteUI.cpp similarity index 100% rename from Platformio/src/OmoteUI.cpp rename to Platformio/OmoteUI/OmoteUI.cpp diff --git a/Platformio/include/OmoteUI/OmoteUI.hpp b/Platformio/OmoteUI/OmoteUI.hpp similarity index 100% rename from Platformio/include/OmoteUI/OmoteUI.hpp rename to Platformio/OmoteUI/OmoteUI.hpp diff --git a/Platformio/platformio.ini b/Platformio/platformio.ini index 9617d7c..aa2a195 100644 --- a/Platformio/platformio.ini +++ b/Platformio/platformio.ini @@ -8,6 +8,27 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = esp32 + + +; ; Shared options +; [env] +; build_flags = +; ; Don't use lv_conf.h. Tweak params via platfom.ini. +; -D LV_CONF_SKIP +; -D LV_CONF_INCLUDE_SIMPLE +; ; Enable LVGL demo, remove when working on your own project +; -D LV_USE_DEMO_WIDGETS=1 +; ; Add more defines below to overide lvgl:/src/lv_conf_simple.h +; lib_deps = +; ; Use direct URL, because package registry is unstable +; ;lvgl@~7.11.0 +; lvgl=https://github.com/lvgl/lvgl/archive/refs/tags/v8.2.0.zip +; lib_archive = false + + + [env:esp32] platform = espressif32 board = esp32dev @@ -23,13 +44,21 @@ lib_deps = lvgl/lvgl@^8.3.4 bodmer/TFT_eSPI@^2.5.23 knolleary/PubSubClient@^2.8 + Wire + WiFi + SPI + Keypad + Preferences build_flags = -std=c++17 -std=gnu++17 -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -I include - -I include/OmoteUI - ; Include the folder containing lv_conf.h + -I OmoteUI + -I HAL + -I HAL/Interface + -I HAL/Targets/ESP32 + ; The following lines replace the TFT_eSPI User_setup.h-file -D USER_SETUP_LOADED=1 -D ILI9341_DRIVER=1 @@ -52,4 +81,48 @@ build_flags = ;-D LOAD_GFXFF=1 ;-D SMOOTH_FONT=1 build_unflags = - -std=gnu++11 \ No newline at end of file + -std=gnu++11 +build_src_filter = + + + +<../HAL/Targets/ESP32/*> + +<../OmoteUI/*> + + +[env:emulator_64bits] +platform = native@^1.1.3 +build_flags = + ${env.build_flags} + ; -D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO + -D LV_LOG_PRINTF=1 + ;-lSDL2 + ; SDL drivers options + -D LV_LVGL_H_INCLUDE_SIMPLE + -D LV_DRV_NO_CONF +; -D USE_SDL +; -D SDL_HOR_RES=480 +; -D SDL_VER_RES=320 +; -D SDL_ZOOM=1 + + ; LVGL memory options, setup for the demo to run properly + -D LV_MEM_CUSTOM=1 + -D LV_MEM_SIZE="(128U * 1024U)" + +lib_deps = + ${env.lib_deps} + ; Use direct URL, because package registry is unstable + ;lv_drivers@~7.9.0 + lv_drivers=https://github.com/lvgl/lv_drivers/archive/refs/tags/v8.2.0.zip +build_src_filter = + +<*> + ; Force compile LVGL demo, remove when working on your own project + + +[env:emulator_32bits] +extends = env:emulator_64bits +build_flags = + ${env:emulator_64bits.build_flags} + -m32 +build_src_filter = + +<*> + +<../hal/sdl2> + +<../.pio/libdeps/emulator_32bits/lvgl/demos> diff --git a/Platformio/src/LVGL.Simulator.cpp b/Platformio/src/LVGL.Simulator.cpp new file mode 100644 index 0000000..0164be0 --- /dev/null +++ b/Platformio/src/LVGL.Simulator.cpp @@ -0,0 +1,183 @@ +/* + * PROJECT: LVGL PC Simulator using Visual Studio + * FILE: LVGL.Simulator.cpp + * PURPOSE: Implementation for LVGL ported to Windows Desktop + * + * LICENSE: The MIT License + * + * DEVELOPER: Mouri_Naruto (Mouri_Naruto AT Outlook.com) + */ + +#include +#include +#include "resource.h" + +#include "omoteconfig.h" +#include "HardwareSimulator.hpp" +#include "OmoteUI.hpp" + +#if _MSC_VER >= 1200 +// Disable compilation warnings. +#pragma warning(push) +// nonstandard extension used : bit field types other than int +#pragma warning(disable : 4214) +// 'conversion' conversion from 'type1' to 'type2', possible loss of data +#pragma warning(disable : 4244) +#endif + +#include "lvgl/lvgl.h" +#include "lv_drivers/win32drv/win32drv.h" + +#if _MSC_VER >= 1200 +// Restore compilation warnings. +#pragma warning(pop) +#endif + +#include + +bool single_display_mode_initialization() +{ + if (!lv_win32_init( + GetModuleHandleW(NULL), + SW_SHOW, + 240, + 320, + LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCE(IDI_LVGL)))) + { + return false; + } + lv_win32_add_all_input_devices_to_group(NULL); + + return true; +} + +#include + +HANDLE g_window_mutex = NULL; +bool g_initialization_status = false; + +#define LVGL_SIMULATOR_MAXIMUM_DISPLAYS 16 +HWND g_display_window_handles[LVGL_SIMULATOR_MAXIMUM_DISPLAYS]; + +unsigned int __stdcall lv_win32_window_thread_entrypoint( + void *raw_parameter) +{ + size_t display_id = *(size_t *)(raw_parameter); + + HINSTANCE instance_handle = GetModuleHandleW(NULL); + int show_window_mode = SW_SHOW; + HICON icon_handle = LoadIconW(instance_handle, MAKEINTRESOURCE(IDI_LVGL)); + lv_coord_t hor_res = 240; + lv_coord_t ver_res = 320; + + wchar_t window_title[256]; + memset(window_title, 0, sizeof(window_title)); + _snwprintf( + window_title, + 256, + L"LVGL Simulator for Windows Desktop (Display %d)", + display_id); + + g_display_window_handles[display_id] = lv_win32_create_display_window( + window_title, + hor_res, + ver_res, + instance_handle, + icon_handle, + show_window_mode); + if (!g_display_window_handles[display_id]) + { + return 0; + } + + g_initialization_status = true; + + SetEvent(g_window_mutex); + + MSG message; + while (GetMessageW(&message, NULL, 0, 0)) + { + TranslateMessage(&message); + DispatchMessageW(&message); + } + + lv_win32_quit_signal = true; + + return 0; +} + +bool multiple_display_mode_initialization() +{ + if (!lv_win32_init_window_class()) + { + return false; + } + + for (size_t i = 0; i < LVGL_SIMULATOR_MAXIMUM_DISPLAYS; ++i) + { + g_initialization_status = false; + + g_window_mutex = CreateEventExW(NULL, NULL, 0, EVENT_ALL_ACCESS); + + _beginthreadex( + NULL, + 0, + lv_win32_window_thread_entrypoint, + &i, + 0, + NULL); + + WaitForSingleObjectEx(g_window_mutex, INFINITE, FALSE); + + CloseHandle(g_window_mutex); + + if (!g_initialization_status) + { + return false; + } + } + + lv_win32_window_context_t *context = (lv_win32_window_context_t *)(lv_win32_get_window_context(g_display_window_handles[0])); + if (context) + { + lv_win32_pointer_device_object = context->mouse_device_object; + lv_win32_keypad_device_object = context->keyboard_device_object; + lv_win32_encoder_device_object = context->mousewheel_device_object; + } + + lv_win32_add_all_input_devices_to_group(NULL); + + return true; +} + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +int main() +{ + auto hal = std::make_shared(); + hal->init(); + + auto ui = OmoteUI::getInstance(hal); + + if (!single_display_mode_initialization()) + { + return -1; + } + + ui->layout_UI(); + + while (!lv_win32_quit_signal) + { + lv_task_handler(); + // std::string strng = std::to_string(scroll_value); + // const char* pchar = strng.c_str(); + // OutputDebugStringW(); + // lv_label_set_text_fmt(scrollPos, "%d %d", lv_obj_get_scroll_x(lv_tabview_get_content(tabview)), lv_obj_get_scroll_x(panel)); + + Sleep(1); + } + + return 0; +} diff --git a/Platformio/src/main.cpp b/Platformio/src/main.cpp index 8b4ce67..baf4d6c 100644 --- a/Platformio/src/main.cpp +++ b/Platformio/src/main.cpp @@ -3,7 +3,7 @@ #include #include "HardwareRevX.hpp" -#include "OmoteUI/OmoteUI.hpp" +#include "OmoteUI.hpp" #include "omoteconfig.h" std::shared_ptr hal = nullptr;