Просмотр исходного кода

Merge pull request #22 from leedave/feature/stationSet

Added limitations to first/last pager/station
David Lee 2 лет назад
Родитель
Сommit
663a9859aa

+ 1 - 1
application.fam

@@ -7,7 +7,7 @@ App(
     fap_icon="icons/meal_pager_10px.png",
     fap_icon_assets="icons",
     fap_category="Sub-Ghz",
-    fap_version="1.1",
+    fap_version="1.2",
     fap_libs=["assets"],
     fap_author="leedave",
     fap_weburl="https://github.com/leedave/flipper-zero-meal-pager",

+ 4 - 0
docs/changelog.md

@@ -1,3 +1,7 @@
+## v1.2
+- Fixed Memory bug in Last Station UI
+- Added auto-correction when entries in First/Last station/pager are out of range
+
 ## v1.1
 - Created a new UI Input View as FW does not supply one for numbers
 - New UI to Set First Station

+ 24 - 0
helpers/meal_pager_storage.c

@@ -221,4 +221,28 @@ void meal_pager_set_max_values(void* context) {
         app->max_pager = 999;
         break;
     }
+    if(app->first_station > app->max_station) {
+        app->first_station = app->max_station;
+        snprintf(app->text_store[0], 5, "%lu", app->first_station);
+    }
+    if(app->last_station > app->max_station) {
+        app->last_station = app->max_station;
+        snprintf(app->text_store[1], 5, "%lu", app->last_station);
+    }
+    if(app->last_station < app->first_station) {
+        app->last_station = app->first_station;
+        snprintf(app->text_store[1], 5, "%lu", app->last_station);
+    }
+    if(app->first_pager > app->max_pager) {
+        app->first_pager = app->max_pager;
+        snprintf(app->text_store[2], 4, "%lu", app->first_pager);
+    }
+    if(app->last_pager > app->max_pager) {
+        app->last_pager = app->max_pager;
+        snprintf(app->text_store[3], 4, "%lu", app->last_pager);
+    }
+    if(app->last_pager < app->first_pager) {
+        app->last_pager = app->first_pager;
+        snprintf(app->text_store[3], 4, "%lu", app->last_pager);
+    }
 }

+ 1 - 1
meal_pager_i.h

@@ -64,7 +64,7 @@ typedef struct {
     char* text_buffer;
     uint32_t max_station;
     uint32_t max_pager;
-    char text_store[6][129];
+    char text_store[6][36];
 } Meal_Pager;
 
 typedef enum {

+ 3 - 0
scenes/meal_pager_scene_menu.c

@@ -1,5 +1,6 @@
 #include "../meal_pager_i.h"
 #include "../helpers/meal_pager_led.h"
+#include "../helpers/meal_pager_storage.h"
 #include "../views/meal_pager_transmit.h"
 
 enum SubmenuIndex {
@@ -22,6 +23,8 @@ void meal_pager_scene_menu_submenu_callback(void* context, uint32_t index) {
 void meal_pager_scene_menu_on_enter(void* context) {
     Meal_Pager* app = context;
 
+    meal_pager_set_max_values(app);
+
     submenu_add_item(
         app->submenu,
         "Send Data",

+ 4 - 0
scenes/meal_pager_scene_set_first_pager.c

@@ -41,6 +41,10 @@ bool meal_pager_scene_set_first_pager_on_event(void* context, SceneManagerEvent
         return true;
     } else if(event.type == SceneManagerEventTypeCustom) {
         app->first_pager = atoi(app->text_store[2]);
+        if(app->first_pager > app->max_pager) {
+            app->first_pager = app->max_pager;
+            snprintf(app->text_store[2], 4, "%lu", app->first_pager);
+        }
         app->first_pager_char = app->text_store[2];
         scene_manager_previous_scene(app->scene_manager);
         return true;

+ 4 - 0
scenes/meal_pager_scene_set_first_station.c

@@ -41,6 +41,10 @@ bool meal_pager_scene_set_first_station_on_event(void* context, SceneManagerEven
         return true;
     } else if(event.type == SceneManagerEventTypeCustom) {
         app->first_station = atoi(app->text_store[0]);
+        if(app->first_station > app->max_station) {
+            app->first_station = app->max_station;
+            snprintf(app->text_store[0], 5, "%lu", app->first_station);
+        }
         app->first_station_char = app->text_store[0];
         scene_manager_previous_scene(app->scene_manager);
         return true;

+ 8 - 0
scenes/meal_pager_scene_set_last_pager.c

@@ -41,6 +41,14 @@ bool meal_pager_scene_set_last_pager_on_event(void* context, SceneManagerEvent e
         return true;
     } else if(event.type == SceneManagerEventTypeCustom) {
         app->last_pager = atoi(app->text_store[3]);
+        if(app->last_pager > app->max_pager) {
+            app->last_pager = app->max_pager;
+            snprintf(app->text_store[3], 4, "%lu", app->last_pager);
+        }
+        if(app->last_pager < app->first_pager) {
+            app->last_pager = app->first_pager;
+            snprintf(app->text_store[3], 4, "%lu", app->last_pager);
+        }
         app->last_pager_char = app->text_store[3];
         scene_manager_previous_scene(app->scene_manager);
         return true;

+ 9 - 1
scenes/meal_pager_scene_set_last_station.c

@@ -17,7 +17,7 @@ void meal_pager_scene_set_last_station_on_enter(void* context) {
     meal_pager_set_max_values(app);
     char* str = "Set Last Station (0 - 9999)";
     const char* constStr = str;
-    snprintf(str, 36, "Set Last Station (%lu - %lu)", app->last_station, app->max_station);
+    snprintf(str, 36, "Set Last Station (%lu - %lu)", app->first_station, app->max_station);
 
     int_input_set_header_text(int_input, constStr);
 
@@ -41,6 +41,14 @@ bool meal_pager_scene_set_last_station_on_event(void* context, SceneManagerEvent
         return true;
     } else if(event.type == SceneManagerEventTypeCustom) {
         app->last_station = atoi(app->text_store[1]);
+        if(app->last_station > app->max_station) {
+            app->last_station = app->max_station;
+            snprintf(app->text_store[1], 5, "%lu", app->last_station);
+        }
+        if(app->last_station < app->first_station) {
+            app->last_station = app->first_station;
+            snprintf(app->text_store[1], 5, "%lu", app->last_station);
+        }
         app->last_station_char = app->text_store[1];
         scene_manager_previous_scene(app->scene_manager);
         return true;

+ 1 - 0
scenes/meal_pager_scene_settings.c

@@ -233,4 +233,5 @@ void meal_pager_scene_settings_on_exit(void* context) {
     Meal_Pager* app = context;
     variable_item_list_set_selected_item(app->variable_item_list, 0);
     variable_item_list_reset(app->variable_item_list);
+    meal_pager_set_max_values(app);
 }