lvgl simulator working.
This commit is contained in:
parent
5b1228b167
commit
834780ce83
5 changed files with 147 additions and 226 deletions
|
@ -34,7 +34,7 @@ void OmoteUI::bl_slider_event_cb(lv_event_t *e) {
|
|||
void OmoteUI::appleKey_event_cb(lv_event_t *e) {
|
||||
// Send IR command based on the event user data
|
||||
mHardware->sendIR();
|
||||
mHardware->debugPrint(std::to_string(50 + (int)e->user_data));
|
||||
//mHardware->debugPrint(std::to_string(50 + (int)e->user_data));
|
||||
}
|
||||
|
||||
// Wakeup by IMU Switch Event handler
|
||||
|
@ -51,10 +51,10 @@ void OmoteUI::smartHomeToggle_event_cb(lv_event_t *e) {
|
|||
else
|
||||
strcpy(payload, "false");
|
||||
// Publish an MQTT message based on the event user data
|
||||
if ((int)e->user_data == 1)
|
||||
mHardware->MQTTPublish("bulb1_set", payload);
|
||||
if ((int)e->user_data == 2)
|
||||
mHardware->MQTTPublish("bulb2_set", payload);
|
||||
// if ((int)e->user_data == 1)
|
||||
// mHardware->MQTTPublish("bulb1_set", payload);
|
||||
// if ((int)e->user_data == 2)
|
||||
// mHardware->MQTTPublish("bulb2_set", payload);
|
||||
}
|
||||
|
||||
// Smart Home Toggle Event handler
|
||||
|
@ -69,10 +69,10 @@ void OmoteUI::smartHomeSlider_event_cb(lv_event_t *e) {
|
|||
snprintf(payload, sizeof(payload), "%8.2f", sliderValue);
|
||||
|
||||
// Publish an MQTT message based on the event user data
|
||||
if ((int)e->user_data == 1)
|
||||
mHardware->MQTTPublish("bulb1_setbrightness", payload);
|
||||
if ((int)e->user_data == 2)
|
||||
mHardware->MQTTPublish("bulb2_setbrightness", payload);
|
||||
// if ((int)e->user_data == 1)
|
||||
// mHardware->MQTTPublish("bulb1_setbrightness", payload);
|
||||
// if ((int)e->user_data == 2)
|
||||
// mHardware->MQTTPublish("bulb2_setbrightness", payload);
|
||||
}
|
||||
|
||||
void OmoteUI::virtualKeypad_event_cb(lv_event_t *e) {
|
||||
|
@ -82,9 +82,9 @@ void OmoteUI::virtualKeypad_event_cb(lv_event_t *e) {
|
|||
return;
|
||||
|
||||
char buffer[100];
|
||||
sprintf(buffer, "check it out: %d\n",
|
||||
virtualKeyMapTechnisat[(int)target->user_data]);
|
||||
mHardware->debugPrint(buffer);
|
||||
// sprintf(buffer, "check it out: %d\n",
|
||||
// virtualKeyMapTechnisat[(int)target->user_data]);
|
||||
// mHardware->debugPrint(buffer);
|
||||
}
|
||||
|
||||
void OmoteUI::loopHandler(){
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// OMOTE UI
|
||||
// 2023 Matthew Colvin
|
||||
#pragma once
|
||||
#define LV_CONF_INCLUDE_SIMPLE
|
||||
|
||||
#include "HardwareInterface.h"
|
||||
#include "Images.hpp"
|
||||
|
|
|
@ -9,24 +9,25 @@
|
|||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs = esp32
|
||||
default_envs = x64_sim
|
||||
|
||||
|
||||
; ; 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
|
||||
|
||||
; Shared options
|
||||
[env]
|
||||
build_flags =
|
||||
-std=c++17
|
||||
-std=gnu++17
|
||||
; 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]
|
||||
|
@ -50,8 +51,6 @@ lib_deps =
|
|||
Keypad
|
||||
Preferences
|
||||
build_flags =
|
||||
-std=c++17
|
||||
-std=gnu++17
|
||||
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
-I include
|
||||
-I OmoteUI
|
||||
|
@ -88,20 +87,29 @@ build_src_filter =
|
|||
+<../OmoteUI/*>
|
||||
|
||||
|
||||
[env:emulator_64bits]
|
||||
[env:x64_sim]
|
||||
platform = native@^1.1.3
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
; -D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO
|
||||
-D LV_LOG_PRINTF=1
|
||||
;-lSDL2
|
||||
|
||||
;-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
|
||||
-D USE_SDL
|
||||
-D SDL_HOR_RES=480
|
||||
-D SDL_VER_RES=320
|
||||
-D SDL_ZOOM=1
|
||||
-D SDL_INCLUDE_PATH="\"SDL2/SDL.h\""
|
||||
|
||||
|
||||
-I include
|
||||
-I OmoteUI
|
||||
-I HAL
|
||||
-I HAL/Interface
|
||||
-I HAL/Targets/Simulator
|
||||
|
||||
; LVGL memory options, setup for the demo to run properly
|
||||
-D LV_MEM_CUSTOM=1
|
||||
|
@ -113,14 +121,16 @@ lib_deps =
|
|||
;lv_drivers@~7.9.0
|
||||
lv_drivers=https://github.com/lvgl/lv_drivers/archive/refs/tags/v8.2.0.zip
|
||||
build_src_filter =
|
||||
+<*>
|
||||
+<simMain.cpp>
|
||||
+<../HAL/Targets/Simulator/*>
|
||||
+<../OmoteUI/*>
|
||||
; Force compile LVGL demo, remove when working on your own project
|
||||
|
||||
|
||||
[env:emulator_32bits]
|
||||
extends = env:emulator_64bits
|
||||
[env:x86_sim]
|
||||
extends = env:x64_sim
|
||||
build_flags =
|
||||
${env:emulator_64bits.build_flags}
|
||||
${env:x64_sim.build_flags}
|
||||
-m32
|
||||
build_src_filter =
|
||||
+<*>
|
||||
|
|
|
@ -1,183 +0,0 @@
|
|||
/*
|
||||
* 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 <Windows.h>
|
||||
#include <string>
|
||||
#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 <stdio.h>
|
||||
|
||||
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 <process.h>
|
||||
|
||||
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<HardwareSimulator>();
|
||||
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;
|
||||
}
|
95
Platformio/src/simMain.cpp
Normal file
95
Platformio/src/simMain.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
#include <unistd.h>
|
||||
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
|
||||
#include "SDL2/SDL.h"
|
||||
#include "display/monitor.h"
|
||||
#include "indev/mouse.h"
|
||||
#include "indev/mousewheel.h"
|
||||
#include "indev/keyboard.h"
|
||||
#include "sdl/sdl.h"
|
||||
#include "HardwareSimulator.hpp"
|
||||
#include "omoteconfig.h"
|
||||
#include "OmoteUI.hpp"
|
||||
#include <memory>
|
||||
|
||||
|
||||
/**
|
||||
* 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*/
|
||||
|
||||
static lv_disp_draw_buf_t disp_buf;
|
||||
static lv_color_t buf[SDL_HOR_RES * 10]; /*Declare a buffer for 10 lines*/
|
||||
lv_disp_draw_buf_init(&disp_buf, buf, NULL, SDL_HOR_RES * 10); /*Initialize the display buffer*/
|
||||
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
|
||||
disp_drv.flush_cb = sdl_display_flush; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/
|
||||
disp_drv.draw_buf = &disp_buf;
|
||||
disp_drv.hor_res = SDL_HOR_RES;
|
||||
disp_drv.ver_res = SDL_VER_RES;
|
||||
//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*/
|
||||
static 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 = sdl_mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
|
||||
sdl_init();
|
||||
|
||||
/* Tick init.
|
||||
* You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed
|
||||
* Create an SDL thread to do this*/
|
||||
SDL_CreateThread(tick_thread, "tick", NULL);
|
||||
}
|
||||
|
||||
void hal_loop(void)
|
||||
{
|
||||
while(1) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
auto hwSim = std::make_shared<HardwareSimulator>();
|
||||
hwSim->init();
|
||||
|
||||
hal_setup();
|
||||
|
||||
auto ui = OmoteUI::getInstance(hwSim);
|
||||
ui->layout_UI();
|
||||
|
||||
while (true){
|
||||
ui->loopHandler();
|
||||
SDL_Delay(5);
|
||||
lv_task_handler();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue