mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-20 17:53:20 +00:00
d2ca67d261
* SubGhz: add SubGhzThresholdRssi * SubGhz: remove direct reading of subghz-txrx-txrx_state * SubGhz: remove direct reading subghz->txrx->hopper_state * SubGhz: remove direct reading subghz->lock * SubGhz: check load type file * SubGhz: remove direct reading subghz->txrx->rx_key_state * SubGhz: remove direct reading subghz->txrx->speaker_state * SubGhz: refactoring subghz_scene_set_type.c * SubGhz: moving "txrx" entity to a separate file * SubGhz: show error tx start * SubGhz: refactoring RPC * SubGhz: value get optimizations * SubGhz: fix name file * SubGhz: add function description * SubGhz: fix double back with a blocked transmission in this region and speacker, when a transmission is blocked in this region * SubGhz: correct spelling * SubGhz: better naming * SubGhz: simplify includes Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
#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;
|
|
}
|