Remove timer passed into display and convert to a notification send out by the display class

Handle that notification by resetting the sleep timer.
This commit is contained in:
Matthew Colvin 2023-08-14 20:05:15 -05:00 committed by MatthewColvin
parent 916f589344
commit fe51337458
3 changed files with 24 additions and 16 deletions

View file

@ -53,10 +53,13 @@ void HardwareRevX::initIO() {
HardwareRevX::HardwareRevX():
HardwareAbstract(
Display::getInstance(standbyTimer),
Display::getInstance(),
std::make_shared<Battery>(ADC_BAT,CRG_STAT),
wifiHandler::getInstance()
){}
){
// Reset Sleep Timer on Touch Events
Display::getInstance()->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;});
}
HardwareRevX::WakeReason getWakeReason() {
// Find out wakeup cause
@ -361,11 +364,11 @@ void HardwareRevX::loopHandler() {
// lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_FULL);
// else if (battery_percentage > 75)
// lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_3);
// else if (battery_percentage > 50)
// lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_2);
// else if (battery_percentage > 25)
// elsse if (battery_percentage > 25)
// lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_1);
// else
// e if (battery_percentage > 50)
// lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_2);
// elelse
// lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_EMPTY);
// }
// }

View file

@ -3,21 +3,20 @@
#include "omoteconfig.h"
#include "Wire.h"
std::shared_ptr<Display> Display::getInstance(int& standby_timer)
std::shared_ptr<Display> Display::getInstance()
{
if (DisplayAbstract::mInstance == nullptr)
{
DisplayAbstract::mInstance = std::shared_ptr<Display>(new Display(LCD_EN, LCD_BL, standby_timer));
DisplayAbstract::mInstance = std::shared_ptr<Display>(new Display(LCD_EN, LCD_BL));
}
return std::static_pointer_cast<Display>(mInstance);
}
Display::Display(int backlight_pin, int enable_pin, int& standby_timer): DisplayAbstract(),
Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(),
mBacklightPin(backlight_pin),
mEnablePin(enable_pin),
tft(TFT_eSPI()),
touch(Adafruit_FT6206()),
standbyTimer(standby_timer)
touch(Adafruit_FT6206())
{
pinMode(mEnablePin, OUTPUT);
digitalWrite(mEnablePin, HIGH);
@ -41,6 +40,10 @@ Display::Display(int backlight_pin, int enable_pin, int& standby_timer): Display
setupTouchScreen();
}
void Display::onTouch(Notification<TS_Point>::HandlerTy aTouchHandler){
mTouchEvent.onNotify(std::move(aTouchHandler));
}
void Display::setupTFT() {
tft.init();
tft.initDMA();
@ -78,7 +81,7 @@ void Display::screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data){
bool touched = false;
if ((touchX > 0) || (touchY > 0)) {
touched = true;
standbyTimer = SLEEP_TIMEOUT;
mTouchEvent.notify(touchPoint);
}
if (!touched) {

View file

@ -1,5 +1,6 @@
#pragma once
#include "DisplayAbstract.h"
#include "Notification.hpp"
#include <Adafruit_FT6206.h>
#include <memory>
#include <TFT_eSPI.h>
@ -18,18 +19,19 @@
class Display: public DisplayAbstract
{
public:
static std::shared_ptr<Display> getInstance(int& standby_timer);
static std::shared_ptr<Display> getInstance();
virtual void setBrightness(uint8_t brightness) override;
virtual void turnOff() override;
void onTouch(Notification<TS_Point>::HandlerTy aTouchHandler);
protected:
virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override;
private:
// TODO Find a better way to handle timeout resets
Display(int backlight_pin, int enable_pin, int& standby_timer);
Display(int backlight_pin, int enable_pin);
void setupTFT();
void setupTouchScreen();
@ -41,5 +43,5 @@ class Display: public DisplayAbstract
TS_Point touchPoint;
TS_Point oldPoint;
int& standbyTimer;
Notification<TS_Point> mTouchEvent;
};