From 2f479e5fc7688ae47e99c0f4aead87c9cdc29123 Mon Sep 17 00:00:00 2001 From: Avamander Date: Fri, 25 Jun 2021 01:07:40 +0300 Subject: Fixed a bunch of format specifiers --- src/displayapp/screens/Steps.cpp | 6 +++--- src/displayapp/screens/SystemInfo.cpp | 4 ++-- src/displayapp/screens/Timer.cpp | 6 +++--- src/displayapp/screens/settings/SettingSteps.cpp | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index b485c975..cc78813f 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -30,8 +30,8 @@ Steps::Steps( lSteps = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); - lv_obj_set_style_local_text_font(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); - lv_label_set_text_fmt(lSteps, "%li", stepsCount); + lv_obj_set_style_local_text_font(lSteps, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lSteps, "%li", stepsCount); lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -20); lv_obj_t * lstepsL = lv_label_create(lv_scr_act(), nullptr); @@ -41,7 +41,7 @@ Steps::Steps( lv_obj_t * lstepsGoal = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lstepsGoal, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); - lv_label_set_text_fmt(lstepsGoal,"Goal\n%i", settingsController.GetStepsGoal()); + lv_label_set_text_fmt(lstepsGoal, "Goal\n%lu", settingsController.GetStepsGoal()); lv_label_set_align(lstepsGoal, LV_LABEL_ALIGN_CENTER); lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 60); diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 60e53ad6..f70b67fd 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -192,11 +192,11 @@ std::unique_ptr SystemInfo::CreateScreen3() { "\n" "#444444 LVGL Memory#\n" " #444444 used# %d (%d%%)\n" - " #444444 max used# %d\n" + " #444444 max used# %lu\n" " #444444 frag# %d%%\n" " #444444 free# %d" "\n" - "#444444 Steps# %li", + "#444444 Steps# %i", bleAddr[5], bleAddr[4], bleAddr[3], diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp index 260a17ef..99e979ba 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer.cpp @@ -63,8 +63,8 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); uint32_t seconds = timerController.GetTimeRemaining() / 1000; - lv_label_set_text_fmt(time, "%02d:%02d", seconds / 60, seconds % 60); - + lv_label_set_text_fmt(time, "%02lu:%02lu", seconds / 60, seconds % 60); + lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20); btnPlayPause = lv_btn_create(lv_scr_act(), nullptr); @@ -90,7 +90,7 @@ Timer::~Timer() { bool Timer::Refresh() { if (timerController.IsRunning()) { uint32_t seconds = timerController.GetTimeRemaining() / 1000; - lv_label_set_text_fmt(time, "%02d:%02d", seconds / 60, seconds % 60); + lv_label_set_text_fmt(time, "%02lu:%02lu", seconds / 60, seconds % 60); } return running; } diff --git a/src/displayapp/screens/settings/SettingSteps.cpp b/src/displayapp/screens/settings/SettingSteps.cpp index b7c024f1..faa843e6 100644 --- a/src/displayapp/screens/settings/SettingSteps.cpp +++ b/src/displayapp/screens/settings/SettingSteps.cpp @@ -45,7 +45,7 @@ SettingSteps::SettingSteps( stepValue = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); - lv_label_set_text_fmt(stepValue,"%i", settingsController.GetStepsGoal()); + lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal()); lv_label_set_align(stepValue, LV_LABEL_ALIGN_CENTER); lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10); @@ -81,7 +81,7 @@ void SettingSteps::UpdateSelected(lv_obj_t *object, lv_event_t event) { value += 1000; if ( value <= 500000 ) { settingsController.SetStepsGoal(value); - lv_label_set_text_fmt(stepValue,"%i", settingsController.GetStepsGoal()); + lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal()); lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10); } } @@ -90,7 +90,7 @@ void SettingSteps::UpdateSelected(lv_obj_t *object, lv_event_t event) { value -= 1000; if ( value >= 1000 ) { settingsController.SetStepsGoal(value); - lv_label_set_text_fmt(stepValue,"%i", settingsController.GetStepsGoal()); + lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal()); lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10); } } -- cgit v1.2.3 From bdb5965f1a3432a4f24b5fc566973bf4ab811b08 Mon Sep 17 00:00:00 2001 From: Avamander Date: Fri, 25 Jun 2021 00:40:55 +0300 Subject: static_cast cleanup --- src/components/battery/BatteryController.cpp | 2 +- src/displayapp/screens/SystemInfo.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index bc146457..b153b980 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -14,7 +14,7 @@ Battery::Battery() { } void Battery::Init() { - nrf_gpio_cfg_input(chargingPin, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup); + nrf_gpio_cfg_input(chargingPin, static_cast GPIO_PIN_CNF_PULL_Pullup); } void Battery::Update() { diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index f70b67fd..1e90bf40 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -203,11 +203,11 @@ std::unique_ptr SystemInfo::CreateScreen3() { bleAddr[2], bleAddr[1], bleAddr[0], - (int) mon.total_size - mon.free_size, + static_cast(mon.total_size - mon.free_size), mon.used_pct, mon.max_used, mon.frag_pct, - (int) mon.free_biggest_size, + static_cast(mon.free_biggest_size), 0); lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); return std::make_unique(2, 5, app, label); -- cgit v1.2.3 From 7075b7f264d1c5ae3a2b7d2fc26e1d0ad36b2616 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 23 Jun 2021 13:08:51 +0300 Subject: Fix call notification button alignment --- src/displayapp/screens/Notifications.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 1a1729ea..38b12420 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -163,10 +163,10 @@ Notifications::NotificationItem::NotificationItem(const char* title, lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); lv_obj_set_pos(container1, 0, 50); - lv_obj_set_width(container1, 240); - lv_obj_set_height(container1, 190); + lv_obj_set_size(container1, LV_HOR_RES, 190); lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + lv_cont_set_fit(container1, LV_FIT_NONE); lv_obj_t* alert_count = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(alert_count, "%i/%i", notifNr, notifNb); @@ -198,6 +198,7 @@ Notifications::NotificationItem::NotificationItem(const char* title, lv_label_set_text(alert_subject, msg); } break; case Controllers::NotificationManager::Categories::IncomingCall: { + lv_obj_set_height(container1, 108); lv_obj_t* alert_subject = lv_label_create(container1, nullptr); lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); @@ -210,38 +211,29 @@ Notifications::NotificationItem::NotificationItem(const char* title, lv_obj_set_width(alert_caller, LV_HOR_RES - 20); lv_label_set_text(alert_caller, msg); - lv_obj_t* callBtnContainer = lv_cont_create(container1, NULL); - lv_obj_set_width(callBtnContainer, 240); - lv_obj_set_height(callBtnContainer, 90); - lv_cont_set_layout(callBtnContainer, LV_LAYOUT_ROW_MID); - - lv_obj_set_style_local_bg_color(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222)); - lv_obj_set_style_local_pad_all(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - lv_obj_set_style_local_margin_top(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 40); - lv_obj_set_style_local_margin_left(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, -8); - lv_obj_set_style_local_pad_inner(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); - lv_obj_set_style_local_border_width(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - - bt_accept = lv_btn_create(callBtnContainer, nullptr); + bt_accept = lv_btn_create(lv_scr_act(), nullptr); bt_accept->user_data = this; lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler); - lv_obj_set_size(bt_accept, (LV_HOR_RES / 3) - 5, 80); + lv_obj_set_size(bt_accept, 76, 76); + lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); label_accept = lv_label_create(bt_accept, nullptr); lv_label_set_text(label_accept, Symbols::phone); lv_obj_set_style_local_bg_color(bt_accept, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); - bt_reject = lv_btn_create(callBtnContainer, nullptr); + bt_reject = lv_btn_create(lv_scr_act(), nullptr); bt_reject->user_data = this; lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler); - lv_obj_set_size(bt_reject, (LV_HOR_RES / 3) - 5, 80); + lv_obj_set_size(bt_reject, 76, 76); + lv_obj_align(bt_reject, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); label_reject = lv_label_create(bt_reject, nullptr); lv_label_set_text(label_reject, Symbols::phoneSlash); lv_obj_set_style_local_bg_color(bt_reject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - bt_mute = lv_btn_create(callBtnContainer, nullptr); + bt_mute = lv_btn_create(lv_scr_act(), nullptr); bt_mute->user_data = this; lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler); - lv_obj_set_size(bt_mute, (LV_HOR_RES / 3) - 5, 80); + lv_obj_set_size(bt_mute, 76, 76); + lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); label_mute = lv_label_create(bt_mute, nullptr); lv_label_set_text(label_mute, Symbols::volumMute); lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); -- cgit v1.2.3 From 38f40034b0a200586429a3d8329479ad13d84d94 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 2 Jul 2021 18:30:32 +0300 Subject: Float voltage to int (#444) * Change voltage float to millivolt integer * Explain the ADC to milliVolts conversion --- src/components/battery/BatteryController.cpp | 14 +++++++++----- src/components/battery/BatteryController.h | 6 +++--- src/displayapp/screens/BatteryInfo.cpp | 17 ++--------------- src/displayapp/screens/BatteryInfo.h | 2 +- src/displayapp/screens/SystemInfo.cpp | 12 ++---------- 5 files changed, 17 insertions(+), 34 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index b153b980..02901dd8 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -55,17 +55,21 @@ void Battery::SaadcInit() { void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { - const float battery_max = 4.18; // maximum voltage of battery ( max charging voltage is 4.21 ) - const float battery_min = 3.20; // minimum voltage of battery before shutdown ( depends on the battery ) + const uint16_t battery_max = 4180; // maximum voltage of battery ( max charging voltage is 4.21 ) + const uint16_t battery_min = 3200; // minimum voltage of battery before shutdown ( depends on the battery ) if (p_event->type == NRFX_SAADC_EVT_DONE) { APP_ERROR_CHECK(nrfx_saadc_buffer_convert(&saadc_value, 1)); - voltage = (static_cast(p_event->data.done.p_buffer[0]) * 2.04f) / (1024 / 3.0f); - voltage = roundf(voltage * 100) / 100; + // A hardware voltage divider divides the battery voltage by 2 + // ADC gain is 1/5 + // thus adc_voltage = battery_voltage / 2 * gain = battery_voltage / 10 + // reference_voltage is 0.6V + // p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024 + voltage = p_event->data.done.p_buffer[0] * 6000 / 1024; - percentRemaining = static_cast(((voltage - battery_min) / (battery_max - battery_min)) * 100); + percentRemaining = (voltage - battery_min) * 100 / (battery_max - battery_min); percentRemaining = std::max(percentRemaining, 0); percentRemaining = std::min(percentRemaining, 100); diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 04bcf6b8..26e24938 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -50,7 +50,7 @@ namespace Pinetime { return percentRemainingBuffer.GetAverage(); } - float Voltage() const { + uint16_t Voltage() const { return voltage; } @@ -71,7 +71,7 @@ namespace Pinetime { static constexpr uint32_t chargingPin = 12; static constexpr uint32_t powerPresentPin = 19; static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7; - float voltage = 0.0f; + uint16_t voltage = 0; int percentRemaining = -1; bool isCharging = false; @@ -86,4 +86,4 @@ namespace Pinetime { uint8_t samples = 0; }; } -} \ No newline at end of file +} diff --git a/src/displayapp/screens/BatteryInfo.cpp b/src/displayapp/screens/BatteryInfo.cpp index 1ab8b0ad..87c8b4bb 100644 --- a/src/displayapp/screens/BatteryInfo.cpp +++ b/src/displayapp/screens/BatteryInfo.cpp @@ -46,16 +46,9 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT); lv_obj_align(percent, nullptr, LV_ALIGN_CENTER, 0, -60); - // hack to not use the flot functions from printf - uint8_t batteryVoltageBytes[2]; - batteryVoltageBytes[1] = static_cast(batteryVoltage); // truncate whole numbers - batteryVoltageBytes[0] = - static_cast((batteryVoltage - batteryVoltageBytes[1]) * 100); // remove whole part of flt and shift 2 places over - // - voltage = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(voltage, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xC6A600)); - lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltageBytes[1], batteryVoltageBytes[0]); + lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10); lv_label_set_align(voltage, LV_LABEL_ALIGN_CENTER); lv_obj_align(voltage, nullptr, LV_ALIGN_CENTER, 0, 95); @@ -129,13 +122,7 @@ void BatteryInfo::UpdateScreen() { } lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); - // hack to not use the flot functions from printf - uint8_t batteryVoltageBytes[2]; - batteryVoltageBytes[1] = static_cast(batteryVoltage); // truncate whole numbers - batteryVoltageBytes[0] = - static_cast((batteryVoltage - batteryVoltageBytes[1]) * 100); // remove whole part of flt and shift 2 places over - // - lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltageBytes[1], batteryVoltageBytes[0]); + lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10); } bool BatteryInfo::Refresh() { diff --git a/src/displayapp/screens/BatteryInfo.h b/src/displayapp/screens/BatteryInfo.h index 8805db58..346dc571 100644 --- a/src/displayapp/screens/BatteryInfo.h +++ b/src/displayapp/screens/BatteryInfo.h @@ -37,7 +37,7 @@ namespace Pinetime { int8_t animation = 0; int8_t batteryPercent = -1; - float batteryVoltage = 0.0f; + uint16_t batteryVoltage = 0; }; } } diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 1e90bf40..5ae3a595 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -104,8 +104,6 @@ std::unique_ptr SystemInfo::CreateScreen1() { std::unique_ptr SystemInfo::CreateScreen2() { auto batteryPercent = static_cast(batteryController.PercentRemaining()); - float batteryVoltage = batteryController.Voltage(); - auto resetReason = [this]() { switch (watchdog.ResetReason()) { case Drivers::Watchdog::ResetReasons::Watchdog: @@ -144,18 +142,13 @@ std::unique_ptr SystemInfo::CreateScreen2() { uptimeSeconds = uptimeSeconds % secondsInAMinute; // TODO handle more than 100 days of uptime - // hack to not use the flot functions from printf - uint8_t batteryVoltageBytes[2]; - batteryVoltageBytes[1] = static_cast(batteryVoltage); // truncate whole numbers - batteryVoltageBytes[0] = static_cast((batteryVoltage - batteryVoltageBytes[1]) * 100); // remove whole part of flt and shift 2 places over - lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_label_set_recolor(label, true); lv_label_set_text_fmt(label, "#444444 Date# %02d/%02d/%04d\n" "#444444 Time# %02d:%02d:%02d\n" "#444444 Uptime#\n %02lud %02lu:%02lu:%02lu\n" - "#444444 Battery# %d%%/%1i.%02iv\n" + "#444444 Battery# %d%%/%03imV\n" "#444444 Backlight# %s\n" "#444444 Last reset# %s\n" "#444444 Accel.# %s\n", @@ -170,8 +163,7 @@ std::unique_ptr SystemInfo::CreateScreen2() { uptimeMinutes, uptimeSeconds, batteryPercent, - batteryVoltageBytes[1], - batteryVoltageBytes[0], + batteryController.Voltage(), brightnessController.ToString(), resetReason, ToString(motionController.DeviceType())); -- cgit v1.2.3 From 4e435e93e0b4db101f9232661ee4147a90084df0 Mon Sep 17 00:00:00 2001 From: Bryton Hall Date: Fri, 2 Jul 2021 11:34:32 -0400 Subject: and metronome icon (#439) * add drum icon for metronome app --- src/displayapp/fonts/README.md | 2 +- src/displayapp/fonts/jetbrains_mono_bold_20.c | 21 ++++++++++++++++----- src/displayapp/screens/ApplicationList.cpp | 2 +- src/displayapp/screens/Symbols.h | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/fonts/README.md b/src/displayapp/fonts/README.md index 13b61b8e..ec4beb88 100644 --- a/src/displayapp/fonts/README.md +++ b/src/displayapp/fonts/README.md @@ -13,7 +13,7 @@ * Do not enable font compression and horizontal subpixel hinting * Load the file `JetBrainsMono-Bold.tff` (use the file in this repo to ensure the version matches) and specify the following range : `0x20-0x7f, 0x410-0x44f` * Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following - range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252` + range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569` * Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts` * Add the font .c file path to src/CMakeLists.txt * Add an LV_FONT_DECLARE line in src/libs/lv_conf.h diff --git a/src/displayapp/fonts/jetbrains_mono_bold_20.c b/src/displayapp/fonts/jetbrains_mono_bold_20.c index b001bb7e..98243bb4 100644 --- a/src/displayapp/fonts/jetbrains_mono_bold_20.c +++ b/src/displayapp/fonts/jetbrains_mono_bold_20.c @@ -979,6 +979,16 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = { 0x1f, 0xf0, 0x0, 0xfe, 0x0, 0x7, 0xc0, 0x0, 0x38, 0x0, 0x1, 0x0, 0x0, + /* U+F569 "" */ + 0x0, 0x0, 0x4, 0x0, 0x0, 0x3c, 0x0, 0x0, + 0xf0, 0x0, 0x7, 0xc0, 0x1f, 0xfe, 0x3, 0xff, + 0xfe, 0xf, 0x87, 0xfe, 0x38, 0x3e, 0xe, 0xc0, + 0xf8, 0x7, 0x81, 0xc0, 0xf, 0x0, 0x0, 0x1f, + 0x80, 0x0, 0xff, 0xe0, 0xf, 0xff, 0xff, 0xff, + 0xf9, 0xff, 0xf3, 0xf3, 0xe3, 0xe7, 0xe7, 0xc7, + 0xce, 0xcf, 0x8f, 0x98, 0x9f, 0x1f, 0x20, 0x3e, + 0x3e, 0x0, 0x4, 0x60, 0x0, + /* U+F59F "" */ 0x0, 0x78, 0x0, 0x7, 0xf8, 0x0, 0x1f, 0xe0, 0x0, 0xff, 0xc0, 0x3, 0xff, 0x0, 0xf, 0xfc, @@ -1204,9 +1214,10 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { {.bitmap_index = 3750, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2}, {.bitmap_index = 3800, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, {.bitmap_index = 3860, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3}, - {.bitmap_index = 3913, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2}, - {.bitmap_index = 3968, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, - {.bitmap_index = 4021, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0} + {.bitmap_index = 3913, .adv_w = 360, .box_w = 23, .box_h = 21, .ofs_x = 0, .ofs_y = -3}, + {.bitmap_index = 3974, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2}, + {.bitmap_index = 4029, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, + {.bitmap_index = 4082, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0} }; /*--------------------- @@ -1218,7 +1229,7 @@ static const uint16_t unicode_list_2[] = { 0x4a, 0x4b, 0x4c, 0x50, 0x68, 0x94, 0x128, 0x184, 0x1e5, 0x1fb, 0x21d, 0x23f, 0x240, 0x241, 0x242, 0x243, 0x251, 0x292, 0x293, 0x2f1, 0x3dc, 0x3fc, 0x45c, 0x54a, - 0x55f, 0x59e, 0x59f, 0x6a8 + 0x55f, 0x568, 0x59e, 0x59f, 0x6a8 }; /*Collect the unicode lists and glyph_id offsets*/ @@ -1234,7 +1245,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] = }, { .range_start = 61441, .range_length = 1705, .glyph_id_start = 160, - .unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 36, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY + .unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 37, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY } }; diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index d434c177..78c7cd9a 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -63,7 +63,7 @@ std::unique_ptr ApplicationList::CreateScreen2() { {Symbols::paddle, Apps::Paddle}, {"2", Apps::Twos}, {"M", Apps::Motion}, - {"b", Apps::Metronome}, + {Symbols::drum, Apps::Metronome}, {"", Apps::None}, }}; diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index 8d55f693..c9d61541 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -40,6 +40,7 @@ namespace Pinetime { static constexpr const char* stopWatch = "\xEF\x8B\xB2"; static constexpr const char* hourGlass = "\xEF\x89\x92"; static constexpr const char* lapsFlag = "\xEF\x80\xA4"; + static constexpr const char* drum = "\xEF\x95\xA9"; // lv_font_sys_48.c static constexpr const char* settings = "\xEE\xA4\x82"; // e902 -- cgit v1.2.3 From 217f16d18976a6304e411c00f2ccd72f4bd831a7 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 24 Jun 2021 13:33:15 +0300 Subject: Improve paddle game --- src/displayapp/screens/Paddle.cpp | 154 ++++++++++---------------------------- src/displayapp/screens/Paddle.h | 22 +++--- 2 files changed, 50 insertions(+), 126 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 161f175b..5a939ac7 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -4,98 +4,31 @@ using namespace Pinetime::Applications::Screens; -namespace { - const uint8_t paddle_map[] = { - 0xfc, 0xfe, 0xfc, 0xff, /*Color of index 0*/ - 0xff, 0xff, 0xff, 0xff, /*Color of index 1*/ - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }; - - const uint8_t ball_map[] = { - 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, - 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, - 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, - }; -} - Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl {lvgl} { app->SetTouchMode(DisplayApp::TouchModes::Polling); + background = lv_obj_create(lv_scr_act(), nullptr); + lv_obj_set_size(background, LV_HOR_RES + 1, LV_VER_RES); + lv_obj_set_pos(background, -1, 0); + lv_obj_set_style_local_radius(background, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); + lv_obj_set_style_local_bg_color(background, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_border_color(background, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_border_width(background, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 1); + points = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(points, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text(points, "0000"); - lv_obj_set_style_local_text_color(points, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x444444)); - lv_obj_align(points, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0); + lv_obj_align(points, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 10); - paddle.header.always_zero = 0; - paddle.header.w = 4; - paddle.header.h = 60; - paddle.data_size = 68; - paddle.header.cf = LV_IMG_CF_INDEXED_1BIT; - paddle.data = paddle_map; - paddle_image = lv_img_create(lv_scr_act(), nullptr); - lv_img_set_src(paddle_image, &paddle); + paddle = lv_obj_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_bg_color(paddle, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_radius(paddle, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); + lv_obj_set_size(paddle, 4, 60); - ball.header.always_zero = 0; - ball.header.w = 24; - ball.header.h = 24; - ball.data_size = 24 * 24 * LV_COLOR_SIZE / 8; - ball.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED; - ball.data = ball_map; - ball_image = lv_img_create(lv_scr_act(), nullptr); - lv_img_set_src(ball_image, &ball); + ball = lv_obj_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_bg_color(ball, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_radius(ball, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); + lv_obj_set_size(ball, ballSize, ballSize); } Paddle::~Paddle() { @@ -105,41 +38,37 @@ Paddle::~Paddle() { } bool Paddle::Refresh() { - if ((counter++ % 5) == 0) { - counter = 0; - - ballX += dx; - ballY += dy; + ballX += dx; + ballY += dy; - lv_obj_set_pos(ball_image, ballX, ballY); + lv_obj_set_pos(ball, ballX, ballY); - // checks if it has touched the sides (floor and ceiling) - if (ballY <= 0 || ballY >= 215) { - dy *= -1; - } + // checks if it has touched the sides (floor and ceiling) + if (ballY <= 1 || ballY >= LV_VER_RES - ballSize - 2) { + dy *= -1; + } - // checks if it has touched the side (left side) - if (ballX >= 215) { - dx *= -1; - } + // checks if it has touched the side (left side) + if (ballX >= LV_VER_RES - ballSize - 1) { + dx *= -1; + } - // checks if it is in the position of the paddle - if (ballY <= (paddleBottomY + 16) && ballY >= (paddleTopY - 8)) { - if (ballX >= 0 && ballX < 4) { - lv_obj_set_pos(ball_image, 5, ballY); + // checks if it is in the position of the paddle + if (dx < 0 && ballX <= 4) { + if (ballX >= -ballSize / 4) { + if (ballY <= (paddlePos + 30 - ballSize / 4) && ballY >= (paddlePos - 30 - ballSize + ballSize / 4)) { dx *= -1; score++; } } - // checks if it has gone behind the paddle - else if (ballX <= -40) { - ballX = 107; - ballY = 107; + else if (ballX <= -ballSize * 2) { + ballX = (LV_HOR_RES - ballSize) / 2; + ballY = (LV_VER_RES - ballSize) / 2; score = 0; } - lv_label_set_text_fmt(points, "%04d", score); } + lv_label_set_text_fmt(points, "%04d", score); return running; } @@ -148,11 +77,8 @@ bool Paddle::OnTouchEvent(Pinetime::Applications::TouchEvents event) { } bool Paddle::OnTouchEvent(uint16_t x, uint16_t y) { - lv_obj_set_pos( - paddle_image, - 0, - y - 30); // sets the center paddle pos. (30px offset) with the the y_coordinate of the finger and defaults the x_coordinate to 0 - paddleTopY = y - 30; // refreshes the upper extreme of the paddle - paddleBottomY = y + 30; // refreshes the lower extreme of the paddle + // sets the center paddle pos. (30px offset) with the the y_coordinate of the finger + lv_obj_set_pos(paddle, 0, y - 30); + paddlePos = y; return true; } diff --git a/src/displayapp/screens/Paddle.h b/src/displayapp/screens/Paddle.h index e133244f..30ab8f94 100644 --- a/src/displayapp/screens/Paddle.h +++ b/src/displayapp/screens/Paddle.h @@ -24,24 +24,22 @@ namespace Pinetime { private: Pinetime::Components::LittleVgl& lvgl; - int paddleBottomY = 90; // bottom extreme of the paddle - int paddleTopY = 150; // top extreme of the paddle + const uint8_t ballSize = 16; - int ballX = 107; // Initial x_coordinate for the ball (12px offset from the center to counteract the ball's 24px size) - int ballY = 107; // Initial y_coordinate for the ball + uint16_t paddlePos = 30; // Paddle center - int dx = 2; // Velocity of the ball in the x_coordinate - int dy = 3; // Velocity of the ball in the y_coordinate + int16_t ballX = (LV_HOR_RES - ballSize) / 2; + int16_t ballY = (LV_VER_RES - ballSize) / 2; - int counter = 0; // init Frame refresh limit counter - int score = 0; + int8_t dx = 2; // Velocity of the ball in the x_coordinate + int8_t dy = 3; // Velocity of the ball in the y_coordinate - lv_img_dsc_t paddle; - lv_img_dsc_t ball; + uint16_t score = 0; lv_obj_t* points; - lv_obj_t* paddle_image; // pointer to paddle image - lv_obj_t* ball_image; // pointer to ball image + lv_obj_t* paddle; + lv_obj_t* ball; + lv_obj_t* background; }; } } -- cgit v1.2.3 From 94aefed98f1c7a70776863ce235db255affd1640 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 3 Jul 2021 13:32:35 +0300 Subject: Condense firmware validation code --- src/displayapp/screens/FirmwareValidation.cpp | 31 ++++++++------------------- src/displayapp/screens/FirmwareValidation.h | 7 +----- 2 files changed, 10 insertions(+), 28 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp index ad37a3df..d9f162d4 100644 --- a/src/displayapp/screens/FirmwareValidation.cpp +++ b/src/displayapp/screens/FirmwareValidation.cpp @@ -16,30 +16,17 @@ namespace { FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::FirmwareValidator& validator) : Screen {app}, validator {validator} { - labelVersionInfo = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(labelVersionInfo, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); - lv_label_set_text(labelVersionInfo, "Version : "); - lv_label_set_align(labelVersionInfo, LV_LABEL_ALIGN_LEFT); - - labelVersionValue = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(labelVersionValue, labelVersionInfo, LV_ALIGN_OUT_RIGHT_MID, 0, 0); - lv_label_set_recolor(labelVersionValue, true); - sprintf(version, "%ld.%ld.%ld", Version::Major(), Version::Minor(), Version::Patch()); - lv_label_set_text(labelVersionValue, version); - - labelShortRefInfo = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(labelShortRefInfo, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 25); - lv_label_set_text(labelShortRefInfo, "ShortRef : "); - lv_label_set_align(labelShortRefInfo, LV_LABEL_ALIGN_LEFT); - - labelShortRefValue = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(labelShortRefValue, labelShortRefInfo, LV_ALIGN_OUT_RIGHT_MID, 0, 0); - lv_label_set_recolor(labelShortRefValue, true); - sprintf(shortref, "%s", Version::GitCommitHash()); - lv_label_set_text(labelShortRefValue, shortref); + labelVersion = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_fmt(labelVersion, "Version : %d.%d.%d\n" + "ShortRef : %s", + Version::Major(), + Version::Minor(), + Version::Patch(), + Version::GitCommitHash()); + lv_obj_align(labelVersion, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); labelIsValidated = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(labelIsValidated, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 50); + lv_obj_align(labelIsValidated, labelVersion, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); lv_label_set_recolor(labelIsValidated, true); lv_label_set_long_mode(labelIsValidated, LV_LABEL_LONG_BREAK); lv_obj_set_width(labelIsValidated, 240); diff --git a/src/displayapp/screens/FirmwareValidation.h b/src/displayapp/screens/FirmwareValidation.h index 303c2154..1ef5ba0a 100644 --- a/src/displayapp/screens/FirmwareValidation.h +++ b/src/displayapp/screens/FirmwareValidation.h @@ -23,12 +23,7 @@ namespace Pinetime { private: Pinetime::Controllers::FirmwareValidator& validator; - lv_obj_t* labelVersionInfo; - lv_obj_t* labelVersionValue; - lv_obj_t* labelShortRefInfo; - lv_obj_t* labelShortRefValue; - char version[9]; - char shortref[9]; + lv_obj_t* labelVersion; lv_obj_t* labelIsValidated; lv_obj_t* buttonValidate; lv_obj_t* labelButtonValidate; -- cgit v1.2.3 From 3b0fcc2a73c81bc5e0da301fbbe95fdfd09339de Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 3 Jul 2021 13:44:12 +0300 Subject: clang-format --- src/displayapp/screens/FirmwareValidation.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp index d9f162d4..1d05be8d 100644 --- a/src/displayapp/screens/FirmwareValidation.cpp +++ b/src/displayapp/screens/FirmwareValidation.cpp @@ -17,12 +17,13 @@ namespace { FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::FirmwareValidator& validator) : Screen {app}, validator {validator} { labelVersion = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_fmt(labelVersion, "Version : %d.%d.%d\n" - "ShortRef : %s", - Version::Major(), - Version::Minor(), - Version::Patch(), - Version::GitCommitHash()); + lv_label_set_text_fmt(labelVersion, + "Version : %d.%d.%d\n" + "ShortRef : %s", + Version::Major(), + Version::Minor(), + Version::Patch(), + Version::GitCommitHash()); lv_obj_align(labelVersion, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); labelIsValidated = lv_label_create(lv_scr_act(), nullptr); -- cgit v1.2.3 From ab59b9b8301d95206a2f77a4e32e4f6552361a2e Mon Sep 17 00:00:00 2001 From: Avamander Date: Sun, 4 Jul 2021 21:06:50 +0300 Subject: Whitespace and brace fixes (#456) * Brace style and whitespace fixes * Additional whitespace fixes --- src/components/battery/BatteryController.cpp | 3 ++- src/displayapp/screens/Steps.cpp | 29 +++++++++++++--------------- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index 02901dd8..76ad8cb3 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -22,8 +22,9 @@ void Battery::Update() { isCharging = !nrf_gpio_pin_read(chargingPin); isPowerPresent = !nrf_gpio_pin_read(powerPresentPin); - if (isReading) + if (isReading) { return; + } // Non blocking read samples = 0; isReading = true; diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp index cc78813f..6aabd30e 100644 --- a/src/displayapp/screens/Steps.cpp +++ b/src/displayapp/screens/Steps.cpp @@ -6,19 +6,19 @@ using namespace Pinetime::Applications::Screens; Steps::Steps( - Pinetime::Applications::DisplayApp *app, + Pinetime::Applications::DisplayApp *app, Controllers::MotionController& motionController, - Controllers::Settings &settingsController) - : Screen(app), + Controllers::Settings &settingsController) + : Screen(app), motionController{motionController}, settingsController{settingsController} { stepsArc = lv_arc_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_bg_opa(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); - lv_obj_set_style_local_border_width(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 2); - lv_obj_set_style_local_radius(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); - lv_obj_set_style_local_line_color(stepsArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, lv_color_hex(0x0000FF)); + lv_obj_set_style_local_bg_opa(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); + lv_obj_set_style_local_border_width(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 2); + lv_obj_set_style_local_radius(stepsArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); + lv_obj_set_style_local_line_color(stepsArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, lv_color_hex(0x0000FF)); lv_arc_set_end_angle(stepsArc, 200); lv_obj_set_size(stepsArc, 220, 220); lv_arc_set_range(stepsArc, 0, 500); @@ -36,7 +36,7 @@ Steps::Steps( lv_obj_t * lstepsL = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lstepsL, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_label_set_text_static(lstepsL, "Steps"); + lv_label_set_text_static(lstepsL, "Steps"); lv_obj_align(lstepsL, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); lv_obj_t * lstepsGoal = lv_label_create(lv_scr_act(), nullptr); @@ -45,12 +45,11 @@ Steps::Steps( lv_label_set_align(lstepsGoal, LV_LABEL_ALIGN_CENTER); lv_obj_align(lstepsGoal, lSteps, LV_ALIGN_OUT_BOTTOM_MID, 0, 60); - lv_obj_t * backgroundLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); lv_obj_set_size(backgroundLabel, 240, 240); lv_obj_set_pos(backgroundLabel, 0, 0); lv_label_set_text_static(backgroundLabel, ""); - } Steps::~Steps() { @@ -58,15 +57,13 @@ Steps::~Steps() { } bool Steps::Refresh() { - - stepsCount = motionController.NbSteps(); - lv_label_set_text_fmt(lSteps,"%li", stepsCount); + stepsCount = motionController.NbSteps(); + + lv_label_set_text_fmt(lSteps, "%li", stepsCount); lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -20); - + lv_arc_set_value(stepsArc, int16_t(500 * stepsCount / settingsController.GetStepsGoal())); return running; } - - -- cgit v1.2.3 From 61a4642221fc9fcab6889221e7bf9c29778589f2 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 4 Jul 2021 21:23:03 +0300 Subject: Improve stopwatch (#432) * Improve stopwatch more * Make sure sleep gets reenabled * Cleanup and clang-format --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/StopWatch.cpp | 197 +++++++++++++++-------------------- src/displayapp/screens/StopWatch.h | 16 +-- 3 files changed, 95 insertions(+), 120 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index de93428c..04ebd2d3 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -337,7 +337,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None); break; case Apps::StopWatch: - currentScreen = std::make_unique(this); + currentScreen = std::make_unique(this, *systemTask); break; case Apps::Twos: currentScreen = std::make_unique(this); diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp index 7c128d1b..f4db5d6e 100644 --- a/src/displayapp/screens/StopWatch.cpp +++ b/src/displayapp/screens/StopWatch.cpp @@ -45,17 +45,16 @@ static void stop_lap_event_handler(lv_obj_t* obj, lv_event_t event) { stopWatch->stopLapBtnEventHandler(event); } -StopWatch::StopWatch(DisplayApp* app) +StopWatch::StopWatch(DisplayApp* app, System::SystemTask& systemTask) : Screen(app), + systemTask {systemTask}, running {true}, currentState {States::Init}, - currentEvent {Events::Stop}, startTime {}, oldTimeElapsed {}, currentTimeSeparated {}, lapBuffer {}, - lapNr {}, - lapPressed {false} { + lapNr {} { time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); @@ -105,128 +104,100 @@ StopWatch::StopWatch(DisplayApp* app) } StopWatch::~StopWatch() { + systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); lv_obj_clean(lv_scr_act()); } +void StopWatch::reset() { + currentState = States::Init; + oldTimeElapsed = 0; + lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + + lv_label_set_text(time, "00:00"); + lv_label_set_text(msecTime, "00"); + + lv_label_set_text(lapOneText, ""); + lv_label_set_text(lapTwoText, ""); + lapBuffer.clearBuffer(); + lapNr = 0; + lv_obj_set_state(btnStopLap, LV_STATE_DISABLED); + lv_obj_set_state(txtStopLap, LV_STATE_DISABLED); +} + +void StopWatch::start() { + lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT); + lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT); + lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); + lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); + lv_label_set_text(txtPlayPause, Symbols::pause); + lv_label_set_text(txtStopLap, Symbols::lapsFlag); + startTime = xTaskGetTickCount(); + currentState = States::Running; + systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping); +} + +void StopWatch::pause() { + startTime = 0; + // Store the current time elapsed in cache + oldTimeElapsed += timeElapsed; + currentState = States::Halted; + lv_label_set_text(txtPlayPause, Symbols::play); + lv_label_set_text(txtStopLap, Symbols::stop); + lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); + lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); + systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); +} + bool StopWatch::Refresh() { - // @startuml CHIP8_state - // State "Init" as init - // State "Running" as run - // State "Halted" as halt - - // [*] --> init - // init -> run : press play - // run -> run : press lap - // run --> halt : press pause - // halt --> run : press play - // halt --> init : press stop - // @enduml - // Copy paste the above plantuml text to visualize the state diagram - switch (currentState) { - // Init state when an user first opens the app - // and when a stop/reset button is pressed - case States::Init: { - // The initial default value - lv_label_set_text(time, "00:00"); - lv_label_set_text(msecTime, "00"); - - lv_label_set_text(lapOneText, ""); - lv_label_set_text(lapTwoText, ""); - lapBuffer.clearBuffer(); - lapNr = 0; - - if (currentEvent == Events::Play) { - lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT); - lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT); - - startTime = xTaskGetTickCount(); - currentState = States::Running; - } else { - lv_obj_set_state(btnStopLap, LV_STATE_DISABLED); - lv_obj_set_state(txtStopLap, LV_STATE_DISABLED); - } - break; - } - case States::Running: { - lv_label_set_text(txtPlayPause, Symbols::pause); - lv_label_set_text(txtStopLap, Symbols::lapsFlag); - - const auto timeElapsed = calculateDelta(startTime, xTaskGetTickCount()); - currentTimeSeparated = convertTicksToTimeSegments((oldTimeElapsed + timeElapsed)); - - lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs); - lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths); - - if (lapPressed == true) { - if (lapBuffer[1]) { - lv_label_set_text_fmt( - lapOneText, "#%2d %2d:%02d.%02d", (lapNr - 1), lapBuffer[1]->mins, lapBuffer[1]->secs, lapBuffer[1]->hundredths); - } - if (lapBuffer[0]) { - lv_label_set_text_fmt( - lapTwoText, "#%2d %2d:%02d.%02d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->hundredths); - } - // Reset the bool to avoid setting the text in each cycle until there is a change - lapPressed = false; - } - - if (currentEvent == Events::Pause) { - // Reset the start time - startTime = 0; - // Store the current time elapsed in cache - oldTimeElapsed += timeElapsed; - currentState = States::Halted; - lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - } else { - lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); - lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); - } - break; - } - case States::Halted: { - lv_label_set_text(txtPlayPause, Symbols::play); - lv_label_set_text(txtStopLap, Symbols::stop); - - if (currentEvent == Events::Play) { - startTime = xTaskGetTickCount(); - currentState = States::Running; - } - if (currentEvent == Events::Stop) { - currentState = States::Init; - oldTimeElapsed = 0; - lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - } - break; - } + if (currentState == States::Running) { + timeElapsed = calculateDelta(startTime, xTaskGetTickCount()); + currentTimeSeparated = convertTicksToTimeSegments((oldTimeElapsed + timeElapsed)); + + lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs); + lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths); } return running; } void StopWatch::playPauseBtnEventHandler(lv_event_t event) { - if (event == LV_EVENT_CLICKED) { - if (currentState == States::Init) { - currentEvent = Events::Play; - } else { - // Simple Toggle for play/pause - currentEvent = (currentEvent == Events::Play ? Events::Pause : Events::Play); - } + if (event != LV_EVENT_PRESSED) { + return; + } + if (currentState == States::Init) { + start(); + } else if (currentState == States::Running) { + pause(); + } else if (currentState == States::Halted) { + start(); } } void StopWatch::stopLapBtnEventHandler(lv_event_t event) { - if (event == LV_EVENT_CLICKED) { - // If running, then this button is used to save laps - if (currentState == States::Running) { - lapBuffer.addLaps(currentTimeSeparated); - lapNr++; - lapPressed = true; - - } else if (currentState == States::Halted) { - currentEvent = Events::Stop; - } else { - // Not possible to reach here. Do nothing. + if (event != LV_EVENT_PRESSED) { + return; + } + // If running, then this button is used to save laps + if (currentState == States::Running) { + lapBuffer.addLaps(currentTimeSeparated); + lapNr++; + if (lapBuffer[1]) { + lv_label_set_text_fmt( + lapOneText, "#%2d %2d:%02d.%02d", (lapNr - 1), lapBuffer[1]->mins, lapBuffer[1]->secs, lapBuffer[1]->hundredths); + } + if (lapBuffer[0]) { + lv_label_set_text_fmt(lapTwoText, "#%2d %2d:%02d.%02d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->hundredths); } + } else if (currentState == States::Halted) { + reset(); + } +} + +bool StopWatch::OnButtonPushed() { + if (currentState == States::Running) { + pause(); + } else { + running = false; } + return true; } diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h index ff604361..e132f158 100644 --- a/src/displayapp/screens/StopWatch.h +++ b/src/displayapp/screens/StopWatch.h @@ -8,13 +8,12 @@ #include "portmacro_cmsis.h" #include +#include "systemtask/SystemTask.h" namespace Pinetime::Applications::Screens { enum class States { Init, Running, Halted }; - enum class Events { Play, Pause, Stop }; - struct TimeSeparated_t { int mins; int secs; @@ -63,23 +62,28 @@ namespace Pinetime::Applications::Screens { class StopWatch : public Screen { public: - StopWatch(DisplayApp* app); + StopWatch(DisplayApp* app, System::SystemTask& systemTask); ~StopWatch() override; bool Refresh() override; void playPauseBtnEventHandler(lv_event_t event); void stopLapBtnEventHandler(lv_event_t event); + bool OnButtonPushed() override; + + void reset(); + void start(); + void pause(); private: + Pinetime::System::SystemTask& systemTask; + TickType_t timeElapsed; bool running; States currentState; - Events currentEvent; TickType_t startTime; TickType_t oldTimeElapsed; TimeSeparated_t currentTimeSeparated; // Holds Mins, Secs, millisecs LapTextBuffer_t<2> lapBuffer; - int lapNr; - bool lapPressed; + int lapNr = 0; lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap; lv_obj_t *lapOneText, *lapTwoText; }; -- cgit v1.2.3 From 6a91b83b12ef849f68d54f490153b02f0ecf58dc Mon Sep 17 00:00:00 2001 From: kieranc Date: Sun, 11 Jul 2021 15:08:23 +0200 Subject: Change step gauge range to 100 and calculate progress as percantage (#468) --- src/displayapp/screens/PineTimeStyle.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/PineTimeStyle.cpp b/src/displayapp/screens/PineTimeStyle.cpp index 678099c0..591f3a49 100644 --- a/src/displayapp/screens/PineTimeStyle.cpp +++ b/src/displayapp/screens/PineTimeStyle.cpp @@ -179,8 +179,8 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_align(stepGauge, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_gauge_set_scale(stepGauge, 360, 11, 0); lv_gauge_set_angle_offset(stepGauge, 180); - lv_gauge_set_critical_value(stepGauge, (settingsController.GetStepsGoal() / 100)); - lv_gauge_set_range(stepGauge, 0, (settingsController.GetStepsGoal() / 100)); + lv_gauge_set_critical_value(stepGauge, 100); + lv_gauge_set_range(stepGauge, 0, 100); lv_gauge_set_value(stepGauge, 0, 0); lv_obj_set_style_local_pad_right(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, 3); @@ -328,7 +328,7 @@ bool PineTimeStyle::Refresh() { stepCount = motionController.NbSteps(); motionSensorOk = motionController.IsSensorOk(); if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) { - lv_gauge_set_value(stepGauge, 0, (stepCount.Get() / 100)); + lv_gauge_set_value(stepGauge, 0, (stepCount.Get() / (settingsController.GetStepsGoal() / 100))); lv_obj_realign(stepGauge); if (stepCount.Get() > settingsController.GetStepsGoal()) { lv_obj_set_style_local_line_color(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); -- cgit v1.2.3