From 46eeefb53a1843908c3e7dbae56dbaa0a6d83bdd Mon Sep 17 00:00:00 2001 From: JF Date: Fri, 27 Dec 2019 17:05:49 +0100 Subject: [PATCH] Add BleController to manage the BLE connection status --- README.md | 1 - src/CMakeLists.txt | 2 ++ src/Components/Ble/BleController.cpp | 11 +++++++++++ src/Components/Ble/BleController.h | 15 +++++++++++++++ src/DisplayApp/DisplayApp.cpp | 15 ++++++++++++--- src/DisplayApp/DisplayApp.h | 5 ++++- src/main.cpp | 5 ++++- 7 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 src/Components/Ble/BleController.cpp create mode 100644 src/Components/Ble/BleController.h diff --git a/README.md b/README.md index b1806851..70580715 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ I've tested this project on the actual PineTime hardware. * BLE advertising, connection and bonding * BLE CTS client (retrieves the time from the connected device if it implements a CTS server) * Push button to go to disable screen (and go to low power mode) / enable screen (and wake-up). **NOTE** : I'm not completely sure the power consumption is optimal, especially in sleep mode. Any help to measure and debug this is welcome. - ## How to build diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b845fedd..a30bd19a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ list(APPEND SOURCE_FILES Components/Gfx/Gfx.cpp BLE/BleManager.c Components/Battery/BatteryController.cpp + Components/Ble/BleController.cpp ) set(INCLUDE_FILES @@ -53,6 +54,7 @@ set(INCLUDE_FILES Components/Gfx/Gfx.h BLE/BleManager.h Components/Battery/BatteryController.h + Components/Ble/BleController.h ) nRF5x_addExecutable(pinetime-app "${SOURCE_FILES}") \ No newline at end of file diff --git a/src/Components/Ble/BleController.cpp b/src/Components/Ble/BleController.cpp new file mode 100644 index 00000000..c2458087 --- /dev/null +++ b/src/Components/Ble/BleController.cpp @@ -0,0 +1,11 @@ +#include "BleController.h" + +using namespace Pinetime::Controllers; + +void Ble::Connect() { + isConnected = true; +} + +void Ble::Disconnect() { + isConnected = false; +} diff --git a/src/Components/Ble/BleController.h b/src/Components/Ble/BleController.h new file mode 100644 index 00000000..be491ee9 --- /dev/null +++ b/src/Components/Ble/BleController.h @@ -0,0 +1,15 @@ +#pragma once + +namespace Pinetime { + namespace Controllers { + class Ble { + public: + bool IsConnected() const {return isConnected;} + void Connect(); + void Disconnect(); + + private: + bool isConnected = false; + }; + } +} \ No newline at end of file diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 10153930..f72f057b 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -10,7 +10,9 @@ using namespace Pinetime::Applications; -DisplayApp::DisplayApp(Pinetime::Controllers::Battery &batteryController) : batteryController{batteryController} { +DisplayApp::DisplayApp(Pinetime::Controllers::Battery &batteryController, Pinetime::Controllers::Ble &bleController) : + batteryController{batteryController}, + bleController{bleController} { msgQueue = xQueueCreate(queueSize, itemSize); } @@ -66,8 +68,8 @@ void DisplayApp::InitHw() { x = 181; gfx->DrawChar(&largeFont, '0', &x, 78, 0xffff); - gfx->DrawString(10, 0, 0xffff, "BLE", &smallFont, false); - gfx->DrawString(20, 160, 0xffff, "FRIDAY 27 DEC 2019", &smallFont, false); + gfx->DrawString(10, 0, 0x0000, "BLE", &smallFont, false); + gfx->DrawString(20, 180, 0xffff, "FRIDAY 27 DEC 2019", &smallFont, false); } void DisplayApp::Refresh() { @@ -133,6 +135,13 @@ void DisplayApp::RunningState() { gfx->DrawString((240-108), 0, 0xffff, batteryChar, &smallFont, false); } + bool newIsBleConnected = bleController.IsConnected(); + if(newIsBleConnected != bleConnected) { + bleConnected = newIsBleConnected; + uint16_t color = (bleConnected) ? 0xffff : 0x0000; + gfx->DrawString(10, 0, color, "BLE", &smallFont, false); + } + auto raw = systick_counter / 1000; auto currentDeltaSeconds = raw - deltaSeconds; diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 4605cf1c..3bc9f468 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "lcdfont14.h" extern const FONT_INFO lCD_70ptFontInfo; @@ -17,7 +18,7 @@ namespace Pinetime { public: enum class States {Idle, Running}; enum class Messages : uint8_t {GoToSleep, GoToRunning} ; - DisplayApp(Pinetime::Controllers::Battery& batteryController); + DisplayApp(Pinetime::Controllers::Battery& batteryController, Pinetime::Controllers::Ble& bleController); void Start(); void Minutes(uint8_t m); @@ -53,7 +54,9 @@ namespace Pinetime { static constexpr uint8_t itemSize = 1; Pinetime::Controllers::Battery &batteryController; + Pinetime::Controllers::Ble &bleController; uint16_t battery = 0; + bool bleConnected = false; }; } diff --git a/src/main.cpp b/src/main.cpp index b883ce02..396935b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include #include "BLE/BleManager.h" #include "Components/Battery/BatteryController.h" +#include "Components/Ble/BleController.h" #if NRF_LOG_ENABLED #include "Logging/NrfLogger.h" @@ -26,6 +27,7 @@ TaskHandle_t systemThread; bool isSleeping = false; TimerHandle_t debounceTimer; Pinetime::Controllers::Battery batteryController; +Pinetime::Controllers::Ble bleController; extern "C" { void vApplicationIdleHook() { @@ -85,11 +87,12 @@ void SystemTask(void *) { } void OnNewTime(uint8_t minutes, uint8_t hours) { + bleController.Connect(); displayApp->SetTime(minutes, hours); } int main(void) { - displayApp.reset(new Pinetime::Applications::DisplayApp(batteryController)); + displayApp.reset(new Pinetime::Applications::DisplayApp(batteryController, bleController)); logger.Init(); nrf_drv_clock_init();