Merge remote-tracking branch 'origin/release-candidate' into release
This commit is contained in:
commit
3991db4b36
5
.github/workflows/unit_tests.yml
vendored
5
.github/workflows/unit_tests.yml
vendored
@ -29,12 +29,14 @@ jobs:
|
||||
- name: 'Flash unit tests firmware'
|
||||
id: flashing
|
||||
if: success()
|
||||
timeout-minutes: 10
|
||||
run: |
|
||||
./fbt flash OPENOCD_ADAPTER_SERIAL=2A0906016415303030303032 FIRMWARE_APP_SET=unit_tests FORCE=1
|
||||
|
||||
- name: 'Wait for flipper and format ext'
|
||||
id: format_ext
|
||||
if: steps.flashing.outcome == 'success'
|
||||
timeout-minutes: 5
|
||||
run: |
|
||||
source scripts/toolchain/fbtenv.sh
|
||||
python3 scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}}
|
||||
@ -43,6 +45,7 @@ jobs:
|
||||
- name: 'Copy assets and unit data, reboot and wait for flipper'
|
||||
id: copy
|
||||
if: steps.format_ext.outcome == 'success'
|
||||
timeout-minutes: 5
|
||||
run: |
|
||||
source scripts/toolchain/fbtenv.sh
|
||||
python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} -f send assets/resources /ext
|
||||
@ -53,7 +56,7 @@ jobs:
|
||||
- name: 'Run units and validate results'
|
||||
id: run_units
|
||||
if: steps.copy.outcome == 'success'
|
||||
timeout-minutes: 2.5
|
||||
timeout-minutes: 7
|
||||
run: |
|
||||
source scripts/toolchain/fbtenv.sh
|
||||
python3 scripts/testing/units.py ${{steps.device.outputs.flipper}}
|
||||
|
||||
2
.github/workflows/updater_test.yml
vendored
2
.github/workflows/updater_test.yml
vendored
@ -30,6 +30,7 @@ jobs:
|
||||
|
||||
- name: 'Flashing target firmware'
|
||||
id: first_full_flash
|
||||
timeout-minutes: 10
|
||||
run: |
|
||||
source scripts/toolchain/fbtenv.sh
|
||||
./fbt flash_usb_full PORT=${{steps.device.outputs.flipper}} FORCE=1
|
||||
@ -37,6 +38,7 @@ jobs:
|
||||
|
||||
- name: 'Validating updater'
|
||||
id: second_full_flash
|
||||
timeout-minutes: 10
|
||||
if: success()
|
||||
run: |
|
||||
source scripts/toolchain/fbtenv.sh
|
||||
|
||||
@ -48,7 +48,7 @@ Almost everything in flipper firmware is built around this concept.
|
||||
# C coding style
|
||||
|
||||
- Tab is 4 spaces
|
||||
- Use `fbt format` to reformat source code and check style guide before commit
|
||||
- Use `./fbt format` to reformat source code and check style guide before commit
|
||||
|
||||
## Naming
|
||||
|
||||
|
||||
@ -26,7 +26,6 @@ Applications for main Flipper menu.
|
||||
|
||||
- `archive` - Archive and file manager
|
||||
- `bad_usb` - Bad USB application
|
||||
- `fap_loader` - External applications loader
|
||||
- `gpio` - GPIO application: includes USART bridge and GPIO control
|
||||
- `ibutton` - iButton application, onewire keys and more
|
||||
- `infrared` - Infrared application, controls your IR devices
|
||||
|
||||
@ -12,5 +12,6 @@ App(
|
||||
"display_test",
|
||||
"text_box_test",
|
||||
"file_browser_test",
|
||||
"speaker_debug",
|
||||
],
|
||||
)
|
||||
|
||||
10
applications/debug/crash_test/application.fam
Normal file
10
applications/debug/crash_test/application.fam
Normal file
@ -0,0 +1,10 @@
|
||||
App(
|
||||
appid="crash_test",
|
||||
name="Crash Test",
|
||||
apptype=FlipperAppType.DEBUG,
|
||||
entry_point="crash_test_app",
|
||||
cdefines=["APP_CRASH_TEST"],
|
||||
requires=["gui"],
|
||||
stack_size=1 * 1024,
|
||||
fap_category="Debug",
|
||||
)
|
||||
128
applications/debug/crash_test/crash_test.c
Normal file
128
applications/debug/crash_test/crash_test.c
Normal file
@ -0,0 +1,128 @@
|
||||
#include <furi_hal.h>
|
||||
#include <furi.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
|
||||
#define TAG "CrashTest"
|
||||
|
||||
typedef struct {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
Submenu* submenu;
|
||||
} CrashTest;
|
||||
|
||||
typedef enum {
|
||||
CrashTestViewSubmenu,
|
||||
} CrashTestView;
|
||||
|
||||
typedef enum {
|
||||
CrashTestSubmenuCheck,
|
||||
CrashTestSubmenuCheckMessage,
|
||||
CrashTestSubmenuAssert,
|
||||
CrashTestSubmenuAssertMessage,
|
||||
CrashTestSubmenuCrash,
|
||||
CrashTestSubmenuHalt,
|
||||
} CrashTestSubmenu;
|
||||
|
||||
static void crash_test_submenu_callback(void* context, uint32_t index) {
|
||||
CrashTest* instance = (CrashTest*)context;
|
||||
UNUSED(instance);
|
||||
|
||||
switch(index) {
|
||||
case CrashTestSubmenuCheck:
|
||||
furi_check(false);
|
||||
break;
|
||||
case CrashTestSubmenuCheckMessage:
|
||||
furi_check(false, "Crash test: furi_check with message");
|
||||
break;
|
||||
case CrashTestSubmenuAssert:
|
||||
furi_assert(false);
|
||||
break;
|
||||
case CrashTestSubmenuAssertMessage:
|
||||
furi_assert(false, "Crash test: furi_assert with message");
|
||||
break;
|
||||
case CrashTestSubmenuCrash:
|
||||
furi_crash("Crash test: furi_crash");
|
||||
break;
|
||||
case CrashTestSubmenuHalt:
|
||||
furi_halt("Crash test: furi_halt");
|
||||
break;
|
||||
default:
|
||||
furi_crash("Programming error");
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t crash_test_exit_callback(void* context) {
|
||||
UNUSED(context);
|
||||
return VIEW_NONE;
|
||||
}
|
||||
|
||||
CrashTest* crash_test_alloc() {
|
||||
CrashTest* instance = malloc(sizeof(CrashTest));
|
||||
|
||||
View* view = NULL;
|
||||
|
||||
instance->gui = furi_record_open(RECORD_GUI);
|
||||
instance->view_dispatcher = view_dispatcher_alloc();
|
||||
view_dispatcher_enable_queue(instance->view_dispatcher);
|
||||
view_dispatcher_attach_to_gui(
|
||||
instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
// Menu
|
||||
instance->submenu = submenu_alloc();
|
||||
view = submenu_get_view(instance->submenu);
|
||||
view_set_previous_callback(view, crash_test_exit_callback);
|
||||
view_dispatcher_add_view(instance->view_dispatcher, CrashTestViewSubmenu, view);
|
||||
submenu_add_item(
|
||||
instance->submenu, "Check", CrashTestSubmenuCheck, crash_test_submenu_callback, instance);
|
||||
submenu_add_item(
|
||||
instance->submenu,
|
||||
"Check with message",
|
||||
CrashTestSubmenuCheckMessage,
|
||||
crash_test_submenu_callback,
|
||||
instance);
|
||||
submenu_add_item(
|
||||
instance->submenu, "Assert", CrashTestSubmenuAssert, crash_test_submenu_callback, instance);
|
||||
submenu_add_item(
|
||||
instance->submenu,
|
||||
"Assert with message",
|
||||
CrashTestSubmenuAssertMessage,
|
||||
crash_test_submenu_callback,
|
||||
instance);
|
||||
submenu_add_item(
|
||||
instance->submenu, "Crash", CrashTestSubmenuCrash, crash_test_submenu_callback, instance);
|
||||
submenu_add_item(
|
||||
instance->submenu, "Halt", CrashTestSubmenuHalt, crash_test_submenu_callback, instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void crash_test_free(CrashTest* instance) {
|
||||
view_dispatcher_remove_view(instance->view_dispatcher, CrashTestViewSubmenu);
|
||||
submenu_free(instance->submenu);
|
||||
|
||||
view_dispatcher_free(instance->view_dispatcher);
|
||||
furi_record_close(RECORD_GUI);
|
||||
|
||||
free(instance);
|
||||
}
|
||||
|
||||
int32_t crash_test_run(CrashTest* instance) {
|
||||
view_dispatcher_switch_to_view(instance->view_dispatcher, CrashTestViewSubmenu);
|
||||
view_dispatcher_run(instance->view_dispatcher);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t crash_test_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
CrashTest* instance = crash_test_alloc();
|
||||
|
||||
int32_t ret = crash_test_run(instance);
|
||||
|
||||
crash_test_free(instance);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -6,6 +6,11 @@ static void comparator_trigger_callback(bool level, void* comp_ctx) {
|
||||
furi_hal_gpio_write(&gpio_ext_pa7, !level);
|
||||
}
|
||||
|
||||
void lfrfid_debug_view_tune_callback(void* context) {
|
||||
LfRfidDebug* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, 0xBA);
|
||||
}
|
||||
|
||||
void lfrfid_debug_scene_tune_on_enter(void* context) {
|
||||
LfRfidDebug* app = context;
|
||||
|
||||
@ -16,6 +21,8 @@ void lfrfid_debug_scene_tune_on_enter(void* context) {
|
||||
|
||||
furi_hal_rfid_tim_read_start(125000, 0.5);
|
||||
|
||||
lfrfid_debug_view_tune_set_callback(app->tune_view, lfrfid_debug_view_tune_callback, app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidDebugViewTune);
|
||||
}
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@ typedef struct {
|
||||
uint32_t ARR;
|
||||
uint32_t CCR;
|
||||
int pos;
|
||||
void (*update_callback)(void* context);
|
||||
void* update_context;
|
||||
} LfRfidTuneViewModel;
|
||||
|
||||
static void lfrfid_debug_view_tune_draw_callback(Canvas* canvas, void* _model) {
|
||||
@ -151,6 +153,18 @@ static bool lfrfid_debug_view_tune_input_callback(InputEvent* event, void* conte
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(event->key == InputKeyLeft || event->key == InputKeyRight) {
|
||||
with_view_model(
|
||||
tune_view->view,
|
||||
LfRfidTuneViewModel * model,
|
||||
{
|
||||
if(model->update_callback) {
|
||||
model->update_callback(model->update_context);
|
||||
}
|
||||
},
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
@ -161,19 +175,7 @@ LfRfidTuneView* lfrfid_debug_view_tune_alloc() {
|
||||
tune_view->view = view_alloc();
|
||||
view_set_context(tune_view->view, tune_view);
|
||||
view_allocate_model(tune_view->view, ViewModelTypeLocking, sizeof(LfRfidTuneViewModel));
|
||||
|
||||
with_view_model(
|
||||
tune_view->view,
|
||||
LfRfidTuneViewModel * model,
|
||||
{
|
||||
model->dirty = true;
|
||||
model->fine = false;
|
||||
model->ARR = 511;
|
||||
model->CCR = 255;
|
||||
model->pos = 0;
|
||||
},
|
||||
true);
|
||||
|
||||
lfrfid_debug_view_tune_clean(tune_view);
|
||||
view_set_draw_callback(tune_view->view, lfrfid_debug_view_tune_draw_callback);
|
||||
view_set_input_callback(tune_view->view, lfrfid_debug_view_tune_input_callback);
|
||||
|
||||
@ -199,6 +201,8 @@ void lfrfid_debug_view_tune_clean(LfRfidTuneView* tune_view) {
|
||||
model->ARR = 511;
|
||||
model->CCR = 255;
|
||||
model->pos = 0;
|
||||
model->update_callback = NULL;
|
||||
model->update_context = NULL;
|
||||
},
|
||||
true);
|
||||
}
|
||||
@ -232,3 +236,17 @@ uint32_t lfrfid_debug_view_tune_get_ccr(LfRfidTuneView* tune_view) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void lfrfid_debug_view_tune_set_callback(
|
||||
LfRfidTuneView* tune_view,
|
||||
void (*callback)(void* context),
|
||||
void* context) {
|
||||
with_view_model(
|
||||
tune_view->view,
|
||||
LfRfidTuneViewModel * model,
|
||||
{
|
||||
model->update_callback = callback;
|
||||
model->update_context = context;
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
@ -16,3 +16,8 @@ bool lfrfid_debug_view_tune_is_dirty(LfRfidTuneView* tune_view);
|
||||
uint32_t lfrfid_debug_view_tune_get_arr(LfRfidTuneView* tune_view);
|
||||
|
||||
uint32_t lfrfid_debug_view_tune_get_ccr(LfRfidTuneView* tune_view);
|
||||
|
||||
void lfrfid_debug_view_tune_set_callback(
|
||||
LfRfidTuneView* tune_view,
|
||||
void (*callback)(void* context),
|
||||
void* context);
|
||||
|
||||
11
applications/debug/speaker_debug/application.fam
Normal file
11
applications/debug/speaker_debug/application.fam
Normal file
@ -0,0 +1,11 @@
|
||||
App(
|
||||
appid="speaker_debug",
|
||||
name="Speaker Debug",
|
||||
apptype=FlipperAppType.DEBUG,
|
||||
entry_point="speaker_debug_app",
|
||||
requires=["gui", "notification"],
|
||||
stack_size=2 * 1024,
|
||||
order=10,
|
||||
fap_category="Debug",
|
||||
fap_libs=["music_worker"],
|
||||
)
|
||||
120
applications/debug/speaker_debug/speaker_debug.c
Normal file
120
applications/debug/speaker_debug/speaker_debug.c
Normal file
@ -0,0 +1,120 @@
|
||||
#include <furi.h>
|
||||
#include <notification/notification.h>
|
||||
#include <music_worker/music_worker.h>
|
||||
#include <cli/cli.h>
|
||||
#include <toolbox/args.h>
|
||||
|
||||
#define TAG "SpeakerDebug"
|
||||
#define CLI_COMMAND "speaker_debug"
|
||||
|
||||
typedef enum {
|
||||
SpeakerDebugAppMessageTypeStop,
|
||||
} SpeakerDebugAppMessageType;
|
||||
|
||||
typedef struct {
|
||||
SpeakerDebugAppMessageType type;
|
||||
} SpeakerDebugAppMessage;
|
||||
|
||||
typedef struct {
|
||||
MusicWorker* music_worker;
|
||||
FuriMessageQueue* message_queue;
|
||||
Cli* cli;
|
||||
} SpeakerDebugApp;
|
||||
|
||||
static SpeakerDebugApp* speaker_app_alloc() {
|
||||
SpeakerDebugApp* app = (SpeakerDebugApp*)malloc(sizeof(SpeakerDebugApp));
|
||||
app->music_worker = music_worker_alloc();
|
||||
app->message_queue = furi_message_queue_alloc(8, sizeof(SpeakerDebugAppMessage));
|
||||
app->cli = furi_record_open(RECORD_CLI);
|
||||
return app;
|
||||
}
|
||||
|
||||
static void speaker_app_free(SpeakerDebugApp* app) {
|
||||
music_worker_free(app->music_worker);
|
||||
furi_message_queue_free(app->message_queue);
|
||||
furi_record_close(RECORD_CLI);
|
||||
free(app);
|
||||
}
|
||||
|
||||
static void speaker_app_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(cli);
|
||||
|
||||
SpeakerDebugApp* app = (SpeakerDebugApp*)context;
|
||||
SpeakerDebugAppMessage message;
|
||||
FuriString* cmd = furi_string_alloc();
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
furi_string_free(cmd);
|
||||
printf("Usage:\r\n");
|
||||
printf("\t" CLI_COMMAND " stop\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(furi_string_cmp(cmd, "stop") == 0) {
|
||||
message.type = SpeakerDebugAppMessageTypeStop;
|
||||
FuriStatus status = furi_message_queue_put(app->message_queue, &message, 100);
|
||||
if(status != FuriStatusOk) {
|
||||
printf("Failed to send message\r\n");
|
||||
} else {
|
||||
printf("Stopping\r\n");
|
||||
}
|
||||
} else {
|
||||
printf("Usage:\r\n");
|
||||
printf("\t" CLI_COMMAND " stop\r\n");
|
||||
}
|
||||
|
||||
furi_string_free(cmd);
|
||||
}
|
||||
|
||||
static bool speaker_app_music_play(SpeakerDebugApp* app, const char* rtttl) {
|
||||
if(music_worker_is_playing(app->music_worker)) {
|
||||
music_worker_stop(app->music_worker);
|
||||
}
|
||||
|
||||
if(!music_worker_load_rtttl_from_string(app->music_worker, rtttl)) {
|
||||
FURI_LOG_E(TAG, "Failed to load RTTTL");
|
||||
return false;
|
||||
}
|
||||
|
||||
music_worker_set_volume(app->music_worker, 1.0f);
|
||||
music_worker_start(app->music_worker);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void speaker_app_music_stop(SpeakerDebugApp* app) {
|
||||
if(music_worker_is_playing(app->music_worker)) {
|
||||
music_worker_stop(app->music_worker);
|
||||
}
|
||||
}
|
||||
|
||||
static void speaker_app_run(SpeakerDebugApp* app, const char* arg) {
|
||||
if(!arg || !speaker_app_music_play(app, arg)) {
|
||||
FURI_LOG_E(TAG, "Provided RTTTL is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
cli_add_command(app->cli, CLI_COMMAND, CliCommandFlagParallelSafe, speaker_app_cli, app);
|
||||
|
||||
SpeakerDebugAppMessage message;
|
||||
FuriStatus status;
|
||||
while(true) {
|
||||
status = furi_message_queue_get(app->message_queue, &message, FuriWaitForever);
|
||||
|
||||
if(status == FuriStatusOk) {
|
||||
if(message.type == SpeakerDebugAppMessageTypeStop) {
|
||||
speaker_app_music_stop(app);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cli_delete_command(app->cli, CLI_COMMAND);
|
||||
}
|
||||
|
||||
int32_t speaker_debug_app(void* arg) {
|
||||
SpeakerDebugApp* app = speaker_app_alloc();
|
||||
speaker_app_run(app, arg);
|
||||
speaker_app_free(app);
|
||||
return 0;
|
||||
}
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
#define LINES_ON_SCREEN 6
|
||||
#define COLUMNS_ON_SCREEN 21
|
||||
#define TAG "UartEcho"
|
||||
#define DEFAULT_BAUD_RATE 230400
|
||||
|
||||
typedef struct UartDumpModel UartDumpModel;
|
||||
|
||||
@ -179,7 +181,7 @@ static int32_t uart_echo_worker(void* context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static UartEchoApp* uart_echo_app_alloc() {
|
||||
static UartEchoApp* uart_echo_app_alloc(uint32_t baudrate) {
|
||||
UartEchoApp* app = malloc(sizeof(UartEchoApp));
|
||||
|
||||
app->rx_stream = furi_stream_buffer_alloc(2048, 1);
|
||||
@ -220,7 +222,7 @@ static UartEchoApp* uart_echo_app_alloc() {
|
||||
|
||||
// Enable uart listener
|
||||
furi_hal_console_disable();
|
||||
furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200);
|
||||
furi_hal_uart_set_br(FuriHalUartIdUSART1, baudrate);
|
||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, uart_echo_on_irq_cb, app);
|
||||
|
||||
return app;
|
||||
@ -263,8 +265,18 @@ static void uart_echo_app_free(UartEchoApp* app) {
|
||||
}
|
||||
|
||||
int32_t uart_echo_app(void* p) {
|
||||
UNUSED(p);
|
||||
UartEchoApp* app = uart_echo_app_alloc();
|
||||
uint32_t baudrate = DEFAULT_BAUD_RATE;
|
||||
if(p) {
|
||||
const char* baudrate_str = p;
|
||||
if(sscanf(baudrate_str, "%lu", &baudrate) != 1) {
|
||||
FURI_LOG_E(TAG, "Invalid baudrate: %s", baudrate_str);
|
||||
baudrate = DEFAULT_BAUD_RATE;
|
||||
}
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Using baudrate: %lu", baudrate);
|
||||
|
||||
UartEchoApp* app = uart_echo_app_alloc(baudrate);
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
uart_echo_app_free(app);
|
||||
return 0;
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
#include <dialogs/dialogs.h>
|
||||
|
||||
#include "../minunit.h"
|
||||
|
||||
MU_TEST(test_dialog_file_browser_set_basic_options_should_init_all_fields) {
|
||||
mu_assert(
|
||||
sizeof(DialogsFileBrowserOptions) == 28,
|
||||
"Changes to `DialogsFileBrowserOptions` should also be reflected in `dialog_file_browser_set_basic_options`");
|
||||
|
||||
DialogsFileBrowserOptions options;
|
||||
dialog_file_browser_set_basic_options(&options, ".fap", NULL);
|
||||
// note: this assertions can safely be changed, their primary purpose is to remind the maintainer
|
||||
// to update `dialog_file_browser_set_basic_options` by including all structure fields in it
|
||||
mu_assert_string_eq(".fap", options.extension);
|
||||
mu_assert_null(options.base_path);
|
||||
mu_assert(options.skip_assets, "`skip_assets` should default to `true");
|
||||
mu_assert(options.hide_dot_files, "`hide_dot_files` should default to `true");
|
||||
mu_assert_null(options.icon);
|
||||
mu_assert(options.hide_ext, "`hide_ext` should default to `true");
|
||||
mu_assert_null(options.item_loader_callback);
|
||||
mu_assert_null(options.item_loader_context);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(dialogs_file_browser_options) {
|
||||
MU_RUN_TEST(test_dialog_file_browser_set_basic_options_should_init_all_fields);
|
||||
}
|
||||
|
||||
int run_minunit_test_dialogs_file_browser_options() {
|
||||
MU_RUN_SUITE(dialogs_file_browser_options);
|
||||
|
||||
return MU_EXIT_CODE;
|
||||
}
|
||||
@ -7,6 +7,8 @@
|
||||
#include <lib/subghz/subghz_file_encoder_worker.h>
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#define TAG "SubGhz TEST"
|
||||
#define KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes")
|
||||
@ -49,12 +51,15 @@ static void subghz_test_init(void) {
|
||||
subghz_environment_set_protocol_registry(
|
||||
environment_handler, (void*)&subghz_protocol_registry);
|
||||
|
||||
subghz_devices_init();
|
||||
|
||||
receiver_handler = subghz_receiver_alloc_init(environment_handler);
|
||||
subghz_receiver_set_filter(receiver_handler, SubGhzProtocolFlag_Decodable);
|
||||
subghz_receiver_set_rx_callback(receiver_handler, subghz_test_rx_callback, NULL);
|
||||
}
|
||||
|
||||
static void subghz_test_deinit(void) {
|
||||
subghz_devices_deinit();
|
||||
subghz_receiver_free(receiver_handler);
|
||||
subghz_environment_free(environment_handler);
|
||||
}
|
||||
@ -68,7 +73,7 @@ static bool subghz_decoder_test(const char* path, const char* name_decoder) {
|
||||
|
||||
if(decoder) {
|
||||
file_worker_encoder_handler = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path)) {
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path, NULL)) {
|
||||
// the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
|
||||
@ -108,7 +113,7 @@ static bool subghz_decode_random_test(const char* path) {
|
||||
uint32_t test_start = furi_get_tick();
|
||||
|
||||
file_worker_encoder_handler = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path)) {
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path, NULL)) {
|
||||
// the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
|
||||
@ -318,7 +323,7 @@ bool subghz_hal_async_tx_test_run(SubGhzHalAsyncTxTestType type) {
|
||||
SubGhzHalAsyncTxTest test = {0};
|
||||
test.type = type;
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
furi_hal_subghz_set_frequency_and_path(433920000);
|
||||
|
||||
if(!furi_hal_subghz_start_async_tx(subghz_hal_async_tx_test_yield, &test)) {
|
||||
|
||||
@ -27,6 +27,7 @@ int run_minunit_test_nfc();
|
||||
int run_minunit_test_bit_lib();
|
||||
int run_minunit_test_float_tools();
|
||||
int run_minunit_test_bt();
|
||||
int run_minunit_test_dialogs_file_browser_options();
|
||||
|
||||
typedef int (*UnitTestEntry)();
|
||||
|
||||
@ -55,6 +56,8 @@ const UnitTest unit_tests[] = {
|
||||
{.name = "bit_lib", .entry = run_minunit_test_bit_lib},
|
||||
{.name = "float_tools", .entry = run_minunit_test_float_tools},
|
||||
{.name = "bt", .entry = run_minunit_test_bt},
|
||||
{.name = "dialogs_file_browser_options",
|
||||
.entry = run_minunit_test_dialogs_file_browser_options},
|
||||
};
|
||||
|
||||
void minunit_print_progress() {
|
||||
|
||||
6
applications/drivers/application.fam
Normal file
6
applications/drivers/application.fam
Normal file
@ -0,0 +1,6 @@
|
||||
# Placeholder
|
||||
App(
|
||||
appid="drivers",
|
||||
name="Drivers device",
|
||||
apptype=FlipperAppType.METAPACKAGE,
|
||||
)
|
||||
8
applications/drivers/subghz/application.fam
Normal file
8
applications/drivers/subghz/application.fam
Normal file
@ -0,0 +1,8 @@
|
||||
App(
|
||||
appid="radio_device_cc1101_ext",
|
||||
apptype=FlipperAppType.PLUGIN,
|
||||
targets=["f7"],
|
||||
entry_point="subghz_device_cc1101_ext_ep",
|
||||
requires=["subghz"],
|
||||
fap_libs=["hwdrivers"],
|
||||
)
|
||||
765
applications/drivers/subghz/cc1101_ext/cc1101_ext.c
Normal file
765
applications/drivers/subghz/cc1101_ext/cc1101_ext.c
Normal file
@ -0,0 +1,765 @@
|
||||
#include "cc1101_ext.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <furi_hal_region.h>
|
||||
#include <furi_hal_version.h>
|
||||
#include <furi_hal_rtc.h>
|
||||
#include <furi_hal_spi.h>
|
||||
#include <furi_hal_interrupt.h>
|
||||
#include <furi_hal_resources.h>
|
||||
#include <furi_hal_bus.h>
|
||||
|
||||
#include <stm32wbxx_ll_dma.h>
|
||||
#include <furi_hal_cortex.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <cc1101.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define TAG "SubGhz_Device_CC1101_Ext"
|
||||
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2
|
||||
|
||||
/* DMA Channels definition */
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL LL_DMA_CHANNEL_3
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_CHANNEL LL_DMA_CHANNEL_4
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_CHANNEL LL_DMA_CHANNEL_5
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ FuriHalInterruptIdDma2Ch3
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF \
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF \
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_CHANNEL
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF \
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_CHANNEL
|
||||
|
||||
/** Low level buffer dimensions and guard times */
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL (256)
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF \
|
||||
(SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL / 2)
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME 999
|
||||
|
||||
/** SubGhz state */
|
||||
typedef enum {
|
||||
SubGhzDeviceCC1101ExtStateInit, /**< Init pending */
|
||||
SubGhzDeviceCC1101ExtStateIdle, /**< Idle, energy save mode */
|
||||
SubGhzDeviceCC1101ExtStateAsyncRx, /**< Async RX started */
|
||||
SubGhzDeviceCC1101ExtStateAsyncTx, /**< Async TX started, DMA and timer is on */
|
||||
SubGhzDeviceCC1101ExtStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
|
||||
} SubGhzDeviceCC1101ExtState;
|
||||
|
||||
/** SubGhz regulation, receive transmission on the current frequency for the
|
||||
* region */
|
||||
typedef enum {
|
||||
SubGhzDeviceCC1101ExtRegulationOnlyRx, /**only Rx*/
|
||||
SubGhzDeviceCC1101ExtRegulationTxRx, /**TxRx*/
|
||||
} SubGhzDeviceCC1101ExtRegulation;
|
||||
|
||||
typedef struct {
|
||||
uint32_t* buffer;
|
||||
LevelDuration carry_ld;
|
||||
SubGhzDeviceCC1101ExtCallback callback;
|
||||
void* callback_context;
|
||||
uint32_t gpio_tx_buff[2];
|
||||
uint32_t debug_gpio_buff[2];
|
||||
} SubGhzDeviceCC1101ExtAsyncTx;
|
||||
|
||||
typedef struct {
|
||||
uint32_t capture_delta_duration;
|
||||
SubGhzDeviceCC1101ExtCaptureCallback capture_callback;
|
||||
void* capture_callback_context;
|
||||
} SubGhzDeviceCC1101ExtAsyncRx;
|
||||
|
||||
typedef struct {
|
||||
volatile SubGhzDeviceCC1101ExtState state;
|
||||
volatile SubGhzDeviceCC1101ExtRegulation regulation;
|
||||
const GpioPin* async_mirror_pin;
|
||||
FuriHalSpiBusHandle* spi_bus_handle;
|
||||
const GpioPin* g0_pin;
|
||||
SubGhzDeviceCC1101ExtAsyncTx async_tx;
|
||||
SubGhzDeviceCC1101ExtAsyncRx async_rx;
|
||||
} SubGhzDeviceCC1101Ext;
|
||||
|
||||
static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL;
|
||||
|
||||
static bool subghz_device_cc1101_ext_check_init() {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateInit);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
|
||||
|
||||
bool ret = false;
|
||||
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
FuriHalCortexTimer timer = furi_hal_cortex_timer_get(100 * 1000);
|
||||
do {
|
||||
// Reset
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
|
||||
// Prepare GD0 for power on self test
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// GD0 low
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
while(furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin) != false) {
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
break;
|
||||
}
|
||||
|
||||
// GD0 high
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle,
|
||||
CC1101_IOCFG0,
|
||||
CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
while(furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin) != true) {
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
break;
|
||||
}
|
||||
|
||||
// Reset GD0 to floating state
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// RF switches
|
||||
furi_hal_gpio_init(&gpio_rf_sw_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
|
||||
// Go to sleep
|
||||
cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
ret = true;
|
||||
} while(false);
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
if(ret) {
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Init failed");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_alloc() {
|
||||
furi_assert(subghz_device_cc1101_ext == NULL);
|
||||
subghz_device_cc1101_ext = malloc(sizeof(SubGhzDeviceCC1101Ext));
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateInit;
|
||||
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
|
||||
subghz_device_cc1101_ext->async_mirror_pin = NULL;
|
||||
subghz_device_cc1101_ext->spi_bus_handle = &furi_hal_spi_bus_handle_external;
|
||||
subghz_device_cc1101_ext->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO;
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
|
||||
|
||||
furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
return subghz_device_cc1101_ext_check_init();
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_free() {
|
||||
furi_assert(subghz_device_cc1101_ext != NULL);
|
||||
furi_hal_spi_bus_handle_deinit(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
free(subghz_device_cc1101_ext);
|
||||
subghz_device_cc1101_ext = NULL;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_set_async_mirror_pin(const GpioPin* pin) {
|
||||
subghz_device_cc1101_ext->async_mirror_pin = pin;
|
||||
}
|
||||
|
||||
const GpioPin* subghz_device_cc1101_ext_get_data_gpio() {
|
||||
return subghz_device_cc1101_ext->g0_pin;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_connect() {
|
||||
bool ret = false;
|
||||
|
||||
if(subghz_device_cc1101_ext == NULL) { // not initialized
|
||||
ret = subghz_device_cc1101_ext_alloc();
|
||||
subghz_device_cc1101_ext_free();
|
||||
} else { // initialized
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint8_t partnumber = cc1101_get_partnumber(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
ret = (partnumber != 0) && (partnumber != 0xFF);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_sleep() {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_dump_state() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
printf(
|
||||
"[subghz_device_cc1101_ext] cc1101 chip %d, version %d\r\n",
|
||||
cc1101_get_partnumber(subghz_device_cc1101_ext->spi_bus_handle),
|
||||
cc1101_get_version(subghz_device_cc1101_ext->spi_bus_handle));
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_load_custom_preset(const uint8_t* preset_data) {
|
||||
//load config
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint32_t i = 0;
|
||||
uint8_t pa[8] = {0};
|
||||
while(preset_data[i]) {
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, preset_data[i], preset_data[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
//load pa table
|
||||
memcpy(&pa[0], &preset_data[i + 2], 8);
|
||||
subghz_device_cc1101_ext_load_patable(pa);
|
||||
|
||||
//show debug
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
i = 0;
|
||||
FURI_LOG_D(TAG, "Loading custom preset");
|
||||
while(preset_data[i]) {
|
||||
FURI_LOG_D(TAG, "Reg[%lu]: %02X=%02X", i, preset_data[i], preset_data[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
for(uint8_t y = i; y < i + 10; y++) {
|
||||
FURI_LOG_D(TAG, "PA[%u]: %02X", y, preset_data[y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_load_registers(const uint8_t* data) {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint32_t i = 0;
|
||||
while(data[i]) {
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, data[i], data[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_load_patable(const uint8_t data[8]) {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_set_pa_table(subghz_device_cc1101_ext->spi_bus_handle, data);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_write_packet(const uint8_t* data, uint8_t size) {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_flush_tx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_FIFO, size);
|
||||
cc1101_write_fifo(subghz_device_cc1101_ext->spi_bus_handle, data, size);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_flush_rx() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_flush_rx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_flush_tx() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_flush_tx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_rx_pipe_not_empty() {
|
||||
CC1101RxBytes status[1];
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_read_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle,
|
||||
(CC1101_STATUS_RXBYTES) | CC1101_BURST,
|
||||
(uint8_t*)status);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
// TODO: you can add a buffer overflow flag if needed
|
||||
if(status->NUM_RXBYTES > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_rx_data_crc_valid() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint8_t data[1];
|
||||
cc1101_read_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(((data[0] >> 7) & 0x01)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_read_packet(uint8_t* data, uint8_t* size) {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_read_fifo(subghz_device_cc1101_ext->spi_bus_handle, data, size);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_shutdown() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
// Reset and shutdown
|
||||
cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_reset() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_idle() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_rx() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_switch_to_rx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_tx() {
|
||||
if(subghz_device_cc1101_ext->regulation != SubGhzDeviceCC1101ExtRegulationTxRx) return false;
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_switch_to_tx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
float subghz_device_cc1101_ext_get_rssi() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
int32_t rssi_dec = cc1101_get_rssi(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
float rssi = rssi_dec;
|
||||
if(rssi_dec >= 128) {
|
||||
rssi = ((rssi - 256.0f) / 2.0f) - 74.0f;
|
||||
} else {
|
||||
rssi = (rssi / 2.0f) - 74.0f;
|
||||
}
|
||||
|
||||
return rssi;
|
||||
}
|
||||
|
||||
uint8_t subghz_device_cc1101_ext_get_lqi() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint8_t data[1];
|
||||
cc1101_read_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
return data[0] & 0x7F;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) {
|
||||
if(!(value >= 299999755 && value <= 348000335) &&
|
||||
!(value >= 386999938 && value <= 464000000) &&
|
||||
!(value >= 778999847 && value <= 928000000)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t subghz_device_cc1101_ext_set_frequency(uint32_t value) {
|
||||
if(furi_hal_region_is_frequency_allowed(value)) {
|
||||
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
|
||||
} else {
|
||||
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationOnlyRx;
|
||||
}
|
||||
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint32_t real_frequency =
|
||||
cc1101_set_frequency(subghz_device_cc1101_ext->spi_bus_handle, value);
|
||||
cc1101_calibrate(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
while(true) {
|
||||
CC1101Status status = cc1101_get_status(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(status.STATE == CC1101StateIDLE) break;
|
||||
}
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
return real_frequency;
|
||||
}
|
||||
|
||||
static bool subghz_device_cc1101_ext_start_debug() {
|
||||
bool ret = false;
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL) {
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->async_mirror_pin,
|
||||
GpioModeOutputPushPull,
|
||||
GpioPullNo,
|
||||
GpioSpeedVeryHigh);
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool subghz_device_cc1101_ext_stop_debug() {
|
||||
bool ret = false;
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL) {
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->async_mirror_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_capture_ISR() {
|
||||
if(!furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin)) {
|
||||
if(subghz_device_cc1101_ext->async_rx.capture_callback) {
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, false);
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback(
|
||||
true,
|
||||
LL_TIM_GetCounter(TIM17),
|
||||
(void*)subghz_device_cc1101_ext->async_rx.capture_callback_context);
|
||||
}
|
||||
} else {
|
||||
if(subghz_device_cc1101_ext->async_rx.capture_callback) {
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, true);
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback(
|
||||
false,
|
||||
LL_TIM_GetCounter(TIM17),
|
||||
(void*)subghz_device_cc1101_ext->async_rx.capture_callback_context);
|
||||
}
|
||||
}
|
||||
LL_TIM_SetCounter(TIM17, 6);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_start_async_rx(
|
||||
SubGhzDeviceCC1101ExtCaptureCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncRx;
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback = callback;
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback_context = context;
|
||||
|
||||
furi_hal_bus_enable(FuriHalBusTIM17);
|
||||
|
||||
// Configure TIM
|
||||
LL_TIM_SetPrescaler(TIM17, 64 - 1);
|
||||
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
|
||||
LL_TIM_SetAutoReload(TIM17, 0xFFFF);
|
||||
LL_TIM_SetClockDivision(TIM17, LL_TIM_CLOCKDIVISION_DIV1);
|
||||
|
||||
// Timer: advanced
|
||||
LL_TIM_SetClockSource(TIM17, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
LL_TIM_DisableARRPreload(TIM17);
|
||||
LL_TIM_DisableDMAReq_TRIG(TIM17);
|
||||
LL_TIM_DisableIT_TRIG(TIM17);
|
||||
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeInterruptRiseFall, GpioPullUp, GpioSpeedVeryHigh);
|
||||
furi_hal_gpio_remove_int_callback(subghz_device_cc1101_ext->g0_pin);
|
||||
furi_hal_gpio_add_int_callback(
|
||||
subghz_device_cc1101_ext->g0_pin,
|
||||
subghz_device_cc1101_ext_capture_ISR,
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback);
|
||||
|
||||
// Start timer
|
||||
LL_TIM_SetCounter(TIM17, 0);
|
||||
LL_TIM_EnableCounter(TIM17);
|
||||
|
||||
// Start debug
|
||||
subghz_device_cc1101_ext_start_debug();
|
||||
|
||||
// Switch to RX
|
||||
subghz_device_cc1101_ext_rx();
|
||||
|
||||
//Clear the variable after the end of the session
|
||||
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_stop_async_rx() {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncRx);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
|
||||
|
||||
// Shutdown radio
|
||||
subghz_device_cc1101_ext_idle();
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_bus_disable(FuriHalBusTIM17);
|
||||
|
||||
// Stop debug
|
||||
subghz_device_cc1101_ext_stop_debug();
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
furi_hal_gpio_remove_int_callback(subghz_device_cc1101_ext->g0_pin);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_async_tx_refill(uint32_t* buffer, size_t samples) {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx);
|
||||
while(samples > 0) {
|
||||
bool is_odd = samples % 2;
|
||||
LevelDuration ld;
|
||||
if(level_duration_is_reset(subghz_device_cc1101_ext->async_tx.carry_ld)) {
|
||||
ld = subghz_device_cc1101_ext->async_tx.callback(
|
||||
subghz_device_cc1101_ext->async_tx.callback_context);
|
||||
} else {
|
||||
ld = subghz_device_cc1101_ext->async_tx.carry_ld;
|
||||
subghz_device_cc1101_ext->async_tx.carry_ld = level_duration_reset();
|
||||
}
|
||||
|
||||
if(level_duration_is_wait(ld)) {
|
||||
*buffer = SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME;
|
||||
buffer++;
|
||||
samples--;
|
||||
} else if(level_duration_is_reset(ld)) {
|
||||
*buffer = 0;
|
||||
buffer++;
|
||||
samples--;
|
||||
LL_DMA_DisableIT_HT(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_DMA_DisableIT_TC(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_TIM_EnableIT_UPDATE(TIM17);
|
||||
break;
|
||||
} else {
|
||||
bool level = level_duration_get_level(ld);
|
||||
|
||||
// Inject guard time if level is incorrect
|
||||
if(is_odd != level) {
|
||||
*buffer = SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME;
|
||||
buffer++;
|
||||
samples--;
|
||||
|
||||
// Special case: prevent buffer overflow if sample is last
|
||||
if(samples == 0) {
|
||||
subghz_device_cc1101_ext->async_tx.carry_ld = ld;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t duration = level_duration_get_duration(ld);
|
||||
furi_assert(duration > 0);
|
||||
*buffer = duration - 1;
|
||||
buffer++;
|
||||
samples--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_async_tx_dma_isr() {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx);
|
||||
|
||||
#if SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL == LL_DMA_CHANNEL_3
|
||||
if(LL_DMA_IsActiveFlag_HT3(SUBGHZ_DEVICE_CC1101_EXT_DMA)) {
|
||||
LL_DMA_ClearFlag_HT3(SUBGHZ_DEVICE_CC1101_EXT_DMA);
|
||||
subghz_device_cc1101_ext_async_tx_refill(
|
||||
subghz_device_cc1101_ext->async_tx.buffer,
|
||||
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF);
|
||||
}
|
||||
if(LL_DMA_IsActiveFlag_TC3(SUBGHZ_DEVICE_CC1101_EXT_DMA)) {
|
||||
LL_DMA_ClearFlag_TC3(SUBGHZ_DEVICE_CC1101_EXT_DMA);
|
||||
subghz_device_cc1101_ext_async_tx_refill(
|
||||
subghz_device_cc1101_ext->async_tx.buffer +
|
||||
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF,
|
||||
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF);
|
||||
}
|
||||
#else
|
||||
#error Update this code. Would you kindly?
|
||||
#endif
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_async_tx_timer_isr() {
|
||||
if(LL_TIM_IsActiveFlag_UPDATE(TIM17)) {
|
||||
if(LL_TIM_GetAutoReload(TIM17) == 0) {
|
||||
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, false);
|
||||
LL_TIM_DisableCounter(TIM17);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncTxEnd;
|
||||
}
|
||||
LL_TIM_ClearFlag_UPDATE(TIM17);
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callback, void* context) {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
|
||||
furi_assert(callback);
|
||||
|
||||
//If transmission is prohibited by regional settings
|
||||
if(subghz_device_cc1101_ext->regulation != SubGhzDeviceCC1101ExtRegulationTxRx) return false;
|
||||
|
||||
subghz_device_cc1101_ext->async_tx.callback = callback;
|
||||
subghz_device_cc1101_ext->async_tx.callback_context = context;
|
||||
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncTx;
|
||||
|
||||
subghz_device_cc1101_ext->async_tx.buffer =
|
||||
malloc(SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
|
||||
|
||||
//Signal generation with mem-to-mem DMA
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
|
||||
|
||||
// Configure DMA update timer
|
||||
LL_DMA_SetMemoryAddress(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, (uint32_t)subghz_device_cc1101_ext->async_tx.buffer);
|
||||
LL_DMA_SetPeriphAddress(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, (uint32_t) & (TIM17->ARR));
|
||||
LL_DMA_ConfigTransfer(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF,
|
||||
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_MODE_NORMAL);
|
||||
LL_DMA_SetDataLength(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL);
|
||||
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, LL_DMAMUX_REQ_TIM17_UP);
|
||||
|
||||
LL_DMA_EnableIT_TC(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_DMA_EnableIT_HT(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
|
||||
furi_hal_interrupt_set_isr(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ, subghz_device_cc1101_ext_async_tx_dma_isr, NULL);
|
||||
|
||||
furi_hal_bus_enable(FuriHalBusTIM17);
|
||||
|
||||
// Configure TIM
|
||||
LL_TIM_SetPrescaler(TIM17, 64 - 1);
|
||||
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
|
||||
LL_TIM_SetAutoReload(TIM17, 0xFFFF);
|
||||
LL_TIM_SetClockDivision(TIM17, LL_TIM_CLOCKDIVISION_DIV1);
|
||||
LL_TIM_SetClockSource(TIM17, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
LL_TIM_DisableARRPreload(TIM17);
|
||||
|
||||
furi_hal_interrupt_set_isr(
|
||||
FuriHalInterruptIdTim1TrgComTim17, subghz_device_cc1101_ext_async_tx_timer_isr, NULL);
|
||||
|
||||
subghz_device_cc1101_ext_async_tx_refill(
|
||||
subghz_device_cc1101_ext->async_tx.buffer, SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL);
|
||||
|
||||
// Configure tx gpio dma
|
||||
const GpioPin* gpio = subghz_device_cc1101_ext->g0_pin;
|
||||
|
||||
subghz_device_cc1101_ext->async_tx.gpio_tx_buff[0] = (uint32_t)gpio->pin << GPIO_NUMBER;
|
||||
subghz_device_cc1101_ext->async_tx.gpio_tx_buff[1] = gpio->pin;
|
||||
|
||||
LL_DMA_SetMemoryAddress(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF,
|
||||
(uint32_t)subghz_device_cc1101_ext->async_tx.gpio_tx_buff);
|
||||
LL_DMA_SetPeriphAddress(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, (uint32_t) & (gpio->port->BSRR));
|
||||
LL_DMA_ConfigTransfer(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF,
|
||||
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_PRIORITY_HIGH);
|
||||
LL_DMA_SetDataLength(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, 2);
|
||||
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, LL_DMAMUX_REQ_TIM17_UP);
|
||||
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF);
|
||||
|
||||
// Start debug
|
||||
if(subghz_device_cc1101_ext_start_debug()) {
|
||||
gpio = subghz_device_cc1101_ext->async_mirror_pin;
|
||||
subghz_device_cc1101_ext->async_tx.debug_gpio_buff[0] = (uint32_t)gpio->pin << GPIO_NUMBER;
|
||||
subghz_device_cc1101_ext->async_tx.debug_gpio_buff[1] = gpio->pin;
|
||||
|
||||
LL_DMA_SetMemoryAddress(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF,
|
||||
(uint32_t)subghz_device_cc1101_ext->async_tx.debug_gpio_buff);
|
||||
LL_DMA_SetPeriphAddress(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, (uint32_t) & (gpio->port->BSRR));
|
||||
LL_DMA_ConfigTransfer(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF,
|
||||
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_PRIORITY_LOW);
|
||||
LL_DMA_SetDataLength(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, 2);
|
||||
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, LL_DMAMUX_REQ_TIM17_UP);
|
||||
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF);
|
||||
}
|
||||
|
||||
// Start counter
|
||||
LL_TIM_EnableDMAReq_UPDATE(TIM17);
|
||||
LL_TIM_GenerateEvent_UPDATE(TIM17);
|
||||
|
||||
subghz_device_cc1101_ext_tx();
|
||||
|
||||
LL_TIM_SetCounter(TIM17, 0);
|
||||
LL_TIM_EnableCounter(TIM17);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_async_tx_complete() {
|
||||
return subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTxEnd;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_stop_async_tx() {
|
||||
furi_assert(
|
||||
subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx ||
|
||||
subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTxEnd);
|
||||
|
||||
// Shutdown radio
|
||||
subghz_device_cc1101_ext_idle();
|
||||
|
||||
// Deinitialize Timer
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_bus_disable(FuriHalBusTIM17);
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdTim1TrgComTim17, NULL, NULL);
|
||||
|
||||
// Deinitialize DMA
|
||||
LL_DMA_DeInit(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF);
|
||||
furi_hal_interrupt_set_isr(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ, NULL, NULL);
|
||||
|
||||
// Deinitialize GPIO
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// Stop debug
|
||||
if(subghz_device_cc1101_ext_stop_debug()) {
|
||||
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF);
|
||||
}
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
free(subghz_device_cc1101_ext->async_tx.buffer);
|
||||
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
|
||||
}
|
||||
206
applications/drivers/subghz/cc1101_ext/cc1101_ext.h
Normal file
206
applications/drivers/subghz/cc1101_ext/cc1101_ext.h
Normal file
@ -0,0 +1,206 @@
|
||||
/**
|
||||
* @file furi_hal_subghz.h
|
||||
* SubGhz HAL API
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <lib/subghz/devices/preset.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <toolbox/level_duration.h>
|
||||
#include <furi_hal_gpio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Mirror RX/TX async modulation signal to specified pin
|
||||
*
|
||||
* @warning Configures pin to output mode. Make sure it is not connected
|
||||
* directly to power or ground.
|
||||
*
|
||||
* @param[in] pin pointer to the gpio pin structure or NULL to disable
|
||||
*/
|
||||
void subghz_device_cc1101_ext_set_async_mirror_pin(const GpioPin* pin);
|
||||
|
||||
/** Get data GPIO
|
||||
*
|
||||
* @return pointer to the gpio pin structure
|
||||
*/
|
||||
const GpioPin* subghz_device_cc1101_ext_get_data_gpio();
|
||||
|
||||
/** Initialize device
|
||||
*
|
||||
* @return true if success
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_alloc();
|
||||
|
||||
/** Deinitialize device
|
||||
*/
|
||||
void subghz_device_cc1101_ext_free();
|
||||
|
||||
/** Check and switch to power save mode Used by internal API-HAL
|
||||
* initialization routine Can be used to reinitialize device to safe state and
|
||||
* send it to sleep
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_is_connect();
|
||||
|
||||
/** Send device to sleep mode
|
||||
*/
|
||||
void subghz_device_cc1101_ext_sleep();
|
||||
|
||||
/** Dump info to stdout
|
||||
*/
|
||||
void subghz_device_cc1101_ext_dump_state();
|
||||
|
||||
/** Load custom registers from preset
|
||||
*
|
||||
* @param preset_data registers to load
|
||||
*/
|
||||
void subghz_device_cc1101_ext_load_custom_preset(const uint8_t* preset_data);
|
||||
|
||||
/** Load registers
|
||||
*
|
||||
* @param data Registers data
|
||||
*/
|
||||
void subghz_device_cc1101_ext_load_registers(const uint8_t* data);
|
||||
|
||||
/** Load PATABLE
|
||||
*
|
||||
* @param data 8 uint8_t values
|
||||
*/
|
||||
void subghz_device_cc1101_ext_load_patable(const uint8_t data[8]);
|
||||
|
||||
/** Write packet to FIFO
|
||||
*
|
||||
* @param data bytes array
|
||||
* @param size size
|
||||
*/
|
||||
void subghz_device_cc1101_ext_write_packet(const uint8_t* data, uint8_t size);
|
||||
|
||||
/** Check if receive pipe is not empty
|
||||
*
|
||||
* @return true if not empty
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_rx_pipe_not_empty();
|
||||
|
||||
/** Check if received data crc is valid
|
||||
*
|
||||
* @return true if valid
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_is_rx_data_crc_valid();
|
||||
|
||||
/** Read packet from FIFO
|
||||
*
|
||||
* @param data pointer
|
||||
* @param size size
|
||||
*/
|
||||
void subghz_device_cc1101_ext_read_packet(uint8_t* data, uint8_t* size);
|
||||
|
||||
/** Flush rx FIFO buffer
|
||||
*/
|
||||
void subghz_device_cc1101_ext_flush_rx();
|
||||
|
||||
/** Flush tx FIFO buffer
|
||||
*/
|
||||
void subghz_device_cc1101_ext_flush_tx();
|
||||
|
||||
/** Shutdown Issue SPWD command
|
||||
* @warning registers content will be lost
|
||||
*/
|
||||
void subghz_device_cc1101_ext_shutdown();
|
||||
|
||||
/** Reset Issue reset command
|
||||
* @warning registers content will be lost
|
||||
*/
|
||||
void subghz_device_cc1101_ext_reset();
|
||||
|
||||
/** Switch to Idle
|
||||
*/
|
||||
void subghz_device_cc1101_ext_idle();
|
||||
|
||||
/** Switch to Receive
|
||||
*/
|
||||
void subghz_device_cc1101_ext_rx();
|
||||
|
||||
/** Switch to Transmit
|
||||
*
|
||||
* @return true if the transfer is allowed by belonging to the region
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_tx();
|
||||
|
||||
/** Get RSSI value in dBm
|
||||
*
|
||||
* @return RSSI value
|
||||
*/
|
||||
float subghz_device_cc1101_ext_get_rssi();
|
||||
|
||||
/** Get LQI
|
||||
*
|
||||
* @return LQI value
|
||||
*/
|
||||
uint8_t subghz_device_cc1101_ext_get_lqi();
|
||||
|
||||
/** Check if frequency is in valid range
|
||||
*
|
||||
* @param value frequency in Hz
|
||||
*
|
||||
* @return true if frequency is valid, otherwise false
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value);
|
||||
|
||||
/** Set frequency
|
||||
*
|
||||
* @param value frequency in Hz
|
||||
*
|
||||
* @return real frequency in Hz
|
||||
*/
|
||||
uint32_t subghz_device_cc1101_ext_set_frequency(uint32_t value);
|
||||
|
||||
/* High Level API */
|
||||
|
||||
/** Signal Timings Capture callback */
|
||||
typedef void (*SubGhzDeviceCC1101ExtCaptureCallback)(bool level, uint32_t duration, void* context);
|
||||
|
||||
/** Enable signal timings capture Initializes GPIO and TIM2 for timings capture
|
||||
*
|
||||
* @param callback SubGhzDeviceCC1101ExtCaptureCallback
|
||||
* @param context callback context
|
||||
*/
|
||||
void subghz_device_cc1101_ext_start_async_rx(
|
||||
SubGhzDeviceCC1101ExtCaptureCallback callback,
|
||||
void* context);
|
||||
|
||||
/** Disable signal timings capture Resets GPIO and TIM2
|
||||
*/
|
||||
void subghz_device_cc1101_ext_stop_async_rx();
|
||||
|
||||
/** Async TX callback type
|
||||
* @param context callback context
|
||||
* @return LevelDuration
|
||||
*/
|
||||
typedef LevelDuration (*SubGhzDeviceCC1101ExtCallback)(void* context);
|
||||
|
||||
/** Start async TX Initializes GPIO, TIM2 and DMA1 for signal output
|
||||
*
|
||||
* @param callback SubGhzDeviceCC1101ExtCallback
|
||||
* @param context callback context
|
||||
*
|
||||
* @return true if the transfer is allowed by belonging to the region
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callback, void* context);
|
||||
|
||||
/** Wait for async transmission to complete
|
||||
*
|
||||
* @return true if TX complete
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_is_async_tx_complete();
|
||||
|
||||
/** Stop async transmission and cleanup resources Resets GPIO, TIM2, and DMA1
|
||||
*/
|
||||
void subghz_device_cc1101_ext_stop_async_tx();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
110
applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.c
Normal file
110
applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.c
Normal file
@ -0,0 +1,110 @@
|
||||
#include "cc1101_ext_interconnect.h"
|
||||
#include "cc1101_ext.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#define TAG "SubGhzDeviceCC1101Ext"
|
||||
|
||||
static bool subghz_device_cc1101_ext_interconnect_is_frequency_valid(uint32_t frequency) {
|
||||
bool ret = subghz_device_cc1101_ext_is_frequency_valid(frequency);
|
||||
if(!ret) {
|
||||
furi_crash("SubGhz: Incorrect frequency.");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint32_t subghz_device_cc1101_ext_interconnect_set_frequency(uint32_t frequency) {
|
||||
subghz_device_cc1101_ext_interconnect_is_frequency_valid(frequency);
|
||||
return subghz_device_cc1101_ext_set_frequency(frequency);
|
||||
}
|
||||
|
||||
static bool subghz_device_cc1101_ext_interconnect_start_async_tx(void* callback, void* context) {
|
||||
return subghz_device_cc1101_ext_start_async_tx(
|
||||
(SubGhzDeviceCC1101ExtCallback)callback, context);
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_interconnect_start_async_rx(void* callback, void* context) {
|
||||
subghz_device_cc1101_ext_start_async_rx(
|
||||
(SubGhzDeviceCC1101ExtCaptureCallback)callback, context);
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_interconnect_load_preset(
|
||||
FuriHalSubGhzPreset preset,
|
||||
uint8_t* preset_data) {
|
||||
switch(preset) {
|
||||
case FuriHalSubGhzPresetOok650Async:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetOok270Async:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_ook_270khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPreset2FSKDev238Async:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPreset2FSKDev476Async:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetMSK99_97KbAsync:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_msk_99_97kb_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetGFSK9_99KbAsync:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_gfsk_9_99kb_async_regs);
|
||||
break;
|
||||
|
||||
default:
|
||||
subghz_device_cc1101_ext_load_custom_preset(preset_data);
|
||||
}
|
||||
}
|
||||
|
||||
const SubGhzDeviceInterconnect subghz_device_cc1101_ext_interconnect = {
|
||||
.begin = subghz_device_cc1101_ext_alloc,
|
||||
.end = subghz_device_cc1101_ext_free,
|
||||
.is_connect = subghz_device_cc1101_ext_is_connect,
|
||||
.reset = subghz_device_cc1101_ext_reset,
|
||||
.sleep = subghz_device_cc1101_ext_sleep,
|
||||
.idle = subghz_device_cc1101_ext_idle,
|
||||
.load_preset = subghz_device_cc1101_ext_interconnect_load_preset,
|
||||
.set_frequency = subghz_device_cc1101_ext_interconnect_set_frequency,
|
||||
.is_frequency_valid = subghz_device_cc1101_ext_is_frequency_valid,
|
||||
.set_async_mirror_pin = subghz_device_cc1101_ext_set_async_mirror_pin,
|
||||
.get_data_gpio = subghz_device_cc1101_ext_get_data_gpio,
|
||||
|
||||
.set_tx = subghz_device_cc1101_ext_tx,
|
||||
.flush_tx = subghz_device_cc1101_ext_flush_tx,
|
||||
.start_async_tx = subghz_device_cc1101_ext_interconnect_start_async_tx,
|
||||
.is_async_complete_tx = subghz_device_cc1101_ext_is_async_tx_complete,
|
||||
.stop_async_tx = subghz_device_cc1101_ext_stop_async_tx,
|
||||
|
||||
.set_rx = subghz_device_cc1101_ext_rx,
|
||||
.flush_rx = subghz_device_cc1101_ext_flush_rx,
|
||||
.start_async_rx = subghz_device_cc1101_ext_interconnect_start_async_rx,
|
||||
.stop_async_rx = subghz_device_cc1101_ext_stop_async_rx,
|
||||
|
||||
.get_rssi = subghz_device_cc1101_ext_get_rssi,
|
||||
.get_lqi = subghz_device_cc1101_ext_get_lqi,
|
||||
|
||||
.rx_pipe_not_empty = subghz_device_cc1101_ext_rx_pipe_not_empty,
|
||||
.is_rx_data_crc_valid = subghz_device_cc1101_ext_is_rx_data_crc_valid,
|
||||
.read_packet = subghz_device_cc1101_ext_read_packet,
|
||||
.write_packet = subghz_device_cc1101_ext_write_packet,
|
||||
};
|
||||
|
||||
const SubGhzDevice subghz_device_cc1101_ext = {
|
||||
.name = SUBGHZ_DEVICE_CC1101_EXT_NAME,
|
||||
.interconnect = &subghz_device_cc1101_ext_interconnect,
|
||||
};
|
||||
|
||||
static const FlipperAppPluginDescriptor subghz_device_cc1101_ext_descriptor = {
|
||||
.appid = SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID,
|
||||
.ep_api_version = SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION,
|
||||
.entry_point = &subghz_device_cc1101_ext,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* subghz_device_cc1101_ext_ep() {
|
||||
return &subghz_device_cc1101_ext_descriptor;
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <lib/subghz/devices/types.h>
|
||||
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_NAME "cc1101_ext"
|
||||
|
||||
typedef struct SubGhzDeviceCC1101Ext SubGhzDeviceCC1101Ext;
|
||||
|
||||
const FlipperAppPluginDescriptor* subghz_device_cc1101_ext_ep();
|
||||
@ -60,7 +60,9 @@ static int32_t avr_isp_worker_rw_thread(void* context) {
|
||||
AvrIspWorkerRW* instance = context;
|
||||
|
||||
/* start PWM on &gpio_ext_pa4 */
|
||||
furi_hal_pwm_start(FuriHalPwmOutputIdLptim2PA4, 4000000, 50);
|
||||
if(!furi_hal_pwm_is_running(FuriHalPwmOutputIdLptim2PA4)) {
|
||||
furi_hal_pwm_start(FuriHalPwmOutputIdLptim2PA4, 4000000, 50);
|
||||
}
|
||||
|
||||
FURI_LOG_D(TAG, "Start");
|
||||
|
||||
@ -122,7 +124,9 @@ static int32_t avr_isp_worker_rw_thread(void* context) {
|
||||
}
|
||||
FURI_LOG_D(TAG, "Stop");
|
||||
|
||||
furi_hal_pwm_stop(FuriHalPwmOutputIdLptim2PA4);
|
||||
if(furi_hal_pwm_is_running(FuriHalPwmOutputIdLptim2PA4)) {
|
||||
furi_hal_pwm_stop(FuriHalPwmOutputIdLptim2PA4);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -136,7 +140,12 @@ bool avr_isp_worker_rw_detect_chip(AvrIspWorkerRW* instance) {
|
||||
instance->chip_arr_ind = avr_isp_chip_arr_size + 1;
|
||||
|
||||
/* start PWM on &gpio_ext_pa4 */
|
||||
furi_hal_pwm_start(FuriHalPwmOutputIdLptim2PA4, 4000000, 50);
|
||||
bool was_pwm_enabled = false;
|
||||
if(!furi_hal_pwm_is_running(FuriHalPwmOutputIdLptim2PA4)) {
|
||||
furi_hal_pwm_start(FuriHalPwmOutputIdLptim2PA4, 4000000, 50);
|
||||
} else {
|
||||
was_pwm_enabled = true;
|
||||
}
|
||||
|
||||
do {
|
||||
if(!avr_isp_auto_set_spi_speed_start_pmode(instance->avr_isp)) {
|
||||
@ -200,7 +209,9 @@ bool avr_isp_worker_rw_detect_chip(AvrIspWorkerRW* instance) {
|
||||
|
||||
} while(0);
|
||||
|
||||
furi_hal_pwm_stop(FuriHalPwmOutputIdLptim2PA4);
|
||||
if(furi_hal_pwm_is_running(FuriHalPwmOutputIdLptim2PA4) && !was_pwm_enabled) {
|
||||
furi_hal_pwm_stop(FuriHalPwmOutputIdLptim2PA4);
|
||||
}
|
||||
|
||||
if(instance->callback) {
|
||||
if(instance->chip_arr_ind > avr_isp_chip_arr_size) {
|
||||
|
||||
BIN
applications/external/hid_app/assets/Space_60x18.png
vendored
Normal file
BIN
applications/external/hid_app/assets/Space_60x18.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
12
applications/external/hid_app/hid.c
vendored
12
applications/external/hid_app/hid.c
vendored
@ -7,6 +7,7 @@
|
||||
|
||||
enum HidDebugSubmenuIndex {
|
||||
HidSubmenuIndexKeynote,
|
||||
HidSubmenuIndexKeynoteVertical,
|
||||
HidSubmenuIndexKeyboard,
|
||||
HidSubmenuIndexMedia,
|
||||
HidSubmenuIndexTikTok,
|
||||
@ -20,6 +21,11 @@ static void hid_submenu_callback(void* context, uint32_t index) {
|
||||
Hid* app = context;
|
||||
if(index == HidSubmenuIndexKeynote) {
|
||||
app->view_id = HidViewKeynote;
|
||||
hid_keynote_set_orientation(app->hid_keynote, false);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeynote);
|
||||
} else if(index == HidSubmenuIndexKeynoteVertical) {
|
||||
app->view_id = HidViewKeynote;
|
||||
hid_keynote_set_orientation(app->hid_keynote, true);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeynote);
|
||||
} else if(index == HidSubmenuIndexKeyboard) {
|
||||
app->view_id = HidViewKeyboard;
|
||||
@ -105,6 +111,12 @@ Hid* hid_alloc(HidTransport transport) {
|
||||
app->device_type_submenu = submenu_alloc();
|
||||
submenu_add_item(
|
||||
app->device_type_submenu, "Keynote", HidSubmenuIndexKeynote, hid_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
app->device_type_submenu,
|
||||
"Keynote Vertical",
|
||||
HidSubmenuIndexKeynoteVertical,
|
||||
hid_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
app->device_type_submenu, "Keyboard", HidSubmenuIndexKeyboard, hid_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
|
||||
@ -111,6 +111,91 @@ static void hid_keynote_draw_callback(Canvas* canvas, void* context) {
|
||||
elements_multiline_text_aligned(canvas, 91, 57, AlignLeft, AlignBottom, "Back");
|
||||
}
|
||||
|
||||
static void hid_keynote_draw_vertical_callback(Canvas* canvas, void* context) {
|
||||
furi_assert(context);
|
||||
HidKeynoteModel* model = context;
|
||||
|
||||
// Header
|
||||
if(model->transport == HidTransportBle) {
|
||||
if(model->connected) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15);
|
||||
} else {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15);
|
||||
}
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
elements_multiline_text_aligned(canvas, 20, 3, AlignLeft, AlignTop, "Keynote");
|
||||
} else {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
elements_multiline_text_aligned(canvas, 12, 3, AlignLeft, AlignTop, "Keynote");
|
||||
}
|
||||
|
||||
canvas_draw_icon(canvas, 2, 18, &I_Pin_back_arrow_10x8);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_multiline_text_aligned(canvas, 15, 19, AlignLeft, AlignTop, "Hold to exit");
|
||||
|
||||
const uint8_t x_2 = 23;
|
||||
const uint8_t x_1 = 2;
|
||||
const uint8_t x_3 = 44;
|
||||
|
||||
const uint8_t y_1 = 44;
|
||||
const uint8_t y_2 = 65;
|
||||
|
||||
// Up
|
||||
canvas_draw_icon(canvas, x_2, y_1, &I_Button_18x18);
|
||||
if(model->up_pressed) {
|
||||
elements_slightly_rounded_box(canvas, x_2 + 3, y_1 + 2, 13, 13);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
hid_keynote_draw_arrow(canvas, x_2 + 9, y_1 + 6, CanvasDirectionBottomToTop);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Down
|
||||
canvas_draw_icon(canvas, x_2, y_2, &I_Button_18x18);
|
||||
if(model->down_pressed) {
|
||||
elements_slightly_rounded_box(canvas, x_2 + 3, y_2 + 2, 13, 13);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
hid_keynote_draw_arrow(canvas, x_2 + 9, y_2 + 10, CanvasDirectionTopToBottom);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Left
|
||||
canvas_draw_icon(canvas, x_1, y_2, &I_Button_18x18);
|
||||
if(model->left_pressed) {
|
||||
elements_slightly_rounded_box(canvas, x_1 + 3, y_2 + 2, 13, 13);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
hid_keynote_draw_arrow(canvas, x_1 + 7, y_2 + 8, CanvasDirectionRightToLeft);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Right
|
||||
canvas_draw_icon(canvas, x_3, y_2, &I_Button_18x18);
|
||||
if(model->right_pressed) {
|
||||
elements_slightly_rounded_box(canvas, x_3 + 3, y_2 + 2, 13, 13);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
hid_keynote_draw_arrow(canvas, x_3 + 11, y_2 + 8, CanvasDirectionLeftToRight);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Ok
|
||||
canvas_draw_icon(canvas, 2, 86, &I_Space_60x18);
|
||||
if(model->ok_pressed) {
|
||||
elements_slightly_rounded_box(canvas, 5, 88, 55, 13);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
canvas_draw_icon(canvas, 11, 90, &I_Ok_btn_9x9);
|
||||
elements_multiline_text_aligned(canvas, 26, 98, AlignLeft, AlignBottom, "Space");
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Back
|
||||
canvas_draw_icon(canvas, 2, 107, &I_Space_60x18);
|
||||
if(model->back_pressed) {
|
||||
elements_slightly_rounded_box(canvas, 5, 109, 55, 13);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
canvas_draw_icon(canvas, 11, 111, &I_Pin_back_arrow_10x8);
|
||||
elements_multiline_text_aligned(canvas, 26, 119, AlignLeft, AlignBottom, "Back");
|
||||
}
|
||||
|
||||
static void hid_keynote_process(HidKeynote* hid_keynote, InputEvent* event) {
|
||||
with_view_model(
|
||||
hid_keynote->view,
|
||||
@ -212,3 +297,16 @@ void hid_keynote_set_connected_status(HidKeynote* hid_keynote, bool connected) {
|
||||
with_view_model(
|
||||
hid_keynote->view, HidKeynoteModel * model, { model->connected = connected; }, true);
|
||||
}
|
||||
|
||||
void hid_keynote_set_orientation(HidKeynote* hid_keynote, bool vertical) {
|
||||
furi_assert(hid_keynote);
|
||||
|
||||
if(vertical) {
|
||||
view_set_draw_callback(hid_keynote->view, hid_keynote_draw_vertical_callback);
|
||||
view_set_orientation(hid_keynote->view, ViewOrientationVerticalFlip);
|
||||
|
||||
} else {
|
||||
view_set_draw_callback(hid_keynote->view, hid_keynote_draw_callback);
|
||||
view_set_orientation(hid_keynote->view, ViewOrientationHorizontal);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,3 +12,5 @@ void hid_keynote_free(HidKeynote* hid_keynote);
|
||||
View* hid_keynote_get_view(HidKeynote* hid_keynote);
|
||||
|
||||
void hid_keynote_set_connected_status(HidKeynote* hid_keynote, bool connected);
|
||||
|
||||
void hid_keynote_set_orientation(HidKeynote* hid_keynote, bool vertical);
|
||||
|
||||
@ -7,18 +7,10 @@ App(
|
||||
"gui",
|
||||
"dialogs",
|
||||
],
|
||||
provides=["music_player_start"],
|
||||
stack_size=2 * 1024,
|
||||
order=20,
|
||||
fap_icon="icons/music_10px.png",
|
||||
fap_category="Media",
|
||||
fap_icon_assets="icons",
|
||||
)
|
||||
|
||||
App(
|
||||
appid="music_player_start",
|
||||
apptype=FlipperAppType.STARTUP,
|
||||
entry_point="music_player_on_system_start",
|
||||
requires=["music_player"],
|
||||
order=30,
|
||||
fap_libs=["music_worker"],
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "music_player_worker.h"
|
||||
#include <music_worker/music_worker.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
@ -34,7 +34,7 @@ typedef struct {
|
||||
ViewPort* view_port;
|
||||
Gui* gui;
|
||||
|
||||
MusicPlayerWorker* worker;
|
||||
MusicWorker* worker;
|
||||
} MusicPlayer;
|
||||
|
||||
static const float MUSIC_PLAYER_VOLUMES[] = {0, .25, .5, .75, 1};
|
||||
@ -218,7 +218,7 @@ static void input_callback(InputEvent* input_event, void* ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
static void music_player_worker_callback(
|
||||
static void music_worker_callback(
|
||||
uint8_t semitone,
|
||||
uint8_t dots,
|
||||
uint8_t duration,
|
||||
@ -250,7 +250,7 @@ static void music_player_worker_callback(
|
||||
void music_player_clear(MusicPlayer* instance) {
|
||||
memset(instance->model->duration_history, 0xff, MUSIC_PLAYER_SEMITONE_HISTORY_SIZE);
|
||||
memset(instance->model->semitone_history, 0xff, MUSIC_PLAYER_SEMITONE_HISTORY_SIZE);
|
||||
music_player_worker_clear(instance->worker);
|
||||
music_worker_clear(instance->worker);
|
||||
}
|
||||
|
||||
MusicPlayer* music_player_alloc() {
|
||||
@ -263,10 +263,9 @@ MusicPlayer* music_player_alloc() {
|
||||
|
||||
instance->input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
||||
|
||||
instance->worker = music_player_worker_alloc();
|
||||
music_player_worker_set_volume(
|
||||
instance->worker, MUSIC_PLAYER_VOLUMES[instance->model->volume]);
|
||||
music_player_worker_set_callback(instance->worker, music_player_worker_callback, instance);
|
||||
instance->worker = music_worker_alloc();
|
||||
music_worker_set_volume(instance->worker, MUSIC_PLAYER_VOLUMES[instance->model->volume]);
|
||||
music_worker_set_callback(instance->worker, music_worker_callback, instance);
|
||||
|
||||
music_player_clear(instance);
|
||||
|
||||
@ -286,7 +285,7 @@ void music_player_free(MusicPlayer* instance) {
|
||||
furi_record_close(RECORD_GUI);
|
||||
view_port_free(instance->view_port);
|
||||
|
||||
music_player_worker_free(instance->worker);
|
||||
music_worker_free(instance->worker);
|
||||
|
||||
furi_message_queue_free(instance->input_queue);
|
||||
|
||||
@ -330,12 +329,12 @@ int32_t music_player_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
if(!music_player_worker_load(music_player->worker, furi_string_get_cstr(file_path))) {
|
||||
if(!music_worker_load(music_player->worker, furi_string_get_cstr(file_path))) {
|
||||
FURI_LOG_E(TAG, "Unable to load file");
|
||||
break;
|
||||
}
|
||||
|
||||
music_player_worker_start(music_player->worker);
|
||||
music_worker_start(music_player->worker);
|
||||
|
||||
InputEvent input;
|
||||
while(furi_message_queue_get(music_player->input_queue, &input, FuriWaitForever) ==
|
||||
@ -349,11 +348,11 @@ int32_t music_player_app(void* p) {
|
||||
} else if(input.key == InputKeyUp) {
|
||||
if(music_player->model->volume < COUNT_OF(MUSIC_PLAYER_VOLUMES) - 1)
|
||||
music_player->model->volume++;
|
||||
music_player_worker_set_volume(
|
||||
music_worker_set_volume(
|
||||
music_player->worker, MUSIC_PLAYER_VOLUMES[music_player->model->volume]);
|
||||
} else if(input.key == InputKeyDown) {
|
||||
if(music_player->model->volume > 0) music_player->model->volume--;
|
||||
music_player_worker_set_volume(
|
||||
music_worker_set_volume(
|
||||
music_player->worker, MUSIC_PLAYER_VOLUMES[music_player->model->volume]);
|
||||
}
|
||||
|
||||
@ -361,7 +360,7 @@ int32_t music_player_app(void* p) {
|
||||
view_port_update(music_player->view_port);
|
||||
}
|
||||
|
||||
music_player_worker_stop(music_player->worker);
|
||||
music_worker_stop(music_player->worker);
|
||||
if(p && strlen(p)) break; // Exit instead of going to browser if launched with arg
|
||||
music_player_clear(music_player);
|
||||
} while(1);
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
#include <furi.h>
|
||||
#include <cli/cli.h>
|
||||
#include <storage/storage.h>
|
||||
#include "music_player_worker.h"
|
||||
|
||||
static void music_player_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
MusicPlayerWorker* music_player_worker = music_player_worker_alloc();
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
do {
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(args), NULL) == FSE_OK) {
|
||||
if(!music_player_worker_load(music_player_worker, furi_string_get_cstr(args))) {
|
||||
printf("Failed to open file %s\r\n", furi_string_get_cstr(args));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if(!music_player_worker_load_rtttl_from_string(
|
||||
music_player_worker, furi_string_get_cstr(args))) {
|
||||
printf("Argument is not a file or RTTTL\r\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
music_player_worker_set_volume(music_player_worker, 1.0f);
|
||||
music_player_worker_start(music_player_worker);
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
furi_delay_ms(50);
|
||||
}
|
||||
music_player_worker_stop(music_player_worker);
|
||||
} while(0);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
music_player_worker_free(music_player_worker);
|
||||
}
|
||||
|
||||
void music_player_on_system_start() {
|
||||
#ifdef SRV_CLI
|
||||
Cli* cli = furi_record_open(RECORD_CLI);
|
||||
|
||||
cli_add_command(cli, "music_player", CliCommandFlagDefault, music_player_cli, NULL);
|
||||
|
||||
furi_record_close(RECORD_CLI);
|
||||
#else
|
||||
UNUSED(music_player_cli);
|
||||
#endif
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef void (*MusicPlayerWorkerCallback)(
|
||||
uint8_t semitone,
|
||||
uint8_t dots,
|
||||
uint8_t duration,
|
||||
float position,
|
||||
void* context);
|
||||
|
||||
typedef struct MusicPlayerWorker MusicPlayerWorker;
|
||||
|
||||
MusicPlayerWorker* music_player_worker_alloc();
|
||||
|
||||
void music_player_worker_clear(MusicPlayerWorker* instance);
|
||||
|
||||
void music_player_worker_free(MusicPlayerWorker* instance);
|
||||
|
||||
bool music_player_worker_load(MusicPlayerWorker* instance, const char* file_path);
|
||||
|
||||
bool music_player_worker_load_fmf_from_file(MusicPlayerWorker* instance, const char* file_path);
|
||||
|
||||
bool music_player_worker_load_rtttl_from_file(MusicPlayerWorker* instance, const char* file_path);
|
||||
|
||||
bool music_player_worker_load_rtttl_from_string(MusicPlayerWorker* instance, const char* string);
|
||||
|
||||
void music_player_worker_set_callback(
|
||||
MusicPlayerWorker* instance,
|
||||
MusicPlayerWorkerCallback callback,
|
||||
void* context);
|
||||
|
||||
void music_player_worker_set_volume(MusicPlayerWorker* instance, float volume);
|
||||
|
||||
void music_player_worker_start(MusicPlayerWorker* instance);
|
||||
|
||||
void music_player_worker_stop(MusicPlayerWorker* instance);
|
||||
@ -46,6 +46,7 @@ enum NfcMagicCustomEvent {
|
||||
struct NfcMagicDevice {
|
||||
MagicType type;
|
||||
uint32_t cuid;
|
||||
uint8_t uid_len;
|
||||
uint32_t password;
|
||||
};
|
||||
|
||||
|
||||
@ -107,14 +107,7 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
|
||||
}
|
||||
magic_activate();
|
||||
if(magic_gen1_wupa()) {
|
||||
if(!magic_gen1_data_access_cmd()) {
|
||||
FURI_LOG_E(
|
||||
TAG, "No card response to data access command (not a magic card)");
|
||||
nfc_magic_worker->callback(
|
||||
NfcMagicWorkerEventWrongCard, nfc_magic_worker->context);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
magic_gen1_data_access_cmd();
|
||||
|
||||
MfClassicData* mfc_data = &dev_data->mf_classic_data;
|
||||
for(size_t i = 0; i < 64; i++) {
|
||||
@ -296,6 +289,7 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
|
||||
}
|
||||
|
||||
void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) {
|
||||
FuriHalNfcDevData nfc_data = {};
|
||||
NfcMagicDevice* magic_dev = nfc_magic_worker->magic_dev;
|
||||
bool card_found_notified = false;
|
||||
uint8_t gen4_config[MAGIC_GEN4_CONFIG_LEN];
|
||||
@ -310,32 +304,44 @@ void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) {
|
||||
card_found_notified = true;
|
||||
}
|
||||
|
||||
furi_hal_nfc_activate_nfca(200, &magic_dev->cuid);
|
||||
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||
break;
|
||||
}
|
||||
|
||||
magic_deactivate();
|
||||
furi_delay_ms(300);
|
||||
magic_activate();
|
||||
|
||||
furi_hal_nfc_activate_nfca(200, &magic_dev->cuid);
|
||||
if(magic_gen4_get_cfg(magic_dev->password, gen4_config)) {
|
||||
magic_dev->type = MagicTypeGen4;
|
||||
if(!card_found_notified) {
|
||||
nfc_magic_worker->callback(
|
||||
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||
card_found_notified = true;
|
||||
if(furi_hal_nfc_detect(&nfc_data, 200)) {
|
||||
magic_dev->cuid = nfc_data.cuid;
|
||||
magic_dev->uid_len = nfc_data.uid_len;
|
||||
} else {
|
||||
// wrong BCC
|
||||
magic_dev->uid_len = 4;
|
||||
}
|
||||
|
||||
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
magic_deactivate();
|
||||
magic_activate();
|
||||
if(furi_hal_nfc_detect(&nfc_data, 200)) {
|
||||
magic_dev->cuid = nfc_data.cuid;
|
||||
magic_dev->uid_len = nfc_data.uid_len;
|
||||
if(magic_gen4_get_cfg(magic_dev->password, gen4_config)) {
|
||||
magic_dev->type = MagicTypeGen4;
|
||||
if(!card_found_notified) {
|
||||
nfc_magic_worker->callback(
|
||||
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||
card_found_notified = true;
|
||||
}
|
||||
|
||||
if(card_found_notified) {
|
||||
nfc_magic_worker->callback(
|
||||
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||
card_found_notified = false;
|
||||
nfc_magic_worker->callback(
|
||||
NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||
} else {
|
||||
nfc_magic_worker->callback(
|
||||
NfcMagicWorkerEventWrongCard, nfc_magic_worker->context);
|
||||
card_found_notified = true;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if(card_found_notified) {
|
||||
nfc_magic_worker->callback(
|
||||
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||
card_found_notified = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
magic_deactivate();
|
||||
|
||||
@ -8,7 +8,7 @@ static bool nfc_magic_scene_file_select_is_file_suitable(NfcMagic* nfc_magic) {
|
||||
case MagicTypeClassicDirectWrite:
|
||||
case MagicTypeClassicAPDU:
|
||||
if((nfc_dev->dev_data.mf_classic_data.type != MfClassicType1k) ||
|
||||
(nfc_dev->dev_data.nfc_data.uid_len != 4)) {
|
||||
(nfc_dev->dev_data.nfc_data.uid_len != nfc_magic->dev->uid_len)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -13,11 +13,10 @@ void nfc_magic_scene_not_magic_on_enter(void* context) {
|
||||
|
||||
notification_message(nfc_magic->notifications, &sequence_error);
|
||||
|
||||
// widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
|
||||
widget_add_string_element(
|
||||
widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "This is wrong card");
|
||||
widget_add_string_multiline_element(
|
||||
widget, 4, 17, AlignLeft, AlignTop, FontSecondary, "Not a magic\ncard");
|
||||
widget, 4, 17, AlignLeft, AlignTop, FontSecondary, "Not magic or unsupported\ncard");
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_not_magic_widget_callback, nfc_magic);
|
||||
|
||||
|
||||
13
applications/external/nfc_rfid_detector/application.fam
vendored
Normal file
13
applications/external/nfc_rfid_detector/application.fam
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
App(
|
||||
appid="nfc_rfid_detector",
|
||||
name="NFC/RFID detector",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
targets=["f7"],
|
||||
entry_point="nfc_rfid_detector_app",
|
||||
requires=["gui"],
|
||||
stack_size=4 * 1024,
|
||||
order=50,
|
||||
fap_icon="nfc_rfid_detector_10px.png",
|
||||
fap_category="Tools",
|
||||
fap_icon_assets="images",
|
||||
)
|
||||
7
applications/external/nfc_rfid_detector/helpers/nfc_rfid_detector_event.h
vendored
Normal file
7
applications/external/nfc_rfid_detector/helpers/nfc_rfid_detector_event.h
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
//NfcRfidDetectorCustomEvent
|
||||
NfcRfidDetectorCustomEventStartId = 100,
|
||||
|
||||
} NfcRfidDetectorCustomEvent;
|
||||
15
applications/external/nfc_rfid_detector/helpers/nfc_rfid_detector_types.h
vendored
Normal file
15
applications/external/nfc_rfid_detector/helpers/nfc_rfid_detector_types.h
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define NFC_RFID_DETECTOR_VERSION_APP "0.1"
|
||||
#define NFC_RFID_DETECTOR_DEVELOPED "SkorP"
|
||||
#define NFC_RFID_DETECTOR_GITHUB "https://github.com/flipperdevices/flipperzero-firmware"
|
||||
|
||||
typedef enum {
|
||||
NfcRfidDetectorViewVariableItemList,
|
||||
NfcRfidDetectorViewSubmenu,
|
||||
NfcRfidDetectorViewFieldPresence,
|
||||
NfcRfidDetectorViewWidget,
|
||||
} NfcRfidDetectorView;
|
||||
BIN
applications/external/nfc_rfid_detector/images/Modern_reader_18x34.png
vendored
Normal file
BIN
applications/external/nfc_rfid_detector/images/Modern_reader_18x34.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
BIN
applications/external/nfc_rfid_detector/images/Move_flipper_26x39.png
vendored
Normal file
BIN
applications/external/nfc_rfid_detector/images/Move_flipper_26x39.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
BIN
applications/external/nfc_rfid_detector/images/NFC_detect_45x30.png
vendored
Normal file
BIN
applications/external/nfc_rfid_detector/images/NFC_detect_45x30.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 168 B |
BIN
applications/external/nfc_rfid_detector/images/Rfid_detect_45x30.png
vendored
Normal file
BIN
applications/external/nfc_rfid_detector/images/Rfid_detect_45x30.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 B |
BIN
applications/external/nfc_rfid_detector/nfc_rfid_detector_10px.png
vendored
Normal file
BIN
applications/external/nfc_rfid_detector/nfc_rfid_detector_10px.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 124 B |
108
applications/external/nfc_rfid_detector/nfc_rfid_detector_app.c
vendored
Normal file
108
applications/external/nfc_rfid_detector/nfc_rfid_detector_app.c
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
#include "nfc_rfid_detector_app_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
static bool nfc_rfid_detector_app_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||
}
|
||||
|
||||
static bool nfc_rfid_detector_app_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
static void nfc_rfid_detector_app_tick_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
scene_manager_handle_tick_event(app->scene_manager);
|
||||
}
|
||||
|
||||
NfcRfidDetectorApp* nfc_rfid_detector_app_alloc() {
|
||||
NfcRfidDetectorApp* app = malloc(sizeof(NfcRfidDetectorApp));
|
||||
|
||||
// GUI
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
// View Dispatcher
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
app->scene_manager = scene_manager_alloc(&nfc_rfid_detector_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
|
||||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
app->view_dispatcher, nfc_rfid_detector_app_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
app->view_dispatcher, nfc_rfid_detector_app_back_event_callback);
|
||||
view_dispatcher_set_tick_event_callback(
|
||||
app->view_dispatcher, nfc_rfid_detector_app_tick_event_callback, 100);
|
||||
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
// Open Notification record
|
||||
app->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
// SubMenu
|
||||
app->submenu = submenu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, NfcRfidDetectorViewSubmenu, submenu_get_view(app->submenu));
|
||||
|
||||
// Widget
|
||||
app->widget = widget_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, NfcRfidDetectorViewWidget, widget_get_view(app->widget));
|
||||
|
||||
// Field Presence
|
||||
app->nfc_rfid_detector_field_presence = nfc_rfid_detector_view_field_presence_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
NfcRfidDetectorViewFieldPresence,
|
||||
nfc_rfid_detector_view_field_presence_get_view(app->nfc_rfid_detector_field_presence));
|
||||
|
||||
scene_manager_next_scene(app->scene_manager, NfcRfidDetectorSceneStart);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_app_free(NfcRfidDetectorApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewSubmenu);
|
||||
submenu_free(app->submenu);
|
||||
|
||||
// Widget
|
||||
view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewWidget);
|
||||
widget_free(app->widget);
|
||||
|
||||
// Field Presence
|
||||
view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewFieldPresence);
|
||||
nfc_rfid_detector_view_field_presence_free(app->nfc_rfid_detector_field_presence);
|
||||
|
||||
// View dispatcher
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
scene_manager_free(app->scene_manager);
|
||||
|
||||
// Notifications
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
app->notifications = NULL;
|
||||
|
||||
// Close records
|
||||
furi_record_close(RECORD_GUI);
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
int32_t nfc_rfid_detector_app(void* p) {
|
||||
UNUSED(p);
|
||||
NfcRfidDetectorApp* nfc_rfid_detector_app = nfc_rfid_detector_app_alloc();
|
||||
|
||||
view_dispatcher_run(nfc_rfid_detector_app->view_dispatcher);
|
||||
|
||||
nfc_rfid_detector_app_free(nfc_rfid_detector_app);
|
||||
|
||||
return 0;
|
||||
}
|
||||
40
applications/external/nfc_rfid_detector/nfc_rfid_detector_app_i.c
vendored
Normal file
40
applications/external/nfc_rfid_detector/nfc_rfid_detector_app_i.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#include "nfc_rfid_detector_app_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "NfcRfidDetector"
|
||||
|
||||
void nfc_rfid_detector_app_field_presence_start(NfcRfidDetectorApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
// start the field presence rfid detection
|
||||
furi_hal_rfid_field_detect_start();
|
||||
|
||||
// start the field presence nfc detection
|
||||
furi_hal_nfc_exit_sleep();
|
||||
furi_hal_nfc_field_detect_start();
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_app_field_presence_stop(NfcRfidDetectorApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
// stop the field presence rfid detection
|
||||
furi_hal_rfid_field_detect_stop();
|
||||
|
||||
// stop the field presence nfc detection
|
||||
furi_hal_nfc_start_sleep();
|
||||
}
|
||||
|
||||
bool nfc_rfid_detector_app_field_presence_is_nfc(NfcRfidDetectorApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
// check if the field presence is nfc
|
||||
return furi_hal_nfc_field_is_present();
|
||||
}
|
||||
|
||||
bool nfc_rfid_detector_app_field_presence_is_rfid(NfcRfidDetectorApp* app, uint32_t* frequency) {
|
||||
furi_assert(app);
|
||||
|
||||
// check if the field presence is rfid
|
||||
return furi_hal_rfid_field_is_present(frequency);
|
||||
}
|
||||
30
applications/external/nfc_rfid_detector/nfc_rfid_detector_app_i.h
vendored
Normal file
30
applications/external/nfc_rfid_detector/nfc_rfid_detector_app_i.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "helpers/nfc_rfid_detector_types.h"
|
||||
#include "helpers/nfc_rfid_detector_event.h"
|
||||
|
||||
#include "scenes/nfc_rfid_detector_scene.h"
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/widget.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include "views/nfc_rfid_detector_view_field_presence.h"
|
||||
|
||||
typedef struct NfcRfidDetectorApp NfcRfidDetectorApp;
|
||||
|
||||
struct NfcRfidDetectorApp {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
SceneManager* scene_manager;
|
||||
NotificationApp* notifications;
|
||||
Submenu* submenu;
|
||||
Widget* widget;
|
||||
NfcRfidDetectorFieldPresence* nfc_rfid_detector_field_presence;
|
||||
};
|
||||
|
||||
void nfc_rfid_detector_app_field_presence_start(NfcRfidDetectorApp* app);
|
||||
void nfc_rfid_detector_app_field_presence_stop(NfcRfidDetectorApp* app);
|
||||
bool nfc_rfid_detector_app_field_presence_is_nfc(NfcRfidDetectorApp* app);
|
||||
bool nfc_rfid_detector_app_field_presence_is_rfid(NfcRfidDetectorApp* app, uint32_t* frequency);
|
||||
31
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene.c
vendored
Normal file
31
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene.c
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
#include "../nfc_rfid_detector_app_i.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const nfc_rfid_detector_scene_on_enter_handlers[])(void*) = {
|
||||
#include "nfc_rfid_detector_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const nfc_rfid_detector_scene_on_event_handlers[])(void* context, SceneManagerEvent event) =
|
||||
{
|
||||
#include "nfc_rfid_detector_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const nfc_rfid_detector_scene_on_exit_handlers[])(void* context) = {
|
||||
#include "nfc_rfid_detector_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers nfc_rfid_detector_scene_handlers = {
|
||||
.on_enter_handlers = nfc_rfid_detector_scene_on_enter_handlers,
|
||||
.on_event_handlers = nfc_rfid_detector_scene_on_event_handlers,
|
||||
.on_exit_handlers = nfc_rfid_detector_scene_on_exit_handlers,
|
||||
.scene_num = NfcRfidDetectorSceneNum,
|
||||
};
|
||||
29
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene.h
vendored
Normal file
29
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene.h
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) NfcRfidDetectorScene##id,
|
||||
typedef enum {
|
||||
#include "nfc_rfid_detector_scene_config.h"
|
||||
NfcRfidDetectorSceneNum,
|
||||
} NfcRfidDetectorScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers nfc_rfid_detector_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "nfc_rfid_detector_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "nfc_rfid_detector_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "nfc_rfid_detector_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
69
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene_about.c
vendored
Normal file
69
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene_about.c
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
#include "../nfc_rfid_detector_app_i.h"
|
||||
|
||||
void nfc_rfid_detector_scene_about_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
NfcRfidDetectorApp* app = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_scene_about_on_enter(void* context) {
|
||||
NfcRfidDetectorApp* app = context;
|
||||
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
furi_string_printf(temp_str, "\e#%s\n", "Information");
|
||||
|
||||
furi_string_cat_printf(temp_str, "Version: %s\n", NFC_RFID_DETECTOR_VERSION_APP);
|
||||
furi_string_cat_printf(temp_str, "Developed by: %s\n", NFC_RFID_DETECTOR_DEVELOPED);
|
||||
furi_string_cat_printf(temp_str, "Github: %s\n\n", NFC_RFID_DETECTOR_GITHUB);
|
||||
|
||||
furi_string_cat_printf(temp_str, "\e#%s\n", "Description");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"This application allows\nyou to determine what\ntype of electromagnetic\nfield the reader is using.\nFor LF RFID you can also\nsee the carrier frequency\n\n");
|
||||
|
||||
widget_add_text_box_element(
|
||||
app->widget,
|
||||
0,
|
||||
0,
|
||||
128,
|
||||
14,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
"\e#\e! \e!\n",
|
||||
false);
|
||||
widget_add_text_box_element(
|
||||
app->widget,
|
||||
0,
|
||||
2,
|
||||
128,
|
||||
14,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
"\e#\e! NFC/RFID detector \e!\n",
|
||||
false);
|
||||
widget_add_text_scroll_element(app->widget, 0, 16, 128, 50, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, NfcRfidDetectorViewWidget);
|
||||
}
|
||||
|
||||
bool nfc_rfid_detector_scene_about_on_event(void* context, SceneManagerEvent event) {
|
||||
NfcRfidDetectorApp* app = context;
|
||||
bool consumed = false;
|
||||
UNUSED(app);
|
||||
UNUSED(event);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_scene_about_on_exit(void* context) {
|
||||
NfcRfidDetectorApp* app = context;
|
||||
|
||||
// Clear views
|
||||
widget_reset(app->widget);
|
||||
}
|
||||
3
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene_config.h
vendored
Normal file
3
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene_config.h
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
ADD_SCENE(nfc_rfid_detector, start, Start)
|
||||
ADD_SCENE(nfc_rfid_detector, about, About)
|
||||
ADD_SCENE(nfc_rfid_detector, field_presence, FieldPresence)
|
||||
60
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene_field_presence.c
vendored
Normal file
60
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene_field_presence.c
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
#include "../nfc_rfid_detector_app_i.h"
|
||||
#include "../views/nfc_rfid_detector_view_field_presence.h"
|
||||
|
||||
void nfc_rfid_detector_scene_field_presence_callback(
|
||||
NfcRfidDetectorCustomEvent event,
|
||||
void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
static const NotificationSequence notification_app_display_on = {
|
||||
|
||||
&message_display_backlight_on,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static void nfc_rfid_detector_scene_field_presence_update(void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
|
||||
uint32_t frequency = 0;
|
||||
bool nfc_field = nfc_rfid_detector_app_field_presence_is_nfc(app);
|
||||
bool rfid_field = nfc_rfid_detector_app_field_presence_is_rfid(app, &frequency);
|
||||
|
||||
if(nfc_field || rfid_field)
|
||||
notification_message(app->notifications, ¬ification_app_display_on);
|
||||
|
||||
nfc_rfid_detector_view_field_presence_update(
|
||||
app->nfc_rfid_detector_field_presence, nfc_field, rfid_field, frequency);
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_scene_field_presence_on_enter(void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
|
||||
// Start detection of field presence
|
||||
nfc_rfid_detector_app_field_presence_start(app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, NfcRfidDetectorViewFieldPresence);
|
||||
}
|
||||
|
||||
bool nfc_rfid_detector_scene_field_presence_on_event(void* context, SceneManagerEvent event) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeTick) {
|
||||
nfc_rfid_detector_scene_field_presence_update(app);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_scene_field_presence_on_exit(void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
// Stop detection of field presence
|
||||
nfc_rfid_detector_app_field_presence_stop(app);
|
||||
}
|
||||
58
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene_start.c
vendored
Normal file
58
applications/external/nfc_rfid_detector/scenes/nfc_rfid_detector_scene_start.c
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
#include "../nfc_rfid_detector_app_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexNfcRfidDetectorFieldPresence,
|
||||
SubmenuIndexNfcRfidDetectorAbout,
|
||||
} SubmenuIndex;
|
||||
|
||||
void nfc_rfid_detector_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
NfcRfidDetectorApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_scene_start_on_enter(void* context) {
|
||||
UNUSED(context);
|
||||
NfcRfidDetectorApp* app = context;
|
||||
Submenu* submenu = app->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Detect field type",
|
||||
SubmenuIndexNfcRfidDetectorFieldPresence,
|
||||
nfc_rfid_detector_scene_start_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"About",
|
||||
SubmenuIndexNfcRfidDetectorAbout,
|
||||
nfc_rfid_detector_scene_start_submenu_callback,
|
||||
app);
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(app->scene_manager, NfcRfidDetectorSceneStart));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, NfcRfidDetectorViewSubmenu);
|
||||
}
|
||||
|
||||
bool nfc_rfid_detector_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
NfcRfidDetectorApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexNfcRfidDetectorAbout) {
|
||||
scene_manager_next_scene(app->scene_manager, NfcRfidDetectorSceneAbout);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexNfcRfidDetectorFieldPresence) {
|
||||
scene_manager_next_scene(app->scene_manager, NfcRfidDetectorSceneFieldPresence);
|
||||
consumed = true;
|
||||
}
|
||||
scene_manager_set_scene_state(app->scene_manager, NfcRfidDetectorSceneStart, event.event);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_scene_start_on_exit(void* context) {
|
||||
NfcRfidDetectorApp* app = context;
|
||||
submenu_reset(app->submenu);
|
||||
}
|
||||
164
applications/external/nfc_rfid_detector/views/nfc_rfid_detector_view_field_presence.c
vendored
Normal file
164
applications/external/nfc_rfid_detector/views/nfc_rfid_detector_view_field_presence.c
vendored
Normal file
@ -0,0 +1,164 @@
|
||||
#include "nfc_rfid_detector_view_field_presence.h"
|
||||
#include "../nfc_rfid_detector_app_i.h"
|
||||
#include <nfc_rfid_detector_icons.h>
|
||||
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
|
||||
#define FIELD_FOUND_WEIGHT 5
|
||||
|
||||
typedef enum {
|
||||
NfcRfidDetectorTypeFieldPresenceNfc,
|
||||
NfcRfidDetectorTypeFieldPresenceRfid,
|
||||
} NfcRfidDetectorTypeFieldPresence;
|
||||
|
||||
static const Icon* NfcRfidDetectorFieldPresenceIcons[] = {
|
||||
[NfcRfidDetectorTypeFieldPresenceNfc] = &I_NFC_detect_45x30,
|
||||
[NfcRfidDetectorTypeFieldPresenceRfid] = &I_Rfid_detect_45x30,
|
||||
};
|
||||
|
||||
struct NfcRfidDetectorFieldPresence {
|
||||
View* view;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t nfc_field;
|
||||
uint8_t rfid_field;
|
||||
uint32_t rfid_frequency;
|
||||
} NfcRfidDetectorFieldPresenceModel;
|
||||
|
||||
void nfc_rfid_detector_view_field_presence_update(
|
||||
NfcRfidDetectorFieldPresence* instance,
|
||||
bool nfc_field,
|
||||
bool rfid_field,
|
||||
uint32_t rfid_frequency) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view,
|
||||
NfcRfidDetectorFieldPresenceModel * model,
|
||||
{
|
||||
if(nfc_field) {
|
||||
model->nfc_field = FIELD_FOUND_WEIGHT;
|
||||
} else if(model->nfc_field) {
|
||||
model->nfc_field--;
|
||||
}
|
||||
if(rfid_field) {
|
||||
model->rfid_field = FIELD_FOUND_WEIGHT;
|
||||
model->rfid_frequency = rfid_frequency;
|
||||
} else if(model->rfid_field) {
|
||||
model->rfid_field--;
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_view_field_presence_draw(
|
||||
Canvas* canvas,
|
||||
NfcRfidDetectorFieldPresenceModel* model) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
if(!model->nfc_field && !model->rfid_field) {
|
||||
canvas_draw_icon(canvas, 0, 16, &I_Modern_reader_18x34);
|
||||
canvas_draw_icon(canvas, 22, 12, &I_Move_flipper_26x39);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 56, 36, "Touch the reader");
|
||||
} else {
|
||||
if(model->nfc_field) {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 21, 10, "NFC");
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
9,
|
||||
17,
|
||||
NfcRfidDetectorFieldPresenceIcons[NfcRfidDetectorTypeFieldPresenceNfc]);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 9, 62, "13,56 MHz");
|
||||
}
|
||||
|
||||
if(model->rfid_field) {
|
||||
char str[16];
|
||||
snprintf(str, sizeof(str), "%.02f KHz", (double)model->rfid_frequency / 1000);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 76, 10, "LF RFID");
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
71,
|
||||
17,
|
||||
NfcRfidDetectorFieldPresenceIcons[NfcRfidDetectorTypeFieldPresenceRfid]);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 69, 62, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool nfc_rfid_detector_view_field_presence_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorFieldPresence* instance = context;
|
||||
UNUSED(instance);
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_view_field_presence_enter(void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorFieldPresence* instance = context;
|
||||
with_view_model(
|
||||
instance->view,
|
||||
NfcRfidDetectorFieldPresenceModel * model,
|
||||
{
|
||||
model->nfc_field = 0;
|
||||
model->rfid_field = 0;
|
||||
model->rfid_frequency = 0;
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_view_field_presence_exit(void* context) {
|
||||
furi_assert(context);
|
||||
NfcRfidDetectorFieldPresence* instance = context;
|
||||
UNUSED(instance);
|
||||
}
|
||||
|
||||
NfcRfidDetectorFieldPresence* nfc_rfid_detector_view_field_presence_alloc() {
|
||||
NfcRfidDetectorFieldPresence* instance = malloc(sizeof(NfcRfidDetectorFieldPresence));
|
||||
|
||||
// View allocation and configuration
|
||||
instance->view = view_alloc();
|
||||
|
||||
view_allocate_model(
|
||||
instance->view, ViewModelTypeLocking, sizeof(NfcRfidDetectorFieldPresenceModel));
|
||||
view_set_context(instance->view, instance);
|
||||
view_set_draw_callback(
|
||||
instance->view, (ViewDrawCallback)nfc_rfid_detector_view_field_presence_draw);
|
||||
view_set_input_callback(instance->view, nfc_rfid_detector_view_field_presence_input);
|
||||
view_set_enter_callback(instance->view, nfc_rfid_detector_view_field_presence_enter);
|
||||
view_set_exit_callback(instance->view, nfc_rfid_detector_view_field_presence_exit);
|
||||
|
||||
with_view_model(
|
||||
instance->view,
|
||||
NfcRfidDetectorFieldPresenceModel * model,
|
||||
{
|
||||
model->nfc_field = 0;
|
||||
model->rfid_field = 0;
|
||||
model->rfid_frequency = 0;
|
||||
},
|
||||
true);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void nfc_rfid_detector_view_field_presence_free(NfcRfidDetectorFieldPresence* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
view_free(instance->view);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
View* nfc_rfid_detector_view_field_presence_get_view(NfcRfidDetectorFieldPresence* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->view;
|
||||
}
|
||||
19
applications/external/nfc_rfid_detector/views/nfc_rfid_detector_view_field_presence.h
vendored
Normal file
19
applications/external/nfc_rfid_detector/views/nfc_rfid_detector_view_field_presence.h
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/nfc_rfid_detector_types.h"
|
||||
#include "../helpers/nfc_rfid_detector_event.h"
|
||||
|
||||
typedef struct NfcRfidDetectorFieldPresence NfcRfidDetectorFieldPresence;
|
||||
|
||||
void nfc_rfid_detector_view_field_presence_update(
|
||||
NfcRfidDetectorFieldPresence* instance,
|
||||
bool nfc_field,
|
||||
bool rfid_field,
|
||||
uint32_t rfid_frequency);
|
||||
|
||||
NfcRfidDetectorFieldPresence* nfc_rfid_detector_view_field_presence_alloc();
|
||||
|
||||
void nfc_rfid_detector_view_field_presence_free(NfcRfidDetectorFieldPresence* instance);
|
||||
|
||||
View* nfc_rfid_detector_view_field_presence_get_view(NfcRfidDetectorFieldPresence* instance);
|
||||
@ -16,6 +16,7 @@ PicopassDevice* picopass_device_alloc() {
|
||||
PicopassDevice* picopass_dev = malloc(sizeof(PicopassDevice));
|
||||
picopass_dev->dev_data.pacs.legacy = false;
|
||||
picopass_dev->dev_data.pacs.se_enabled = false;
|
||||
picopass_dev->dev_data.pacs.elite_kdf = false;
|
||||
picopass_dev->dev_data.pacs.pin_length = 0;
|
||||
picopass_dev->storage = furi_record_open(RECORD_STORAGE);
|
||||
picopass_dev->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
@ -77,6 +78,7 @@ static bool picopass_device_save_file(
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO: Add elite
|
||||
if(!flipper_format_write_comment_cstr(file, "Picopass blocks")) break;
|
||||
bool block_saved = true;
|
||||
|
||||
@ -256,6 +258,7 @@ void picopass_device_data_clear(PicopassDeviceData* dev_data) {
|
||||
}
|
||||
dev_data->pacs.legacy = false;
|
||||
dev_data->pacs.se_enabled = false;
|
||||
dev_data->pacs.elite_kdf = false;
|
||||
dev_data->pacs.pin_length = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -62,6 +62,7 @@ typedef struct {
|
||||
bool sio;
|
||||
bool biometrics;
|
||||
uint8_t key[8];
|
||||
bool elite_kdf;
|
||||
uint8_t pin_length;
|
||||
PicopassEncryption encryption;
|
||||
uint8_t credential[8];
|
||||
|
||||
@ -550,6 +550,7 @@ void picopass_worker_elite_dict_attack(PicopassWorker* picopass_worker) {
|
||||
if(err == ERR_NONE) {
|
||||
FURI_LOG_I(TAG, "Found key");
|
||||
memcpy(pacs->key, key, PICOPASS_BLOCK_LEN);
|
||||
pacs->elite_kdf = elite;
|
||||
err = picopass_read_card(AA1);
|
||||
if(err != ERR_NONE) {
|
||||
FURI_LOG_E(TAG, "picopass_read_card error %d", err);
|
||||
@ -720,7 +721,7 @@ void picopass_worker_write_key(PicopassWorker* picopass_worker) {
|
||||
uint8_t* oldKey = AA1[PICOPASS_KD_BLOCK_INDEX].data;
|
||||
|
||||
uint8_t newKey[PICOPASS_BLOCK_LEN] = {0};
|
||||
loclass_iclass_calc_div_key(csn, pacs->key, newKey, false);
|
||||
loclass_iclass_calc_div_key(csn, pacs->key, newKey, pacs->elite_kdf);
|
||||
|
||||
if((fuses & 0x80) == 0x80) {
|
||||
FURI_LOG_D(TAG, "Plain write for personalized mode key change");
|
||||
|
||||
@ -60,24 +60,28 @@ bool picopass_scene_key_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_set_scene_state(
|
||||
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteStandard);
|
||||
memcpy(picopass->dev->dev_data.pacs.key, picopass_iclass_key, PICOPASS_BLOCK_LEN);
|
||||
picopass->dev->dev_data.pacs.elite_kdf = false;
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexWriteiCE) {
|
||||
scene_manager_set_scene_state(
|
||||
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
|
||||
memcpy(picopass->dev->dev_data.pacs.key, picopass_xice_key, PICOPASS_BLOCK_LEN);
|
||||
picopass->dev->dev_data.pacs.elite_kdf = true;
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexWriteiCL) {
|
||||
scene_manager_set_scene_state(
|
||||
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
|
||||
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCL);
|
||||
memcpy(picopass->dev->dev_data.pacs.key, picopass_xicl_key, PICOPASS_BLOCK_LEN);
|
||||
picopass->dev->dev_data.pacs.elite_kdf = false;
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexWriteiCS) {
|
||||
scene_manager_set_scene_state(
|
||||
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
|
||||
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCS);
|
||||
memcpy(picopass->dev->dev_data.pacs.key, picopass_xics_key, PICOPASS_BLOCK_LEN);
|
||||
picopass->dev->dev_data.pacs.elite_kdf = false;
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
@ -33,7 +33,13 @@ void signal_gen_scene_pwm_on_enter(void* context) {
|
||||
signal_gen_pwm_set_callback(app->pwm_view, signal_gen_pwm_callback, app);
|
||||
|
||||
signal_gen_pwm_set_params(app->pwm_view, 0, DEFAULT_FREQ, DEFAULT_DUTY);
|
||||
furi_hal_pwm_start(pwm_ch_id[0], DEFAULT_FREQ, DEFAULT_DUTY);
|
||||
|
||||
if(!furi_hal_pwm_is_running(pwm_ch_id[0])) {
|
||||
furi_hal_pwm_start(pwm_ch_id[0], DEFAULT_FREQ, DEFAULT_DUTY);
|
||||
} else {
|
||||
furi_hal_pwm_stop(pwm_ch_id[0]);
|
||||
furi_hal_pwm_start(pwm_ch_id[0], DEFAULT_FREQ, DEFAULT_DUTY);
|
||||
}
|
||||
}
|
||||
|
||||
bool signal_gen_scene_pwm_on_event(void* context, SceneManagerEvent event) {
|
||||
@ -46,8 +52,18 @@ bool signal_gen_scene_pwm_on_event(void* context, SceneManagerEvent event) {
|
||||
furi_hal_pwm_set_params(app->pwm_ch, app->pwm_freq, app->pwm_duty);
|
||||
} else if(event.event == SignalGenPwmEventChannelChange) {
|
||||
consumed = true;
|
||||
furi_hal_pwm_stop(app->pwm_ch_prev);
|
||||
furi_hal_pwm_start(app->pwm_ch, app->pwm_freq, app->pwm_duty);
|
||||
// Stop previous channel PWM
|
||||
if(furi_hal_pwm_is_running(app->pwm_ch_prev)) {
|
||||
furi_hal_pwm_stop(app->pwm_ch_prev);
|
||||
}
|
||||
|
||||
// Start PWM and restart if it was starter already
|
||||
if(furi_hal_pwm_is_running(app->pwm_ch)) {
|
||||
furi_hal_pwm_stop(app->pwm_ch);
|
||||
furi_hal_pwm_start(app->pwm_ch, app->pwm_freq, app->pwm_duty);
|
||||
} else {
|
||||
furi_hal_pwm_start(app->pwm_ch, app->pwm_freq, app->pwm_duty);
|
||||
}
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
@ -56,5 +72,8 @@ bool signal_gen_scene_pwm_on_event(void* context, SceneManagerEvent event) {
|
||||
void signal_gen_scene_pwm_on_exit(void* context) {
|
||||
SignalGenApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
furi_hal_pwm_stop(app->pwm_ch);
|
||||
|
||||
if(furi_hal_pwm_is_running(app->pwm_ch)) {
|
||||
furi_hal_pwm_stop(app->pwm_ch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ App(
|
||||
"subghz",
|
||||
"bad_usb",
|
||||
"u2f",
|
||||
"fap_loader",
|
||||
"archive",
|
||||
],
|
||||
)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#include <core/common_defines.h>
|
||||
#include <core/log.h>
|
||||
#include <gui/modules/file_browser_worker.h>
|
||||
#include <fap_loader/fap_loader_app.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <math.h>
|
||||
|
||||
static void
|
||||
@ -367,7 +367,7 @@ void archive_add_app_item(ArchiveBrowserView* browser, const char* name) {
|
||||
static bool archive_get_fap_meta(FuriString* file_path, FuriString* fap_name, uint8_t** icon_ptr) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
bool success = false;
|
||||
if(fap_loader_load_name_and_icon(file_path, storage, icon_ptr, fap_name)) {
|
||||
if(flipper_application_load_name_and_icon(file_path, storage, icon_ptr, fap_name)) {
|
||||
success = true;
|
||||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
@ -11,17 +11,28 @@
|
||||
#define SCENE_STATE_DEFAULT (0)
|
||||
#define SCENE_STATE_NEED_REFRESH (1)
|
||||
|
||||
static const char* flipper_app_name[] = {
|
||||
[ArchiveFileTypeIButton] = "iButton",
|
||||
[ArchiveFileTypeNFC] = "NFC",
|
||||
[ArchiveFileTypeSubGhz] = "Sub-GHz",
|
||||
[ArchiveFileTypeLFRFID] = "125 kHz RFID",
|
||||
[ArchiveFileTypeInfrared] = "Infrared",
|
||||
[ArchiveFileTypeBadUsb] = "Bad USB",
|
||||
[ArchiveFileTypeU2f] = "U2F",
|
||||
[ArchiveFileTypeUpdateManifest] = "UpdaterApp",
|
||||
[ArchiveFileTypeApplication] = "Applications",
|
||||
};
|
||||
const char* archive_get_flipper_app_name(ArchiveFileTypeEnum file_type) {
|
||||
switch(file_type) {
|
||||
case ArchiveFileTypeIButton:
|
||||
return "iButton";
|
||||
case ArchiveFileTypeNFC:
|
||||
return "NFC";
|
||||
case ArchiveFileTypeSubGhz:
|
||||
return "Sub-GHz";
|
||||
case ArchiveFileTypeLFRFID:
|
||||
return "125 kHz RFID";
|
||||
case ArchiveFileTypeInfrared:
|
||||
return "Infrared";
|
||||
case ArchiveFileTypeBadUsb:
|
||||
return "Bad USB";
|
||||
case ArchiveFileTypeU2f:
|
||||
return "U2F";
|
||||
case ArchiveFileTypeUpdateManifest:
|
||||
return "UpdaterApp";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void archive_loader_callback(const void* message, void* context) {
|
||||
furi_assert(message);
|
||||
@ -39,20 +50,20 @@ static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selec
|
||||
UNUSED(browser);
|
||||
Loader* loader = furi_record_open(RECORD_LOADER);
|
||||
|
||||
LoaderStatus status;
|
||||
if(selected->is_app) {
|
||||
char* param = strrchr(furi_string_get_cstr(selected->path), '/');
|
||||
if(param != NULL) {
|
||||
param++;
|
||||
}
|
||||
status = loader_start(loader, flipper_app_name[selected->type], param);
|
||||
} else {
|
||||
status = loader_start(
|
||||
loader, flipper_app_name[selected->type], furi_string_get_cstr(selected->path));
|
||||
}
|
||||
const char* app_name = archive_get_flipper_app_name(selected->type);
|
||||
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
if(app_name) {
|
||||
if(selected->is_app) {
|
||||
char* param = strrchr(furi_string_get_cstr(selected->path), '/');
|
||||
if(param != NULL) {
|
||||
param++;
|
||||
}
|
||||
loader_start_with_gui_error(loader, app_name, param);
|
||||
} else {
|
||||
loader_start_with_gui_error(loader, app_name, furi_string_get_cstr(selected->path));
|
||||
}
|
||||
} else {
|
||||
loader_start_with_gui_error(loader, furi_string_get_cstr(selected->path), NULL);
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_LOADER);
|
||||
|
||||
@ -334,9 +334,24 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
int32_t scroll_speed = 1;
|
||||
if(model->button_held_for_ticks > 5) {
|
||||
if(model->button_held_for_ticks % 2) {
|
||||
scroll_speed = 0;
|
||||
} else {
|
||||
scroll_speed = model->button_held_for_ticks > 9 ? 4 : 2;
|
||||
}
|
||||
}
|
||||
|
||||
if(event->key == InputKeyUp) {
|
||||
model->item_idx =
|
||||
((model->item_idx - 1) + model->item_cnt) % model->item_cnt;
|
||||
if(model->item_idx < scroll_speed) {
|
||||
model->button_held_for_ticks = 0;
|
||||
model->item_idx = model->item_cnt - 1;
|
||||
} else {
|
||||
model->item_idx =
|
||||
((model->item_idx - scroll_speed) + model->item_cnt) %
|
||||
model->item_cnt;
|
||||
}
|
||||
if(is_file_list_load_required(model)) {
|
||||
model->list_loading = true;
|
||||
browser->callback(ArchiveBrowserEventLoadPrevItems, browser->context);
|
||||
@ -345,8 +360,15 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
browser->callback(ArchiveBrowserEventFavMoveUp, browser->context);
|
||||
}
|
||||
model->scroll_counter = 0;
|
||||
model->button_held_for_ticks += 1;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
model->item_idx = (model->item_idx + 1) % model->item_cnt;
|
||||
int32_t count = model->item_cnt;
|
||||
if(model->item_idx + scroll_speed >= count) {
|
||||
model->button_held_for_ticks = 0;
|
||||
model->item_idx = 0;
|
||||
} else {
|
||||
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
|
||||
}
|
||||
if(is_file_list_load_required(model)) {
|
||||
model->list_loading = true;
|
||||
browser->callback(ArchiveBrowserEventLoadNextItems, browser->context);
|
||||
@ -355,6 +377,7 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
browser->callback(ArchiveBrowserEventFavMoveDown, browser->context);
|
||||
}
|
||||
model->scroll_counter = 0;
|
||||
model->button_held_for_ticks += 1;
|
||||
}
|
||||
},
|
||||
true);
|
||||
@ -391,6 +414,14 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
if(event->type == InputTypeRelease) {
|
||||
with_view_model(
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{ model->button_held_for_ticks = 0; },
|
||||
true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -100,6 +100,8 @@ typedef struct {
|
||||
int32_t array_offset;
|
||||
int32_t list_offset;
|
||||
size_t scroll_counter;
|
||||
|
||||
uint32_t button_held_for_ticks;
|
||||
} ArchiveBrowserViewModel;
|
||||
|
||||
void archive_browser_set_callback(
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
App(
|
||||
appid="fap_loader",
|
||||
name="Applications",
|
||||
apptype=FlipperAppType.APP,
|
||||
entry_point="fap_loader_app",
|
||||
cdefines=["APP_FAP_LOADER"],
|
||||
requires=[
|
||||
"gui",
|
||||
"storage",
|
||||
"loader",
|
||||
],
|
||||
stack_size=int(1.5 * 1024),
|
||||
icon="A_Plugins_14",
|
||||
order=90,
|
||||
)
|
||||
@ -1,216 +0,0 @@
|
||||
#include "fap_loader_app.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal_debug.h>
|
||||
|
||||
#include <assets_icons.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/loading.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <toolbox/path.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <loader/firmware_api/firmware_api.h>
|
||||
|
||||
#define TAG "FapLoader"
|
||||
|
||||
struct FapLoader {
|
||||
FlipperApplication* app;
|
||||
Storage* storage;
|
||||
DialogsApp* dialogs;
|
||||
Gui* gui;
|
||||
FuriString* fap_path;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
Loading* loading;
|
||||
};
|
||||
|
||||
bool fap_loader_load_name_and_icon(
|
||||
FuriString* path,
|
||||
Storage* storage,
|
||||
uint8_t** icon_ptr,
|
||||
FuriString* item_name) {
|
||||
FlipperApplication* app = flipper_application_alloc(storage, firmware_api_interface);
|
||||
|
||||
FlipperApplicationPreloadStatus preload_res =
|
||||
flipper_application_preload_manifest(app, furi_string_get_cstr(path));
|
||||
|
||||
bool load_success = false;
|
||||
|
||||
if(preload_res == FlipperApplicationPreloadStatusSuccess) {
|
||||
const FlipperApplicationManifest* manifest = flipper_application_get_manifest(app);
|
||||
if(manifest->has_icon) {
|
||||
memcpy(*icon_ptr, manifest->icon, FAP_MANIFEST_MAX_ICON_SIZE);
|
||||
}
|
||||
furi_string_set(item_name, manifest->name);
|
||||
load_success = true;
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "FAP Loader failed to preload %s", furi_string_get_cstr(path));
|
||||
load_success = false;
|
||||
}
|
||||
|
||||
flipper_application_free(app);
|
||||
return load_success;
|
||||
}
|
||||
|
||||
static bool fap_loader_item_callback(
|
||||
FuriString* path,
|
||||
void* context,
|
||||
uint8_t** icon_ptr,
|
||||
FuriString* item_name) {
|
||||
FapLoader* fap_loader = context;
|
||||
furi_assert(fap_loader);
|
||||
return fap_loader_load_name_and_icon(path, fap_loader->storage, icon_ptr, item_name);
|
||||
}
|
||||
|
||||
static bool fap_loader_run_selected_app(FapLoader* loader) {
|
||||
furi_assert(loader);
|
||||
|
||||
FuriString* error_message;
|
||||
|
||||
error_message = furi_string_alloc_set("unknown error");
|
||||
|
||||
bool file_selected = false;
|
||||
bool show_error = true;
|
||||
do {
|
||||
file_selected = true;
|
||||
loader->app = flipper_application_alloc(loader->storage, firmware_api_interface);
|
||||
size_t start = furi_get_tick();
|
||||
|
||||
FURI_LOG_I(TAG, "FAP Loader is loading %s", furi_string_get_cstr(loader->fap_path));
|
||||
|
||||
FlipperApplicationPreloadStatus preload_res =
|
||||
flipper_application_preload(loader->app, furi_string_get_cstr(loader->fap_path));
|
||||
if(preload_res != FlipperApplicationPreloadStatusSuccess) {
|
||||
const char* err_msg = flipper_application_preload_status_to_string(preload_res);
|
||||
furi_string_printf(error_message, "Preload failed: %s", err_msg);
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"FAP Loader failed to preload %s: %s",
|
||||
furi_string_get_cstr(loader->fap_path),
|
||||
err_msg);
|
||||
break;
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "FAP Loader is mapping");
|
||||
FlipperApplicationLoadStatus load_status = flipper_application_map_to_memory(loader->app);
|
||||
if(load_status != FlipperApplicationLoadStatusSuccess) {
|
||||
const char* err_msg = flipper_application_load_status_to_string(load_status);
|
||||
furi_string_printf(error_message, "Load failed: %s", err_msg);
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"FAP Loader failed to map to memory %s: %s",
|
||||
furi_string_get_cstr(loader->fap_path),
|
||||
err_msg);
|
||||
break;
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Loaded in %ums", (size_t)(furi_get_tick() - start));
|
||||
FURI_LOG_I(TAG, "FAP Loader is starting app");
|
||||
|
||||
FuriThread* thread = flipper_application_spawn(loader->app, NULL);
|
||||
|
||||
/* This flag is set by the debugger - to break on app start */
|
||||
if(furi_hal_debug_is_gdb_session_active()) {
|
||||
FURI_LOG_W(TAG, "Triggering BP for debugger");
|
||||
/* After hitting this, you can set breakpoints in your .fap's code
|
||||
* Note that you have to toggle breakpoints that were set before */
|
||||
__asm volatile("bkpt 0");
|
||||
}
|
||||
|
||||
FuriString* app_name = furi_string_alloc();
|
||||
path_extract_filename_no_ext(furi_string_get_cstr(loader->fap_path), app_name);
|
||||
furi_thread_set_appid(thread, furi_string_get_cstr(app_name));
|
||||
furi_string_free(app_name);
|
||||
|
||||
furi_thread_start(thread);
|
||||
furi_thread_join(thread);
|
||||
|
||||
show_error = false;
|
||||
int ret = furi_thread_get_return_code(thread);
|
||||
|
||||
FURI_LOG_I(TAG, "FAP app returned: %i", ret);
|
||||
} while(0);
|
||||
|
||||
if(show_error) {
|
||||
DialogMessage* message = dialog_message_alloc();
|
||||
dialog_message_set_header(message, "Error", 64, 0, AlignCenter, AlignTop);
|
||||
dialog_message_set_buttons(message, NULL, NULL, NULL);
|
||||
|
||||
FuriString* buffer;
|
||||
buffer = furi_string_alloc();
|
||||
furi_string_printf(buffer, "%s", furi_string_get_cstr(error_message));
|
||||
furi_string_replace(buffer, ":", "\n");
|
||||
dialog_message_set_text(
|
||||
message, furi_string_get_cstr(buffer), 64, 32, AlignCenter, AlignCenter);
|
||||
|
||||
dialog_message_show(loader->dialogs, message);
|
||||
dialog_message_free(message);
|
||||
furi_string_free(buffer);
|
||||
}
|
||||
|
||||
furi_string_free(error_message);
|
||||
|
||||
if(file_selected) {
|
||||
flipper_application_free(loader->app);
|
||||
}
|
||||
|
||||
return file_selected;
|
||||
}
|
||||
|
||||
static bool fap_loader_select_app(FapLoader* loader) {
|
||||
const DialogsFileBrowserOptions browser_options = {
|
||||
.extension = ".fap",
|
||||
.skip_assets = true,
|
||||
.icon = &I_unknown_10px,
|
||||
.hide_ext = true,
|
||||
.item_loader_callback = fap_loader_item_callback,
|
||||
.item_loader_context = loader,
|
||||
.base_path = EXT_PATH("apps"),
|
||||
};
|
||||
|
||||
return dialog_file_browser_show(
|
||||
loader->dialogs, loader->fap_path, loader->fap_path, &browser_options);
|
||||
}
|
||||
|
||||
static FapLoader* fap_loader_alloc(const char* path) {
|
||||
FapLoader* loader = malloc(sizeof(FapLoader)); //-V799
|
||||
loader->fap_path = furi_string_alloc_set(path);
|
||||
loader->storage = furi_record_open(RECORD_STORAGE);
|
||||
loader->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
loader->gui = furi_record_open(RECORD_GUI);
|
||||
loader->view_dispatcher = view_dispatcher_alloc();
|
||||
loader->loading = loading_alloc();
|
||||
view_dispatcher_attach_to_gui(
|
||||
loader->view_dispatcher, loader->gui, ViewDispatcherTypeFullscreen);
|
||||
view_dispatcher_add_view(loader->view_dispatcher, 0, loading_get_view(loader->loading));
|
||||
return loader;
|
||||
} //-V773
|
||||
|
||||
static void fap_loader_free(FapLoader* loader) {
|
||||
view_dispatcher_remove_view(loader->view_dispatcher, 0);
|
||||
loading_free(loader->loading);
|
||||
view_dispatcher_free(loader->view_dispatcher);
|
||||
furi_string_free(loader->fap_path);
|
||||
furi_record_close(RECORD_GUI);
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
free(loader);
|
||||
}
|
||||
|
||||
int32_t fap_loader_app(void* p) {
|
||||
FapLoader* loader;
|
||||
if(p) {
|
||||
loader = fap_loader_alloc((const char*)p);
|
||||
view_dispatcher_switch_to_view(loader->view_dispatcher, 0);
|
||||
fap_loader_run_selected_app(loader);
|
||||
} else {
|
||||
loader = fap_loader_alloc(EXT_PATH("apps"));
|
||||
while(fap_loader_select_app(loader)) {
|
||||
view_dispatcher_switch_to_view(loader->view_dispatcher, 0);
|
||||
fap_loader_run_selected_app(loader);
|
||||
};
|
||||
}
|
||||
|
||||
fap_loader_free(loader);
|
||||
return 0;
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
#include <storage/storage.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct FapLoader FapLoader;
|
||||
|
||||
/**
|
||||
* @brief Load name and icon from FAP file.
|
||||
*
|
||||
* @param path Path to FAP file.
|
||||
* @param storage Storage instance.
|
||||
* @param icon_ptr Icon pointer.
|
||||
* @param item_name Application name.
|
||||
* @return true if icon and name were loaded successfully.
|
||||
*/
|
||||
bool fap_loader_load_name_and_icon(
|
||||
FuriString* path,
|
||||
Storage* storage,
|
||||
uint8_t** icon_ptr,
|
||||
FuriString* item_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -144,6 +144,10 @@ static void nfc_cli_apdu(Cli* cli, FuriString* args) {
|
||||
break;
|
||||
}
|
||||
resp_size = (tx_rx.rx_bits / 8) * 2;
|
||||
if(!resp_size) {
|
||||
printf("No response\r\n");
|
||||
break;
|
||||
}
|
||||
resp_buffer = malloc(resp_size);
|
||||
uint8_to_hex_chars(tx_rx.rx_data, resp_buffer, resp_size);
|
||||
resp_buffer[resp_size] = 0;
|
||||
|
||||
@ -7,6 +7,83 @@ void nfc_scene_nfc_data_info_widget_callback(GuiButtonType result, InputType typ
|
||||
}
|
||||
}
|
||||
|
||||
void nfc_scene_slix_build_string(
|
||||
FuriString* temp_str,
|
||||
NfcVData* nfcv_data,
|
||||
SlixTypeFeatures features,
|
||||
const char* type) {
|
||||
furi_string_cat_printf(temp_str, "Type: %s\n", type);
|
||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
||||
if(features & SlixFeatureRead) {
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Read %08llX%s\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_read, 4),
|
||||
(nfcv_data->sub_data.slix.flags & NfcVSlixDataFlagsHasKeyRead) ? "" : " (unset)");
|
||||
}
|
||||
if(features & SlixFeatureWrite) {
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Write %08llX%s\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_write, 4),
|
||||
(nfcv_data->sub_data.slix.flags & NfcVSlixDataFlagsHasKeyWrite) ? "" : " (unset)");
|
||||
}
|
||||
if(features & SlixFeaturePrivacy) {
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Privacy %08llX%s\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_privacy, 4),
|
||||
(nfcv_data->sub_data.slix.flags & NfcVSlixDataFlagsHasKeyPrivacy) ? "" : " (unset)");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Privacy mode %s\n",
|
||||
(nfcv_data->sub_data.slix.flags & NfcVSlixDataFlagsPrivacy) ? "ENABLED" : "DISABLED");
|
||||
}
|
||||
if(features & SlixFeatureDestroy) {
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Destroy %08llX%s\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_destroy, 4),
|
||||
(nfcv_data->sub_data.slix.flags & NfcVSlixDataFlagsHasKeyDestroy) ? "" : " (unset)");
|
||||
}
|
||||
if(features & SlixFeatureEas) {
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" EAS %08llX%s\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4),
|
||||
(nfcv_data->sub_data.slix.flags & NfcVSlixDataFlagsHasKeyEas) ? "" : " (unset)");
|
||||
}
|
||||
if(features & SlixFeatureSignature) {
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"Signature %08llX...\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.signature, 4));
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"DSFID: %02X %s\n",
|
||||
nfcv_data->dsfid,
|
||||
(nfcv_data->security_status[0] & NfcVLockBitDsfid) ? "(locked)" : "");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"AFI: %02X %s\n",
|
||||
nfcv_data->afi,
|
||||
(nfcv_data->security_status[0] & NfcVLockBitAfi) ? "(locked)" : "");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"EAS: %s\n",
|
||||
(nfcv_data->security_status[0] & NfcVLockBitEas) ? "locked" : "not locked");
|
||||
|
||||
if(features & SlixFeatureProtection) {
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"PPL: %s\n",
|
||||
(nfcv_data->security_status[0] & NfcVLockBitPpl) ? "locked" : "not locked");
|
||||
furi_string_cat_printf(temp_str, "Prot.ptr %02X\n", nfcv_data->sub_data.slix.pp_pointer);
|
||||
furi_string_cat_printf(temp_str, "Prot.con %02X\n", nfcv_data->sub_data.slix.pp_condition);
|
||||
}
|
||||
}
|
||||
|
||||
void nfc_scene_nfc_data_info_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
Widget* widget = nfc->widget;
|
||||
@ -76,95 +153,25 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "\n");
|
||||
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"DSFID: %02X %s\n",
|
||||
nfcv_data->dsfid,
|
||||
(nfcv_data->security_status[0] & NfcVLockBitDsfid) ? "(locked)" : "");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"AFI: %02X %s\n",
|
||||
nfcv_data->afi,
|
||||
(nfcv_data->security_status[0] & NfcVLockBitAfi) ? "(locked)" : "");
|
||||
furi_string_cat_printf(temp_str, "IC Ref: %02X\n", nfcv_data->ic_ref);
|
||||
furi_string_cat_printf(temp_str, "Blocks: %02X\n", nfcv_data->block_num);
|
||||
furi_string_cat_printf(temp_str, "Blocksize: %02X\n", nfcv_data->block_size);
|
||||
furi_string_cat_printf(temp_str, "IC Ref: %d\n", nfcv_data->ic_ref);
|
||||
furi_string_cat_printf(temp_str, "Blocks: %d\n", nfcv_data->block_num);
|
||||
furi_string_cat_printf(temp_str, "Blocksize: %d\n", nfcv_data->block_size);
|
||||
|
||||
switch(dev_data->nfcv_data.sub_type) {
|
||||
case NfcVTypePlain:
|
||||
furi_string_cat_printf(temp_str, "Type: Plain\n");
|
||||
break;
|
||||
case NfcVTypeSlix:
|
||||
furi_string_cat_printf(temp_str, "Type: SLIX\n");
|
||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" EAS %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4));
|
||||
nfc_scene_slix_build_string(temp_str, nfcv_data, SlixFeatureSlix, "SLIX");
|
||||
break;
|
||||
case NfcVTypeSlixS:
|
||||
furi_string_cat_printf(temp_str, "Type: SLIX-S\n");
|
||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Read %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_read, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Write %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_write, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Privacy %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_privacy, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Destroy %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_destroy, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" EAS %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4));
|
||||
nfc_scene_slix_build_string(temp_str, nfcv_data, SlixFeatureSlixS, "SLIX-S");
|
||||
break;
|
||||
case NfcVTypeSlixL:
|
||||
furi_string_cat_printf(temp_str, "Type: SLIX-L\n");
|
||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Privacy %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_privacy, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Destroy %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_destroy, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" EAS %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4));
|
||||
nfc_scene_slix_build_string(temp_str, nfcv_data, SlixFeatureSlixL, "SLIX-L");
|
||||
break;
|
||||
case NfcVTypeSlix2:
|
||||
furi_string_cat_printf(temp_str, "Type: SLIX2\n");
|
||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Read %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_read, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Write %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_write, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Privacy %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_privacy, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" Destroy %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_destroy, 4));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
" EAS %08llX\n",
|
||||
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4));
|
||||
nfc_scene_slix_build_string(temp_str, nfcv_data, SlixFeatureSlix2, "SLIX2");
|
||||
break;
|
||||
default:
|
||||
furi_string_cat_printf(temp_str, "\e#ISO15693 (unknown)\n");
|
||||
|
||||
@ -16,7 +16,6 @@ void nfc_scene_nfcv_read_success_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
NfcDeviceData* dev_data = &nfc->dev->dev_data;
|
||||
FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
|
||||
NfcVData* nfcv_data = &nfc->dev->dev_data.nfcv_data;
|
||||
// Setup view
|
||||
Widget* widget = nfc->widget;
|
||||
widget_add_button_element(
|
||||
@ -46,13 +45,12 @@ void nfc_scene_nfcv_read_success_on_enter(void* context) {
|
||||
furi_string_cat_printf(temp_str, "\e#ISO15693 (unknown)\n");
|
||||
break;
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "UID:");
|
||||
furi_string_cat_printf(temp_str, "UID:\n");
|
||||
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
||||
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "\n");
|
||||
furi_string_cat_printf(temp_str, "Blocks: %02X\n", nfcv_data->block_num);
|
||||
furi_string_cat_printf(temp_str, "Blocksize: %02X\n", nfcv_data->block_size);
|
||||
furi_string_cat_printf(temp_str, "(see More->Info for details)\n");
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
@ -76,12 +76,15 @@ void subghz_chat_worker_free(SubGhzChatWorker* instance) {
|
||||
free(instance);
|
||||
}
|
||||
|
||||
bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency) {
|
||||
bool subghz_chat_worker_start(
|
||||
SubGhzChatWorker* instance,
|
||||
const SubGhzDevice* device,
|
||||
uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
bool res = false;
|
||||
|
||||
if(subghz_tx_rx_worker_start(instance->subghz_txrx, frequency)) {
|
||||
if(subghz_tx_rx_worker_start(instance->subghz_txrx, device, frequency)) {
|
||||
furi_message_queue_reset(instance->event_queue);
|
||||
subghz_tx_rx_worker_set_callback_have_read(
|
||||
instance->subghz_txrx, subghz_chat_worker_update_rx_event_chat, instance);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "../subghz_i.h"
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
#include <cli/cli.h>
|
||||
|
||||
typedef struct SubGhzChatWorker SubGhzChatWorker;
|
||||
@ -20,7 +21,10 @@ typedef struct {
|
||||
|
||||
SubGhzChatWorker* subghz_chat_worker_alloc(Cli* cli);
|
||||
void subghz_chat_worker_free(SubGhzChatWorker* instance);
|
||||
bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency);
|
||||
bool subghz_chat_worker_start(
|
||||
SubGhzChatWorker* instance,
|
||||
const SubGhzDevice* device,
|
||||
uint32_t frequency);
|
||||
void subghz_chat_worker_stop(SubGhzChatWorker* instance);
|
||||
bool subghz_chat_worker_is_running(SubGhzChatWorker* instance);
|
||||
SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance);
|
||||
|
||||
@ -27,10 +27,15 @@ TUPLE_DEF2(
|
||||
(rssi_max, uint8_t))
|
||||
/* Register globally the oplist */
|
||||
#define M_OPL_SubGhzFrequencyAnalyzerLogItem_t() \
|
||||
TUPLE_OPLIST(SubGhzFrequencyAnalyzerLogItem, M_POD_OPLIST, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
|
||||
TUPLE_OPLIST( \
|
||||
SubGhzFrequencyAnalyzerLogItem, \
|
||||
M_DEFAULT_OPLIST, \
|
||||
M_DEFAULT_OPLIST, \
|
||||
M_DEFAULT_OPLIST, \
|
||||
M_DEFAULT_OPLIST)
|
||||
|
||||
/* Define the array, register the oplist and define further algorithms on it */
|
||||
ARRAY_DEF(SubGhzFrequencyAnalyzerLogItemArray, SubGhzFrequencyAnalyzerLogItem_t)
|
||||
ARRAY_DEF(SubGhzFrequencyAnalyzerLogItemArray, SubGhzFrequencyAnalyzerLogItem_t) //-V779
|
||||
#define M_OPL_SubGhzFrequencyAnalyzerLogItemArray_t() \
|
||||
ARRAY_OPLIST(SubGhzFrequencyAnalyzerLogItemArray, M_OPL_SubGhzFrequencyAnalyzerLogItem_t())
|
||||
ALGO_DEF(SubGhzFrequencyAnalyzerLogItemArray, SubGhzFrequencyAnalyzerLogItemArray_t)
|
||||
|
||||
@ -32,9 +32,8 @@ float subghz_threshold_rssi_get(SubGhzThresholdRssi* instance) {
|
||||
return instance->threshold_rssi;
|
||||
}
|
||||
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance) {
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance, float rssi) {
|
||||
furi_assert(instance);
|
||||
float rssi = furi_hal_subghz_get_rssi();
|
||||
SubGhzThresholdRssiData ret = {.rssi = rssi, .is_above = false};
|
||||
|
||||
if(float_is_equal(instance->threshold_rssi, SUBGHZ_RAW_THRESHOLD_MIN)) {
|
||||
|
||||
@ -38,6 +38,7 @@ float subghz_threshold_rssi_get(SubGhzThresholdRssi* instance);
|
||||
/** Check threshold
|
||||
*
|
||||
* @param instance Pointer to a SubGhzThresholdRssi
|
||||
* @param rssi Current RSSI
|
||||
* @return SubGhzThresholdRssiData
|
||||
*/
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance);
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance, float rssi);
|
||||
|
||||
@ -1,9 +1,32 @@
|
||||
#include "subghz_txrx_i.h"
|
||||
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
||||
|
||||
#define TAG "SubGhz"
|
||||
|
||||
static void subghz_txrx_radio_device_power_on(SubGhzTxRx* instance) {
|
||||
UNUSED(instance);
|
||||
uint8_t attempts = 5;
|
||||
while(--attempts > 0) {
|
||||
if(furi_hal_power_enable_otg()) break;
|
||||
}
|
||||
if(attempts == 0) {
|
||||
if(furi_hal_power_get_usb_voltage() < 4.5f) {
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"Error power otg enable. BQ2589 check otg fault = %d",
|
||||
furi_hal_power_check_otg_fault() ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_txrx_radio_device_power_off(SubGhzTxRx* instance) {
|
||||
UNUSED(instance);
|
||||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
SubGhzTxRx* subghz_txrx_alloc() {
|
||||
SubGhzTxRx* instance = malloc(sizeof(SubGhzTxRx));
|
||||
instance->setting = subghz_setting_alloc();
|
||||
@ -23,16 +46,15 @@ SubGhzTxRx* subghz_txrx_alloc() {
|
||||
instance->fff_data = flipper_format_string_alloc();
|
||||
|
||||
instance->environment = subghz_environment_alloc();
|
||||
instance->is_database_loaded = subghz_environment_load_keystore(
|
||||
instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
||||
subghz_environment_load_keystore(
|
||||
instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
||||
instance->is_database_loaded =
|
||||
subghz_environment_load_keystore(instance->environment, SUBGHZ_KEYSTORE_DIR_NAME);
|
||||
subghz_environment_load_keystore(instance->environment, SUBGHZ_KEYSTORE_DIR_USER_NAME);
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
instance->environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/alutech_at_4n"));
|
||||
instance->environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
instance->environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(
|
||||
instance->environment, (void*)&subghz_protocol_registry);
|
||||
instance->receiver = subghz_receiver_alloc_init(instance->environment);
|
||||
@ -43,18 +65,32 @@ SubGhzTxRx* subghz_txrx_alloc() {
|
||||
instance->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
|
||||
subghz_worker_set_context(instance->worker, instance->receiver);
|
||||
|
||||
//set default device External
|
||||
subghz_devices_init();
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeInternal;
|
||||
instance->radio_device_type =
|
||||
subghz_txrx_radio_device_set(instance, SubGhzRadioDeviceTypeExternalCC1101);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_txrx_free(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
if(instance->radio_device_type != SubGhzRadioDeviceTypeInternal) {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
subghz_devices_end(instance->radio_device);
|
||||
}
|
||||
|
||||
subghz_devices_deinit();
|
||||
|
||||
subghz_worker_free(instance->worker);
|
||||
subghz_receiver_free(instance->receiver);
|
||||
subghz_environment_free(instance->environment);
|
||||
flipper_format_free(instance->fff_data);
|
||||
furi_string_free(instance->preset->name);
|
||||
subghz_setting_free(instance->setting);
|
||||
|
||||
free(instance->preset);
|
||||
free(instance);
|
||||
}
|
||||
@ -122,29 +158,26 @@ void subghz_txrx_get_frequency_and_modulation(
|
||||
|
||||
static void subghz_txrx_begin(SubGhzTxRx* instance, uint8_t* preset_data) {
|
||||
furi_assert(instance);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_custom_preset(preset_data);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_devices_reset(instance->radio_device);
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_devices_load_preset(instance->radio_device, FuriHalSubGhzPresetCustom, preset_data);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
static uint32_t subghz_txrx_rx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("SubGhz: Incorrect RX frequency.");
|
||||
}
|
||||
|
||||
furi_assert(
|
||||
instance->txrx_state != SubGhzTxRxStateRx && instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_flush_rx();
|
||||
subghz_txrx_speaker_on(instance);
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, instance->worker);
|
||||
uint32_t value = subghz_devices_set_frequency(instance->radio_device, frequency);
|
||||
subghz_devices_flush_rx(instance->radio_device);
|
||||
subghz_txrx_speaker_on(instance);
|
||||
|
||||
subghz_devices_start_async_rx(
|
||||
instance->radio_device, subghz_worker_rx_callback, instance->worker);
|
||||
subghz_worker_start(instance->worker);
|
||||
instance->txrx_state = SubGhzTxRxStateRx;
|
||||
return value;
|
||||
@ -153,7 +186,7 @@ static uint32_t subghz_txrx_rx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
static void subghz_txrx_idle(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
@ -164,30 +197,26 @@ static void subghz_txrx_rx_end(SubGhzTxRx* instance) {
|
||||
|
||||
if(subghz_worker_is_running(instance->worker)) {
|
||||
subghz_worker_stop(instance->worker);
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
subghz_devices_stop_async_rx(instance->radio_device);
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
void subghz_txrx_sleep(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(instance->radio_device);
|
||||
instance->txrx_state = SubGhzTxRxStateSleep;
|
||||
}
|
||||
|
||||
static bool subghz_txrx_tx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("SubGhz: Incorrect TX frequency.");
|
||||
}
|
||||
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, false);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
bool ret = furi_hal_subghz_tx();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_devices_set_frequency(instance->radio_device, frequency);
|
||||
|
||||
bool ret = subghz_devices_set_tx(instance->radio_device);
|
||||
if(ret) {
|
||||
subghz_txrx_speaker_on(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateTx;
|
||||
@ -249,8 +278,8 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
|
||||
|
||||
if(ret == SubGhzTxRxStartTxStateOk) {
|
||||
//Start TX
|
||||
furi_hal_subghz_start_async_tx(
|
||||
subghz_transmitter_yield, instance->transmitter);
|
||||
subghz_devices_start_async_tx(
|
||||
instance->radio_device, subghz_transmitter_yield, instance->transmitter);
|
||||
}
|
||||
} else {
|
||||
ret = SubGhzTxRxStartTxStateErrorParserOthers;
|
||||
@ -293,7 +322,7 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->txrx_state == SubGhzTxRxStateTx);
|
||||
//Stop TX
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
subghz_devices_stop_async_tx(instance->radio_device);
|
||||
subghz_transmitter_stop(instance->transmitter);
|
||||
subghz_transmitter_free(instance->transmitter);
|
||||
|
||||
@ -306,7 +335,6 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
|
||||
subghz_txrx_idle(instance);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
//Todo: Show message
|
||||
// notification_message(notifications, &sequence_reset_red);
|
||||
}
|
||||
|
||||
FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) {
|
||||
@ -356,7 +384,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance) {
|
||||
float rssi = -127.0f;
|
||||
if(instance->hopper_state != SubGhzHopperStateRSSITimeOut) {
|
||||
// See RSSI Calculation timings in CC1101 17.3 RSSI
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
rssi = subghz_devices_get_rssi(instance->radio_device);
|
||||
|
||||
// Stay if RSSI is high enough
|
||||
if(rssi > -90.0f) {
|
||||
@ -414,7 +442,7 @@ void subghz_txrx_speaker_on(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_acquire(30)) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_speaker);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_speaker);
|
||||
} else {
|
||||
instance->speaker_state = SubGhzSpeakerStateDisable;
|
||||
}
|
||||
@ -425,7 +453,7 @@ void subghz_txrx_speaker_off(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->speaker_state != SubGhzSpeakerStateDisable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
furi_hal_speaker_release();
|
||||
if(instance->speaker_state == SubGhzSpeakerStateShutdown)
|
||||
instance->speaker_state = SubGhzSpeakerStateDisable;
|
||||
@ -437,7 +465,7 @@ void subghz_txrx_speaker_mute(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -446,7 +474,7 @@ void subghz_txrx_speaker_unmute(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_speaker);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_speaker);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -519,3 +547,66 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end(
|
||||
callback,
|
||||
context);
|
||||
}
|
||||
|
||||
bool subghz_txrx_radio_device_is_external_connected(SubGhzTxRx* instance, const char* name) {
|
||||
furi_assert(instance);
|
||||
|
||||
bool is_connect = false;
|
||||
bool is_otg_enabled = furi_hal_power_is_otg_enabled();
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
subghz_txrx_radio_device_power_on(instance);
|
||||
}
|
||||
|
||||
const SubGhzDevice* device = subghz_devices_get_by_name(name);
|
||||
if(device) {
|
||||
is_connect = subghz_devices_is_connect(device);
|
||||
}
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
}
|
||||
return is_connect;
|
||||
}
|
||||
|
||||
SubGhzRadioDeviceType
|
||||
subghz_txrx_radio_device_set(SubGhzTxRx* instance, SubGhzRadioDeviceType radio_device_type) {
|
||||
furi_assert(instance);
|
||||
|
||||
if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 &&
|
||||
subghz_txrx_radio_device_is_external_connected(instance, SUBGHZ_DEVICE_CC1101_EXT_NAME)) {
|
||||
subghz_txrx_radio_device_power_on(instance);
|
||||
instance->radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
||||
subghz_devices_begin(instance->radio_device);
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeExternalCC1101;
|
||||
} else {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
if(instance->radio_device_type != SubGhzRadioDeviceTypeInternal) {
|
||||
subghz_devices_end(instance->radio_device);
|
||||
}
|
||||
instance->radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeInternal;
|
||||
}
|
||||
|
||||
return instance->radio_device_type;
|
||||
}
|
||||
|
||||
SubGhzRadioDeviceType subghz_txrx_radio_device_get(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->radio_device_type;
|
||||
}
|
||||
|
||||
float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_get_rssi(instance->radio_device);
|
||||
}
|
||||
|
||||
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_get_name(instance->radio_device);
|
||||
}
|
||||
|
||||
bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_is_frequency_valid(instance->radio_device, frequency);
|
||||
}
|
||||
@ -7,6 +7,7 @@
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/protocols/raw.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
typedef struct SubGhzTxRx SubGhzTxRx;
|
||||
|
||||
@ -288,3 +289,48 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end(
|
||||
SubGhzTxRx* instance,
|
||||
SubGhzProtocolEncoderRAWCallbackEnd callback,
|
||||
void* context);
|
||||
|
||||
/* Checking if an external radio device is connected
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @param name Name of external radio device
|
||||
* @return bool True if is connected to the external radio device
|
||||
*/
|
||||
bool subghz_txrx_radio_device_is_external_connected(SubGhzTxRx* instance, const char* name);
|
||||
|
||||
/* Set the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @param radio_device_type Radio device type
|
||||
* @return SubGhzRadioDeviceType Type of installed radio device
|
||||
*/
|
||||
SubGhzRadioDeviceType
|
||||
subghz_txrx_radio_device_set(SubGhzTxRx* instance, SubGhzRadioDeviceType radio_device_type);
|
||||
|
||||
/* Get the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return SubGhzRadioDeviceType Type of installed radio device
|
||||
*/
|
||||
SubGhzRadioDeviceType subghz_txrx_radio_device_get(SubGhzTxRx* instance);
|
||||
|
||||
/* Get RSSI the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return float RSSI
|
||||
*/
|
||||
float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance);
|
||||
|
||||
/* Get name the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return const char* Name of installed radio device
|
||||
*/
|
||||
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
|
||||
|
||||
/* Get get intelligence whether frequency the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return bool True if the frequency is valid
|
||||
*/
|
||||
bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency);
|
||||
@ -21,6 +21,8 @@ struct SubGhzTxRx {
|
||||
|
||||
SubGhzTxRxState txrx_state;
|
||||
SubGhzSpeakerState speaker_state;
|
||||
const SubGhzDevice* radio_device;
|
||||
SubGhzRadioDeviceType radio_device_type;
|
||||
|
||||
SubGhzTxRxNeedSaveCallback need_save_callback;
|
||||
void* need_save_context;
|
||||
|
||||
@ -35,6 +35,13 @@ typedef enum {
|
||||
SubGhzSpeakerStateEnable,
|
||||
} SubGhzSpeakerState;
|
||||
|
||||
/** SubGhzRadioDeviceType */
|
||||
typedef enum {
|
||||
SubGhzRadioDeviceTypeAuto,
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
} SubGhzRadioDeviceType;
|
||||
|
||||
/** SubGhzRxKeyState state */
|
||||
typedef enum {
|
||||
SubGhzRxKeyStateIDLE,
|
||||
|
||||
@ -24,3 +24,4 @@ ADD_SCENE(subghz, delete_raw, DeleteRAW)
|
||||
ADD_SCENE(subghz, need_saving, NeedSaving)
|
||||
ADD_SCENE(subghz, rpc, Rpc)
|
||||
ADD_SCENE(subghz, region_info, RegionInfo)
|
||||
ADD_SCENE(subghz, radio_settings, RadioSettings)
|
||||
|
||||
70
applications/main/subghz/scenes/subghz_scene_radio_setting.c
Normal file
70
applications/main/subghz/scenes/subghz_scene_radio_setting.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include "../subghz_i.h"
|
||||
#include <lib/toolbox/value_index.h>
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
|
||||
enum SubGhzRadioSettingIndex {
|
||||
SubGhzRadioSettingIndexDevice,
|
||||
};
|
||||
|
||||
#define RADIO_DEVICE_COUNT 2
|
||||
const char* const radio_device_text[RADIO_DEVICE_COUNT] = {
|
||||
"Internal",
|
||||
"External",
|
||||
};
|
||||
|
||||
const uint32_t radio_device_value[RADIO_DEVICE_COUNT] = {
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
};
|
||||
|
||||
static void subghz_scene_radio_settings_set_device(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
if(!subghz_txrx_radio_device_is_external_connected(
|
||||
subghz->txrx, SUBGHZ_DEVICE_CC1101_EXT_NAME) &&
|
||||
radio_device_value[index] == SubGhzRadioDeviceTypeExternalCC1101) {
|
||||
//ToDo correct if there is more than 1 module
|
||||
index = 0;
|
||||
}
|
||||
variable_item_set_current_value_text(item, radio_device_text[index]);
|
||||
subghz_txrx_radio_device_set(subghz->txrx, radio_device_value[index]);
|
||||
}
|
||||
|
||||
void subghz_scene_radio_settings_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
uint8_t value_count_device = RADIO_DEVICE_COUNT;
|
||||
if(subghz_txrx_radio_device_get(subghz->txrx) == SubGhzRadioDeviceTypeInternal &&
|
||||
!subghz_txrx_radio_device_is_external_connected(subghz->txrx, SUBGHZ_DEVICE_CC1101_EXT_NAME))
|
||||
value_count_device = 1;
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Module",
|
||||
value_count_device,
|
||||
subghz_scene_radio_settings_set_device,
|
||||
subghz);
|
||||
value_index = value_index_uint32(
|
||||
subghz_txrx_radio_device_get(subghz->txrx), radio_device_value, value_count_device);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, radio_device_text[value_index]);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
|
||||
}
|
||||
|
||||
bool subghz_scene_radio_settings_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
bool consumed = false;
|
||||
UNUSED(subghz);
|
||||
UNUSED(event);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void subghz_scene_radio_settings_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
|
||||
variable_item_list_reset(subghz->variable_item_list);
|
||||
}
|
||||
@ -48,6 +48,9 @@ static void subghz_scene_read_raw_update_statusbar(void* context) {
|
||||
|
||||
furi_string_free(frequency_str);
|
||||
furi_string_free(modulation_str);
|
||||
|
||||
subghz_read_raw_set_radio_device_type(
|
||||
subghz->subghz_read_raw, subghz_txrx_radio_device_get(subghz->txrx));
|
||||
}
|
||||
|
||||
void subghz_scene_read_raw_callback(SubGhzCustomEvent event, void* context) {
|
||||
@ -238,7 +241,9 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
furi_string_printf(
|
||||
temp_str, "%s/%s%s", SUBGHZ_RAW_FOLDER, RAW_FILE_NAME, SUBGHZ_APP_EXTENSION);
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
subghz_txrx_get_fff_data(subghz->txrx), furi_string_get_cstr(temp_str));
|
||||
subghz_txrx_get_fff_data(subghz->txrx),
|
||||
furi_string_get_cstr(temp_str),
|
||||
subghz_txrx_radio_device_get_name(subghz->txrx));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
if(spl_count > 0) {
|
||||
@ -298,8 +303,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
subghz_read_raw_update_sample_write(
|
||||
subghz->subghz_read_raw, subghz_protocol_raw_get_sample_write(decoder_raw));
|
||||
|
||||
SubGhzThresholdRssiData ret_rssi =
|
||||
subghz_threshold_get_rssi_data(subghz->threshold_rssi);
|
||||
SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(
|
||||
subghz->threshold_rssi, subghz_txrx_radio_device_get_rssi(subghz->txrx));
|
||||
subghz_read_raw_add_data_rssi(
|
||||
subghz->subghz_read_raw, ret_rssi.rssi, ret_rssi.is_above);
|
||||
subghz_protocol_raw_save_to_file_pause(decoder_raw, !ret_rssi.is_above);
|
||||
|
||||
@ -56,6 +56,9 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
}
|
||||
furi_string_free(history_stat_str);
|
||||
|
||||
subghz_view_receiver_set_radio_device_type(
|
||||
subghz->subghz_receiver, subghz_txrx_radio_device_get(subghz->txrx));
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_callback(SubGhzCustomEvent event, void* context) {
|
||||
@ -189,7 +192,8 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
||||
subghz_scene_receiver_update_statusbar(subghz);
|
||||
}
|
||||
|
||||
SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(subghz->threshold_rssi);
|
||||
SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(
|
||||
subghz->threshold_rssi, subghz_txrx_radio_device_get_rssi(subghz->txrx));
|
||||
|
||||
subghz_receiver_rssi(subghz->subghz_receiver, ret_rssi.rssi);
|
||||
subghz_protocol_decoder_bin_raw_data_input_rssi(
|
||||
|
||||
@ -122,7 +122,8 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhzCustomEventManagerNoSet) {
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
subghz_txrx_get_fff_data(subghz->txrx),
|
||||
furi_string_get_cstr(subghz->file_path));
|
||||
furi_string_get_cstr(subghz->file_path),
|
||||
subghz_txrx_radio_device_get_name(subghz->txrx));
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
||||
} else {
|
||||
|
||||
@ -8,7 +8,8 @@ enum SubmenuIndex {
|
||||
SubmenuIndexAddManually,
|
||||
SubmenuIndexFrequencyAnalyzer,
|
||||
SubmenuIndexReadRAW,
|
||||
SubmenuIndexShowRegionInfo
|
||||
SubmenuIndexShowRegionInfo,
|
||||
SubmenuIndexRadioSetting,
|
||||
};
|
||||
|
||||
void subghz_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
@ -49,6 +50,12 @@ void subghz_scene_start_on_enter(void* context) {
|
||||
SubmenuIndexShowRegionInfo,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Radio Settings",
|
||||
SubmenuIndexRadioSetting,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz);
|
||||
@ -104,6 +111,11 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexShowRegionInfo);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneRegionInfo);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexRadioSetting) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRadioSetting);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneRadioSettings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -35,6 +35,8 @@ bool subghz_scene_transmitter_update_data_show(void* context) {
|
||||
furi_string_free(modulation_str);
|
||||
furi_string_free(key_str);
|
||||
}
|
||||
subghz_view_transmitter_set_radio_device_type(
|
||||
subghz->subghz_transmitter, subghz_txrx_radio_device_get(subghz->txrx));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,10 @@
|
||||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/subghz_file_encoder_worker.h>
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include "helpers/subghz_chat.h"
|
||||
|
||||
@ -24,6 +28,19 @@
|
||||
|
||||
#define SUBGHZ_REGION_FILENAME "/int/.region_data"
|
||||
|
||||
static void subghz_cli_radio_device_power_on() {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
//CC1101 power-up time
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_cli_radio_device_power_off() {
|
||||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx_carrier(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
@ -44,7 +61,7 @@ void subghz_cli_command_tx_carrier(Cli* cli, FuriString* args, void* context) {
|
||||
}
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
@ -88,7 +105,7 @@ void subghz_cli_command_rx_carrier(Cli* cli, FuriString* args, void* context) {
|
||||
}
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
printf("Receiving at frequency %lu Hz\r\n", frequency);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
@ -109,44 +126,70 @@ void subghz_cli_command_rx_carrier(Cli* cli, FuriString* args, void* context) {
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
static const SubGhzDevice* subghz_cli_command_get_device(uint32_t device_ind) {
|
||||
const SubGhzDevice* device = NULL;
|
||||
switch(device_ind) {
|
||||
case 1:
|
||||
subghz_cli_radio_device_power_on();
|
||||
device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
||||
break;
|
||||
|
||||
default:
|
||||
device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
break;
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
uint32_t key = 0x0074BADE;
|
||||
uint32_t repeat = 10;
|
||||
uint32_t te = 403;
|
||||
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
int ret =
|
||||
sscanf(furi_string_get_cstr(args), "%lx %lu %lu %lu", &key, &frequency, &te, &repeat);
|
||||
if(ret != 4) {
|
||||
int ret = sscanf(
|
||||
furi_string_get_cstr(args),
|
||||
"%lx %lu %lu %lu %lu",
|
||||
&key,
|
||||
&frequency,
|
||||
&te,
|
||||
&repeat,
|
||||
&device_ind);
|
||||
if(ret != 5) {
|
||||
printf(
|
||||
"sscanf returned %d, key: %lx, frequency: %lu, te:%lu, repeat: %lu\r\n",
|
||||
"sscanf returned %d, key: %lx, frequency: %lu, te: %lu, repeat: %lu, device: %lu\r\n ",
|
||||
ret,
|
||||
key,
|
||||
frequency,
|
||||
te,
|
||||
repeat);
|
||||
repeat,
|
||||
device_ind);
|
||||
cli_print_usage(
|
||||
"subghz tx",
|
||||
"<3 Byte Key: in hex> <Frequency: in Hz> <Te us> <Repeat count>",
|
||||
"<3 Byte Key: in hex> <Frequency: in Hz> <Te us> <Repeat count> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
||||
furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
subghz_devices_init();
|
||||
const SubGhzDevice* device = subghz_cli_command_get_device(device_ind);
|
||||
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
return;
|
||||
}
|
||||
printf(
|
||||
"Transmitting at %lu, key %lx, te %lu, repeat %lu. Press CTRL+C to stop\r\n",
|
||||
"Transmitting at %lu, key %lx, te %lu, repeat %lu device %lu. Press CTRL+C to stop\r\n",
|
||||
frequency,
|
||||
key,
|
||||
te,
|
||||
repeat);
|
||||
repeat,
|
||||
device_ind);
|
||||
|
||||
FuriString* flipper_format_string = furi_string_alloc_printf(
|
||||
"Protocol: Princeton\n"
|
||||
@ -170,25 +213,29 @@ void subghz_cli_command_tx(Cli* cli, FuriString* args, void* context) {
|
||||
SubGhzTransmitter* transmitter = subghz_transmitter_alloc_init(environment, "Princeton");
|
||||
subghz_transmitter_deserialize(transmitter, flipper_format);
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
subghz_devices_begin(device);
|
||||
subghz_devices_reset(device);
|
||||
subghz_devices_load_preset(device, FuriHalSubGhzPresetOok650Async, NULL);
|
||||
frequency = subghz_devices_set_frequency(device, frequency);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
if(furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter)) {
|
||||
while(!(furi_hal_subghz_is_async_tx_complete() || cli_cmd_interrupt_received(cli))) {
|
||||
if(subghz_devices_start_async_tx(device, subghz_transmitter_yield, transmitter)) {
|
||||
while(!(subghz_devices_is_async_complete_tx(device) || cli_cmd_interrupt_received(cli))) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
furi_delay_ms(333);
|
||||
}
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
subghz_devices_stop_async_tx(device);
|
||||
|
||||
} else {
|
||||
printf("Transmission on this frequency is restricted in your region\r\n");
|
||||
}
|
||||
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(device);
|
||||
subghz_devices_end(device);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
flipper_format_free(flipper_format);
|
||||
@ -233,21 +280,29 @@ static void subghz_cli_command_rx_callback(
|
||||
void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz rx", "<Frequency: in Hz>", furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu %lu", &frequency, &device_ind);
|
||||
if(ret != 2) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
"sscanf returned %d, frequency: %lu device: %lu\r\n", ret, frequency, device_ind);
|
||||
cli_print_usage(
|
||||
"subghz rx",
|
||||
"<Frequency: in Hz> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
||||
furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
}
|
||||
subghz_devices_init();
|
||||
const SubGhzDevice* device = subghz_cli_command_get_device(device_ind);
|
||||
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
return;
|
||||
}
|
||||
|
||||
// Allocate context and buffers
|
||||
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
||||
@ -256,14 +311,14 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
||||
furi_check(instance->stream);
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
||||
subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
||||
subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME);
|
||||
subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME);
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/alutech_at_4n"));
|
||||
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
@ -271,18 +326,21 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
||||
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
|
||||
|
||||
// Configure radio
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_devices_begin(device);
|
||||
subghz_devices_reset(device);
|
||||
subghz_devices_load_preset(device, FuriHalSubGhzPresetOok650Async, NULL);
|
||||
frequency = subghz_devices_set_frequency(device, frequency);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
// Prepare and start RX
|
||||
furi_hal_subghz_start_async_rx(subghz_cli_command_rx_capture_callback, instance);
|
||||
subghz_devices_start_async_rx(device, subghz_cli_command_rx_capture_callback, instance);
|
||||
|
||||
// Wait for packets to arrive
|
||||
printf("Listening at %lu. Press CTRL+C to stop\r\n", frequency);
|
||||
printf(
|
||||
"Listening at frequency: %lu device: %lu. Press CTRL+C to stop\r\n",
|
||||
frequency,
|
||||
device_ind);
|
||||
LevelDuration level_duration;
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
int ret = furi_stream_buffer_receive(
|
||||
@ -300,8 +358,11 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
||||
}
|
||||
|
||||
// Shutdown radio
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_stop_async_rx(device);
|
||||
subghz_devices_sleep(device);
|
||||
subghz_devices_end(device);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
@ -341,7 +402,7 @@ void subghz_cli_command_rx_raw(Cli* cli, FuriString* args, void* context) {
|
||||
|
||||
// Configure radio
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok270Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_270khz_async_regs);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
@ -389,6 +450,7 @@ void subghz_cli_command_rx_raw(Cli* cli, FuriString* args, void* context) {
|
||||
furi_stream_buffer_free(instance->stream);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
FuriString* file_name;
|
||||
@ -442,25 +504,23 @@ void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
||||
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
if(subghz_environment_load_keystore(
|
||||
environment, EXT_PATH("subghz/assets/keeloq_mfcodes"))) {
|
||||
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME)) {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
if(subghz_environment_load_keystore(
|
||||
environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"))) {
|
||||
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME)) {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf(
|
||||
"SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/alutech_at_4n"));
|
||||
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
@ -468,7 +528,8 @@ void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
||||
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
|
||||
|
||||
SubGhzFileEncoderWorker* file_worker_encoder = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder, furi_string_get_cstr(file_name))) {
|
||||
if(subghz_file_encoder_worker_start(
|
||||
file_worker_encoder, furi_string_get_cstr(file_name), NULL)) {
|
||||
//the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
}
|
||||
@ -510,10 +571,11 @@ static void subghz_cli_command_print_usage() {
|
||||
printf("subghz <cmd> <args>\r\n");
|
||||
printf("Cmd list:\r\n");
|
||||
|
||||
printf("\tchat <frequency:in Hz>\t - Chat with other Flippers\r\n");
|
||||
printf(
|
||||
"\ttx <3 byte Key: in hex> <frequency: in Hz> <te: us> <repeat: count>\t - Transmitting key\r\n");
|
||||
printf("\trx <frequency:in Hz>\t - Receive\r\n");
|
||||
"\tchat <frequency:in Hz> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Chat with other Flippers\r\n");
|
||||
printf(
|
||||
"\ttx <3 byte Key: in hex> <frequency: in Hz> <te: us> <repeat: count> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Transmitting key\r\n");
|
||||
printf("\trx <frequency:in Hz> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Receive\r\n");
|
||||
printf("\trx_raw <frequency:in Hz>\t - Receive RAW\r\n");
|
||||
printf("\tdecode_raw <file_name: path_RAW_file>\t - Testing\r\n");
|
||||
|
||||
@ -611,21 +673,29 @@ static void subghz_cli_command_encrypt_raw(Cli* cli, FuriString* args) {
|
||||
|
||||
static void subghz_cli_command_chat(Cli* cli, FuriString* args) {
|
||||
uint32_t frequency = 433920000;
|
||||
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz chat", "<Frequency: in Hz>", furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu %lu", &frequency, &device_ind);
|
||||
if(ret != 2) {
|
||||
printf("sscanf returned %d, Frequency: %lu\r\n", ret, frequency);
|
||||
printf("sscanf returned %d, Device: %lu\r\n", ret, device_ind);
|
||||
cli_print_usage(
|
||||
"subghz chat",
|
||||
"<Frequency: in Hz> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
||||
furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
}
|
||||
subghz_devices_init();
|
||||
const SubGhzDevice* device = subghz_cli_command_get_device(device_ind);
|
||||
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_region_is_frequency_allowed(frequency)) {
|
||||
printf(
|
||||
"In your region, only reception on this frequency (%lu) is allowed,\r\n"
|
||||
@ -635,7 +705,8 @@ static void subghz_cli_command_chat(Cli* cli, FuriString* args) {
|
||||
}
|
||||
|
||||
SubGhzChatWorker* subghz_chat = subghz_chat_worker_alloc(cli);
|
||||
if(!subghz_chat_worker_start(subghz_chat, frequency)) {
|
||||
|
||||
if(!subghz_chat_worker_start(subghz_chat, device, frequency)) {
|
||||
printf("Startup error SubGhzChatWorker\r\n");
|
||||
|
||||
if(subghz_chat_worker_is_running(subghz_chat)) {
|
||||
@ -781,6 +852,10 @@ static void subghz_cli_command_chat(Cli* cli, FuriString* args) {
|
||||
furi_string_free(name);
|
||||
furi_string_free(output);
|
||||
furi_string_free(sysmsg);
|
||||
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
|
||||
|
||||
@ -115,7 +115,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
if(!subghz_txrx_radio_device_is_frequecy_valid(subghz->txrx, temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Frequency not supported");
|
||||
break;
|
||||
}
|
||||
@ -163,7 +163,8 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
|
||||
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
|
||||
//if RAW
|
||||
subghz->load_type_file = SubGhzLoadTypeFileRaw;
|
||||
subghz_protocol_raw_gen_fff_data(fff_data, file_path);
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
fff_data, file_path, subghz_txrx_radio_device_get_name(subghz->txrx));
|
||||
} else {
|
||||
subghz->load_type_file = SubGhzLoadTypeFileKey;
|
||||
stream_copy_full(
|
||||
|
||||
@ -62,6 +62,7 @@ typedef struct {
|
||||
uint16_t history_item;
|
||||
SubGhzViewReceiverBarShow bar_show;
|
||||
uint8_t u_rssi;
|
||||
SubGhzRadioDeviceType device_type;
|
||||
} SubGhzViewReceiverModel;
|
||||
|
||||
void subghz_receiver_rssi(SubGhzViewReceiver* instance, float rssi) {
|
||||
@ -173,6 +174,17 @@ void subghz_view_receiver_add_data_statusbar(
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_view_receiver_set_radio_device_type(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
SubGhzRadioDeviceType device_type) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->device_type = device_type; },
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, 0, 0 + idx * FRAME_HEIGHT, scrollbar ? 122 : 127, FRAME_HEIGHT);
|
||||
@ -190,9 +202,9 @@ static void subghz_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool s
|
||||
static void subghz_view_rssi_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
||||
for(uint8_t i = 1; i < model->u_rssi; i++) {
|
||||
if(i % 5) {
|
||||
canvas_draw_dot(canvas, 46 + i, 50);
|
||||
canvas_draw_dot(canvas, 47 + i, 51);
|
||||
canvas_draw_dot(canvas, 46 + i, 52);
|
||||
canvas_draw_dot(canvas, 47 + i, 53);
|
||||
canvas_draw_dot(canvas, 46 + i, 54);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -232,22 +244,28 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
if(model->history_item == 0) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Scanning_123x52);
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Scanning_short_96x52);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 63, 44, "Scanning...");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
}
|
||||
|
||||
if(model->device_type == SubGhzRadioDeviceTypeInternal) {
|
||||
canvas_draw_icon(canvas, 108, 0, &I_Internal_antenna_20x12);
|
||||
} else {
|
||||
canvas_draw_icon(canvas, 108, 0, &I_External_antenna_20x12);
|
||||
}
|
||||
|
||||
subghz_view_rssi_draw(canvas, model);
|
||||
switch(model->bar_show) {
|
||||
case SubGhzViewReceiverBarShowLock:
|
||||
canvas_draw_icon(canvas, 64, 55, &I_Lock_7x8);
|
||||
canvas_draw_str(canvas, 74, 62, "Locked");
|
||||
canvas_draw_icon(canvas, 64, 56, &I_Lock_7x8);
|
||||
canvas_draw_str(canvas, 74, 64, "Locked");
|
||||
break;
|
||||
case SubGhzViewReceiverBarShowToUnlockPress:
|
||||
canvas_draw_str(canvas, 44, 62, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 96, 62, furi_string_get_cstr(model->history_stat_str));
|
||||
canvas_draw_str(canvas, 44, 64, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 79, 64, furi_string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 97, 64, furi_string_get_cstr(model->history_stat_str));
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
|
||||
elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
|
||||
@ -258,13 +276,13 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
||||
canvas_draw_dot(canvas, 17, 61);
|
||||
break;
|
||||
case SubGhzViewReceiverBarShowUnlock:
|
||||
canvas_draw_icon(canvas, 64, 55, &I_Unlock_7x8);
|
||||
canvas_draw_str(canvas, 74, 62, "Unlocked");
|
||||
canvas_draw_icon(canvas, 64, 56, &I_Unlock_7x8);
|
||||
canvas_draw_str(canvas, 74, 64, "Unlocked");
|
||||
break;
|
||||
default:
|
||||
canvas_draw_str(canvas, 44, 62, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 96, 62, furi_string_get_cstr(model->history_stat_str));
|
||||
canvas_draw_str(canvas, 44, 64, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 79, 64, furi_string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 97, 64, furi_string_get_cstr(model->history_stat_str));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,10 @@ void subghz_view_receiver_add_data_statusbar(
|
||||
const char* preset_str,
|
||||
const char* history_stat_str);
|
||||
|
||||
void subghz_view_receiver_set_radio_device_type(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
SubGhzRadioDeviceType device_type);
|
||||
|
||||
void subghz_view_receiver_add_item_to_menu(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
const char* name,
|
||||
|
||||
@ -177,7 +177,8 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
|
||||
}
|
||||
subghz_frequency_analyzer_log_frequency_draw(canvas, model);
|
||||
} else {
|
||||
canvas_draw_str(canvas, 20, 8, "Frequency Analyzer");
|
||||
canvas_draw_str(canvas, 0, 8, "Frequency Analyzer");
|
||||
canvas_draw_icon(canvas, 108, 0, &I_Internal_antenna_20x12);
|
||||
canvas_draw_str(canvas, 0, 64, "RSSI");
|
||||
subghz_frequency_analyzer_draw_rssi(canvas, model->rssi, 20, 64);
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ typedef struct {
|
||||
uint8_t ind_sin;
|
||||
SubGhzReadRAWStatus status;
|
||||
float raw_threshold_rssi;
|
||||
SubGhzRadioDeviceType device_type;
|
||||
} SubGhzReadRAWModel;
|
||||
|
||||
void subghz_read_raw_set_callback(
|
||||
@ -56,6 +57,14 @@ void subghz_read_raw_add_data_statusbar(
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_set_radio_device_type(
|
||||
SubGhzReadRAW* instance,
|
||||
SubGhzRadioDeviceType device_type) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, SubGhzReadRAWModel * model, { model->device_type = device_type; }, true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi, bool trace) {
|
||||
furi_assert(instance);
|
||||
uint8_t u_rssi = 0;
|
||||
@ -279,11 +288,16 @@ void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) {
|
||||
uint8_t graphics_mode = 1;
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 5, 7, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 40, 7, furi_string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 0, 9, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 35, 9, furi_string_get_cstr(model->preset_str));
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 126, 0, AlignRight, AlignTop, furi_string_get_cstr(model->sample_write));
|
||||
canvas, 106, 2, AlignRight, AlignTop, furi_string_get_cstr(model->sample_write));
|
||||
|
||||
if(model->device_type == SubGhzRadioDeviceTypeInternal) {
|
||||
canvas_draw_icon(canvas, 108, 0, &I_Internal_antenna_20x12);
|
||||
} else {
|
||||
canvas_draw_icon(canvas, 108, 0, &I_External_antenna_20x12);
|
||||
}
|
||||
canvas_draw_line(canvas, 0, 14, 115, 14);
|
||||
canvas_draw_line(canvas, 0, 48, 115, 48);
|
||||
canvas_draw_line(canvas, 115, 14, 115, 48);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_types.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
#define SUBGHZ_RAW_THRESHOLD_MIN -90.0f
|
||||
@ -36,6 +37,10 @@ void subghz_read_raw_add_data_statusbar(
|
||||
const char* frequency_str,
|
||||
const char* preset_str);
|
||||
|
||||
void subghz_read_raw_set_radio_device_type(
|
||||
SubGhzReadRAW* instance,
|
||||
SubGhzRadioDeviceType device_type);
|
||||
|
||||
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample);
|
||||
|
||||
void subghz_read_raw_stop_send(SubGhzReadRAW* instance);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "subghz_test_carrier.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
@ -138,7 +139,7 @@ void subghz_test_carrier_enter(void* context) {
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "subghz_test_packet.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
@ -194,7 +195,7 @@ void subghz_test_packet_enter(void* context) {
|
||||
SubGhzTestPacket* instance = context;
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
|
||||
with_view_model(
|
||||
instance->view,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "subghz_test_static.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
@ -141,7 +142,7 @@ void subghz_test_static_enter(void* context) {
|
||||
SubGhzTestStatic* instance = context;
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, false);
|
||||
|
||||
@ -15,6 +15,7 @@ typedef struct {
|
||||
FuriString* preset_str;
|
||||
FuriString* key_str;
|
||||
bool show_button;
|
||||
SubGhzRadioDeviceType device_type;
|
||||
} SubGhzViewTransmitterModel;
|
||||
|
||||
void subghz_view_transmitter_set_callback(
|
||||
@ -46,6 +47,17 @@ void subghz_view_transmitter_add_data_to_show(
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_view_transmitter_set_radio_device_type(
|
||||
SubGhzViewTransmitter* subghz_transmitter,
|
||||
SubGhzRadioDeviceType device_type) {
|
||||
furi_assert(subghz_transmitter);
|
||||
with_view_model(
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{ model->device_type = device_type; },
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_view_transmitter_button_right(Canvas* canvas, const char* str) {
|
||||
const uint8_t button_height = 12;
|
||||
const uint8_t vertical_offset = 3;
|
||||
@ -56,7 +68,7 @@ static void subghz_view_transmitter_button_right(Canvas* canvas, const char* str
|
||||
const uint8_t icon_width_with_offset = icon_get_width(icon) + icon_offset;
|
||||
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
|
||||
|
||||
const uint8_t x = (canvas_width(canvas) - button_width) / 2 + 40;
|
||||
const uint8_t x = (canvas_width(canvas) - button_width) / 2 + 44;
|
||||
const uint8_t y = canvas_height(canvas);
|
||||
|
||||
canvas_draw_box(canvas, x, y - button_height, button_width, button_height);
|
||||
@ -88,7 +100,14 @@ void subghz_view_transmitter_draw(Canvas* canvas, SubGhzViewTransmitterModel* mo
|
||||
canvas, 0, 0, AlignLeft, AlignTop, furi_string_get_cstr(model->key_str));
|
||||
canvas_draw_str(canvas, 78, 7, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 113, 7, furi_string_get_cstr(model->preset_str));
|
||||
if(model->show_button) subghz_view_transmitter_button_right(canvas, "Send");
|
||||
if(model->show_button) {
|
||||
if(model->device_type == SubGhzRadioDeviceTypeInternal) {
|
||||
canvas_draw_icon(canvas, 108, 39, &I_Internal_antenna_20x12);
|
||||
} else {
|
||||
canvas_draw_icon(canvas, 108, 39, &I_External_antenna_20x12);
|
||||
}
|
||||
subghz_view_transmitter_button_right(canvas, "Send");
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_types.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubGhzViewTransmitter SubGhzViewTransmitter;
|
||||
@ -12,6 +13,10 @@ void subghz_view_transmitter_set_callback(
|
||||
SubGhzViewTransmitterCallback callback,
|
||||
void* context);
|
||||
|
||||
void subghz_view_transmitter_set_radio_device_type(
|
||||
SubGhzViewTransmitter* subghz_transmitter,
|
||||
SubGhzRadioDeviceType device_type);
|
||||
|
||||
SubGhzViewTransmitter* subghz_view_transmitter_alloc();
|
||||
|
||||
void subghz_view_transmitter_free(SubGhzViewTransmitter* subghz_transmitter);
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
#include <gui/icon.h>
|
||||
|
||||
typedef enum {
|
||||
FlipperApplicationFlagDefault = 0,
|
||||
FlipperApplicationFlagInsomniaSafe = (1 << 0),
|
||||
} FlipperApplicationFlag;
|
||||
FlipperInternalApplicationFlagDefault = 0,
|
||||
FlipperInternalApplicationFlagInsomniaSafe = (1 << 0),
|
||||
} FlipperInternalApplicationFlag;
|
||||
|
||||
typedef struct {
|
||||
const FuriThreadCallback app;
|
||||
@ -14,48 +14,41 @@ typedef struct {
|
||||
const char* appid;
|
||||
const size_t stack_size;
|
||||
const Icon* icon;
|
||||
const FlipperApplicationFlag flags;
|
||||
} FlipperApplication;
|
||||
const FlipperInternalApplicationFlag flags;
|
||||
} FlipperInternalApplication;
|
||||
|
||||
typedef void (*FlipperOnStartHook)(void);
|
||||
typedef void (*FlipperInternalOnStartHook)(void);
|
||||
|
||||
extern const char* FLIPPER_AUTORUN_APP_NAME;
|
||||
|
||||
/* Services list
|
||||
* Spawned on startup
|
||||
*/
|
||||
extern const FlipperApplication FLIPPER_SERVICES[];
|
||||
extern const FlipperInternalApplication FLIPPER_SERVICES[];
|
||||
extern const size_t FLIPPER_SERVICES_COUNT;
|
||||
|
||||
/* Apps list
|
||||
* Spawned by loader
|
||||
*/
|
||||
extern const FlipperApplication FLIPPER_APPS[];
|
||||
extern const FlipperInternalApplication FLIPPER_APPS[];
|
||||
extern const size_t FLIPPER_APPS_COUNT;
|
||||
|
||||
/* On system start hooks
|
||||
* Called by loader, after OS initialization complete
|
||||
*/
|
||||
extern const FlipperOnStartHook FLIPPER_ON_SYSTEM_START[];
|
||||
extern const FlipperInternalOnStartHook FLIPPER_ON_SYSTEM_START[];
|
||||
extern const size_t FLIPPER_ON_SYSTEM_START_COUNT;
|
||||
|
||||
/* System apps
|
||||
* Can only be spawned by loader by name
|
||||
*/
|
||||
extern const FlipperApplication FLIPPER_SYSTEM_APPS[];
|
||||
extern const FlipperInternalApplication FLIPPER_SYSTEM_APPS[];
|
||||
extern const size_t FLIPPER_SYSTEM_APPS_COUNT;
|
||||
|
||||
/* Separate scene app holder
|
||||
* Spawned by loader
|
||||
*/
|
||||
extern const FlipperApplication FLIPPER_SCENE;
|
||||
extern const FlipperApplication FLIPPER_SCENE_APPS[];
|
||||
extern const size_t FLIPPER_SCENE_APPS_COUNT;
|
||||
|
||||
extern const FlipperApplication FLIPPER_ARCHIVE;
|
||||
extern const FlipperInternalApplication FLIPPER_ARCHIVE;
|
||||
|
||||
/* Settings list
|
||||
* Spawned by loader
|
||||
*/
|
||||
extern const FlipperApplication FLIPPER_SETTINGS_APPS[];
|
||||
extern const FlipperInternalApplication FLIPPER_SETTINGS_APPS[];
|
||||
extern const size_t FLIPPER_SETTINGS_APPS_COUNT;
|
||||
|
||||
@ -36,6 +36,7 @@ static void desktop_loader_callback(const void* message, void* context) {
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAfterAppFinished);
|
||||
}
|
||||
}
|
||||
|
||||
static void desktop_lock_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
UNUSED(context);
|
||||
furi_assert(canvas);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user