mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-13 13:09:49 +04:00
Merge pull request #77 from derskythe/subghz-save-settings-v2
SubGHz save settings version 2
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#include "../subghz_i.h"
|
#include "../subghz_i.h"
|
||||||
#include "../views/subghz_frequency_analyzer.h"
|
|
||||||
#include <dolphin/dolphin.h>
|
#include <dolphin/dolphin.h>
|
||||||
|
|
||||||
void subghz_scene_frequency_analyzer_callback(SubGhzCustomEvent event, void* context) {
|
void subghz_scene_frequency_analyzer_callback(SubGhzCustomEvent event, void* context) {
|
||||||
@@ -17,8 +16,18 @@ void subghz_scene_frequency_analyzer_on_enter(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
|
bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
|
||||||
UNUSED(context);
|
SubGhz* subghz = context;
|
||||||
UNUSED(event);
|
if(event.type == SceneManagerEventTypeCustom &&
|
||||||
|
event.event == SubGhzCustomEventViewReceiverOK) {
|
||||||
|
uint32_t frequency =
|
||||||
|
subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer);
|
||||||
|
if(frequency > 0) {
|
||||||
|
subghz->last_settings->frequency = frequency;
|
||||||
|
subghz_last_settings_save(subghz->last_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
|
|||||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||||
subghz_preset_init(
|
subghz_preset_init(
|
||||||
subghz,
|
subghz,
|
||||||
"AM650",
|
subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset),
|
||||||
subghz_setting_get_default_frequency(subghz->setting),
|
subghz->last_settings->frequency,
|
||||||
NULL,
|
NULL,
|
||||||
0);
|
0);
|
||||||
scene_manager_search_and_switch_to_previous_scene(
|
scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
|||||||
@@ -136,8 +136,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
|||||||
//Restore default setting
|
//Restore default setting
|
||||||
subghz_preset_init(
|
subghz_preset_init(
|
||||||
subghz,
|
subghz,
|
||||||
"AM650",
|
subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset),
|
||||||
subghz_setting_get_default_frequency(subghz->setting),
|
subghz->last_settings->frequency,
|
||||||
NULL,
|
NULL,
|
||||||
0);
|
0);
|
||||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "../subghz_i.h"
|
#include "../subghz_i.h"
|
||||||
#include "../views/receiver.h"
|
#include "../views/receiver.h"
|
||||||
|
|
||||||
|
#define TAG "SubGhzSceneReceiver"
|
||||||
|
|
||||||
const NotificationSequence subghz_sequence_rx = {
|
const NotificationSequence subghz_sequence_rx = {
|
||||||
&message_green_255,
|
&message_green_255,
|
||||||
|
|
||||||
@@ -103,7 +105,11 @@ void subghz_scene_receiver_on_enter(void* context) {
|
|||||||
|
|
||||||
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) {
|
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) {
|
||||||
subghz_preset_init(
|
subghz_preset_init(
|
||||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
subghz,
|
||||||
|
subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset),
|
||||||
|
subghz->last_settings->frequency,
|
||||||
|
NULL,
|
||||||
|
0);
|
||||||
subghz_history_reset(subghz->txrx->history);
|
subghz_history_reset(subghz->txrx->history);
|
||||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateStart;
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateStart;
|
||||||
}
|
}
|
||||||
@@ -169,8 +175,8 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
|||||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||||
subghz_preset_init(
|
subghz_preset_init(
|
||||||
subghz,
|
subghz,
|
||||||
"AM650",
|
subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset),
|
||||||
subghz_setting_get_default_frequency(subghz->setting),
|
subghz->last_settings->frequency,
|
||||||
NULL,
|
NULL,
|
||||||
0);
|
0);
|
||||||
scene_manager_search_and_switch_to_previous_scene(
|
scene_manager_search_and_switch_to_previous_scene(
|
||||||
@@ -188,6 +194,8 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
|||||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||||
subghz->txrx->idx_menu_chosen =
|
subghz->txrx->idx_menu_chosen =
|
||||||
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
|
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
subghz->scene_manager, SubGhzViewIdReceiver, SubGhzCustomEventManagerSet);
|
||||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
|
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <lib/subghz/protocols/raw.h>
|
#include <lib/subghz/protocols/raw.h>
|
||||||
|
|
||||||
|
#define TAG "SubGhzSceneReceiverConfig"
|
||||||
|
|
||||||
enum SubGhzSettingIndex {
|
enum SubGhzSettingIndex {
|
||||||
SubGhzSettingIndexFrequency,
|
SubGhzSettingIndexFrequency,
|
||||||
SubGhzSettingIndexHopping,
|
SubGhzSettingIndexHopping,
|
||||||
@@ -145,6 +147,8 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
|
|||||||
(subghz_setting_get_frequency(subghz->setting, index) % 1000000) / 10000);
|
(subghz_setting_get_frequency(subghz->setting, index) % 1000000) / 10000);
|
||||||
variable_item_set_current_value_text(item, text_buf);
|
variable_item_set_current_value_text(item, text_buf);
|
||||||
subghz->txrx->preset->frequency = subghz_setting_get_frequency(subghz->setting, index);
|
subghz->txrx->preset->frequency = subghz_setting_get_frequency(subghz->setting, index);
|
||||||
|
subghz->last_settings->frequency = subghz->txrx->preset->frequency;
|
||||||
|
subghz_setting_set_default_frequency(subghz->setting, subghz->txrx->preset->frequency);
|
||||||
} else {
|
} else {
|
||||||
variable_item_set_current_value_index(
|
variable_item_set_current_value_index(
|
||||||
item, subghz_setting_get_frequency_default_index(subghz->setting));
|
item, subghz_setting_get_frequency_default_index(subghz->setting));
|
||||||
@@ -154,11 +158,13 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
|
|||||||
static void subghz_scene_receiver_config_set_preset(VariableItem* item) {
|
static void subghz_scene_receiver_config_set_preset(VariableItem* item) {
|
||||||
SubGhz* subghz = variable_item_get_context(item);
|
SubGhz* subghz = variable_item_get_context(item);
|
||||||
uint8_t index = variable_item_get_current_value_index(item);
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
variable_item_set_current_value_text(
|
const char* preset_name = subghz_setting_get_preset_name(subghz->setting, index);
|
||||||
item, subghz_setting_get_preset_name(subghz->setting, index));
|
variable_item_set_current_value_text(item, preset_name);
|
||||||
|
subghz->last_settings->preset = index;
|
||||||
|
|
||||||
subghz_preset_init(
|
subghz_preset_init(
|
||||||
subghz,
|
subghz,
|
||||||
subghz_setting_get_preset_name(subghz->setting, index),
|
preset_name,
|
||||||
subghz->txrx->preset->frequency,
|
subghz->txrx->preset->frequency,
|
||||||
subghz_setting_get_preset_data(subghz->setting, index),
|
subghz_setting_get_preset_data(subghz->setting, index),
|
||||||
subghz_setting_get_preset_data_size(subghz->setting, index));
|
subghz_setting_get_preset_data_size(subghz->setting, index));
|
||||||
@@ -238,6 +244,13 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
|||||||
VariableItem* item;
|
VariableItem* item;
|
||||||
uint8_t value_index;
|
uint8_t value_index;
|
||||||
|
|
||||||
|
#if FURI_DEBUG
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG,
|
||||||
|
"last frequency: %d, preset: %d",
|
||||||
|
subghz->last_settings->frequency,
|
||||||
|
subghz->last_settings->preset);
|
||||||
|
#endif
|
||||||
item = variable_item_list_add(
|
item = variable_item_list_add(
|
||||||
subghz->variable_item_list,
|
subghz->variable_item_list,
|
||||||
"Frequency:",
|
"Frequency:",
|
||||||
@@ -258,20 +271,6 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
|||||||
(subghz_setting_get_frequency(subghz->setting, value_index) % 1000000) / 10000);
|
(subghz_setting_get_frequency(subghz->setting, value_index) % 1000000) / 10000);
|
||||||
variable_item_set_current_value_text(item, text_buf);
|
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(
|
item = variable_item_list_add(
|
||||||
subghz->variable_item_list,
|
subghz->variable_item_list,
|
||||||
"Modulation:",
|
"Modulation:",
|
||||||
@@ -286,6 +285,19 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
|||||||
|
|
||||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
||||||
SubGhzCustomEventManagerSet) {
|
SubGhzCustomEventManagerSet) {
|
||||||
|
// Hopping
|
||||||
|
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]);
|
||||||
|
|
||||||
|
// Detect Raw
|
||||||
item = variable_item_list_add(
|
item = variable_item_list_add(
|
||||||
subghz->variable_item_list,
|
subghz->variable_item_list,
|
||||||
"Detect Raw:",
|
"Detect Raw:",
|
||||||
@@ -298,10 +310,8 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
|||||||
DETECT_RAW_COUNT);
|
DETECT_RAW_COUNT);
|
||||||
variable_item_set_current_value_index(item, value_index);
|
variable_item_set_current_value_index(item, value_index);
|
||||||
variable_item_set_current_value_text(item, detect_raw_text[value_index]);
|
variable_item_set_current_value_text(item, detect_raw_text[value_index]);
|
||||||
}
|
|
||||||
|
|
||||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
// RSSI
|
||||||
SubGhzCustomEventManagerSet) {
|
|
||||||
item = variable_item_list_add(
|
item = variable_item_list_add(
|
||||||
subghz->variable_item_list,
|
subghz->variable_item_list,
|
||||||
"RSSI for Raw:",
|
"RSSI for Raw:",
|
||||||
@@ -315,10 +325,8 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
|||||||
RSSI_THRESHOLD_COUNT);
|
RSSI_THRESHOLD_COUNT);
|
||||||
variable_item_set_current_value_index(item, value_index);
|
variable_item_set_current_value_index(item, value_index);
|
||||||
variable_item_set_current_value_text(item, rssi_threshold_text[value_index]);
|
variable_item_set_current_value_text(item, rssi_threshold_text[value_index]);
|
||||||
}
|
|
||||||
|
|
||||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
// Lock keyboard
|
||||||
SubGhzCustomEventManagerSet) {
|
|
||||||
variable_item_list_add(subghz->variable_item_list, "Lock Keyboard", 1, NULL, NULL);
|
variable_item_list_add(subghz->variable_item_list, "Lock Keyboard", 1, NULL, NULL);
|
||||||
variable_item_list_set_enter_callback(
|
variable_item_list_set_enter_callback(
|
||||||
subghz->variable_item_list,
|
subghz->variable_item_list,
|
||||||
@@ -347,6 +355,7 @@ void subghz_scene_receiver_config_on_exit(void* context) {
|
|||||||
SubGhz* subghz = context;
|
SubGhz* subghz = context;
|
||||||
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
|
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
|
||||||
variable_item_list_reset(subghz->variable_item_list);
|
variable_item_list_reset(subghz->variable_item_list);
|
||||||
|
subghz_last_settings_save(subghz->last_settings);
|
||||||
scene_manager_set_scene_state(
|
scene_manager_set_scene_state(
|
||||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <lib/toolbox/path.h>
|
#include <lib/toolbox/path.h>
|
||||||
#include "subghz_i.h"
|
#include "subghz_i.h"
|
||||||
|
|
||||||
|
#define TAG "SubGhzApp"
|
||||||
|
|
||||||
bool subghz_custom_event_callback(void* context, uint32_t event) {
|
bool subghz_custom_event_callback(void* context, uint32_t event) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
SubGhz* subghz = context;
|
SubGhz* subghz = context;
|
||||||
@@ -174,13 +176,30 @@ SubGhz* subghz_alloc() {
|
|||||||
subghz->setting = subghz_setting_alloc();
|
subghz->setting = subghz_setting_alloc();
|
||||||
subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"));
|
subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"));
|
||||||
|
|
||||||
|
// Load last used values for Read, Read RAW, etc. or default
|
||||||
|
subghz->last_settings = subghz_last_settings_alloc();
|
||||||
|
subghz_last_settings_load(
|
||||||
|
subghz->last_settings, subghz_setting_get_preset_count(subghz->setting));
|
||||||
|
#if FURI_DEBUG
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG,
|
||||||
|
"last frequency: %d, preset: %d",
|
||||||
|
subghz->last_settings->frequency,
|
||||||
|
subghz->last_settings->preset);
|
||||||
|
#endif
|
||||||
|
subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency);
|
||||||
|
|
||||||
//init Worker & Protocol & History & KeyBoard
|
//init Worker & Protocol & History & KeyBoard
|
||||||
subghz->lock = SubGhzLockOff;
|
subghz->lock = SubGhzLockOff;
|
||||||
subghz->txrx = malloc(sizeof(SubGhzTxRx));
|
subghz->txrx = malloc(sizeof(SubGhzTxRx));
|
||||||
subghz->txrx->preset = malloc(sizeof(SubGhzPresetDefinition));
|
subghz->txrx->preset = malloc(sizeof(SubGhzPresetDefinition));
|
||||||
string_init(subghz->txrx->preset->name);
|
string_init(subghz->txrx->preset->name);
|
||||||
subghz_preset_init(
|
subghz_preset_init(
|
||||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
subghz,
|
||||||
|
subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset),
|
||||||
|
subghz->last_settings->frequency,
|
||||||
|
NULL,
|
||||||
|
0);
|
||||||
|
|
||||||
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
|
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
|
||||||
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
||||||
@@ -287,6 +306,7 @@ void subghz_free(SubGhz* subghz) {
|
|||||||
|
|
||||||
//setting
|
//setting
|
||||||
subghz_setting_free(subghz->setting);
|
subghz_setting_free(subghz->setting);
|
||||||
|
subghz_last_settings_free(subghz->last_settings);
|
||||||
|
|
||||||
//Worker & Protocol & History
|
//Worker & Protocol & History
|
||||||
subghz_receiver_free(subghz->txrx->receiver);
|
subghz_receiver_free(subghz->txrx->receiver);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include "subghz_history.h"
|
#include "subghz_history.h"
|
||||||
#include "subghz_setting.h"
|
#include "subghz_setting.h"
|
||||||
|
#include "subghz_last_settings.h"
|
||||||
|
|
||||||
#include <gui/modules/variable_item_list.h>
|
#include <gui/modules/variable_item_list.h>
|
||||||
#include <lib/toolbox/path.h>
|
#include <lib/toolbox/path.h>
|
||||||
@@ -100,10 +101,10 @@ struct SubGhz {
|
|||||||
SubGhzTestPacket* subghz_test_packet;
|
SubGhzTestPacket* subghz_test_packet;
|
||||||
string_t error_str;
|
string_t error_str;
|
||||||
SubGhzSetting* setting;
|
SubGhzSetting* setting;
|
||||||
|
SubGhzLastSettings* last_settings;
|
||||||
SubGhzLock lock;
|
SubGhzLock lock;
|
||||||
|
|
||||||
bool in_decoder_scene;
|
bool in_decoder_scene;
|
||||||
|
|
||||||
void* rpc_ctx;
|
void* rpc_ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
105
applications/main/subghz/subghz_last_settings.c
Normal file
105
applications/main/subghz/subghz_last_settings.c
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
#include "subghz_last_settings.h"
|
||||||
|
#include <lib/flipper_format/flipper_format.h>
|
||||||
|
|
||||||
|
#define TAG "SubGhzLastSettings"
|
||||||
|
|
||||||
|
#define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File"
|
||||||
|
#define SUBGHZ_LAST_SETTING_FILE_VERSION 1
|
||||||
|
#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/last_subghz.settings")
|
||||||
|
// 1 = "AM650"
|
||||||
|
// "AM270", "AM650", "FM238", "FM476",
|
||||||
|
#define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1
|
||||||
|
#define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000
|
||||||
|
|
||||||
|
SubGhzLastSettings* subghz_last_settings_alloc(void) {
|
||||||
|
SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings));
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_last_settings_free(SubGhzLastSettings* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
free(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count) {
|
||||||
|
furi_assert(instance);
|
||||||
|
#if FURI_DEBUG
|
||||||
|
FURI_LOG_I(TAG, "subghz_last_settings_load");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
|
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||||
|
|
||||||
|
uint32_t temp_frequency = 0;
|
||||||
|
int32_t temp_preset = 0;
|
||||||
|
|
||||||
|
if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH &&
|
||||||
|
flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) {
|
||||||
|
flipper_format_read_int32(fff_data_file, "Preset", (int32_t*)&temp_preset, 1);
|
||||||
|
flipper_format_read_uint32(fff_data_file, "Frequency", (uint32_t*)&temp_frequency, 1);
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(temp_frequency == 0 || !furi_hal_subghz_is_tx_allowed(temp_frequency)) {
|
||||||
|
FURI_LOG_W(TAG, "Last used frequency not found or can't be used!");
|
||||||
|
instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY;
|
||||||
|
instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET;
|
||||||
|
} else {
|
||||||
|
instance->frequency = temp_frequency;
|
||||||
|
|
||||||
|
if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) {
|
||||||
|
FURI_LOG_W(TAG, "Last used preset no found");
|
||||||
|
instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET;
|
||||||
|
} else {
|
||||||
|
instance->preset = temp_preset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flipper_format_file_close(fff_data_file);
|
||||||
|
flipper_format_free(fff_data_file);
|
||||||
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool subghz_last_settings_save(SubGhzLastSettings* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
#if FURI_DEBUG
|
||||||
|
FURI_LOG_I(TAG, "subghz_last_settings_save");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool saved = false;
|
||||||
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(FSE_OK != storage_sd_status(storage)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open file
|
||||||
|
if(!flipper_format_file_open_always(file, SUBGHZ_LAST_SETTINGS_PATH)) break;
|
||||||
|
|
||||||
|
// Write header
|
||||||
|
if(!flipper_format_write_header_cstr(
|
||||||
|
file, SUBGHZ_LAST_SETTING_FILE_TYPE, SUBGHZ_LAST_SETTING_FILE_VERSION))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!flipper_format_insert_or_update_int32(file, "Preset", &instance->preset, 1)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!flipper_format_insert_or_update_uint32(file, "Frequency", &instance->frequency, 1)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
saved = true;
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
if(!saved) {
|
||||||
|
FURI_LOG_E(TAG, "Error save file %s", SUBGHZ_LAST_SETTINGS_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
flipper_format_file_close(file);
|
||||||
|
flipper_format_free(file);
|
||||||
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
19
applications/main/subghz/subghz_last_settings.h
Normal file
19
applications/main/subghz/subghz_last_settings.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <furi_hal.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <storage/storage.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t frequency;
|
||||||
|
int32_t preset;
|
||||||
|
} SubGhzLastSettings;
|
||||||
|
|
||||||
|
SubGhzLastSettings* subghz_last_settings_alloc(void);
|
||||||
|
|
||||||
|
void subghz_last_settings_free(SubGhzLastSettings* instance);
|
||||||
|
|
||||||
|
void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count);
|
||||||
|
|
||||||
|
bool subghz_last_settings_save(SubGhzLastSettings* instance);
|
||||||
@@ -260,13 +260,7 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) {
|
if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) {
|
||||||
for
|
subghz_setting_set_default_frequency(instance, temp_data32);
|
||||||
M_EACH(frequency, instance->frequencies, FrequencyList_t) {
|
|
||||||
*frequency &= FREQUENCY_MASK;
|
|
||||||
if(*frequency == temp_data32) {
|
|
||||||
*frequency |= FREQUENCY_FLAG_DEFAULT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom preset (optional)
|
// custom preset (optional)
|
||||||
@@ -294,6 +288,16 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void subghz_setting_set_default_frequency(SubGhzSetting* instance, uint32_t frequency_to_setup) {
|
||||||
|
for
|
||||||
|
M_EACH(frequency, instance->frequencies, FrequencyList_t) {
|
||||||
|
*frequency &= FREQUENCY_MASK;
|
||||||
|
if(*frequency == frequency_to_setup) {
|
||||||
|
*frequency |= FREQUENCY_FLAG_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t subghz_setting_get_frequency_count(SubGhzSetting* instance) {
|
size_t subghz_setting_get_frequency_count(SubGhzSetting* instance) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
return FrequencyList_size(instance->frequencies);
|
return FrequencyList_size(instance->frequencies);
|
||||||
@@ -311,6 +315,9 @@ size_t subghz_setting_get_preset_count(SubGhzSetting* instance) {
|
|||||||
|
|
||||||
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx) {
|
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
if(idx >= SubGhzSettingCustomPresetItemArray_size(instance->preset->data)) {
|
||||||
|
idx = 0;
|
||||||
|
}
|
||||||
SubGhzSettingCustomPresetItem* item =
|
SubGhzSettingCustomPresetItem* item =
|
||||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||||
return string_get_cstr(item->custom_preset_name);
|
return string_get_cstr(item->custom_preset_name);
|
||||||
|
|||||||
@@ -46,3 +46,5 @@ uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx
|
|||||||
uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance);
|
uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance);
|
||||||
|
|
||||||
uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance);
|
uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance);
|
||||||
|
|
||||||
|
void subghz_setting_set_default_frequency(SubGhzSetting* instance, uint32_t frequency_to_setup);
|
||||||
|
|||||||
@@ -30,6 +30,32 @@ static const NotificationSequence sequence_hw_blink_stop = {
|
|||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const NotificationSequence sequence_saved = {
|
||||||
|
&message_blink_stop,
|
||||||
|
&message_blue_0,
|
||||||
|
&message_green_255,
|
||||||
|
&message_red_0,
|
||||||
|
&message_vibro_on,
|
||||||
|
&message_delay_100,
|
||||||
|
&message_vibro_off,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
static const NotificationSequence sequence_not_saved = {
|
||||||
|
&message_blink_stop,
|
||||||
|
&message_green_255,
|
||||||
|
&message_blue_255,
|
||||||
|
&message_red_255,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t subghz_frequency_list[] = {
|
||||||
|
300000000, 302757000, 303875000, 304250000, 307000000, 307500000, 307800000,
|
||||||
|
309000000, 310000000, 312000000, 312100000, 313000000, 313850000, 314000000,
|
||||||
|
314350000, 315000000, 318000000, 345000000, 348000000, 387000000, 390000000,
|
||||||
|
418000000, 433075000, 433220000, 433420000, 433657070, 433889000, 433920000,
|
||||||
|
434176948, 434420000, 434775000, 438900000, 464000000, 779000000, 868350000,
|
||||||
|
868400000, 868950000, 906400000, 915000000, 925000000, 928000000};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SubGhzFrequencyAnalyzerStatusIDLE,
|
SubGhzFrequencyAnalyzerStatusIDLE,
|
||||||
} SubGhzFrequencyAnalyzerStatus;
|
} SubGhzFrequencyAnalyzerStatus;
|
||||||
@@ -50,6 +76,7 @@ struct SubGhzFrequencyAnalyzer {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t frequency;
|
uint32_t frequency;
|
||||||
uint32_t frequency_last;
|
uint32_t frequency_last;
|
||||||
|
uint32_t frequency_to_save;
|
||||||
float rssi;
|
float rssi;
|
||||||
float rssi_last;
|
float rssi_last;
|
||||||
float trigger;
|
float trigger;
|
||||||
@@ -163,6 +190,33 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
|
|||||||
elements_button_right(canvas, "T+");
|
elements_button_right(canvas, "T+");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t subghz_frequency_find_correct(uint32_t input) {
|
||||||
|
uint32_t prev_freq = 0;
|
||||||
|
uint32_t current = 0;
|
||||||
|
uint32_t result = 0;
|
||||||
|
#if FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "input: %d", input);
|
||||||
|
#endif
|
||||||
|
for(size_t i = 0; i < sizeof(subghz_frequency_list); i++) {
|
||||||
|
current = subghz_frequency_list[i];
|
||||||
|
if(current == input) {
|
||||||
|
result = current;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(current > input && prev_freq < input) {
|
||||||
|
if(current - input < input - prev_freq) {
|
||||||
|
result = current;
|
||||||
|
} else {
|
||||||
|
result = prev_freq;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prev_freq = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
SubGhzFrequencyAnalyzer* instance = context;
|
SubGhzFrequencyAnalyzer* instance = context;
|
||||||
@@ -201,6 +255,43 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
|||||||
need_redraw = true;
|
need_redraw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(event->type == InputTypeShort && event->key == InputKeyOk) {
|
||||||
|
with_view_model(
|
||||||
|
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||||
|
uint32_t prev_freq_to_save = model->frequency_to_save;
|
||||||
|
uint32_t frequency_candidate = 0;
|
||||||
|
if(model->frequency != 0) {
|
||||||
|
frequency_candidate = model->frequency;
|
||||||
|
} else if(model->frequency_last != 0) {
|
||||||
|
frequency_candidate = model->frequency_last;
|
||||||
|
}
|
||||||
|
if(frequency_candidate == 0 ||
|
||||||
|
!furi_hal_subghz_is_frequency_valid(frequency_candidate) ||
|
||||||
|
prev_freq_to_save == frequency_candidate) {
|
||||||
|
frequency_candidate = 0;
|
||||||
|
} else {
|
||||||
|
frequency_candidate = subghz_frequency_find_correct(frequency_candidate);
|
||||||
|
}
|
||||||
|
if(frequency_candidate > 0 && frequency_candidate != model->frequency_to_save) {
|
||||||
|
#if FURI_DEBUG
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG,
|
||||||
|
"frequency_to_save: %d, candidate: %d",
|
||||||
|
model->frequency_to_save,
|
||||||
|
frequency_candidate);
|
||||||
|
#endif
|
||||||
|
model->frequency_to_save = frequency_candidate;
|
||||||
|
notification_message(instance->notifications, &sequence_saved);
|
||||||
|
instance->callback(SubGhzCustomEventViewReceiverOK, instance->context);
|
||||||
|
notification_message(instance->notifications, &sequence_hw_blink);
|
||||||
|
} else {
|
||||||
|
notification_message(instance->notifications, &sequence_not_saved);
|
||||||
|
notification_message(instance->notifications, &sequence_hw_blink);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if(need_redraw) {
|
if(need_redraw) {
|
||||||
SubGhzFrequencyAnalyzer* instance = context;
|
SubGhzFrequencyAnalyzer* instance = context;
|
||||||
with_view_model(
|
with_view_model(
|
||||||
@@ -309,6 +400,7 @@ void subghz_frequency_analyzer_enter(void* context) {
|
|||||||
model->rssi_last = 0;
|
model->rssi_last = 0;
|
||||||
model->frequency = 0;
|
model->frequency = 0;
|
||||||
model->frequency_last = 0;
|
model->frequency_last = 0;
|
||||||
|
model->frequency_to_save = 0;
|
||||||
model->trigger = RSSI_MIN;
|
model->trigger = RSSI_MIN;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -359,4 +451,16 @@ void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* instance) {
|
|||||||
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* instance) {
|
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* instance) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
return instance->view;
|
return instance->view;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t subghz_frequency_analyzer_get_frequency_to_save(SubGhzFrequencyAnalyzer* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
uint32_t frequency;
|
||||||
|
with_view_model(
|
||||||
|
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||||
|
frequency = model->frequency_to_save;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
return frequency;
|
||||||
}
|
}
|
||||||
@@ -17,3 +17,5 @@ SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc();
|
|||||||
void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* subghz_static);
|
void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* subghz_static);
|
||||||
|
|
||||||
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* subghz_static);
|
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* subghz_static);
|
||||||
|
|
||||||
|
uint32_t subghz_frequency_analyzer_get_frequency_to_save(SubGhzFrequencyAnalyzer* instance);
|
||||||
|
|||||||
Reference in New Issue
Block a user