From 2ed76ac55615a720dbcbf2ac828ad3060a252273 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 15 Mar 2020 18:03:11 +0100 Subject: Encapsulate brightness controll into the class BrightnessController. Add a new app to configure the brightness. --- src/Components/Brightness/BrightnessController.cpp | 70 ++++++++++++++++++++++ src/Components/Brightness/BrightnessController.h | 28 +++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/Components/Brightness/BrightnessController.cpp create mode 100644 src/Components/Brightness/BrightnessController.h (limited to 'src/Components') diff --git a/src/Components/Brightness/BrightnessController.cpp b/src/Components/Brightness/BrightnessController.cpp new file mode 100644 index 00000000..c8825d68 --- /dev/null +++ b/src/Components/Brightness/BrightnessController.cpp @@ -0,0 +1,70 @@ +#include +#include "BrightnessController.h" + +using namespace Pinetime::Controllers; + + +void BrightnessController::Init() { + nrf_gpio_cfg_output(pinLcdBacklight1); + nrf_gpio_cfg_output(pinLcdBacklight2); + nrf_gpio_cfg_output(pinLcdBacklight3); + Set(level); +} + +void BrightnessController::Set(BrightnessController::Levels level) { + this->level = level; + switch(level) { + default: + case Levels::High: + nrf_gpio_pin_clear(pinLcdBacklight1); + nrf_gpio_pin_clear(pinLcdBacklight2); + nrf_gpio_pin_clear(pinLcdBacklight3); + break; + case Levels::Medium: + nrf_gpio_pin_clear(pinLcdBacklight1); + nrf_gpio_pin_clear(pinLcdBacklight2); + nrf_gpio_pin_set(pinLcdBacklight3); + break; + case Levels::Low: + nrf_gpio_pin_clear(pinLcdBacklight1); + nrf_gpio_pin_set(pinLcdBacklight2); + nrf_gpio_pin_set(pinLcdBacklight3); + break; + case Levels::Off: + nrf_gpio_pin_set(pinLcdBacklight1); + nrf_gpio_pin_set(pinLcdBacklight2); + nrf_gpio_pin_set(pinLcdBacklight3); + break; + } +} + +void BrightnessController::Lower() { + switch(level) { + case Levels::High: Set(Levels::Medium); break; + case Levels::Medium: Set(Levels::Low); break; + case Levels::Low: Set(Levels::Off); break; + default: break; + } +} + +void BrightnessController::Higher() { + switch(level) { + case Levels::Off: Set(Levels::Low); break; + case Levels::Low: Set(Levels::Medium); break; + case Levels::Medium: Set(Levels::High); break; + default: break; + } +} + +BrightnessController::Levels BrightnessController::Level() const { + return level; +} + +void BrightnessController::Backup() { + backupLevel = level; +} + +void BrightnessController::Restore() { + Set(backupLevel); +} + diff --git a/src/Components/Brightness/BrightnessController.h b/src/Components/Brightness/BrightnessController.h new file mode 100644 index 00000000..b8354ec0 --- /dev/null +++ b/src/Components/Brightness/BrightnessController.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +namespace Pinetime { + namespace Controllers { + class BrightnessController { + public: + enum class Levels {Off, Low, Medium, High}; + void Init(); + + void Set(Levels level); + Levels Level() const; + void Lower(); + void Higher(); + + void Backup(); + void Restore(); + + private: + static constexpr uint8_t pinLcdBacklight1 = 14; + static constexpr uint8_t pinLcdBacklight2 = 22; + static constexpr uint8_t pinLcdBacklight3 = 23; + Levels level = Levels::High; + Levels backupLevel = Levels::High; + }; + } +} -- cgit v1.2.3 From fb64ba8fb6953fe7e98db6874207a687d0d57bac Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 22 Mar 2020 12:03:17 +0100 Subject: 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 (limited to 'src/Components') 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; }; } } -- cgit v1.2.3 From 68240704c7a60534342cfc0157564f11cf82d9d8 Mon Sep 17 00:00:00 2001 From: JF Date: Wed, 25 Mar 2020 21:23:40 +0100 Subject: Add support for BLE notification (ANS client). Work In Progress!!! --- cmake-nRF5x/CMake_nRF5x.cmake | 3 +- src/BLE/BleManager.c | 220 ++++++++++++++++++++++++++++++++++- src/BLE/BleManager.h | 4 + src/Components/Ble/BleController.cpp | 28 +++++ src/Components/Ble/BleController.h | 14 +++ src/DisplayApp/DisplayApp.cpp | 11 ++ src/DisplayApp/DisplayApp.h | 7 +- src/DisplayApp/Screens/Modal.cpp | 37 ++++++ src/DisplayApp/Screens/Modal.h | 3 + src/SystemTask/SystemTask.cpp | 8 +- src/SystemTask/SystemTask.h | 3 +- src/main.cpp | 8 ++ src/sdk_config.h | 12 +- 13 files changed, 346 insertions(+), 12 deletions(-) (limited to 'src/Components') diff --git a/cmake-nRF5x/CMake_nRF5x.cmake b/cmake-nRF5x/CMake_nRF5x.cmake index 8a43cf12..3e8e96aa 100755 --- a/cmake-nRF5x/CMake_nRF5x.cmake +++ b/cmake-nRF5x/CMake_nRF5x.cmake @@ -260,7 +260,8 @@ macro(nRF5x_setup) list(APPEND SDK_SOURCE_FILES "${NRF5_SDK_PATH}/components/ble/ble_db_discovery/ble_db_discovery.c" "${NRF5_SDK_PATH}/components/ble/ble_services/ble_cts_c/ble_cts_c.c" - "${NRF5_SDK_PATH}/external/thedotfactory_fonts/orkney24pts.c" + "${NRF5_SDK_PATH}/components/ble/ble_services/ble_ans_c/ble_ans_c.c" +# "${NRF5_SDK_PATH}/external/thedotfactory_fonts/orkney24pts.c" ) #BLE S132 diff --git a/src/BLE/BleManager.c b/src/BLE/BleManager.c index 48653982..b7d6074a 100644 --- a/src/BLE/BleManager.c +++ b/src/BLE/BleManager.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include "nrf_sdh_soc.h" @@ -42,14 +43,31 @@ void ble_manager_cts_print_time(ble_cts_c_evt_t *p_evt); void ble_manager_conn_params_event_handler(ble_conn_params_evt_t *p_evt); void ble_manager_conn_params_error_handler(uint32_t nrf_error); +typedef enum +{ + ALERT_NOTIFICATION_DISABLED, /**< Alert Notifications has been disabled. */ + ALERT_NOTIFICATION_ENABLED, /**< Alert Notifications has been enabled. */ + ALERT_NOTIFICATION_ON, /**< Alert State is on. */ +} ble_ans_c_alert_state_t; + +void on_ans_c_evt(ble_ans_c_evt_t * p_evt); +void alert_notification_error_handler(uint32_t nrf_error); +void handle_alert_notification(ble_ans_c_evt_t * p_evt); +void supported_alert_notification_read(void); +void alert_notification_setup(void); +void control_point_setup(ble_ans_c_evt_t * p_evt); + uint16_t ble_manager_connection_handle = BLE_CONN_HANDLE_INVALID; // Handle of the current connection. NRF_BLE_QWR_DEF(ble_manager_queue_write); // Context for the Queued Write module. BLE_CTS_C_DEF(ble_manager_cts_client); // Current Time service instance. NRF_BLE_GATT_DEF(ble_manager_gatt); // GATT module instance. BLE_ADVERTISING_DEF(ble_manager_advertising); // Advertising module instance. BLE_DB_DISCOVERY_DEF(ble_manager_db_discovery); +BLE_ANS_C_DEF(m_ans_c); - +static uint8_t m_alert_message_buffer[MESSAGE_BUFFER_SIZE]; /**< Message buffer for optional notify messages. */ +static ble_ans_c_alert_state_t m_new_alert_state = ALERT_NOTIFICATION_DISABLED; /**< State that holds the current state of New Alert Notifications, i.e. Enabled, Alert On, Disabled. */ +static ble_ans_c_alert_state_t m_unread_alert_state = ALERT_NOTIFICATION_DISABLED; /**< State that holds the current state of Unread Alert Notifications, i.e. Enabled, Alert On, Disabled. */ static ble_uuid_t ble_manager_advertising_uuids[] = /* Universally unique service identifiers.*/ { @@ -88,6 +106,21 @@ static char const *month_of_year[] = "December" }; +static char const * lit_catid[BLE_ANS_NB_OF_CATEGORY_ID] = + { + "Simple alert", + "Email", + "News", + "Incoming call", + "Missed call", + "SMS/MMS", + "Voice mail", + "Schedule", + "High prioritized alert", + "Instant message" + }; + + void ble_manager_init() { ble_manager_init_stack(); ble_manager_init_gap_params(); @@ -133,6 +166,11 @@ void ble_manager_set_ble_disconnection_callback(void (*OnBleDisconnection)()) { OnBleDisconnectionCallback = OnBleDisconnection; } +void (*OnNewNotificationCallback)(const char* message, uint8_t size); +void ble_manager_set_new_notification_callback(void (*OnNewNotification)(const char*, uint8_t size)) { + OnNewNotificationCallback = OnNewNotification; +} + void ble_manager_event_handler(ble_evt_t const *p_ble_evt, void *p_context) { uint32_t err_code; @@ -227,6 +265,8 @@ void ble_manager_init_db_discovery() { void ble_manager_discover_handler(ble_db_discovery_evt_t *p_evt) { ble_cts_c_on_db_disc_evt(&ble_manager_cts_client, p_evt); + NRF_LOG_INFO("ble_ans_c_on_db_disc_evt"); + ble_ans_c_on_db_disc_evt(&m_ans_c, p_evt); } void ble_manager_init_advertising() { @@ -382,12 +422,165 @@ void ble_manager_start_advertising(void *p_erase_bonds) { } } +void handle_alert_notification(ble_ans_c_evt_t * p_evt) +{ + ret_code_t err_code; + + if (p_evt->uuid.uuid == BLE_UUID_UNREAD_ALERT_CHAR) + { + if (m_unread_alert_state == ALERT_NOTIFICATION_ENABLED) + { +// err_code = bsp_indication_set(BSP_INDICATE_ALERT_1); + APP_ERROR_CHECK(err_code); + m_unread_alert_state = ALERT_NOTIFICATION_ON; + NRF_LOG_INFO("Unread Alert state: On."); + NRF_LOG_INFO(" Category: %s", + (uint32_t)lit_catid[p_evt->data.alert.alert_category]); + NRF_LOG_INFO(" Number of unread alerts: %d", + p_evt->data.alert.alert_category_count); + } + } + else if (p_evt->uuid.uuid == BLE_UUID_NEW_ALERT_CHAR) + { +// if (m_new_alert_state == ALERT_NOTIFICATION_ENABLED) + if(true) + { +// err_code = bsp_indication_set(BSP_INDICATE_ALERT_0); +// APP_ERROR_CHECK(err_code); + m_new_alert_state = ALERT_NOTIFICATION_ON; + NRF_LOG_INFO("New Alert state: On."); + NRF_LOG_INFO(" Category: %s", + (uint32_t)lit_catid[p_evt->data.alert.alert_category]); + NRF_LOG_INFO(" Number of new alerts: %d", + p_evt->data.alert.alert_category_count); + NRF_LOG_INFO(" Text String Information: (%d) %s", + p_evt->data.alert.alert_msg_length, (uint32_t)p_evt->data.alert.p_alert_msg_buf); + + OnNewNotificationCallback(p_evt->data.alert.p_alert_msg_buf, p_evt->data.alert.alert_msg_length); + } + } + else + { + // Only Unread and New Alerts exists, thus do nothing. + } +} + +void supported_alert_notification_read(void) +{ + NRF_LOG_INFO("Read supported Alert Notification characteristics on the connected peer."); + + ret_code_t err_code; + + err_code = ble_ans_c_new_alert_read(&m_ans_c); + APP_ERROR_CHECK(err_code); + + err_code = ble_ans_c_unread_alert_read(&m_ans_c); + APP_ERROR_CHECK(err_code); + +} + +void alert_notification_setup(void) +{ + ret_code_t err_code; + + err_code = ble_ans_c_enable_notif_new_alert(&m_ans_c); + APP_ERROR_CHECK(err_code); + + m_new_alert_state = ALERT_NOTIFICATION_ENABLED; + NRF_LOG_INFO("New Alert State: Enabled."); + + err_code = ble_ans_c_enable_notif_unread_alert(&m_ans_c); + APP_ERROR_CHECK(err_code); + + m_unread_alert_state = ALERT_NOTIFICATION_ENABLED; + NRF_LOG_INFO("Unread Alert State: Enabled."); + + NRF_LOG_INFO("Notifications enabled."); +} + +void control_point_setup(ble_ans_c_evt_t * p_evt) +{ + uint32_t err_code; + ble_ans_control_point_t setting; + + if (p_evt->uuid.uuid == BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR) + { + setting.command = ANS_ENABLE_UNREAD_CATEGORY_STATUS_NOTIFICATION; + setting.category = (ble_ans_category_id_t)p_evt->data.alert.alert_category; + NRF_LOG_INFO("Unread status notification enabled for received categories."); + } + else if (p_evt->uuid.uuid == BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR) + { + setting.command = ANS_ENABLE_NEW_INCOMING_ALERT_NOTIFICATION; + setting.category = (ble_ans_category_id_t)p_evt->data.alert.alert_category; + NRF_LOG_INFO("New incoming notification enabled for received categories."); + } + else + { + return; + } + + err_code = ble_ans_c_control_point_write(&m_ans_c, &setting); + APP_ERROR_CHECK(err_code); +} + +void on_ans_c_evt(ble_ans_c_evt_t * p_evt) +{ + ret_code_t err_code; + NRF_LOG_INFO("ANS %d", p_evt->evt_type); + + + switch (p_evt->evt_type) + { + case BLE_ANS_C_EVT_DISCOVERY_FAILED: + NRF_LOG_INFO("ANS discovery failed"); + break; + case BLE_ANS_C_EVT_NOTIFICATION: + handle_alert_notification(p_evt); + NRF_LOG_INFO("Alert Notification received from server, UUID: %X.", p_evt->uuid.uuid); + break; // BLE_ANS_C_EVT_NOTIFICATION + + case BLE_ANS_C_EVT_DISCOVERY_COMPLETE: + NRF_LOG_INFO("Alert Notification Service discovered on the server."); + err_code = ble_ans_c_handles_assign(&m_ans_c, + p_evt->conn_handle, + &p_evt->data.service); + APP_ERROR_CHECK(err_code); + supported_alert_notification_read(); + alert_notification_setup(); + break; // BLE_ANS_C_EVT_DISCOVERY_COMPLETE + + case BLE_ANS_C_EVT_READ_RESP: + NRF_LOG_INFO("Alert Setup received from server, UUID: %X.", p_evt->uuid.uuid); + control_point_setup(p_evt); + break; // BLE_ANS_C_EVT_READ_RESP + + case BLE_ANS_C_EVT_DISCONN_COMPLETE: + m_new_alert_state = ALERT_NOTIFICATION_DISABLED; + m_unread_alert_state = ALERT_NOTIFICATION_DISABLED; + +// err_code = bsp_indication_set(BSP_INDICATE_ALERT_OFF); + APP_ERROR_CHECK(err_code); + break; // BLE_ANS_C_EVT_DISCONN_COMPLETE + + default: + // No implementation needed. + break; + } +} + +void alert_notification_error_handler(uint32_t nrf_error) +{ + APP_ERROR_HANDLER(nrf_error); +} + void ble_manager_init_services() { ret_code_t err_code; ble_hrs_init_t hrs_init; ble_bas_init_t bas_init; ble_dis_init_t dis_init; ble_cts_c_init_t cts_init; + ble_ans_c_init_t ans_init_obj; nrf_ble_qwr_init_t qwr_init = {0}; uint8_t body_sensor_location; @@ -441,6 +634,21 @@ void ble_manager_init_services() { cts_init.error_handler = ble_manager_cts_error_handler; err_code = ble_cts_c_init(&ble_manager_cts_client, &cts_init); APP_ERROR_CHECK(err_code); + + // Alert Notification service + memset(&ans_init_obj, 0, sizeof(ans_init_obj)); + memset(m_alert_message_buffer, 0, MESSAGE_BUFFER_SIZE); + + ans_init_obj.evt_handler = on_ans_c_evt; + ans_init_obj.message_buffer_size = MESSAGE_BUFFER_SIZE; + ans_init_obj.p_message_buffer = m_alert_message_buffer; + ans_init_obj.error_handler = alert_notification_error_handler; + + NRF_LOG_INFO("ble_ans_c_init"); + err_code = ble_ans_c_init(&m_ans_c, &ans_init_obj); + NRF_SDH_BLE_OBSERVER(ans_observer, BLE_ANS_C_BLE_OBSERVER_PRIO,*ble_ans_c_on_ble_evt, &m_ans_c); + + APP_ERROR_CHECK(err_code); } void ble_manager_queue_write_error_handler(uint32_t nrf_error) { @@ -467,11 +675,11 @@ void ble_manager_cts_event_handler(ble_cts_c_t *p_cts, ble_cts_c_evt_t *p_evt) { NRF_LOG_INFO("Current Time Service not found on server. "); // CTS not found in this case we just disconnect. There is no reason to stay // in the connection for this simple app since it all wants is to interact with CT - if (p_evt->conn_handle != BLE_CONN_HANDLE_INVALID) { - err_code = sd_ble_gap_disconnect(p_evt->conn_handle, - BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - APP_ERROR_CHECK(err_code); - } +// if (p_evt->conn_handle != BLE_CONN_HANDLE_INVALID) { +// err_code = sd_ble_gap_disconnect(p_evt->conn_handle, +// BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); +// APP_ERROR_CHECK(err_code); +// } break; case BLE_CTS_C_EVT_DISCONN_COMPLETE: diff --git a/src/BLE/BleManager.h b/src/BLE/BleManager.h index 4424d665..e3b9faf3 100644 --- a/src/BLE/BleManager.h +++ b/src/BLE/BleManager.h @@ -31,6 +31,8 @@ extern "C" { #define NEXT_CONN_PARAMS_UPDATE_DELAY 30000 /* Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */ #define MAX_CONN_PARAMS_UPDATE_COUNT 3 /* Number of attempts before giving up the connection parameter negotiation. */ +#define MESSAGE_BUFFER_SIZE 18 /**< Size of buffer holding optional messages in notifications. */ +#define BLE_ANS_NB_OF_CATEGORY_ID 10 /**< Number of categories. */ void ble_manager_init(); void ble_manager_start_advertising(void *p_erase_bonds); @@ -41,6 +43,8 @@ void ble_manager_set_new_time_callback(void (*OnNewTime)(current_time_char_t* cu void ble_manager_set_ble_disconnection_callback(void (*OnBleDisconnection)()); void ble_manager_set_ble_connection_callback(void (*OnBleConnection)()); +void ble_manager_set_new_notification_callback(void (*OnNewNotification)(const char* message, uint8_t size)); + #ifdef __cplusplus } diff --git a/src/Components/Ble/BleController.cpp b/src/Components/Ble/BleController.cpp index c2458087..fd405896 100644 --- a/src/Components/Ble/BleController.cpp +++ b/src/Components/Ble/BleController.cpp @@ -1,7 +1,13 @@ +#include +#include #include "BleController.h" using namespace Pinetime::Controllers; +Ble::Ble() { + notificationQueue = xQueueCreate(10, sizeof(NotificationMessage)); +} + void Ble::Connect() { isConnected = true; } @@ -9,3 +15,25 @@ void Ble::Connect() { void Ble::Disconnect() { isConnected = false; } + +void Ble::PushNotification(const char *message, uint8_t size) { + char* messageCopy = static_cast(malloc(sizeof(char) * size)); + std::memcpy(messageCopy, message, size); + NotificationMessage msg; + msg.size = size; + msg.message = messageCopy; + + BaseType_t xHigherPriorityTaskWoken; + xHigherPriorityTaskWoken = pdFALSE; + xQueueSendFromISR(notificationQueue, &msg, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken) { + /* Actual macro used here is port specific. */ + // TODO : should I do something here? + } +} + +bool Ble::PopNotification(Ble::NotificationMessage& msg) { + return xQueueReceive(notificationQueue, &msg, 0) != 0; +} + + diff --git a/src/Components/Ble/BleController.h b/src/Components/Ble/BleController.h index be491ee9..4f037fc1 100644 --- a/src/Components/Ble/BleController.h +++ b/src/Components/Ble/BleController.h @@ -1,15 +1,29 @@ #pragma once +#include > +#include + namespace Pinetime { namespace Controllers { class Ble { public: + struct NotificationMessage { + uint8_t size = 0; + const char* message = nullptr; + }; + + Ble(); bool IsConnected() const {return isConnected;} void Connect(); void Disconnect(); + void PushNotification(const char* message, uint8_t size); + bool PopNotification(NotificationMessage& msg); + private: bool isConnected = false; + QueueHandle_t notificationQueue; + }; } } \ No newline at end of file diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index e7187f1d..2e07cbc5 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -38,6 +38,7 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd, systemTask{systemTask} { msgQueue = xQueueCreate(queueSize, itemSize); onClockApp = true; + modal.reset(new Screens::Modal(this)); } void DisplayApp::Start() { @@ -103,6 +104,7 @@ void DisplayApp::Refresh() { state = States::Running; break; case Messages::UpdateDateTime: +// modal->Show(); break; case Messages::UpdateBleConnection: // clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected); @@ -110,6 +112,15 @@ void DisplayApp::Refresh() { case Messages::UpdateBatteryLevel: // clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining()); break; + case Messages::NewNotification: { + Pinetime::Controllers::Ble::NotificationMessage notificationMessage; + if (bleController.PopNotification(notificationMessage)) { + std::string m {notificationMessage.message, notificationMessage.size}; + modal->Show(m); + // TODO delete message + } + } + break; case Messages::TouchEvent: { if (state != States::Running) break; auto gesture = OnTouchEvent(); diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 04c82fee..ad817331 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -16,6 +16,7 @@ #include #include #include +#include #include "TouchEvents.h" @@ -27,7 +28,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, + NewNotification + }; enum class FullRefreshDirections { None, Up, Down }; @@ -78,6 +81,8 @@ namespace Pinetime { Apps nextApp = Apps::None; bool onClockApp = false; // TODO find a better way to know that we should handle gestures and button differently for the Clock app. Controllers::BrightnessController brightnessController; + std::unique_ptr modal; + }; } } diff --git a/src/DisplayApp/Screens/Modal.cpp b/src/DisplayApp/Screens/Modal.cpp index fc353c49..ec477b6e 100644 --- a/src/DisplayApp/Screens/Modal.cpp +++ b/src/DisplayApp/Screens/Modal.cpp @@ -26,6 +26,8 @@ bool Modal::OnButtonPushed() { } void Modal::Show() { + if(isVisible) return; + isVisible = true; lv_style_copy(&modal_style, &lv_style_plain_color); modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK; modal_style.body.opa = LV_OPA_50; @@ -63,6 +65,7 @@ void Modal::Hide() { /* Delete the parent modal background */ lv_obj_del_async(lv_obj_get_parent(mbox)); mbox = NULL; /* happens before object is actually deleted! */ + isVisible = false; } void Modal::mbox_event_cb(lv_obj_t *obj, lv_event_t evt) { @@ -79,3 +82,37 @@ void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) { // Hide(); } } + +void Modal::Show(const std::string& message) { + if(isVisible) return; + this->message = message; + isVisible = true; + lv_style_copy(&modal_style, &lv_style_plain_color); + modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK; + modal_style.body.opa = LV_OPA_50; + + obj = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(obj, &modal_style); + lv_obj_set_pos(obj, 0, 0); + lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES); + lv_obj_set_opa_scale_enable(obj, true); /* Enable opacity scaling for the animation */ + + static const char * btns2[] = {"Ok", ""}; + + /* Create the message box as a child of the modal background */ + mbox = lv_mbox_create(obj, NULL); + lv_mbox_add_btns(mbox, btns2); + lv_mbox_set_text(mbox, message.data()); + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_event_cb(mbox, Modal::mbox_event_cb); + + mbox->user_data = this; + + /* Fade the message box in with an animation */ + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_time(&a, 500, 0); + lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER); + lv_anim_set_exec_cb(&a, obj, (lv_anim_exec_xcb_t)lv_obj_set_opa_scale); + lv_anim_create(&a); +} diff --git a/src/DisplayApp/Screens/Modal.h b/src/DisplayApp/Screens/Modal.h index de287293..b13b5c60 100644 --- a/src/DisplayApp/Screens/Modal.h +++ b/src/DisplayApp/Screens/Modal.h @@ -23,6 +23,7 @@ namespace Pinetime { ~Modal() override; void Show(); + void Show(const std::string& message); void Hide(); bool Refresh() override; @@ -37,6 +38,8 @@ namespace Pinetime { lv_obj_t *mbox; lv_obj_t *info; bool running = true; + bool isVisible = false; + std::string message; }; } diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index c4e1386c..0080c6b6 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -35,7 +35,7 @@ void SystemTask::Work() { watchdog.Start(); NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); APP_GPIOTE_INIT(2); - bool erase_bonds=false; + bool erase_bonds=true; ble_manager_init_peer_manager(); nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds); @@ -84,6 +84,12 @@ void SystemTask::Work() { NRF_LOG_INFO("[SystemTask] Going to sleep"); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep); isSleeping = true; break; + case Messages::OnNewTime: + displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateDateTime); + break; + case Messages::OnNewNotification: + displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification); + break; default: break; } } diff --git a/src/SystemTask/SystemTask.h b/src/SystemTask/SystemTask.h index a2775d9d..b64fda65 100644 --- a/src/SystemTask/SystemTask.h +++ b/src/SystemTask/SystemTask.h @@ -13,7 +13,8 @@ namespace Pinetime { namespace System { class SystemTask { public: - enum class Messages {GoToSleep, GoToRunning}; + enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification + }; SystemTask(Pinetime::Drivers::SpiMaster& spi, Pinetime::Drivers::St7789& lcd, diff --git a/src/main.cpp b/src/main.cpp index 25a8a6c9..a4a759d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,6 +85,11 @@ void OnBleDisconnection() { bleController.Disconnect(); } +void OnNewNotification(const char* message, uint8_t size) { + bleController.PushNotification(message, size); + systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); +} + void OnNewTime(current_time_char_t* currentTime) { auto dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week; auto year = currentTime->exact_time_256.day_date_time.date_time.year; @@ -96,6 +101,8 @@ void OnNewTime(current_time_char_t* currentTime) { dateTimeController.SetTime(year, month, day, dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG)); + + systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewTime); } void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { @@ -128,6 +135,7 @@ int main(void) { ble_manager_set_new_time_callback(OnNewTime); ble_manager_set_ble_connection_callback(OnBleConnection); ble_manager_set_ble_disconnection_callback(OnBleDisconnection); + ble_manager_set_new_notification_callback(OnNewNotification); vTaskStartScheduler(); diff --git a/src/sdk_config.h b/src/sdk_config.h index 0d9b2744..5bff52ee 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -1322,7 +1322,15 @@ #ifndef BLE_ANS_C_ENABLED -#define BLE_ANS_C_ENABLED 0 +#define BLE_ANS_C_ENABLED 1 +#endif + +#ifndef BLE_ANS_C_LOG_ENABLED +#define BLE_ANS_C_LOG_ENABLED 1 +#endif + +#ifndef BLE_ANS_C_LOG_LEVEL +#define BLE_ANS_C_LOG_LEVEL 4 #endif // BLE_BAS_C_ENABLED - ble_bas_c - Battery Service Client @@ -8532,7 +8540,7 @@ // <4=> Debug #ifndef NRF_LOG_DEFAULT_LEVEL -#define NRF_LOG_DEFAULT_LEVEL 3 +#define NRF_LOG_DEFAULT_LEVEL 4 #endif // NRF_LOG_DEFERRED - Enable deffered logger. -- cgit v1.2.3 From baca0fc3e59e88420d6c7983ad133fe63c794ec0 Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 28 Mar 2020 19:05:28 +0100 Subject: Encapsulate Notification management in NotificationManager. It implement a static array of notifications to avoid dynamic allocation. --- src/CMakeLists.txt | 2 ++ src/Components/Ble/BleController.cpp | 24 ----------------- src/Components/Ble/BleController.h | 11 +------- src/Components/Ble/NotificationManager.cpp | 29 +++++++++++++++++++++ src/Components/Ble/NotificationManager.h | 29 +++++++++++++++++++++ src/DisplayApp/DisplayApp.cpp | 25 ++++++++---------- src/DisplayApp/DisplayApp.h | 16 +++++------- src/DisplayApp/Screens/Modal.cpp | 41 ++---------------------------- src/DisplayApp/Screens/Modal.h | 4 +-- src/DisplayApp/Screens/Tile.cpp | 4 ++- src/SystemTask/SystemTask.cpp | 15 ++++++----- src/SystemTask/SystemTask.h | 13 +++++----- src/main.cpp | 8 ++++-- 13 files changed, 105 insertions(+), 116 deletions(-) create mode 100644 src/Components/Ble/NotificationManager.cpp create mode 100644 src/Components/Ble/NotificationManager.h (limited to 'src/Components') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c521b33..e92e3998 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -223,6 +223,7 @@ list(APPEND SOURCE_FILES BLE/BleManager.c Components/Battery/BatteryController.cpp Components/Ble/BleController.cpp + Components/Ble/NotificationManager.cpp Components/DateTime/DateTimeController.cpp Components/Brightness/BrightnessController.cpp drivers/Cst816s.cpp @@ -264,6 +265,7 @@ set(INCLUDE_FILES BLE/BleManager.h Components/Battery/BatteryController.h Components/Ble/BleController.h + Components/Ble/NotificationManager.h Components/DateTime/DateTimeController.h Components/Brightness/BrightnessController.h drivers/Cst816s.h diff --git a/src/Components/Ble/BleController.cpp b/src/Components/Ble/BleController.cpp index fd405896..5fa51688 100644 --- a/src/Components/Ble/BleController.cpp +++ b/src/Components/Ble/BleController.cpp @@ -4,10 +4,6 @@ using namespace Pinetime::Controllers; -Ble::Ble() { - notificationQueue = xQueueCreate(10, sizeof(NotificationMessage)); -} - void Ble::Connect() { isConnected = true; } @@ -16,24 +12,4 @@ void Ble::Disconnect() { isConnected = false; } -void Ble::PushNotification(const char *message, uint8_t size) { - char* messageCopy = static_cast(malloc(sizeof(char) * size)); - std::memcpy(messageCopy, message, size); - NotificationMessage msg; - msg.size = size; - msg.message = messageCopy; - - BaseType_t xHigherPriorityTaskWoken; - xHigherPriorityTaskWoken = pdFALSE; - xQueueSendFromISR(notificationQueue, &msg, &xHigherPriorityTaskWoken); - if (xHigherPriorityTaskWoken) { - /* Actual macro used here is port specific. */ - // TODO : should I do something here? - } -} - -bool Ble::PopNotification(Ble::NotificationMessage& msg) { - return xQueueReceive(notificationQueue, &msg, 0) != 0; -} - diff --git a/src/Components/Ble/BleController.h b/src/Components/Ble/BleController.h index 4f037fc1..31d66986 100644 --- a/src/Components/Ble/BleController.h +++ b/src/Components/Ble/BleController.h @@ -7,22 +7,13 @@ namespace Pinetime { namespace Controllers { class Ble { public: - struct NotificationMessage { - uint8_t size = 0; - const char* message = nullptr; - }; - Ble(); + Ble() = default; bool IsConnected() const {return isConnected;} void Connect(); void Disconnect(); - - void PushNotification(const char* message, uint8_t size); - bool PopNotification(NotificationMessage& msg); - private: bool isConnected = false; - QueueHandle_t notificationQueue; }; } diff --git a/src/Components/Ble/NotificationManager.cpp b/src/Components/Ble/NotificationManager.cpp new file mode 100644 index 00000000..2e02cb15 --- /dev/null +++ b/src/Components/Ble/NotificationManager.cpp @@ -0,0 +1,29 @@ +#include +#include "NotificationManager.h" + +using namespace Pinetime::Controllers; + +void NotificationManager::Push(Pinetime::Controllers::NotificationManager::Categories category, + const char *message, uint8_t messageSize) { + // TODO handle edge cases on read/write index + auto& notif = notifications[writeIndex]; + std::memcpy(notif.message.data(), message, messageSize); + notif.message[messageSize] = '\0'; + notif.category = category; + + writeIndex = (writeIndex + 1 < TotalNbNotifications) ? writeIndex + 1 : 0; + if(!empty && writeIndex == readIndex) + readIndex = writeIndex + 1; +} + +NotificationManager::Notification Pinetime::Controllers::NotificationManager::Pop() { +// TODO handle edge cases on read/write index + NotificationManager::Notification notification = notifications[readIndex]; + + if(readIndex != writeIndex) { + readIndex = (readIndex + 1 < TotalNbNotifications) ? readIndex + 1 : 0; + } + + // TODO Check move optimization on return + return notification; +} diff --git a/src/Components/Ble/NotificationManager.h b/src/Components/Ble/NotificationManager.h new file mode 100644 index 00000000..8edd6828 --- /dev/null +++ b/src/Components/Ble/NotificationManager.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace Pinetime { + namespace Controllers { + class NotificationManager { + public: + enum class Categories {Unknown, SimpleAlert, Email, News, IncomingCall, MissedCall, Sms, VoiceMail, Schedule, HighProriotyAlert, InstantMessage }; + static constexpr uint8_t MessageSize = 18; + + struct Notification { + std::array message; + Categories category = Categories::Unknown; + }; + + void Push(Categories category, const char* message, uint8_t messageSize); + Notification Pop(); + + + private: + static constexpr uint8_t TotalNbNotifications = 5; + std::array notifications; + uint8_t readIndex = 0; + uint8_t writeIndex = 0; + bool empty = true; + }; + } +} \ No newline at end of file diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 2e07cbc5..1b4515e0 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -15,18 +15,16 @@ #include #include #include +#include #include "../SystemTask/SystemTask.h" using namespace Pinetime::Applications; -DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd, - Pinetime::Components::LittleVgl& lvgl, - Pinetime::Drivers::Cst816S& touchPanel, - Controllers::Battery &batteryController, - Controllers::Ble &bleController, - Controllers::DateTime &dateTimeController, - Pinetime::Drivers::WatchdogView& watchdog, - Pinetime::System::SystemTask& systemTask) : +DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Drivers::Cst816S &touchPanel, + Controllers::Battery &batteryController, Controllers::Ble &bleController, + Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog, + System::SystemTask &systemTask, + Pinetime::Controllers::NotificationManager& notificationManager) : lcd{lcd}, lvgl{lvgl}, batteryController{batteryController}, @@ -35,7 +33,8 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd, watchdog{watchdog}, touchPanel{touchPanel}, currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController) }, - systemTask{systemTask} { + systemTask{systemTask}, + notificationManager{notificationManager} { msgQueue = xQueueCreate(queueSize, itemSize); onClockApp = true; modal.reset(new Screens::Modal(this)); @@ -113,12 +112,8 @@ void DisplayApp::Refresh() { // clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining()); break; case Messages::NewNotification: { - Pinetime::Controllers::Ble::NotificationMessage notificationMessage; - if (bleController.PopNotification(notificationMessage)) { - std::string m {notificationMessage.message, notificationMessage.size}; - modal->Show(m); - // TODO delete message - } + auto notification = notificationManager.Pop(); + modal->Show(notification.message.data()); } break; case Messages::TouchEvent: { diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index ad817331..09f0d1cd 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "TouchEvents.h" @@ -34,14 +35,11 @@ namespace Pinetime { enum class FullRefreshDirections { None, Up, Down }; - DisplayApp(Pinetime::Drivers::St7789& lcd, - Pinetime::Components::LittleVgl& lvgl, - Pinetime::Drivers::Cst816S&, - Controllers::Battery &batteryController, - Controllers::Ble &bleController, - Controllers::DateTime& dateTimeController, - Pinetime::Drivers::WatchdogView& watchdog, - Pinetime::System::SystemTask& systemTask); + DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Drivers::Cst816S &, + Controllers::Battery &batteryController, Controllers::Ble &bleController, + Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog, + System::SystemTask &systemTask, + Pinetime::Controllers::NotificationManager& notificationManager); void Start(); void PushMessage(Messages msg); @@ -82,7 +80,7 @@ namespace Pinetime { bool onClockApp = false; // TODO find a better way to know that we should handle gestures and button differently for the Clock app. Controllers::BrightnessController brightnessController; std::unique_ptr modal; - + Pinetime::Controllers::NotificationManager& notificationManager; }; } } diff --git a/src/DisplayApp/Screens/Modal.cpp b/src/DisplayApp/Screens/Modal.cpp index ec477b6e..63ae70c0 100644 --- a/src/DisplayApp/Screens/Modal.cpp +++ b/src/DisplayApp/Screens/Modal.cpp @@ -25,42 +25,6 @@ bool Modal::OnButtonPushed() { return true; } -void Modal::Show() { - if(isVisible) return; - isVisible = true; - lv_style_copy(&modal_style, &lv_style_plain_color); - modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK; - modal_style.body.opa = LV_OPA_50; - - obj = lv_obj_create(lv_scr_act(), NULL); - lv_obj_set_style(obj, &modal_style); - lv_obj_set_pos(obj, 0, 0); - lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES); - lv_obj_set_opa_scale_enable(obj, true); /* Enable opacity scaling for the animation */ - - static const char * btns2[] = {"Ok", ""}; - - /* Create the message box as a child of the modal background */ - mbox = lv_mbox_create(obj, NULL); - lv_mbox_add_btns(mbox, btns2); - char versionStr[20]; - sprintf(versionStr, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch()); - lv_mbox_set_text(mbox, versionStr); -// lv_mbox_set_text(mbox, "Hello world!"); - lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_event_cb(mbox, Modal::mbox_event_cb); - - mbox->user_data = this; - - /* Fade the message box in with an animation */ - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_time(&a, 500, 0); - lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER); - lv_anim_set_exec_cb(&a, obj, (lv_anim_exec_xcb_t)lv_obj_set_opa_scale); - lv_anim_create(&a); -} - void Modal::Hide() { /* Delete the parent modal background */ lv_obj_del_async(lv_obj_get_parent(mbox)); @@ -83,9 +47,8 @@ void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) { } } -void Modal::Show(const std::string& message) { +void Modal::Show(const char* msg) { if(isVisible) return; - this->message = message; isVisible = true; lv_style_copy(&modal_style, &lv_style_plain_color); modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK; @@ -102,7 +65,7 @@ void Modal::Show(const std::string& message) { /* Create the message box as a child of the modal background */ mbox = lv_mbox_create(obj, NULL); lv_mbox_add_btns(mbox, btns2); - lv_mbox_set_text(mbox, message.data()); + lv_mbox_set_text(mbox, msg); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_event_cb(mbox, Modal::mbox_event_cb); diff --git a/src/DisplayApp/Screens/Modal.h b/src/DisplayApp/Screens/Modal.h index b13b5c60..b5425906 100644 --- a/src/DisplayApp/Screens/Modal.h +++ b/src/DisplayApp/Screens/Modal.h @@ -22,8 +22,7 @@ namespace Pinetime { Modal(DisplayApp* app); ~Modal() override; - void Show(); - void Show(const std::string& message); + void Show(const char* msg); void Hide(); bool Refresh() override; @@ -39,7 +38,6 @@ namespace Pinetime { lv_obj_t *info; bool running = true; bool isVisible = false; - std::string message; }; } diff --git a/src/DisplayApp/Screens/Tile.cpp b/src/DisplayApp/Screens/Tile.cpp index 7eb1018c..6c225c9d 100644 --- a/src/DisplayApp/Screens/Tile.cpp +++ b/src/DisplayApp/Screens/Tile.cpp @@ -123,7 +123,9 @@ void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) { tile->StartClockApp(); break; case 3: - modal->Show(); + char versionStr[20]; + sprintf(versionStr, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch()); + modal->Show(versionStr); break; case 4: tile->StartSysInfoApp(); diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index 0080c6b6..e65abb61 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -5,17 +5,19 @@ #include #include #include +#include #include "SystemTask.h" #include "../main.h" using namespace Pinetime::System; -SystemTask::SystemTask(Pinetime::Drivers::SpiMaster &spi, Pinetime::Drivers::St7789 &lcd, - Pinetime::Drivers::Cst816S &touchPanel, Pinetime::Components::LittleVgl &lvgl, - Pinetime::Controllers::Battery &batteryController, Pinetime::Controllers::Ble &bleController, - Pinetime::Controllers::DateTime& dateTimeController) : +SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Drivers::Cst816S &touchPanel, + Components::LittleVgl &lvgl, + Controllers::Battery &batteryController, Controllers::Ble &bleController, + Controllers::DateTime &dateTimeController, + Pinetime::Controllers::NotificationManager& notificationManager) : spi{spi}, lcd{lcd}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController}, - watchdog{}, watchdogView{watchdog}{ + watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager} { systemTaksMsgQueue = xQueueCreate(10, 1); } @@ -44,7 +46,8 @@ void SystemTask::Work() { touchPanel.Init(); batteryController.Init(); - displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, dateTimeController, watchdogView, *this)); + displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, + dateTimeController, watchdogView, *this, notificationManager)); displayApp->Start(); batteryController.Update(); diff --git a/src/SystemTask/SystemTask.h b/src/SystemTask/SystemTask.h index b64fda65..a1ba277a 100644 --- a/src/SystemTask/SystemTask.h +++ b/src/SystemTask/SystemTask.h @@ -16,13 +16,11 @@ namespace Pinetime { enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification }; - SystemTask(Pinetime::Drivers::SpiMaster& spi, - Pinetime::Drivers::St7789& lcd, - Pinetime::Drivers::Cst816S& touchPanel, - Pinetime::Components::LittleVgl& lvgl, - Pinetime::Controllers::Battery& batteryController, - Pinetime::Controllers::Ble& bleController, - Pinetime::Controllers::DateTime& dateTimeController); + SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Drivers::Cst816S &touchPanel, + Components::LittleVgl &lvgl, + Controllers::Battery &batteryController, Controllers::Ble &bleController, + Controllers::DateTime &dateTimeController, + Pinetime::Controllers::NotificationManager& manager); void Start(); @@ -45,6 +43,7 @@ namespace Pinetime { bool isSleeping = false; Pinetime::Drivers::Watchdog watchdog; Pinetime::Drivers::WatchdogView watchdogView; + Pinetime::Controllers::NotificationManager& notificationManager; static constexpr uint8_t pinSpiSck = 2; diff --git a/src/main.cpp b/src/main.cpp index a4a759d9..106d19eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #if NRF_LOG_ENABLED #include "Logging/NrfLogger.h" @@ -55,6 +56,8 @@ void ble_manager_set_ble_disconnection_callback(void (*disconnection)()); static constexpr uint8_t pinTouchIrq = 28; std::unique_ptr systemTask; +Pinetime::Controllers::NotificationManager notificationManager; + void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if(pin == pinTouchIrq) { systemTask->OnTouchEvent(); @@ -86,7 +89,7 @@ void OnBleDisconnection() { } void OnNewNotification(const char* message, uint8_t size) { - bleController.PushNotification(message, size); + notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, message, size); systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } @@ -128,7 +131,8 @@ int main(void) { debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback); - systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, touchPanel, lvgl, batteryController, bleController, dateTimeController)); + systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, touchPanel, lvgl, batteryController, bleController, + dateTimeController, notificationManager)); systemTask->Start(); ble_manager_init(); -- cgit v1.2.3