-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Reset timer by long pressing on the button #1214
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
Conversation
|
It's looks good. No one can tap the wrong button and reset the timer by accident. |
|
I've modified the counter widget to retain it's value when you exit the timer screen. It's done with a pointer that gets its address when counter.Create(&value) is called. If NULL is passed to the function, it will work like it currently does. |
I don't know what the pointer is for. I'd just pass a value to the constructor. It does sound like a useful feature though. |
|
This retains timer settings when on another screen: Codediff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h
index 93d8afc6..78f95da9 100644
--- a/src/components/timer/TimerController.h
+++ b/src/components/timer/TimerController.h
@@ -25,6 +25,10 @@ namespace Pinetime {
void OnTimerEnd();
+ int minutes = 0 ;
+
+ int seconds = 0 ;
+
private:
System::SystemTask* systemTask = nullptr;
TimerHandle_t timer;
diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp
index a25be1c4..42a3cfc6 100644
--- a/src/displayapp/screens/Timer.cpp
+++ b/src/displayapp/screens/Timer.cpp
@@ -24,8 +24,8 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) : S
lv_label_set_text_static(colonLabel, ":");
lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29);
- minuteCounter.Create();
- secondCounter.Create();
+ minuteCounter.Create(&timerController.minutes);
+ secondCounter.Create(&timerController.seconds);
lv_obj_align(minuteCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
lv_obj_align(secondCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
diff --git a/src/displayapp/widgets/Counter.cpp b/src/displayapp/widgets/Counter.cpp
index ecf39613..b46c4bfb 100644
--- a/src/displayapp/widgets/Counter.cpp
+++ b/src/displayapp/widgets/Counter.cpp
@@ -27,6 +27,8 @@ void Counter::Increment() {
value = min;
}
UpdateLabel();
+ if (valuePtr != NULL)
+ *valuePtr = value;
};
void Counter::Decrement() {
@@ -35,11 +37,15 @@ void Counter::Decrement() {
value = max;
}
UpdateLabel();
+ if (valuePtr != NULL)
+ *valuePtr = value;
};
void Counter::SetValue(int newValue) {
value = newValue;
UpdateLabel();
+ if (valuePtr != NULL)
+ *valuePtr = value;
}
void Counter::HideControls() {
@@ -61,7 +67,11 @@ void Counter::UpdateLabel() {
lv_label_set_text_fmt(number, "%.2i", value);
}
-void Counter::Create() {
+void Counter::Create(int* referencePtr = NULL) {
+
+ if (referencePtr != NULL)
+ valuePtr = referencePtr;
+
constexpr lv_color_t bgColor = LV_COLOR_MAKE(0x38, 0x38, 0x38);
counterContainer = lv_obj_create(lv_scr_act(), nullptr);
@@ -71,8 +81,10 @@ void Counter::Create() {
lv_obj_set_style_local_text_font(number, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
lv_obj_align(number, nullptr, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_auto_realign(number, true);
- lv_label_set_text_static(number, "00");
-
+ if (valuePtr == NULL)
+ lv_label_set_text_static(number, "00");
+ else
+ SetValue(*valuePtr);
static constexpr uint8_t padding = 5;
const uint8_t width = lv_obj_get_width(number) + padding * 2;
static constexpr uint8_t btnHeight = 50;
diff --git a/src/displayapp/widgets/Counter.h b/src/displayapp/widgets/Counter.h
index 3df8b839..20ee851f 100644
--- a/src/displayapp/widgets/Counter.h
+++ b/src/displayapp/widgets/Counter.h
@@ -8,7 +8,7 @@ namespace Pinetime {
public:
Counter(int min, int max);
- void Create();
+ void Create(int* referencePtr);
void Increment();
void Decrement();
void SetValue(int newValue);
@@ -36,6 +36,7 @@ namespace Pinetime {
int value = 0;
int min;
int max;
+ int* valuePtr = NULL;
};
}
}
|
|
Sorry about the long wait for reply. I was busy with things, and I'm still learning my way around VSCode. I made a pointer so that retaining its settings could be optional if use of the counter on any other screen doesn't require it. |
|
We could probably use the |
Otherwise the bar would keep increasing if the finger slid off the button
To not clutter the interface, I added long pressing to reset the timer with visual feedback.