Skip to content

Conversation

@Riksu9000
Copy link
Contributor

To not clutter the interface, I added long pressing to reset the timer with visual feedback.

InfiniSim_2022-06-30_100645

@0x0000ff
Copy link

It's looks good. No one can tap the wrong button and reset the timer by accident.

@0x0000ff
Copy link

0x0000ff commented Jul 2, 2022

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.
Shall I add this to the PR?

@Riksu9000
Copy link
Contributor Author

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. Shall I add this to the PR?

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.

@0x0000ff
Copy link

0x0000ff commented Jul 6, 2022

This retains timer settings when on another screen:

Code
diff --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;
       };
     }
   }

@0x0000ff
Copy link

0x0000ff commented Jul 6, 2022

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.

@JF002
Copy link
Collaborator

JF002 commented Jul 7, 2022

We could probably use the Settings controller to retain the last value of the timer. This way, the value could also the persisted across reboot of the watch.

@JF002 JF002 added this to the 1.11.0 milestone Jul 7, 2022
Otherwise the bar would keep increasing if the finger slid off the
button
@Riksu9000 Riksu9000 merged commit 9ee1160 into InfiniTimeOrg:develop Jul 21, 2022
@Riksu9000 Riksu9000 deleted the timer-reset branch July 21, 2022 19:53
@ghost ghost mentioned this pull request Jul 28, 2022
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants