Skip to content

Commit 8c44dfb

Browse files
committed
Save preset, RSSIm ignore values in last settings
- Save preset - Save RSSI - Save Ignore Starline, Cars, Magellan - Fix types of COUNT_OF result - Move subghz_set_default_preset to SubGhzTxRx - In subghz_txrx_radio_device_is_tx_allowed check for SubGhzTxRxStateSleep is not working
1 parent 540862f commit 8c44dfb

18 files changed

+294
-154
lines changed

applications/main/subghz/helpers/subghz_txrx.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ SubGhzTxRx* subghz_txrx_alloc() {
2929

3030
instance->preset = malloc(sizeof(SubGhzRadioPreset));
3131
instance->preset->name = furi_string_alloc();
32-
subghz_txrx_set_preset(
33-
instance, "AM650", subghz_setting_get_default_frequency(instance->setting), NULL, 0);
32+
subghz_txrx_set_default_preset(instance, 0);
3433

3534
instance->txrx_state = SubGhzTxRxStateSleep;
3635

@@ -636,7 +635,7 @@ bool subghz_txrx_radio_device_is_frequency_valid(SubGhzTxRx* instance, uint32_t
636635

637636
bool subghz_txrx_radio_device_is_tx_allowed(SubGhzTxRx* instance, uint32_t frequency) {
638637
furi_assert(instance);
639-
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
638+
//furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
640639

641640
subghz_devices_idle(instance->radio_device);
642641
subghz_devices_set_frequency(instance->radio_device, frequency);
@@ -668,3 +667,31 @@ SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) {
668667
furi_assert(instance);
669668
return instance->receiver;
670669
}
670+
671+
void subghz_txrx_set_default_preset(SubGhzTxRx* instance, uint32_t frequency) {
672+
furi_assert(instance);
673+
674+
const char* default_modulation = "AM650";
675+
if(frequency == 0) {
676+
frequency = subghz_setting_get_default_frequency(subghz_txrx_get_setting(instance));
677+
}
678+
subghz_txrx_set_preset(instance, default_modulation, frequency, NULL, 0);
679+
}
680+
681+
const char*
682+
subghz_txrx_set_preset_internal(SubGhzTxRx* instance, uint32_t frequency, uint8_t index) {
683+
furi_assert(instance);
684+
685+
SubGhzSetting* setting = subghz_txrx_get_setting(instance);
686+
const char* preset_name = subghz_setting_get_preset_name(setting, index);
687+
subghz_setting_set_default_frequency(setting, frequency);
688+
689+
subghz_txrx_set_preset(
690+
instance,
691+
preset_name,
692+
frequency,
693+
subghz_setting_get_preset_data(setting, index),
694+
subghz_setting_get_preset_data_size(setting, index));
695+
696+
return preset_name;
697+
}

applications/main/subghz/helpers/subghz_txrx.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance);
329329
*/
330330
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
331331

332-
/* Get get intelligence whether frequency the selected radio device to use
332+
/* Get intelligence whether frequency the selected radio device to use
333333
*
334334
* @param instance Pointer to a SubGhzTxRx
335335
* @return bool True if the frequency is valid
@@ -344,3 +344,8 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance);
344344
void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance);
345345

346346
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw
347+
348+
void subghz_txrx_set_default_preset(SubGhzTxRx* instance, uint32_t frequency);
349+
350+
const char*
351+
subghz_txrx_set_preset_internal(SubGhzTxRx* instance, uint32_t frequency, uint8_t index);

applications/main/subghz/scenes/subghz_scene_decode_raw.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#include "../subghz_i.h"
2-
#include "../views/receiver.h"
3-
#include <lib/subghz/protocols/raw.h>
4-
5-
#include <lib/subghz/subghz_file_encoder_worker.h>
62

73
#define TAG "SubGhzDecodeRaw"
84
#define SAMPLES_TO_READ_PER_TICK 400
@@ -28,7 +24,11 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
2824
furi_string_free(modulation_str);
2925
} else {
3026
subghz_view_receiver_add_data_statusbar(
31-
subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "", false);
27+
subghz->subghz_receiver,
28+
furi_string_get_cstr(history_stat_str),
29+
"",
30+
"",
31+
subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF);
3232
}
3333
furi_string_free(history_stat_str);
3434
}
@@ -171,7 +171,7 @@ void subghz_scene_decode_raw_on_enter(void* context) {
171171
} else {
172172
//Load history to receiver
173173
subghz_view_receiver_exit(subghz->subghz_receiver);
174-
for(uint8_t i = 0; i < subghz_history_get_item(subghz->history); i++) {
174+
for(uint16_t i = 0; i < subghz_history_get_item(subghz->history); i++) {
175175
furi_string_reset(item_name);
176176
furi_string_reset(item_time);
177177
subghz_history_get_text_item_menu(subghz->history, item_name, i);

applications/main/subghz/scenes/subghz_scene_delete_raw.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "../subghz.h"
12
#include "../subghz_i.h"
23
#include "../helpers/subghz_custom_event.h"
34

applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e
6060
subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer);
6161
if(frequency > 0) {
6262
subghz->last_settings->frequency = frequency;
63+
#ifdef FURI_DEBUG
64+
subghz_last_settings_log(subghz->last_settings, subghz->ignore_filter);
65+
#endif
6366
subghz_last_settings_save(subghz->last_settings);
6467
}
6568

applications/main/subghz/scenes/subghz_scene_read_raw.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,17 @@ void subghz_scene_read_raw_on_enter(void* context) {
104104

105105
if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateBack) {
106106
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
107+
if(furi_string_empty(file_name)) {
108+
subghz_txrx_set_preset_internal(
109+
subghz->txrx,
110+
subghz->last_settings->frequency,
111+
subghz->last_settings->preset_index);
112+
subghz_txrx_speaker_set_state(
113+
subghz->txrx,
114+
subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown :
115+
SubGhzSpeakerStateEnable);
116+
}
107117
}
108-
furi_string_free(file_name);
109118
subghz_scene_read_raw_update_statusbar(subghz);
110119

111120
//set callback view raw
@@ -115,6 +124,8 @@ void subghz_scene_read_raw_on_enter(void* context) {
115124

116125
//set filter RAW feed
117126
subghz_txrx_receiver_set_filter(subghz->txrx, SubGhzProtocolFlag_RAW);
127+
furi_string_free(file_name);
128+
118129
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReadRAW);
119130
}
120131

@@ -139,10 +150,9 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
139150
} else {
140151
//Restore default setting
141152
if(subghz->raw_send_only) {
142-
subghz_set_default_preset(subghz);
153+
subghz_txrx_set_default_preset(subghz->txrx, 0);
143154
} else {
144-
subghz_txrx_set_preset(
145-
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
155+
subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency);
146156
}
147157
if(!scene_manager_search_and_switch_to_previous_scene(
148158
subghz->scene_manager, SubGhzSceneSaved)) {

applications/main/subghz/scenes/subghz_scene_receiver.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "../subghz_i.h"
2-
#include "../views/receiver.h"
32
#include <dolphin/dolphin.h>
43
#include <lib/subghz/protocols/bin_raw.h>
54

@@ -77,7 +76,11 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
7776
furi_string_free(modulation_str);
7877
} else {
7978
subghz_view_receiver_add_data_statusbar(
80-
subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "", false);
79+
subghz->subghz_receiver,
80+
furi_string_get_cstr(history_stat_str),
81+
"",
82+
"",
83+
subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF);
8184
subghz->state_notifications = SubGhzNotificationStateIDLE;
8285
}
8386
furi_string_free(history_stat_str);
@@ -143,7 +146,16 @@ void subghz_scene_receiver_on_enter(void* context) {
143146
FuriString* item_time = furi_string_alloc();
144147

145148
if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) {
146-
subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
149+
subghz->filter = subghz->last_settings->filter;
150+
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
151+
subghz->ignore_filter = subghz->last_settings->ignore_filter;
152+
subghz_txrx_set_preset_internal(
153+
subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index);
154+
subghz_txrx_speaker_set_state(
155+
subghz->txrx,
156+
subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown :
157+
SubGhzSpeakerStateEnable);
158+
147159
subghz_history_reset(history);
148160
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart);
149161
subghz->idx_menu_chosen = 0;
@@ -154,7 +166,7 @@ void subghz_scene_receiver_on_enter(void* context) {
154166

155167
// Load history to receiver
156168
subghz_view_receiver_exit(subghz->subghz_receiver);
157-
for(uint8_t i = 0; i < subghz_history_get_item(history); i++) {
169+
for(uint16_t i = 0; i < subghz_history_get_item(history); i++) {
158170
furi_string_reset(item_name);
159171
furi_string_reset(item_time);
160172
subghz_history_get_text_item_menu(history, item_name, i);
@@ -178,11 +190,10 @@ void subghz_scene_receiver_on_enter(void* context) {
178190
}
179191

180192
// Check if hopping was enabled
181-
#ifdef FURI_DEBUG
182-
subghz_last_settings_log(subghz->last_settings);
183-
#endif
184193
if(subghz->last_settings->enable_hopping) {
185194
subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateRunning);
195+
} else {
196+
subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF);
186197
}
187198

188199
subghz_scene_receiver_update_statusbar(subghz);
@@ -216,8 +227,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
216227
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
217228
} else {
218229
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
219-
subghz_txrx_set_preset(
220-
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
230+
subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency);
221231
scene_manager_search_and_switch_to_previous_scene(
222232
subghz->scene_manager, SubGhzSceneStart);
223233
}

0 commit comments

Comments
 (0)