rename loop handler

reorder setup to better match the origional main
This commit is contained in:
Matthew Colvin 2023-07-29 17:42:08 -05:00
parent 5d1b0086fd
commit e29e2aa7e9
4 changed files with 46 additions and 62 deletions

View file

@ -53,5 +53,6 @@
"typeinfo": "cpp" "typeinfo": "cpp"
}, },
"cmake.sourceDirectory": "${workspaceFolder}/.pio/libdeps/esp32/Adafruit BusIO", "cmake.sourceDirectory": "${workspaceFolder}/.pio/libdeps/esp32/Adafruit BusIO",
"editor.formatOnSave": false "editor.formatOnSave": false,
"idf.portWin": "COM8"
} }

View file

@ -62,49 +62,46 @@ HardwareRevX::WakeReason getWakeReason() {
} }
void HardwareRevX::init() { void HardwareRevX::init() {
// Make sure ESP32 is running at full speed // Make sure ESP32 is running at full speed
setCpuFrequencyMhz(240); setCpuFrequencyMhz(240);
Serial.begin(115200);
wakeup_reason = getWakeReason(); wakeup_reason = getWakeReason();
setupTouchScreen();
slowDisplayWakeup();
initIO(); initIO();
restorePreferences();
setupBacklight(); setupBacklight();
Serial.begin(115200);
restorePreferences();
slowDisplayWakeup();
setupTFT(); setupTFT();
setupTouchScreen();
initLVGL();
setupWifi();
setupIMU(); setupIMU();
setupIR(); setupIR();
initLVGL(); debugPrint(std::string("Finished Hardware Setup in %d",millis()));
} }
void HardwareRevX::initLVGL() { void HardwareRevX::initLVGL() {
{ lv_init();
lv_init();
lv_disp_draw_buf_init(&mdraw_buf, mbufA, mbufB, lv_disp_draw_buf_init(&mdraw_buf, mbufA, mbufB,
SCREEN_WIDTH * SCREEN_HEIGHT / 10); SCREEN_WIDTH * SCREEN_HEIGHT / 10);
// Initialize the display driver // Initialize the display driver
static lv_disp_drv_t disp_drv; static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = SCREEN_WIDTH; disp_drv.hor_res = SCREEN_WIDTH;
disp_drv.ver_res = SCREEN_HEIGHT; disp_drv.ver_res = SCREEN_HEIGHT;
disp_drv.flush_cb = &HardwareRevX::displayFlushImpl; disp_drv.flush_cb = &HardwareRevX::displayFlushImpl;
disp_drv.draw_buf = &mdraw_buf; disp_drv.draw_buf = &mdraw_buf;
lv_disp_drv_register(&disp_drv); lv_disp_drv_register(&disp_drv);
// Initialize the touchscreen driver // Initialize the touchscreen driver
static lv_indev_drv_t indev_drv; static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER; indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = &HardwareRevX::touchPadReadImpl; indev_drv.read_cb = &HardwareRevX::touchPadReadImpl;
lv_indev_drv_register(&indev_drv); lv_indev_drv_register(&indev_drv);
}
} }
void HardwareRevX::displayFlush(lv_disp_drv_t *disp, const lv_area_t *area, void HardwareRevX::displayFlush(lv_disp_drv_t *disp, const lv_area_t *area,
@ -174,7 +171,6 @@ void HardwareRevX::activityDetection() {
accZold = accZ; accZold = accZ;
} }
// Enter Sleep Mode
void HardwareRevX::enterSleep() { void HardwareRevX::enterSleep() {
// Save settings to internal flash memory // Save settings to internal flash memory
preferences.putBool("wkpByIMU", wakeupByIMUEnabled); preferences.putBool("wkpByIMU", wakeupByIMUEnabled);
@ -398,7 +394,7 @@ void HardwareRevX::setupWifi(){
#endif #endif
} }
void HardwareRevX::handleLoop(){ void HardwareRevX::loopHandler(){
// Update Backlight brightness // Update Backlight brightness
static int fadeInTimer = millis(); // fadeInTimer = time after setup static int fadeInTimer = millis(); // fadeInTimer = time after setup
if (millis() < if (millis() <

View file

@ -35,7 +35,7 @@ public:
HardwareRevX() : HardwareAbstractionInterface(){}; HardwareRevX() : HardwareAbstractionInterface(){};
virtual void debugPrint(std::string aDebugMessage) override {} virtual void debugPrint(std::string aDebugMessage) override {Serial.print(aDebugMessage.c_str());}
virtual void sendIR() override {} virtual void sendIR() override {}
@ -43,43 +43,35 @@ public:
virtual void init(); virtual void init();
void handleLoop(); void loopHandler();
protected: protected:
virtual void initLVGL(); // Init Functions to setup hardware
void initIO(); void initIO();
void setupBacklight();
void restorePreferences();
void slowDisplayWakeup();
void setupTFT();
void setupTouchScreen();
void initLVGL();
void setupIMU();
void setupIR();
void setupWifi();
void activityDetection();
void enterSleep();
void configIMUInterrupts();
// UI/UX Handlers
void displayFlush(lv_disp_drv_t *disp, const lv_area_t *area, void displayFlush(lv_disp_drv_t *disp, const lv_area_t *area,
lv_color_t *color_p); lv_color_t *color_p);
void touchPadRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data); void touchPadRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data);
void activityDetection();
void enterSleep();
void configIMUInterrupts();
void setupBacklight();
void restorePreferences();
void setupTFT();
void setupTouchScreen();
void setupIMU();
void slowDisplayWakeup();
void setupWifi();
void setupIR();
void handleWifiEvent(WiFiEvent_t event); void handleWifiEvent(WiFiEvent_t event);
private: private:
// Static Wrappers Needed to Satisfy C APIs
static void WiFiEvent(WiFiEvent_t event){ static void WiFiEvent(WiFiEvent_t event){
mInstance->handleWifiEvent(event); mInstance->handleWifiEvent(event);
} }
@ -154,10 +146,5 @@ private:
byte virtualKeyMapTechnisat[10] = {0x1, 0x2, 0x3, 0x4, 0x5, byte virtualKeyMapTechnisat[10] = {0x1, 0x2, 0x3, 0x4, 0x5,
0x6, 0x7, 0x8, 0x9, 0x0}; 0x6, 0x7, 0x8, 0x9, 0x0};
static std::shared_ptr<HardwareRevX> mInstance; static std::shared_ptr<HardwareRevX> mInstance;
}; };

View file

@ -27,7 +27,7 @@ void setup() {
void loop() { void loop() {
HardwareRevX::getInstance()->handleLoop(); HardwareRevX::getInstance()->loopHandler();
// IR Test // IR Test
// tft.drawString("IR Command: ", 10, 90, 1); // tft.drawString("IR Command: ", 10, 90, 1);
// decode_results results; // decode_results results;