mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-30 08:20:21 +00:00
SubGhz: add SubGhzThresholdRssi
This commit is contained in:
parent
1feb876a32
commit
ff24bf6829
7 changed files with 143 additions and 48 deletions
60
applications/main/subghz/helpers/subghz_threshold_rssi.c
Normal file
60
applications/main/subghz/helpers/subghz_threshold_rssi.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include "subghz_threshold_rssi.h"
|
||||
#include <float_tools.h>
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#define TAG "SubGhzThresholdRssi"
|
||||
#define THRESHOLD_RSSI_LOW_COUNT 10
|
||||
|
||||
struct SubGhzThresholdRssi {
|
||||
float threshold_rssi;
|
||||
uint8_t threshold_rssi_low_count;
|
||||
};
|
||||
|
||||
SubGhzThresholdRssi* subghz_threshold_rssi_alloc(void) {
|
||||
SubGhzThresholdRssi* instance = malloc(sizeof(SubGhzThresholdRssi));
|
||||
instance->threshold_rssi = SUBGHZ_RAW_THRESHOLD_MIN;
|
||||
instance->threshold_rssi_low_count = THRESHOLD_RSSI_LOW_COUNT;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_threshold_rssi_free(SubGhzThresholdRssi* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_threshold_rssi_set(SubGhzThresholdRssi* instance, float rssi) {
|
||||
furi_assert(instance);
|
||||
instance->threshold_rssi = rssi;
|
||||
}
|
||||
|
||||
float subghz_threshold_rssi_get(SubGhzThresholdRssi* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->threshold_rssi;
|
||||
}
|
||||
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance) {
|
||||
furi_assert(instance);
|
||||
float rssi = furi_hal_subghz_get_rssi();
|
||||
SubGhzThresholdRssiData ret = {.rssi = rssi, .is_above = false};
|
||||
|
||||
if(float_is_equal(instance->threshold_rssi, SUBGHZ_RAW_THRESHOLD_MIN)) {
|
||||
ret.is_above = true;
|
||||
} else {
|
||||
if(rssi < instance->threshold_rssi) {
|
||||
instance->threshold_rssi_low_count++;
|
||||
if(instance->threshold_rssi_low_count > THRESHOLD_RSSI_LOW_COUNT) {
|
||||
instance->threshold_rssi_low_count = THRESHOLD_RSSI_LOW_COUNT;
|
||||
}
|
||||
ret.is_above = false;
|
||||
} else {
|
||||
instance->threshold_rssi_low_count = 0;
|
||||
}
|
||||
|
||||
if(instance->threshold_rssi_low_count == THRESHOLD_RSSI_LOW_COUNT) {
|
||||
ret.is_above = false;
|
||||
} else {
|
||||
ret.is_above = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
43
applications/main/subghz/helpers/subghz_threshold_rssi.h
Normal file
43
applications/main/subghz/helpers/subghz_threshold_rssi.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
typedef struct {
|
||||
float rssi; /**< Current RSSI */
|
||||
bool is_above; /**< Exceeded threshold level */
|
||||
} SubGhzThresholdRssiData;
|
||||
|
||||
typedef struct SubGhzThresholdRssi SubGhzThresholdRssi;
|
||||
|
||||
/** Allocate SubGhzThresholdRssi
|
||||
*
|
||||
* @return SubGhzThresholdRssi*
|
||||
*/
|
||||
SubGhzThresholdRssi* subghz_threshold_rssi_alloc(void);
|
||||
|
||||
/** Free SubGhzThresholdRssi
|
||||
*
|
||||
* @param instance Pointer to a SubGhzThresholdRssi
|
||||
*/
|
||||
void subghz_threshold_rssi_free(SubGhzThresholdRssi* instance);
|
||||
|
||||
/** Set threshold
|
||||
*
|
||||
* @param instance Pointer to a SubGhzThresholdRssi
|
||||
* @param rssi RSSI threshold
|
||||
*/
|
||||
void subghz_threshold_rssi_set(SubGhzThresholdRssi* instance, float rssi);
|
||||
|
||||
/** Get threshold
|
||||
*
|
||||
* @param instance Pointer to a SubGhzThresholdRssi
|
||||
* @return float RSSI threshold
|
||||
*/
|
||||
float subghz_threshold_rssi_get(SubGhzThresholdRssi* instance);
|
||||
|
||||
/** Check threshold
|
||||
*
|
||||
* @param instance Pointer to a SubGhzThresholdRssi
|
||||
* @return SubGhzThresholdRssiData
|
||||
*/
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance);
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#define RAW_FILE_NAME "RAW_"
|
||||
#define TAG "SubGhzSceneReadRAW"
|
||||
#define RAW_THRESHOLD_RSSI_LOW_COUNT 10
|
||||
|
||||
bool subghz_scene_read_raw_update_filename(SubGhz* subghz) {
|
||||
bool ret = false;
|
||||
|
@ -75,7 +74,10 @@ void subghz_scene_read_raw_on_enter(void* context) {
|
|||
switch(subghz->txrx->rx_key_state) {
|
||||
case SubGhzRxKeyStateBack:
|
||||
subghz_read_raw_set_status(
|
||||
subghz->subghz_read_raw, SubGhzReadRAWStatusIDLE, "", subghz->txrx->raw_threshold_rssi);
|
||||
subghz->subghz_read_raw,
|
||||
SubGhzReadRAWStatusIDLE,
|
||||
"",
|
||||
subghz_threshold_rssi_get(subghz->threshold_rssi));
|
||||
break;
|
||||
case SubGhzRxKeyStateRAWLoad:
|
||||
path_extract_filename(subghz->file_path, file_name, true);
|
||||
|
@ -83,7 +85,7 @@ void subghz_scene_read_raw_on_enter(void* context) {
|
|||
subghz->subghz_read_raw,
|
||||
SubGhzReadRAWStatusLoadKeyTX,
|
||||
furi_string_get_cstr(file_name),
|
||||
subghz->txrx->raw_threshold_rssi);
|
||||
subghz_threshold_rssi_get(subghz->threshold_rssi));
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
case SubGhzRxKeyStateRAWSave:
|
||||
|
@ -92,7 +94,7 @@ void subghz_scene_read_raw_on_enter(void* context) {
|
|||
subghz->subghz_read_raw,
|
||||
SubGhzReadRAWStatusSaveKey,
|
||||
furi_string_get_cstr(file_name),
|
||||
subghz->txrx->raw_threshold_rssi);
|
||||
subghz_threshold_rssi_get(subghz->threshold_rssi));
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
default:
|
||||
|
@ -100,7 +102,7 @@ void subghz_scene_read_raw_on_enter(void* context) {
|
|||
subghz->subghz_read_raw,
|
||||
SubGhzReadRAWStatusStart,
|
||||
"",
|
||||
subghz->txrx->raw_threshold_rssi);
|
||||
subghz_threshold_rssi_get(subghz->threshold_rssi));
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
}
|
||||
|
@ -238,7 +240,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
|||
subghz->subghz_read_raw,
|
||||
SubGhzReadRAWStatusIDLE,
|
||||
"",
|
||||
subghz->txrx->raw_threshold_rssi);
|
||||
subghz_threshold_rssi_get(subghz->threshold_rssi));
|
||||
} else {
|
||||
if(scene_manager_has_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneSaved) ||
|
||||
|
@ -311,7 +313,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
|||
if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
|
||||
} else {
|
||||
subghz->txrx->raw_threshold_rssi_low_count = RAW_THRESHOLD_RSSI_LOW_COUNT;
|
||||
if(subghz_protocol_raw_save_to_file_init(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result,
|
||||
RAW_FILE_NAME,
|
||||
|
@ -359,40 +360,18 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
|||
switch(subghz->state_notifications) {
|
||||
case SubGhzNotificationStateRx:
|
||||
notification_message(subghz->notifications, &sequence_blink_cyan_10);
|
||||
|
||||
subghz_read_raw_update_sample_write(
|
||||
subghz->subghz_read_raw,
|
||||
subghz_protocol_raw_get_sample_write(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result));
|
||||
|
||||
float rssi = furi_hal_subghz_get_rssi();
|
||||
|
||||
if(float_is_equal(subghz->txrx->raw_threshold_rssi, SUBGHZ_RAW_THRESHOLD_MIN)) {
|
||||
subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, true);
|
||||
SubGhzThresholdRssiData ret_rssi =
|
||||
subghz_threshold_get_rssi_data(subghz->threshold_rssi);
|
||||
subghz_read_raw_add_data_rssi(
|
||||
subghz->subghz_read_raw, ret_rssi.rssi, ret_rssi.is_above);
|
||||
subghz_protocol_raw_save_to_file_pause(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, false);
|
||||
} else {
|
||||
if(rssi < subghz->txrx->raw_threshold_rssi) {
|
||||
subghz->txrx->raw_threshold_rssi_low_count++;
|
||||
if(subghz->txrx->raw_threshold_rssi_low_count > RAW_THRESHOLD_RSSI_LOW_COUNT) {
|
||||
subghz->txrx->raw_threshold_rssi_low_count = RAW_THRESHOLD_RSSI_LOW_COUNT;
|
||||
}
|
||||
subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, false);
|
||||
} else {
|
||||
subghz->txrx->raw_threshold_rssi_low_count = 0;
|
||||
}
|
||||
|
||||
if(subghz->txrx->raw_threshold_rssi_low_count == RAW_THRESHOLD_RSSI_LOW_COUNT) {
|
||||
subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, false);
|
||||
subghz_protocol_raw_save_to_file_pause(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, true);
|
||||
subghz_speaker_mute(subghz);
|
||||
} else {
|
||||
subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, true);
|
||||
subghz_protocol_raw_save_to_file_pause(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, false);
|
||||
subghz_speaker_unmute(subghz);
|
||||
}
|
||||
}
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, !ret_rssi.is_above);
|
||||
|
||||
break;
|
||||
case SubGhzNotificationStateTx:
|
||||
|
|
|
@ -283,10 +283,11 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
|||
}
|
||||
|
||||
//get RSSI
|
||||
float rssi = furi_hal_subghz_get_rssi();
|
||||
subghz_receiver_rssi(subghz->subghz_receiver, rssi);
|
||||
SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(subghz->threshold_rssi);
|
||||
|
||||
subghz_receiver_rssi(subghz->subghz_receiver, ret_rssi.rssi);
|
||||
subghz_protocol_decoder_bin_raw_data_input_rssi(
|
||||
(SubGhzProtocolDecoderBinRAW*)subghz->txrx->decoder_result, rssi);
|
||||
(SubGhzProtocolDecoderBinRAW*)subghz->txrx->decoder_result, ret_rssi.rssi);
|
||||
|
||||
switch(subghz->state_notifications) {
|
||||
case SubGhzNotificationStateRx:
|
||||
|
|
|
@ -234,7 +234,7 @@ static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* it
|
|||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, raw_threshold_rssi_text[index]);
|
||||
subghz->txrx->raw_threshold_rssi = raw_threshold_rssi_value[index];
|
||||
subghz_threshold_rssi_set(subghz->threshold_rssi, raw_threshold_rssi_value[index]);
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_starline(VariableItem* item) {
|
||||
|
@ -400,7 +400,9 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
|||
subghz_scene_receiver_config_set_raw_threshold_rssi,
|
||||
subghz);
|
||||
value_index = value_index_float(
|
||||
subghz->txrx->raw_threshold_rssi, raw_threshold_rssi_value, RAW_THRESHOLD_RSSI_COUNT);
|
||||
subghz_threshold_rssi_get(subghz->threshold_rssi),
|
||||
raw_threshold_rssi_value,
|
||||
RAW_THRESHOLD_RSSI_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, raw_threshold_rssi_text[value_index]);
|
||||
}
|
||||
|
|
|
@ -255,6 +255,10 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
|||
#endif
|
||||
subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency);
|
||||
}
|
||||
|
||||
//init threshold rssi
|
||||
subghz->threshold_rssi = subghz_threshold_rssi_alloc();
|
||||
|
||||
//init Worker & Protocol & History & KeyBoard
|
||||
subghz->lock = SubGhzLockOff;
|
||||
subghz->txrx = malloc(sizeof(SubGhzTxRx));
|
||||
|
@ -275,7 +279,6 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
|||
subghz->txrx->history = subghz_history_alloc();
|
||||
}
|
||||
|
||||
subghz->txrx->raw_threshold_rssi = SUBGHZ_RAW_THRESHOLD_MIN;
|
||||
subghz->txrx->worker = subghz_worker_alloc();
|
||||
|
||||
subghz->txrx->fff_data = flipper_format_string_alloc();
|
||||
|
@ -391,6 +394,10 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) {
|
|||
if(!alloc_for_tx_only) {
|
||||
subghz_last_settings_free(subghz->last_settings);
|
||||
}
|
||||
|
||||
// threshold rssi
|
||||
subghz_threshold_rssi_free(subghz->threshold_rssi);
|
||||
|
||||
//Worker & Protocol & History
|
||||
|
||||
subghz_receiver_free(subghz->txrx->receiver);
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
|
||||
#include "rpc/rpc_app.h"
|
||||
|
||||
#include "helpers/subghz_threshold_rssi.h"
|
||||
|
||||
#define SUBGHZ_MAX_LEN_NAME 64
|
||||
#define SUBGHZ_EXT_PRESET_NAME true
|
||||
|
||||
|
@ -70,20 +72,19 @@ struct SubGhzTxRx {
|
|||
SubGhzRadioPreset* preset;
|
||||
SubGhzHistory* history;
|
||||
uint16_t idx_menu_chosen;
|
||||
uint8_t hopper_timeout;
|
||||
uint8_t hopper_idx_frequency;
|
||||
|
||||
SubGhzTxRxState txrx_state;
|
||||
SubGhzHopperState hopper_state;
|
||||
SubGhzSpeakerState speaker_state;
|
||||
bool ignore_starline;
|
||||
bool ignore_auto_alarms;
|
||||
bool ignore_magellan;
|
||||
uint8_t hopper_timeout;
|
||||
uint8_t hopper_idx_frequency;
|
||||
|
||||
SubGhzRxKeyState rx_key_state;
|
||||
|
||||
bool debug_pin_state;
|
||||
|
||||
float raw_threshold_rssi;
|
||||
uint8_t raw_threshold_rssi_low_count;
|
||||
};
|
||||
|
||||
typedef struct SubGhzTxRx SubGhzTxRx;
|
||||
|
@ -131,6 +132,8 @@ struct SubGhz {
|
|||
SubGhzDecodeRawState decode_raw_state;
|
||||
SubGhzFileEncoderWorker* decode_raw_file_worker_encoder;
|
||||
|
||||
SubGhzThresholdRssi* threshold_rssi;
|
||||
|
||||
void* rpc_ctx;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue