From fb64ba8fb6953fe7e98db6874207a687d0d57bac Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 22 Mar 2020 12:03:17 +0100 Subject: [PATCH] Add new App : Sysinfo. It displays various info about the running system : version, date/time, battery, brightness and resetreason. It contains placeholder for future use (like mac address, uptime,...). --- src/CMakeLists.txt | 5 +- src/Components/Battery/BatteryController.cpp | 4 +- src/DisplayApp/DisplayApp.cpp | 21 +++- src/DisplayApp/DisplayApp.h | 10 +- src/DisplayApp/Screens/Clock.cpp | 17 --- src/DisplayApp/Screens/Label.cpp | 28 +++++ src/DisplayApp/Screens/Label.h | 24 ++++ src/DisplayApp/Screens/ScreenList.cpp | 125 +++++++++++++++++++ src/DisplayApp/Screens/ScreenList.h | 34 +++++ src/DisplayApp/Screens/Tile.cpp | 6 +- src/DisplayApp/Screens/Tile.h | 2 +- src/SystemTask/SystemTask.cpp | 6 +- src/SystemTask/SystemTask.h | 1 + src/drivers/Watchdog.cpp | 20 +-- src/drivers/Watchdog.h | 14 ++- 15 files changed, 276 insertions(+), 41 deletions(-) create mode 100644 src/DisplayApp/Screens/Label.cpp create mode 100644 src/DisplayApp/Screens/Label.h create mode 100644 src/DisplayApp/Screens/ScreenList.cpp create mode 100644 src/DisplayApp/Screens/ScreenList.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34a7e250..5c521b33 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -213,6 +213,8 @@ list(APPEND SOURCE_FILES DisplayApp/Screens/BatteryIcon.cpp DisplayApp/Screens/BleIcon.cpp DisplayApp/Screens/Brightness.cpp + DisplayApp/Screens/ScreenList.cpp + DisplayApp/Screens/Label.cpp main.cpp drivers/St7789.cpp drivers/SpiMaster.cpp @@ -253,7 +255,8 @@ set(INCLUDE_FILES DisplayApp/Screens/BatteryIcon.h DisplayApp/Screens/BleIcon.cpp DisplayApp/Screens/Brightness.h -# DisplayApp/Screens/Tab.h + DisplayApp/Screens/ScreenList.h + DisplayApp/Screens/Label.h drivers/St7789.h drivers/SpiMaster.h drivers/Watchdog.h diff --git a/src/Components/Battery/BatteryController.cpp b/src/Components/Battery/BatteryController.cpp index 7719bcbb..198ce5aa 100644 --- a/src/Components/Battery/BatteryController.cpp +++ b/src/Components/Battery/BatteryController.cpp @@ -36,8 +36,8 @@ void Battery::Update() { voltage = (value * 2.0f) / (1024/3.0f); percentRemaining = ((voltage - 3.55)*100)*3.9; - NRF_LOG_INFO("BATTERY " NRF_LOG_FLOAT_MARKER " %% - " NRF_LOG_FLOAT_MARKER " v", NRF_LOG_FLOAT(percentRemaining), NRF_LOG_FLOAT(voltage)); - NRF_LOG_INFO("POWER Charging : %d - Power : %d", isCharging, isPowerPresent); +// NRF_LOG_INFO("BATTERY " NRF_LOG_FLOAT_MARKER " %% - " NRF_LOG_FLOAT_MARKER " v", NRF_LOG_FLOAT(percentRemaining), NRF_LOG_FLOAT(voltage)); +// NRF_LOG_INFO("POWER Charging : %d - Power : %d", isCharging, isPowerPresent); } void Battery::SaadcEventHandler(nrfx_saadc_evt_t const * event) { diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 14545d2e..e7187f1d 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "../SystemTask/SystemTask.h" using namespace Pinetime::Applications; @@ -24,13 +25,15 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd, Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::DateTime &dateTimeController, + Pinetime::Drivers::WatchdogView& watchdog, Pinetime::System::SystemTask& systemTask) : lcd{lcd}, lvgl{lvgl}, - touchPanel{touchPanel}, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController}, + watchdog{watchdog}, + touchPanel{touchPanel}, currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController) }, systemTask{systemTask} { msgQueue = xQueueCreate(queueSize, itemSize); @@ -167,7 +170,8 @@ void DisplayApp::RunningState() { currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController)); onClockApp = true; break; - case Apps::Test: currentScreen.reset(new Screens::Message(this)); break; +// case Apps::Test: currentScreen.reset(new Screens::Message(this)); break; + case Apps::SysInfo: currentScreen.reset(new Screens::ScreenList(this, dateTimeController, batteryController, brightnessController, watchdog)); break; case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break; case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break; case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break; @@ -221,3 +225,16 @@ TouchEvents DisplayApp::OnTouchEvent() { void DisplayApp::StartApp(DisplayApp::Apps app) { nextApp = app; } + +void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) { + switch(direction){ + case DisplayApp::FullRefreshDirections::Down: + lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Down); + break; + case DisplayApp::FullRefreshDirections::Up: + lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); + break; + default: break; + } + +} diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 38edd056..04c82fee 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -15,6 +15,7 @@ #include "LittleVgl.h" #include #include +#include #include "TouchEvents.h" @@ -26,7 +27,9 @@ namespace Pinetime { class DisplayApp { public: enum class States {Idle, Running}; - enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed} ; + enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed}; + enum class FullRefreshDirections { None, Up, Down }; + DisplayApp(Pinetime::Drivers::St7789& lcd, Pinetime::Components::LittleVgl& lvgl, @@ -34,13 +37,15 @@ namespace Pinetime { Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::DateTime& dateTimeController, + Pinetime::Drivers::WatchdogView& watchdog, Pinetime::System::SystemTask& systemTask); void Start(); void PushMessage(Messages msg); - enum class Apps {None, Launcher, Clock, Test, Meter, Gauge, Brightness}; + enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness}; void StartApp(Apps app); + void SetFullRefresh(FullRefreshDirections direction); private: TaskHandle_t taskHandle; static void Process(void* instance); @@ -60,6 +65,7 @@ namespace Pinetime { Pinetime::Controllers::Battery &batteryController; Pinetime::Controllers::Ble &bleController; Pinetime::Controllers::DateTime& dateTimeController; + Pinetime::Drivers::WatchdogView& watchdog; Pinetime::Drivers::Cst816S& touchPanel; TouchEvents OnTouchEvent(); diff --git a/src/DisplayApp/Screens/Clock.cpp b/src/DisplayApp/Screens/Clock.cpp index 00590777..07db83ee 100644 --- a/src/DisplayApp/Screens/Clock.cpp +++ b/src/DisplayApp/Screens/Clock.cpp @@ -37,23 +37,6 @@ Clock::Clock(DisplayApp* app, lv_img_set_src(bleIcon, BleIcon::GetIcon(false)); lv_obj_align(bleIcon, batteryIcon, LV_ALIGN_OUT_LEFT_MID, 0, 0); -// label_battery = lv_label_create(lv_scr_act(), NULL); -// lv_obj_align(label_battery, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -80, 0); - -// labelStyle = const_cast(lv_label_get_style(label_battery, LV_LABEL_STYLE_MAIN)); -// labelStyle->text.font = &jetbrains_mono_bold_20; -// -// lv_style_copy(&labelBigStyle, labelStyle); -// labelBigStyle.text.font = &jetbrains_mono_extrabold_compressed; -// -// lv_label_set_style(label_battery, LV_LABEL_STYLE_MAIN, labelStyle); - -// label_ble = lv_label_create(lv_scr_act(), NULL); - - -// lv_label_set_style(label_ble, LV_LABEL_STYLE_MAIN, labelStyle); -// lv_obj_align(label_ble, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 10, 0); - label_date = lv_label_create(lv_scr_act(), NULL); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60); diff --git a/src/DisplayApp/Screens/Label.cpp b/src/DisplayApp/Screens/Label.cpp new file mode 100644 index 00000000..ba35279d --- /dev/null +++ b/src/DisplayApp/Screens/Label.cpp @@ -0,0 +1,28 @@ +#include +#include "Label.h" + +using namespace Pinetime::Applications::Screens; + + +Label::Label(const char* text) : text{text} { + +} + +Label::~Label() { + +} + +void Label::Refresh() { + +} + +void Label::Show() { + label = lv_label_create(lv_scr_act(), NULL); + lv_label_set_align(label, LV_LABEL_ALIGN_LEFT); + lv_obj_set_size(label, 240, 240); + lv_label_set_text(label, text); +} + +void Label::Hide() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/DisplayApp/Screens/Label.h b/src/DisplayApp/Screens/Label.h new file mode 100644 index 00000000..b73540f4 --- /dev/null +++ b/src/DisplayApp/Screens/Label.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include "Screen.h" + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Label { + public: + Label() = default; + explicit Label(const char* text); + ~Label(); + void Refresh(); + + void Hide(); + void Show(); + private: + lv_obj_t * label = nullptr; + const char* text = nullptr; + }; + } + } +} \ No newline at end of file diff --git a/src/DisplayApp/Screens/ScreenList.cpp b/src/DisplayApp/Screens/ScreenList.cpp new file mode 100644 index 00000000..bea335ff --- /dev/null +++ b/src/DisplayApp/Screens/ScreenList.cpp @@ -0,0 +1,125 @@ +#include +#include +#include "ScreenList.h" + +using namespace Pinetime::Applications::Screens; + +// TODO this class must be improved to receive the list of "sub screens" via pointer or +// move operation. +// It should accept many type of "sub screen" (it only supports Label for now). +// The number of sub screen it supports must be dynamic. +ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController, + Pinetime::Controllers::Battery& batteryController, Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Drivers::WatchdogView& watchdog) : + Screen(app), + dateTimeController{dateTimeController}, batteryController{batteryController}, brightnessController{brightnessController}, watchdog{watchdog} { + screens.reserve(3); + + // TODO all of this is far too heavy (string processing). This should be improved. + // TODO the info (battery, time,...) should be updated in the Refresh method. + char t1[200]; + + auto batteryPercent = static_cast(batteryController.PercentRemaining()); + if(batteryPercent > 100) batteryPercent = 100; + else if(batteryPercent < 0) batteryPercent = 0; + + uint8_t brightness = 0; + switch(brightnessController.Level()) { + case Controllers::BrightnessController::Levels::Low: brightness = 1; break; + case Controllers::BrightnessController::Levels::Medium: brightness = 2; break; + case Controllers::BrightnessController::Levels::High: brightness = 3; break; + } + auto resetReason = [&watchdog]() { + switch (watchdog.ResetReason()) { + case Drivers::Watchdog::ResetReasons::Watchdog: return "wtdg"; + case Drivers::Watchdog::ResetReasons::HardReset: return "hardr"; + case Drivers::Watchdog::ResetReasons::NFC: return "nfc"; + case Drivers::Watchdog::ResetReasons::SoftReset: return "softr"; + case Drivers::Watchdog::ResetReasons::CpuLockup: return "cpulock"; + case Drivers::Watchdog::ResetReasons::SystemOff: return "off"; + case Drivers::Watchdog::ResetReasons::LpComp: return "lpcomp"; + case Drivers::Watchdog::ResetReasons::DebugInterface: return "dbg"; + case Drivers::Watchdog::ResetReasons::ResetPin: return "rst"; + default: return "?"; + } + }(); + + + sprintf(t1, "Pinetime\n" + "Version:%d.%d.%d\n" + "Build: xx/xx/xxxx\n" + "Time: %02d:%02d:%02d\n" + "date: %02d/%02d/%04d\n" + "Uptime: xd xxhxx:xx\n" + "Battery: %d%%\n" + "Backlight: %d/3\n" + "Last reset: %s\n" + "BLE MAC: \n AA:BB:CC:DD:EE:FF", Version::Major(), Version::Minor(), Version::Patch(), + dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(), + dateTimeController.Day(), dateTimeController.Month(), dateTimeController.Year(), + batteryPercent, brightness, resetReason); +/* + auto t1 = "Pinetime\n" + "Version:\n" + "Build: 23/03/2020\n" + "Time: 17:23:12\n" + "date: 23/03/2020\n" + "Uptime: 2d 13h52:21\n" + "Battery: 3.56v/82%\n" + "Backlight: 2/3\n" + "Last reset: wtdg\n" + "BLE MAC: \n AA:BB:CC:DD:EE:FF";*/ + screens.emplace_back(t1); + + auto t2 = "Hello from\nthe developper!"; + screens.emplace_back(t2); + + auto t3 = "Place holder\nin case we need\nmore room!"; + screens.emplace_back(t3); + + auto &screen = screens[screenIndex]; + screen.Show(); +} + +ScreenList::~ScreenList() { + lv_obj_clean(lv_scr_act()); +} + +bool ScreenList::Refresh() { + auto &screen = screens[screenIndex]; + screen.Refresh(); + + return running; +} + +bool ScreenList::OnButtonPushed() { + running = false; + return true; +} + +bool ScreenList::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + switch (event) { + case TouchEvents::SwipeDown: + if (screenIndex > 0) { + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); + auto &oldScreen = screens[screenIndex]; + oldScreen.Hide(); + screenIndex--; + auto &newScreen = screens[screenIndex]; + newScreen.Show(); + } + return true; + case TouchEvents::SwipeUp: + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); + if (screenIndex < screens.size() - 1) { + auto &oldScreen = screens[screenIndex]; + oldScreen.Hide(); + screenIndex++; + auto &newScreen = screens[screenIndex]; + newScreen.Show(); + } + return true; + default: + return false; + } + return false; +} diff --git a/src/DisplayApp/Screens/ScreenList.h b/src/DisplayApp/Screens/ScreenList.h new file mode 100644 index 00000000..ba8e7700 --- /dev/null +++ b/src/DisplayApp/Screens/ScreenList.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include "Screen.h" +#include "Label.h" + +namespace Pinetime { + namespace Applications { + namespace Screens { + class ScreenList : public Screen { + public: + explicit ScreenList(DisplayApp* app, + Pinetime::Controllers::DateTime& dateTimeController, + Pinetime::Controllers::Battery& batteryController, + Pinetime::Controllers::BrightnessController& brightnessController, + Pinetime::Drivers::WatchdogView& watchdog); + ~ScreenList() override; + bool Refresh() override; + bool OnButtonPushed() override; + bool OnTouchEvent(TouchEvents event) override; + private: + bool running = true; + uint8_t screenIndex = 0; + + // TODO choose another container without dynamic alloc + std::vector screens; + Pinetime::Controllers::DateTime& dateTimeController; + Pinetime::Controllers::Battery& batteryController; + Pinetime::Controllers::BrightnessController& brightnessController; + Pinetime::Drivers::WatchdogView& watchdog; + }; + } + } +} \ No newline at end of file diff --git a/src/DisplayApp/Screens/Tile.cpp b/src/DisplayApp/Screens/Tile.cpp index 5dc1fce4..7eb1018c 100644 --- a/src/DisplayApp/Screens/Tile.cpp +++ b/src/DisplayApp/Screens/Tile.cpp @@ -126,7 +126,7 @@ void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) { modal->Show(); break; case 4: - tile->StartTestApp(); + tile->StartSysInfoApp(); break; case 5: tile->StartBrightnessApp(); @@ -148,8 +148,8 @@ void Tile::StartClockApp() { running = false; } -void Tile::StartTestApp() { - app->StartApp(DisplayApp::Apps::Test); +void Tile::StartSysInfoApp() { + app->StartApp(DisplayApp::Apps::SysInfo); running = false; } diff --git a/src/DisplayApp/Screens/Tile.h b/src/DisplayApp/Screens/Tile.h index cfd9b01f..fa2d6db0 100644 --- a/src/DisplayApp/Screens/Tile.h +++ b/src/DisplayApp/Screens/Tile.h @@ -52,7 +52,7 @@ namespace Pinetime { uint32_t clickCount = 0 ; uint32_t previousClickCount = 0; void StartClockApp(); - void StartTestApp(); + void StartSysInfoApp(); void StartMeterApp(); void StartGaugeApp(); bool running = true; diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index 00fad002..c4e1386c 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -13,7 +13,9 @@ SystemTask::SystemTask(Pinetime::Drivers::SpiMaster &spi, Pinetime::Drivers::St7 Pinetime::Drivers::Cst816S &touchPanel, Pinetime::Components::LittleVgl &lvgl, Pinetime::Controllers::Battery &batteryController, Pinetime::Controllers::Ble &bleController, Pinetime::Controllers::DateTime& dateTimeController) : - spi{spi}, lcd{lcd}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController} { + spi{spi}, lcd{lcd}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, + bleController{bleController}, dateTimeController{dateTimeController}, + watchdog{}, watchdogView{watchdog}{ systemTaksMsgQueue = xQueueCreate(10, 1); } @@ -42,7 +44,7 @@ void SystemTask::Work() { touchPanel.Init(); batteryController.Init(); - displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, dateTimeController, *this)); + displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, dateTimeController, watchdogView, *this)); displayApp->Start(); batteryController.Update(); diff --git a/src/SystemTask/SystemTask.h b/src/SystemTask/SystemTask.h index f5ba2d75..a2775d9d 100644 --- a/src/SystemTask/SystemTask.h +++ b/src/SystemTask/SystemTask.h @@ -43,6 +43,7 @@ namespace Pinetime { QueueHandle_t systemTaksMsgQueue; bool isSleeping = false; Pinetime::Drivers::Watchdog watchdog; + Pinetime::Drivers::WatchdogView watchdogView; static constexpr uint8_t pinSpiSck = 2; diff --git a/src/drivers/Watchdog.cpp b/src/drivers/Watchdog.cpp index b0dc12e5..55b6de73 100644 --- a/src/drivers/Watchdog.cpp +++ b/src/drivers/Watchdog.cpp @@ -19,6 +19,8 @@ void Watchdog::Setup(uint8_t timeoutSeconds) { /* Enable reload requests */ NRF_WDT->RREN = (WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos); + + resetReason = ActualResetReason(); } void Watchdog::Start() { @@ -29,18 +31,18 @@ void Watchdog::Kick() { NRF_WDT->RR[0] = WDT_RR_RR_Reload; } -Watchdog::ResetReasons Watchdog::ResetReason() { +Watchdog::ResetReasons Watchdog::ActualResetReason() const { uint32_t resetReason; sd_power_reset_reason_get(&resetReason); sd_power_reset_reason_clr(0xFFFFFFFF); - if(resetReason & 0x01) return ResetReasons::ResetPin; - if((resetReason >> 1) & 0x01) return ResetReasons::Watchdog; - if((resetReason >> 2) & 0x01) return ResetReasons::SoftReset; - if((resetReason >> 3) & 0x01) return ResetReasons::CpuLockup; - if((resetReason >> 16) & 0x01) return ResetReasons::SystemOff; - if((resetReason >> 17) & 0x01) return ResetReasons::LpComp; - if((resetReason >> 18) & 0x01) return ResetReasons::DebugInterface; - if((resetReason >> 19) & 0x01) return ResetReasons::NFC; + if(resetReason & 0x01u) return ResetReasons::ResetPin; + if((resetReason >> 1u) & 0x01u) return ResetReasons::Watchdog; + if((resetReason >> 2u) & 0x01u) return ResetReasons::SoftReset; + if((resetReason >> 3u) & 0x01u) return ResetReasons::CpuLockup; + if((resetReason >> 16u) & 0x01u) return ResetReasons::SystemOff; + if((resetReason >> 17u) & 0x01u) return ResetReasons::LpComp; + if((resetReason >> 18u) & 0x01u) return ResetReasons::DebugInterface; + if((resetReason >> 19u) & 0x01u) return ResetReasons::NFC; return ResetReasons::HardReset; } diff --git a/src/drivers/Watchdog.h b/src/drivers/Watchdog.h index da192d9e..73f99ea1 100644 --- a/src/drivers/Watchdog.h +++ b/src/drivers/Watchdog.h @@ -8,10 +8,20 @@ namespace Pinetime { void Setup(uint8_t timeoutSeconds); void Start(); void Kick(); - - ResetReasons ResetReason(); + ResetReasons ResetReason() const { return resetReason; } static const char* ResetReasonToString(ResetReasons reason); + private: + ResetReasons resetReason; + ResetReasons ActualResetReason() const; + }; + class WatchdogView { + public: + WatchdogView(const Watchdog& watchdog) : watchdog{watchdog} { } + Watchdog::ResetReasons ResetReason() const { return watchdog.ResetReason();} + + private: + const Watchdog& watchdog; }; } }