From 284498ddcb4a0adecb5a01b69f016784c7cde744 Mon Sep 17 00:00:00 2001 From: David Lee Date: Mon, 8 Jan 2024 10:07:29 +0100 Subject: [PATCH] Added limitations to first/last pager/station --- application.fam | 2 +- docs/changelog.md | 4 ++++ helpers/meal_pager_storage.c | 24 +++++++++++++++++++++ meal_pager_i.h | 2 +- scenes/meal_pager_scene_menu.c | 3 +++ scenes/meal_pager_scene_set_first_pager.c | 4 ++++ scenes/meal_pager_scene_set_first_station.c | 4 ++++ scenes/meal_pager_scene_set_last_pager.c | 8 +++++++ scenes/meal_pager_scene_set_last_station.c | 10 ++++++++- scenes/meal_pager_scene_settings.c | 1 + 10 files changed, 59 insertions(+), 3 deletions(-) diff --git a/application.fam b/application.fam index 01eb0d23379..98257407a24 100644 --- a/application.fam +++ b/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", diff --git a/docs/changelog.md b/docs/changelog.md index 64f39d6e03d..6d783b4d490 100644 --- a/docs/changelog.md +++ b/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 diff --git a/helpers/meal_pager_storage.c b/helpers/meal_pager_storage.c index 83d9a1796bf..187031f33ad 100644 --- a/helpers/meal_pager_storage.c +++ b/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); + } } \ No newline at end of file diff --git a/meal_pager_i.h b/meal_pager_i.h index fab22e07bf8..2c8de587d55 100644 --- a/meal_pager_i.h +++ b/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 { diff --git a/scenes/meal_pager_scene_menu.c b/scenes/meal_pager_scene_menu.c index f30daac5a86..1f477e13dfb 100644 --- a/scenes/meal_pager_scene_menu.c +++ b/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", diff --git a/scenes/meal_pager_scene_set_first_pager.c b/scenes/meal_pager_scene_set_first_pager.c index 5ee2b0990b1..e8c1611e21e 100644 --- a/scenes/meal_pager_scene_set_first_pager.c +++ b/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; diff --git a/scenes/meal_pager_scene_set_first_station.c b/scenes/meal_pager_scene_set_first_station.c index 0711823d050..ca035883d7e 100644 --- a/scenes/meal_pager_scene_set_first_station.c +++ b/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; diff --git a/scenes/meal_pager_scene_set_last_pager.c b/scenes/meal_pager_scene_set_last_pager.c index 6cfd83f3990..f67cef501ca 100644 --- a/scenes/meal_pager_scene_set_last_pager.c +++ b/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; diff --git a/scenes/meal_pager_scene_set_last_station.c b/scenes/meal_pager_scene_set_last_station.c index 67eb633923f..70efe784415 100644 --- a/scenes/meal_pager_scene_set_last_station.c +++ b/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; diff --git a/scenes/meal_pager_scene_settings.c b/scenes/meal_pager_scene_settings.c index d60efe52da4..7c8f0fee092 100644 --- a/scenes/meal_pager_scene_settings.c +++ b/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); } \ No newline at end of file