diff options
| -rw-r--r-- | src/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/components/ble/MotionService.cpp | 125 | ||||
| -rw-r--r-- | src/components/ble/MotionService.h | 39 | ||||
| -rw-r--r-- | src/components/ble/NimbleController.cpp | 9 | ||||
| -rw-r--r-- | src/components/ble/NimbleController.h | 5 | ||||
| -rw-r--r-- | src/components/motion/MotionController.cpp | 11 | ||||
| -rw-r--r-- | src/components/motion/MotionController.h | 3 | ||||
| -rw-r--r-- | src/displayapp/Apps.h | 1 | ||||
| -rw-r--r-- | src/displayapp/DisplayApp.cpp | 4 | ||||
| -rw-r--r-- | src/displayapp/screens/ApplicationList.cpp | 26 | ||||
| -rw-r--r-- | src/displayapp/screens/ApplicationList.h | 4 | ||||
| -rw-r--r-- | src/displayapp/screens/Motion.cpp | 61 | ||||
| -rw-r--r-- | src/displayapp/screens/Motion.h | 34 | ||||
| -rw-r--r-- | src/systemtask/SystemTask.cpp | 3 |
14 files changed, 7 insertions, 324 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d8798b..f98beb3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -394,12 +394,10 @@ list(APPEND SOURCE_FILES displayapp/screens/Brightness.cpp displayapp/screens/Label.cpp displayapp/screens/FirmwareUpdate.cpp - displayapp/screens/Motion.cpp displayapp/screens/FirmwareValidation.cpp displayapp/screens/ApplicationList.cpp displayapp/screens/Notifications.cpp displayapp/screens/HeartRate.cpp - displayapp/screens/Motion.cpp displayapp/screens/List.cpp displayapp/screens/Steps.cpp displayapp/screens/Error.cpp @@ -450,7 +448,6 @@ list(APPEND SOURCE_FILES components/ble/ImmediateAlertService.cpp components/ble/ServiceDiscovery.cpp components/ble/HeartRateService.cpp - components/ble/MotionService.cpp components/firmwarevalidator/FirmwareValidator.cpp components/motor/MotorController.cpp components/settings/Settings.cpp @@ -516,7 +513,6 @@ list(APPEND RECOVERY_SOURCE_FILES components/ble/ImmediateAlertService.cpp components/ble/ServiceDiscovery.cpp components/ble/HeartRateService.cpp - components/ble/MotionService.cpp components/firmwarevalidator/FirmwareValidator.cpp components/settings/Settings.cpp components/alarm/AlarmController.cpp @@ -586,7 +582,6 @@ set(INCLUDE_FILES displayapp/Apps.h displayapp/screens/Notifications.h displayapp/screens/HeartRate.h - displayapp/screens/Motion.h displayapp/screens/Alarm.h displayapp/Colors.h drivers/St7789.h @@ -621,7 +616,6 @@ set(INCLUDE_FILES components/ble/ServiceDiscovery.h components/ble/BleClient.h components/ble/HeartRateService.h - components/ble/MotionService.h components/settings/Settings.h components/alarm/AlarmController.h drivers/Cst816s.h diff --git a/src/components/ble/MotionService.cpp b/src/components/ble/MotionService.cpp deleted file mode 100644 index 87923c2..0000000 --- a/src/components/ble/MotionService.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "components/ble/MotionService.h" -#include "components/motion/MotionController.h" -#include "systemtask/SystemTask.h" -#include <nrf_log.h> - -using namespace Pinetime::Controllers; - -namespace { - // 0003yyxx-78fc-48fe-8e23-433b3a1942d0 - constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) { - return ble_uuid128_t{ - .u = {.type = BLE_UUID_TYPE_128}, - .value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00 } - }; - } - - // 00030000-78fc-48fe-8e23-433b3a1942d0 - constexpr ble_uuid128_t BaseUuid() { - return CharUuid(0x00, 0x00); - } - - constexpr ble_uuid128_t motionServiceUuid {BaseUuid()}; - constexpr ble_uuid128_t stepCountCharUuid {CharUuid(0x01, 0x00)}; - constexpr ble_uuid128_t motionValuesCharUuid {CharUuid(0x02, 0x00)}; - - int MotionServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { - auto* motionService = static_cast<MotionService*>(arg); - return motionService->OnStepCountRequested(conn_handle, attr_handle, ctxt); - } -} - -// TODO Refactoring - remove dependency to SystemTask -MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController) - : system {system}, - motionController {motionController}, - characteristicDefinition {{.uuid = &stepCountCharUuid.u, - .access_cb = MotionServiceCallback, - .arg = this, - .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, - .val_handle = &stepCountHandle}, - {.uuid = &motionValuesCharUuid.u, - .access_cb = MotionServiceCallback, - .arg = this, - .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, - .val_handle = &motionValuesHandle}, - {0}}, - serviceDefinition { - { - .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = &motionServiceUuid.u, - .characteristics = characteristicDefinition - }, - {0}, - } { - // TODO refactor to prevent this loop dependency (service depends on controller and controller depends on service) - motionController.SetService(this); -} - -void MotionService::Init() { - int res = 0; - res = ble_gatts_count_cfg(serviceDefinition); - ASSERT(res == 0); - - res = ble_gatts_add_svcs(serviceDefinition); - ASSERT(res == 0); -} - -int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) { - if (attributeHandle == stepCountHandle) { - NRF_LOG_INFO("Motion-stepcount : handle = %d", stepCountHandle); - uint32_t buffer = motionController.NbSteps(); - - int res = os_mbuf_append(context->om, &buffer, 4); - return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } else if(attributeHandle == motionValuesHandle) { - int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() }; - - int res = os_mbuf_append(context->om, buffer, 3 * sizeof(int16_t)); - return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } - return 0; -} - -void MotionService::OnNewStepCountValue(uint32_t stepCount) { - if(!stepCountNoficationEnabled) return; - - uint32_t buffer = stepCount; - auto* om = ble_hs_mbuf_from_flat(&buffer, 4); - - uint16_t connectionHandle = system.nimble().connHandle(); - - if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { - return; - } - - ble_gattc_notify_custom(connectionHandle, stepCountHandle, om); -} -void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) { - if(!motionValuesNoficationEnabled) return; - - int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() }; - auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t)); - - uint16_t connectionHandle = system.nimble().connHandle(); - - if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { - return; - } - - ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om); -} - -void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == stepCountHandle) - stepCountNoficationEnabled = true; - else if(attributeHandle == motionValuesHandle) - motionValuesNoficationEnabled = true; -} - -void MotionService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == stepCountHandle) - stepCountNoficationEnabled = false; - else if(attributeHandle == motionValuesHandle) - motionValuesNoficationEnabled = false; -} diff --git a/src/components/ble/MotionService.h b/src/components/ble/MotionService.h deleted file mode 100644 index 1b4ac0a..0000000 --- a/src/components/ble/MotionService.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#define min // workaround: nimble's min/max macros conflict with libstdc++ -#define max -#include <host/ble_gap.h> -#include <atomic> -#undef max -#undef min - -namespace Pinetime { - namespace System { - class SystemTask; - } - namespace Controllers { - class MotionController; - class MotionService { - public: - MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController); - void Init(); - int OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context); - void OnNewStepCountValue(uint32_t stepCount); - void OnNewMotionValues(int16_t x, int16_t y, int16_t z); - - void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle); - void UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle); - - private: - Pinetime::System::SystemTask& system; - Controllers::MotionController& motionController; - - struct ble_gatt_chr_def characteristicDefinition[3]; - struct ble_gatt_svc_def serviceDefinition[2]; - - uint16_t stepCountHandle; - uint16_t motionValuesHandle; - std::atomic_bool stepCountNoficationEnabled {false}; - std::atomic_bool motionValuesNoficationEnabled {false}; - }; - } -} diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index a5bc41b..bc712f4 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -28,8 +28,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, NotificationManager& notificationManager, Battery& batteryController, Pinetime::Drivers::SpiNorFlash& spiNorFlash, - HeartRateController& heartRateController, - MotionController& motionController) + HeartRateController& heartRateController + ) : systemTask {systemTask}, bleController {bleController}, dateTimeController {dateTimeController}, @@ -44,7 +44,6 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, batteryInformationService {batteryController}, immediateAlertService {systemTask, notificationManager}, heartRateService {systemTask, heartRateController}, - motionService {systemTask, motionController}, serviceDiscovery({¤tTimeClient, &alertNotificationClient}) { } @@ -88,7 +87,6 @@ void NimbleController::Init() { batteryInformationService.Init(); immediateAlertService.Init(); heartRateService.Init(); - motionService.Init(); int rc; rc = ble_hs_util_ensure_addr(0); @@ -248,13 +246,10 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) { if (event->subscribe.reason == BLE_GAP_SUBSCRIBE_REASON_TERM) { heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); - motionService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); } else if (event->subscribe.prev_notify == 0 && event->subscribe.cur_notify == 1) { heartRateService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); - motionService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); } else if (event->subscribe.prev_notify == 1 && event->subscribe.cur_notify == 0) { heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); - motionService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); } break; diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h index 263d498..0facca6 100644 --- a/src/components/ble/NimbleController.h +++ b/src/components/ble/NimbleController.h @@ -17,7 +17,6 @@ #include "components/ble/HeartRateService.h" #include "components/ble/ImmediateAlertService.h" #include "components/ble/ServiceDiscovery.h" -#include "components/ble/MotionService.h" namespace Pinetime { namespace Drivers { @@ -42,8 +41,7 @@ namespace Pinetime { NotificationManager& notificationManager, Battery& batteryController, Pinetime::Drivers::SpiNorFlash& spiNorFlash, - HeartRateController& heartRateController, - MotionController& motionController); + HeartRateController& heartRateController); void Init(); void StartAdvertising(); int OnGAPEvent(ble_gap_event* event); @@ -77,7 +75,6 @@ namespace Pinetime { BatteryInformationService batteryInformationService; ImmediateAlertService immediateAlertService; HeartRateService heartRateService; - MotionService motionService; ServiceDiscovery serviceDiscovery; uint8_t addrType; diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index 7dd3212..4a7a7eb 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -3,14 +3,6 @@ using namespace Pinetime::Controllers; void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) { - if (this->nbSteps != nbSteps && service != nullptr) { - service->OnNewStepCountValue(nbSteps); - } - - if (service != nullptr && (this->x != x || this->y != y || this->z != z)) { - service->OnNewMotionValues(x, y, z); - } - this->x = x; this->y = y; this->z = z; @@ -82,6 +74,3 @@ void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) { break; } } -void MotionController::SetService(Pinetime::Controllers::MotionService* service) { - this->service = service; -} diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index f80b11b..5385658 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -2,7 +2,6 @@ #include <cstdint> #include <drivers/Bma421.h> -#include <components/ble/MotionService.h> namespace Pinetime { namespace Controllers { @@ -49,7 +48,6 @@ namespace Pinetime { } void Init(Pinetime::Drivers::Bma421::DeviceTypes types); - void SetService(Pinetime::Controllers::MotionService* service); private: uint32_t nbSteps; @@ -60,7 +58,6 @@ namespace Pinetime { int16_t lastYForWakeUp = 0; bool isSensorOk = false; DeviceTypes deviceType = DeviceTypes::Unknown; - Pinetime::Controllers::MotionService* service = nullptr; int16_t lastXForShake = 0; int16_t lastYForShake = 0; diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 8d93cf7..adbd386 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -12,7 +12,6 @@ namespace Pinetime { Notifications, Alarm, HeartRate, - Motion, Steps, QuickSettings, Settings, diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index db9d253..5db479c 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -1,7 +1,6 @@ #include "displayapp/DisplayApp.h" #include <libraries/log/nrf_log.h> #include "displayapp/screens/HeartRate.h" -#include "displayapp/screens/Motion.h" #include "displayapp/screens/Alarm.h" #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" @@ -375,9 +374,6 @@ void DisplayApp::LoadApp(Apps app) { case Apps::HeartRate: currentScreen = std::make_unique<Screens::HeartRate>(this, heartRateController, *systemTask); break; - case Apps::Motion: - currentScreen = std::make_unique<Screens::Motion>(this, motionController); - break; case Apps::Steps: currentScreen = std::make_unique<Screens::Steps>(this, motionController, settingsController); break; diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index a34a255..b7498aa 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -21,11 +21,7 @@ ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app, { [this]() -> std::unique_ptr<Screen> { return CreateScreen1(); - }, - [this]() -> std::unique_ptr<Screen> { - return CreateScreen2(); - }, - //[this]() -> std::unique_ptr<Screen> { return CreateScreen3(); } + } }, Screens::ScreenListModes::UpDown} { } @@ -42,27 +38,9 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen1() { std::array<Screens::Tile::Applications, 6> applications {{ {Symbols::shoe, Apps::Steps}, {Symbols::heartBeat, Apps::HeartRate}, - }}; - - return std::make_unique<Screens::Tile>(0, 2, app, settingsController, batteryController, dateTimeController, applications); -} - -std::unique_ptr<Screen> ApplicationList::CreateScreen2() { - std::array<Screens::Tile::Applications, 6> applications {{ - {Symbols::chartLine, Apps::Motion}, {Symbols::clock, Apps::Alarm}, }}; - return std::make_unique<Screens::Tile>(1, 2, app, settingsController, batteryController, dateTimeController, applications); + return std::make_unique<Screens::Tile>(0, 1, app, settingsController, batteryController, dateTimeController, applications); } -/*std::unique_ptr<Screen> ApplicationList::CreateScreen3() { - std::array<Screens::Tile::Applications, 6> applications { - {{"A", Apps::Meter}, - {"C", Apps::Clock}, - {"F", Apps::Brightness} - } - }; - - return std::make_unique<Screens::Tile>(2, 3, app, settingsController, batteryController, dateTimeController, applications); -}*/ diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h index f430a89..9cd8efa 100644 --- a/src/displayapp/screens/ApplicationList.h +++ b/src/displayapp/screens/ApplicationList.h @@ -25,10 +25,8 @@ namespace Pinetime { Pinetime::Controllers::Battery& batteryController; Controllers::DateTime& dateTimeController; - ScreenList<2> screens; + ScreenList<1> screens; std::unique_ptr<Screen> CreateScreen1(); - std::unique_ptr<Screen> CreateScreen2(); - // std::unique_ptr<Screen> CreateScreen3(); }; } } diff --git a/src/displayapp/screens/Motion.cpp b/src/displayapp/screens/Motion.cpp deleted file mode 100644 index 23eb276..0000000 --- a/src/displayapp/screens/Motion.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "displayapp/screens/Motion.h" -#include <lvgl/lvgl.h> -#include "displayapp/DisplayApp.h" - -using namespace Pinetime::Applications::Screens; - -Motion::Motion(Pinetime::Applications::DisplayApp* app, Controllers::MotionController& motionController) - : Screen(app), motionController {motionController} { - chart = lv_chart_create(lv_scr_act(), NULL); - lv_obj_set_size(chart, 240, 240); - lv_obj_align(chart, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); - lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/ - // lv_chart_set_series_opa(chart, LV_OPA_70); /*Opacity of the data series*/ - // lv_chart_set_series_width(chart, 4); /*Line width and point radious*/ - - lv_chart_set_range(chart, -1100, 1100); - lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT); - lv_chart_set_point_count(chart, 10); - - /*Add 3 data series*/ - ser1 = lv_chart_add_series(chart, LV_COLOR_RED); - ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN); - ser3 = lv_chart_add_series(chart, LV_COLOR_YELLOW); - - lv_chart_init_points(chart, ser1, 0); - lv_chart_init_points(chart, ser2, 0); - lv_chart_init_points(chart, ser3, 0); - lv_chart_refresh(chart); /*Required after direct set*/ - - label = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text_fmt(label, "X #FF0000 %d# Y #008000 %d# Z #FFFF00 %d#", 0, 0, 0); - lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); - lv_label_set_recolor(label, true); - - labelStep = lv_label_create(lv_scr_act(), NULL); - lv_obj_align(labelStep, chart, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); - lv_label_set_text(labelStep, "Steps ---"); - - taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); -} - -Motion::~Motion() { - lv_task_del(taskRefresh); - lv_obj_clean(lv_scr_act()); -} - -void Motion::Refresh() { - lv_chart_set_next(chart, ser1, motionController.X()); - lv_chart_set_next(chart, ser2, motionController.Y()); - lv_chart_set_next(chart, ser3, motionController.Z()); - - lv_label_set_text_fmt(labelStep, "Steps %lu", motionController.NbSteps()); - - lv_label_set_text_fmt(label, - "X #FF0000 %d# Y #008000 %d# Z #FFFF00 %d#", - motionController.X() / 0x10, - motionController.Y() / 0x10, - motionController.Z() / 0x10); - lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); -} diff --git a/src/displayapp/screens/Motion.h b/src/displayapp/screens/Motion.h deleted file mode 100644 index 4d2bd4f..0000000 --- a/src/displayapp/screens/Motion.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include <cstdint> -#include <chrono> -#include "displayapp/screens/Screen.h" -#include <lvgl/src/lv_core/lv_style.h> -#include <lvgl/src/lv_core/lv_obj.h> -#include <components/motion/MotionController.h> - -namespace Pinetime { - namespace Applications { - namespace Screens { - - class Motion : public Screen { - public: - Motion(DisplayApp* app, Controllers::MotionController& motionController); - ~Motion() override; - - void Refresh() override; - - private: - Controllers::MotionController& motionController; - lv_obj_t* chart; - lv_chart_series_t* ser1; - lv_chart_series_t* ser2; - lv_chart_series_t* ser3; - lv_obj_t* label; - - lv_obj_t* labelStep; - lv_task_t* taskRefresh; - }; - } - } -} diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 92a19e4..b1b72e2 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -96,8 +96,7 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, notificationManager, batteryController, spiNorFlash, - heartRateController, - motionController) { + heartRateController) { } void SystemTask::Start() { |
