Skip to content

Commit 79f8d7a

Browse files
authored
Merge pull request #968 from Dmitry422/dev
Subghz Signal Settings Improvements
2 parents 937e937 + 927c563 commit 79f8d7a

File tree

6 files changed

+93
-46
lines changed

6 files changed

+93
-46
lines changed

applications/main/subghz/scenes/subghz_scene_signal_settings.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

70102
void 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

312344
void 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);

lib/subghz/protocols/alutech_at_4n.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#define SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE 0xFFFFFFFFFFFFFFFF
1313
#define SUBGHZ_ALUTECH_AT_4N_RAINBOW_TABLE_SIZE_BYTES 32
1414

15+
//variable used to bypass CounterMode settings if user just change Counter or Button
16+
static bool bypass = false;
17+
1518
static const SubGhzBlockConst subghz_protocol_alutech_at_4n_const = {
1619
.te_short = 400,
1720
.te_long = 800,
@@ -293,9 +296,13 @@ static bool subghz_protocol_alutech_at_4n_gen_data(
293296
instance->generic.serial = (uint32_t)(data >> 24) & 0xFFFFFFFF;
294297
}
295298

296-
if(alutech_at4n_counter_mode == 0) {
299+
// if we change counter/button in SignalSettings menu then we must bypass counter_modes, just gen and save signal file.
300+
if(subghz_block_generic_global.cnt_need_override) bypass = true;
301+
302+
if((alutech_at4n_counter_mode == 0) || bypass) {
297303
// Check for OFEX (overflow experimental) mode
298-
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) {
304+
if((furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) || bypass) {
305+
bypass = false;
299306
// standart counter mode. PULL data from subghz_block_generic_global variables
300307
if(!subghz_block_generic_global_counter_override_get(&instance->generic.cnt)) {
301308
// if counter_override_get return FALSE then counter was not changed and we increase counter by standart mult value
@@ -401,8 +408,10 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload(
401408
btn = subghz_protocol_alutech_at_4n_get_btn_code();
402409

403410
// override button if we change it with signal settings button editor
404-
if(subghz_block_generic_global_button_override_get(&btn))
411+
if(subghz_block_generic_global_button_override_get(&btn)) {
412+
bypass = true;
405413
FURI_LOG_D(TAG, "Button sucessfully changed to 0x%X", btn);
414+
}
406415

407416
// Gen new key
408417
if(!subghz_protocol_alutech_at_4n_gen_data(instance, btn)) {

lib/subghz/protocols/came_atomo.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
#define TAG "SubGhzProtocoCameAtomo"
1313

14+
//variable used to bypass CounterMode settings if user just change Counter or Button
15+
static bool bypass = false;
16+
1417
static const SubGhzBlockConst subghz_protocol_came_atomo_const = {
1518
.te_short = 600,
1619
.te_long = 1200,
@@ -187,9 +190,15 @@ static void subghz_protocol_encoder_came_atomo_get_upload(
187190

188191
uint8_t pack[8] = {};
189192

190-
if(came_atomo_counter_mode == 0) {
193+
// if we change counter/button in SignalSettings menu then we must bypass counter_modes, just gen and save signal file.
194+
if(subghz_block_generic_global.cnt_need_override ||
195+
subghz_block_generic_global.btn_need_override)
196+
bypass = true;
197+
198+
if(came_atomo_counter_mode == 0 || bypass) {
191199
// Check for OFEX (overflow experimental) mode
192-
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) {
200+
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF || bypass) {
201+
bypass = false;
193202
// standart counter mode. PULL data from subghz_block_generic_global variables
194203
if(!subghz_block_generic_global_counter_override_get(&instance->generic.cnt)) {
195204
// if counter_override_get return FALSE then counter was not changed and we increase counter by standart mult value

lib/subghz/protocols/keeloq.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#define TAG "SubGhzProtocolKeeloq"
1717

18+
//variable used to bypass CounterMode settings if user just change Counter or Button
19+
static bool bypass = false;
20+
1821
static const SubGhzBlockConst subghz_protocol_keeloq_const = {
1922
.te_short = 400,
2023
.te_long = 800,
@@ -241,9 +244,10 @@ static bool subghz_protocol_keeloq_gen_data(
241244
if(counter_up && prog_mode == PROG_MODE_OFF) {
242245
// Counter increment conditions
243246

244-
if(keeloq_counter_mode == 0) {
247+
if(keeloq_counter_mode == 0 || bypass) {
245248
// Check for OFEX (overflow experimental) mode
246-
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) {
249+
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF || bypass) {
250+
bypass = false;
247251
// standart counter mode. PULL data from subghz_block_generic_global variables
248252
if(!subghz_block_generic_global_counter_override_get(&instance->generic.cnt)) {
249253
// if counter_override_get return FALSE then counter was not changed and we increase counter by standart mult value
@@ -601,7 +605,13 @@ static bool
601605
instance->encoder.size_upload = 0;
602606
size_t upindex = 0;
603607

604-
if(keeloq_counter_mode == 7) {
608+
// if we change counter/button in SignalSettings menu then we must bypass counter_modes, just gen and save signal file.
609+
if(subghz_block_generic_global.cnt_need_override ||
610+
subghz_block_generic_global.btn_need_override)
611+
bypass = true;
612+
613+
// Create mode7 upload only if counter and button was not changed by SignalSettings menu
614+
if(keeloq_counter_mode == 7 && !bypass) {
605615
uint16_t temp_cnt = instance->generic.cnt;
606616
instance->encoder.repeat = 1;
607617
for(uint8_t i = 7; i > 0; i--) {

lib/subghz/protocols/nice_flor_s.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#define SUBGHZ_NICE_FLOR_S_RAINBOW_TABLE_SIZE_BYTES 32
2222
#define SUBGHZ_NO_NICE_FLOR_S_RAINBOW_TABLE 0
2323

24+
//variable used to bypass CounterMode settings if user just change Counter or Button
25+
static bool bypass = false;
26+
2427
static const SubGhzBlockConst subghz_protocol_nice_flor_s_const = {
2528
.te_short = 500,
2629
.te_long = 1000,
@@ -148,18 +151,25 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload(
148151
btn = subghz_protocol_nice_flor_s_get_btn_code();
149152

150153
// override button if we change it with signal settings button editor
151-
if(subghz_block_generic_global_button_override_get(&btn))
154+
if(subghz_block_generic_global_button_override_get(&btn)) {
155+
bypass = true;
152156
FURI_LOG_D(TAG, "Button sucessfully changed to 0x%X", btn);
157+
}
153158

154159
size_t size_upload = ((instance->generic.data_count_bit * 2) + ((37 + 2 + 2) * 2) * 16);
155160
if(size_upload > instance->encoder.size_upload) {
156161
FURI_LOG_E(TAG, "Size upload exceeds allocated encoder buffer.");
157162
} else {
158163
instance->encoder.size_upload = size_upload;
159164
}
160-
if(nice_flors_counter_mode == 0) {
165+
166+
// if we change counter/button in SignalSettings menu then we must bypass counter_modes, just gen and save signal file.
167+
if(subghz_block_generic_global.cnt_need_override) bypass = true;
168+
169+
if(nice_flors_counter_mode == 0 || bypass) {
161170
// Check for OFEX (overflow experimental) mode
162-
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) {
171+
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF || bypass) {
172+
bypass = false;
163173
// standart counter mode. PULL data from subghz_block_generic_global variables
164174
if(!subghz_block_generic_global_counter_override_get(&instance->generic.cnt)) {
165175
// if counter_override_get return FALSE then counter was not changed and we increase counter by standart mult value

lib/subghz/protocols/phoenix_v2.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#define TAG "SubGhzProtocolPhoenixV2"
1212

13+
//variable used to bypass CounterMode settings if user just change Counter or Button
14+
static bool bypass = false;
15+
1316
static const SubGhzBlockConst subghz_protocol_phoenix_v2_const = {
1417
.te_short = 427,
1518
.te_long = 853,
@@ -256,13 +259,19 @@ static bool
256259
btn = subghz_protocol_phoenix_v2_get_btn_code();
257260

258261
// override button if we change it with signal settings button editor
259-
if(subghz_block_generic_global_button_override_get(&btn))
262+
if(subghz_block_generic_global_button_override_get(&btn)) {
263+
bypass = true;
260264
FURI_LOG_D(TAG, "Button sucessfully changed to 0x%X", btn);
265+
}
261266

262267
// Reconstruction of the data
263-
if(v2_phoenix_counter_mode == 0) {
268+
// if we change counter/button in SignalSettings menu then we must bypass counter_modes, just gen and save signal file.
269+
if(subghz_block_generic_global.cnt_need_override) bypass = true;
270+
271+
if(v2_phoenix_counter_mode == 0 || bypass) {
264272
// Check for OFEX (overflow experimental) mode
265-
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) {
273+
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF || bypass) {
274+
bypass = false;
266275
// standart counter mode. PULL data from subghz_block_generic_global variables
267276
if(!subghz_block_generic_global_counter_override_get(&instance->generic.cnt)) {
268277
// if counter_override_get return FALSE then counter was not changed and we increase counter by standart mult value

0 commit comments

Comments
 (0)