Added ability for sim to simulate brightness and battery along with displaying it via the title.
This commit is contained in:
parent
b45de68ebb
commit
4a1eb8abfa
5 changed files with 41 additions and 12 deletions
|
@ -1,13 +1,7 @@
|
|||
#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 <sstream>
|
||||
|
||||
HardwareSimulator::HardwareSimulator(): HardwareAbstract(),
|
||||
mTickThread([](){
|
||||
|
@ -18,7 +12,30 @@ HardwareSimulator::HardwareSimulator(): HardwareAbstract(),
|
|||
mBattery(std::make_shared<BatterySimulator>()),
|
||||
mDisplay(SDLDisplay::getInstance()),
|
||||
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(){
|
||||
return mBattery;
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
|
||||
private:
|
||||
std::thread mTickThread;
|
||||
std::thread mHardwareStatusTitleUpdate;
|
||||
|
||||
std::shared_ptr<BatterySimulator> mBattery;
|
||||
std::shared_ptr<SDLDisplay> mDisplay;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "SDLDisplay.hpp"
|
||||
#include "SDL2/SDL.h"
|
||||
#include "sdl/sdl.h"
|
||||
#include <string>
|
||||
|
||||
std::shared_ptr<SDLDisplay> SDLDisplay::getInstance(){
|
||||
if (!DisplayAbstract::mInstance){
|
||||
|
@ -10,11 +10,11 @@ std::shared_ptr<SDLDisplay> 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...
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#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;
|
||||
};
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue