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
This commit is contained in:
DerSkythe
2023-08-08 08:58:20 +04:00
parent 540862fbf2
commit 8c44dfb6af
18 changed files with 294 additions and 154 deletions

View File

@@ -29,8 +29,7 @@ SubGhzTxRx* subghz_txrx_alloc() {
instance->preset = malloc(sizeof(SubGhzRadioPreset));
instance->preset->name = furi_string_alloc();
subghz_txrx_set_preset(
instance, "AM650", subghz_setting_get_default_frequency(instance->setting), NULL, 0);
subghz_txrx_set_default_preset(instance, 0);
instance->txrx_state = SubGhzTxRxStateSleep;
@@ -636,7 +635,7 @@ bool subghz_txrx_radio_device_is_frequency_valid(SubGhzTxRx* instance, uint32_t
bool subghz_txrx_radio_device_is_tx_allowed(SubGhzTxRx* instance, uint32_t frequency) {
furi_assert(instance);
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
//furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
subghz_devices_idle(instance->radio_device);
subghz_devices_set_frequency(instance->radio_device, frequency);
@@ -668,3 +667,31 @@ SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) {
furi_assert(instance);
return instance->receiver;
}
void subghz_txrx_set_default_preset(SubGhzTxRx* instance, uint32_t frequency) {
furi_assert(instance);
const char* default_modulation = "AM650";
if(frequency == 0) {
frequency = subghz_setting_get_default_frequency(subghz_txrx_get_setting(instance));
}
subghz_txrx_set_preset(instance, default_modulation, frequency, NULL, 0);
}
const char*
subghz_txrx_set_preset_internal(SubGhzTxRx* instance, uint32_t frequency, uint8_t index) {
furi_assert(instance);
SubGhzSetting* setting = subghz_txrx_get_setting(instance);
const char* preset_name = subghz_setting_get_preset_name(setting, index);
subghz_setting_set_default_frequency(setting, frequency);
subghz_txrx_set_preset(
instance,
preset_name,
frequency,
subghz_setting_get_preset_data(setting, index),
subghz_setting_get_preset_data_size(setting, index));
return preset_name;
}

View File

@@ -329,7 +329,7 @@ float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance);
*/
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
/* Get get intelligence whether frequency the selected radio device to use
/* Get intelligence whether frequency the selected radio device to use
*
* @param instance Pointer to a SubGhzTxRx
* @return bool True if the frequency is valid
@@ -344,3 +344,8 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance);
void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance);
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw
void subghz_txrx_set_default_preset(SubGhzTxRx* instance, uint32_t frequency);
const char*
subghz_txrx_set_preset_internal(SubGhzTxRx* instance, uint32_t frequency, uint8_t index);

View File

@@ -1,8 +1,4 @@
#include "../subghz_i.h"
#include "../views/receiver.h"
#include <lib/subghz/protocols/raw.h>
#include <lib/subghz/subghz_file_encoder_worker.h>
#define TAG "SubGhzDecodeRaw"
#define SAMPLES_TO_READ_PER_TICK 400
@@ -28,7 +24,11 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
furi_string_free(modulation_str);
} else {
subghz_view_receiver_add_data_statusbar(
subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "", false);
subghz->subghz_receiver,
furi_string_get_cstr(history_stat_str),
"",
"",
subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF);
}
furi_string_free(history_stat_str);
}
@@ -171,7 +171,7 @@ void subghz_scene_decode_raw_on_enter(void* context) {
} else {
//Load history to receiver
subghz_view_receiver_exit(subghz->subghz_receiver);
for(uint8_t i = 0; i < subghz_history_get_item(subghz->history); i++) {
for(uint16_t i = 0; i < subghz_history_get_item(subghz->history); i++) {
furi_string_reset(item_name);
furi_string_reset(item_time);
subghz_history_get_text_item_menu(subghz->history, item_name, i);

View File

@@ -1,3 +1,4 @@
#include "../subghz.h"
#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"

View File

@@ -60,6 +60,9 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e
subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer);
if(frequency > 0) {
subghz->last_settings->frequency = frequency;
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings, subghz->ignore_filter);
#endif
subghz_last_settings_save(subghz->last_settings);
}

View File

@@ -104,8 +104,17 @@ void subghz_scene_read_raw_on_enter(void* context) {
if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateBack) {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
if(furi_string_empty(file_name)) {
subghz_txrx_set_preset_internal(
subghz->txrx,
subghz->last_settings->frequency,
subghz->last_settings->preset_index);
subghz_txrx_speaker_set_state(
subghz->txrx,
subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown :
SubGhzSpeakerStateEnable);
}
}
furi_string_free(file_name);
subghz_scene_read_raw_update_statusbar(subghz);
//set callback view raw
@@ -115,6 +124,8 @@ void subghz_scene_read_raw_on_enter(void* context) {
//set filter RAW feed
subghz_txrx_receiver_set_filter(subghz->txrx, SubGhzProtocolFlag_RAW);
furi_string_free(file_name);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReadRAW);
}
@@ -139,10 +150,9 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
} else {
//Restore default setting
if(subghz->raw_send_only) {
subghz_set_default_preset(subghz);
subghz_txrx_set_default_preset(subghz->txrx, 0);
} else {
subghz_txrx_set_preset(
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency);
}
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneSaved)) {

View File

@@ -1,5 +1,4 @@
#include "../subghz_i.h"
#include "../views/receiver.h"
#include <dolphin/dolphin.h>
#include <lib/subghz/protocols/bin_raw.h>
@@ -77,7 +76,11 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
furi_string_free(modulation_str);
} else {
subghz_view_receiver_add_data_statusbar(
subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "", false);
subghz->subghz_receiver,
furi_string_get_cstr(history_stat_str),
"",
"",
subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF);
subghz->state_notifications = SubGhzNotificationStateIDLE;
}
furi_string_free(history_stat_str);
@@ -143,7 +146,16 @@ void subghz_scene_receiver_on_enter(void* context) {
FuriString* item_time = furi_string_alloc();
if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) {
subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
subghz->filter = subghz->last_settings->filter;
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
subghz->ignore_filter = subghz->last_settings->ignore_filter;
subghz_txrx_set_preset_internal(
subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index);
subghz_txrx_speaker_set_state(
subghz->txrx,
subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown :
SubGhzSpeakerStateEnable);
subghz_history_reset(history);
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart);
subghz->idx_menu_chosen = 0;
@@ -154,7 +166,7 @@ void subghz_scene_receiver_on_enter(void* context) {
// Load history to receiver
subghz_view_receiver_exit(subghz->subghz_receiver);
for(uint8_t i = 0; i < subghz_history_get_item(history); i++) {
for(uint16_t i = 0; i < subghz_history_get_item(history); i++) {
furi_string_reset(item_name);
furi_string_reset(item_time);
subghz_history_get_text_item_menu(history, item_name, i);
@@ -178,11 +190,10 @@ void subghz_scene_receiver_on_enter(void* context) {
}
// Check if hopping was enabled
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings);
#endif
if(subghz->last_settings->enable_hopping) {
subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateRunning);
} else {
subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF);
}
subghz_scene_receiver_update_statusbar(subghz);
@@ -216,8 +227,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
subghz_txrx_set_preset(
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency);
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}

View File

@@ -16,10 +16,6 @@ enum SubGhzSettingIndex {
SubGhzSettingIndexRAWThresholdRSSI,
};
static inline const char* bool_to_char(bool value) {
return value ? "ON" : "OFF";
}
#define RAW_THRESHOLD_RSSI_COUNT 11
const char* const raw_threshold_rssi_text[RAW_THRESHOLD_RSSI_COUNT] = {
"-----",
@@ -49,47 +45,51 @@ const float raw_threshold_rssi_value[RAW_THRESHOLD_RSSI_COUNT] = {
-40.0f,
};
#define HOPPING_COUNT 2
const char* const hopping_text[HOPPING_COUNT] = {
"OFF",
"ON",
};
const uint32_t hopping_value[HOPPING_COUNT] = {
#define COMBO_BOX_COUNT 2
const uint32_t hopping_value[COMBO_BOX_COUNT] = {
SubGhzHopperStateOFF,
SubGhzHopperStateRunning,
};
#define SPEAKER_COUNT 2
const char* const speaker_text[SPEAKER_COUNT] = {
"OFF",
"ON",
};
const uint32_t speaker_value[SPEAKER_COUNT] = {
const uint32_t speaker_value[COMBO_BOX_COUNT] = {
SubGhzSpeakerStateShutdown,
SubGhzSpeakerStateEnable,
};
#define BIN_RAW_COUNT 2
const char* const bin_raw_text[BIN_RAW_COUNT] = {
"OFF",
"ON",
};
const uint32_t bin_raw_value[BIN_RAW_COUNT] = {
const uint32_t bin_raw_value[COMBO_BOX_COUNT] = {
SubGhzProtocolFlag_Decodable,
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_BinRAW,
};
#define PROTOCOL_IGNORE_COUNT 2
const char* const protocol_ignore_text[PROTOCOL_IGNORE_COUNT] = {
const char* const combobox_text[COMBO_BOX_COUNT] = {
"OFF",
"ON",
};
static void
subghz_scene_receiver_config_set_ignore_filter(VariableItem* item, SubGhzProtocolFlag filter) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, combobox_text[index]);
if(index == 0) {
CLEAR_BIT(subghz->ignore_filter, filter);
} else {
SET_BIT(subghz->ignore_filter, filter);
}
subghz->last_settings->ignore_filter = subghz->ignore_filter;
}
uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* context) {
furi_assert(context);
SubGhz* subghz = context;
SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx);
uint8_t index = 0;
for(uint8_t i = 0; i < subghz_setting_get_frequency_count(setting); i++) {
for(size_t i = 0; i < subghz_setting_get_frequency_count(setting); i++) {
if(value == subghz_setting_get_frequency(setting, i)) {
index = i;
break;
@@ -106,7 +106,7 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void*
uint8_t index = 0;
SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx);
for(uint8_t i = 0; i < subghz_setting_get_preset_count(setting); i++) {
for(size_t i = 0; i < subghz_setting_get_preset_count(setting); i++) {
if(!strcmp(subghz_setting_get_preset_name(setting, i), preset_name)) {
index = i;
break;
@@ -181,6 +181,7 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) {
preset.frequency,
subghz_setting_get_preset_data(setting, index),
subghz_setting_get_preset_data_size(setting, index));
subghz->last_settings->preset_index = index;
}
static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) {
@@ -190,7 +191,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item)
VariableItem* frequency_item = (VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig);
variable_item_set_current_value_text(item, hopping_text[(uint8_t)index]);
variable_item_set_current_value_text(item, combobox_text[(uint8_t)index]);
if(index == SubGhzHopperStateOFF) {
char text_buf[10] = {0};
@@ -220,9 +221,6 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item)
frequency_item, subghz_setting_get_frequency_default_index(setting));
}
subghz->last_settings->enable_hopping = index != SubGhzHopperStateOFF;
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings);
#endif
subghz_txrx_hopper_set_state(subghz->txrx, index);
}
@@ -230,17 +228,21 @@ static void subghz_scene_receiver_config_set_speaker(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, speaker_text[index]);
variable_item_set_current_value_text(item, combobox_text[index]);
subghz_txrx_speaker_set_state(subghz->txrx, speaker_value[index]);
subghz->last_settings->sound = index;
}
static void subghz_scene_receiver_config_set_bin_raw(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, bin_raw_text[index]);
variable_item_set_current_value_text(item, combobox_text[index]);
subghz->filter = bin_raw_value[index];
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
subghz->last_settings->filter = subghz->filter;
}
static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* item) {
@@ -249,21 +251,10 @@ static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* it
variable_item_set_current_value_text(item, raw_threshold_rssi_text[index]);
subghz_threshold_rssi_set(subghz->threshold_rssi, raw_threshold_rssi_value[index]);
subghz->last_settings->rssi = raw_threshold_rssi_value[index];
}
static inline void
subghz_scene_receiver_config_set_ignore_filter(VariableItem* item, SubGhzProtocolFlag filter) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, protocol_ignore_text[index]);
if(index == 0) {
CLEAR_BIT(subghz->ignore_filter, filter);
} else {
SET_BIT(subghz->ignore_filter, filter);
}
}
static inline bool subghz_scene_receiver_config_ignore_filter_get_index(
SubGhzProtocolFlag filter,
SubGhzProtocolFlag flag) {
@@ -336,13 +327,13 @@ void subghz_scene_receiver_config_on_enter(void* context) {
item = variable_item_list_add(
subghz->variable_item_list,
"Hopping:",
HOPPING_COUNT,
COMBO_BOX_COUNT,
subghz_scene_receiver_config_set_hopping_running,
subghz);
value_index = subghz_scene_receiver_config_hopper_value_index(subghz);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, hopping_text[value_index]);
variable_item_set_current_value_text(item, combobox_text[value_index]);
}
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
@@ -350,12 +341,13 @@ void subghz_scene_receiver_config_on_enter(void* context) {
item = variable_item_list_add(
subghz->variable_item_list,
"Bin RAW:",
BIN_RAW_COUNT,
COMBO_BOX_COUNT,
subghz_scene_receiver_config_set_bin_raw,
subghz);
value_index = value_index_uint32(subghz->filter, bin_raw_value, BIN_RAW_COUNT);
value_index = value_index_uint32(subghz->filter, bin_raw_value, COMBO_BOX_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, bin_raw_text[value_index]);
variable_item_set_current_value_text(item, combobox_text[value_index]);
}
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
@@ -363,51 +355,51 @@ void subghz_scene_receiver_config_on_enter(void* context) {
item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Starline:",
PROTOCOL_IGNORE_COUNT,
COMBO_BOX_COUNT,
subghz_scene_receiver_config_set_starline,
subghz);
value_index = subghz_scene_receiver_config_ignore_filter_get_index(
subghz->ignore_filter, SubGhzProtocolFlag_StarLine);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, protocol_ignore_text[value_index]);
variable_item_set_current_value_text(item, combobox_text[value_index]);
item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Cars:",
PROTOCOL_IGNORE_COUNT,
COMBO_BOX_COUNT,
subghz_scene_receiver_config_set_auto_alarms,
subghz);
value_index = subghz_scene_receiver_config_ignore_filter_get_index(
subghz->ignore_filter, SubGhzProtocolFlag_AutoAlarms);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, protocol_ignore_text[value_index]);
variable_item_set_current_value_text(item, combobox_text[value_index]);
item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Magellan:",
PROTOCOL_IGNORE_COUNT,
COMBO_BOX_COUNT,
subghz_scene_receiver_config_set_magellan,
subghz);
value_index = subghz_scene_receiver_config_ignore_filter_get_index(
subghz->ignore_filter, SubGhzProtocolFlag_Magelan);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, protocol_ignore_text[value_index]);
variable_item_set_current_value_text(item, combobox_text[value_index]);
}
// Enable speaker, will send all incoming noises and signals to speaker so you can listen how your remote sounds like :)
item = variable_item_list_add(
subghz->variable_item_list,
"Sound:",
SPEAKER_COUNT,
COMBO_BOX_COUNT,
subghz_scene_receiver_config_set_speaker,
subghz);
value_index = value_index_uint32(
subghz_txrx_speaker_get_state(subghz->txrx), speaker_value, SPEAKER_COUNT);
subghz_txrx_speaker_get_state(subghz->txrx), speaker_value, COMBO_BOX_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, speaker_text[value_index]);
variable_item_set_current_value_text(item, combobox_text[value_index]);
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
@@ -454,6 +446,9 @@ void subghz_scene_receiver_config_on_exit(void* context) {
SubGhz* subghz = context;
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
variable_item_list_reset(subghz->variable_item_list);
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings, subghz->ignore_filter);
#endif
subghz_last_settings_save(subghz->last_settings);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);

View File

@@ -3,6 +3,8 @@
#include <lib/subghz/blocks/custom_btn.h>
#define TAG "SubGhzSceneReceiverInfo"
void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
SubGhz* subghz = context;

View File

@@ -1,5 +1,7 @@
#include "../subghz_i.h"
#define TAG "SubGhzSceneSaved"
void subghz_scene_saved_on_enter(void* context) {
SubGhz* subghz = context;

View File

@@ -4,6 +4,8 @@
#include <lib/subghz/blocks/custom_btn.h>
#define TAG "SubGhzSceneTransmitter"
void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;

View File

@@ -1,9 +1,9 @@
/* Abandon hope, all ye who enter here. */
#include <furi/core/log.h>
#include <subghz/types.h>
#include <lib/toolbox/path.h>
#include "subghz_i.h"
#include <lib/subghz/protocols/protocol_items.h>
#define TAG "SubGhzApp"
@@ -73,7 +73,7 @@ static void subghz_load_custom_presets(SubGhzSetting* setting) {
FlipperFormat* fff_temp = flipper_format_string_alloc();
for(uint8_t i = 0; i < COUNT_OF(presets); i++) {
for(size_t i = 0; i < COUNT_OF(presets); i++) {
flipper_format_insert_or_update_string_cstr(fff_temp, "Custom_preset_data", presets[i][1]);
flipper_format_rewind(fff_temp);
@@ -195,26 +195,45 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
// 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, 0);
size_t preset_count = subghz_setting_get_preset_count(setting);
subghz_last_settings_load(subghz->last_settings, preset_count);
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings, subghz->last_settings->ignore_filter);
#endif
if(!alloc_for_tx_only) {
subghz_setting_set_default_frequency(setting, subghz->last_settings->frequency);
subghz_txrx_set_preset_internal(
subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index);
subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
subghz->history = subghz_history_alloc();
}
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
subghz->secure_data = malloc(sizeof(SecureData));
subghz->filter = SubGhzProtocolFlag_Decodable;
subghz->ignore_filter = 0x0;
if(!alloc_for_tx_only) {
subghz->ignore_filter = subghz->last_settings->ignore_filter;
subghz->filter = subghz->last_settings->filter;
} else {
subghz->filter = SubGhzProtocolFlag_Decodable;
subghz->ignore_filter = 0x0;
}
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
subghz_txrx_set_need_save_callback(subghz->txrx, subghz_save_to_file, subghz);
if(!alloc_for_tx_only) {
if(subghz->last_settings->rssi != 0) {
subghz_threshold_rssi_set(subghz->threshold_rssi, subghz->last_settings->rssi);
} else {
subghz->last_settings->rssi = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER;
}
}
//Init Error_str
subghz->error_str = furi_string_alloc();
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings, subghz->ignore_filter);
#endif
return subghz;
}

View File

@@ -4,30 +4,13 @@
#include "subghz/types.h"
#include <math.h>
#include <furi.h>
#include <furi_hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <flipper_format/flipper_format.h>
#include "views/receiver.h"
#include <flipper_format/flipper_format_i.h>
#include <lib/toolbox/stream/stream.h>
#include <lib/subghz/protocols/raw.h>
#define TAG "SubGhz"
void subghz_set_default_preset(SubGhz* subghz) {
furi_assert(subghz);
subghz_txrx_set_preset(
subghz->txrx,
"AM650",
subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)),
NULL,
0);
}
void subghz_blink_start(SubGhz* subghz) {
furi_assert(subghz);
notification_message(subghz->notifications, &sequence_blink_stop);

View File

@@ -98,7 +98,6 @@ struct SubGhz {
void* rpc_ctx;
};
void subghz_set_default_preset(SubGhz* subghz);
void subghz_blink_start(SubGhz* subghz);
void subghz_blink_stop(SubGhz* subghz);
@@ -106,6 +105,7 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format);
void subghz_dialog_message_freq_error(SubGhz* subghz, bool only_rx);
bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog);
// Not used
bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len);
bool subghz_save_protocol_to_file(
SubGhz* subghz,

View File

@@ -11,10 +11,9 @@
#define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1
#define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000
#define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL 2
#define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER -93.0f
#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency"
//#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset"
#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" // AKA Modulation
#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_FEEDBACK_LEVEL "FeedbackLevel"
#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger"
#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External"
@@ -22,10 +21,10 @@
#define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames"
#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp"
#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE "Hopping"
static inline const char* bool_to_char(bool value) {
return value ? "ON" : "OFF";
}
#define SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER "IgnoreFilter"
#define SUBGHZ_LAST_SETTING_FIELD_FILTER "Filter"
#define SUBGHZ_LAST_SETTING_FIELD_SOUND "Sound"
#define SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD "RSSI"
SubGhzLastSettings* subghz_last_settings_alloc(void) {
SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings));
@@ -38,7 +37,6 @@ void subghz_last_settings_free(SubGhzLastSettings* instance) {
}
void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count) {
UNUSED(preset_count);
furi_assert(instance);
Storage* storage = furi_record_open(RECORD_STORAGE);
@@ -52,15 +50,18 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
bool temp_external_module_power_amp = false;
bool temp_timestamp_file_names = false;
bool temp_enable_hopping = false;
//int32_t temp_preset = 0;
uint32_t temp_ignore_filter = 0;
uint32_t temp_filter = 0;
uint32_t temp_sound = 0;
float temp_rssi = 0;
uint32_t temp_preset = 0;
bool frequency_analyzer_feedback_level_was_read = false;
bool frequency_analyzer_trigger_was_read = false;
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, SUBGHZ_LAST_SETTING_FIELD_PRESET, (int32_t*)&temp_preset, 1);*/
flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (uint32_t*)&temp_preset, 1);
flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1);
frequency_analyzer_feedback_level_was_read = flipper_format_read_uint32(
@@ -98,14 +99,27 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE,
(bool*)&temp_enable_hopping,
1);
flipper_format_read_float(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD, (float*)&temp_rssi, 1);
flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_SOUND, (uint32_t*)&temp_sound, 1);
flipper_format_read_uint32(
fff_data_file,
SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER,
(uint32_t*)&temp_ignore_filter,
1);
flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FILTER, (uint32_t*)&temp_filter, 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;
instance->preset_index = SUBGHZ_LAST_SETTING_DEFAULT_PRESET;
instance->frequency_analyzer_feedback_level =
SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL;
instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER;
@@ -113,7 +127,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
instance->timestamp_file_names = false;
instance->external_module_power_amp = false;
instance->enable_hopping = false;
instance->ignore_filter = 0x00;
// See bin_raw_value in applications/main/subghz/scenes/subghz_scene_receiver_config.c
instance->filter = SubGhzProtocolFlag_Decodable;
instance->sound = 0;
instance->rssi = SUBGHZ_RAW_THRESHOLD_MIN;
} else {
instance->frequency = temp_frequency;
instance->frequency_analyzer_feedback_level =
@@ -125,10 +143,16 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
temp_frequency_analyzer_trigger :
SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER;
/*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;
if(temp_preset > (uint32_t)preset_count - 1) {
FURI_LOG_W(
TAG,
"Last used preset out of range. Preset to set: %ld, Max index: %ld. Set default",
temp_preset,
(uint32_t)preset_count - 1);
instance->preset_index = SUBGHZ_LAST_SETTING_DEFAULT_PRESET;
} else {
instance->preset_index = temp_preset;
}
instance->external_module_enabled = temp_external_module_enabled;
instance->external_module_power_5v_disable = temp_external_module_power_5v_disable;
@@ -138,8 +162,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
// External power amp CC1101
instance->external_module_power_amp = temp_external_module_power_amp;
instance->rssi = temp_rssi;
instance->enable_hopping = temp_enable_hopping;
instance->ignore_filter = temp_ignore_filter;
instance->filter = temp_filter;
instance->sound = temp_sound;
// Set globally in furi hal
furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp);
@@ -147,9 +174,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
instance->preset = temp_preset;
}*/
}
#ifdef FURI_DEBUG
subghz_last_settings_log(instance);
#endif
flipper_format_file_close(fff_data_file);
flipper_format_free(fff_data_file);
@@ -158,9 +182,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
bool subghz_last_settings_save(SubGhzLastSettings* instance) {
furi_assert(instance);
#ifdef FURI_DEBUG
subghz_last_settings_log(instance);
#endif
bool saved = false;
Storage* storage = furi_record_open(RECORD_STORAGE);
@@ -178,12 +199,10 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
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, SUBGHZ_LAST_SETTING_FIELD_PRESET, &instance->preset, 1)) {
if(!flipper_format_insert_or_update_uint32(
file, SUBGHZ_LAST_SETTING_FIELD_PRESET, &instance->preset_index, 1)) {
break;
}*/
}
if(!flipper_format_insert_or_update_uint32(
file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, &instance->frequency, 1)) {
break;
@@ -234,6 +253,22 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
file, SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE, &instance->enable_hopping, 1)) {
break;
}
if(!flipper_format_insert_or_update_float(
file, SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD, &instance->rssi, 1)) {
break;
}
if(!flipper_format_insert_or_update_uint32(
file, SUBGHZ_LAST_SETTING_FIELD_SOUND, &instance->sound, 1)) {
break;
}
if(!flipper_format_insert_or_update_uint32(
file, SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER, &instance->ignore_filter, 1)) {
break;
}
if(!flipper_format_insert_or_update_uint32(
file, SUBGHZ_LAST_SETTING_FIELD_FILTER, &instance->filter, 1)) {
break;
}
saved = true;
} while(0);
@@ -248,12 +283,27 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
return saved;
}
void subghz_last_settings_log(SubGhzLastSettings* instance) {
const char* LOG_ON = "ON";
const char* LOG_OFF = "OFF";
static inline const char*
subghz_last_settings_log_filter_get_index(uint32_t filter, uint32_t flag) {
return READ_BIT(filter, flag) > 0 ? LOG_ON : LOG_OFF;
}
static inline const char* bool_to_char(bool value) {
return value ? LOG_ON : LOG_OFF;
}
void subghz_last_settings_log(SubGhzLastSettings* instance, SubGhzProtocolFlag ignore_filter) {
furi_assert(instance);
UNUSED(ignore_filter);
FURI_LOG_I(
TAG,
"Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s, Hopping: %s",
"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, BinRAW: %s, Sound: %ld",
instance->frequency / 1000000 % 1000,
instance->frequency / 10000 % 100,
instance->frequency_analyzer_feedback_level,
@@ -262,5 +312,15 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) {
bool_to_char(instance->external_module_power_5v_disable),
bool_to_char(instance->timestamp_file_names),
bool_to_char(instance->external_module_power_amp),
bool_to_char(instance->enable_hopping));
bool_to_char(instance->enable_hopping),
instance->preset_index,
(double)instance->rssi,
subghz_last_settings_log_filter_get_index(
instance->ignore_filter, SubGhzProtocolFlag_StarLine),
subghz_last_settings_log_filter_get_index(
instance->ignore_filter, SubGhzProtocolFlag_AutoAlarms),
subghz_last_settings_log_filter_get_index(
instance->ignore_filter, SubGhzProtocolFlag_Magelan),
subghz_last_settings_log_filter_get_index(instance->filter, SubGhzProtocolFlag_BinRAW),
instance->sound);
}

View File

@@ -4,10 +4,13 @@
#include <stdint.h>
#include <stdbool.h>
#include <storage/storage.h>
#include <lib/subghz/types.h>
#define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER (-93.0f)
typedef struct {
uint32_t frequency;
int32_t preset;
uint32_t preset_index; // AKA Modulation
uint32_t frequency_analyzer_feedback_level;
float frequency_analyzer_trigger;
// TODO not using but saved so as not to change the version
@@ -17,6 +20,10 @@ typedef struct {
// saved so as not to change the version
bool timestamp_file_names;
bool enable_hopping;
uint32_t ignore_filter;
uint32_t filter;
uint32_t sound;
float rssi;
} SubGhzLastSettings;
SubGhzLastSettings* subghz_last_settings_alloc(void);
@@ -27,4 +34,4 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
bool subghz_last_settings_save(SubGhzLastSettings* instance);
void subghz_last_settings_log(SubGhzLastSettings* instance);
void subghz_last_settings_log(SubGhzLastSettings* instance, SubGhzProtocolFlag ignore_filter);

View File

@@ -12,7 +12,7 @@
#define MENU_ITEMS 4u
#define UNLOCK_CNT 3
#define SUBGHZ_RAW_THRESHOLD_MIN -90.0f
// #define SUBGHZ_RAW_THRESHOLD_MIN (-90.0f)
#define FLIP_TIMEOUT (500)
@@ -322,15 +322,19 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
(model->device_type == SubGhzRadioDeviceTypeInternal) ? &I_Scanning_123x52 :
&I_Fishing_123x52);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 63, 46, "Scanning...");
if(model->hopping_enabled) {
canvas_draw_str(canvas, 59, 46, "Hopper scan...");
} else {
canvas_draw_str(canvas, 59, 46, "Fixed scan...");
}
//canvas_draw_line(canvas, 46, 51, 125, 51);
canvas_set_font(canvas, FontSecondary);
if(model->hopping_enabled) {
const uint8_t vertical_offset = 7;
const uint8_t horizontal_offset = 3;
canvas_draw_icon(canvas, horizontal_offset, vertical_offset, &I_Dynamic_9x7);
}
// if(model->hopping_enabled) {
// const uint8_t vertical_offset = 0;
// const uint8_t horizontal_offset = 3;
// canvas_draw_icon(canvas, horizontal_offset, vertical_offset, &I_Dynamic_9x7);
// }
} else {
canvas_draw_icon(
canvas,
@@ -466,8 +470,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
return true;
}
bool consumed = false;
if(event->key == InputKeyBack && event->type == InputTypeShort) {
subghz_receiver->callback(SubGhzCustomEventViewReceiverBack, subghz_receiver->context);
consumed = true;
} else if(
event->key == InputKeyUp &&
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
@@ -479,6 +485,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
subghz_view_receiver_show_time_moment(context);
},
true);
consumed = true;
} else if(
event->key == InputKeyDown &&
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
@@ -492,8 +499,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
}
},
true);
consumed = true;
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
subghz_receiver->callback(SubGhzCustomEventViewReceiverConfig, subghz_receiver->context);
consumed = true;
} else if(event->key == InputKeyRight && event->type == InputTypeLong) {
with_view_model(
subghz_receiver->view,
@@ -506,6 +515,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
}
},
false);
consumed = true;
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
with_view_model(
subghz_receiver->view,
@@ -517,11 +527,13 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
}
},
false);
consumed = true;
}
subghz_view_receiver_update_offset(subghz_receiver);
return true;
if(consumed) {
subghz_view_receiver_update_offset(subghz_receiver);
}
return consumed;
}
void subghz_view_receiver_enter(void* context) {
@@ -551,6 +563,7 @@ void subghz_view_receiver_exit(void* context) {
model->list_offset = 0;
model->history_item = 0;
model->nodraw = false;
model->hopping_enabled = false;
},
false);
furi_timer_stop(subghz_receiver->timer);
@@ -587,6 +600,7 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() {
model->bar_show = SubGhzViewReceiverBarShowDefault;
model->nodraw = false;
model->history = malloc(sizeof(SubGhzReceiverHistory));
model->hopping_enabled = false;
SubGhzReceiverMenuItemArray_init(model->history->data);
},
true);
@@ -630,7 +644,7 @@ View* subghz_view_receiver_get_view(SubGhzViewReceiver* subghz_receiver) {
uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
uint16_t idx = 0;
uint16_t idx;
with_view_model(
subghz_receiver->view, SubGhzViewReceiverModel * model, { idx = model->idx; }, false);
return idx;

View File

@@ -32,4 +32,4 @@ SubGHzFrequencyAnalyzerFeedbackLevel subghz_frequency_analyzer_feedback_level(
SubGHzFrequencyAnalyzerFeedbackLevel level,
bool update);
float subghz_frequency_analyzer_get_trigger_level(SubGhzFrequencyAnalyzer* instance);
float subghz_frequency_analyzer_get_trigger_level(SubGhzFrequencyAnalyzer* instance);