Преглед на файлове

add progress bar and other changes

0w0mewo преди 3 години
родител
ревизия
f63ba6aada
променени са 4 файла, в които са добавени 38 реда и са изтрити 41 реда
  1. 12 19
      utils/utils.c
  2. 2 0
      utils/utils.h
  3. 23 19
      views/countdown_view.c
  4. 1 3
      views/countdown_view.h

+ 12 - 19
utils/utils.c

@@ -1,23 +1,6 @@
+#include <furi.h>
 #include "utils.h"
 #include "utils.h"
 
 
-static const NotificationSequence sequence_finish = {
-    &message_display_backlight_on,
-    &message_blue_255,
-    &message_vibro_on,
-    &message_note_c5,
-    &message_delay_250,
-    &message_note_c5,
-    &message_delay_500,
-    &message_note_c5,
-    &message_delay_100,
-    &message_note_c5,
-    &message_delay_500,
-    &message_sound_off,
-    &message_vibro_off,
-    &message_delay_250,
-    NULL,
-};
-
 static const NotificationSequence sequence_beep = {
 static const NotificationSequence sequence_beep = {
     &message_blue_255,
     &message_blue_255,
     &message_note_d5,
     &message_note_d5,
@@ -37,5 +20,15 @@ void notification_off() {
 }
 }
 
 
 void notification_timeup() {
 void notification_timeup() {
-    notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_finish);
+    notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_audiovisual_alert);
+}
+
+void parse_sec_to_time_str(char* buffer, size_t len, int32_t sec) {
+    snprintf(
+        buffer,
+        len,
+        "%02ld:%02ld:%02ld",
+        (sec % (60 * 60 * 24)) / (60 * 60), // hour
+        (sec % (60 * 60)) / 60, // minute
+        sec % 60); // second
 }
 }

+ 2 - 0
utils/utils.h

@@ -7,4 +7,6 @@ void notification_beep_once();
 void notification_off();
 void notification_off();
 void notification_timeup();
 void notification_timeup();
 
 
+void parse_sec_to_time_str(char *buffer, size_t len, int32_t sec);
+
 #endif // __UTILS_H__
 #endif // __UTILS_H__

+ 23 - 19
views/countdown_view.c

@@ -74,9 +74,15 @@ static void countdown_timer_view_on_enter(void* ctx) {
 
 
     CountDownTimView* cdv = (CountDownTimView*)ctx;
     CountDownTimView* cdv = (CountDownTimView*)ctx;
 
 
-    // set current count to 10 seconds
+    // set current count to a initial value
     with_view_model(
     with_view_model(
-        cdv->view, CountDownModel * model, { model->count = 10; }, true);
+        cdv->view,
+        CountDownModel * model,
+        {
+            model->count = INIT_COUNT;
+            model->saved_count_setting = INIT_COUNT;
+        },
+        true);
 }
 }
 
 
 // view draw callback, CountDownModel as ctx
 // view draw callback, CountDownModel as ctx
@@ -86,23 +92,21 @@ static void countdown_timer_view_on_draw(Canvas* canvas, void* ctx) {
 
 
     char buffer[64];
     char buffer[64];
 
 
-    int32_t sec = model->count;
+    int32_t count = model->count;
+    int32_t expected_count = model->saved_count_setting;
+
     CountDownViewSelect select = model->select;
     CountDownViewSelect select = model->select;
 
 
-    elements_frame(canvas, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+    // elements_frame(canvas, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 
 
     canvas_set_font(canvas, FontBigNumbers);
     canvas_set_font(canvas, FontBigNumbers);
     draw_selection(canvas, select);
     draw_selection(canvas, select);
 
 
-    snprintf(
-        buffer,
-        sizeof(buffer),
-        "%02ld:%02ld:%02ld",
-        (sec % (60 * 60 * 24)) / (60 * 60), // hour
-        (sec % (60 * 60)) / 60, // minute
-        sec % 60); // second
+    parse_sec_to_time_str(buffer, sizeof(buffer), count);
     canvas_draw_str_aligned(
     canvas_draw_str_aligned(
         canvas, SCREEN_CENTER_X, SCREEN_CENTER_Y, AlignCenter, AlignCenter, buffer);
         canvas, SCREEN_CENTER_X, SCREEN_CENTER_Y, AlignCenter, AlignCenter, buffer);
+
+    elements_progress_bar(canvas, 0, 0, SCREEN_WIDTH, (1.0 * count / expected_count));
 }
 }
 
 
 // keys input event callback, CountDownTimView as ctx
 // keys input event callback, CountDownTimView as ctx
@@ -158,7 +162,7 @@ static void timer_cb(void* ctx) {
 
 
     CountDownTimView* cdv = (CountDownTimView*)ctx;
     CountDownTimView* cdv = (CountDownTimView*)ctx;
 
 
-    int32_t sec;
+    int32_t count;
     bool timeup = false;
     bool timeup = false;
 
 
     // decrement counter
     // decrement counter
@@ -166,16 +170,16 @@ static void timer_cb(void* ctx) {
         cdv->view,
         cdv->view,
         CountDownModel * model,
         CountDownModel * model,
         {
         {
-            sec = model->count;
-            sec--;
+            count = model->count;
+            count--;
 
 
             // check timeup
             // check timeup
-            if(sec <= 0) {
-                sec = 0;
+            if(count <= 0) {
+                count = 0;
                 timeup = true;
                 timeup = true;
             }
             }
 
 
-            model->count = sec;
+            model->count = count;
         },
         },
         true);
         true);
 
 
@@ -321,13 +325,13 @@ static void handle_time_setting_select(InputKey key, CountDownTimView* cdv) {
 static void draw_selection(Canvas* canvas, CountDownViewSelect selection) {
 static void draw_selection(Canvas* canvas, CountDownViewSelect selection) {
     switch(selection) {
     switch(selection) {
     case CountDownTimerSelectSec:
     case CountDownTimerSelectSec:
-        elements_slightly_rounded_box(canvas, SCREEN_CENTER_X + 25, SCREEN_CENTER_Y + 11, 21, 2);
+        elements_slightly_rounded_box(canvas, SCREEN_CENTER_X + 25, SCREEN_CENTER_Y + 11, 24, 2);
         break;
         break;
     case CountDownTimerSelectMinute:
     case CountDownTimerSelectMinute:
         elements_slightly_rounded_box(canvas, SCREEN_CENTER_X - 10, SCREEN_CENTER_Y + 11, 21, 2);
         elements_slightly_rounded_box(canvas, SCREEN_CENTER_X - 10, SCREEN_CENTER_Y + 11, 21, 2);
         break;
         break;
     case CountDownTimerSelectHour:
     case CountDownTimerSelectHour:
-        elements_slightly_rounded_box(canvas, SCREEN_CENTER_X - 47, SCREEN_CENTER_Y + 11, 21, 2);
+        elements_slightly_rounded_box(canvas, SCREEN_CENTER_X - 47, SCREEN_CENTER_Y + 11, 24, 2);
         break;
         break;
     }
     }
 }
 }

+ 1 - 3
views/countdown_view.h

@@ -11,9 +11,7 @@
 #define SCREEN_CENTER_X (SCREEN_WIDTH / 2)
 #define SCREEN_CENTER_X (SCREEN_WIDTH / 2)
 #define SCREEN_CENTER_Y (SCREEN_HEIGHT / 2)
 #define SCREEN_CENTER_Y (SCREEN_HEIGHT / 2)
 
 
-#define MAX_SCALE 80
-#define MAX_MOVE_STEP 16
-#define MIN_MOVE_STEP 2
+#define INIT_COUNT 10
 
 
 typedef enum {
 typedef enum {
     CountDownTimerMinuteUp,
     CountDownTimerMinuteUp,