Skip to content

Commit

Permalink
Merge branch 'InfiniTimeOrg:develop' into dice
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufmte authored Dec 19, 2022
2 parents feb8d14 + afea7ca commit 7131e3c
Show file tree
Hide file tree
Showing 31 changed files with 247 additions and 269 deletions.
33 changes: 16 additions & 17 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -20,19 +21,17 @@ Checks: '*,
-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,
-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
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ link_directories(
)


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)
Expand Down
2 changes: 1 addition & 1 deletion src/components/alarm/AlarmController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : da

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();
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/components/battery/BatteryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Battery::Battery() {
}

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;
Expand Down Expand Up @@ -81,10 +81,8 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
// 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});
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ble/NavigationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace {
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
Expand Down
38 changes: 23 additions & 15 deletions src/components/heartrate/Ppg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ namespace {
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;
}
Expand All @@ -52,41 +53,48 @@ int8_t Ppg::Preprocess(float 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) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/heartrate/Ppg.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Pinetime {
public:
Ppg();
int8_t Preprocess(float spl);
float HeartRate();
int HeartRate();

void SetOffset(uint16_t i);
void SetOffset(uint16_t offset);
void Reset();

private:
Expand All @@ -25,7 +25,7 @@ namespace Pinetime {
Ptagc agc;
Biquad lpf;

float ProcessHeartRate();
int ProcessHeartRate();
};
}
}
8 changes: 5 additions & 3 deletions src/components/heartrate/Ptagc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ Ptagc::Ptagc(float start, float decay, float threshold) : peak {start}, decay {d
}

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;
Expand Down
5 changes: 2 additions & 3 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ bool MotionController::Should_RaiseWake(bool isSleeping) {
if (not isSleeping) {
if (y <= 0) {
return false;
} else {
lastYForWakeUp = 0;
return false;
}
lastYForWakeUp = 0;
return false;
}

if (y >= 0) {
Expand Down
10 changes: 4 additions & 6 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void DisplayApp::Refresh() {
}

Messages msg;
if (xQueueReceive(msgQueue, &msg, queueTimeout)) {
if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) {
switch (msg) {
case Messages::DimScreen:
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
Expand Down Expand Up @@ -489,10 +489,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)

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 {
Expand Down Expand Up @@ -536,8 +535,7 @@ void DisplayApp::Register(Pinetime::System::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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/displayapp/screens/FirmwareValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app,
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);

Expand Down
8 changes: 5 additions & 3 deletions src/displayapp/screens/HeartRate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ HeartRate::HeartRate(Pinetime::Applications::DisplayApp* app,

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);
}
Expand Down Expand Up @@ -110,8 +111,9 @@ void HeartRate::OnStartStopEvent(lv_event_t event) {
}

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");
}
}
12 changes: 6 additions & 6 deletions src/displayapp/screens/Motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand All @@ -28,13 +28,13 @@ Motion::Motion(Pinetime::Applications::DisplayApp* app, Controllers::MotionContr
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 ---");

Expand All @@ -58,5 +58,5 @@ void Motion::Refresh() {
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);
}
Loading

0 comments on commit 7131e3c

Please sign in to comment.