Merge pull request #70 from derskythe/fix-subghz-last-used-settings

Fix SubGHz last used settings
This commit is contained in:
MX
2022-09-16 21:58:24 +03:00
committed by GitHub
12 changed files with 89 additions and 77 deletions
@@ -112,7 +112,7 @@ bool subghz_scene_decode_raw_start(SubGhz* subghz) {
} while(false);
if(success) {
FURI_LOG_I(TAG, "Listening at \033[0;33m%s\033[0m.", string_get_cstr(file_name));
//FURI_LOG_I(TAG, "Listening at \033[0;33m%s\033[0m.", string_get_cstr(file_name));
file_worker_encoder = subghz_file_encoder_worker_alloc();
if(subghz_file_encoder_worker_start(file_worker_encoder, string_get_cstr(file_name))) {
@@ -237,7 +237,7 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) {
consumed = true;
break;
case SubGhzCustomEventViewReceiverConfig:
FURI_LOG_I(TAG, "No config options");
FURI_LOG_W(TAG, "No config options");
consumed = true;
break;
case SubGhzCustomEventViewReceiverOffDisplay:
@@ -257,7 +257,7 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) {
notification_message(subghz->notifications, &sequence_blink_cyan_10);
break;
case SubGhzNotificationStateRxDone:
notification_message(subghz->notifications, &subghs_sequence_rx);
notification_message(subghz->notifications, &subghz_sequence_rx);
subghz->state_notifications = SubGhzNotificationStateRx;
break;
default:
@@ -115,6 +115,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
case SubGhzCustomEventViewReadRAWBack:
// Check if return from config save values
if(subghz->current_scene == SubGhzSceneReceiverConfig) {
//FURI_LOG_I(TAG, "Raw value: %d", subghz->last_setting->detect_raw);
subghz_last_setting_save(
subghz->last_setting, EXT_PATH("subghz/assets/last_used.txt"));
}
@@ -181,6 +182,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
subghz->current_scene = SubGhzSceneReceiverConfig;
//FURI_LOG_I(TAG, "Raw value: %d", subghz->last_setting->detect_raw);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
consumed = true;
break;
@@ -1,7 +1,9 @@
#include "../subghz_i.h"
#include "../views/receiver.h"
const NotificationSequence subghs_sequence_rx = {
#define TAG "SubGhzSceneReceiver"
const NotificationSequence subghz_sequence_rx = {
&message_green_255,
&message_vibro_on,
@@ -14,7 +16,7 @@ const NotificationSequence subghs_sequence_rx = {
NULL,
};
const NotificationSequence subghs_sequence_rx_locked = {
const NotificationSequence subghz_sequence_rx_locked = {
&message_green_255,
&message_display_backlight_on,
@@ -98,6 +100,8 @@ static void subghz_scene_add_to_history_callback(
void subghz_scene_receiver_on_enter(void* context) {
SubGhz* subghz = context;
subghz_last_setting_set_receiver_values(subghz->last_setting, subghz->txrx->receiver);
string_t str_buff;
string_init(str_buff);
@@ -136,9 +140,11 @@ void subghz_scene_receiver_on_enter(void* context) {
subghz->state_notifications = SubGhzNotificationStateRx;
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
subghz_rx_end(subghz);
};
}
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
// Set values that can be reset after using DetectRAW Scene
subghz_last_setting_set_receiver_values(subghz->last_setting, subghz->txrx->receiver);
subghz_begin(
subghz,
subghz_setting_get_preset_data_by_name(
@@ -158,6 +164,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
case SubGhzCustomEventViewReceiverBack:
// Check if return from config save values
if(subghz->current_scene == SubGhzSceneReceiverConfig) {
//FURI_LOG_I(TAG, "Raw value: %d", subghz->last_setting->detect_raw);
subghz_last_setting_save(
subghz->last_setting, EXT_PATH("subghz/assets/last_used.txt"));
}
@@ -166,7 +173,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
subghz_rx_end(subghz);
subghz_sleep(subghz);
};
}
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
subghz->txrx->idx_menu_chosen = 0;
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
@@ -200,7 +207,10 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz->txrx->idx_menu_chosen =
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzViewIdReceiver, SubGhzCustomEventManagerSet);
subghz->current_scene = SubGhzSceneReceiverConfig;
//FURI_LOG_I(TAG, "Raw value: %d", subghz->last_setting->detect_raw);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
consumed = true;
break;
@@ -226,9 +236,9 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
break;
case SubGhzNotificationStateRxDone:
if(subghz->lock != SubGhzLockOn) {
notification_message(subghz->notifications, &subghs_sequence_rx);
notification_message(subghz->notifications, &subghz_sequence_rx);
} else {
notification_message(subghz->notifications, &subghs_sequence_rx_locked);
notification_message(subghz->notifications, &subghz_sequence_rx_locked);
}
subghz->state_notifications = SubGhzNotificationStateRx;
break;
@@ -240,5 +250,8 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
}
void subghz_scene_receiver_on_exit(void* context) {
UNUSED(context);
SubGhz* subghz = context;
//filter restoration
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
}
@@ -186,8 +186,7 @@ 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->last_setting->detect_raw = detect_raw_value[index];
subghz_protocol_decoder_raw_set_auto_mode(
subghz_receiver_search_decoder_base_by_name(
@@ -265,20 +264,6 @@ void subghz_scene_receiver_config_on_enter(void* context) {
(subghz_setting_get_frequency(subghz->setting, value_index) % 1000000) / 10000);
variable_item_set_current_value_text(item, text_buf);
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
item = variable_item_list_add(
subghz->variable_item_list,
"Hopping:",
HOPPING_COUNT,
subghz_scene_receiver_config_set_hopping_running,
subghz);
value_index = subghz_scene_receiver_config_hopper_value_index(
subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, hopping_text[value_index]);
}
item = variable_item_list_add(
subghz->variable_item_list,
"Modulation:",
@@ -293,6 +278,17 @@ void subghz_scene_receiver_config_on_enter(void* context) {
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
item = variable_item_list_add(
subghz->variable_item_list,
"Hopping:",
HOPPING_COUNT,
subghz_scene_receiver_config_set_hopping_running,
subghz);
value_index = subghz_scene_receiver_config_hopper_value_index(
subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, hopping_text[value_index]);
item = variable_item_list_add(
subghz->variable_item_list,
"Detect Raw:",
@@ -305,10 +301,7 @@ void subghz_scene_receiver_config_on_enter(void* context) {
DETECT_RAW_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, detect_raw_text[value_index]);
}
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
item = variable_item_list_add(
subghz->variable_item_list,
"RSSI for Raw:",
@@ -322,10 +315,7 @@ void subghz_scene_receiver_config_on_enter(void* context) {
RSSI_THRESHOLD_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, rssi_threshold_text[value_index]);
}
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
variable_item_list_add(subghz->variable_item_list, "Lock Keyboard", 1, NULL, NULL);
variable_item_list_set_enter_callback(
subghz->variable_item_list,
@@ -1,7 +1,7 @@
#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"
static const NotificationSequence subghs_sequence_sd_error = {
static const NotificationSequence subghz_sequence_sd_error = {
&message_red_255,
&message_green_255,
&message_do_not_reset,
@@ -39,7 +39,7 @@ void subghz_scene_show_error_on_enter(void* context) {
widget_add_button_element(
subghz->widget, GuiButtonTypeRight, "OK", subghz_scene_show_error_callback, subghz);
} else {
notification_message(subghz->notifications, &subghs_sequence_sd_error);
notification_message(subghz->notifications, &subghz_sequence_sd_error);
}
widget_add_button_element(
+4 -4
View File
@@ -1,9 +1,9 @@
/* Abandon hope, all ye who enter here. */
#include "m-string.h"
#include "subghz/types.h"
#include "subghz_i.h"
#include <m-string.h>
#include <subghz/types.h>
#include <lib/toolbox/path.h>
#include "subghz_i.h"
bool subghz_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
@@ -207,7 +207,7 @@ SubGhz* subghz_alloc() {
subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment);
// Setup values
subghz_last_setting_set_receiver_values(subghz->last_setting, subghz->txrx->receiver);
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
subghz_worker_set_overrun_callback(
subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
+10 -14
View File
@@ -1,9 +1,5 @@
#include "subghz_history.h"
#include <lib/subghz/receiver.h>
#include <lib/subghz/protocols/came.h>
#include <furi.h>
#include <m-string.h>
#define SUBGHZ_HISTORY_MAX 65
#define TAG "SubGhzHistory"
@@ -41,15 +37,9 @@ SubGhzHistory* subghz_history_alloc(void) {
void subghz_history_free(SubGhzHistory* instance) {
furi_assert(instance);
string_clear(instance->tmp_string);
for
M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) {
string_clear(item->item_str);
string_clear(item->preset->name);
free(item->preset);
flipper_format_free(item->flipper_string);
item->type = 0;
}
// Call method instead of code duplicate
subghz_history_reset(instance);
SubGhzHistoryItemArray_clear(instance->history->data);
free(instance->history);
free(instance);
@@ -143,16 +133,22 @@ bool subghz_history_add_to_history(
furi_assert(instance);
furi_assert(context);
if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return false;
if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) {
FURI_LOG_W(TAG, "Out of history slots!");
return false;
}
SubGhzProtocolDecoderBase* decoder_base = context;
if((instance->code_last_hash_data ==
subghz_protocol_decoder_base_get_hash_data(decoder_base)) &&
((furi_get_tick() - instance->last_update_timestamp) < 500)) {
//FURI_LOG_W(TAG, "Too short period for add");
instance->last_update_timestamp = furi_get_tick();
return false;
}
//FURI_LOG_I(TAG, "Add to history. Total: %d", instance->last_index_write + 1);
instance->code_last_hash_data = subghz_protocol_decoder_base_get_hash_data(decoder_base);
instance->last_update_timestamp = furi_get_tick();
+2 -2
View File
@@ -142,5 +142,5 @@ bool subghz_path_is_file(string_t path);
uint32_t subghz_random_serial(void);
void subghz_hopper_update(SubGhz* subghz);
extern const NotificationSequence subghs_sequence_rx;
extern const NotificationSequence subghs_sequence_rx_locked;
extern const NotificationSequence subghz_sequence_rx;
extern const NotificationSequence subghz_sequence_rx_locked;
+15 -19
View File
@@ -1,12 +1,11 @@
#include "subghz_setting.h"
#include "subghz_i.h"
#include "subghz_last_setting.h"
#include <furi.h>
#include <m-list.h>
#include "furi_hal_subghz.h"
#include "furi_hal_subghz_configs.h"
#include <furi_hal_subghz.h>
#include <furi_hal_subghz_configs.h>
#include <lib/subghz/protocols/raw.h>
#define TAG "SubGhzLastSetting"
@@ -41,7 +40,7 @@ void subghz_last_setting_load(SubGhzLastSetting* instance, const char* file_path
string_init(temp_preset);
uint32_t temp_frequency = 0; // Default 433920000
uint32_t temp_hopping = 0; // Default 0
//uint32_t temp_detect_raw = 0; Default 2
uint32_t temp_detect_raw = 0; // Default 2
int32_t temp_rssi_threshold = 0; // Default -72
if(FSE_OK == storage_sd_status(storage) && file_path &&
@@ -49,31 +48,31 @@ void subghz_last_setting_load(SubGhzLastSetting* instance, const char* file_path
flipper_format_read_string(fff_data_file, "Preset", temp_preset);
flipper_format_read_uint32(fff_data_file, "Frequency", (uint32_t*)&temp_frequency, 1);
flipper_format_read_uint32(fff_data_file, "Hopping", (uint32_t*)&temp_hopping, 1);
//flipper_format_read_uint32(fff_data_file, "DetectRaw", (uint32_t*)&temp_detect_raw, 1);
flipper_format_read_uint32(fff_data_file, "DetectRaw", (uint32_t*)&temp_detect_raw, 1);
flipper_format_read_int32(fff_data_file, "Rssi", (int32_t*)&temp_rssi_threshold, 1);
} else {
FURI_LOG_E(TAG, "Error open file %s", file_path);
}
if(string_empty_p(temp_preset)) {
//FURI_LOG_I(TAG, "Last used preset not found");
FURI_LOG_D(TAG, "Last used preset not found");
string_set(instance->preset_name, SUBGHZ_LAST_SETTING_DEFAULT_PRESET);
} else {
string_set(instance->preset_name, temp_preset);
}
if(temp_frequency == 0 || !furi_hal_subghz_is_tx_allowed(temp_frequency)) {
//FURI_LOG_I(TAG, "Last used frequency not found or can't be used!");
FURI_LOG_D(TAG, "Last used frequency not found or can't be used!");
instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY;
} else {
instance->frequency = temp_frequency;
}
/*if(temp_detect_raw == 0) {
if(temp_detect_raw == 0) {
instance->detect_raw = SubGhzProtocolFlag_Decodable;
} else {
instance->detect_raw = temp_detect_raw;
}*/
}
if(temp_rssi_threshold == 0) {
instance->rssi_threshold = -72;
@@ -112,8 +111,8 @@ bool subghz_last_setting_save(SubGhzLastSetting* instance, const char* file_path
if(!flipper_format_insert_or_update_uint32(file, "Frequency", &instance->frequency, 1))
break;
if(!flipper_format_insert_or_update_uint32(file, "Hopping", &instance->hopping, 1)) break;
//if(!flipper_format_insert_or_update_uint32(file, "DetectRaw", &instance->detect_raw, 1))
// break;
if(!flipper_format_insert_or_update_uint32(file, "DetectRaw", &instance->detect_raw, 1))
break;
if(!flipper_format_insert_or_update_int32(file, "Rssi", &instance->rssi_threshold, 1))
break;
@@ -131,14 +130,11 @@ bool subghz_last_setting_save(SubGhzLastSetting* instance, const char* file_path
}
void subghz_last_setting_set_receiver_values(SubGhzLastSetting* instance, SubGhzReceiver* receiver) {
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
/*subghz_receiver_set_filter(receiver, instance->detect_raw);
SubGhzProtocolDecoderBase* protocolDecoderBase =
subghz_receiver_search_decoder_base_by_name(receiver, SUBGHZ_PROTOCOL_RAW_NAME);
subghz_receiver_set_filter(receiver, instance->detect_raw);
subghz_protocol_decoder_raw_set_auto_mode(
subghz_receiver_search_decoder_base_by_name(receiver, SUBGHZ_PROTOCOL_RAW_NAME),
(instance->detect_raw != SubGhzProtocolFlag_Decodable));*/
subghz_protocol_decoder_raw_set_rssi_threshold(
subghz_receiver_search_decoder_base_by_name(receiver, SUBGHZ_PROTOCOL_RAW_NAME),
instance->rssi_threshold);
protocolDecoderBase, (instance->detect_raw != SubGhzProtocolFlag_Decodable));
subghz_protocol_decoder_raw_set_rssi_threshold(protocolDecoderBase, instance->rssi_threshold);
}
@@ -9,7 +9,7 @@ typedef struct {
string_t preset_name;
uint32_t frequency;
uint32_t hopping;
//uint32_t detect_raw;
uint32_t detect_raw;
int32_t rssi_threshold;
} SubGhzLastSetting;
+1 -1
View File
@@ -3,7 +3,7 @@
#include <furi.h>
#include <m-list.h>
#include "furi_hal_subghz_configs.h"
#include <furi_hal_subghz_configs.h>
#define TAG "SubGhzSetting"
@@ -46,7 +46,7 @@ const char* const volume_text[VOLUME_COUNT] = {
};
const float volume_value[VOLUME_COUNT] = {0.0f, 0.25f, 0.5f, 0.75f, 1.0f};
#define DELAY_COUNT 8
#define DELAY_COUNT 11
const char* const delay_text[DELAY_COUNT] = {
"1s",
"5s",
@@ -56,8 +56,23 @@ const char* const delay_text[DELAY_COUNT] = {
"60s",
"90s",
"120s",
"5min",
"10min",
"30min",
};
const uint32_t delay_value[DELAY_COUNT] = {
1000,
5000,
10000,
15000,
30000,
60000,
90000,
120000,
300000,
600000,
1800000
};
const uint32_t delay_value[DELAY_COUNT] = {1000, 5000, 10000, 15000, 30000, 60000, 90000, 120000};
#define VIBRO_COUNT 2
const char* const vibro_text[VIBRO_COUNT] = {