Author: Riku Isokoski <riksu9000@gmail.com>
Update clang-tidy configuration and fix some warnings (#1474) Don't enable coding conventions from unrelated projects. Only enable generic checks.
.clang-tidy | 33 +++--- src/CMakeLists.txt | 2 src/components/alarm/AlarmController.cpp | 2 src/components/battery/BatteryController.cpp | 10 - src/components/ble/NavigationService.cpp | 2 src/components/heartrate/Ppg.cpp | 38 +++++--- src/components/heartrate/Ppg.h | 6 src/components/heartrate/Ptagc.cpp | 8 + src/components/motion/MotionController.cpp | 5 src/displayapp/DisplayApp.cpp | 10 - src/displayapp/screens/FirmwareValidation.cpp | 6 src/displayapp/screens/HeartRate.cpp | 8 + src/displayapp/screens/Motion.cpp | 12 +- src/displayapp/screens/Notifications.cpp | 18 +-- src/displayapp/screens/Steps.h | 1 src/displayapp/screens/SystemInfo.cpp | 4 src/displayapp/screens/Tile.cpp | 8 + src/displayapp/screens/Timer.h | 5 src/displayapp/screens/WatchFaceAnalog.cpp | 22 ++-- src/displayapp/screens/settings/SettingShakeThreshold.cpp | 4 src/heartratetask/HeartRateTask.cpp | 35 ++++--- src/main.cpp | 39 ++++---- src/systemtask/Messages.h | 4 src/systemtask/SystemTask.cpp | 20 ++--
diff --git a/.clang-tidy b/.clang-tidy index 88ca6c542d244b00e0d6756f155baf4bc3d003f9..f1ddc5725029a315433a2817c0489437300f8438 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,14 +1,15 @@ -Checks: '*, - -altera-unroll-loops, - -llvmlibc-callee-namespace, - -llvmlibc-implementation-in-namespace, - -llvmlibc-restrict-system-libc-headers, - -llvm-header-guard, - -llvm-namespace-comment, - -google-build-using-namespace, - -google-runtime-int, - -google-readability-namespace-comments, - -fuchsia-statically-constructed-objects, +Checks: 'bugprone-*, + cert-*, + cppcoreguidelines-*, + hicpp-*, + misc-*, + modernize-*, + performance-*, + portability-*, + readability-*, + fuchsia-trailing-return, + -cert-err58-cpp, + -cert-err60-cpp, -cppcoreguidelines-prefer-member-initializer, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, @@ -20,10 +21,6 @@ -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-avoid-c-arrays, -cppcoreguidelines-special-member-functions, - -readability-magic-numbers, - -readability-uppercase-literal-suffix, - -modernize-use-trailing-return-type, - -modernize-avoid-c-arrays, -hicpp-avoid-c-arrays, -hicpp-uppercase-literal-suffix, -hicpp-vararg, @@ -31,8 +28,10 @@ -hicpp-no-assembler, -hicpp-no-array-decay, -hicpp-signed-bitwise, -hicpp-special-member-functions, - -cert-err58-cpp, - -cert-err60-cpp' + -modernize-use-trailing-return-type, + -modernize-avoid-c-arrays, + -readability-magic-numbers, + -readability-uppercase-literal-suffix' CheckOptions: - key: readability-function-cognitive-complexity.Threshold value: 100 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e59c0d814b8e87754d0df0989b98984f17bd0e2e..00be3c87c9f19039d4725c6cd8a8eae0ac339e7d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -778,7 +778,7 @@ ../ ) -set(COMMON_FLAGS -MP -MD -mthumb -mabi=aapcs -Wall -Wextra -Warray-bounds=2 -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wformat-nonliteral -ftree-vrp -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-expansion-to-defined -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wreturn-type -Werror=return-type -fstack-usage -fno-exceptions -fno-non-call-exceptions) +set(COMMON_FLAGS -MP -MD -mthumb -mabi=aapcs -Wall -Wextra -Warray-bounds=2 -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wformat-nonliteral -ftree-vrp -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-expansion-to-defined -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin -fshort-enums -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wreturn-type -Werror=return-type -fstack-usage -fno-exceptions -fno-non-call-exceptions) add_definitions(-DCONFIG_GPIO_AS_PINRESET) add_definitions(-DNIMBLE_CFG_CONTROLLER) add_definitions(-DOS_CPUTIME_FREQ) diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index d97e1cffcf4a8b07f59d7e90a471ea8ab3946e6e..88f65d9adbabbcd82b5250bb300e74d8dc6fceb7 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -28,7 +28,7 @@ } namespace { void SetOffAlarm(TimerHandle_t xTimer) { - auto controller = static_cast<Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID(xTimer)); + auto* controller = static_cast<Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID(xTimer)); controller->SetOffAlarmNow(); } } diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index b61f0ce3df9dc3791ec23dd496223e0aabe82d4c..dc15612e3dac7d28743bd5d37c9a033398eb2976 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -16,8 +16,8 @@ nrf_gpio_cfg_input(PinMap::Charging, static_castGPIO_PIN_CNF_PULL_Disabled); } void Battery::ReadPowerState() { - isCharging = !nrf_gpio_pin_read(PinMap::Charging); - isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent); + isCharging = (nrf_gpio_pin_read(PinMap::Charging) == 0); + isPowerPresent = (nrf_gpio_pin_read(PinMap::PowerPresent) == 0); if (isPowerPresent && !isCharging) { isFull = true; @@ -81,10 +81,8 @@ // reference_voltage is 600mV // p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024 voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024; - uint8_t newPercent; - if (isFull) { - newPercent = 100; - } else { + uint8_t newPercent = 100; + if (!isFull) { newPercent = std::min(aprox.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100}); } diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index 76143686ab41e30577b66de93ae638d174d9fd0c..ea8f3a4d34fa9d783a7a5f440901da4a437ffe23 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -40,7 +40,7 @@ constexpr ble_uuid128_t navManDistCharUuid {CharUuid(0x03, 0x00)}; constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)}; int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { - auto navService = static_cast<Pinetime::Controllers::NavigationService*>(arg); + auto* navService = static_cast<Pinetime::Controllers::NavigationService*>(arg); return navService->OnCommand(conn_handle, attr_handle, ctxt); } } // namespace diff --git a/src/components/heartrate/Ppg.cpp b/src/components/heartrate/Ppg.cpp index a5d836966ae3939cc8add3c0c640d0b1a8e479d7..900b1c22cc777d1b8b42f2304ab04c1b6ab6d405 100644 --- a/src/components/heartrate/Ppg.cpp +++ b/src/components/heartrate/Ppg.cpp @@ -29,8 +29,9 @@ auto z2 = CompareShift(d, mn - 2, size); auto z1 = CompareShift(d, mn - 1, size); for (int i = mn; i < mx + 1; i++) { auto z = CompareShift(d, i, size); - if (z2 > z1 && z1 < z) + if (z2 > z1 && z1 < z) { return i; + } z2 = z1; z1 = z; } @@ -52,41 +53,48 @@ spl = lpf.Step(spl); auto spl_int = static_cast<int8_t>(spl); - if (dataIndex < 200) + if (dataIndex < 200) { data[dataIndex++] = spl_int; + } return spl_int; } -float Ppg::HeartRate() { - if (dataIndex < 200) +int Ppg::HeartRate() { + if (dataIndex < 200) { return 0; + } NRF_LOG_INFO("PREPROCESS, offset = %d", offset); auto hr = ProcessHeartRate(); dataIndex = 0; return hr; } -float Ppg::ProcessHeartRate() { - auto t0 = Trough(data.data(), dataIndex, 7, 48); - if (t0 < 0) + +int Ppg::ProcessHeartRate() { + int t0 = Trough(data.data(), dataIndex, 7, 48); + if (t0 < 0) { return 0; + } - float t1 = t0 * 2; + int t1 = t0 * 2; t1 = Trough(data.data(), dataIndex, t1 - 5, t1 + 5); - if (t1 < 0) + if (t1 < 0) { return 0; + } - float t2 = static_cast<int>(t1 * 3) / 2; + int t2 = (t1 * 3) / 2; t2 = Trough(data.data(), dataIndex, t2 - 5, t2 + 5); - if (t2 < 0) + if (t2 < 0) { return 0; + } - float t3 = static_cast<int>(t2 * 4) / 3; + int t3 = (t2 * 4) / 3; t3 = Trough(data.data(), dataIndex, t3 - 4, t3 + 4); - if (t3 < 0) - return static_cast<int>(60 * 24 * 3) / static_cast<int>(t2); + if (t3 < 0) { + return (60 * 24 * 3) / t2; + } - return static_cast<int>(60 * 24 * 4) / static_cast<int>(t3); + return (60 * 24 * 4) / t3; } void Ppg::SetOffset(uint16_t offset) { diff --git a/src/components/heartrate/Ppg.h b/src/components/heartrate/Ppg.h index 7000c8710bb49cfc56815a82f54c0bbf0c8ddd50..1f709babb368a635dacd2c4e54b45c4015526ece 100644 --- a/src/components/heartrate/Ppg.h +++ b/src/components/heartrate/Ppg.h @@ -12,9 +12,9 @@ class Ppg { public: Ppg(); int8_t Preprocess(float spl); - float HeartRate(); + int HeartRate(); - void SetOffset(uint16_t i); + void SetOffset(uint16_t offset); void Reset(); private: @@ -25,7 +25,7 @@ Biquad hpf; Ptagc agc; Biquad lpf; - float ProcessHeartRate(); + int ProcessHeartRate(); }; } } diff --git a/src/components/heartrate/Ptagc.cpp b/src/components/heartrate/Ptagc.cpp index 1c60bc2398ccbcdf506ebbf591c499e9fdf20508..221be460c4b5b71807bf520c94258a9ec6bae81c 100644 --- a/src/components/heartrate/Ptagc.cpp +++ b/src/components/heartrate/Ptagc.cpp @@ -14,13 +14,15 @@ Ptagc::Ptagc(float start, float decay, float threshold) : peak {start}, decay {decay}, boost {1.0f / decay}, threshold {threshold} { } float Ptagc::Step(float spl) { - if (std::abs(spl) > peak) + if (std::abs(spl) > peak) { peak *= boost; - else + } else { peak *= decay; + } - if ((spl > (peak * threshold)) || (spl < (peak * -threshold))) + if ((spl > (peak * threshold)) || (spl < (peak * -threshold))) { return 0.0f; + } spl = 100.0f * spl / (2.0f * peak); return spl; diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index 7dd321271c707a20f928a35020673fdafe32e60f..d93d769ba5693aec227ae772068c43b9fbd7c6af 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -26,10 +26,9 @@ if ((x + 335) <= 670 && z < 0) { if (not isSleeping) { if (y <= 0) { return false; - } else { - lastYForWakeUp = 0; - return false; } + lastYForWakeUp = 0; + return false; } if (y >= 0) { diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 108e380d69d3e9f215ae498833e42cfea345e78e..015bc8de6452afb7b77ebad59d7036595c0b3b40 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -152,7 +152,7 @@ break; } Messages msg; - if (xQueueReceive(msgQueue, &msg, queueTimeout)) { + if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) { switch (msg) { case Messages::DimScreen: brightnessController.Set(Controllers::BrightnessController::Levels::Low); @@ -485,10 +485,9 @@ } void DisplayApp::PushMessage(Messages msg) { if (in_isr()) { - BaseType_t xHigherPriorityTaskWoken; - xHigherPriorityTaskWoken = pdFALSE; + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken); - if (xHigherPriorityTaskWoken) { + if (xHigherPriorityTaskWoken == pdTRUE) { portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } } else { @@ -532,8 +531,7 @@ this->systemTask = systemTask; } void DisplayApp::ApplyBrightness() { auto brightness = settingsController.GetBrightness(); - if(brightness != Controllers::BrightnessController::Levels::Low && - brightness != Controllers::BrightnessController::Levels::Medium && + if (brightness != Controllers::BrightnessController::Levels::Low && brightness != Controllers::BrightnessController::Levels::Medium && brightness != Controllers::BrightnessController::Levels::High) { brightness = Controllers::BrightnessController::Levels::High; } diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp index a2314690c35479ee15ab223abce16403f8c3e71c..bda6d68d7c45847b74fe2cf3bbcb3b9191ecf823 100644 --- a/src/displayapp/screens/FirmwareValidation.cpp +++ b/src/displayapp/screens/FirmwareValidation.cpp @@ -32,16 +32,16 @@ lv_label_set_recolor(labelIsValidated, true); lv_label_set_long_mode(labelIsValidated, LV_LABEL_LONG_BREAK); lv_obj_set_width(labelIsValidated, 240); - if (validator.IsValidated()) + if (validator.IsValidated()) { lv_label_set_text_static(labelIsValidated, "You have already\n#00ff00 validated# this firmware#"); - else { + } else { lv_label_set_text_static(labelIsValidated, "Please #00ff00 Validate# this version or\n#ff0000 Reset# to rollback to the previous version."); buttonValidate = lv_btn_create(lv_scr_act(), nullptr); buttonValidate->user_data = this; lv_obj_set_size(buttonValidate, 115, 50); - lv_obj_align(buttonValidate, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_align(buttonValidate, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_obj_set_event_cb(buttonValidate, ButtonEventHandler); lv_obj_set_style_local_bg_color(buttonValidate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight); diff --git a/src/displayapp/screens/HeartRate.cpp b/src/displayapp/screens/HeartRate.cpp index 305e0c4bd92b11d1166f1ff01111532b54a07f1b..71bf86caf143a8ed6e999dcec20712a71f0e5a6e 100644 --- a/src/displayapp/screens/HeartRate.cpp +++ b/src/displayapp/screens/HeartRate.cpp @@ -64,8 +64,9 @@ lv_obj_align(btn_startStop, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); label_startStop = lv_label_create(btn_startStop, nullptr); UpdateStartStopButton(isHrRunning); - if (isHrRunning) + if (isHrRunning) { systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping); + } taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); } @@ -110,8 +111,9 @@ } } void HeartRate::UpdateStartStopButton(bool isRunning) { - if (isRunning) + if (isRunning) { lv_label_set_text_static(label_startStop, "Stop"); - else + } else { lv_label_set_text_static(label_startStop, "Start"); + } } diff --git a/src/displayapp/screens/Motion.cpp b/src/displayapp/screens/Motion.cpp index c2dc4dac1ab6a9fc32272e09871ba3ad3dfc7074..e3689599a2d4209ebc95188f5011ad05c1500761 100644 --- a/src/displayapp/screens/Motion.cpp +++ b/src/displayapp/screens/Motion.cpp @@ -7,9 +7,9 @@ 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); + chart = lv_chart_create(lv_scr_act(), nullptr); lv_obj_set_size(chart, 240, 240); - lv_obj_align(chart, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); + lv_obj_align(chart, nullptr, 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*/ @@ -28,13 +28,13 @@ 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); + label = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(label, "X #FF0000 %d# Y #00B000 %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_obj_align(label, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10); lv_label_set_recolor(label, true); - labelStep = lv_label_create(lv_scr_act(), NULL); + labelStep = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(labelStep, chart, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_label_set_text_static(labelStep, "Steps ---"); @@ -58,5 +58,5 @@ "X #FF0000 %d# Y #00B000 %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); + lv_obj_align(label, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10); } diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 90a010f5fc391b6ed6aa4e7d5948976f7f00324e..5100ef9b47947240cc0bf3fefa8275e856bea34b 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -139,15 +139,9 @@ switch (event) { case Pinetime::Applications::TouchEvents::SwipeRight: if (validDisplay) { - Controllers::NotificationManager::Notification previousNotification; auto previousMessage = notificationManager.GetPrevious(currentId); auto nextMessage = notificationManager.GetNext(currentId); - if (!previousMessage.valid) { - // dismissed last message (like 5/5), need to go one message down (like 4/4) - afterDismissNextMessageFromAbove = false; // show next message coming from below - } else { - afterDismissNextMessageFromAbove = true; // show next message coming from above - } + afterDismissNextMessageFromAbove = previousMessage.valid; notificationManager.Dismiss(currentId); if (previousMessage.valid) { currentId = previousMessage.id; @@ -270,7 +264,7 @@ lv_cont_set_fit(subject_container, LV_FIT_NONE); lv_obj_t* alert_count = lv_label_create(container, nullptr); lv_label_set_text_fmt(alert_count, "%i/%i", notifNr, notifNb); - lv_obj_align(alert_count, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 16); + lv_obj_align(alert_count, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 16); lv_obj_t* alert_type = lv_label_create(container, nullptr); lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange); @@ -288,7 +282,7 @@ lv_label_refr_text(alert_type); } lv_label_set_long_mode(alert_type, LV_LABEL_LONG_SROLL_CIRC); lv_obj_set_width(alert_type, 180); - lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 16); + lv_obj_align(alert_type, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 16); lv_obj_t* alert_subject = lv_label_create(subject_container, nullptr); lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); @@ -312,7 +306,7 @@ bt_accept = lv_btn_create(container, nullptr); bt_accept->user_data = this; lv_obj_set_event_cb(bt_accept, CallEventHandler); lv_obj_set_size(bt_accept, 76, 76); - lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_align(bt_accept, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); label_accept = lv_label_create(bt_accept, nullptr); lv_label_set_text_static(label_accept, Symbols::phone); lv_obj_set_style_local_bg_color(bt_accept, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight); @@ -321,7 +315,7 @@ bt_reject = lv_btn_create(container, nullptr); bt_reject->user_data = this; lv_obj_set_event_cb(bt_reject, CallEventHandler); lv_obj_set_size(bt_reject, 76, 76); - lv_obj_align(bt_reject, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_obj_align(bt_reject, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); label_reject = lv_label_create(bt_reject, nullptr); lv_label_set_text_static(label_reject, Symbols::phoneSlash); lv_obj_set_style_local_bg_color(bt_reject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); @@ -330,7 +324,7 @@ bt_mute = lv_btn_create(container, nullptr); bt_mute->user_data = this; lv_obj_set_event_cb(bt_mute, CallEventHandler); lv_obj_set_size(bt_mute, 76, 76); - lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + lv_obj_align(bt_mute, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); label_mute = lv_label_create(bt_mute, nullptr); lv_label_set_text_static(label_mute, Symbols::volumMute); lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); diff --git a/src/displayapp/screens/Steps.h b/src/displayapp/screens/Steps.h index f109e0f237263d47c5c04aa4f27b5ba515d86958..32ad40bd553f4b2e4671e30b3445c8896812a588 100644 --- a/src/displayapp/screens/Steps.h +++ b/src/displayapp/screens/Steps.h @@ -29,7 +29,6 @@ uint32_t currentTripSteps = 0; lv_obj_t* lSteps; - lv_obj_t* lStepsIcon; lv_obj_t* stepsArc; lv_obj_t* resetBtn; lv_obj_t* resetButtonLabel; diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 01c351955ec4fd772e1f48c4868b1dabfd611860..b5b17347dfcdfba1f6b4119630e65b02a324c039 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -99,7 +99,7 @@ } std::unique_ptr<Screen> SystemInfo::CreateScreen2() { auto batteryPercent = batteryController.PercentRemaining(); - auto resetReason = [this]() { + const auto* resetReason = [this]() { switch (watchdog.ResetReason()) { case Drivers::Watchdog::ResetReasons::Watchdog: return "wtdg"; @@ -182,7 +182,7 @@ lv_mem_monitor(&mon); lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_label_set_recolor(label, true); - auto& bleAddr = bleController.Address(); + const auto& bleAddr = bleController.Address(); lv_label_set_text_fmt(label, "#808080 BLE MAC#\n" " %02x:%02x:%02x:%02x:%02x:%02x" diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index a60076ed635e0f9cb03f49cd523362f647341848..681f9c9fa09b5500934261fe75b53468324e5535 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -51,8 +51,9 @@ pageIndicator.Create(); uint8_t btIndex = 0; for (uint8_t i = 0; i < 6; i++) { - if (i == 3) + if (i == 3) { btnmMap[btIndex++] = "\n"; + } if (applications[i].application == Apps::None) { btnmMap[btIndex] = " "; } else { @@ -66,7 +67,7 @@ btnm1 = lv_btnmatrix_create(lv_scr_act(), nullptr); lv_btnmatrix_set_map(btnm1, btnmMap); lv_obj_set_size(btnm1, LV_HOR_RES - 16, LV_VER_RES - 60); - lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 10); + lv_obj_align(btnm1, nullptr, LV_ALIGN_CENTER, 0, 10); lv_obj_set_style_local_radius(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, 20); lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, LV_OPA_50); @@ -102,8 +103,9 @@ statusIcons.Update(); } void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) { - if (obj != btnm1) + if (obj != btnm1) { return; + } app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up); running = false; diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer.h index a6b60a177153e92893fd25d11b85041c6606f8c2..306281d77883a5d2bce23172189078ee3ad4d226 100644 --- a/src/displayapp/screens/Timer.h +++ b/src/displayapp/screens/Timer.h @@ -26,7 +26,6 @@ void SetTimerStopped(); void UpdateMask(); Controllers::TimerController& timerController; - lv_obj_t* msecTime; lv_obj_t* btnPlayPause; lv_obj_t* txtPlayPause; @@ -40,7 +39,7 @@ Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76); Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76); bool buttonPressing = false; - int maskPosition = 0; - TickType_t pressTime; + lv_coord_t maskPosition = 0; + TickType_t pressTime = 0; }; } diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index 5e5317eefe6a2ee7791e51ee391ef90874ec6438..b36c29d3fc562e05839c4ffda411ba3eea66123b 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -61,9 +61,9 @@ sHour = 99; sMinute = 99; sSecond = 99; - lv_obj_t* bg_clock_img = lv_img_create(lv_scr_act(), NULL); + lv_obj_t* bg_clock_img = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src(bg_clock_img, &bg_clock); - lv_obj_align(bg_clock_img, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_align(bg_clock_img, nullptr, LV_ALIGN_CENTER, 0, 0); batteryIcon.Create(lv_scr_act()); lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); @@ -72,24 +72,24 @@ plugIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(plugIcon, Symbols::plug); lv_obj_align(plugIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); - notificationIcon = lv_label_create(lv_scr_act(), NULL); + notificationIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME); lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); - lv_obj_align(notificationIcon, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); // Date - Day / Week day - label_date_day = lv_label_create(lv_scr_act(), NULL); + label_date_day = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange); lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day()); lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label_date_day, NULL, LV_ALIGN_CENTER, 50, 0); + lv_obj_align(label_date_day, nullptr, LV_ALIGN_CENTER, 50, 0); - minute_body = lv_line_create(lv_scr_act(), NULL); - minute_body_trace = lv_line_create(lv_scr_act(), NULL); - hour_body = lv_line_create(lv_scr_act(), NULL); - hour_body_trace = lv_line_create(lv_scr_act(), NULL); - second_body = lv_line_create(lv_scr_act(), NULL); + minute_body = lv_line_create(lv_scr_act(), nullptr); + minute_body_trace = lv_line_create(lv_scr_act(), nullptr); + hour_body = lv_line_create(lv_scr_act(), nullptr); + hour_body_trace = lv_line_create(lv_scr_act(), nullptr); + second_body = lv_line_create(lv_scr_act(), nullptr); lv_style_init(&second_line_style); lv_style_set_line_width(&second_line_style, LV_STATE_DEFAULT, 3); diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index de46f7de0c8b40e138177eec15ede4d1d4b93b6e..e7edee9a8d6975406d0602780f8f48f333098fe0 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -57,7 +57,7 @@ lv_obj_set_height(calButton, 80); lv_obj_set_width(calButton, 200); lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_btn_set_checkable(calButton, true); - calLabel = lv_label_create(calButton, NULL); + calLabel = lv_label_create(calButton, nullptr); lv_label_set_text_static(calLabel, "Calibrate"); lv_arc_set_value(positionArc, settingsController.GetShakeThreshold()); @@ -102,7 +102,7 @@ lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 300); } if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(7500)) { lv_btn_set_state(calButton, LV_STATE_DEFAULT); - lv_event_send(calButton, LV_EVENT_VALUE_CHANGED, NULL); + lv_event_send(calButton, LV_EVENT_VALUE_CHANGED, nullptr); } } if (motionController.currentShakeSpeed() - 300 > lv_arc_get_value(animArc)) { diff --git a/src/heartratetask/HeartRateTask.cpp b/src/heartratetask/HeartRateTask.cpp index bc22762469d6aa66e859c4aed733590d56a091dd..50833ab23ac5daa192aed7e55ad9a7c0c6efff78 100644 --- a/src/heartratetask/HeartRateTask.cpp +++ b/src/heartratetask/HeartRateTask.cpp @@ -6,15 +6,16 @@ using namespace Pinetime::Applications; HeartRateTask::HeartRateTask(Drivers::Hrs3300& heartRateSensor, Controllers::HeartRateController& controller) - : heartRateSensor {heartRateSensor}, controller {controller}, ppg {} { + : heartRateSensor {heartRateSensor}, controller {controller} { } void HeartRateTask::Start() { messageQueue = xQueueCreate(10, 1); controller.SetHeartRateTask(this); - if (pdPASS != xTaskCreate(HeartRateTask::Process, "Heartrate", 500, this, 0, &taskHandle)) + if (pdPASS != xTaskCreate(HeartRateTask::Process, "Heartrate", 500, this, 0, &taskHandle)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); + } } void HeartRateTask::Process(void* instance) { @@ -25,17 +26,19 @@ void HeartRateTask::Work() { int lastBpm = 0; while (true) { - Messages msg; - uint32_t delay; + auto delay = portMAX_DELAY; if (state == States::Running) { - if (measurementStarted) + if (measurementStarted) { delay = 40; - else + } else { delay = 100; - } else + } + } else { delay = portMAX_DELAY; + } - if (xQueueReceive(messageQueue, &msg, delay)) { + Messages msg; + if (xQueueReceive(messageQueue, &msg, delay) == pdTRUE) { switch (msg) { case Messages::GoToSleep: StopMeasurement(); @@ -49,15 +52,17 @@ StartMeasurement(); } break; case Messages::StartMeasurement: - if (measurementStarted) + if (measurementStarted) { break; + } lastBpm = 0; StartMeasurement(); measurementStarted = true; break; case Messages::StopMeasurement: - if (!measurementStarted) + if (!measurementStarted) { break; + } StopMeasurement(); measurementStarted = false; break; @@ -68,8 +73,9 @@ if (measurementStarted) { ppg.Preprocess(static_cast<float>(heartRateSensor.ReadHrs())); auto bpm = ppg.HeartRate(); - if (lastBpm == 0 && bpm == 0) + if (lastBpm == 0 && bpm == 0) { controller.Update(Controllers::HeartRateController::States::NotEnoughData, 0); + } if (bpm != 0) { lastBpm = bpm; controller.Update(Controllers::HeartRateController::States::Running, lastBpm); @@ -79,10 +85,9 @@ } } void HeartRateTask::PushMessage(HeartRateTask::Messages msg) { - BaseType_t xHigherPriorityTaskWoken; - xHigherPriorityTaskWoken = pdFALSE; + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xQueueSendFromISR(messageQueue, &msg, &xHigherPriorityTaskWoken); - if (xHigherPriorityTaskWoken) { + if (xHigherPriorityTaskWoken == pdTRUE) { /* Actual macro used here is port specific. */ // TODO : should I do something here? } @@ -91,7 +96,7 @@ void HeartRateTask::StartMeasurement() { heartRateSensor.Enable(); vTaskDelay(100); - ppg.SetOffset(static_cast<float>(heartRateSensor.ReadHrs())); + ppg.SetOffset(heartRateSensor.ReadHrs()); } void HeartRateTask::StopMeasurement() { diff --git a/src/main.cpp b/src/main.cpp index ad7a07dc9890c82374629c477557cf2dd79b16d7..b205f1e6b32f4036371dccea804166a0b402e6d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,6 @@ #include "drivers/TwiMaster.h" #include "drivers/Cst816s.h" #include "drivers/PinMap.h" #include "systemtask/SystemTask.h" -#include "drivers/PinMap.h" #include "touchhandler/TouchHandler.h" #include "buttonhandler/ButtonHandler.h" @@ -210,29 +209,29 @@ NRF_SPIM0->EVENTS_STOPPED = 0; } } -static void (*radio_isr_addr)(void); -static void (*rng_isr_addr)(void); -static void (*rtc0_isr_addr)(void); +static void (*radio_isr_addr)(); +static void (*rng_isr_addr)(); +static void (*rtc0_isr_addr)(); /* Some interrupt handlers required for NimBLE radio driver */ extern "C" { void RADIO_IRQHandler(void) { - ((void (*)(void)) radio_isr_addr)(); + ((void (*)()) radio_isr_addr)(); } void RNG_IRQHandler(void) { - ((void (*)(void)) rng_isr_addr)(); + ((void (*)()) rng_isr_addr)(); } void RTC0_IRQHandler(void) { - ((void (*)(void)) rtc0_isr_addr)(); + ((void (*)()) rtc0_isr_addr)(); } void WDT_IRQHandler(void) { nrf_wdt_event_clear(NRF_WDT_EVENT_TIMEOUT); } -void npl_freertos_hw_set_isr(int irqn, void (*addr)(void)) { +void npl_freertos_hw_set_isr(int irqn, void (*addr)()) { switch (irqn) { case RADIO_IRQn: radio_isr_addr = addr; @@ -243,6 +242,8 @@ break; case RTC0_IRQn: rtc0_isr_addr = addr; break; + default: + break; } } @@ -253,7 +254,7 @@ return (ctx & 0x01); } void npl_freertos_hw_exit_critical(uint32_t ctx) { - if (!ctx) { + if (ctx == 0) { __enable_irq(); } } @@ -265,15 +266,14 @@ return &g_eventq_dflt; } void nimble_port_run(void) { - struct ble_npl_event* ev; - - while (1) { - ev = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER); - ble_npl_event_run(ev); + struct ble_npl_event* event; + while (true) { + event = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER); + ble_npl_event_run(event); } } -void BleHost(void*) { +void BleHost(void* /*unused*/) { nimble_port_run(); } @@ -285,8 +285,7 @@ os_msys_init(); ble_hs_init(); ble_store_ram_init(); - int res; - res = hal_timer_init(5, NULL); + int res = hal_timer_init(5, nullptr); ASSERT(res == 0); res = os_cputime_init(32768); ASSERT(res == 0); @@ -301,17 +300,17 @@ ble_ll_task(args); } } -void calibrate_lf_clock_rc(nrf_drv_clock_evt_type_t event) { +void calibrate_lf_clock_rc(nrf_drv_clock_evt_type_t /*event*/) { // 16 * 0.25s = 4s calibration cycle // Not recursive, call is deferred via internal calibration timer nrf_drv_clock_calibration_start(16, calibrate_lf_clock_rc); } -int main(void) { +int main() { logger.Init(); nrf_drv_clock_init(); - nrf_drv_clock_lfclk_request(NULL); + nrf_drv_clock_lfclk_request(nullptr); // When loading the firmware via the Wasp-OS reloader-factory, which uses the used internal LF RC oscillator, // the LF clock has to be explicitly restarted because InfiniTime uses the external crystal oscillator if available. diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index 7a46e0609cb3ac84cecd0f31d6f5eaea0b1a0ced..d730d74f3076e4041ec30c638223a73a387d87e1 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -1,8 +1,8 @@ #pragma once - +#include <cstdint> namespace Pinetime { namespace System { - enum class Messages { + enum class Messages : uint8_t { GoToSleep, GoToRunning, TouchWakeUp, diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index ef631af74e332db6a11945da2a58488e0a66b392..01056a9addf555454b807315ea8ef23344a3affa 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -30,14 +30,14 @@ void DimTimerCallback(TimerHandle_t xTimer) { NRF_LOG_INFO("DimTimerCallback"); - auto sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer)); + auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer)); sysTask->OnDim(); } void IdleTimerCallback(TimerHandle_t xTimer) { NRF_LOG_INFO("IdleTimerCallback"); - auto sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer)); + auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer)); sysTask->OnIdle(); } @@ -208,10 +208,9 @@ #pragma ide diagnostic ignored "EndlessLoop" while (true) { UpdateMotion(); - uint8_t msg; - if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) { - Messages message = static_cast<Messages>(msg); - switch (message) { + Messages msg; + if (xQueueReceive(systemTasksMsgQueue, &msg, 100) == pdTRUE) { + switch (msg) { case Messages::EnableSleeping: // Make sure that exiting an app doesn't enable sleeping, // if the exiting was caused by a firmware update @@ -348,7 +347,7 @@ ReloadIdleTimer(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); break; case Messages::HandleButtonEvent: { - Controllers::ButtonActions action; + Controllers::ButtonActions action = Controllers::ButtonActions::None; if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) { action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release); } else { @@ -459,7 +458,7 @@ monitor.Process(); uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG); dateTimeController.UpdateTime(systick_counter); NoInit_BackUpTime = dateTimeController.CurrentDateTime(); - if (!nrf_gpio_pin_read(PinMap::Button)) { + if (nrf_gpio_pin_read(PinMap::Button) == 0) { watchdog.Kick(); } } @@ -552,10 +551,9 @@ state = SystemTaskState::GoingToSleep; } if (in_isr()) { - BaseType_t xHigherPriorityTaskWoken; - xHigherPriorityTaskWoken = pdFALSE; + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken); - if (xHigherPriorityTaskWoken) { + if (xHigherPriorityTaskWoken == pdTRUE) { /* Actual macro used here is port specific. */ portYIELD_FROM_ISR(xHigherPriorityTaskWoken); }