From 4cc6776e6402d620d2bb7c5bad2bf908ea38be79 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sun, 11 Sep 2022 00:05:27 -0400 Subject: [PATCH 01/51] initial commit for Dice.h and Dice.cpp --- src/displayapp/screens/Dice.cpp | 64 +++++++++++++++++++++++++++++++++ src/displayapp/screens/Dice.h | 31 ++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/displayapp/screens/Dice.cpp create mode 100644 src/displayapp/screens/Dice.h diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp new file mode 100644 index 0000000000..b0e4ddc9bf --- /dev/null +++ b/src/displayapp/screens/Dice.cpp @@ -0,0 +1,64 @@ +#include "displayapp/screens/Dice.h" + +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" + +#include + +using namespace Pinetime::Applications::Screens; + +static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); + if (event == LV_EVENT_CLICKED) { + screen->Roll(); + } +} + +Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app), dateTime {dateTime} { + + srand(dateTime.Uptime().count() * dateTime.Seconds()); + + lv_obj_t* dLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_obj_set_style_local_text_color(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_label_set_text_static(dLabel, "d"); + lv_obj_align(dLabel, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 14, 80); + + sidesCounter.Create(); + lv_obj_align(sidesCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 49, 24); + sidesCounter.SetValue(2); + + currentColorIndex = rand() % resultColorsLength; + + resultLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); + lv_obj_set_style_local_text_color(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); + lv_obj_align(resultLabel, nullptr, LV_ALIGN_IN_TOP_RIGHT, -110, 60); + + Roll(); + + btnRoll = lv_btn_create(lv_scr_act(), nullptr); + btnRoll->user_data = this; + lv_obj_set_event_cb(btnRoll, btnRollEventHandler); + lv_obj_set_size(btnRoll, 240, 50); + lv_obj_align(btnRoll, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + btnRollLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_align(btnRollLabel, btnRoll, LV_ALIGN_CENTER, 12, 0); + lv_label_set_text_static(btnRollLabel, Symbols::dice); +} + +Dice::~Dice() { + lv_obj_clean(lv_scr_act()); +} + +void Dice::Roll() { + rollResult = ((rand() % sidesCounter.GetValue()) + 1); + lv_label_set_text_fmt(resultLabel, "%d", rollResult); + NextColor(); +} + +void Dice::NextColor() { + currentColorIndex = (currentColorIndex + 1) % resultColorsLength; + lv_obj_set_style_local_text_color(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); +} diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h new file mode 100644 index 0000000000..b942e26af8 --- /dev/null +++ b/src/displayapp/screens/Dice.h @@ -0,0 +1,31 @@ +#pragma once + +#include "displayapp/screens/Screen.h" +#include "displayapp/widgets/Counter.h" +#include "components/datetime/DateTimeController.h" +#include + +namespace Pinetime::Applications::Screens { + class Dice : public Screen { + public: + Dice(DisplayApp* app, Controllers::DateTime& dateTime); + ~Dice() override; + void Roll(); + void NextColor(); + + private: + Controllers::DateTime& dateTime; + + lv_obj_t* btnRoll; + lv_obj_t* btnRollLabel; + lv_obj_t* resultLabel; + + lv_color_t resultColors[3] = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; + uint8_t resultColorsLength = sizeof(resultColors) / sizeof(resultColors[0]); + uint8_t currentColorIndex; + + uint8_t rollResult; + + Widgets::Counter sidesCounter = Widgets::Counter(2, 99, jetbrains_mono_42); + }; +} From b238d06f0bd43c56412916269934d2de5f2a92c3 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sun, 11 Sep 2022 00:07:37 -0400 Subject: [PATCH 02/51] include Dice.h and Dice.cpp into compilation in CMakeLists.txt --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index db4a8e2aae..4d183fd180 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -399,6 +399,7 @@ list(APPEND SOURCE_FILES displayapp/screens/BatteryInfo.cpp displayapp/screens/Steps.cpp displayapp/screens/Timer.cpp + displayapp/screens/Dice.cpp displayapp/screens/PassKey.cpp displayapp/screens/Error.cpp displayapp/screens/Alarm.cpp @@ -608,6 +609,7 @@ set(INCLUDE_FILES displayapp/screens/Metronome.h displayapp/screens/Motion.h displayapp/screens/Timer.h + displayapp/screens/Dice.h displayapp/screens/Alarm.h displayapp/Colors.h displayapp/widgets/Counter.h From 62780084bd342c74e526a3318db78cdfd18217be Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sun, 11 Sep 2022 00:09:16 -0400 Subject: [PATCH 03/51] add "d" (0x64) to the range in jetbrains_mono_42 in fonts.json --- src/displayapp/fonts/fonts.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index 006b884947..f5f6a368ba 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -18,7 +18,7 @@ "sources": [ { "file": "JetBrainsMono-Regular.ttf", - "range": "0x25, 0x2b, 0x2d, 0x30-0x3a" + "range": "0x25, 0x2b, 0x2d, 0x30-0x3a, 0x64" } ], "bpp": 1, From 12a565a5763111753b651f2fa3495b04960ed254 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sun, 11 Sep 2022 00:16:46 -0400 Subject: [PATCH 04/51] add dice symbol --- src/displayapp/fonts/fonts.json | 2 +- src/displayapp/screens/Symbols.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index f5f6a368ba..c93d2561f0 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -7,7 +7,7 @@ }, { "file": "FontAwesome5-Solid+Brands+Regular.woff", - "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015, 0xf00c" + "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015, 0xf00c, 0xf522" } ], "bpp": 1, diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index 1180ec6f28..5363d1fb65 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -34,6 +34,7 @@ namespace Pinetime { static constexpr const char* hourGlass = "\xEF\x89\x92"; static constexpr const char* lapsFlag = "\xEF\x80\xA4"; static constexpr const char* drum = "\xEF\x95\xA9"; + static constexpr const char* dice = "\xEF\x94\xA2"; static constexpr const char* chartLine = "\xEF\x88\x81"; static constexpr const char* eye = "\xEF\x81\xAE"; static constexpr const char* home = "\xEF\x80\x95"; From b37781a2eb5541cefc030fa4fec3f7649cb4b52e Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sun, 11 Sep 2022 00:25:16 -0400 Subject: [PATCH 05/51] add dice app to app launcher --- src/displayapp/Apps.h | 1 + src/displayapp/DisplayApp.cpp | 4 ++++ src/displayapp/screens/ApplicationList.h | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 8aad953517..013964c17d 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -25,6 +25,7 @@ namespace Pinetime { Metronome, Motion, Steps, + Dice, Weather, PassKey, QuickSettings, diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 2968446686..dda49e0a29 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -27,6 +27,7 @@ #include "displayapp/screens/FlashLight.h" #include "displayapp/screens/BatteryInfo.h" #include "displayapp/screens/Steps.h" +#include "displayapp/screens/Dice.h" #include "displayapp/screens/PassKey.h" #include "displayapp/screens/Error.h" @@ -476,6 +477,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) case Apps::Steps: currentScreen = std::make_unique(this, motionController, settingsController); break; + case Apps::Dice: + currentScreen = std::make_unique(this, dateTimeController); + break; } currentApp = app; } diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h index e7c094bffe..1aa63a802a 100644 --- a/src/displayapp/screens/ApplicationList.h +++ b/src/displayapp/screens/ApplicationList.h @@ -52,6 +52,8 @@ namespace Pinetime { {Symbols::chartLine, Apps::Motion}, {Symbols::drum, Apps::Metronome}, {Symbols::map, Apps::Navigation}, + + {Symbols::dice, Apps::Dice}, }}; ScreenList screens; }; From 1996113f9726002c3241c5fb901bf49f713809cf Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sun, 11 Sep 2022 22:54:13 -0400 Subject: [PATCH 06/51] increase number of app screens to 3 --- src/displayapp/screens/ApplicationList.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h index 1aa63a802a..8c83fecff6 100644 --- a/src/displayapp/screens/ApplicationList.h +++ b/src/displayapp/screens/ApplicationList.h @@ -36,7 +36,7 @@ namespace Pinetime { static constexpr int appsPerScreen = 6; // Increment this when more space is needed - static constexpr int nScreens = 2; + static constexpr int nScreens = 3; static constexpr std::array applications {{ {Symbols::stopWatch, Apps::StopWatch}, From f00d779d3e6871c185f5e437ce9255bc440d92af Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sun, 11 Sep 2022 22:55:11 -0400 Subject: [PATCH 07/51] modify dice seed to use epoch time --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index b0e4ddc9bf..12401e1148 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -16,7 +16,7 @@ static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app), dateTime {dateTime} { - srand(dateTime.Uptime().count() * dateTime.Seconds()); + srand(dateTime.Uptime().count() * time(nullptr)); lv_obj_t* dLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); From b073b485d913ee538d10dfaa6c55d38233b9799b Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Tue, 13 Sep 2022 16:29:29 -0400 Subject: [PATCH 08/51] apply clang-format to Dice.h --- src/displayapp/screens/Dice.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index b942e26af8..f6547479e4 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -7,25 +7,25 @@ namespace Pinetime::Applications::Screens { class Dice : public Screen { - public: - Dice(DisplayApp* app, Controllers::DateTime& dateTime); - ~Dice() override; - void Roll(); - void NextColor(); + public: + Dice(DisplayApp* app, Controllers::DateTime& dateTime); + ~Dice() override; + void Roll(); + void NextColor(); - private: - Controllers::DateTime& dateTime; + private: + Controllers::DateTime& dateTime; - lv_obj_t* btnRoll; - lv_obj_t* btnRollLabel; - lv_obj_t* resultLabel; + lv_obj_t* btnRoll; + lv_obj_t* btnRollLabel; + lv_obj_t* resultLabel; - lv_color_t resultColors[3] = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; - uint8_t resultColorsLength = sizeof(resultColors) / sizeof(resultColors[0]); - uint8_t currentColorIndex; + lv_color_t resultColors[3] = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; + uint8_t resultColorsLength = sizeof(resultColors) / sizeof(resultColors[0]); + uint8_t currentColorIndex; - uint8_t rollResult; + uint8_t rollResult; - Widgets::Counter sidesCounter = Widgets::Counter(2, 99, jetbrains_mono_42); + Widgets::Counter sidesCounter = Widgets::Counter(2, 99, jetbrains_mono_42); }; } From 1edfddd1c570767f52eb12e9c237f873a3349a0a Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Tue, 13 Sep 2022 16:47:10 -0400 Subject: [PATCH 09/51] remove unnecessary stored reference to dateTime in Dice.h --- src/displayapp/screens/Dice.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index f6547479e4..70c2e23689 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -14,8 +14,6 @@ namespace Pinetime::Applications::Screens { void NextColor(); private: - Controllers::DateTime& dateTime; - lv_obj_t* btnRoll; lv_obj_t* btnRollLabel; lv_obj_t* resultLabel; From 6c7d8c2fcae8f649b94a3d23fe4b42c4ea1fd806 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Tue, 13 Sep 2022 16:56:21 -0400 Subject: [PATCH 10/51] remove unnecessary stored reference to dateTime in Dice.cpp --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 12401e1148..2e0b9078f8 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -14,7 +14,7 @@ static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { } } -Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app), dateTime {dateTime} { +Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app) { srand(dateTime.Uptime().count() * time(nullptr)); From 3bd3d817a04134a50d11062de7c836e6a5251d2a Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Tue, 13 Sep 2022 17:00:56 -0400 Subject: [PATCH 11/51] use std::array to reduce unnecessary variables --- src/displayapp/screens/Dice.cpp | 4 ++-- src/displayapp/screens/Dice.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 2e0b9078f8..7091f3f17f 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -28,7 +28,7 @@ Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app) { lv_obj_align(sidesCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 49, 24); sidesCounter.SetValue(2); - currentColorIndex = rand() % resultColorsLength; + currentColorIndex = rand() % resultColors.size(); resultLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); @@ -59,6 +59,6 @@ void Dice::Roll() { } void Dice::NextColor() { - currentColorIndex = (currentColorIndex + 1) % resultColorsLength; + currentColorIndex = (currentColorIndex + 1) % resultColors.size(); lv_obj_set_style_local_text_color(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); } diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 70c2e23689..56f76f4859 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -4,6 +4,7 @@ #include "displayapp/widgets/Counter.h" #include "components/datetime/DateTimeController.h" #include +#include namespace Pinetime::Applications::Screens { class Dice : public Screen { @@ -18,8 +19,7 @@ namespace Pinetime::Applications::Screens { lv_obj_t* btnRollLabel; lv_obj_t* resultLabel; - lv_color_t resultColors[3] = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; - uint8_t resultColorsLength = sizeof(resultColors) / sizeof(resultColors[0]); + std::array resultColors = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; uint8_t currentColorIndex; uint8_t rollResult; From 21e5ec188447c357409e91ea5b905d3e161d02b0 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Tue, 13 Sep 2022 17:03:18 -0400 Subject: [PATCH 12/51] remove unnecessary member variable in Dice.h --- src/displayapp/screens/Dice.cpp | 3 +-- src/displayapp/screens/Dice.h | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 7091f3f17f..077a8060e0 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -53,8 +53,7 @@ Dice::~Dice() { } void Dice::Roll() { - rollResult = ((rand() % sidesCounter.GetValue()) + 1); - lv_label_set_text_fmt(resultLabel, "%d", rollResult); + lv_label_set_text_fmt(resultLabel, "%d", ((rand() % sidesCounter.GetValue()) + 1)); NextColor(); } diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 56f76f4859..7ce8a5b995 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -22,8 +22,6 @@ namespace Pinetime::Applications::Screens { std::array resultColors = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; uint8_t currentColorIndex; - uint8_t rollResult; - Widgets::Counter sidesCounter = Widgets::Counter(2, 99, jetbrains_mono_42); }; } From b1e522fc42e8819e7d8ca90e7a8e2b877f6fd303 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Tue, 13 Sep 2022 17:04:54 -0400 Subject: [PATCH 13/51] move NextColor() into private namespace of Dice --- src/displayapp/screens/Dice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 7ce8a5b995..a03bace827 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -12,7 +12,6 @@ namespace Pinetime::Applications::Screens { Dice(DisplayApp* app, Controllers::DateTime& dateTime); ~Dice() override; void Roll(); - void NextColor(); private: lv_obj_t* btnRoll; @@ -21,6 +20,7 @@ namespace Pinetime::Applications::Screens { std::array resultColors = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; uint8_t currentColorIndex; + void NextColor(); Widgets::Counter sidesCounter = Widgets::Counter(2, 99, jetbrains_mono_42); }; From 8ecfb49b4aa3d50f0daa034c330ad53d77707c76 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Wed, 14 Sep 2022 16:48:35 -0400 Subject: [PATCH 14/51] modify seed to avoid overflow error --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 077a8060e0..41f95c1938 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -16,7 +16,7 @@ static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app) { - srand(dateTime.Uptime().count() * time(nullptr)); + srand(time(nullptr) - dateTime.Uptime().count()); lv_obj_t* dLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); From 616413d5a2068474b52797226035f6b165e20477 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Wed, 14 Sep 2022 17:20:16 -0400 Subject: [PATCH 15/51] fix unchanging seed --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 41f95c1938..0b7e50e9a8 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -16,7 +16,7 @@ static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app) { - srand(time(nullptr) - dateTime.Uptime().count()); + srand(time(nullptr) + dateTime.Uptime().count()); lv_obj_t* dLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); From 6d23a14993e0def3ae14f90feebf70cf0a973ba0 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Thu, 15 Sep 2022 12:20:31 -0400 Subject: [PATCH 16/51] fix Dice seed to use system tick count --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/Dice.cpp | 5 ++--- src/displayapp/screens/Dice.h | 6 ++++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index dda49e0a29..a2f7a23c90 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -478,7 +478,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, motionController, settingsController); break; case Apps::Dice: - currentScreen = std::make_unique(this, dateTimeController); + currentScreen = std::make_unique(this, *systemTask); break; } currentApp = app; diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 0b7e50e9a8..d4fa6d40e7 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -14,9 +14,8 @@ static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { } } -Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app) { - - srand(time(nullptr) + dateTime.Uptime().count()); +Dice::Dice(DisplayApp* app, System::SystemTask& systemTask) : Screen(app), systemTask {systemTask} { + srand(xTaskGetTickCount() % (std::numeric_limits::max())); lv_obj_t* dLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index a03bace827..e00c7e7ebf 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -2,18 +2,20 @@ #include "displayapp/screens/Screen.h" #include "displayapp/widgets/Counter.h" -#include "components/datetime/DateTimeController.h" +#include "systemtask/SystemTask.h" #include #include namespace Pinetime::Applications::Screens { class Dice : public Screen { public: - Dice(DisplayApp* app, Controllers::DateTime& dateTime); + Dice(DisplayApp* app, System::SystemTask& systemTask); ~Dice() override; void Roll(); private: + Pinetime::System::SystemTask& systemTask; + lv_obj_t* btnRoll; lv_obj_t* btnRollLabel; lv_obj_t* resultLabel; From 52e4af53332a4e6d8c6e54b4862c08df300aeef0 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Thu, 15 Sep 2022 14:44:50 -0400 Subject: [PATCH 17/51] implement rolling multiple dice in Dice --- src/displayapp/screens/Dice.cpp | 50 ++++++++++++++++++++++++++------- src/displayapp/screens/Dice.h | 6 ++-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index d4fa6d40e7..904b41512b 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -17,22 +17,37 @@ static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { Dice::Dice(DisplayApp* app, System::SystemTask& systemTask) : Screen(app), systemTask {systemTask} { srand(xTaskGetTickCount() % (std::numeric_limits::max())); + nCounter.Create(); + lv_obj_align(nCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 24); + nCounter.SetValue(1); + lv_obj_t* dLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_obj_set_style_local_text_color(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_label_set_text_static(dLabel, "d"); - lv_obj_align(dLabel, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 14, 80); + lv_obj_align(dLabel, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 57, 80); - sidesCounter.Create(); - lv_obj_align(sidesCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 49, 24); - sidesCounter.SetValue(2); + dCounter.Create(); + lv_obj_align(dCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 83, 24); + dCounter.SetValue(2); currentColorIndex = rand() % resultColors.size(); - resultLabel = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_font(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); - lv_obj_set_style_local_text_color(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); - lv_obj_align(resultLabel, nullptr, LV_ALIGN_IN_TOP_RIGHT, -110, 60); + resultTotalLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(resultTotalLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_obj_set_style_local_text_color(resultTotalLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); + lv_label_set_long_mode(resultTotalLabel, LV_LABEL_LONG_BREAK); + lv_obj_set_width(resultTotalLabel, 120); + lv_label_set_align(resultTotalLabel, LV_LABEL_ALIGN_CENTER); + lv_obj_align(resultTotalLabel, nullptr, LV_ALIGN_IN_TOP_RIGHT, 11, 25); + + resultIndividualLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(resultIndividualLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); + lv_obj_set_style_local_text_color(resultIndividualLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); + lv_label_set_long_mode(resultIndividualLabel, LV_LABEL_LONG_BREAK); + lv_obj_set_width(resultIndividualLabel, 90); + lv_label_set_align(resultIndividualLabel, LV_LABEL_ALIGN_CENTER); + lv_obj_align(resultIndividualLabel, nullptr, LV_ALIGN_IN_TOP_RIGHT, -4, 75); Roll(); @@ -52,11 +67,26 @@ Dice::~Dice() { } void Dice::Roll() { - lv_label_set_text_fmt(resultLabel, "%d", ((rand() % sidesCounter.GetValue()) + 1)); + uint8_t resultIndividual; + uint16_t resultTotal = 0; + + lv_label_set_text(resultIndividualLabel, ""); + + for (uint8_t i = 0; i < nCounter.GetValue(); i++) { + resultIndividual = ((rand() % dCounter.GetValue()) + 1); + resultTotal += resultIndividual; + lv_label_ins_text(resultIndividualLabel, LV_LABEL_POS_LAST, std::to_string(resultIndividual).c_str()); + if (i < (nCounter.GetValue() - 1)) { + lv_label_ins_text(resultIndividualLabel, LV_LABEL_POS_LAST, "+"); + } + } + + lv_label_set_text_fmt(resultTotalLabel, "%d", resultTotal); NextColor(); } void Dice::NextColor() { currentColorIndex = (currentColorIndex + 1) % resultColors.size(); - lv_obj_set_style_local_text_color(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); + lv_obj_set_style_local_text_color(resultTotalLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); + lv_obj_set_style_local_text_color(resultIndividualLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); } diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index e00c7e7ebf..2e17cc031a 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -18,12 +18,14 @@ namespace Pinetime::Applications::Screens { lv_obj_t* btnRoll; lv_obj_t* btnRollLabel; - lv_obj_t* resultLabel; + lv_obj_t* resultTotalLabel; + lv_obj_t* resultIndividualLabel; std::array resultColors = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; uint8_t currentColorIndex; void NextColor(); - Widgets::Counter sidesCounter = Widgets::Counter(2, 99, jetbrains_mono_42); + Widgets::Counter nCounter = Widgets::Counter(1, 9, jetbrains_mono_42); + Widgets::Counter dCounter = Widgets::Counter(2, 99, jetbrains_mono_42); }; } From adc97a03ba0b9555970692ddf01c7e9ce56e2e20 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Fri, 16 Sep 2022 16:19:42 -0400 Subject: [PATCH 18/51] removed unnecessary reference to SystemTask --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/Dice.cpp | 2 +- src/displayapp/screens/Dice.h | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index a2f7a23c90..b3c1ff4801 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -478,7 +478,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, motionController, settingsController); break; case Apps::Dice: - currentScreen = std::make_unique(this, *systemTask); + currentScreen = std::make_unique(this); break; } currentApp = app; diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 904b41512b..3a5ec0c667 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -14,7 +14,7 @@ static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { } } -Dice::Dice(DisplayApp* app, System::SystemTask& systemTask) : Screen(app), systemTask {systemTask} { +Dice::Dice(DisplayApp* app) : Screen(app) { srand(xTaskGetTickCount() % (std::numeric_limits::max())); nCounter.Create(); diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 2e17cc031a..c1cf633cd7 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -9,13 +9,11 @@ namespace Pinetime::Applications::Screens { class Dice : public Screen { public: - Dice(DisplayApp* app, System::SystemTask& systemTask); + Dice(DisplayApp* app); ~Dice() override; void Roll(); private: - Pinetime::System::SystemTask& systemTask; - lv_obj_t* btnRoll; lv_obj_t* btnRollLabel; lv_obj_t* resultTotalLabel; From 13758ad4ec83e04253fd4b88fbfe8d9a5f875d0d Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sat, 17 Sep 2022 21:58:17 -0400 Subject: [PATCH 19/51] change starting die to d6 --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 3a5ec0c667..5d832b0ae3 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -29,7 +29,7 @@ Dice::Dice(DisplayApp* app) : Screen(app) { dCounter.Create(); lv_obj_align(dCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 83, 24); - dCounter.SetValue(2); + dCounter.SetValue(6); currentColorIndex = rand() % resultColors.size(); From f0cc97c631f781e57aff83c34ebe061637f9fbb7 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sat, 17 Sep 2022 22:19:39 -0400 Subject: [PATCH 20/51] clean up labels in Dice.cpp and remove duplicate code --- src/displayapp/screens/Dice.cpp | 55 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 5d832b0ae3..94203d0922 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -7,10 +7,26 @@ using namespace Pinetime::Applications::Screens; -static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { - auto* screen = static_cast(obj->user_data); - if (event == LV_EVENT_CLICKED) { - screen->Roll(); +namespace { + lv_obj_t* MakeLabel(lv_font_t* font, lv_color_t color, lv_label_long_mode_t longMode, uint8_t width, lv_label_align_t labelAlignment, const char* text, lv_obj_t* reference, lv_align_t alignment, int8_t x, int8_t y) { + lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font); + lv_obj_set_style_local_text_color(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color); + lv_label_set_long_mode(label, longMode); + if (width != 0) { + lv_obj_set_width(label, width); + } + lv_label_set_align(label, labelAlignment); + lv_label_set_text(label, text); + lv_obj_align(label, reference, alignment, x, y); + return label; + } + + static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); + if (event == LV_EVENT_CLICKED) { + screen->Roll(); + } } } @@ -18,36 +34,19 @@ Dice::Dice(DisplayApp* app) : Screen(app) { srand(xTaskGetTickCount() % (std::numeric_limits::max())); nCounter.Create(); - lv_obj_align(nCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 24); + lv_obj_align(nCounter.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 24); nCounter.SetValue(1); - lv_obj_t* dLabel = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_font(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); - lv_obj_set_style_local_text_color(dLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_label_set_text_static(dLabel, "d"); - lv_obj_align(dLabel, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 57, 80); + lv_obj_t* dLabel = MakeLabel(&jetbrains_mono_42, LV_COLOR_WHITE, LV_LABEL_LONG_EXPAND, 0, LV_LABEL_ALIGN_LEFT, "d", nCounter.GetObject(), LV_ALIGN_OUT_RIGHT_MID, 0, 0); dCounter.Create(); - lv_obj_align(dCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 83, 24); + lv_obj_align(dCounter.GetObject(), dLabel, LV_ALIGN_OUT_RIGHT_MID, 2, 0); dCounter.SetValue(6); currentColorIndex = rand() % resultColors.size(); - resultTotalLabel = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_font(resultTotalLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); - lv_obj_set_style_local_text_color(resultTotalLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); - lv_label_set_long_mode(resultTotalLabel, LV_LABEL_LONG_BREAK); - lv_obj_set_width(resultTotalLabel, 120); - lv_label_set_align(resultTotalLabel, LV_LABEL_ALIGN_CENTER); - lv_obj_align(resultTotalLabel, nullptr, LV_ALIGN_IN_TOP_RIGHT, 11, 25); - - resultIndividualLabel = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_font(resultIndividualLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); - lv_obj_set_style_local_text_color(resultIndividualLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); - lv_label_set_long_mode(resultIndividualLabel, LV_LABEL_LONG_BREAK); - lv_obj_set_width(resultIndividualLabel, 90); - lv_label_set_align(resultIndividualLabel, LV_LABEL_ALIGN_CENTER); - lv_obj_align(resultIndividualLabel, nullptr, LV_ALIGN_IN_TOP_RIGHT, -4, 75); + resultTotalLabel = MakeLabel(&jetbrains_mono_42, resultColors[currentColorIndex], LV_LABEL_LONG_BREAK, 120, LV_LABEL_ALIGN_CENTER, "", lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 13, 30); + resultIndividualLabel = MakeLabel(&jetbrains_mono_bold_20, resultColors[currentColorIndex], LV_LABEL_LONG_BREAK, 90, LV_LABEL_ALIGN_CENTER, "", resultTotalLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); Roll(); @@ -57,9 +56,7 @@ Dice::Dice(DisplayApp* app) : Screen(app) { lv_obj_set_size(btnRoll, 240, 50); lv_obj_align(btnRoll, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - btnRollLabel = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(btnRollLabel, btnRoll, LV_ALIGN_CENTER, 12, 0); - lv_label_set_text_static(btnRollLabel, Symbols::dice); + btnRollLabel = MakeLabel(&jetbrains_mono_bold_20, LV_COLOR_WHITE, LV_LABEL_LONG_EXPAND, 0, LV_LABEL_ALIGN_CENTER, Symbols::dice, btnRoll, LV_ALIGN_CENTER, 0, 0); } Dice::~Dice() { From c1b435bcfcb3a242a725333efaab8cd4e00e3762 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Mon, 19 Sep 2022 16:13:29 -0400 Subject: [PATCH 21/51] use library for RNG in Dice and include motion controller in seed there are known problems with rand() and srand() (see https://en.cppreference.com/w/cpp/numeric/random/rand) and the library is preferred for this reason. the function used from also avoids a very rare bias that would occur using rand() and modulo, when RAND_MAX is not a multiple of d and the initially generated number falls in the last "short" segment. this commit also updates the seed to derive entropy (via seed_seq) from a mix of the system tick count and the x,y,z components of the pinetime motion controller-- taking inspiration from and with credit to @w4tsn (https://github.com/InfiniTimeOrg/InfiniTime/pull/1199) --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/Dice.cpp | 9 ++++++--- src/displayapp/screens/Dice.h | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index b3c1ff4801..81752a20a8 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -478,7 +478,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, motionController, settingsController); break; case Apps::Dice: - currentScreen = std::make_unique(this); + currentScreen = std::make_unique(this, motionController); break; } currentApp = app; diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 94203d0922..57c755e340 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -30,8 +30,9 @@ namespace { } } -Dice::Dice(DisplayApp* app) : Screen(app) { - srand(xTaskGetTickCount() % (std::numeric_limits::max())); +Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : Screen(app) { + std::seed_seq sseq{xTaskGetTickCount(), static_cast(motionController.X()), static_cast(motionController.Y()), static_cast(motionController.Z())}; + gen.seed(sseq); nCounter.Create(); lv_obj_align(nCounter.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 24); @@ -66,11 +67,12 @@ Dice::~Dice() { void Dice::Roll() { uint8_t resultIndividual; uint16_t resultTotal = 0; + std::uniform_int_distribution<> distrib(1, dCounter.GetValue()); lv_label_set_text(resultIndividualLabel, ""); for (uint8_t i = 0; i < nCounter.GetValue(); i++) { - resultIndividual = ((rand() % dCounter.GetValue()) + 1); + resultIndividual = distrib(gen); resultTotal += resultIndividual; lv_label_ins_text(resultIndividualLabel, LV_LABEL_POS_LAST, std::to_string(resultIndividual).c_str()); if (i < (nCounter.GetValue() - 1)) { @@ -87,3 +89,4 @@ void Dice::NextColor() { lv_obj_set_style_local_text_color(resultTotalLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); lv_obj_set_style_local_text_color(resultIndividualLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); } + diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index c1cf633cd7..3785dc3a1e 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -3,13 +3,15 @@ #include "displayapp/screens/Screen.h" #include "displayapp/widgets/Counter.h" #include "systemtask/SystemTask.h" +#include #include +#include #include namespace Pinetime::Applications::Screens { class Dice : public Screen { public: - Dice(DisplayApp* app); + Dice(DisplayApp* app, Controllers::MotionController& motionController); ~Dice() override; void Roll(); @@ -19,6 +21,8 @@ namespace Pinetime::Applications::Screens { lv_obj_t* resultTotalLabel; lv_obj_t* resultIndividualLabel; + std::mt19937 gen; + std::array resultColors = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; uint8_t currentColorIndex; void NextColor(); From 20e30236e28246dd80b7ca00423ba2ba67c5149d Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Mon, 19 Sep 2022 16:31:40 -0400 Subject: [PATCH 22/51] in Dice use for initial color picking as well --- src/displayapp/screens/Dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 57c755e340..8b966c5235 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -44,7 +44,8 @@ Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : S lv_obj_align(dCounter.GetObject(), dLabel, LV_ALIGN_OUT_RIGHT_MID, 2, 0); dCounter.SetValue(6); - currentColorIndex = rand() % resultColors.size(); + std::uniform_int_distribution<> distrib(0, resultColors.size()-1); + currentColorIndex = distrib(gen); resultTotalLabel = MakeLabel(&jetbrains_mono_42, resultColors[currentColorIndex], LV_LABEL_LONG_BREAK, 120, LV_LABEL_ALIGN_CENTER, "", lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 13, 30); resultIndividualLabel = MakeLabel(&jetbrains_mono_bold_20, resultColors[currentColorIndex], LV_LABEL_LONG_BREAK, 90, LV_LABEL_ALIGN_CENTER, "", resultTotalLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); From d64f926de1c0ba1c675de041c5d79cbf6770bd0b Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Mon, 19 Sep 2022 17:01:36 -0400 Subject: [PATCH 23/51] make typecasting within sseq uniform --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 8b966c5235..4ccc65dfd5 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -31,7 +31,7 @@ namespace { } Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : Screen(app) { - std::seed_seq sseq{xTaskGetTickCount(), static_cast(motionController.X()), static_cast(motionController.Y()), static_cast(motionController.Z())}; + std::seed_seq sseq{static_cast(xTaskGetTickCount()), static_cast(motionController.X()), static_cast(motionController.Y()), static_cast(motionController.Z())}; gen.seed(sseq); nCounter.Create(); From 39235224f476390ad2e5ffc3418ca96885a491d1 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Mon, 19 Sep 2022 17:32:57 -0400 Subject: [PATCH 24/51] fix code formatting in Dice.h --- src/displayapp/screens/Dice.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 3785dc3a1e..4e062c8f71 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -1,12 +1,13 @@ #pragma once +#include "components/motion/MotionController.h" #include "displayapp/screens/Screen.h" #include "displayapp/widgets/Counter.h" +#include "lvgl/lvgl.h" #include "systemtask/SystemTask.h" -#include -#include -#include + #include +#include namespace Pinetime::Applications::Screens { class Dice : public Screen { From 4647f8aa3e3f464f93e3cdd877d23daecaace796 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Tue, 20 Sep 2022 07:40:13 -0400 Subject: [PATCH 25/51] fix formatting in Dice.h --- src/displayapp/screens/Dice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 4e062c8f71..1c18c319ef 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -3,10 +3,10 @@ #include "components/motion/MotionController.h" #include "displayapp/screens/Screen.h" #include "displayapp/widgets/Counter.h" -#include "lvgl/lvgl.h" #include "systemtask/SystemTask.h" #include +#include #include namespace Pinetime::Applications::Screens { From 9d332c7e825026ed9afa9499c129219cb2eb34c9 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim <45940010+yusufmte@users.noreply.github.com> Date: Tue, 20 Sep 2022 07:54:05 -0400 Subject: [PATCH 26/51] fix Dice.h code formatting Co-authored-by: NeroBurner --- src/displayapp/screens/Dice.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 1c18c319ef..a775838b96 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -5,8 +5,9 @@ #include "displayapp/widgets/Counter.h" #include "systemtask/SystemTask.h" -#include #include + +#include #include namespace Pinetime::Applications::Screens { From 349e63a87b16ef4b5738f8630132926c5bfd35af Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Fri, 30 Sep 2022 12:20:35 -0400 Subject: [PATCH 27/51] fix Dice.cpp formatting according to clang-format --- src/displayapp/screens/Dice.cpp | 63 ++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 4ccc65dfd5..f103c2c53a 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -8,7 +8,16 @@ using namespace Pinetime::Applications::Screens; namespace { - lv_obj_t* MakeLabel(lv_font_t* font, lv_color_t color, lv_label_long_mode_t longMode, uint8_t width, lv_label_align_t labelAlignment, const char* text, lv_obj_t* reference, lv_align_t alignment, int8_t x, int8_t y) { + lv_obj_t* MakeLabel(lv_font_t* font, + lv_color_t color, + lv_label_long_mode_t longMode, + uint8_t width, + lv_label_align_t labelAlignment, + const char* text, + lv_obj_t* reference, + lv_align_t alignment, + int8_t x, + int8_t y) { lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font); lv_obj_set_style_local_text_color(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color); @@ -31,24 +40,54 @@ namespace { } Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : Screen(app) { - std::seed_seq sseq{static_cast(xTaskGetTickCount()), static_cast(motionController.X()), static_cast(motionController.Y()), static_cast(motionController.Z())}; + std::seed_seq sseq {static_cast(xTaskGetTickCount()), + static_cast(motionController.X()), + static_cast(motionController.Y()), + static_cast(motionController.Z())}; gen.seed(sseq); nCounter.Create(); lv_obj_align(nCounter.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 24); nCounter.SetValue(1); - lv_obj_t* dLabel = MakeLabel(&jetbrains_mono_42, LV_COLOR_WHITE, LV_LABEL_LONG_EXPAND, 0, LV_LABEL_ALIGN_LEFT, "d", nCounter.GetObject(), LV_ALIGN_OUT_RIGHT_MID, 0, 0); + lv_obj_t* dLabel = MakeLabel(&jetbrains_mono_42, + LV_COLOR_WHITE, + LV_LABEL_LONG_EXPAND, + 0, + LV_LABEL_ALIGN_LEFT, + "d", + nCounter.GetObject(), + LV_ALIGN_OUT_RIGHT_MID, + 0, + 0); dCounter.Create(); lv_obj_align(dCounter.GetObject(), dLabel, LV_ALIGN_OUT_RIGHT_MID, 2, 0); dCounter.SetValue(6); - std::uniform_int_distribution<> distrib(0, resultColors.size()-1); + std::uniform_int_distribution<> distrib(0, resultColors.size() - 1); currentColorIndex = distrib(gen); - resultTotalLabel = MakeLabel(&jetbrains_mono_42, resultColors[currentColorIndex], LV_LABEL_LONG_BREAK, 120, LV_LABEL_ALIGN_CENTER, "", lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 13, 30); - resultIndividualLabel = MakeLabel(&jetbrains_mono_bold_20, resultColors[currentColorIndex], LV_LABEL_LONG_BREAK, 90, LV_LABEL_ALIGN_CENTER, "", resultTotalLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); + resultTotalLabel = MakeLabel(&jetbrains_mono_42, + resultColors[currentColorIndex], + LV_LABEL_LONG_BREAK, + 120, + LV_LABEL_ALIGN_CENTER, + "", + lv_scr_act(), + LV_ALIGN_IN_TOP_RIGHT, + 13, + 30); + resultIndividualLabel = MakeLabel(&jetbrains_mono_bold_20, + resultColors[currentColorIndex], + LV_LABEL_LONG_BREAK, + 90, + LV_LABEL_ALIGN_CENTER, + "", + resultTotalLabel, + LV_ALIGN_OUT_BOTTOM_MID, + 0, + 10); Roll(); @@ -58,7 +97,16 @@ Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : S lv_obj_set_size(btnRoll, 240, 50); lv_obj_align(btnRoll, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - btnRollLabel = MakeLabel(&jetbrains_mono_bold_20, LV_COLOR_WHITE, LV_LABEL_LONG_EXPAND, 0, LV_LABEL_ALIGN_CENTER, Symbols::dice, btnRoll, LV_ALIGN_CENTER, 0, 0); + btnRollLabel = MakeLabel(&jetbrains_mono_bold_20, + LV_COLOR_WHITE, + LV_LABEL_LONG_EXPAND, + 0, + LV_LABEL_ALIGN_CENTER, + Symbols::dice, + btnRoll, + LV_ALIGN_CENTER, + 0, + 0); } Dice::~Dice() { @@ -90,4 +138,3 @@ void Dice::NextColor() { lv_obj_set_style_local_text_color(resultTotalLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); lv_obj_set_style_local_text_color(resultIndividualLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]); } - From b47b13aecb5db37ea0d592e224d7b3de3e72c58e Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sat, 15 Oct 2022 23:40:01 -0400 Subject: [PATCH 28/51] make Dice vibrate on roll --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/Dice.cpp | 14 +++++++++----- src/displayapp/screens/Dice.h | 7 ++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 1a479bc972..e9e39de196 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -481,7 +481,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, motionController, settingsController); break; case Apps::Dice: - currentScreen = std::make_unique(this, motionController); + currentScreen = std::make_unique(this, motionController, motorController); break; } currentApp = app; diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index f103c2c53a..2d60db7aa9 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -39,11 +39,11 @@ namespace { } } -Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : Screen(app) { +Dice::Dice(DisplayApp* app, Controllers::MotionController& motion, Controllers::MotorController& motor) : Screen(app), motor {motor} { std::seed_seq sseq {static_cast(xTaskGetTickCount()), - static_cast(motionController.X()), - static_cast(motionController.Y()), - static_cast(motionController.Z())}; + static_cast(motion.X()), + static_cast(motion.Y()), + static_cast(motion.Z())}; gen.seed(sseq); nCounter.Create(); @@ -90,6 +90,7 @@ Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : S 10); Roll(); + openingRoll = false; btnRoll = lv_btn_create(lv_scr_act(), nullptr); btnRoll->user_data = this; @@ -130,7 +131,10 @@ void Dice::Roll() { } lv_label_set_text_fmt(resultTotalLabel, "%d", resultTotal); - NextColor(); + if (openingRoll == false) { + motor.RunForDuration(30); + NextColor(); + } } void Dice::NextColor() { diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index a775838b96..26567c0cae 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -1,6 +1,7 @@ #pragma once #include "components/motion/MotionController.h" +#include "components/motor/MotorController.h" #include "displayapp/screens/Screen.h" #include "displayapp/widgets/Counter.h" #include "systemtask/SystemTask.h" @@ -13,7 +14,7 @@ namespace Pinetime::Applications::Screens { class Dice : public Screen { public: - Dice(DisplayApp* app, Controllers::MotionController& motionController); + Dice(DisplayApp* app, Controllers::MotionController& motion, Controllers::MotorController& motor); ~Dice() override; void Roll(); @@ -31,5 +32,9 @@ namespace Pinetime::Applications::Screens { Widgets::Counter nCounter = Widgets::Counter(1, 9, jetbrains_mono_42); Widgets::Counter dCounter = Widgets::Counter(2, 99, jetbrains_mono_42); + + bool openingRoll = true; + + Controllers::MotorController& motor; }; } From 5953c55be0ae3d82f02e9cef0cb292344b394559 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Mon, 31 Oct 2022 10:45:44 -0400 Subject: [PATCH 29/51] in Dice, only show individual results if there are multiple dice --- src/displayapp/screens/Dice.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 2d60db7aa9..d958ec9896 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -121,12 +121,17 @@ void Dice::Roll() { lv_label_set_text(resultIndividualLabel, ""); - for (uint8_t i = 0; i < nCounter.GetValue(); i++) { - resultIndividual = distrib(gen); - resultTotal += resultIndividual; - lv_label_ins_text(resultIndividualLabel, LV_LABEL_POS_LAST, std::to_string(resultIndividual).c_str()); - if (i < (nCounter.GetValue() - 1)) { - lv_label_ins_text(resultIndividualLabel, LV_LABEL_POS_LAST, "+"); + if (nCounter.GetValue() == 1) { + resultTotal = distrib(gen); + } + else { + for (uint8_t i = 0; i < nCounter.GetValue(); i++) { + resultIndividual = distrib(gen); + resultTotal += resultIndividual; + lv_label_ins_text(resultIndividualLabel, LV_LABEL_POS_LAST, std::to_string(resultIndividual).c_str()); + if (i < (nCounter.GetValue() - 1)) { + lv_label_ins_text(resultIndividualLabel, LV_LABEL_POS_LAST, "+"); + } } } From cb940bf47f3e5fb399b887bd48a7bc349c88a281 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Wed, 2 Nov 2022 14:37:15 -0400 Subject: [PATCH 30/51] fix formatting --- src/displayapp/screens/Dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index d958ec9896..7b039b50a7 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -123,8 +123,7 @@ void Dice::Roll() { if (nCounter.GetValue() == 1) { resultTotal = distrib(gen); - } - else { + } else { for (uint8_t i = 0; i < nCounter.GetValue(); i++) { resultIndividual = distrib(gen); resultTotal += resultIndividual; From ee1f39bf4a55aa677d27669d619a26bd64fe0358 Mon Sep 17 00:00:00 2001 From: yusuf ebrahim Date: Sat, 5 Nov 2022 18:31:05 -0400 Subject: [PATCH 31/51] in Dice, when rolling 1d2, also show "HEADS" or "TAILS" -- suggestion by @medeyko --- src/displayapp/screens/Dice.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 7b039b50a7..05388992bf 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -123,6 +123,16 @@ void Dice::Roll() { if (nCounter.GetValue() == 1) { resultTotal = distrib(gen); + if (dCounter.GetValue() == 2) { + switch (resultTotal) { + case 1: + lv_label_set_text(resultIndividualLabel, "HEADS"); + break; + case 2: + lv_label_set_text(resultIndividualLabel, "TAILS"); + break; + } + } } else { for (uint8_t i = 0; i < nCounter.GetValue(); i++) { resultIndividual = distrib(gen); From 8a217aab3a123a05b9c694d57f5a185f7a9c871d Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Wed, 22 Mar 2023 10:28:02 -0400 Subject: [PATCH 32/51] fix build error in Dice caused by rebase --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/Dice.cpp | 2 +- src/displayapp/screens/Dice.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 081ce9fc3e..8322952a47 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -536,7 +536,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio currentScreen = std::make_unique(motionController, settingsController); break; case Apps::Dice: - currentScreen = std::make_unique(this, motionController, motorController); + currentScreen = std::make_unique(motionController, motorController); break; } currentApp = app; diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 05388992bf..d58b689849 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -39,7 +39,7 @@ namespace { } } -Dice::Dice(DisplayApp* app, Controllers::MotionController& motion, Controllers::MotorController& motor) : Screen(app), motor {motor} { +Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& motor) : motor {motor} { std::seed_seq sseq {static_cast(xTaskGetTickCount()), static_cast(motion.X()), static_cast(motion.Y()), diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 26567c0cae..496b793cdf 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -14,7 +14,7 @@ namespace Pinetime::Applications::Screens { class Dice : public Screen { public: - Dice(DisplayApp* app, Controllers::MotionController& motion, Controllers::MotorController& motor); + Dice(Controllers::MotionController& motion, Controllers::MotorController& motor); ~Dice() override; void Roll(); From 280b3a4e6147f82957a2e7d12f87cf92045ec578 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Fri, 7 Apr 2023 15:24:29 -0400 Subject: [PATCH 33/51] update number of screens --- src/displayapp/screens/ApplicationList.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h index 6c29a716ea..321c74a32b 100644 --- a/src/displayapp/screens/ApplicationList.h +++ b/src/displayapp/screens/ApplicationList.h @@ -37,7 +37,7 @@ namespace Pinetime { static constexpr int appsPerScreen = 6; // Increment this when more space is needed - static constexpr int nScreens = 3; + static constexpr int nScreens = 2; static constexpr std::array applications {{ {Symbols::stopWatch, Apps::StopWatch}, @@ -52,8 +52,8 @@ namespace Pinetime { {"2", Apps::Twos}, {Symbols::drum, Apps::Metronome}, {Symbols::map, Apps::Navigation}, - {Symbols::dice, Apps::Dice}, + // {"M", Apps::Motion}, }}; ScreenList screens; From 1415cf9bc332a9ccd01490709f1518bc8bccdc74 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Thu, 6 Jul 2023 19:24:17 -0400 Subject: [PATCH 34/51] removed unused chart-line icon --- src/displayapp/fonts/fonts.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index 01c1292476..b4c67cc7e9 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -7,7 +7,7 @@ }, { "file": "FontAwesome5-Solid+Brands+Regular.woff", - "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf201, 0xf06e, 0xf015, 0xf00c, 0xf522" + "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf522" } ], "bpp": 1, From 297a15046882f7971227292d959b3508dcc1021d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Wei=C3=9F?= <45500341+Poohl@users.noreply.github.com> Date: Sun, 30 Jul 2023 18:08:15 +0200 Subject: [PATCH 35/51] Motion controlls --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/Dice.cpp | 28 +++++++++++++++++++++++++++- src/displayapp/screens/Dice.h | 10 +++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 83d39ce1d6..faeddb50dd 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -550,7 +550,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio currentScreen = std::make_unique(motionController, settingsController); break; case Apps::Dice: - currentScreen = std::make_unique(motionController, motorController); + currentScreen = std::make_unique(motionController, motorController, settingsController); break; } currentApp = app; diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index d58b689849..6f66755201 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -39,7 +39,8 @@ namespace { } } -Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& motor) : motor {motor} { +Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& motor, Controllers::Settings& settings) + : motor {motor}, motion {motion}, settings {settings} { std::seed_seq sseq {static_cast(xTaskGetTickCount()), static_cast(motion.X()), static_cast(motion.Y()), @@ -108,12 +109,36 @@ Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& LV_ALIGN_CENTER, 0, 0); + + // Spagetti code in motion controller: it only updates the shake speed when shake to wake is on... + enableShakeForDice = !settings.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake); + if (enableShakeForDice) + settings.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, true); + + // TODO: try a higher refresh period + refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } Dice::~Dice() { + // reset the shake to wake mode. + if (enableShakeForDice) { + settings.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, false); + enableShakeForDice = false; + } + lv_task_del(refreshTask); lv_obj_clean(lv_scr_act()); } +void Dice::Refresh() { + // we only reset the hysteresis when at rest + // also motion.ShouldShakeWake() seems to be broken? + if (motion.CurrentShakeSpeed() >= settings.GetShakeThreshold()) { + if (rollHysteresis <= 0) + Roll(); + } else if (rollHysteresis > 0) + --rollHysteresis; +} + void Dice::Roll() { uint8_t resultIndividual; uint16_t resultTotal = 0; @@ -148,6 +173,7 @@ void Dice::Roll() { if (openingRoll == false) { motor.RunForDuration(30); NextColor(); + rollHysteresis = ROLL_HYSTERESIS; } } diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 496b793cdf..085dfcc80c 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -11,18 +11,23 @@ #include #include +#define ROLL_HYSTERESIS 10 + namespace Pinetime::Applications::Screens { class Dice : public Screen { public: - Dice(Controllers::MotionController& motion, Controllers::MotorController& motor); + Dice(Controllers::MotionController& motion, Controllers::MotorController& motor, Controllers::Settings& settings); ~Dice() override; void Roll(); + void Refresh() override; private: lv_obj_t* btnRoll; lv_obj_t* btnRollLabel; lv_obj_t* resultTotalLabel; lv_obj_t* resultIndividualLabel; + lv_task_t* refreshTask; + bool enableShakeForDice = false; std::mt19937 gen; @@ -34,7 +39,10 @@ namespace Pinetime::Applications::Screens { Widgets::Counter dCounter = Widgets::Counter(2, 99, jetbrains_mono_42); bool openingRoll = true; + unsigned int rollHysteresis = 0; Controllers::MotorController& motor; + Controllers::MotionController& motion; + Controllers::Settings& settings; }; } From 5fd99a475ff5af8c62ae1bcc2b37a6018606c9d3 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Sun, 30 Jul 2023 18:46:02 -0400 Subject: [PATCH 36/51] ui adjustments and result realignment at @Boteium suggestion --- src/displayapp/fonts/fonts.json | 2 +- src/displayapp/screens/Dice.cpp | 33 ++++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index b4c67cc7e9..3c6d4f4073 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -18,7 +18,7 @@ "sources": [ { "file": "JetBrainsMono-Regular.ttf", - "range": "0x25, 0x2b, 0x2d, 0x30-0x3a, 0x64" + "range": "0x25, 0x2b, 0x2d, 0x30-0x3a" } ], "bpp": 1, diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index d58b689849..edf08affb5 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -46,23 +46,34 @@ Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& static_cast(motion.Z())}; gen.seed(sseq); - nCounter.Create(); - lv_obj_align(nCounter.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 24); - nCounter.SetValue(1); + lv_obj_t* nCounterLabel = MakeLabel(&jetbrains_mono_bold_20, + LV_COLOR_WHITE, + LV_LABEL_LONG_EXPAND, + 0, + LV_LABEL_ALIGN_CENTER, + "count", + lv_scr_act(), + LV_ALIGN_IN_TOP_LEFT, + 0, + 0); - lv_obj_t* dLabel = MakeLabel(&jetbrains_mono_42, + lv_obj_t* dCounterLabel = MakeLabel(&jetbrains_mono_bold_20, LV_COLOR_WHITE, LV_LABEL_LONG_EXPAND, 0, - LV_LABEL_ALIGN_LEFT, - "d", - nCounter.GetObject(), + LV_LABEL_ALIGN_CENTER, + "sides", + nCounterLabel, LV_ALIGN_OUT_RIGHT_MID, - 0, + 20, 0); + nCounter.Create(); + lv_obj_align(nCounter.GetObject(), nCounterLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); + nCounter.SetValue(1); + dCounter.Create(); - lv_obj_align(dCounter.GetObject(), dLabel, LV_ALIGN_OUT_RIGHT_MID, 2, 0); + lv_obj_align(dCounter.GetObject(), dCounterLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); dCounter.SetValue(6); std::uniform_int_distribution<> distrib(0, resultColors.size() - 1); @@ -76,8 +87,8 @@ Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& "", lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, - 13, - 30); + 11, + 38); resultIndividualLabel = MakeLabel(&jetbrains_mono_bold_20, resultColors[currentColorIndex], LV_LABEL_LONG_BREAK, From c9783e712767c82ee8379a2b7937ca77fef4b753 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Mon, 31 Jul 2023 04:52:12 -0400 Subject: [PATCH 37/51] correct formatting with clang-format --- src/displayapp/screens/Dice.cpp | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index edf08affb5..1d8d965512 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -47,26 +47,26 @@ Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& gen.seed(sseq); lv_obj_t* nCounterLabel = MakeLabel(&jetbrains_mono_bold_20, - LV_COLOR_WHITE, - LV_LABEL_LONG_EXPAND, - 0, - LV_LABEL_ALIGN_CENTER, - "count", - lv_scr_act(), - LV_ALIGN_IN_TOP_LEFT, - 0, - 0); + LV_COLOR_WHITE, + LV_LABEL_LONG_EXPAND, + 0, + LV_LABEL_ALIGN_CENTER, + "count", + lv_scr_act(), + LV_ALIGN_IN_TOP_LEFT, + 0, + 0); lv_obj_t* dCounterLabel = MakeLabel(&jetbrains_mono_bold_20, - LV_COLOR_WHITE, - LV_LABEL_LONG_EXPAND, - 0, - LV_LABEL_ALIGN_CENTER, - "sides", - nCounterLabel, - LV_ALIGN_OUT_RIGHT_MID, - 20, - 0); + LV_COLOR_WHITE, + LV_LABEL_LONG_EXPAND, + 0, + LV_LABEL_ALIGN_CENTER, + "sides", + nCounterLabel, + LV_ALIGN_OUT_RIGHT_MID, + 20, + 0); nCounter.Create(); lv_obj_align(nCounter.GetObject(), nCounterLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); From 7a327f23bd74c96fe60895adee7b0f1803c57173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Wei=C3=9F?= <45500341+Poohl@users.noreply.github.com> Date: Wed, 6 Sep 2023 11:33:42 +0200 Subject: [PATCH 38/51] make label static --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 6f66755201..6d8870588f 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -8,7 +8,7 @@ using namespace Pinetime::Applications::Screens; namespace { - lv_obj_t* MakeLabel(lv_font_t* font, + static lv_obj_t* MakeLabel(lv_font_t* font, lv_color_t color, lv_label_long_mode_t longMode, uint8_t width, From dd11b47c0f4f345199dd1fd15665242ebcf0f3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Wei=C3=9F?= <45500341+Poohl@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:55:08 +0200 Subject: [PATCH 39/51] ignore node shit --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 81e49ae083..a789d0a616 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,8 @@ src/arm-none-eabi # clangd .cache/ + +# node +/node_modules +/package-lock.json +/package.json From 9a640d72c99290da09a54e7e052c7f430ee03b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Wei=C3=9F?= <45500341+Poohl@users.noreply.github.com> Date: Sun, 10 Sep 2023 11:54:12 +0200 Subject: [PATCH 40/51] keep display awake --- src/displayapp/screens/Dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index ad21124db6..7168439e7b 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -144,8 +144,10 @@ void Dice::Refresh() { // we only reset the hysteresis when at rest // also motion.ShouldShakeWake() seems to be broken? if (motion.CurrentShakeSpeed() >= settings.GetShakeThreshold()) { - if (rollHysteresis <= 0) + if (rollHysteresis <= 0) { + lv_disp_get_next(NULL)->last_activity_time = lv_tick_get(); Roll(); + } } else if (rollHysteresis > 0) --rollHysteresis; } From f8d1bb7f48d15f16abbbcabe501275fe4d044caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Wei=C3=9F?= <45500341+Poohl@users.noreply.github.com> Date: Sun, 10 Sep 2023 11:57:26 +0200 Subject: [PATCH 41/51] doc --- src/displayapp/screens/Dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 7168439e7b..1ad9623ea2 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -145,7 +145,9 @@ void Dice::Refresh() { // also motion.ShouldShakeWake() seems to be broken? if (motion.CurrentShakeSpeed() >= settings.GetShakeThreshold()) { if (rollHysteresis <= 0) { + // this timestamp is used for the secreen timeout lv_disp_get_next(NULL)->last_activity_time = lv_tick_get(); + Roll(); } } else if (rollHysteresis > 0) From 8c6e98ba62e51f6e2ade17a99064c2ce5f8ab98b Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Wed, 13 Dec 2023 14:24:44 -0500 Subject: [PATCH 42/51] update as user/optional app --- src/displayapp/DisplayApp.cpp | 3 --- src/displayapp/screens/ApplicationList.h | 20 +------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 92df4cc644..feda8726b6 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -549,9 +549,6 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio case Apps::Steps: currentScreen = std::make_unique(motionController, settingsController); break; - case Apps::Dice: - currentScreen = std::make_unique(motionController, motorController, settingsController); - break; } currentApp = app; } diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h index f73c9acb73..01689e9db9 100644 --- a/src/displayapp/screens/ApplicationList.h +++ b/src/displayapp/screens/ApplicationList.h @@ -39,26 +39,8 @@ namespace Pinetime { static constexpr int appsPerScreen = 6; - // Increment this when more space is needed - static constexpr int nScreens = 2; + static constexpr int nScreens = UserAppTypes::Count > 0 ? (UserAppTypes::Count - 1) / appsPerScreen + 1 : 1; - std::array applications {{ - {Symbols::stopWatch, Apps::StopWatch, true}, - {Symbols::clock, Apps::Alarm, true}, - {Symbols::hourGlass, Apps::Timer, true}, - {Symbols::shoe, Apps::Steps, true}, - {Symbols::heartBeat, Apps::HeartRate, true}, - {Symbols::music, Apps::Music, true}, - - {Symbols::paintbrush, Apps::Paint, true}, - {Symbols::paddle, Apps::Paddle, true}, - {"2", Apps::Twos, true}, - {Symbols::drum, Apps::Metronome, true}, - {Symbols::map, Apps::Navigation, Applications::Screens::Navigation::IsAvailable(filesystem)}, - {Symbols::dice, Apps::Dice, true}, - - // {"M", Apps::Motion}, - }}; ScreenList screens; }; } From ee8aaad250e897f49756cc945c10941598e506a6 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Wed, 13 Dec 2023 15:30:40 -0500 Subject: [PATCH 43/51] updated for new optional user app interface, fixed bugs and formatting --- src/displayapp/Apps.h | 1 + src/displayapp/UserApps.h | 1 + src/displayapp/screens/Dice.cpp | 50 +++++++++---------- src/displayapp/screens/Dice.h | 88 +++++++++++++++++++-------------- 4 files changed, 78 insertions(+), 62 deletions(-) diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 9fbe1acbc2..9fdebecb95 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -55,6 +55,7 @@ namespace Pinetime { Apps::Alarm, Apps::Timer, Apps::Steps, + Apps::Dice, Apps::HeartRate, Apps::Music, Apps::Paint, diff --git a/src/displayapp/UserApps.h b/src/displayapp/UserApps.h index 0ed9d60294..804c7ca59e 100644 --- a/src/displayapp/UserApps.h +++ b/src/displayapp/UserApps.h @@ -8,6 +8,7 @@ #include "displayapp/screens/Tile.h" #include "displayapp/screens/ApplicationList.h" #include "displayapp/screens/Clock.h" +#include "displayapp/screens/Dice.h" namespace Pinetime { namespace Applications { diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 1ad9623ea2..615a51c35f 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -1,23 +1,23 @@ #include "displayapp/screens/Dice.h" - #include "displayapp/screens/Screen.h" #include "displayapp/screens/Symbols.h" - -#include +#include "components/settings/Settings.h" +#include "components/motor/MotorController.h" +#include "components/motion/MotionController.h" using namespace Pinetime::Applications::Screens; namespace { static lv_obj_t* MakeLabel(lv_font_t* font, - lv_color_t color, - lv_label_long_mode_t longMode, - uint8_t width, - lv_label_align_t labelAlignment, - const char* text, - lv_obj_t* reference, - lv_align_t alignment, - int8_t x, - int8_t y) { + lv_color_t color, + lv_label_long_mode_t longMode, + uint8_t width, + lv_label_align_t labelAlignment, + const char* text, + lv_obj_t* reference, + lv_align_t alignment, + int8_t x, + int8_t y) { lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font); lv_obj_set_style_local_text_color(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color); @@ -39,12 +39,14 @@ namespace { } } -Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& motor, Controllers::Settings& settings) - : motor {motor}, motion {motion}, settings {settings} { +Dice::Dice(Controllers::MotionController& motionController, + Controllers::MotorController& motorController, + Controllers::Settings& settingsController) + : motorController {motorController}, motionController {motionController}, settingsController {settingsController} { std::seed_seq sseq {static_cast(xTaskGetTickCount()), - static_cast(motion.X()), - static_cast(motion.Y()), - static_cast(motion.Z())}; + static_cast(motionController.X()), + static_cast(motionController.Y()), + static_cast(motionController.Z())}; gen.seed(sseq); lv_obj_t* nCounterLabel = MakeLabel(&jetbrains_mono_bold_20, @@ -122,18 +124,17 @@ Dice::Dice(Controllers::MotionController& motion, Controllers::MotorController& 0); // Spagetti code in motion controller: it only updates the shake speed when shake to wake is on... - enableShakeForDice = !settings.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake); + enableShakeForDice = !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake); if (enableShakeForDice) - settings.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, true); + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, true); - // TODO: try a higher refresh period refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } Dice::~Dice() { // reset the shake to wake mode. if (enableShakeForDice) { - settings.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, false); + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, false); enableShakeForDice = false; } lv_task_del(refreshTask); @@ -142,12 +143,11 @@ Dice::~Dice() { void Dice::Refresh() { // we only reset the hysteresis when at rest - // also motion.ShouldShakeWake() seems to be broken? - if (motion.CurrentShakeSpeed() >= settings.GetShakeThreshold()) { + if (motionController.CurrentShakeSpeed() >= settingsController.GetShakeThreshold()) { if (rollHysteresis <= 0) { // this timestamp is used for the secreen timeout lv_disp_get_next(NULL)->last_activity_time = lv_tick_get(); - + Roll(); } } else if (rollHysteresis > 0) @@ -186,7 +186,7 @@ void Dice::Roll() { lv_label_set_text_fmt(resultTotalLabel, "%d", resultTotal); if (openingRoll == false) { - motor.RunForDuration(30); + motorController.RunForDuration(30); NextColor(); rollHysteresis = ROLL_HYSTERESIS; } diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 085dfcc80c..86941cf4f3 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -1,48 +1,62 @@ #pragma once -#include "components/motion/MotionController.h" -#include "components/motor/MotorController.h" +#include "displayapp/Apps.h" #include "displayapp/screens/Screen.h" #include "displayapp/widgets/Counter.h" -#include "systemtask/SystemTask.h" - -#include +#include "displayapp/Controllers.h" +#include "Symbols.h" #include #include #define ROLL_HYSTERESIS 10 -namespace Pinetime::Applications::Screens { - class Dice : public Screen { - public: - Dice(Controllers::MotionController& motion, Controllers::MotorController& motor, Controllers::Settings& settings); - ~Dice() override; - void Roll(); - void Refresh() override; - - private: - lv_obj_t* btnRoll; - lv_obj_t* btnRollLabel; - lv_obj_t* resultTotalLabel; - lv_obj_t* resultIndividualLabel; - lv_task_t* refreshTask; - bool enableShakeForDice = false; - - std::mt19937 gen; - - std::array resultColors = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; - uint8_t currentColorIndex; - void NextColor(); - - Widgets::Counter nCounter = Widgets::Counter(1, 9, jetbrains_mono_42); - Widgets::Counter dCounter = Widgets::Counter(2, 99, jetbrains_mono_42); - - bool openingRoll = true; - unsigned int rollHysteresis = 0; - - Controllers::MotorController& motor; - Controllers::MotionController& motion; - Controllers::Settings& settings; - }; +namespace Pinetime { + namespace Applications { + namespace Screens { + class Dice : public Screen { + public: + Dice(Controllers::MotionController& motionController, + Controllers::MotorController& motorController, + Controllers::Settings& settingsController); + ~Dice() override; + void Roll(); + void Refresh() override; + + private: + lv_obj_t* btnRoll; + lv_obj_t* btnRollLabel; + lv_obj_t* resultTotalLabel; + lv_obj_t* resultIndividualLabel; + lv_task_t* refreshTask; + bool enableShakeForDice = false; + + std::mt19937 gen; + + std::array resultColors = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA}; + uint8_t currentColorIndex; + void NextColor(); + + Widgets::Counter nCounter = Widgets::Counter(1, 9, jetbrains_mono_42); + Widgets::Counter dCounter = Widgets::Counter(2, 99, jetbrains_mono_42); + + bool openingRoll = true; + unsigned int rollHysteresis = 0; + + Controllers::MotorController& motorController; + Controllers::MotionController& motionController; + Controllers::Settings& settingsController; + }; + } + + template <> + struct AppTraits { + static constexpr Apps app = Apps::Dice; + static constexpr const char* icon = Screens::Symbols::dice; + + static Screens::Screen* Create(AppControllers& controllers) { + return new Screens::Dice(controllers.motionController, controllers.motorController, controllers.settingsController); + }; + }; + } } From 3e0e30f32af34a31b6170cc2e6024e56c8397d15 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Fri, 15 Dec 2023 15:51:21 -0500 Subject: [PATCH 44/51] fix formatting --- src/displayapp/Apps.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 9fdebecb95..d83b601a0a 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -55,7 +55,7 @@ namespace Pinetime { Apps::Alarm, Apps::Timer, Apps::Steps, - Apps::Dice, + Apps::Dice, Apps::HeartRate, Apps::Music, Apps::Paint, From e231b586fc92fc8af52b7a19d8c814d082cd014f Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Wed, 10 Jan 2024 17:25:28 -0500 Subject: [PATCH 45/51] add to user apps --- src/displayapp/apps/CMakeLists.txt | 1 + src/displayapp/screens/Dice.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/displayapp/apps/CMakeLists.txt b/src/displayapp/apps/CMakeLists.txt index a531bdfff5..51c08595d1 100644 --- a/src/displayapp/apps/CMakeLists.txt +++ b/src/displayapp/apps/CMakeLists.txt @@ -10,6 +10,7 @@ else () set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Paint") set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Paddle") set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Twos") + set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Dice") set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome") set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation") #set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather") diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 86941cf4f3..807b564473 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -1,6 +1,6 @@ #pragma once -#include "displayapp/Apps.h" +#include "displayapp/apps/Apps.h" #include "displayapp/screens/Screen.h" #include "displayapp/widgets/Counter.h" #include "displayapp/Controllers.h" From 1166939f65cf5cca8f829c78724dfe4bcb90e906 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim <45940010+yusufmte@users.noreply.github.com> Date: Sat, 13 Jan 2024 21:49:09 -0500 Subject: [PATCH 46/51] remove unnecessary static declaration Co-authored-by: FintasticMan --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 615a51c35f..1b03c25109 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -8,7 +8,7 @@ using namespace Pinetime::Applications::Screens; namespace { - static lv_obj_t* MakeLabel(lv_font_t* font, + lv_obj_t* MakeLabel(lv_font_t* font, lv_color_t color, lv_label_long_mode_t longMode, uint8_t width, From 945a0995a91afccc71858f485bce32a22ef2f675 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim <45940010+yusufmte@users.noreply.github.com> Date: Sat, 13 Jan 2024 21:49:25 -0500 Subject: [PATCH 47/51] remove unnecessary static declaration Co-authored-by: FintasticMan --- src/displayapp/screens/Dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 1b03c25109..63c45aa70f 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -31,7 +31,7 @@ namespace { return label; } - static void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { + void btnRollEventHandler(lv_obj_t* obj, lv_event_t event) { auto* screen = static_cast(obj->user_data); if (event == LV_EVENT_CLICKED) { screen->Roll(); From 3c4027ab3cf6231f7de64822db51929ab696a8e7 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Sat, 13 Jan 2024 22:13:59 -0500 Subject: [PATCH 48/51] removed vestigial chartLine symbol --- src/displayapp/screens/Symbols.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index 0acc840bd9..4434194b6c 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -35,7 +35,6 @@ namespace Pinetime { static constexpr const char* lapsFlag = "\xEF\x80\xA4"; static constexpr const char* drum = "\xEF\x95\xA9"; static constexpr const char* dice = "\xEF\x94\xA2"; - static constexpr const char* chartLine = "\xEF\x88\x81"; static constexpr const char* eye = "\xEF\x81\xAE"; static constexpr const char* home = "\xEF\x80\x95"; static constexpr const char* sleep = "\xEE\xBD\x84"; From d4c69757e4f8be9e3b5059cd38f2f8a90a4ba5fa Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Sun, 14 Jan 2024 12:27:14 -0500 Subject: [PATCH 49/51] replace preprocessor def with static constexpr value, and formatting fix --- src/displayapp/screens/Dice.cpp | 32 ++++++++++++++++---------------- src/displayapp/screens/Dice.h | 5 ++--- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 63c45aa70f..9d273f1ed7 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -9,15 +9,15 @@ using namespace Pinetime::Applications::Screens; namespace { lv_obj_t* MakeLabel(lv_font_t* font, - lv_color_t color, - lv_label_long_mode_t longMode, - uint8_t width, - lv_label_align_t labelAlignment, - const char* text, - lv_obj_t* reference, - lv_align_t alignment, - int8_t x, - int8_t y) { + lv_color_t color, + lv_label_long_mode_t longMode, + uint8_t width, + lv_label_align_t labelAlignment, + const char* text, + lv_obj_t* reference, + lv_align_t alignment, + int8_t x, + int8_t y) { lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font); lv_obj_set_style_local_text_color(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color); @@ -125,9 +125,9 @@ Dice::Dice(Controllers::MotionController& motionController, // Spagetti code in motion controller: it only updates the shake speed when shake to wake is on... enableShakeForDice = !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake); - if (enableShakeForDice) + if (enableShakeForDice) { settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, true); - + } refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } @@ -144,14 +144,14 @@ Dice::~Dice() { void Dice::Refresh() { // we only reset the hysteresis when at rest if (motionController.CurrentShakeSpeed() >= settingsController.GetShakeThreshold()) { - if (rollHysteresis <= 0) { - // this timestamp is used for the secreen timeout + if (currentRollHysteresis <= 0) { + // this timestamp is used for the screen timeout lv_disp_get_next(NULL)->last_activity_time = lv_tick_get(); Roll(); } - } else if (rollHysteresis > 0) - --rollHysteresis; + } else if (currentRollHysteresis > 0) + --currentRollHysteresis; } void Dice::Roll() { @@ -188,7 +188,7 @@ void Dice::Roll() { if (openingRoll == false) { motorController.RunForDuration(30); NextColor(); - rollHysteresis = ROLL_HYSTERESIS; + currentRollHysteresis = ROLL_HYSTERESIS; } } diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 807b564473..7228218d97 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -9,8 +9,6 @@ #include #include -#define ROLL_HYSTERESIS 10 - namespace Pinetime { namespace Applications { namespace Screens { @@ -41,7 +39,8 @@ namespace Pinetime { Widgets::Counter dCounter = Widgets::Counter(2, 99, jetbrains_mono_42); bool openingRoll = true; - unsigned int rollHysteresis = 0; + uint8_t currentRollHysteresis = 0; + static constexpr uint8_t ROLL_HYSTERESIS = 10; Controllers::MotorController& motorController; Controllers::MotionController& motionController; From 8880acc1f69b34b7e89212549b867d9fc2724fd8 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Sun, 14 Jan 2024 22:08:45 -0500 Subject: [PATCH 50/51] remove unrelated .gitignore changes --- .gitignore | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitignore b/.gitignore index a789d0a616..81e49ae083 100644 --- a/.gitignore +++ b/.gitignore @@ -50,8 +50,3 @@ src/arm-none-eabi # clangd .cache/ - -# node -/node_modules -/package-lock.json -/package.json From 01b241bbde1433acac58a6521debb63ef32ee772 Mon Sep 17 00:00:00 2001 From: Yusuf Ebrahim Date: Sun, 14 Jan 2024 22:14:22 -0500 Subject: [PATCH 51/51] use camelCase for rollHysteresis constant --- src/displayapp/screens/Dice.cpp | 2 +- src/displayapp/screens/Dice.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 9d273f1ed7..302c5f3fb2 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -188,7 +188,7 @@ void Dice::Roll() { if (openingRoll == false) { motorController.RunForDuration(30); NextColor(); - currentRollHysteresis = ROLL_HYSTERESIS; + currentRollHysteresis = rollHysteresis; } } diff --git a/src/displayapp/screens/Dice.h b/src/displayapp/screens/Dice.h index 7228218d97..da91657d0c 100644 --- a/src/displayapp/screens/Dice.h +++ b/src/displayapp/screens/Dice.h @@ -40,7 +40,7 @@ namespace Pinetime { bool openingRoll = true; uint8_t currentRollHysteresis = 0; - static constexpr uint8_t ROLL_HYSTERESIS = 10; + static constexpr uint8_t rollHysteresis = 10; Controllers::MotorController& motorController; Controllers::MotionController& motionController;