1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 20:49:49 +04:00

Rework by review

This commit is contained in:
Dmitry422
2025-11-11 08:46:32 +07:00
parent da3a2834d4
commit b391cfc71d

View File

@@ -1,15 +1,14 @@
#include "../subghz_i.h" #include "../subghz_i.h"
#include "subghz/types.h" #include "subghz/types.h"
#include "../helpers/subghz_custom_event.h" #include "../helpers/subghz_custom_event.h"
#include <dolphin/dolphin.h>
#include <lib/toolbox/value_index.h> #include <lib/toolbox/value_index.h>
#define TAG "SubGhzSceneSignalSettings" #define TAG "SubGhzSceneSignalSettings"
uint32_t counter_mode = 0xff; static uint32_t counter_mode = 0xff;
#define COUNTER_MODE_COUNT 7 #define COUNTER_MODE_COUNT 7
const char* const counter_mode_text[COUNTER_MODE_COUNT] = { static const char* const counter_mode_text[COUNTER_MODE_COUNT] = {
"System", "System",
"Mode 1", "Mode 1",
"Mode 2", "Mode 2",
@@ -19,7 +18,7 @@ const char* const counter_mode_text[COUNTER_MODE_COUNT] = {
"Mode 6", "Mode 6",
}; };
const int32_t counter_mode_value[COUNTER_MODE_COUNT] = { static const int32_t counter_mode_value[COUNTER_MODE_COUNT] = {
0, 0,
1, 1,
2, 2,
@@ -45,24 +44,14 @@ static Protocols protocols[] = {
#define PROTOCOLS_COUNT (sizeof(protocols) / sizeof(Protocols)); #define PROTOCOLS_COUNT (sizeof(protocols) / sizeof(Protocols));
void subghz_scene_signal_settings_counter_mode_changed(VariableItem* item) { 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); uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, counter_mode_text[index]); variable_item_set_current_value_text(item, counter_mode_text[index]);
counter_mode = counter_mode_value[index]; counter_mode = counter_mode_value[index];
} }
void subghz_scene_signal_settings_variable_item_list_enter_callback(void* context, uint32_t index) {
UNUSED(context);
SubGhz* subghz = context;
if(index == 1) {
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}
}
void subghz_scene_signal_settings_on_enter(void* context) { void subghz_scene_signal_settings_on_enter(void* context) {
// when we open saved file we do some check and fill up subghz->file_path. So now we use it to check is there CounterMode in file or not // When we open saved file we do some check and fill up subghz->file_path.
// So now we use it to check is there CounterMode in file or not
SubGhz* subghz = context; SubGhz* subghz = context;
const char* file_path = furi_string_get_cstr(subghz->file_path); const char* file_path = furi_string_get_cstr(subghz->file_path);
@@ -78,8 +67,8 @@ void subghz_scene_signal_settings_on_enter(void* context) {
counter_mode = 0xff; counter_mode = 0xff;
uint8_t mode_count = 1; uint8_t mode_count = 1;
// open file and check is it contains allowed protocols and CounterMode variable - if not then CcounterMode will stay 0xff // 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 allowed protocol but not contain CounterMode value then setup default CounterMode value = 0 and available CounterMode count for this protocol
// if file contain CounterMode value then load it // if file contain CounterMode value then load it
if(!flipper_format_file_open_existing(fff_data_file, file_path)) { if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
FURI_LOG_E(TAG, "Error open file %s", file_path); FURI_LOG_E(TAG, "Error open file %s", file_path);
@@ -97,7 +86,7 @@ void subghz_scene_signal_settings_on_enter(void* context) {
} }
} }
} }
FURI_LOG_I(TAG, "Current CounterMode value %li", counter_mode); FURI_LOG_D(TAG, "Current CounterMode value %li", counter_mode);
furi_string_free(tmp_string); furi_string_free(tmp_string);
flipper_format_file_close(fff_data_file); flipper_format_file_close(fff_data_file);
@@ -109,8 +98,6 @@ void subghz_scene_signal_settings_on_enter(void* context) {
int32_t value_index; int32_t value_index;
VariableItem* item; VariableItem* item;
variable_item_list_set_enter_callback (variable_item_list,subghz_scene_signal_settings_variable_item_list_enter_callback,subghz);
item = variable_item_list_add( item = variable_item_list_add(
variable_item_list, variable_item_list,
"Counter Mode", "Counter Mode",
@@ -121,16 +108,7 @@ void subghz_scene_signal_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, counter_mode_text[value_index]); variable_item_set_current_value_text(item, counter_mode_text[value_index]);
variable_item_set_locked( variable_item_set_locked(item, (counter_mode == 0xff), "Not available\nfor this\nprotocol!");
item, (counter_mode == 0xff), " Not available \n for this \nprotocol !");
// item = variable_item_list_add(
// variable_item_list,
// "Counter Value",
// 1,
// NULL,
// subghz);
// variable_item_set_current_value_text(item, "FFFFFF");
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
} }
@@ -156,16 +134,16 @@ void subghz_scene_signal_settings_on_exit(void* context) {
Storage* storage = furi_record_open(RECORD_STORAGE); Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
// check is the file available for update or write brand new value and to it // check is the file available for update or write brand new value to it
if(flipper_format_file_open_existing(fff_data_file, file_path)) { if(flipper_format_file_open_existing(fff_data_file, file_path)) {
if(flipper_format_update_uint32(fff_data_file, "CounterMode", &counter_mode, 1)) { if(flipper_format_update_uint32(fff_data_file, "CounterMode", &counter_mode, 1)) {
FURI_LOG_I(TAG, "Successfully update CounterMode value to %li", counter_mode); FURI_LOG_D(TAG, "Successfully update CounterMode value to %li", counter_mode);
} else { } else {
FURI_LOG_E(TAG, "Error update CounterMode value trying append and add .. "); FURI_LOG_E(TAG, "Error update CounterMode value trying append and add .. ");
flipper_format_file_close(fff_data_file); flipper_format_file_close(fff_data_file);
flipper_format_file_open_append(fff_data_file, file_path); flipper_format_file_open_append(fff_data_file, file_path);
if(flipper_format_write_uint32(fff_data_file, "CounterMode", &counter_mode, 1)) { if(flipper_format_write_uint32(fff_data_file, "CounterMode", &counter_mode, 1)) {
FURI_LOG_I(TAG, "Successfully added CounterMode value %li", counter_mode); FURI_LOG_D(TAG, "Successfully added CounterMode value %li", counter_mode);
} else { } else {
FURI_LOG_E(TAG, "Error with adding CounterMode value %li", counter_mode); FURI_LOG_E(TAG, "Error with adding CounterMode value %li", counter_mode);
} }