Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save last used SubGHZ config settings #67

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions applications/subghz/scenes/subghz_scene_need_saving.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
subghz_preset_init(
subghz,
"AM650",
subghz_setting_get_default_frequency(subghz->setting),
string_get_cstr(subghz->last_setting->preset_name),
subghz->last_setting->frequency,
NULL,
0);
scene_manager_search_and_switch_to_previous_scene(
Expand Down
20 changes: 18 additions & 2 deletions applications/subghz/scenes/subghz_scene_read_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SubGhzCustomEventViewReadRAWBack:
// Check if return from config save values
if(subghz->current_scene == SubGhzSceneReceiverConfig) {
subghz_last_setting_save(
subghz->last_setting, EXT_PATH("subghz/assets/last_used.txt"));
}
//Stop TX
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
subghz_tx_stop(subghz);
Expand All @@ -131,13 +136,14 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
if((subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) ||
(subghz->txrx->rx_key_state == SubGhzRxKeyStateBack)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit;
subghz->current_scene = SubGhzSceneNeedSaving;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
//Restore default setting
subghz_preset_init(
subghz,
"AM650",
subghz_setting_get_default_frequency(subghz->setting),
string_get_cstr(subghz->last_setting->preset_name),
subghz->last_setting->frequency,
NULL,
0);
if(!scene_manager_search_and_switch_to_previous_scene(
Expand All @@ -146,7 +152,11 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz->scene_manager, SubGhzSceneStart)) {
scene_manager_stop(subghz->scene_manager);
view_dispatcher_stop(subghz->view_dispatcher);
} else {
subghz->current_scene = SubGhzSceneStart;
}
} else {
subghz->current_scene = SubGhzSceneSaved;
}
}
consumed = true;
Expand All @@ -170,6 +180,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
case SubGhzCustomEventViewReadRAWConfig:
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
subghz->current_scene = SubGhzSceneReceiverConfig;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
consumed = true;
break;
Expand All @@ -191,6 +202,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
subghz->current_scene = SubGhzSceneMoreRAW;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW);
consumed = true;
} else {
Expand All @@ -210,6 +222,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
subghz->current_scene = SubGhzSceneShowOnlyRx;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
} else {
DOLPHIN_DEED(DolphinDeedSubGhzSend);
Expand Down Expand Up @@ -269,6 +282,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {

case SubGhzCustomEventViewReadRAWREC:
if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) {
subghz->current_scene = SubGhzSceneNeedSaving;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
//subghz_get_preset_name(subghz, subghz->error_str);
Expand All @@ -289,6 +303,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
} else {
string_set_str(subghz->error_str, "Function requires\nan SD card.");
subghz->current_scene = SubGhzSceneShowError;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
}
Expand All @@ -300,6 +315,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSetRAW);
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
subghz->current_scene = SubGhzSceneSaveName;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
}
consumed = true;
Expand Down
19 changes: 16 additions & 3 deletions applications/subghz/scenes/subghz_scene_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ void subghz_scene_receiver_on_enter(void* context) {

if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) {
subghz_preset_init(
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
subghz,
string_get_cstr(subghz->last_setting->preset_name),
subghz->last_setting->frequency,
NULL,
0);
subghz_history_reset(subghz->txrx->history);
subghz->txrx->rx_key_state = SubGhzRxKeyStateStart;
}
Expand Down Expand Up @@ -152,6 +156,11 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SubGhzCustomEventViewReceiverBack:
// Check if return from config save values
if(subghz->current_scene == SubGhzSceneReceiverConfig) {
subghz_last_setting_save(
subghz->last_setting, EXT_PATH("subghz/assets/last_used.txt"));
}
// Stop CC1101 Rx
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
Expand All @@ -164,15 +173,17 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {

if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit;
subghz->current_scene = SubGhzSceneNeedSaving;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
subghz_preset_init(
subghz,
"AM650",
subghz_setting_get_default_frequency(subghz->setting),
string_get_cstr(subghz->last_setting->preset_name),
subghz->last_setting->frequency,
NULL,
0);
subghz->current_scene = SubGhzSceneStart;
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
Expand All @@ -181,13 +192,15 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
case SubGhzCustomEventViewReceiverOK:
subghz->txrx->idx_menu_chosen =
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
subghz->current_scene = SubGhzSceneReceiverInfo;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo);
consumed = true;
break;
case SubGhzCustomEventViewReceiverConfig:
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz->txrx->idx_menu_chosen =
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
subghz->current_scene = SubGhzSceneReceiverConfig;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
consumed = true;
break;
Expand Down
15 changes: 11 additions & 4 deletions applications/subghz/scenes/subghz_scene_receiver_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
(subghz_setting_get_frequency(subghz->setting, index) % 1000000) / 10000);
variable_item_set_current_value_text(item, text_buf);
subghz->txrx->preset->frequency = subghz_setting_get_frequency(subghz->setting, index);
subghz->last_setting->frequency = subghz->txrx->preset->frequency;
subghz_setting_set_default_frequency(subghz->setting, subghz->txrx->preset->frequency);
} else {
variable_item_set_current_value_index(
item, subghz_setting_get_frequency_default_index(subghz->setting));
Expand All @@ -154,11 +156,13 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
static void subghz_scene_receiver_config_set_preset(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(
item, subghz_setting_get_preset_name(subghz->setting, index));
const char* preset_name = subghz_setting_get_preset_name(subghz->setting, index);
variable_item_set_current_value_text(item, preset_name);
string_set_str(subghz->last_setting->preset_name, preset_name);

subghz_preset_init(
subghz,
subghz_setting_get_preset_name(subghz->setting, index),
preset_name,
subghz->txrx->preset->frequency,
subghz_setting_get_preset_data(subghz->setting, index),
subghz_setting_get_preset_data_size(subghz->setting, index));
Expand All @@ -173,6 +177,7 @@ static void subghz_scene_receiver_config_set_rssi_threshold(VariableItem* item)
subghz_receiver_search_decoder_base_by_name(
subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME),
rssi_threshold_value[index]);
subghz->last_setting->rssi_threshold = rssi_threshold_value[index];
}

static void subghz_scene_receiver_config_set_detect_raw(VariableItem* item) {
Expand All @@ -182,6 +187,8 @@ static void subghz_scene_receiver_config_set_detect_raw(VariableItem* item) {
variable_item_set_current_value_text(item, detect_raw_text[index]);
subghz_receiver_set_filter(subghz->txrx->receiver, detect_raw_value[index]);

subghz->last_setting->detect_raw = detect_raw_value[index];

subghz_protocol_decoder_raw_set_auto_mode(
subghz_receiver_search_decoder_base_by_name(
subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME),
Expand Down Expand Up @@ -221,7 +228,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item)
subghz_setting_get_frequency_default_index(subghz->setting));
}

subghz->txrx->hopper_state = hopping_value[index];
subghz->txrx->hopper_state = subghz->last_setting->hopping = hopping_value[index];
}

static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
Expand Down
20 changes: 17 additions & 3 deletions applications/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,25 @@ SubGhz* subghz_alloc() {
subghz->setting = subghz_setting_alloc();
subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"));

// Load last used values for Read, Read RAW, etc. or default
subghz->last_setting = subghz_last_setting_alloc();
subghz_last_setting_load(subghz->last_setting, EXT_PATH("subghz/assets/last_used.txt"));
subghz_setting_set_default_frequency(subghz->setting, subghz->last_setting->frequency);

//init Worker & Protocol & History & KeyBoard
subghz->lock = SubGhzLockOff;
subghz->txrx = malloc(sizeof(SubGhzTxRx));
subghz->txrx->preset = malloc(sizeof(SubGhzPresetDefinition));
string_init(subghz->txrx->preset->name);
subghz_preset_init(
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
subghz,
string_get_cstr(subghz->last_setting->preset_name),
subghz->last_setting->frequency,
NULL,
0);

subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
subghz->txrx->hopper_state = subghz->last_setting->hopping;
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
subghz->txrx->history = subghz_history_alloc();
subghz->txrx->worker = subghz_worker_alloc();
Expand All @@ -196,7 +205,9 @@ SubGhz* subghz_alloc() {
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s"));
subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment);
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);

// Setup values
subghz_last_setting_set_receiver_values(subghz->last_setting, subghz->txrx->receiver);

subghz_worker_set_overrun_callback(
subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
Expand Down Expand Up @@ -288,6 +299,9 @@ void subghz_free(SubGhz* subghz) {
//setting
subghz_setting_free(subghz->setting);

// Last setting
subghz_last_setting_free(subghz->last_setting);

//Worker & Protocol & History
subghz_receiver_free(subghz->txrx->receiver);
subghz_environment_free(subghz->txrx->environment);
Expand Down
4 changes: 3 additions & 1 deletion applications/subghz/subghz_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "subghz_history.h"
#include "subghz_setting.h"
#include "subghz_last_setting.h"

#include <gui/modules/variable_item_list.h>
#include <lib/toolbox/path.h>
Expand Down Expand Up @@ -100,10 +101,11 @@ struct SubGhz {
SubGhzTestPacket* subghz_test_packet;
string_t error_str;
SubGhzSetting* setting;
SubGhzLastSetting* last_setting;
SubGhzLock lock;

bool in_decoder_scene;

SubGhzScene current_scene;
void* rpc_ctx;
};

Expand Down
Loading