mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-11-29 11:52:30 +03:00
Sub-GHz: Choose RSSI threshold for Hopping mode
by Willy-JL
This commit is contained in:
parent
365159c11a
commit
039274f718
@ -363,7 +363,7 @@ void subghz_txrx_stop(SubGhzTxRx* instance) {
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_txrx_hopper_update(SubGhzTxRx* instance) {
|
||||
void subghz_txrx_hopper_update(SubGhzTxRx* instance, float stay_threshold) {
|
||||
furi_assert(instance);
|
||||
|
||||
switch(instance->hopper_state) {
|
||||
@ -386,7 +386,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance) {
|
||||
float rssi = subghz_devices_get_rssi(instance->radio_device);
|
||||
|
||||
// Stay if RSSI is high enough
|
||||
if(rssi > -90.0f) {
|
||||
if(rssi > stay_threshold) {
|
||||
instance->hopper_timeout = 10;
|
||||
instance->hopper_state = SubGhzHopperStateRSSITimeOut;
|
||||
return;
|
||||
|
@ -121,8 +121,9 @@ void subghz_txrx_sleep(SubGhzTxRx* instance);
|
||||
* Update frequency CC1101 in automatic mode (hopper)
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @param stay_threshold RSSI theshold over which to stay before hopping
|
||||
*/
|
||||
void subghz_txrx_hopper_update(SubGhzTxRx* instance);
|
||||
void subghz_txrx_hopper_update(SubGhzTxRx* instance, float stay_threshold);
|
||||
|
||||
/**
|
||||
* Get state hopper
|
||||
|
@ -294,7 +294,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) {
|
||||
subghz_txrx_hopper_update(subghz->txrx);
|
||||
subghz_txrx_hopper_update(subghz->txrx, subghz->last_settings->hopping_threshold);
|
||||
subghz_scene_receiver_update_statusbar(subghz);
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,37 @@ const float raw_threshold_rssi_value[RAW_THRESHOLD_RSSI_COUNT] = {
|
||||
-40.0f,
|
||||
};
|
||||
|
||||
#define HOPPING_MODE_COUNT 12
|
||||
const char* const hopping_mode_text[HOPPING_MODE_COUNT] = {
|
||||
"OFF",
|
||||
"-90.0",
|
||||
"-85.0",
|
||||
"-80.0",
|
||||
"-75.0",
|
||||
"-70.0",
|
||||
"-65.0",
|
||||
"-60.0",
|
||||
"-55.0",
|
||||
"-50.0",
|
||||
"-45.0",
|
||||
"-40.0",
|
||||
|
||||
};
|
||||
const float hopping_mode_value[HOPPING_MODE_COUNT] = {
|
||||
NAN,
|
||||
-90.0f,
|
||||
-85.0f,
|
||||
-80.0f,
|
||||
-75.0f,
|
||||
-70.0f,
|
||||
-65.0f,
|
||||
-60.0f,
|
||||
-55.0f,
|
||||
-50.0f,
|
||||
-45.0f,
|
||||
-40.0f,
|
||||
};
|
||||
|
||||
#define COMBO_BOX_COUNT 2
|
||||
|
||||
const uint32_t hopping_value[COMBO_BOX_COUNT] = {
|
||||
@ -121,18 +152,19 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void*
|
||||
return index;
|
||||
}
|
||||
|
||||
SubGhzHopperState subghz_scene_receiver_config_hopper_value_index(void* context) {
|
||||
uint8_t subghz_scene_receiver_config_hopper_value_index(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz_txrx_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) {
|
||||
return SubGhzHopperStateOFF;
|
||||
return 0;
|
||||
} else {
|
||||
variable_item_set_current_value_text(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
variable_item_list_get(subghz->variable_item_list, SubGhzSettingIndexFrequency),
|
||||
" -----");
|
||||
return SubGhzHopperStateRunning;
|
||||
return value_index_float(
|
||||
subghz->last_settings->hopping_threshold, hopping_mode_value, HOPPING_MODE_COUNT);
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,16 +220,16 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) {
|
||||
subghz->last_settings->preset_index = index;
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) {
|
||||
static void subghz_scene_receiver_config_set_hopping(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
SubGhzHopperState index = variable_item_get_current_value_index(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx);
|
||||
VariableItem* frequency_item = (VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig);
|
||||
VariableItem* frequency_item =
|
||||
variable_item_list_get(subghz->variable_item_list, SubGhzSettingIndexFrequency);
|
||||
|
||||
variable_item_set_current_value_text(item, combobox_text[(uint8_t)index]);
|
||||
variable_item_set_current_value_text(item, hopping_mode_text[index]);
|
||||
|
||||
if(index == SubGhzHopperStateOFF) {
|
||||
if(index == 0) {
|
||||
char text_buf[10] = {0};
|
||||
uint32_t frequency = subghz_setting_get_default_frequency(setting);
|
||||
SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
|
||||
@ -224,8 +256,10 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item)
|
||||
variable_item_set_current_value_index(
|
||||
frequency_item, subghz_setting_get_frequency_default_index(setting));
|
||||
}
|
||||
subghz->last_settings->enable_hopping = index != SubGhzHopperStateOFF;
|
||||
subghz_txrx_hopper_set_state(subghz->txrx, index);
|
||||
subghz->last_settings->enable_hopping = index != 0;
|
||||
subghz->last_settings->hopping_threshold = hopping_mode_value[index];
|
||||
subghz_txrx_hopper_set_state(
|
||||
subghz->txrx, index != 0 ? SubGhzHopperStateRunning : SubGhzHopperStateOFF);
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_speaker(VariableItem* item) {
|
||||
@ -383,13 +417,13 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Hopping",
|
||||
COMBO_BOX_COUNT,
|
||||
subghz_scene_receiver_config_set_hopping_running,
|
||||
HOPPING_MODE_COUNT,
|
||||
subghz_scene_receiver_config_set_hopping,
|
||||
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, combobox_text[value_index]);
|
||||
variable_item_set_current_value_text(item, hopping_mode_text[value_index]);
|
||||
}
|
||||
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
||||
|
@ -175,7 +175,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) {
|
||||
subghz_txrx_hopper_update(subghz->txrx);
|
||||
subghz_txrx_hopper_update(subghz->txrx, subghz->last_settings->hopping_threshold);
|
||||
}
|
||||
switch(subghz->state_notifications) {
|
||||
case SubGhzNotificationStateTx:
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_FILTER "Filter"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD "RSSI"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD "DelOldSignals"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD "HoppingThreshold"
|
||||
|
||||
SubGhzLastSettings* subghz_last_settings_alloc(void) {
|
||||
SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings));
|
||||
@ -40,6 +41,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
||||
// See bin_raw_value in scenes/subghz_scene_receiver_config.c
|
||||
instance->filter = SubGhzProtocolFlag_Decodable;
|
||||
instance->rssi = SUBGHZ_RAW_THRESHOLD_MIN;
|
||||
instance->hopping_threshold = -90.0f;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
@ -114,6 +116,13 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
||||
1)) {
|
||||
flipper_format_rewind(fff_data_file);
|
||||
}
|
||||
if(!flipper_format_read_float(
|
||||
fff_data_file,
|
||||
SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD,
|
||||
&instance->hopping_threshold,
|
||||
1)) {
|
||||
flipper_format_rewind(fff_data_file);
|
||||
}
|
||||
|
||||
} while(0);
|
||||
} else {
|
||||
@ -203,6 +212,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
|
||||
file, SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD, &instance->delete_old_signals, 1)) {
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_write_float(
|
||||
file,
|
||||
SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD,
|
||||
&instance->hopping_threshold,
|
||||
1)) {
|
||||
break;
|
||||
}
|
||||
|
||||
saved = true;
|
||||
} while(0);
|
||||
|
@ -24,6 +24,7 @@ typedef struct {
|
||||
uint32_t filter;
|
||||
float rssi;
|
||||
bool delete_old_signals;
|
||||
float hopping_threshold;
|
||||
} SubGhzLastSettings;
|
||||
|
||||
SubGhzLastSettings* subghz_last_settings_alloc(void);
|
||||
|
Loading…
Reference in New Issue
Block a user