Skip to content

Commit

Permalink
Add Loop Handler that updates UI
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewColvin committed Jul 29, 2023
1 parent e29e2aa commit 064d442
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Platformio/include/OmoteUI/OmoteUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class OmoteUI {
// Use LVGL to layout the ui and register the callbacks
void layout_UI();

void loopHandler();

private:
static std::shared_ptr<OmoteUI> mInstance;
std::shared_ptr<HardwareAbstractionInterface> mHardware;
Expand Down
13 changes: 9 additions & 4 deletions Platformio/src/HardwareRevX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,6 @@ void HardwareRevX::loopHandler(){
ledcWrite(5, backlight_brightness); // Backlight on
}

// Update LVGL UI
lv_timer_handler();

// Blink debug LED at 1 Hz
digitalWrite(USER_LED, millis() % 1000 > 500);

Expand All @@ -425,6 +422,7 @@ void HardwareRevX::loopHandler(){
IMUTaskTimer = millis();
}

// TODO Convert to free RTOS task
// Update battery stats at 1Hz
static unsigned long batteryTaskTimer =
millis() + 1000; // add 1s to start immediately
Expand All @@ -437,7 +435,7 @@ void HardwareRevX::loopHandler(){
battery_ischarging = !digitalRead(CRG_STAT);
// Check if battery is charging, fully charged or disconnected
}
// TODO Create batter change notification for UI
// TODO Create batter change notification for UI

// if (battery_ischarging || (!battery_ischarging && battery_voltage > 4350)) {
// lv_label_set_text(objBattPercentage, "");
Expand Down Expand Up @@ -476,4 +474,11 @@ void HardwareRevX::loopHandler(){
}
}
}
// IR Test
// tft.drawString("IR Command: ", 10, 90, 1);
// decode_results results;
// if (IrReceiver.decode(&results)) {
// IrReceiver.resume(); // Enable receiving of the next value
//} //tft.drawString(String(results.command) + " ", 80, 90, 1);
//
}
4 changes: 4 additions & 0 deletions Platformio/src/OmoteUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ void OmoteUI::virtualKeypad_event_cb(lv_event_t *e) {
mHardware->debugPrint(buffer);
}

void OmoteUI::loopHandler(){
lv_timer_handler();
}

void OmoteUI::layout_UI() {

// --- LVGL UI Configuration ---
Expand Down
15 changes: 1 addition & 14 deletions Platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,16 @@
std::shared_ptr<HardwareRevX> hal = nullptr;

void setup() {

hal = HardwareRevX::getInstance();
hal->init();

auto ui = OmoteUI::getInstance(hal);
ui->layout_UI();


lv_timer_handler(); // Run the LVGL UI once before the loop takes over

Serial.print("Setup finised in ");
Serial.print(millis());
Serial.println("ms.");
}

void loop() {

HardwareRevX::getInstance()->loopHandler();
// IR Test
// tft.drawString("IR Command: ", 10, 90, 1);
// decode_results results;
// if (IrReceiver.decode(&results)) {
// IrReceiver.resume(); // Enable receiving of the next value
//} //tft.drawString(String(results.command) + " ", 80, 90, 1);
//
OmoteUI::getInstance()->loopHandler();
}

0 comments on commit 064d442

Please sign in to comment.