mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-25 06:13:14 +03:00
acc39a4bc0
* Api Symbols: replace asserts with checks * Api Symbols: replace asserts with checks part 2 * Update no args function signatures with void, to help compiler to track incorrect usage * More unavoidable void * Update PVS config and code to make it happy * Format sources * nfc: fix checks * dead code cleanup & include fixes Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: hedger <hedger@nanode.su>
75 lines
1.8 KiB
C
75 lines
1.8 KiB
C
#include <furi.h>
|
|
#include <furi_hal.h>
|
|
#include <cli/cli.h>
|
|
#include <lib/toolbox/args.h>
|
|
#include <lib/toolbox/hex.h>
|
|
|
|
#include <furi_hal_nfc.h>
|
|
|
|
#define FLAG_EVENT (1 << 10)
|
|
|
|
static void nfc_cli_print_usage(void) {
|
|
printf("Usage:\r\n");
|
|
printf("nfc <cmd>\r\n");
|
|
printf("Cmd list:\r\n");
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
|
printf("\tfield\t - turn field on\r\n");
|
|
}
|
|
}
|
|
|
|
static void nfc_cli_field(Cli* cli, FuriString* args) {
|
|
UNUSED(args);
|
|
// Check if nfc worker is not busy
|
|
if(furi_hal_nfc_is_hal_ready() != FuriHalNfcErrorNone) {
|
|
printf("NFC chip failed to start\r\n");
|
|
return;
|
|
}
|
|
|
|
furi_hal_nfc_acquire();
|
|
furi_hal_nfc_low_power_mode_stop();
|
|
furi_hal_nfc_poller_field_on();
|
|
|
|
printf("Field is on. Don't leave device in this mode for too long.\r\n");
|
|
printf("Press Ctrl+C to abort\r\n");
|
|
|
|
while(!cli_cmd_interrupt_received(cli)) {
|
|
furi_delay_ms(50);
|
|
}
|
|
|
|
furi_hal_nfc_low_power_mode_start();
|
|
furi_hal_nfc_release();
|
|
}
|
|
|
|
static void nfc_cli(Cli* cli, FuriString* args, void* context) {
|
|
UNUSED(context);
|
|
FuriString* cmd;
|
|
cmd = furi_string_alloc();
|
|
|
|
do {
|
|
if(!args_read_string_and_trim(args, cmd)) {
|
|
nfc_cli_print_usage();
|
|
break;
|
|
}
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
|
if(furi_string_cmp_str(cmd, "field") == 0) {
|
|
nfc_cli_field(cli, args);
|
|
break;
|
|
}
|
|
}
|
|
|
|
nfc_cli_print_usage();
|
|
} while(false);
|
|
|
|
furi_string_free(cmd);
|
|
}
|
|
|
|
void nfc_on_system_start(void) {
|
|
#ifdef SRV_CLI
|
|
Cli* cli = furi_record_open(RECORD_CLI);
|
|
cli_add_command(cli, "nfc", CliCommandFlagDefault, nfc_cli, NULL);
|
|
furi_record_close(RECORD_CLI);
|
|
#else
|
|
UNUSED(nfc_cli);
|
|
#endif
|
|
}
|