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

View file

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

View file

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