Added ability for sim to simulate brightness and battery along with displaying it via the title.

This commit is contained in:
Matthew Colvin 2023-08-31 10:14:09 -05:00 committed by MatthewColvin
parent b45de68ebb
commit 4a1eb8abfa
5 changed files with 41 additions and 12 deletions

View file

@ -1,13 +1,7 @@
#include "HardwareSimulator.hpp" #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"
#include "SDLDisplay.hpp" #include "SDLDisplay.hpp"
#include <sstream>
HardwareSimulator::HardwareSimulator(): HardwareAbstract(), HardwareSimulator::HardwareSimulator(): HardwareAbstract(),
mTickThread([](){ mTickThread([](){
@ -18,7 +12,30 @@ HardwareSimulator::HardwareSimulator(): HardwareAbstract(),
mBattery(std::make_shared<BatterySimulator>()), mBattery(std::make_shared<BatterySimulator>()),
mDisplay(SDLDisplay::getInstance()), mDisplay(SDLDisplay::getInstance()),
mWifiHandler(std::make_shared<wifiHandlerSim>()) mWifiHandler(std::make_shared<wifiHandlerSim>())
{} {
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<int>(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<BatteryInterface> HardwareSimulator::battery(){ std::shared_ptr<BatteryInterface> HardwareSimulator::battery(){
return mBattery; return mBattery;

View file

@ -26,6 +26,7 @@ public:
private: private:
std::thread mTickThread; std::thread mTickThread;
std::thread mHardwareStatusTitleUpdate;
std::shared_ptr<BatterySimulator> mBattery; std::shared_ptr<BatterySimulator> mBattery;
std::shared_ptr<SDLDisplay> mDisplay; std::shared_ptr<SDLDisplay> mDisplay;

View file

@ -1,6 +1,6 @@
#include "SDLDisplay.hpp" #include "SDLDisplay.hpp"
#include "SDL2/SDL.h"
#include "sdl/sdl.h" #include "sdl/sdl.h"
#include <string>
std::shared_ptr<SDLDisplay> SDLDisplay::getInstance(){ std::shared_ptr<SDLDisplay> SDLDisplay::getInstance(){
if (!DisplayAbstract::mInstance){ if (!DisplayAbstract::mInstance){
@ -10,11 +10,11 @@ std::shared_ptr<SDLDisplay> SDLDisplay::getInstance(){
} }
void SDLDisplay::setBrightness(uint8_t brightness){ void SDLDisplay::setBrightness(uint8_t brightness){
mBrightness = brightness;
} }
uint8_t SDLDisplay::getBrightness(){ uint8_t SDLDisplay::getBrightness(){
return mBrightness;
} }
void SDLDisplay::turnOff(){ 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); sdl_mouse_read(indev_driver,data);
} }
void SDLDisplay::setTitle(std::string aNewTitle){
SDL_SetWindowTitle(mSimWindow,aNewTitle.c_str());
}
SDLDisplay::SDLDisplay(): DisplayAbstract() { SDLDisplay::SDLDisplay(): DisplayAbstract() {
sdl_init(); sdl_init();
mSimWindow = SDL_GetWindowFromID(1); // Get the SDL window via ID hopefully it is always 1...
} }

View file

@ -1,4 +1,6 @@
#pragma once #pragma once
#include <stdint.h>
#include "SDL2/SDL.h"
#include "DisplayAbstract.h" #include "DisplayAbstract.h"
class SDLDisplay : public DisplayAbstract{ class SDLDisplay : public DisplayAbstract{
@ -10,11 +12,14 @@ public:
virtual uint8_t getBrightness() override; virtual uint8_t getBrightness() override;
virtual void turnOff() override; virtual void turnOff() override;
void setTitle(std::string aNewTitle);
protected: protected:
virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) override; 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; virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override;
private: private:
SDLDisplay(); SDLDisplay();
uint8_t mBrightness;
SDL_Window* mSimWindow;
}; };

View file

@ -124,6 +124,7 @@ build_flags =
-D LV_LVGL_H_INCLUDE_SIMPLE -D LV_LVGL_H_INCLUDE_SIMPLE
-D LV_DRV_NO_CONF -D LV_DRV_NO_CONF
-D USE_SDL -D USE_SDL
-D SDL_MAIN_HANDLED
-D SDL_HOR_RES=SCREEN_WIDTH -D SDL_HOR_RES=SCREEN_WIDTH
-D SDL_VER_RES=SCREEN_HEIGHT -D SDL_VER_RES=SCREEN_HEIGHT
-D SDL_ZOOM=1 -D SDL_ZOOM=1