2021-10-10 14:35:10 +00:00
|
|
|
#include "subghz_frequency_analyzer.h"
|
|
|
|
#include "../subghz_i.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <furi.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-10-10 14:35:10 +00:00
|
|
|
#include <input/input.h>
|
2022-11-03 07:57:56 +00:00
|
|
|
#include <gui/elements.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <notification/notification_messages.h>
|
2021-10-10 14:35:10 +00:00
|
|
|
#include "../helpers/subghz_frequency_analyzer_worker.h"
|
2022-11-03 07:57:56 +00:00
|
|
|
#include "../helpers/subghz_frequency_analyzer_log_item_array.h"
|
2021-10-10 14:35:10 +00:00
|
|
|
|
|
|
|
#include <assets_icons.h>
|
2022-12-26 12:13:30 +00:00
|
|
|
#include <float_tools.h>
|
2021-10-10 14:35:10 +00:00
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
#define LOG_FREQUENCY_MAX_ITEMS 60 // uint8_t (limited by 'seq' of SubGhzFrequencyAnalyzerLogItem)
|
|
|
|
|
|
|
|
#define SNPRINTF_FREQUENCY(buff, freq) \
|
|
|
|
snprintf(buff, sizeof(buff), "%03ld.%03ld", freq / 1000000 % 1000, freq / 1000 % 1000);
|
|
|
|
|
2021-10-10 14:35:10 +00:00
|
|
|
typedef enum {
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzFrequencyAnalyzerStatusIDLE,
|
|
|
|
} SubGhzFrequencyAnalyzerStatus;
|
2021-10-10 14:35:10 +00:00
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
typedef enum {
|
|
|
|
SubGhzFrequencyAnalyzerFragmentBottomTypeMain,
|
|
|
|
SubGhzFrequencyAnalyzerFragmentBottomTypeLog,
|
|
|
|
} SubGhzFrequencyAnalyzerFragmentBottomType;
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
struct SubGhzFrequencyAnalyzer {
|
2021-10-10 14:35:10 +00:00
|
|
|
View* view;
|
|
|
|
SubGhzFrequencyAnalyzerWorker* worker;
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzFrequencyAnalyzerCallback callback;
|
2021-10-10 14:35:10 +00:00
|
|
|
void* context;
|
2022-04-28 17:20:59 +00:00
|
|
|
bool locked;
|
2022-11-03 07:57:56 +00:00
|
|
|
uint32_t last_frequency;
|
2021-10-10 14:35:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t frequency;
|
2022-11-03 07:57:56 +00:00
|
|
|
uint8_t rssi;
|
2022-10-06 14:48:29 +00:00
|
|
|
uint32_t history_frequency[3];
|
|
|
|
bool signal;
|
2022-11-03 07:57:56 +00:00
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_t log_frequency;
|
|
|
|
SubGhzFrequencyAnalyzerFragmentBottomType fragment_bottom_type;
|
|
|
|
SubGhzFrequencyAnalyzerLogOrderBy log_frequency_order_by;
|
|
|
|
uint8_t log_frequency_scroll_offset;
|
2022-03-03 09:48:56 +00:00
|
|
|
} SubGhzFrequencyAnalyzerModel;
|
2021-10-10 14:35:10 +00:00
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
static inline uint8_t rssi_sanitize(float rssi) {
|
2022-12-26 12:13:30 +00:00
|
|
|
return (
|
|
|
|
!float_is_equal(rssi, 0.f) ? (uint8_t)(rssi - SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) : 0);
|
2022-11-03 07:57:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 14:35:10 +00:00
|
|
|
void subghz_frequency_analyzer_set_callback(
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer,
|
|
|
|
SubGhzFrequencyAnalyzerCallback callback,
|
2021-10-10 14:35:10 +00:00
|
|
|
void* context) {
|
|
|
|
furi_assert(subghz_frequency_analyzer);
|
|
|
|
furi_assert(callback);
|
|
|
|
subghz_frequency_analyzer->callback = callback;
|
|
|
|
subghz_frequency_analyzer->context = context;
|
|
|
|
}
|
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
void subghz_frequency_analyzer_draw_rssi(Canvas* canvas, uint8_t rssi, uint8_t x, uint8_t y) {
|
2021-10-10 14:35:10 +00:00
|
|
|
uint8_t column_number = 0;
|
|
|
|
if(rssi) {
|
2022-11-23 13:31:39 +00:00
|
|
|
rssi = rssi / 3 + 2;
|
|
|
|
if(rssi > 20) rssi = 20;
|
2022-11-03 07:57:56 +00:00
|
|
|
for(uint8_t i = 1; i < rssi; i++) {
|
2021-10-10 14:35:10 +00:00
|
|
|
if(i % 4) {
|
|
|
|
column_number++;
|
2022-11-23 13:31:39 +00:00
|
|
|
canvas_draw_box(canvas, x + 2 * i, y - column_number, 2, column_number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_frequency_analyzer_draw_log_rssi(Canvas* canvas, uint8_t rssi, uint8_t x, uint8_t y) {
|
|
|
|
uint8_t column_height = 6;
|
|
|
|
if(rssi) {
|
|
|
|
if(rssi > 54) rssi = 54;
|
|
|
|
for(uint8_t i = 1; i < rssi; i++) {
|
|
|
|
if(i % 5) {
|
|
|
|
canvas_draw_box(canvas, x + i, y - column_height, 1, column_height);
|
2021-10-10 14:35:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
static void subghz_frequency_analyzer_log_frequency_draw(
|
|
|
|
Canvas* canvas,
|
|
|
|
SubGhzFrequencyAnalyzerModel* model) {
|
|
|
|
char buffer[64];
|
|
|
|
const uint8_t offset_x = 0;
|
|
|
|
const uint8_t offset_y = 43;
|
|
|
|
canvas_set_font(canvas, FontKeyboard);
|
|
|
|
|
|
|
|
const size_t items_count = SubGhzFrequencyAnalyzerLogItemArray_size(model->log_frequency);
|
|
|
|
if(items_count == 0) {
|
2022-11-23 13:31:39 +00:00
|
|
|
canvas_draw_rframe(canvas, offset_x + 27, offset_y - 3, 73, 16, 5);
|
2022-11-03 07:57:56 +00:00
|
|
|
canvas_draw_str_aligned(
|
2022-11-23 13:31:39 +00:00
|
|
|
canvas, offset_x + 64, offset_y + 8, AlignCenter, AlignBottom, "No records");
|
2022-11-03 07:57:56 +00:00
|
|
|
return;
|
|
|
|
} else if(items_count > 3) {
|
|
|
|
elements_scrollbar_pos(
|
|
|
|
canvas,
|
|
|
|
offset_x + 127,
|
|
|
|
offset_y - 8,
|
|
|
|
29,
|
|
|
|
model->log_frequency_scroll_offset,
|
|
|
|
items_count - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
SubGhzFrequencyAnalyzerLogItem_t* log_frequency_item;
|
|
|
|
for(uint8_t i = 0; i < 3; ++i) {
|
|
|
|
const uint8_t item_pos = model->log_frequency_scroll_offset + i;
|
|
|
|
if(item_pos >= items_count) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
log_frequency_item =
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_get(model->log_frequency, item_pos);
|
|
|
|
// Frequency
|
|
|
|
SNPRINTF_FREQUENCY(buffer, (*log_frequency_item)->frequency)
|
|
|
|
canvas_draw_str(canvas, offset_x, offset_y + i * 10, buffer);
|
|
|
|
|
|
|
|
// Count
|
|
|
|
snprintf(buffer, sizeof(buffer), "%3d", (*log_frequency_item)->count);
|
|
|
|
canvas_draw_str(canvas, offset_x + 48, offset_y + i * 10, buffer);
|
|
|
|
|
|
|
|
// Max RSSI
|
2022-11-23 13:31:39 +00:00
|
|
|
subghz_frequency_analyzer_draw_log_rssi(
|
2022-11-03 07:57:56 +00:00
|
|
|
canvas, (*log_frequency_item)->rssi_max, offset_x + 69, (offset_y + i * 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:48:29 +00:00
|
|
|
static void subghz_frequency_analyzer_history_frequency_draw(
|
|
|
|
Canvas* canvas,
|
|
|
|
SubGhzFrequencyAnalyzerModel* model) {
|
|
|
|
char buffer[64];
|
|
|
|
uint8_t x = 66;
|
|
|
|
uint8_t y = 43;
|
|
|
|
|
|
|
|
canvas_set_font(canvas, FontKeyboard);
|
|
|
|
for(uint8_t i = 0; i < 3; i++) {
|
|
|
|
if(model->history_frequency[i]) {
|
2022-11-03 07:57:56 +00:00
|
|
|
SNPRINTF_FREQUENCY(buffer, model->history_frequency[i])
|
2022-10-06 14:48:29 +00:00
|
|
|
canvas_draw_str(canvas, x, y + i * 10, buffer);
|
|
|
|
} else {
|
|
|
|
canvas_draw_str(canvas, x, y + i * 10, "---.---");
|
|
|
|
}
|
|
|
|
canvas_draw_str(canvas, x + 44, y + i * 10, "MHz");
|
|
|
|
}
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel* model) {
|
2022-11-03 07:57:56 +00:00
|
|
|
furi_assert(canvas);
|
|
|
|
furi_assert(model);
|
2021-10-10 14:35:10 +00:00
|
|
|
char buffer[64];
|
|
|
|
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
if(model->fragment_bottom_type == SubGhzFrequencyAnalyzerFragmentBottomTypeLog) {
|
|
|
|
const size_t items_count = SubGhzFrequencyAnalyzerLogItemArray_size(model->log_frequency);
|
|
|
|
const char* log_order_by_name =
|
|
|
|
subghz_frequency_analyzer_log_get_order_name(model->log_frequency_order_by);
|
|
|
|
if(items_count < LOG_FREQUENCY_MAX_ITEMS) {
|
|
|
|
snprintf(buffer, sizeof(buffer), "Frequency Analyzer [%s]", log_order_by_name);
|
|
|
|
canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignBottom, buffer);
|
|
|
|
} else {
|
|
|
|
snprintf(buffer, sizeof(buffer), "The log is full! [%s]", log_order_by_name);
|
|
|
|
canvas_draw_str(canvas, 2, 8, buffer);
|
|
|
|
}
|
|
|
|
subghz_frequency_analyzer_log_frequency_draw(canvas, model);
|
|
|
|
} else {
|
|
|
|
canvas_draw_str(canvas, 20, 8, "Frequency Analyzer");
|
|
|
|
canvas_draw_str(canvas, 0, 64, "RSSI");
|
2022-11-23 13:31:39 +00:00
|
|
|
subghz_frequency_analyzer_draw_rssi(canvas, model->rssi, 20, 64);
|
2021-10-10 14:35:10 +00:00
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
subghz_frequency_analyzer_history_frequency_draw(canvas, model);
|
|
|
|
}
|
2022-10-06 14:48:29 +00:00
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
// Frequency
|
2021-10-10 14:35:10 +00:00
|
|
|
canvas_set_font(canvas, FontBigNumbers);
|
2022-11-23 13:31:39 +00:00
|
|
|
SNPRINTF_FREQUENCY(buffer, model->frequency);
|
2022-10-06 14:48:29 +00:00
|
|
|
if(model->signal) {
|
2022-11-23 13:31:39 +00:00
|
|
|
canvas_draw_box(canvas, 4, 11, 121, 22);
|
2022-10-06 14:48:29 +00:00
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
}
|
2022-11-23 13:31:39 +00:00
|
|
|
canvas_draw_str(canvas, 8, 29, buffer);
|
|
|
|
canvas_draw_icon(canvas, 96, 18, &I_MHz_25x11);
|
2021-10-10 14:35:10 +00:00
|
|
|
}
|
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
static void subghz_frequency_analyzer_log_frequency_sort(SubGhzFrequencyAnalyzerModel* model) {
|
|
|
|
furi_assert(model);
|
|
|
|
M_LET((cmp, model->log_frequency_order_by), SubGhzFrequencyAnalyzerLogItemArray_compare_by_t)
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_sort_fo(
|
|
|
|
model->log_frequency, SubGhzFrequencyAnalyzerLogItemArray_compare_by_as_interface(cmp));
|
|
|
|
}
|
|
|
|
|
2021-10-10 14:35:10 +00:00
|
|
|
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
|
|
|
furi_assert(context);
|
2022-11-03 07:57:56 +00:00
|
|
|
SubGhzFrequencyAnalyzer* instance = context;
|
2021-10-10 14:35:10 +00:00
|
|
|
|
|
|
|
if(event->key == InputKeyBack) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
if((event->type == InputTypeShort) &&
|
|
|
|
((event->key == InputKeyLeft) || (event->key == InputKeyRight))) {
|
|
|
|
with_view_model(
|
|
|
|
instance->view,
|
|
|
|
SubGhzFrequencyAnalyzerModel * model,
|
|
|
|
{
|
|
|
|
if(event->key == InputKeyLeft) {
|
|
|
|
if(model->fragment_bottom_type == 0) {
|
|
|
|
model->fragment_bottom_type = SubGhzFrequencyAnalyzerFragmentBottomTypeLog;
|
|
|
|
} else {
|
|
|
|
--model->fragment_bottom_type;
|
|
|
|
}
|
|
|
|
} else if(event->key == InputKeyRight) {
|
|
|
|
if(model->fragment_bottom_type ==
|
|
|
|
SubGhzFrequencyAnalyzerFragmentBottomTypeLog) {
|
|
|
|
model->fragment_bottom_type = 0;
|
|
|
|
} else {
|
|
|
|
++model->fragment_bottom_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
} else if((event->type == InputTypeShort) && (event->key == InputKeyOk)) {
|
|
|
|
with_view_model(
|
|
|
|
instance->view,
|
|
|
|
SubGhzFrequencyAnalyzerModel * model,
|
|
|
|
{
|
|
|
|
if(model->fragment_bottom_type == SubGhzFrequencyAnalyzerFragmentBottomTypeLog) {
|
|
|
|
++model->log_frequency_order_by;
|
|
|
|
if(model->log_frequency_order_by >
|
|
|
|
SubGhzFrequencyAnalyzerLogOrderByFrequencyAsc) {
|
|
|
|
model->log_frequency_order_by = 0;
|
|
|
|
}
|
|
|
|
subghz_frequency_analyzer_log_frequency_sort(model);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
} else if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
|
|
|
|
with_view_model(
|
|
|
|
instance->view,
|
|
|
|
SubGhzFrequencyAnalyzerModel * model,
|
|
|
|
{
|
|
|
|
if(model->fragment_bottom_type == SubGhzFrequencyAnalyzerFragmentBottomTypeLog) {
|
|
|
|
if(event->key == InputKeyUp) {
|
|
|
|
if(model->log_frequency_scroll_offset > 0) {
|
|
|
|
--model->log_frequency_scroll_offset;
|
|
|
|
}
|
|
|
|
} else if(event->key == InputKeyDown) {
|
|
|
|
const size_t items_count =
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_size(model->log_frequency);
|
|
|
|
if((model->log_frequency_scroll_offset + 3u) < items_count) {
|
|
|
|
++model->log_frequency_scroll_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2021-10-10 14:35:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-11-03 07:57:56 +00:00
|
|
|
static void subghz_frequency_analyzer_log_frequency_search_it(
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_it_t* itref,
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_t* log_frequency,
|
|
|
|
uint32_t frequency) {
|
|
|
|
furi_assert(log_frequency);
|
|
|
|
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_it(*itref, *log_frequency);
|
|
|
|
SubGhzFrequencyAnalyzerLogItem_t* item;
|
|
|
|
while(!SubGhzFrequencyAnalyzerLogItemArray_end_p(*itref)) {
|
|
|
|
item = SubGhzFrequencyAnalyzerLogItemArray_ref(*itref);
|
|
|
|
if((*item)->frequency == frequency) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_next(*itref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool subghz_frequency_analyzer_log_frequency_insert(SubGhzFrequencyAnalyzerModel* model) {
|
|
|
|
furi_assert(model);
|
|
|
|
const size_t items_count = SubGhzFrequencyAnalyzerLogItemArray_size(model->log_frequency);
|
|
|
|
if(items_count < LOG_FREQUENCY_MAX_ITEMS) {
|
|
|
|
SubGhzFrequencyAnalyzerLogItem_t* item =
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_push_new(model->log_frequency);
|
|
|
|
(*item)->frequency = model->frequency;
|
2022-11-23 13:31:39 +00:00
|
|
|
(*item)->count = 1;
|
2022-11-03 07:57:56 +00:00
|
|
|
(*item)->rssi_max = model->rssi;
|
|
|
|
(*item)->seq = items_count;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void subghz_frequency_analyzer_log_frequency_update(
|
|
|
|
SubGhzFrequencyAnalyzerModel* model,
|
|
|
|
bool need_insert) {
|
|
|
|
furi_assert(model);
|
|
|
|
if(!model->frequency) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_it_t it;
|
|
|
|
subghz_frequency_analyzer_log_frequency_search_it(
|
|
|
|
&it, &model->log_frequency, model->frequency);
|
|
|
|
if(!SubGhzFrequencyAnalyzerLogItemArray_end_p(it)) {
|
|
|
|
SubGhzFrequencyAnalyzerLogItem_t* item = SubGhzFrequencyAnalyzerLogItemArray_ref(it);
|
|
|
|
if((*item)->rssi_max < model->rssi) {
|
|
|
|
(*item)->rssi_max = model->rssi;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(need_insert && (*item)->count < UINT8_MAX) {
|
|
|
|
++(*item)->count;
|
|
|
|
subghz_frequency_analyzer_log_frequency_sort(model);
|
|
|
|
}
|
|
|
|
} else if(need_insert) {
|
|
|
|
if(subghz_frequency_analyzer_log_frequency_insert(model)) {
|
|
|
|
subghz_frequency_analyzer_log_frequency_sort(model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:48:29 +00:00
|
|
|
void subghz_frequency_analyzer_pair_callback(
|
|
|
|
void* context,
|
|
|
|
uint32_t frequency,
|
|
|
|
float rssi,
|
|
|
|
bool signal) {
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzFrequencyAnalyzer* instance = context;
|
2022-12-26 12:13:30 +00:00
|
|
|
if(float_is_equal(rssi, 0.f) && instance->locked) {
|
2022-04-28 17:20:59 +00:00
|
|
|
if(instance->callback) {
|
|
|
|
instance->callback(SubGhzCustomEventSceneAnalyzerUnlock, instance->context);
|
|
|
|
}
|
2022-11-03 07:57:56 +00:00
|
|
|
instance->last_frequency = 0;
|
2022-10-06 14:48:29 +00:00
|
|
|
//update history
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
instance->view,
|
|
|
|
SubGhzFrequencyAnalyzerModel * model,
|
|
|
|
{
|
2022-10-06 14:48:29 +00:00
|
|
|
model->history_frequency[2] = model->history_frequency[1];
|
|
|
|
model->history_frequency[1] = model->history_frequency[0];
|
|
|
|
model->history_frequency[0] = model->frequency;
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2022-12-26 12:13:30 +00:00
|
|
|
} else if(!float_is_equal(rssi, 0.f) && !instance->locked) {
|
2022-04-28 17:20:59 +00:00
|
|
|
if(instance->callback) {
|
|
|
|
instance->callback(SubGhzCustomEventSceneAnalyzerLock, instance->context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-26 12:13:30 +00:00
|
|
|
instance->locked = !float_is_equal(rssi, 0.f);
|
2021-10-10 14:35:10 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
instance->view,
|
|
|
|
SubGhzFrequencyAnalyzerModel * model,
|
|
|
|
{
|
2022-11-03 07:57:56 +00:00
|
|
|
model->rssi = rssi_sanitize(rssi);
|
2021-10-10 14:35:10 +00:00
|
|
|
model->frequency = frequency;
|
2022-10-06 14:48:29 +00:00
|
|
|
model->signal = signal;
|
2022-11-03 07:57:56 +00:00
|
|
|
if(frequency) {
|
|
|
|
subghz_frequency_analyzer_log_frequency_update(
|
|
|
|
model, frequency != instance->last_frequency);
|
|
|
|
instance->last_frequency = frequency;
|
|
|
|
}
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
true);
|
2021-10-10 14:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_frequency_analyzer_enter(void* context) {
|
|
|
|
furi_assert(context);
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzFrequencyAnalyzer* instance = context;
|
2021-10-10 14:35:10 +00:00
|
|
|
|
|
|
|
//Start worker
|
2022-05-31 15:50:50 +00:00
|
|
|
instance->worker = subghz_frequency_analyzer_worker_alloc(instance->context);
|
2021-10-10 14:35:10 +00:00
|
|
|
|
|
|
|
subghz_frequency_analyzer_worker_set_pair_callback(
|
|
|
|
instance->worker,
|
|
|
|
(SubGhzFrequencyAnalyzerWorkerPairCallback)subghz_frequency_analyzer_pair_callback,
|
|
|
|
instance);
|
|
|
|
|
|
|
|
subghz_frequency_analyzer_worker_start(instance->worker);
|
|
|
|
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
instance->view,
|
|
|
|
SubGhzFrequencyAnalyzerModel * model,
|
|
|
|
{
|
2022-11-03 07:57:56 +00:00
|
|
|
model->rssi = 0u;
|
2021-10-10 14:35:10 +00:00
|
|
|
model->frequency = 0;
|
2022-11-03 07:57:56 +00:00
|
|
|
model->fragment_bottom_type = SubGhzFrequencyAnalyzerFragmentBottomTypeMain;
|
|
|
|
model->log_frequency_order_by = SubGhzFrequencyAnalyzerLogOrderBySeqDesc;
|
2022-11-23 13:31:39 +00:00
|
|
|
model->log_frequency_scroll_offset = 0;
|
2022-11-03 07:57:56 +00:00
|
|
|
model->history_frequency[0] = model->history_frequency[1] =
|
2022-11-23 13:31:39 +00:00
|
|
|
model->history_frequency[2] = 0;
|
2022-11-03 07:57:56 +00:00
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_init(model->log_frequency);
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
true);
|
2021-10-10 14:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_frequency_analyzer_exit(void* context) {
|
|
|
|
furi_assert(context);
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzFrequencyAnalyzer* instance = context;
|
2021-10-10 14:35:10 +00:00
|
|
|
|
|
|
|
//Stop worker
|
|
|
|
if(subghz_frequency_analyzer_worker_is_running(instance->worker)) {
|
|
|
|
subghz_frequency_analyzer_worker_stop(instance->worker);
|
|
|
|
}
|
|
|
|
subghz_frequency_analyzer_worker_free(instance->worker);
|
|
|
|
|
|
|
|
with_view_model(
|
2022-11-03 07:57:56 +00:00
|
|
|
instance->view,
|
|
|
|
SubGhzFrequencyAnalyzerModel * model,
|
|
|
|
{
|
2022-11-23 13:31:39 +00:00
|
|
|
model->rssi = 0;
|
2022-11-03 07:57:56 +00:00
|
|
|
model->frequency = 0;
|
|
|
|
model->fragment_bottom_type = SubGhzFrequencyAnalyzerFragmentBottomTypeMain;
|
|
|
|
model->log_frequency_order_by = SubGhzFrequencyAnalyzerLogOrderBySeqDesc;
|
2022-11-23 13:31:39 +00:00
|
|
|
model->log_frequency_scroll_offset = 0;
|
2022-11-03 07:57:56 +00:00
|
|
|
model->history_frequency[0] = model->history_frequency[1] =
|
2022-11-23 13:31:39 +00:00
|
|
|
model->history_frequency[2] = 0;
|
2022-11-03 07:57:56 +00:00
|
|
|
SubGhzFrequencyAnalyzerLogItemArray_clear(model->log_frequency);
|
|
|
|
},
|
|
|
|
true);
|
2021-10-10 14:35:10 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
|
|
|
SubGhzFrequencyAnalyzer* instance = malloc(sizeof(SubGhzFrequencyAnalyzer));
|
2021-10-10 14:35:10 +00:00
|
|
|
|
|
|
|
// View allocation and configuration
|
2022-11-03 07:57:56 +00:00
|
|
|
instance->last_frequency = 0;
|
2021-10-10 14:35:10 +00:00
|
|
|
instance->view = view_alloc();
|
|
|
|
view_allocate_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, ViewModelTypeLocking, sizeof(SubGhzFrequencyAnalyzerModel));
|
2021-10-10 14:35:10 +00:00
|
|
|
view_set_context(instance->view, instance);
|
|
|
|
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_frequency_analyzer_draw);
|
|
|
|
view_set_input_callback(instance->view, subghz_frequency_analyzer_input);
|
|
|
|
view_set_enter_callback(instance->view, subghz_frequency_analyzer_enter);
|
|
|
|
view_set_exit_callback(instance->view, subghz_frequency_analyzer_exit);
|
|
|
|
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
instance->view, SubGhzFrequencyAnalyzerModel * model, { model->rssi = 0; }, true);
|
2021-10-10 14:35:10 +00:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* instance) {
|
2021-10-10 14:35:10 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
|
|
|
|
view_free(instance->view);
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* instance) {
|
2021-10-10 14:35:10 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
return instance->view;
|
2022-02-18 19:53:46 +00:00
|
|
|
}
|