Skip to content

Commit

Permalink
SubGHZ: Sound State saved with rest of settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeroysHub committed Nov 27, 2023
1 parent 7ca4437 commit 9694ece
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
14 changes: 9 additions & 5 deletions applications/main/subghz/scenes/subghz_scene_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,15 @@ void subghz_scene_receiver_on_enter(void* context) {
}

// Check if hopping was enabled, and restart the radio.
if(subghz->last_settings->enable_hopping) {
subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateRunning);
} else {
subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF);
}
subghz_txrx_hopper_set_state(
subghz->txrx,
subghz->last_settings->enable_hopping ? SubGhzHopperStateRunning : SubGhzHopperStateOFF);

// Check if Sound was enabled, and restart the Speaker.
subghz_txrx_speaker_set_state(
subghz->txrx,
subghz->last_settings->enable_sound ? SubGhzSpeakerStateEnable :
SubGhzSpeakerStateDisable);

/* Proper fix now! Start the radio again. */
subghz_txrx_rx_start(subghz->txrx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ static void subghz_scene_receiver_config_set_speaker(VariableItem* item) {

variable_item_set_current_value_text(item, combobox_text[index]);
subghz_txrx_speaker_set_state(subghz->txrx, speaker_value[index]);
subghz->last_settings->enable_sound = (speaker_value[index] == SubGhzSpeakerStateEnable);
}

static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) {
Expand Down
9 changes: 8 additions & 1 deletion applications/main/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,15 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {

subghz->secure_data = malloc(sizeof(SecureData));

//Put the Listen after TX back to what the user selected..
//Put the Listen after TX back to what the user selected.
subghz->ListenAfterTX = subghz->last_settings->enable_listen_after_tx;

//Put the Speaker Back to what the user selected.
subghz_txrx_speaker_set_state(
subghz->txrx,
subghz->last_settings->enable_sound ? SubGhzSpeakerStateEnable :
SubGhzSpeakerStateDisable);

if(!alloc_for_tx_only) {
subghz->ignore_filter = subghz->last_settings->ignore_filter;
subghz->filter = subghz->last_settings->filter;
Expand Down Expand Up @@ -417,3 +423,4 @@ int32_t subghz_app(void* p) {

return 0;
}

15 changes: 13 additions & 2 deletions applications/main/subghz/subghz_last_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD "RSSI"
#define SUBGHZ_LAST_SETTING_FIELD_REPEATER "Repeater"
#define SUBGHZ_LAST_SETTING_FIELD_LISTEN_AFTER_TX "ListenAfterTX"
#define SUBGHZ_LAST_SETTING_FIELD_SOUND "Sound"

SubGhzLastSettings* subghz_last_settings_alloc(void) {
SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings));
Expand All @@ -47,6 +48,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
bool temp_timestamp_file_names = false;
bool temp_enable_hopping = false;
bool temp_enable_listen_after_tx = false;
bool temp_enable_sound = false;
uint32_t temp_RepeaterState = false;
uint32_t temp_ignore_filter = 0;
uint32_t temp_filter = 0;
Expand Down Expand Up @@ -117,6 +119,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
SUBGHZ_LAST_SETTING_FIELD_LISTEN_AFTER_TX,
(bool*)&temp_enable_listen_after_tx,
1);
flipper_format_read_bool(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_SOUND, (bool*)&temp_enable_sound, 1);

} else {
FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH);
Expand All @@ -135,6 +139,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
instance->external_module_power_amp = false;
instance->enable_hopping = false;
instance->enable_listen_after_tx = false;
instance->enable_sound = false;
instance->ignore_filter = 0x00;
// See bin_raw_value in applications/main/subghz/scenes/subghz_scene_receiver_config.c
instance->filter = SubGhzProtocolFlag_Decodable;
Expand Down Expand Up @@ -176,6 +181,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
instance->rssi = rssi_was_read ? temp_rssi : SUBGHZ_RAW_THRESHOLD_MIN;
instance->enable_hopping = temp_enable_hopping;
instance->enable_listen_after_tx = temp_enable_listen_after_tx;
instance->enable_sound = temp_enable_sound;
instance->RepeaterState = temp_RepeaterState;
instance->ignore_filter = ignore_filter_was_read ? temp_ignore_filter : 0x00;
#if SUBGHZ_LAST_SETTING_SAVE_BIN_RAW
Expand Down Expand Up @@ -297,6 +303,10 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
1)) {
break;
}
if(!flipper_format_insert_or_update_bool(
file, SUBGHZ_LAST_SETTING_FIELD_SOUND, &instance->enable_sound, 1)) {
break;
}
saved = true;
} while(0);

Expand Down Expand Up @@ -330,7 +340,7 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) {
TAG,
"Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s,\n"
"Hopping: %s,\nPreset: %ld, RSSI: %.2f, "
"Starline: %s, Cars: %s, Magellan: %s, NiceFloR-S: %s, BinRAW: %s, Repeater: %lu, ListenAfterTX %s",
"Starline: %s, Cars: %s, Magellan: %s, NiceFloR-S: %s, BinRAW: %s, Repeater: %lu, ListenAfterTX %s, Sound: %s",
instance->frequency / 1000000 % 1000,
instance->frequency / 10000 % 100,
instance->frequency_analyzer_feedback_level,
Expand All @@ -352,5 +362,6 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) {
instance->ignore_filter, SubGhzProtocolFlag_NiceFlorS),
subghz_last_settings_log_filter_get_index(instance->filter, SubGhzProtocolFlag_BinRAW),
instance->RepeaterState,
bool_to_char(instance->enable_listen_after_tx));
bool_to_char(instance->enable_listen_after_tx),
bool_to_char(instance->enable_sound));
}
1 change: 1 addition & 0 deletions applications/main/subghz/subghz_last_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct {
bool timestamp_file_names;
bool enable_hopping;
bool enable_listen_after_tx;
bool enable_sound;

uint32_t RepeaterState;
uint32_t ignore_filter;
Expand Down

0 comments on commit 9694ece

Please sign in to comment.