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:
@@ -216,19 +216,16 @@ void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
|
||||
|
||||
volatile bool subghz_cli_overrun = false;
|
||||
|
||||
void subghz_cli_command_rx_callback(
|
||||
ApiHalSubGhzCaptureLevel level,
|
||||
uint32_t duration,
|
||||
void* context) {
|
||||
void subghz_cli_command_rx_callback(bool level, uint32_t duration, void* context) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
LevelPair pair = {.level = level, .duration = duration};
|
||||
LevelDuration level_duration = level_duration_make(level, duration);
|
||||
if(subghz_cli_overrun) {
|
||||
subghz_cli_overrun = false;
|
||||
pair.level = ApiHalSubGhzCaptureLevelOverrun;
|
||||
level_duration = level_duration_reset();
|
||||
}
|
||||
size_t ret =
|
||||
xStreamBufferSendFromISR(context, &pair, sizeof(LevelPair), &xHigherPriorityTaskWoken);
|
||||
if(sizeof(LevelPair) != ret) subghz_cli_overrun = true;
|
||||
size_t ret = xStreamBufferSendFromISR(
|
||||
context, &level_duration, sizeof(LevelDuration), &xHigherPriorityTaskWoken);
|
||||
if(sizeof(LevelDuration) != ret) subghz_cli_overrun = true;
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
@@ -257,13 +254,13 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
|
||||
SubGhzProtocol* protocol = subghz_protocol_alloc();
|
||||
subghz_protocol_load_keeloq_file(protocol, "/assets/subghz/keeloq_mfcodes");
|
||||
subghz_protocol_load_nice_flor_s_file(protocol, "/assets/subghz/nice_floor_s_rx");
|
||||
subghz_protocol_enable_dump(protocol, NULL, NULL);
|
||||
subghz_protocol_enable_dump_text(protocol, NULL, NULL);
|
||||
|
||||
frequency = api_hal_subghz_set_frequency_and_path(frequency);
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
StreamBufferHandle_t rx_stream =
|
||||
xStreamBufferCreate(sizeof(LevelPair) * 1024, sizeof(LevelPair));
|
||||
xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
|
||||
|
||||
api_hal_subghz_set_capture_callback(subghz_cli_command_rx_callback, rx_stream);
|
||||
api_hal_subghz_enable_capture();
|
||||
@@ -272,15 +269,17 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
|
||||
api_hal_subghz_rx();
|
||||
|
||||
printf("Listening at %lu. Press CTRL+C to stop\r\n", frequency);
|
||||
LevelPair pair;
|
||||
LevelDuration level_duration;
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
int ret = xStreamBufferReceive(rx_stream, &pair, sizeof(LevelPair), 10);
|
||||
if(ret == sizeof(LevelPair)) {
|
||||
if(pair.level == ApiHalSubGhzCaptureLevelOverrun) {
|
||||
int ret = xStreamBufferReceive(rx_stream, &level_duration, sizeof(LevelDuration), 10);
|
||||
if(ret == sizeof(LevelDuration)) {
|
||||
if(level_duration_is_reset(level_duration)) {
|
||||
printf(".");
|
||||
subghz_protocol_reset(protocol);
|
||||
} else {
|
||||
subghz_protocol_parse(protocol, pair);
|
||||
bool level = level_duration_get_level(level_duration);
|
||||
uint32_t duration = level_duration_get_duration(level_duration);
|
||||
subghz_protocol_parse(protocol, level, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user