diff --git a/applications/main/subghz/scenes/subghz_scene_signal_settings.c b/applications/main/subghz/scenes/subghz_scene_signal_settings.c index 4433aa2b5..33ce18783 100644 --- a/applications/main/subghz/scenes/subghz_scene_signal_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_signal_settings.c @@ -29,7 +29,22 @@ const int32_t counter_mode_value[COUNTER_MODE_COUNT] = { 6, }; -void subghz_scene_signal_settings_counter_mode_changed(VariableItem* item) { +typedef struct { + char* name; + uint8_t mode_count; +} Protocols; + +// List of protocols names and appropriate CounterMode counts +static Protocols protocols[] = { + {"Nice FloR-S", 3}, + {"CAME Atomo", 4}, + {"Alutech AT-4N", 3}, + {"KeeLoq", 7}, +}; + +#define PROTOCOLS_COUNT (sizeof(protocols) / sizeof(Protocols)); + +void subghz_scene_signal_settings_counter_mode_changed(VariableItem * item) { SubGhz* subghz = variable_item_get_context(item); UNUSED(subghz); uint8_t index = variable_item_get_current_value_index(item); @@ -52,26 +67,28 @@ void subghz_scene_signal_settings_on_enter(void* context) { uint32_t tmp_counter_mode = 0; counter_mode = 0xff; + uint8_t mode_count=1; - // open file and check is it contains allowed protocols and CounterMode variable - if not then CcounterMode will stay 0xff - // if file contain allowed protocols but not contain CounterMode - set it to default 0 - // if file contain CounterMode then load it + // open file and check is it contains allowed protocols and CounterMode variable - if not then CcounterMode will stay 0xff + // if file contain allowed protocol but not contain CounterMode value - set default CounterMode value = 0 and available CounterMode count for this protocol + // if file contain CounterMode value then load it if(!flipper_format_file_open_existing(fff_data_file, file_path)) { FURI_LOG_E(TAG, "Error open file %s", file_path); } else { flipper_format_read_string(fff_data_file, "Protocol", tmp_string); - if((!strcmp(furi_string_get_cstr(tmp_string), "Nice FloR-S")) || - (!strcmp(furi_string_get_cstr(tmp_string), "CAME Atomo")) || - (!strcmp(furi_string_get_cstr(tmp_string), "Alutech AT-4N")) || - (!strcmp(furi_string_get_cstr(tmp_string), "KeeLoq"))) { - if(flipper_format_read_uint32(fff_data_file, "CounterMode", &tmp_counter_mode, 1)) { - counter_mode = (uint8_t)tmp_counter_mode; - } else { - counter_mode = 0; + // compare available protocols names, load CounterMode value from file and setup variable_item_list values_count + for(uint8_t i = 0; i < PROTOCOLS_COUNT i++) { + if(!strcmp(furi_string_get_cstr(tmp_string), protocols[i].name)) { + mode_count = protocols[i].mode_count; + if(flipper_format_read_uint32(fff_data_file, "CounterMode", &tmp_counter_mode, 1)) { + counter_mode = (uint8_t)tmp_counter_mode; + } else { + counter_mode = 0; + } } } } - FURI_LOG_I(TAG, "Loaded CounterMode value %li", counter_mode); + FURI_LOG_I(TAG, "Current CounterMode value %li", counter_mode); furi_string_free(tmp_string); flipper_format_file_close(fff_data_file); @@ -82,15 +99,15 @@ void subghz_scene_signal_settings_on_enter(void* context) { VariableItemList* variable_item_list = subghz->variable_item_list; int32_t value_index; VariableItem* item; - int32_t available_count = COUNTER_MODE_COUNT; + //int32_t available_count = COUNTER_MODE_COUNT; item = variable_item_list_add( variable_item_list, "Counter Mode", - available_count, + mode_count, subghz_scene_signal_settings_counter_mode_changed, subghz); - value_index = value_index_int32(counter_mode, counter_mode_value, available_count); + value_index = value_index_int32(counter_mode, counter_mode_value, mode_count); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, counter_mode_text[value_index]);