@@ -65,6 +65,38 @@ void subghz_scene_signal_settings_counter_mode_changed(VariableItem* item) {
6565 uint8_t index = variable_item_get_current_value_index (item );
6666 variable_item_set_current_value_text (item , counter_mode_text [index ]);
6767 counter_mode = counter_mode_value [index ];
68+
69+ SubGhz * subghz = variable_item_get_context (item );
70+ const char * file_path = furi_string_get_cstr (subghz -> file_path );
71+
72+ furi_assert (subghz );
73+ furi_assert (file_path );
74+
75+ // update file every time when we change mode
76+ Storage * storage = furi_record_open (RECORD_STORAGE );
77+ FlipperFormat * fff_data_file = flipper_format_file_alloc (storage );
78+
79+ // check is the file available for update/insert CounterMode value
80+ if (flipper_format_file_open_existing (fff_data_file , file_path )) {
81+ if (flipper_format_insert_or_update_uint32 (fff_data_file , "CounterMode" , & counter_mode , 1 )) {
82+ FURI_LOG_D (TAG , "Successfully updated/inserted CounterMode value %li" , counter_mode );
83+ } else {
84+ FURI_LOG_E (TAG , "Error update/insert CounterMode value" );
85+ }
86+ } else {
87+ FURI_LOG_E (TAG , "Error open file %s for writing" , file_path );
88+ }
89+
90+ flipper_format_file_close (fff_data_file );
91+ flipper_format_free (fff_data_file );
92+ furi_record_close (RECORD_STORAGE );
93+
94+ // we need to reload file after editing it
95+ if (subghz_key_load (subghz , file_path , false)) {
96+ FURI_LOG_D (TAG , "Subghz file was successfully reloaded" );
97+ } else {
98+ FURI_LOG_E (TAG , "Error reloading subghz file" );
99+ }
68100}
69101
70102void subghz_scene_signal_settings_byte_input_callback (void * context ) {
@@ -311,40 +343,8 @@ bool subghz_scene_signal_settings_on_event(void* context, SceneManagerEvent even
311343
312344void subghz_scene_signal_settings_on_exit (void * context ) {
313345 SubGhz * subghz = context ;
314- const char * file_path = furi_string_get_cstr (subghz -> file_path );
315346
316347 furi_assert (subghz );
317- furi_assert (file_path );
318-
319- // if ConterMode was changed from 0xff then we must update or write new value to file
320- if (counter_mode != 0xff ) {
321- Storage * storage = furi_record_open (RECORD_STORAGE );
322- FlipperFormat * fff_data_file = flipper_format_file_alloc (storage );
323-
324- // check is the file available for update/insert CounterMode value
325- if (flipper_format_file_open_existing (fff_data_file , file_path )) {
326- if (flipper_format_insert_or_update_uint32 (
327- fff_data_file , "CounterMode" , & counter_mode , 1 )) {
328- FURI_LOG_D (
329- TAG , "Successfully updated/inserted CounterMode value %li" , counter_mode );
330- } else {
331- FURI_LOG_E (TAG , "Error update/insert CounterMode value" );
332- }
333- } else {
334- FURI_LOG_E (TAG , "Error open file %s for writing" , file_path );
335- }
336-
337- flipper_format_file_close (fff_data_file );
338- flipper_format_free (fff_data_file );
339- furi_record_close (RECORD_STORAGE );
340-
341- // we need to reload file after editing when we exit from Signal Settings menu.
342- if (subghz_key_load (subghz , file_path , false)) {
343- FURI_LOG_D (TAG , "Subghz file was successfully reloaded" );
344- } else {
345- FURI_LOG_E (TAG , "Error reloading subghz file" );
346- }
347- }
348348
349349 // Clear views
350350 variable_item_list_set_selected_item (subghz -> variable_item_list , 0 );
0 commit comments