OMOTE/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp

70 lines
2.4 KiB
C++
Raw Normal View History

Add platform io sim (#31) * Lower default SPI Clock Lowered the default SPI clock as some displays might show glitches with the SPI frequency set above 40MHz. * Added missing library components Added the missing library symbols, footprints and 3D-models. These are all in a project-specific library called "omoteLib" (#19) * Implement MQTT publish in HardwareRevX Change-Id: I7b6955a662716f83dd8daf34128a353efa26bf80 * add batteryStatus info and allow access to it through the interface. Change-Id: Ieb748b1478d532f52ffff9edc783de3cbcf9f303 * rename hardwareAbstractionInterface Change-Id: I39a9bcd7fc4d92b271a40a869faae7870d6d88a1 * rename HardwareAbstractionInterface files Change-Id: Ifb6a96c38da61cb80aabc6c929e392a2fc91cf29 * fixed a typo * Re work directory structure to support new architecture Still need to get the Sim building * lvgl simulator working. * put init code into HardwareSimulator Class * ensure all targets build remove unused assets.c add new github actions that reflect new simulator * clean up build defines by using platform.ini to override default lv_config. remove unneeded include directory. Change-Id: Id63baa80dae89977d239a539b5db9ff67266e1d6 * Fix ESP32 Windows build after battling escape characters. Add esp32 Windows target to Actions. * Fixed screen height - corrected the SCREEN_HEIGHT - small graphical changes in OmoteUI to make it look like in the main branch --------- Co-authored-by: Max <Max-MKA@web.de> Co-authored-by: Matthew Colvin <Matthew.Colvin@garmin.com> Co-authored-by: Matthew Colvin <35540398+Mc067415@users.noreply.github.com>
2023-08-11 18:16:48 -04:00
#include "HardwareSimulator.hpp"
#include <unistd.h>
#include "SDL2/SDL.h"
#include "display/monitor.h"
#include "indev/mouse.h"
#include "indev/mousewheel.h"
#include "indev/keyboard.h"
#include "sdl/sdl.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 HardwareSimulator::init() {
lv_init();
// 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);
}