From e20fdfa494ed8b1b6a62b71ca605a6a801e54e4e Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 2 May 2020 14:16:57 +0200 Subject: Add new screen that is displayed during the OTA transfert. --- src/Components/Ble/BleController.cpp | 16 ++++++++++++++++ src/Components/Ble/BleController.h | 12 ++++++++++++ src/Components/Ble/DfuService.cpp | 13 ++++++++++++- src/Components/Ble/DfuService.h | 9 ++++++++- src/Components/Ble/NimbleController.cpp | 1 + src/Components/Ble/NimbleController.h | 2 +- 6 files changed, 50 insertions(+), 3 deletions(-) (limited to 'src/Components') diff --git a/src/Components/Ble/BleController.cpp b/src/Components/Ble/BleController.cpp index 5fa51688..2b396e12 100644 --- a/src/Components/Ble/BleController.cpp +++ b/src/Components/Ble/BleController.cpp @@ -12,4 +12,20 @@ void Ble::Disconnect() { isConnected = false; } +void Ble::StartFirmwareUpdate() { + isFirmwareUpdating = true; +} + +void Ble::StopFirmwareUpdate() { + isFirmwareUpdating = false; +} + +void Ble::FirmwareUpdateTotalBytes(uint32_t totalBytes) { + firmwareUpdateTotalBytes = totalBytes; +} + +void Ble::FirmwareUpdateCurrentBytes(uint32_t currentBytes) { + firmwareUpdateCurrentBytes = currentBytes; +} + diff --git a/src/Components/Ble/BleController.h b/src/Components/Ble/BleController.h index f2bd77e0..65a5ef8f 100644 --- a/src/Components/Ble/BleController.h +++ b/src/Components/Ble/BleController.h @@ -12,8 +12,20 @@ namespace Pinetime { bool IsConnected() const {return isConnected;} void Connect(); void Disconnect(); + + void StartFirmwareUpdate(); + void StopFirmwareUpdate(); + void FirmwareUpdateTotalBytes(uint32_t totalBytes); + void FirmwareUpdateCurrentBytes(uint32_t currentBytes); + + bool IsFirmwareUpdating() const { return isFirmwareUpdating; } + uint32_t FirmwareUpdateTotalBytes() const { return firmwareUpdateTotalBytes; } + uint32_t FirmwareUpdateCurrentBytes() const { return firmwareUpdateCurrentBytes; } private: bool isConnected = false; + bool isFirmwareUpdating = false; + uint32_t firmwareUpdateTotalBytes = 0; + uint32_t firmwareUpdateCurrentBytes = 0; }; } diff --git a/src/Components/Ble/DfuService.cpp b/src/Components/Ble/DfuService.cpp index bc96dd9b..2870d7f0 100644 --- a/src/Components/Ble/DfuService.cpp +++ b/src/Components/Ble/DfuService.cpp @@ -1,3 +1,5 @@ +#include +#include #include "DfuService.h" using namespace Pinetime::Controllers; @@ -13,7 +15,9 @@ int DfuServiceCallback(uint16_t conn_handle, uint16_t attr_handle, return dfuService->OnServiceData(conn_handle, attr_handle, ctxt); } -DfuService::DfuService() : +DfuService::DfuService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController) : + systemTask{systemTask}, + bleController{bleController}, characteristicDefinition{ { .uuid = (ble_uuid_t *) &packetCharacteristicUuid, @@ -102,6 +106,7 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf *om) { case States::Data: { nbPacketReceived++; bytesReceived += om->om_len; + bleController.FirmwareUpdateCurrentBytes(bytesReceived); NRF_LOG_INFO("[DFU] -> Bytes received : %d in %d packets", bytesReceived, nbPacketReceived); if((nbPacketReceived % nbPacketsToNotify) == 0) { @@ -139,6 +144,10 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf *om) { if(imageType == ImageTypes::Application) { NRF_LOG_INFO("[DFU] -> Start DFU, mode = Application"); state = States::Start; + bleController.StartFirmwareUpdate(); + bleController.FirmwareUpdateTotalBytes(175280); + bleController.FirmwareUpdateCurrentBytes(0); + systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateStarted); return 0; } else { NRF_LOG_INFO("[DFU] -> Start DFU, mode %d not supported!", imageType); @@ -194,6 +203,8 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf *om) { return 0; } NRF_LOG_INFO("[DFU] -> Activate image and reset!"); + bleController.StopFirmwareUpdate(); + systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateFinished); return 0; default: return 0; } diff --git a/src/Components/Ble/DfuService.h b/src/Components/Ble/DfuService.h index 1b13c00d..7077bf02 100644 --- a/src/Components/Ble/DfuService.h +++ b/src/Components/Ble/DfuService.h @@ -5,14 +5,21 @@ #include namespace Pinetime { + namespace System { + class SystemTask; + } namespace Controllers { + class Ble; class DfuService { public: - DfuService(); + DfuService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController); void Init(); int OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context); private: + Pinetime::System::SystemTask& systemTask; + Pinetime::Controllers::Ble& bleController; + static constexpr uint16_t dfuServiceId {0x1530}; static constexpr uint16_t packetCharacteristicId {0x1532}; static constexpr uint16_t controlPointCharacteristicId {0x1531}; diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp index f3d271ec..f16d8af0 100644 --- a/src/Components/Ble/NimbleController.cpp +++ b/src/Components/Ble/NimbleController.cpp @@ -29,6 +29,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, bleController{bleController}, dateTimeController{dateTimeController}, notificationManager{notificationManager}, + dfuService{systemTask, bleController}, currentTimeClient{dateTimeController}, alertNotificationClient{systemTask, notificationManager} { diff --git a/src/Components/Ble/NimbleController.h b/src/Components/Ble/NimbleController.h index 945d3329..c4922bae 100644 --- a/src/Components/Ble/NimbleController.h +++ b/src/Components/Ble/NimbleController.h @@ -34,7 +34,7 @@ namespace Pinetime { Pinetime::Controllers::Ble& bleController; DateTime& dateTimeController; Pinetime::Controllers::NotificationManager& notificationManager; - DfuService dfuService; + Pinetime::Controllers::DfuService dfuService; DeviceInformationService deviceInformationService; CurrentTimeClient currentTimeClient; -- cgit v1.2.3-70-g09d2