diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-06-06 18:27:54 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-06-06 23:09:58 (GMT) |
| commit | 7c45f185a32c7bcff47c8fda1acdec82d3213717 (patch) | |
| tree | 53b0419fe2a19e6ec5c89d0be0a11dcd8d4ceb00 /src/components | |
| parent | 94b1b330fc1f6e941a797fedabade4e790e28bc2 (diff) | |
| parent | 35dcf8c8607483c104711c9398d47d57147f4389 (diff) | |
Merge remote-tracking branch 'origin/develop' into analog24
Diffstat (limited to 'src/components')
24 files changed, 177 insertions, 170 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index 5432e75..596bcaf 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -17,7 +17,6 @@ */ #include "components/alarm/AlarmController.h" #include "systemtask/SystemTask.h" -#include "app_timer.h" #include "task.h" #include <chrono> @@ -36,7 +35,7 @@ namespace { void AlarmController::Init(System::SystemTask* systemTask) { this->systemTask = systemTask; - alarmAppTimer = xTimerCreate("alarmAppTm", 1, pdFALSE, this, SetOffAlarm); + alarmTimer = xTimerCreate("Alarm", 1, pdFALSE, this, SetOffAlarm); } void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) { @@ -65,11 +64,11 @@ void AlarmController::OnAdjustTime() { void AlarmController::ScheduleAlarm() { // Determine the next time the alarm needs to go off and set the timer - xTimerStop(alarmAppTimer, 0); + xTimerStop(alarmTimer, 0); auto now = dateTimeController.CurrentDateTime(); alarmTime = now; - time_t ttAlarmTime = std::chrono::system_clock::to_time_t(alarmTime); + time_t ttAlarmTime = std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(alarmTime)); tm* tmAlarmTime = std::localtime(&ttAlarmTime); // If the time being set has already passed today,the alarm should be set for tomorrow @@ -95,9 +94,9 @@ void AlarmController::ScheduleAlarm() { // now can convert back to a time_point alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime)); - auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count(); - xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0); - xTimerStart(alarmAppTimer, 0); + auto secondsToAlarm = std::chrono::duration_cast<std::chrono::seconds>(alarmTime - now).count(); + xTimerChangePeriod(alarmTimer, secondsToAlarm * configTICK_RATE_HZ, 0); + xTimerStart(alarmTimer, 0); state = AlarmState::Set; } @@ -107,7 +106,7 @@ uint32_t AlarmController::SecondsToAlarm() { } void AlarmController::DisableAlarm() { - xTimerStop(alarmAppTimer, 0); + xTimerStop(alarmTimer, 0); state = AlarmState::Not_Set; } @@ -117,20 +116,12 @@ void AlarmController::SetOffAlarmNow() { } void AlarmController::StopAlerting() { - systemTask->PushMessage(System::Messages::StopRinging); -} - -void AlarmController::OnStopRinging() { - if (state != AlarmState::Alerting) { - return; - } - // Alarm state is off unless this is a recurring alarm if (recurrence == RecurType::None) { state = AlarmState::Not_Set; } else { - state = AlarmState::Set; // set next instance ScheduleAlarm(); } + systemTask->PushMessage(System::Messages::StopRinging); } diff --git a/src/components/alarm/AlarmController.h b/src/components/alarm/AlarmController.h index 6ad220f..c3a9fec 100644 --- a/src/components/alarm/AlarmController.h +++ b/src/components/alarm/AlarmController.h @@ -59,12 +59,11 @@ namespace Pinetime { protected: friend class Pinetime::System::SystemTask; void Init(System::SystemTask* systemTask); - void OnStopRinging(); private: Controllers::DateTime& dateTimeController; System::SystemTask* systemTask = nullptr; - TimerHandle_t alarmAppTimer; + TimerHandle_t alarmTimer; uint8_t hours = 7; uint8_t minutes = 0; std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime; diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp index 335845e..095fdef 100644 --- a/src/components/ble/AlertNotificationClient.cpp +++ b/src/components/ble/AlertNotificationClient.cpp @@ -26,8 +26,11 @@ namespace { return client->OnCharacteristicsDiscoveryEvent(conn_handle, error, chr); } - int OnAlertNotificationDescriptorDiscoveryEventCallback( - uint16_t conn_handle, const struct ble_gatt_error* error, uint16_t chr_val_handle, const struct ble_gatt_dsc* dsc, void* arg) { + int OnAlertNotificationDescriptorDiscoveryEventCallback(uint16_t conn_handle, + const struct ble_gatt_error* error, + uint16_t chr_val_handle, + const struct ble_gatt_dsc* dsc, + void* arg) { auto client = static_cast<AlertNotificationClient*>(arg); return client->OnDescriptorDiscoveryEventCallback(conn_handle, error, chr_val_handle, dsc); } diff --git a/src/components/ble/BatteryInformationService.h b/src/components/ble/BatteryInformationService.h index 1303fd6..c6fc52e 100644 --- a/src/components/ble/BatteryInformationService.h +++ b/src/components/ble/BatteryInformationService.h @@ -18,6 +18,7 @@ namespace Pinetime { int OnBatteryServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context); void NotifyBatteryLevel(uint16_t connectionHandle, uint8_t level); + private: Controllers::Battery& batteryController; static constexpr uint16_t batteryInformationServiceId {0x180F}; diff --git a/src/components/ble/CurrentTimeClient.cpp b/src/components/ble/CurrentTimeClient.cpp index dd8171b..53e98cb 100644 --- a/src/components/ble/CurrentTimeClient.cpp +++ b/src/components/ble/CurrentTimeClient.cpp @@ -85,10 +85,21 @@ int CurrentTimeClient::OnCurrentTimeReadResult(uint16_t conn_handle, const ble_g // TODO check that attribute->handle equals the handle discovered in OnCharacteristicDiscoveryEvent CtsData result; os_mbuf_copydata(attribute->om, 0, sizeof(CtsData), &result); - NRF_LOG_INFO( - "Received data: %d-%d-%d %d:%d:%d", result.year, result.month, result.dayofmonth, result.hour, result.minute, result.second); - dateTimeController.SetTime( - result.year, result.month, result.dayofmonth, 0, result.hour, result.minute, result.second, nrf_rtc_counter_get(portNRF_RTC_REG)); + NRF_LOG_INFO("Received data: %d-%d-%d %d:%d:%d", + result.year, + result.month, + result.dayofmonth, + result.hour, + result.minute, + result.second); + dateTimeController.SetTime(result.year, + result.month, + result.dayofmonth, + 0, + result.hour, + result.minute, + result.second, + nrf_rtc_counter_get(portNRF_RTC_REG)); } else { NRF_LOG_INFO("Error retrieving current time: %d", error->status); } diff --git a/src/components/ble/CurrentTimeService.cpp b/src/components/ble/CurrentTimeService.cpp index e509aea..8430d1b 100644 --- a/src/components/ble/CurrentTimeService.cpp +++ b/src/components/ble/CurrentTimeService.cpp @@ -29,11 +29,22 @@ int CurrentTimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handl CtsData result; os_mbuf_copydata(ctxt->om, 0, sizeof(CtsData), &result); - NRF_LOG_INFO( - "Received data: %d-%d-%d %d:%d:%d", result.year, result.month, result.dayofmonth, result.hour, result.minute, result.second); + NRF_LOG_INFO("Received data: %d-%d-%d %d:%d:%d", + result.year, + result.month, + result.dayofmonth, + result.hour, + result.minute, + result.second); - m_dateTimeController.SetTime( - result.year, result.month, result.dayofmonth, 0, result.hour, result.minute, result.second, nrf_rtc_counter_get(portNRF_RTC_REG)); + m_dateTimeController.SetTime(result.year, + result.month, + result.dayofmonth, + 0, + result.hour, + result.minute, + result.second, + nrf_rtc_counter_get(portNRF_RTC_REG)); } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) { CtsData currentDateTime; diff --git a/src/components/ble/DfuService.cpp b/src/components/ble/DfuService.cpp index cf99f01..1f06b69 100644 --- a/src/components/ble/DfuService.cpp +++ b/src/components/ble/DfuService.cpp @@ -119,8 +119,10 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) { bootloaderSize = om->om_data[4] + (om->om_data[5] << 8) + (om->om_data[6] << 16) + (om->om_data[7] << 24); applicationSize = om->om_data[8] + (om->om_data[9] << 8) + (om->om_data[10] << 16) + (om->om_data[11] << 24); bleController.FirmwareUpdateTotalBytes(applicationSize); - NRF_LOG_INFO( - "[DFU] -> Start data received : SD size : %d, BT size : %d, app size : %d", softdeviceSize, bootloaderSize, applicationSize); + NRF_LOG_INFO("[DFU] -> Start data received : SD size : %d, BT size : %d, app size : %d", + softdeviceSize, + bootloaderSize, + applicationSize); // wait until SystemTask has finished waking up all devices while (systemTask.IsSleeping()) { @@ -165,10 +167,10 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) { if ((nbPacketReceived % nbPacketsToNotify) == 0 && bytesReceived != applicationSize) { uint8_t data[5] {static_cast<uint8_t>(Opcodes::PacketReceiptNotification), - (uint8_t)(bytesReceived & 0x000000FFu), - (uint8_t)(bytesReceived >> 8u), - (uint8_t)(bytesReceived >> 16u), - (uint8_t)(bytesReceived >> 24u)}; + static_cast<uint8_t>(bytesReceived & 0x000000FFu), + static_cast<uint8_t>(bytesReceived >> 8u), + static_cast<uint8_t>(bytesReceived >> 16u), + static_cast<uint8_t>(bytesReceived >> 24u)}; NRF_LOG_INFO("[DFU] -> Send packet notification: %d bytes received", bytesReceived); notificationManager.Send(connectionHandle, controlPointCharacteristicHandle, data, 5); } @@ -244,7 +246,7 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf* om) { NRF_LOG_INFO("[DFU] -> Receive firmware image requested, but we are not in Start Init"); return 0; } - // TODO the chunk size is dependant of the implementation of the host application... + // TODO the chunk size is dependent of the implementation of the host application... dfuImage.Init(20, applicationSize, expectedCrc); NRF_LOG_INFO("[DFU] -> Starting receive firmware"); state = States::Data; @@ -423,9 +425,9 @@ uint16_t DfuService::DfuImage::ComputeCrc(uint8_t const* p_data, uint32_t size, uint16_t crc = (p_crc == NULL) ? 0xFFFF : *p_crc; for (uint32_t i = 0; i < size; i++) { - crc = (uint8_t)(crc >> 8) | (crc << 8); + crc = static_cast<uint8_t>(crc >> 8) | (crc << 8); crc ^= p_data[i]; - crc ^= (uint8_t)(crc & 0xFF) >> 4; + crc ^= static_cast<uint8_t>(crc & 0xFF) >> 4; crc ^= (crc << 8) << 4; crc ^= ((crc & 0xFF) << 4) << 1; } diff --git a/src/components/ble/FSService.cpp b/src/components/ble/FSService.cpp index 8dc9ed6..fda6b39 100644 --- a/src/components/ble/FSService.cpp +++ b/src/components/ble/FSService.cpp @@ -81,7 +81,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) { return -1; } memcpy(filepath, header->pathstr, plen); - filepath[plen] = 0; // Copy and null teminate string + filepath[plen] = 0; // Copy and null terminate string ReadResponse resp; os_mbuf* om; resp.command = commands::READ_DATA; @@ -148,7 +148,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) { return -1; // TODO make this actually return a BLE notif } memcpy(filepath, header->pathstr, plen); - filepath[plen] = 0; // Copy and null teminate string + filepath[plen] = 0; // Copy and null terminate string fileSize = header->totalSize; WriteResponse resp; resp.command = commands::WRITE_PACING; @@ -193,7 +193,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) { uint16_t plen = header->pathlen; char path[plen + 1] = {0}; memcpy(path, header->pathstr, plen); - path[plen] = 0; // Copy and null teminate string + path[plen] = 0; // Copy and null terminate string DelResponse resp {}; resp.command = commands::DELETE_STATUS; int res = fs.FileDelete(path); @@ -208,7 +208,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) { uint16_t plen = header->pathlen; char path[plen + 1] = {0}; memcpy(path, header->pathstr, plen); - path[plen] = 0; // Copy and null teminate string + path[plen] = 0; // Copy and null terminate string MKDirResponse resp {}; resp.command = commands::MKDIR_STATUS; resp.modification_time = 0; @@ -223,7 +223,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) { ListDirHeader* header = (ListDirHeader*) om->om_data; uint16_t plen = header->pathlen; char path[plen + 1] = {0}; - path[plen] = 0; // Copy and null teminate string + path[plen] = 0; // Copy and null terminate string memcpy(path, header->pathstr, plen); ListDirResponse resp {}; @@ -290,7 +290,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) { header->pathstr[plen] = 0; char path[header->NewPathLength + 1] = {0}; memcpy(path, &header->pathstr[plen + 1], header->NewPathLength); - path[header->NewPathLength] = 0; // Copy and null teminate string + path[header->NewPathLength] = 0; // Copy and null terminate string MoveResponse resp {}; resp.command = commands::MOVE_STATUS; int8_t res = (int8_t) fs.Rename(header->pathstr, path); diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp index 4824a6b..d49a02c 100644 --- a/src/components/ble/HeartRateService.cpp +++ b/src/components/ble/HeartRateService.cpp @@ -57,7 +57,8 @@ int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t a } void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { - if(!heartRateMeasurementNotificationEnable) return; + if (!heartRateMeasurementNotificationEnable) + return; uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value auto* om = ble_hs_mbuf_from_flat(buffer, 2); @@ -72,11 +73,11 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { } void HeartRateService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == heartRateMeasurementHandle) + if (attributeHandle == heartRateMeasurementHandle) heartRateMeasurementNotificationEnable = true; } void HeartRateService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == heartRateMeasurementHandle) + if (attributeHandle == heartRateMeasurementHandle) heartRateMeasurementNotificationEnable = false; }
\ No newline at end of file diff --git a/src/components/ble/MotionService.cpp b/src/components/ble/MotionService.cpp index 87923c2..121ad3b 100644 --- a/src/components/ble/MotionService.cpp +++ b/src/components/ble/MotionService.cpp @@ -8,10 +8,8 @@ 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 } - }; + 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 @@ -45,11 +43,7 @@ MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers:: .val_handle = &motionValuesHandle}, {0}}, serviceDefinition { - { - .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = &motionServiceUuid.u, - .characteristics = characteristicDefinition - }, + {.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) @@ -72,8 +66,8 @@ int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attr 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() }; + } 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; @@ -82,7 +76,8 @@ int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attr } void MotionService::OnNewStepCountValue(uint32_t stepCount) { - if(!stepCountNoficationEnabled) return; + if (!stepCountNoficationEnabled) + return; uint32_t buffer = stepCount; auto* om = ble_hs_mbuf_from_flat(&buffer, 4); @@ -96,9 +91,10 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) { ble_gattc_notify_custom(connectionHandle, stepCountHandle, om); } void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) { - if(!motionValuesNoficationEnabled) return; + if (!motionValuesNoficationEnabled) + return; - int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() }; + 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(); @@ -111,15 +107,15 @@ void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) { } void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == stepCountHandle) + if (attributeHandle == stepCountHandle) stepCountNoficationEnabled = true; - else if(attributeHandle == motionValuesHandle) + else if (attributeHandle == motionValuesHandle) motionValuesNoficationEnabled = true; } void MotionService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == stepCountHandle) + if (attributeHandle == stepCountHandle) stepCountNoficationEnabled = false; - else if(attributeHandle == motionValuesHandle) + else if (attributeHandle == motionValuesHandle) motionValuesNoficationEnabled = false; } diff --git a/src/components/ble/MusicService.cpp b/src/components/ble/MusicService.cpp index c99aa1e..fc7cef0 100644 --- a/src/components/ble/MusicService.cpp +++ b/src/components/ble/MusicService.cpp @@ -22,10 +22,8 @@ namespace { // 0000yyxx-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, 0x00, 0x00 } - }; + 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, 0x00, 0x00}}; } // 00000000-78fc-48fe-8e23-433b3a1942d0 @@ -111,8 +109,7 @@ Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask& .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; characteristicDefinition[13] = {0}; - serviceDefinition[0] = { - .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &msUuid.u, .characteristics = characteristicDefinition}; + serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &msUuid.u, .characteristics = characteristicDefinition}; serviceDefinition[1] = {0}; } @@ -137,9 +134,9 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_ os_mbuf_copydata(ctxt->om, 0, bufferSize, data); if (notifSize > bufferSize) { - data[bufferSize-1] = '.'; - data[bufferSize-2] = '.'; - data[bufferSize-3] = '.'; + data[bufferSize - 1] = '.'; + data[bufferSize - 2] = '.'; + data[bufferSize - 3] = '.'; } data[bufferSize] = '\0'; @@ -152,12 +149,21 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_ albumName = s; } else if (ble_uuid_cmp(ctxt->chr->uuid, &msStatusCharUuid.u) == 0) { playing = s[0]; + // These variables need to be updated, because the progress may not be updated immediately, + // leading to getProgress() returning an incorrect position. + if (playing) { + trackProgressUpdateTime = xTaskGetTickCount(); + } else { + trackProgress += + static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed()); + } } else if (ble_uuid_cmp(ctxt->chr->uuid, &msRepeatCharUuid.u) == 0) { repeat = s[0]; } else if (ble_uuid_cmp(ctxt->chr->uuid, &msShuffleCharUuid.u) == 0) { shuffle = s[0]; } else if (ble_uuid_cmp(ctxt->chr->uuid, &msPositionCharUuid.u) == 0) { trackProgress = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3]; + trackProgressUpdateTime = xTaskGetTickCount(); } else if (ble_uuid_cmp(ctxt->chr->uuid, &msTotalLengthCharUuid.u) == 0) { trackLength = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3]; } else if (ble_uuid_cmp(ctxt->chr->uuid, &msTrackNumberCharUuid.u) == 0) { @@ -192,6 +198,10 @@ float Pinetime::Controllers::MusicService::getPlaybackSpeed() const { } int Pinetime::Controllers::MusicService::getProgress() const { + if (isPlaying()) { + return trackProgress + + static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed()); + } return trackProgress; } diff --git a/src/components/ble/MusicService.h b/src/components/ble/MusicService.h index 1ad9a42..047d0d2 100644 --- a/src/components/ble/MusicService.h +++ b/src/components/ble/MusicService.h @@ -81,6 +81,7 @@ namespace Pinetime { int trackLength {0}; int trackNumber {}; int tracksTotal {}; + TickType_t trackProgressUpdateTime {0}; float playbackSpeed {1.0f}; diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index 5418b9e..7614368 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -46,15 +46,23 @@ namespace { } // namespace Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) { - characteristicDefinition[0] = { - .uuid = &navFlagCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - - characteristicDefinition[1] = { - .uuid = &navNarrativeCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - characteristicDefinition[2] = { - .uuid = &navManDistCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - characteristicDefinition[3] = { - .uuid = &navProgressCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + characteristicDefinition[0] = {.uuid = &navFlagCharUuid.u, + .access_cb = NAVCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + + characteristicDefinition[1] = {.uuid = &navNarrativeCharUuid.u, + .access_cb = NAVCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + characteristicDefinition[2] = {.uuid = &navManDistCharUuid.u, + .access_cb = NAVCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + characteristicDefinition[3] = {.uuid = &navProgressCharUuid.u, + .access_cb = NAVCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; characteristicDefinition[4] = {0}; diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index ce54bb7..b2cccf7 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -236,7 +236,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) { currentTimeClient.Reset(); alertNotificationClient.Reset(); connectionHandle = BLE_HS_CONN_HANDLE_NONE; - if(bleController.IsConnected()) { + if (bleController.IsConnected()) { bleController.Disconnect(); fastAdvCount = 0; StartAdvertising(); diff --git a/src/components/ble/weather/WeatherService.h b/src/components/ble/weather/WeatherService.h index eca70cb..e37417d 100644 --- a/src/components/ble/weather/WeatherService.h +++ b/src/components/ble/weather/WeatherService.h @@ -127,7 +127,8 @@ namespace Pinetime { {.uuid = &weatherControlCharUuid.u, .access_cb = WeatherCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}, {nullptr}}; const struct ble_gatt_svc_def serviceDefinition[2] = { - {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &weatherUuid.u, .characteristics = characteristicDefinition}, {0}}; + {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &weatherUuid.u, .characteristics = characteristicDefinition}, + {0}}; uint16_t eventHandle {}; diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 7545058..1f7182c 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -19,8 +19,14 @@ void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, UpdateTime(previousSystickCounter); // Update internal state without updating the time } -void DateTime::SetTime( - uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) { +void DateTime::SetTime(uint16_t year, + uint8_t month, + uint8_t day, + uint8_t dayOfWeek, + uint8_t hour, + uint8_t minute, + uint8_t second, + uint32_t systickCounter) { std::tm tm = { /* .tm_sec = */ second, /* .tm_min = */ minute, diff --git a/src/components/fs/FS.cpp b/src/components/fs/FS.cpp index 8c98ae3..14b0552 100644 --- a/src/components/fs/FS.cpp +++ b/src/components/fs/FS.cpp @@ -95,8 +95,8 @@ int FS::DirRewind(lfs_dir_t* dir) { int FS::DirCreate(const char* path) { return lfs_mkdir(&lfs, path); } -int FS::Rename(const char* oldPath, const char* newPath){ - return lfs_rename(&lfs,oldPath,newPath); +int FS::Rename(const char* oldPath, const char* newPath) { + return lfs_rename(&lfs, oldPath, newPath); } int FS::Stat(const char* path, lfs_info* info) { return lfs_stat(&lfs, path, info); diff --git a/src/components/fs/FS.h b/src/components/fs/FS.h index 2b27ae5..87fcdc2 100644 --- a/src/components/fs/FS.h +++ b/src/components/fs/FS.h @@ -26,7 +26,7 @@ namespace Pinetime { int DirRead(lfs_dir_t* dir, lfs_info* info); int DirRewind(lfs_dir_t* dir); int DirCreate(const char* path); - + lfs_ssize_t GetFSSize(); int Rename(const char* oldPath, const char* newPath); int Stat(const char* path, lfs_info* info); diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 4c44fc4..90e41d2 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -1,41 +1,36 @@ #include "components/motor/MotorController.h" #include <hal/nrf_gpio.h> #include "systemtask/SystemTask.h" -#include "app_timer.h" #include "drivers/PinMap.h" -APP_TIMER_DEF(shortVibTimer); -APP_TIMER_DEF(longVibTimer); - using namespace Pinetime::Controllers; void MotorController::Init() { nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor); - shortVibTimer = xTimerCreate("shortVibTm", 1, pdFALSE, nullptr, StopMotor); - longVibTimer = xTimerCreate("longVibTm", 1, pdTRUE, this, Ring); + shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor); + longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring); } void MotorController::Ring(TimerHandle_t xTimer) { - auto motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer)); - xTimerChangePeriod(motorController->longVibTimer, APP_TIMER_TICKS(1000), 0); + auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer)); motorController->RunForDuration(50); } void MotorController::RunForDuration(uint8_t motorDuration) { - if (xTimerChangePeriod(shortVibTimer, APP_TIMER_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVibTimer, 0) == pdPASS) { + if (xTimerChangePeriod(shortVib, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVib, 0) == pdPASS) { nrf_gpio_pin_clear(PinMap::Motor); } } void MotorController::StartRinging() { - xTimerChangePeriod(longVibTimer, 1, 0); - xTimerStart(longVibTimer, 0); + RunForDuration(50); + xTimerStart(longVib, 0); } void MotorController::StopRinging() { - xTimerStop(longVibTimer, 0); + xTimerStop(longVib, 0); nrf_gpio_pin_set(PinMap::Motor); } diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 3c6cbd2..6dea6d1 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -19,8 +19,8 @@ namespace Pinetime { private: static void Ring(TimerHandle_t xTimer); static void StopMotor(TimerHandle_t xTimer); - TimerHandle_t shortVibTimer; - TimerHandle_t longVibTimer; + TimerHandle_t shortVib; + TimerHandle_t longVib; }; } } diff --git a/src/components/settings/Settings.cpp b/src/components/settings/Settings.cpp index fee62da..1ae00a2 100644 --- a/src/components/settings/Settings.cpp +++ b/src/components/settings/Settings.cpp @@ -26,12 +26,12 @@ void Settings::LoadSettingsFromFile() { SettingsData bufferSettings; lfs_file_t settingsFile; - if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDONLY) != LFS_ERR_OK) { + if (fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDONLY) != LFS_ERR_OK) { return; } fs.FileRead(&settingsFile, reinterpret_cast<uint8_t*>(&bufferSettings), sizeof(settings)); fs.FileClose(&settingsFile); - if ( bufferSettings.version == settingsVersion ) { + if (bufferSettings.version == settingsVersion) { settings = bufferSettings; } } @@ -39,7 +39,7 @@ void Settings::LoadSettingsFromFile() { void Settings::SaveSettingsToFile() { lfs_file_t settingsFile; - if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_WRONLY | LFS_O_CREAT) != LFS_ERR_OK) { + if (fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_WRONLY | LFS_O_CREAT) != LFS_ERR_OK) { return; } fs.FileWrite(&settingsFile, reinterpret_cast<uint8_t*>(&settings), sizeof(settings)); diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 5914e1a..393a734 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -140,15 +140,14 @@ namespace Pinetime { return settings.screenTimeOut; }; - void SetShakeThreshold(uint16_t thresh){ - if(settings.shakeWakeThreshold != thresh){ - settings.shakeWakeThreshold = thresh; - settingsChanged = true; + void SetShakeThreshold(uint16_t thresh) { + if (settings.shakeWakeThreshold != thresh) { + settings.shakeWakeThreshold = thresh; + settingsChanged = true; } - } - int16_t GetShakeThreshold() const{ + int16_t GetShakeThreshold() const { return settings.shakeWakeThreshold; } @@ -195,20 +194,20 @@ namespace Pinetime { if (goal != settings.stepsGoal) { settingsChanged = true; } - settings.stepsGoal = goal; + settings.stepsGoal = goal; }; - + uint32_t GetStepsGoal() const { return settings.stepsGoal; }; - void SetBleRadioEnabled(bool enabled) { - bleRadioEnabled = enabled; - }; + void SetBleRadioEnabled(bool enabled) { + bleRadioEnabled = enabled; + }; - bool GetBleRadioEnabled() const { - return bleRadioEnabled; - }; + bool GetBleRadioEnabled() const { + return bleRadioEnabled; + }; void SetBluetoothPasskeyEnabled(bool enabled) { settings.bluetoothPasskeyEnabled = enabled; diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp index 31635a5..eeee61f 100644 --- a/src/components/timer/TimerController.cpp +++ b/src/components/timer/TimerController.cpp @@ -1,62 +1,40 @@ -// -// Created by florian on 16.05.21. -// - #include "components/timer/TimerController.h" #include "systemtask/SystemTask.h" -#include "task.h" using namespace Pinetime::Controllers; -namespace { - void TimerEnd(TimerHandle_t xTimer) { - auto controller = static_cast<Pinetime::Controllers::TimerController*>(pvTimerGetTimerID(xTimer)); - controller->OnTimerEnd(); - } +void TimerCallback(TimerHandle_t xTimer) { + auto* controller = static_cast<TimerController*>(pvTimerGetTimerID(xTimer)); + controller->OnTimerEnd(); } -void TimerController::Init(System::SystemTask* systemTask) { +void TimerController::Init(Pinetime::System::SystemTask* systemTask) { this->systemTask = systemTask; - timerAppTimer = xTimerCreate("timerAppTm", 1, pdFALSE, this, TimerEnd); + timer = xTimerCreate("Timer", 1, pdFALSE, this, TimerCallback); } void TimerController::StartTimer(uint32_t duration) { - xTimerStop(timerAppTimer, 0); - auto currentTicks = xTaskGetTickCount(); - TickType_t durationTicks = APP_TIMER_TICKS(duration); - xTimerChangePeriod(timerAppTimer, durationTicks, 0); - xTimerStart(timerAppTimer, 0); - endTicks = currentTicks + durationTicks; - timerRunning = true; + xTimerChangePeriod(timer, pdMS_TO_TICKS(duration), 0); + xTimerStart(timer, 0); } uint32_t TimerController::GetTimeRemaining() { - if (!timerRunning) { - return 0; - } - auto currentTicks = xTaskGetTickCount(); - - TickType_t deltaTicks = 0; - if (currentTicks > endTicks) { - deltaTicks = 0xffffffff - currentTicks; - deltaTicks += (endTicks + 1); - } else { - deltaTicks = endTicks - currentTicks; + if (IsRunning()) { + TickType_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount(); + return (remainingTime * 1000 / configTICK_RATE_HZ); } - - return (static_cast<TickType_t>(deltaTicks) / static_cast<TickType_t>(configTICK_RATE_HZ)) * 1000; + return 0; } void TimerController::StopTimer() { - xTimerStop(timerAppTimer, 0); - timerRunning = false; + xTimerStop(timer, 0); } bool TimerController::IsRunning() { - return timerRunning; + return (xTimerIsTimerActive(timer) == pdTRUE); } + void TimerController::OnTimerEnd() { - timerRunning = false; - if (systemTask != nullptr) - systemTask->PushMessage(System::Messages::OnTimerDone); + systemTask->PushMessage(System::Messages::OnTimerDone); } + diff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h index 24d7150..93d8afc 100644 --- a/src/components/timer/TimerController.h +++ b/src/components/timer/TimerController.h @@ -2,9 +2,6 @@ #include <FreeRTOS.h> #include <timers.h> -#include <cstdint> -#include "app_timer.h" -#include "portmacro_cmsis.h" namespace Pinetime { namespace System { @@ -16,7 +13,10 @@ namespace Pinetime { public: TimerController() = default; + void Init(System::SystemTask* systemTask); + void StartTimer(uint32_t duration); + void StopTimer(); uint32_t GetTimeRemaining(); @@ -25,15 +25,9 @@ namespace Pinetime { void OnTimerEnd(); - protected: - friend class Pinetime::System::SystemTask; - void Init(System::SystemTask* systemTask); - private: System::SystemTask* systemTask = nullptr; - TimerHandle_t timerAppTimer; - TickType_t endTicks; - bool timerRunning = false; + TimerHandle_t timer; }; } -}
\ No newline at end of file +} |
