From 4a1eb8abfa0a691c646e54d928183d27f1086eb5 Mon Sep 17 00:00:00 2001 From: Matthew Colvin <35540398+Mc067415@users.noreply.github.com> Date: Thu, 31 Aug 2023 10:14:09 -0500 Subject: [PATCH] Added ability for sim to simulate brightness and battery along with displaying it via the title. --- .../Targets/Simulator/HardwareSimulator.cpp | 33 ++++++++++++++----- .../Targets/Simulator/HardwareSimulator.hpp | 1 + .../HAL/Targets/Simulator/SDLDisplay.cpp | 11 +++++-- .../HAL/Targets/Simulator/SDLDisplay.hpp | 7 +++- Platformio/platformio.ini | 1 + 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp b/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp index 3e4c349..a47bfb5 100644 --- a/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp +++ b/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp @@ -1,13 +1,7 @@ #include "HardwareSimulator.hpp" -#include -#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 "SDLDisplay.hpp" +#include HardwareSimulator::HardwareSimulator(): HardwareAbstract(), mTickThread([](){ @@ -18,7 +12,30 @@ HardwareSimulator::HardwareSimulator(): HardwareAbstract(), mBattery(std::make_shared()), mDisplay(SDLDisplay::getInstance()), mWifiHandler(std::make_shared()) -{} +{ + mHardwareStatusTitleUpdate = std::thread([this] { + int dataToShow = 0; + while (true) + { + std::stringstream title; + switch (dataToShow){ + case 0: + title << "Batt:" << mBattery->getPercentage() << "%" << std::endl; + break; + case 1: + title << "BKLght: " << static_cast(mDisplay->getBrightness()) << std::endl; + dataToShow = -1; + break; + default: + dataToShow = -1; + } + dataToShow++; + + mDisplay->setTitle(title.str()); + std::this_thread::sleep_for(std::chrono::seconds(2)); + } + }); +} std::shared_ptr HardwareSimulator::battery(){ return mBattery; diff --git a/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp b/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp index 7e3177b..f66caf4 100644 --- a/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp +++ b/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp @@ -26,6 +26,7 @@ public: private: std::thread mTickThread; + std::thread mHardwareStatusTitleUpdate; std::shared_ptr mBattery; std::shared_ptr mDisplay; diff --git a/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp b/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp index 231ad1e..461cf61 100644 --- a/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp +++ b/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp @@ -1,6 +1,6 @@ #include "SDLDisplay.hpp" -#include "SDL2/SDL.h" #include "sdl/sdl.h" +#include std::shared_ptr SDLDisplay::getInstance(){ if (!DisplayAbstract::mInstance){ @@ -10,11 +10,11 @@ std::shared_ptr SDLDisplay::getInstance(){ } void SDLDisplay::setBrightness(uint8_t brightness){ - + mBrightness = brightness; } uint8_t SDLDisplay::getBrightness(){ - + return mBrightness; } void SDLDisplay::turnOff(){ @@ -29,6 +29,11 @@ void SDLDisplay::screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data sdl_mouse_read(indev_driver,data); } +void SDLDisplay::setTitle(std::string aNewTitle){ + SDL_SetWindowTitle(mSimWindow,aNewTitle.c_str()); +} + SDLDisplay::SDLDisplay(): DisplayAbstract() { sdl_init(); + mSimWindow = SDL_GetWindowFromID(1); // Get the SDL window via ID hopefully it is always 1... } \ No newline at end of file diff --git a/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp b/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp index e49ab0d..98f58b2 100644 --- a/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp +++ b/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp @@ -1,4 +1,6 @@ #pragma once +#include +#include "SDL2/SDL.h" #include "DisplayAbstract.h" class SDLDisplay : public DisplayAbstract{ @@ -10,11 +12,14 @@ public: virtual uint8_t getBrightness() override; virtual void turnOff() override; + void setTitle(std::string aNewTitle); + protected: virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) override; virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override; private: SDLDisplay(); - + uint8_t mBrightness; + SDL_Window* mSimWindow; }; \ No newline at end of file diff --git a/Platformio/platformio.ini b/Platformio/platformio.ini index e52c59f..51ca044 100644 --- a/Platformio/platformio.ini +++ b/Platformio/platformio.ini @@ -124,6 +124,7 @@ build_flags = -D LV_LVGL_H_INCLUDE_SIMPLE -D LV_DRV_NO_CONF -D USE_SDL + -D SDL_MAIN_HANDLED -D SDL_HOR_RES=SCREEN_WIDTH -D SDL_VER_RES=SCREEN_HEIGHT -D SDL_ZOOM=1