Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New frequency analyzer #1557

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions applications/subghz/helpers/subghz_frequency_analyzer_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#define TAG "SubghzFrequencyAnalyzerWorker"

#define SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD -95.0f
#define SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD -97.0f

static const uint8_t subghz_preset_ook_58khz[][2] = {
{CC1101_MDMCFG4, 0b11110111}, // Rx BW filter is 58.035714kHz
Expand All @@ -28,6 +28,7 @@ struct SubGhzFrequencyAnalyzerWorker {
SubGhzSetting* setting;

float filVal;
float trigger_level;

SubGhzFrequencyAnalyzerWorkerPairCallback pair_callback;
void* context;
Expand Down Expand Up @@ -154,7 +155,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
(double)rssi_min);

// Second stage: fine scan
if(frequency_rssi.rssi_coarse > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) {
if(frequency_rssi.rssi_coarse > instance->trigger_level) {
furi_hal_subghz_idle();
subghz_frequency_analyzer_worker_load_registers(subghz_preset_ook_58khz);
//for example -0.3 ... 433.92 ... +0.3 step 20KHz
Expand Down Expand Up @@ -189,7 +190,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
}

// Deliver results fine
if(frequency_rssi.rssi_fine > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) {
if(frequency_rssi.rssi_fine > instance->trigger_level) {
FURI_LOG_D(
TAG, "=:%u:%f", frequency_rssi.frequency_fine, (double)frequency_rssi.rssi_fine);

Expand All @@ -205,7 +206,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
instance->context, frequency_rssi.frequency_fine, frequency_rssi.rssi_fine);
}
} else if( // Deliver results coarse
(frequency_rssi.rssi_coarse > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) &&
(frequency_rssi.rssi_coarse > instance->trigger_level) &&
(instance->sample_hold_counter < 10)) {
FURI_LOG_D(
TAG,
Expand Down Expand Up @@ -255,6 +256,7 @@ SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* cont

SubGhz* subghz = context;
instance->setting = subghz->setting;
instance->trigger_level = SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD;
return instance;
}

Expand Down Expand Up @@ -297,3 +299,13 @@ bool subghz_frequency_analyzer_worker_is_running(SubGhzFrequencyAnalyzerWorker*
furi_assert(instance);
return instance->worker_running;
}

void subghz_frequency_analyzer_worker_set_trigger_level(
SubGhzFrequencyAnalyzerWorker* instance,
float value) {
instance->trigger_level = value;
}

float subghz_frequency_analyzer_worker_get_trigger_level(SubGhzFrequencyAnalyzerWorker* instance) {
return instance->trigger_level;
}
16 changes: 16 additions & 0 deletions applications/subghz/helpers/subghz_frequency_analyzer_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,19 @@ void subghz_frequency_analyzer_worker_stop(SubGhzFrequencyAnalyzerWorker* instan
* @return bool - true if running
*/
bool subghz_frequency_analyzer_worker_is_running(SubGhzFrequencyAnalyzerWorker* instance);

/** Set RSSI trigger level
*
* @param instance SubGhzFrequencyAnalyzerWorker instance
* @param value RSSI level
*/
void subghz_frequency_analyzer_worker_set_trigger_level(
SubGhzFrequencyAnalyzerWorker* instance,
float value);

/** Get RSSI trigger level
*
* @param instance SubGhzFrequencyAnalyzerWorker instance
* @return RSSI trigger level
*/
float subghz_frequency_analyzer_worker_get_trigger_level(SubGhzFrequencyAnalyzerWorker* instance);
12 changes: 2 additions & 10 deletions applications/subghz/scenes/subghz_scene_frequency_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ void subghz_scene_frequency_analyzer_on_enter(void* context) {
}

bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventSceneAnalyzerLock) {
notification_message(subghz->notifications, &sequence_set_green_255);
return true;
} else if(event.event == SubGhzCustomEventSceneAnalyzerUnlock) {
notification_message(subghz->notifications, &sequence_reset_rgb);
return true;
}
}
UNUSED(context);
UNUSED(event);
return false;
}

Expand Down
Loading