flipperzero-firmware/applications/subghz/views/subghz_capture.c

239 lines
7.2 KiB
C
Raw Normal View History

#include "subghz_capture.h"
#include "../subghz_i.h"
#include <math.h>
#include <furi.h>
#include <api-hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <notification/notification-messages.h>
#include <lib/subghz/subghz_worker.h>
#include <lib/subghz/protocols/subghz_protocol.h>
#include <assets_icons.h>
struct SubghzCapture {
View* view;
SubGhzWorker* worker;
SubGhzProtocol* protocol;
};
typedef struct {
uint8_t frequency;
uint32_t real_frequency;
uint32_t counter;
string_t text;
uint16_t scene;
SubGhzProtocolCommon parser;
} SubghzCaptureModel;
static const char subghz_symbols[] = {'-', '\\', '|', '/'};
void subghz_capture_draw(Canvas* canvas, SubghzCaptureModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
snprintf(
buffer,
sizeof(buffer),
"Capture: %03ld.%03ldMHz %c",
model->real_frequency / 1000000 % 1000,
model->real_frequency / 1000 % 1000,
subghz_symbols[model->counter % 4]);
canvas_draw_str(canvas, 0, 8, buffer);
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) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
bool reconfigure = false;
if(event->type == InputTypeShort) {
if(event->key == InputKeyLeft) {
if(model->frequency > 0) model->frequency--;
reconfigure = true;
} else if(event->key == InputKeyRight) {
if(model->frequency < subghz_frequencies_count - 1) model->frequency++;
reconfigure = true;
}
}
if(reconfigure) {
api_hal_subghz_idle();
model->real_frequency =
api_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]);
api_hal_subghz_rx();
}
return reconfigure;
});
return true;
}
void subghz_capture_text_callback(string_t text, void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
with_view_model(
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;
});
}
void subghz_capture_enter(void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
api_hal_subghz_reset();
api_hal_subghz_idle();
api_hal_subghz_load_preset(ApiHalSubGhzPresetOokAsync);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
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;
});
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
api_hal_subghz_set_async_rx_callback(subghz_worker_rx_callback, subghz_capture->worker);
api_hal_subghz_start_async_rx();
subghz_worker_start(subghz_capture->worker);
api_hal_subghz_flush_rx();
api_hal_subghz_rx();
}
void subghz_capture_exit(void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
subghz_worker_stop(subghz_capture->worker);
api_hal_subghz_stop_async_rx();
api_hal_subghz_sleep();
}
uint32_t subghz_capture_back(void* context) {
return SubGhzViewMenu;
}
SubghzCapture* subghz_capture_alloc() {
SubghzCapture* subghz_capture = furi_alloc(sizeof(SubghzCapture));
// View allocation and configuration
subghz_capture->view = view_alloc();
view_allocate_model(subghz_capture->view, ViewModelTypeLocking, sizeof(SubghzCaptureModel));
view_set_context(subghz_capture->view, subghz_capture);
view_set_draw_callback(subghz_capture->view, (ViewDrawCallback)subghz_capture_draw);
view_set_input_callback(subghz_capture->view, subghz_capture_input);
view_set_enter_callback(subghz_capture->view, subghz_capture_enter);
view_set_exit_callback(subghz_capture->view, subghz_capture_exit);
view_set_previous_callback(subghz_capture->view, subghz_capture_back);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
string_init(model->text);
return true;
});
subghz_capture->worker = subghz_worker_alloc();
subghz_capture->protocol = subghz_protocol_alloc();
subghz_worker_set_overrun_callback(
subghz_capture->worker, (SubGhzWorkerOverrunCallback)subghz_protocol_reset);
subghz_worker_set_pair_callback(
subghz_capture->worker, (SubGhzWorkerPairCallback)subghz_protocol_parse);
subghz_worker_set_context(subghz_capture->worker, subghz_capture->protocol);
[FL-1191][FL-1524] Filesystem rework (#568) * FS-Api: removed datetime manipulation functions and most of the file flags * Filesystem: common proxy api * Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance. * Storage: sd mount and sd file open * Storage: sd file close * Storage: temporary test app * Storage: free filedata on close * Storage: sd file read and write * Storage: added internal storage (LittleFS) * Storage: renamed internal commands * Storage: seek, tell, truncate, size, sync, eof * Storage: error descriptions * Storage: directory management api (open, close, read, rewind) * Storage: common management api (stat, fs_stat, remove, rename, mkdir) * Dolphin app and Notifications app now use raw storage. * Storage: storage statuses renamed. Implemented sd card icon. * Storage: added raw sd-card api. * Storage settings: work started * Assets: use new icons approach * Storage settings: working storage settings * Storage: completely redesigned api, no longer sticking out FS_Api * Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file * Storage: cli info and format commands * Storage-cli: file list * Storage: a simpler and more reliable api * FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service. * Storage-cli: accommodate to the new cli api. * Storage: filesystem api is separated into internal and common api. * Cli: added the ability to print the list of free heap blocks * Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags. * Storage settings: added the ability to benchmark the SD card. * Gui module file select: uses new storage api * Apps: removed deprecated sd_card_test application * Args lib: support for enquoted arguments * Dialogs: a new gui app for simple non-asynchronous apps * Dialogs: view holder for easy single view work * File worker: use new storage api * IButton and lfrrfid apps: save keys to any storage * Apps: fix ibutton and lfrfid stack, remove sd_card_test. * SD filesystem: app removed * File worker: fixed api pointer type * Subghz: loading assets using the new storage api * NFC: use the new storage api * Dialogs: the better api for the message element * Archive: use new storage api * Irda: changed assest path, changed app path * FileWorker: removed unused file_buf_cnt * Storage: copying and renaming files now works between storages * Storage cli: read, copy, remove, rename commands * Archive: removed commented code * Storage cli: write command * Applications: add SRV_STORAGE and SRV_DIALOGS * Internal-storage: removed * Storage: improved api * Storage app: changed api pointer from StorageApp to Storage * Storage: better file_id handling * Storage: more consistent errors * Loader: support for NULL icons * Storage: do nothing with the lfs file or directory if it is not open * Storage: fix typo * Storage: minor float usage cleanup, rename some symbols. * Storage: compact doxygen comments. Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 12:20:19 +00:00
subghz_protocol_load_keeloq_file(
subghz_capture->protocol, "/ext/assets/subghz/keeloq_mfcodes");
subghz_protocol_load_nice_flor_s_file(
[FL-1191][FL-1524] Filesystem rework (#568) * FS-Api: removed datetime manipulation functions and most of the file flags * Filesystem: common proxy api * Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance. * Storage: sd mount and sd file open * Storage: sd file close * Storage: temporary test app * Storage: free filedata on close * Storage: sd file read and write * Storage: added internal storage (LittleFS) * Storage: renamed internal commands * Storage: seek, tell, truncate, size, sync, eof * Storage: error descriptions * Storage: directory management api (open, close, read, rewind) * Storage: common management api (stat, fs_stat, remove, rename, mkdir) * Dolphin app and Notifications app now use raw storage. * Storage: storage statuses renamed. Implemented sd card icon. * Storage: added raw sd-card api. * Storage settings: work started * Assets: use new icons approach * Storage settings: working storage settings * Storage: completely redesigned api, no longer sticking out FS_Api * Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file * Storage: cli info and format commands * Storage-cli: file list * Storage: a simpler and more reliable api * FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service. * Storage-cli: accommodate to the new cli api. * Storage: filesystem api is separated into internal and common api. * Cli: added the ability to print the list of free heap blocks * Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags. * Storage settings: added the ability to benchmark the SD card. * Gui module file select: uses new storage api * Apps: removed deprecated sd_card_test application * Args lib: support for enquoted arguments * Dialogs: a new gui app for simple non-asynchronous apps * Dialogs: view holder for easy single view work * File worker: use new storage api * IButton and lfrrfid apps: save keys to any storage * Apps: fix ibutton and lfrfid stack, remove sd_card_test. * SD filesystem: app removed * File worker: fixed api pointer type * Subghz: loading assets using the new storage api * NFC: use the new storage api * Dialogs: the better api for the message element * Archive: use new storage api * Irda: changed assest path, changed app path * FileWorker: removed unused file_buf_cnt * Storage: copying and renaming files now works between storages * Storage cli: read, copy, remove, rename commands * Archive: removed commented code * Storage cli: write command * Applications: add SRV_STORAGE and SRV_DIALOGS * Internal-storage: removed * Storage: improved api * Storage app: changed api pointer from StorageApp to Storage * Storage: better file_id handling * Storage: more consistent errors * Loader: support for NULL icons * Storage: do nothing with the lfs file or directory if it is not open * Storage: fix typo * Storage: minor float usage cleanup, rename some symbols. * Storage: compact doxygen comments. Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 12:20:19 +00:00
subghz_capture->protocol, "/ext/assets/subghz/nice_floor_s_rx");
subghz_protocol_enable_dump_text(
subghz_capture->protocol, subghz_capture_text_callback, subghz_capture);
return subghz_capture;
}
void subghz_capture_free(SubghzCapture* subghz_capture) {
furi_assert(subghz_capture);
subghz_protocol_free(subghz_capture->protocol);
subghz_worker_free(subghz_capture->worker);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
string_clear(model->text);
return true;
});
view_free(subghz_capture->view);
free(subghz_capture);
}
View* subghz_capture_get_view(SubghzCapture* subghz_capture) {
furi_assert(subghz_capture);
return subghz_capture->view;
}