Skip to content

Commit d366342

Browse files
committed
ensure RAW subghz signals repeat
1 parent 0cfc811 commit d366342

File tree

4 files changed

+66
-22
lines changed

4 files changed

+66
-22
lines changed

actions/action_subghz.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static const SubGhzDevice* action_subghz_get_device(uint32_t* device_ind) {
7575
void action_subghz_tx(void* context, const FuriString* action_path, FuriString* error) {
7676
App* app = context;
7777
const char* file_name = furi_string_get_cstr(action_path);
78-
uint32_t repeat = 1; // This is set to 10 in the cli - why?
78+
uint32_t repeat = app->settings.subghz_repeat; // Defaults to 10 in the CLI
7979
uint32_t device_ind = app->settings.subghz_use_ext_antenna ? 1 : 0;
8080

8181
FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
@@ -94,10 +94,10 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
9494
subghz_devices_init();
9595
SubGhzEnvironment* environment = subghz_environment_alloc();
9696
if(!subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME)) {
97-
FURI_LOG_E(TAG, "Load_keystore keeloq_mfcodes ERROR");
97+
FURI_LOG_W(TAG, "Load_keystore keeloq_mfcodes - failed to load");
9898
}
9999
if(!subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME)) {
100-
FURI_LOG_E(TAG, "Load_keystore keeloq_mfcodes_user ERROR");
100+
FURI_LOG_W(TAG, "Load_keystore keeloq_mfcodes_user - failed to load");
101101
}
102102
subghz_environment_set_came_atomo_rainbow_table_file_name(
103103
environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
@@ -154,16 +154,17 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
154154
break;
155155
}
156156

157-
if(action_subghz_get_preset_name(furi_string_get_cstr(temp_str)) ==
158-
FuriHalSubGhzPresetIDLE) {
157+
FuriHalSubGhzPreset preset = action_subghz_get_preset_name(furi_string_get_cstr(temp_str));
158+
if(preset == FuriHalSubGhzPresetIDLE) {
159159
ACTION_SET_ERROR("SUBGHZ: Unknown preset");
160160
break;
161161
}
162162

163163
subghz_devices_begin(device);
164164
subghz_devices_reset(device);
165+
subghz_devices_idle(device);
165166

166-
if(!strcmp(furi_string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) {
167+
if(preset == FuriHalSubGhzPresetCustom) {
167168
uint8_t* custom_preset_data;
168169
uint32_t custom_preset_data_size;
169170
if(!flipper_format_get_value_count(fff_data_file, "Custom_preset_data", &temp_data32))
@@ -184,14 +185,10 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
184185
ACTION_SET_ERROR("SUBGHZ: Custom_preset_data read error");
185186
break;
186187
}
187-
subghz_devices_load_preset(
188-
device,
189-
action_subghz_get_preset_name(furi_string_get_cstr(temp_str)),
190-
custom_preset_data);
188+
subghz_devices_load_preset(device, preset, custom_preset_data);
191189
free(custom_preset_data);
192190
} else {
193-
subghz_devices_load_preset(
194-
device, action_subghz_get_preset_name(furi_string_get_cstr(temp_str)), NULL);
191+
subghz_devices_load_preset(device, preset, NULL);
195192
}
196193

197194
subghz_devices_set_frequency(device, frequency);
@@ -205,7 +202,7 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
205202

206203
SubGhzProtocolStatus status;
207204
bool is_init_protocol = true;
208-
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
205+
if(furi_string_equal(temp_str, "RAW")) {
209206
FURI_LOG_I(TAG, "Protocol = RAW");
210207
subghz_protocol_raw_gen_fff_data(
211208
fff_data_raw, file_name, subghz_devices_get_name(device));
@@ -225,7 +222,10 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
225222
}
226223
} else { // if not RAW protocol
227224
FURI_LOG_I(TAG, "Protocol != RAW");
228-
flipper_format_insert_or_update_uint32(fff_data_file, "Repeat", &repeat, 1);
225+
bool repeat_exists = flipper_format_key_exist(fff_data_file, "Repeat");
226+
if(!repeat_exists) {
227+
flipper_format_write_uint32(fff_data_file, "Repeat", &repeat, 1);
228+
}
229229
transmitter =
230230
subghz_transmitter_alloc_init(environment, furi_string_get_cstr(temp_str));
231231
if(transmitter == NULL) {
@@ -240,7 +240,9 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
240240
is_init_protocol = false;
241241
}
242242
}
243-
flipper_format_delete_key(fff_data_file, "Repeat");
243+
if(!repeat_exists) {
244+
flipper_format_delete_key(fff_data_file, "Repeat");
245+
}
244246
}
245247

246248
if(is_init_protocol) {
@@ -256,32 +258,34 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
256258

257259
if(check_file) {
258260
furi_hal_power_suppress_charge_enter();
261+
subghz_devices_set_tx(device);
259262
FURI_LOG_I(
260263
TAG,
261264
"Transmitting at %s. Frequency=%lu, Protocol=%s",
262265
file_name,
263266
frequency,
264267
furi_string_get_cstr(temp_str));
265268
do {
266-
// delay in downloading files and other preparatory processes
267-
furi_delay_ms(200);
269+
// FURI_LOG_I(TAG, "delaying 200ms");
270+
furi_delay_ms(100); // needed? orig 200
268271
if(subghz_devices_start_async_tx(device, subghz_transmitter_yield, transmitter)) {
269-
while(!(subghz_devices_is_async_complete_tx(
270-
device))) { // || cli_cmd_interrupt_received
271-
furi_delay_ms(333);
272+
while(!subghz_devices_is_async_complete_tx(device)) {
273+
// || cli_cmd_interrupt_received
274+
furi_delay_ms(100); // orig 333
272275
}
273276
subghz_devices_stop_async_tx(device);
274277
} else {
275278
FURI_LOG_W(TAG, "Transmission on this frequency is restricted in your region");
276279
}
277280

278-
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
281+
if(furi_string_equal(temp_str, "RAW")) {
279282
subghz_transmitter_stop(transmitter);
280283
repeat--;
284+
// FURI_LOG_I(TAG, "decrementing repeat: %lu", repeat);
281285
if(repeat) subghz_transmitter_deserialize(transmitter, fff_data_raw);
282286
}
283287

284-
} while(repeat && !strcmp(furi_string_get_cstr(temp_str), "RAW"));
288+
} while(repeat && furi_string_equal(temp_str, "RAW"));
285289

286290
subghz_devices_sleep(device);
287291
subghz_devices_end(device);

quac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct App {
5656
bool show_headers; // Defaults to True
5757
uint32_t rfid_duration; // Defaults to 2500 ms
5858
uint32_t nfc_duration; // Defaults to 1000 ms
59+
uint32_t subghz_repeat; // Defaults to 10, just like the CLI
5960
bool subghz_use_ext_antenna; // Defaults to False
6061
bool show_hidden; // Defaults to False
6162
} settings;

quac_settings.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ void quac_set_default_settings(App* app) {
1212
app->settings.show_headers = true;
1313
app->settings.rfid_duration = 2500;
1414
app->settings.nfc_duration = 1000;
15+
app->settings.subghz_repeat = 10;
1516
app->settings.subghz_use_ext_antenna = false;
1617
app->settings.show_hidden = false;
1718
}
@@ -81,6 +82,12 @@ void quac_load_settings(App* app) {
8182
app->settings.nfc_duration = temp_data32;
8283
}
8384

85+
if(!flipper_format_read_uint32(fff_settings, "SubGHz Repeat", &temp_data32, 1)) {
86+
FURI_LOG_W(TAG, "SETTINGS: Missing 'SubGHz Repeat'");
87+
} else {
88+
app->settings.subghz_repeat = temp_data32;
89+
}
90+
8491
if(!flipper_format_read_uint32(fff_settings, "SubGHz Ext Antenna", &temp_data32, 1)) {
8592
FURI_LOG_W(TAG, "SETTINGS: Missing 'SubGHz Ext Antenna'");
8693
} else {
@@ -144,6 +151,11 @@ void quac_save_settings(App* app) {
144151
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'NFC Duration'");
145152
break;
146153
}
154+
if(!flipper_format_write_uint32(
155+
fff_settings, "SubGHz Repeat", &app->settings.subghz_repeat, 1)) {
156+
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'SubGHz Repeat'");
157+
break;
158+
}
147159
temp_data32 = app->settings.subghz_use_ext_antenna ? 1 : 0;
148160
if(!flipper_format_write_uint32(fff_settings, "SubGHz Ext Antenna", &temp_data32, 1)) {
149161
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'SubGHz Ext Antenna'");

scenes/scene_settings.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef enum {
2020
SceneSettingsHeaders,
2121
SceneSettingsRFIDDuration,
2222
SceneSettingsNFCDuration,
23+
SceneSettingsSubGHzRepeat,
2324
SceneSettingsSubGHzExtAnt,
2425
SceneSettingsHidden,
2526
SceneSettingsAbout
@@ -53,6 +54,19 @@ static const uint32_t duration_value[V_DURATION_COUNT] = {
5354
10000,
5455
};
5556

57+
#define V_REPEAT_COUNT 9
58+
static const char* const repeat_text[V_REPEAT_COUNT] = {
59+
"1",
60+
"2",
61+
"3",
62+
"5",
63+
"8",
64+
"10", // default
65+
"15",
66+
"20",
67+
"50"};
68+
static const uint32_t repeat_value[V_REPEAT_COUNT] = {1, 2, 3, 5, 8, 10, 15, 20, 50};
69+
5670
static const char* const subghz_ext_text[2] = {"Disabled", "Enabled"};
5771
static const uint32_t subghz_ext_value[2] = {false, true};
5872

@@ -91,6 +105,13 @@ static void scene_settings_nfc_duration_changed(VariableItem* item) {
91105
app->settings.nfc_duration = duration_value[index];
92106
}
93107

108+
static void scene_settings_subghz_repeat_changed(VariableItem* item) {
109+
App* app = variable_item_get_context(item);
110+
uint8_t index = variable_item_get_current_value_index(item);
111+
variable_item_set_current_value_text(item, repeat_text[index]);
112+
app->settings.subghz_repeat = repeat_value[index];
113+
}
114+
94115
static void scene_settings_subghz_ext_changed(VariableItem* item) {
95116
App* app = variable_item_get_context(item);
96117
uint8_t index = variable_item_get_current_value_index(item);
@@ -149,6 +170,12 @@ void scene_settings_on_enter(void* context) {
149170
variable_item_set_current_value_index(item, value_index);
150171
variable_item_set_current_value_text(item, duration_text[value_index]);
151172

173+
item = variable_item_list_add(
174+
vil, "SubGHz Repeat", V_REPEAT_COUNT, scene_settings_subghz_repeat_changed, app);
175+
value_index = value_index_uint32(app->settings.subghz_repeat, repeat_value, V_REPEAT_COUNT);
176+
variable_item_set_current_value_index(item, value_index);
177+
variable_item_set_current_value_text(item, repeat_text[value_index]);
178+
152179
item =
153180
variable_item_list_add(vil, "SubGHz Ext Ant", 2, scene_settings_subghz_ext_changed, app);
154181
value_index = value_index_uint32(app->settings.subghz_use_ext_antenna, subghz_ext_value, 2);

0 commit comments

Comments
 (0)