Skorp subghz capture refactoring (#569)

* SubGhz: changing the operation of the capture timer, and the logic of the work of parsers
* Add toolbox lib. Move levels to toolbox. Subghz switch to levels.
* Subghz: update worker signatures
* SubGhz: pluggable level duration implementations.
* SubGhz : test drawing pictures in Gui
* SubGhz: Added a callback with the parser structure as argument
* SubGhz: copy protocol data to model
* SubGhz: refactoing code
* SubGhz: cleanup and format sources
* SubGhz: remove comments

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
Skorpionm
2021-07-07 23:49:45 +04:00
committed by GitHub
parent a7283280ef
commit 4ce41a3e6f
21 changed files with 328 additions and 150 deletions

View File

@@ -11,6 +11,8 @@
#include <fl_subghz/subghz_worker.h>
#include <fl_subghz/protocols/subghz_protocol.h>
#include <assets_icons.h>
struct SubghzCapture {
View* view;
SubGhzWorker* worker;
@@ -22,6 +24,8 @@ typedef struct {
uint32_t real_frequency;
uint32_t counter;
string_t text;
uint16_t scene;
SubGhzProtocolCommon parser;
} SubghzCaptureModel;
static const char subghz_symbols[] = {'-', '\\', '|', '/'};
@@ -41,8 +45,22 @@ void subghz_capture_draw(Canvas* canvas, SubghzCaptureModel* model) {
subghz_symbols[model->counter % 4]);
canvas_draw_str(canvas, 0, 8, buffer);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text(canvas, 0, 20, string_get_cstr(model->text));
switch(model->scene) {
case 1:
canvas_draw_icon(canvas, 0, 10, &I_RFIDDolphinReceive_97x61);
canvas_invert_color(canvas);
canvas_draw_box(canvas, 80, 12, 20, 20);
canvas_invert_color(canvas);
canvas_draw_icon(canvas, 75, 18, &I_sub1_10px);
elements_multiline_text_aligned(
canvas, 90, 38, AlignCenter, AlignTop, "Detecting\r\nSubGhz");
break;
default:
canvas_set_font(canvas, FontSecondary);
elements_multiline_text(canvas, 0, 20, string_get_cstr(model->text));
break;
}
}
bool subghz_capture_input(InputEvent* event, void* context) {
@@ -87,6 +105,34 @@ void subghz_capture_text_callback(string_t text, void* context) {
subghz_capture->view, (SubghzCaptureModel * model) {
model->counter++;
string_set(model->text, text);
model->scene = 0;
return true;
});
}
void subghz_capture_protocol_callback(SubGhzProtocolCommon* parser, void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
char buffer[64];
snprintf(
buffer,
sizeof(buffer),
"%s\r\n"
"K:%lX%lX\r\n"
"SN:%lX\r\n"
"BTN:%X",
parser->name,
(uint32_t)(parser->code_found >> 32),
(uint32_t)(parser->code_found & 0x00000000FFFFFFFF),
parser->serial,
parser->btn);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
model->counter++;
model->parser = *parser;
string_set(model->text, buffer);
model->scene = 0;
return true;
});
}
@@ -104,6 +150,7 @@ void subghz_capture_enter(void* context) {
model->frequency = subghz_frequencies_433_92;
model->real_frequency =
api_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]);
model->scene = 1;
return true;
});
@@ -163,7 +210,7 @@ SubghzCapture* subghz_capture_alloc() {
subghz_protocol_load_keeloq_file(subghz_capture->protocol, "/assets/subghz/keeloq_mfcodes");
subghz_protocol_load_nice_flor_s_file(
subghz_capture->protocol, "/assets/subghz/nice_floor_s_rx");
subghz_protocol_enable_dump(
subghz_protocol_enable_dump_text(
subghz_capture->protocol, subghz_capture_text_callback, subghz_capture);
return subghz_capture;