-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New App: Tally #2320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
owenfromcanada
wants to merge
13
commits into
InfiniTimeOrg:main
Choose a base branch
from
owenfromcanada:tally
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New App: Tally #2320
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
51e7227
Added tally, undo, and sort icons
owenfromcanada c2392a8
Implemented basic counting functionality
owenfromcanada f820ff7
Integrated into project
owenfromcanada 6e95dc7
Added shake-to-count function
owenfromcanada 98a02ce
Added increment delay to avoid double taps
owenfromcanada ec28827
Added wake lock button
owenfromcanada bb82d2f
Added tip messages for buttons
owenfromcanada a681b6c
Added Tally to documentation
owenfromcanada 00be345
clang-format changes
owenfromcanada 979fdad
Corrected issues per pull request discussions
owenfromcanada ba0d9ec
Increased button size
owenfromcanada 6ebe81d
Decrease font size when count reaches 100
owenfromcanada 99e0fb5
Removed unused include
owenfromcanada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ namespace Pinetime { | |
| SettingChimes, | ||
| SettingShakeThreshold, | ||
| SettingBluetooth, | ||
| Tally, | ||
| Error | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| #include "displayapp/screens/Tally.h" | ||
| #include "displayapp/screens/Screen.h" | ||
| #include "displayapp/screens/Symbols.h" | ||
| #include "components/settings/Settings.h" | ||
| #include "components/motion/MotionController.h" | ||
| #include "components/motor/MotorController.h" | ||
|
|
||
| using namespace Pinetime::Applications::Screens; | ||
|
|
||
| namespace { | ||
| void CountButtonEventHandler(lv_obj_t* obj, lv_event_t event) { | ||
| auto* screen = static_cast<Tally*>(obj->user_data); | ||
| if (event == LV_EVENT_CLICKED) { | ||
| screen->Increment(); | ||
| } | ||
| } | ||
|
|
||
| void ResetButtonEventHandler(lv_obj_t* obj, lv_event_t event) { | ||
| auto* screen = static_cast<Tally*>(obj->user_data); | ||
| if (event == LV_EVENT_CLICKED) { | ||
| screen->Reset(); | ||
| } | ||
| } | ||
|
|
||
| void ShakeButtonEventHandler(lv_obj_t* obj, lv_event_t event) { | ||
| auto* screen = static_cast<Tally*>(obj->user_data); | ||
| if (event == LV_EVENT_CLICKED) { | ||
| screen->ToggleShakeToCount(); | ||
| } | ||
| } | ||
|
|
||
| void AwakeButtonEventHandler(lv_obj_t* obj, lv_event_t event) { | ||
| auto* screen = static_cast<Tally*>(obj->user_data); | ||
| if (event == LV_EVENT_CLICKED) { | ||
| screen->ToggleKeepAwake(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Tally::Tally(Controllers::MotionController& motionController, | ||
| Controllers::MotorController& motorController, | ||
| Controllers::Settings& settingsController, | ||
| System::SystemTask& systemTask) | ||
| : motionController {motionController}, motorController {motorController}, settingsController {settingsController}, wakeLock(systemTask) { | ||
|
|
||
| // the count is actually a button (it was the easiest way to detect taps) | ||
| countButton = lv_btn_create(lv_scr_act(), nullptr); | ||
| countButton->user_data = this; | ||
| lv_obj_set_event_cb(countButton, CountButtonEventHandler); | ||
| lv_obj_set_size(countButton, 240, 180); | ||
| lv_obj_set_style_local_bg_color(countButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); | ||
| lv_obj_align(countButton, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0); | ||
| countLabel = lv_label_create(lv_scr_act(), nullptr); | ||
| lv_obj_set_style_local_text_font(countLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light); | ||
| lv_obj_align(countLabel, nullptr, LV_ALIGN_IN_TOP_MID, 0, 25); | ||
|
|
||
| messageLabel = lv_label_create(lv_scr_act(), nullptr); | ||
| lv_obj_align(messageLabel, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -75); | ||
| SetMessage("Tap to count"); | ||
|
|
||
| resetButton = lv_btn_create(lv_scr_act(), nullptr); | ||
| resetButton->user_data = this; | ||
| lv_obj_set_event_cb(resetButton, ResetButtonEventHandler); | ||
| lv_obj_set_size(resetButton, 76, 60); | ||
| lv_obj_align(resetButton, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); | ||
| resetLabel = lv_label_create(resetButton, nullptr); | ||
| lv_label_set_text_static(resetLabel, Symbols::undo); | ||
|
|
||
| shakeButton = lv_btn_create(lv_scr_act(), nullptr); | ||
| shakeButton->user_data = this; | ||
| lv_obj_set_event_cb(shakeButton, ShakeButtonEventHandler); | ||
| lv_obj_set_size(shakeButton, 76, 60); | ||
| lv_obj_set_style_local_bg_color(shakeButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); | ||
| lv_obj_align(shakeButton, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); | ||
| shakeLabel = lv_label_create(shakeButton, nullptr); | ||
| lv_label_set_text_static(shakeLabel, Symbols::sort); | ||
|
|
||
| awakeButton = lv_btn_create(lv_scr_act(), nullptr); | ||
| awakeButton->user_data = this; | ||
| lv_obj_set_event_cb(awakeButton, AwakeButtonEventHandler); | ||
| lv_obj_set_size(awakeButton, 76, 60); | ||
| lv_obj_set_style_local_bg_color(awakeButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); | ||
| lv_obj_align(awakeButton, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); | ||
| awakeLabel = lv_label_create(awakeButton, nullptr); | ||
| lv_label_set_text_static(awakeLabel, Symbols::eye); | ||
|
|
||
| UpdateCount(); | ||
|
|
||
| refreshTask = lv_task_create(RefreshTaskCallback, period, LV_TASK_PRIO_MID, this); | ||
| } | ||
|
|
||
| Tally::~Tally() { | ||
| ShakeToWakeDisable(); | ||
| lv_task_del(refreshTask); | ||
| lv_obj_clean(lv_scr_act()); | ||
| } | ||
|
|
||
| void Tally::Refresh() { | ||
| if (shakeToCountEnabled) { | ||
| if (motionController.CurrentShakeSpeed() >= settingsController.GetShakeThreshold()) { | ||
| if (shakeToCountDelay == 0) { | ||
| shakeToCountDelay = shakeDelayTime / period; | ||
| Increment(); | ||
| } | ||
| } else if (shakeToCountDelay > 0) { | ||
| shakeToCountDelay--; | ||
| } | ||
| } | ||
|
|
||
| if (incrementDelay > 0) { | ||
| incrementDelay--; | ||
| } | ||
owenfromcanada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (messageTimer > 0) { | ||
| messageTimer--; | ||
| if (messageTimer == 0) { | ||
| lv_label_set_text_static(messageLabel, ""); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void Tally::Increment() { | ||
| if (incrementDelay <= 0) { | ||
| incrementDelay = incrementDelayTime / period; | ||
| count++; | ||
| if (count == 100) { | ||
| lv_obj_set_style_local_text_font(countLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); | ||
| } | ||
| motorController.RunForDuration(80); | ||
| UpdateCount(); | ||
| } | ||
| } | ||
|
|
||
| void Tally::Reset() { | ||
| if (count >= 100) { | ||
| lv_obj_set_style_local_text_font(countLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light); | ||
| } | ||
| count = 0; | ||
| UpdateCount(); | ||
| } | ||
|
|
||
| void Tally::ToggleShakeToCount() { | ||
| shakeToCountEnabled = !shakeToCountEnabled; | ||
| if (shakeToCountEnabled) { | ||
| ShakeToWakeEnable(); | ||
| } else { | ||
| ShakeToWakeDisable(); | ||
| } | ||
| SetMessage(shakeToCountEnabled ? "Shake-to-count on" : "Shake-to-count off"); | ||
| lv_obj_set_style_local_bg_color(shakeButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, shakeToCountEnabled ? LV_COLOR_GREEN : LV_COLOR_RED); | ||
| } | ||
|
|
||
| void Tally::ToggleKeepAwake() { | ||
| keepAwakeEnabled = !keepAwakeEnabled; | ||
| if (keepAwakeEnabled) { | ||
| wakeLock.Lock(); | ||
| } else { | ||
| wakeLock.Release(); | ||
| } | ||
| SetMessage(keepAwakeEnabled ? "Keep awake on" : "Keep awake off"); | ||
| lv_obj_set_style_local_bg_color(awakeButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, keepAwakeEnabled ? LV_COLOR_GREEN : LV_COLOR_RED); | ||
| } | ||
|
|
||
| void Tally::UpdateCount() { | ||
| lv_label_set_text_fmt(countLabel, "%d", count); | ||
| lv_obj_realign(countLabel); | ||
| } | ||
|
|
||
| void Tally::ShakeToWakeEnable() { | ||
| // if shake-to-wake is not enabled, enable it while this app is open | ||
| shakeToWakeTempEnable = !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake); | ||
| if (shakeToWakeTempEnable) { | ||
| settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, true); | ||
| } | ||
| } | ||
|
|
||
| void Tally::ShakeToWakeDisable() { | ||
| // if shake-to-wake was not enabled before, disable it again | ||
| if (shakeToWakeTempEnable) { | ||
| settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, false); | ||
| shakeToWakeTempEnable = false; | ||
| } | ||
| } | ||
|
|
||
| void Tally::SetMessage(const char* text) { | ||
| lv_label_set_text_static(messageLabel, text); | ||
| lv_obj_realign(messageLabel); | ||
| messageTimer = messageTime / period; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #pragma once | ||
|
|
||
| #include "displayapp/apps/Apps.h" | ||
| #include "displayapp/screens/Screen.h" | ||
| #include "displayapp/Controllers.h" | ||
| #include "systemtask/SystemTask.h" | ||
| #include "systemtask/WakeLock.h" | ||
| #include "Symbols.h" | ||
|
|
||
| namespace Pinetime { | ||
| namespace Applications { | ||
| namespace Screens { | ||
| class Tally : public Screen { | ||
| public: | ||
| Tally(Controllers::MotionController& motionController, | ||
| Controllers::MotorController& motorController, | ||
| Controllers::Settings& settingsController, | ||
| System::SystemTask& systemTask); | ||
| ~Tally() override; | ||
| void Refresh() override; | ||
| void Increment(); | ||
| void Reset(); | ||
| void ToggleShakeToCount(); | ||
| void ToggleKeepAwake(); | ||
|
|
||
| private: | ||
| static constexpr uint16_t period = 100; // milliseconds | ||
| static constexpr uint16_t incrementDelayTime = 100; // milliseconds | ||
| static constexpr uint16_t shakeDelayTime = 200; // milliseconds | ||
| static constexpr uint16_t messageTime = 3000; // milliseconds | ||
| lv_obj_t* countButton; | ||
| lv_obj_t* countLabel; | ||
| lv_obj_t* messageLabel; | ||
| lv_obj_t* resetButton; | ||
| lv_obj_t* resetLabel; | ||
| lv_obj_t* shakeButton; | ||
| lv_obj_t* shakeLabel; | ||
| lv_obj_t* awakeButton; | ||
| lv_obj_t* awakeLabel; | ||
| uint16_t count = 0; | ||
| bool shakeToCountEnabled = false; | ||
| bool shakeToWakeTempEnable = false; | ||
| bool keepAwakeEnabled = false; | ||
| uint16_t incrementDelay = 0; | ||
| uint16_t shakeToCountDelay = 0; | ||
| uint16_t messageTimer = 0; | ||
| void UpdateCount(); | ||
| void ShakeToWakeEnable(); | ||
| void ShakeToWakeDisable(); | ||
| void SetMessage(const char* text); | ||
|
|
||
| Controllers::MotionController& motionController; | ||
| Controllers::MotorController& motorController; | ||
| Controllers::Settings& settingsController; | ||
| Pinetime::System::WakeLock wakeLock; | ||
| lv_task_t* refreshTask; | ||
| }; | ||
| } | ||
|
|
||
| template <> | ||
| struct AppTraits<Apps::Tally> { | ||
| static constexpr Apps app = Apps::Tally; | ||
| static constexpr const char* icon = Screens::Symbols::tally; | ||
|
|
||
| static Screens::Screen* Create(AppControllers& controllers) { | ||
| return new Screens::Tally(controllers.motionController, | ||
| controllers.motorController, | ||
| controllers.settingsController, | ||
| *controllers.systemTask); | ||
| }; | ||
| }; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.