From 5d4ed946cba10f7fb7618ded3599ccec5d0d3af7 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 15 Jun 2024 15:12:50 +0300 Subject: [PATCH] move part of the CLI to microsd to free up space for COMPACT 0 builds CLI wrapper and idea by Willy-JL --- applications/main/ibutton/application.fam | 11 ++++++- applications/main/ibutton/ibutton_cli.c | 34 ++++++++++----------- applications/main/ibutton/ibutton_start.c | 11 +++++++ applications/main/infrared/application.fam | 15 +++++++-- applications/main/infrared/infrared_cli.c | 20 +++++++----- applications/main/infrared/infrared_start.c | 11 +++++++ applications/main/lfrfid/application.fam | 11 ++++++- applications/main/lfrfid/lfrfid_cli.c | 22 +++++++------ applications/main/lfrfid/lfrfid_start.c | 11 +++++++ applications/main/nfc/application.fam | 11 ++++++- applications/main/nfc/nfc_cli.c | 19 +++++++----- applications/main/nfc/nfc_start.c | 11 +++++++ applications/main/onewire/application.fam | 10 ++++++ applications/main/onewire/onewire_cli.c | 27 ++++++++-------- applications/main/onewire/onewire_start.c | 11 +++++++ applications/services/cli/cli.c | 20 ++++++++++++ applications/services/cli/cli_i.h | 7 +++++ applications/services/gui/canvas.c | 2 +- 18 files changed, 202 insertions(+), 62 deletions(-) create mode 100644 applications/main/ibutton/ibutton_start.c create mode 100644 applications/main/infrared/infrared_start.c create mode 100644 applications/main/lfrfid/lfrfid_start.c create mode 100644 applications/main/nfc/nfc_start.c create mode 100644 applications/main/onewire/onewire_start.c diff --git a/applications/main/ibutton/application.fam b/applications/main/ibutton/application.fam index 01c02ec23d..06455aeb95 100644 --- a/applications/main/ibutton/application.fam +++ b/applications/main/ibutton/application.fam @@ -12,11 +12,20 @@ App( fap_category="iButton", ) +App( + appid="ibutton_cli", + targets=["f7"], + apptype=FlipperAppType.PLUGIN, + entry_point="ibutton_cli_plugin_ep", + requires=["cli"], + sources=["ibutton_cli.c"], +) + App( appid="ibutton_start", apptype=FlipperAppType.STARTUP, targets=["f7"], entry_point="ibutton_on_system_start", - sources=["ibutton_cli.c"], + sources=["ibutton_start.c"], order=60, ) diff --git a/applications/main/ibutton/ibutton_cli.c b/applications/main/ibutton/ibutton_cli.c index 98ef308016..12e237e8a7 100644 --- a/applications/main/ibutton/ibutton_cli.c +++ b/applications/main/ibutton/ibutton_cli.c @@ -8,19 +8,6 @@ #include #include -static void ibutton_cli(Cli* cli, FuriString* args, void* context); - -// app cli function -void ibutton_on_system_start(void) { -#ifdef SRV_CLI - Cli* cli = furi_record_open(RECORD_CLI); - cli_add_command(cli, "ikey", CliCommandFlagDefault, ibutton_cli, cli); - furi_record_close(RECORD_CLI); -#else - UNUSED(ibutton_cli); -#endif -} - static void ibutton_cli_print_usage(void) { printf("Usage:\r\n"); printf("ikey read\r\n"); @@ -31,7 +18,7 @@ static void ibutton_cli_print_usage(void) { printf("\tCyfral (2 bytes key_data)\r\n"); printf("\tMetakom (4 bytes key_data), must contain correct parity\r\n"); printf("\t are hex-formatted\r\n"); -}; +} static bool ibutton_cli_parse_key(iButtonProtocols* protocols, iButtonKey* key, FuriString* args) { bool result = false; @@ -124,7 +111,7 @@ static void ibutton_cli_read(Cli* cli) { ibutton_protocols_free(protocols); furi_event_flag_free(event); -}; +} typedef struct { FuriEventFlag* event; @@ -216,7 +203,7 @@ void ibutton_cli_emulate(Cli* cli, FuriString* args) { while(!cli_cmd_interrupt_received(cli)) { furi_delay_ms(100); - }; + } } while(false); @@ -226,7 +213,7 @@ void ibutton_cli_emulate(Cli* cli, FuriString* args) { ibutton_key_free(key); ibutton_worker_free(worker); ibutton_protocols_free(protocols); -}; +} void ibutton_cli(Cli* cli, FuriString* args, void* context) { UNUSED(cli); @@ -252,3 +239,16 @@ void ibutton_cli(Cli* cli, FuriString* args, void* context) { furi_string_free(cmd); } + +#include +#include + +static const FlipperAppPluginDescriptor plugin_descriptor = { + .appid = CLI_PLUGIN_APP_ID, + .ep_api_version = CLI_PLUGIN_API_VERSION, + .entry_point = &ibutton_cli, +}; + +const FlipperAppPluginDescriptor* ibutton_cli_plugin_ep(void) { + return &plugin_descriptor; +} diff --git a/applications/main/ibutton/ibutton_start.c b/applications/main/ibutton/ibutton_start.c new file mode 100644 index 0000000000..d252bed7fb --- /dev/null +++ b/applications/main/ibutton/ibutton_start.c @@ -0,0 +1,11 @@ +#include + +static void ibutton_cli_wrapper(Cli* cli, FuriString* args, void* context) { + cli_plugin_wrapper("ibutton", cli, args, context); +} + +void ibutton_on_system_start(void) { + Cli* cli = furi_record_open(RECORD_CLI); + cli_add_command(cli, "ikey", CliCommandFlagDefault, ibutton_cli_wrapper, cli); + furi_record_close(RECORD_CLI); +} diff --git a/applications/main/infrared/application.fam b/applications/main/infrared/application.fam index 575bebbe48..586adf1102 100644 --- a/applications/main/infrared/application.fam +++ b/applications/main/infrared/application.fam @@ -15,14 +15,23 @@ App( ) App( - appid="infrared_start", - apptype=FlipperAppType.STARTUP, + appid="infrared_cli", targets=["f7"], - entry_point="infrared_on_system_start", + apptype=FlipperAppType.PLUGIN, + entry_point="infrared_cli_plugin_ep", + requires=["cli"], sources=[ "infrared_cli.c", "infrared_brute_force.c", "infrared_signal.c", ], +) + +App( + appid="infrared_start", + apptype=FlipperAppType.STARTUP, + targets=["f7"], + entry_point="infrared_on_system_start", + sources=["infrared_start.c"], order=20, ) diff --git a/applications/main/infrared/infrared_cli.c b/applications/main/infrared/infrared_cli.c index 123fe78d54..b09c7f0b17 100644 --- a/applications/main/infrared/infrared_cli.c +++ b/applications/main/infrared/infrared_cli.c @@ -544,12 +544,16 @@ static void infrared_cli_start_ir(Cli* cli, FuriString* args, void* context) { furi_string_free(command); } -void infrared_on_system_start(void) { -#ifdef SRV_CLI - Cli* cli = (Cli*)furi_record_open(RECORD_CLI); - cli_add_command(cli, "ir", CliCommandFlagDefault, infrared_cli_start_ir, NULL); - furi_record_close(RECORD_CLI); -#else - UNUSED(infrared_cli_start_ir); -#endif + +#include +#include + +static const FlipperAppPluginDescriptor plugin_descriptor = { + .appid = CLI_PLUGIN_APP_ID, + .ep_api_version = CLI_PLUGIN_API_VERSION, + .entry_point = &infrared_cli_start_ir, +}; + +const FlipperAppPluginDescriptor* infrared_cli_plugin_ep(void) { + return &plugin_descriptor; } diff --git a/applications/main/infrared/infrared_start.c b/applications/main/infrared/infrared_start.c new file mode 100644 index 0000000000..6de11b677d --- /dev/null +++ b/applications/main/infrared/infrared_start.c @@ -0,0 +1,11 @@ +#include + +static void infrared_cli_start_ir_wrapper(Cli* cli, FuriString* args, void* context) { + cli_plugin_wrapper("infrared", cli, args, context); +} + +void infrared_on_system_start(void) { + Cli* cli = (Cli*)furi_record_open(RECORD_CLI); + cli_add_command(cli, "ir", CliCommandFlagDefault, infrared_cli_start_ir_wrapper, NULL); + furi_record_close(RECORD_CLI); +} diff --git a/applications/main/lfrfid/application.fam b/applications/main/lfrfid/application.fam index c067d786fc..efded8001d 100644 --- a/applications/main/lfrfid/application.fam +++ b/applications/main/lfrfid/application.fam @@ -12,11 +12,20 @@ App( fap_category="RFID", ) +App( + appid="lfrfid_cli", + targets=["f7"], + apptype=FlipperAppType.PLUGIN, + entry_point="lfrfid_cli_plugin_ep", + requires=["cli"], + sources=["lfrfid_cli.c"], +) + App( appid="lfrfid_start", targets=["f7"], apptype=FlipperAppType.STARTUP, entry_point="lfrfid_on_system_start", - sources=["lfrfid_cli.c"], + sources=["lfrfid_start.c"], order=50, ) diff --git a/applications/main/lfrfid/lfrfid_cli.c b/applications/main/lfrfid/lfrfid_cli.c index 2101670fa7..de8609aeda 100644 --- a/applications/main/lfrfid/lfrfid_cli.c +++ b/applications/main/lfrfid/lfrfid_cli.c @@ -14,15 +14,6 @@ #include #include -static void lfrfid_cli(Cli* cli, FuriString* args, void* context); - -// app cli function -void lfrfid_on_system_start(void) { - Cli* cli = furi_record_open(RECORD_CLI); - cli_add_command(cli, "rfid", CliCommandFlagDefault, lfrfid_cli, NULL); - furi_record_close(RECORD_CLI); -} - static void lfrfid_cli_print_usage(void) { printf("Usage:\r\n"); printf("rfid read - read in ASK/PSK mode\r\n"); @@ -577,3 +568,16 @@ static void lfrfid_cli(Cli* cli, FuriString* args, void* context) { furi_string_free(cmd); } + +#include +#include + +static const FlipperAppPluginDescriptor plugin_descriptor = { + .appid = CLI_PLUGIN_APP_ID, + .ep_api_version = CLI_PLUGIN_API_VERSION, + .entry_point = &lfrfid_cli, +}; + +const FlipperAppPluginDescriptor* lfrfid_cli_plugin_ep(void) { + return &plugin_descriptor; +} diff --git a/applications/main/lfrfid/lfrfid_start.c b/applications/main/lfrfid/lfrfid_start.c new file mode 100644 index 0000000000..faf275355b --- /dev/null +++ b/applications/main/lfrfid/lfrfid_start.c @@ -0,0 +1,11 @@ +#include + +static void lfrfid_cli_wrapper(Cli* cli, FuriString* args, void* context) { + cli_plugin_wrapper("lfrfid", cli, args, context); +} + +void lfrfid_on_system_start(void) { + Cli* cli = furi_record_open(RECORD_CLI); + cli_add_command(cli, "rfid", CliCommandFlagDefault, lfrfid_cli_wrapper, NULL); + furi_record_close(RECORD_CLI); +} diff --git a/applications/main/nfc/application.fam b/applications/main/nfc/application.fam index 4c347b2d85..ae5372910c 100644 --- a/applications/main/nfc/application.fam +++ b/applications/main/nfc/application.fam @@ -272,11 +272,20 @@ App( sources=["plugins/supported_cards/skylanders.c"], ) +App( + appid="nfc_cli", + targets=["f7"], + apptype=FlipperAppType.PLUGIN, + entry_point="nfc_cli_plugin_ep", + requires=["cli"], + sources=["nfc_cli.c"], +) + App( appid="nfc_start", targets=["f7"], apptype=FlipperAppType.STARTUP, entry_point="nfc_on_system_start", - sources=["nfc_cli.c"], + sources=["nfc_start.c"], order=30, ) diff --git a/applications/main/nfc/nfc_cli.c b/applications/main/nfc/nfc_cli.c index 90ac26d7c2..fae8ca933a 100644 --- a/applications/main/nfc/nfc_cli.c +++ b/applications/main/nfc/nfc_cli.c @@ -63,12 +63,15 @@ static void nfc_cli(Cli* cli, FuriString* args, void* context) { 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 +#include +#include + +static const FlipperAppPluginDescriptor plugin_descriptor = { + .appid = CLI_PLUGIN_APP_ID, + .ep_api_version = CLI_PLUGIN_API_VERSION, + .entry_point = &nfc_cli, +}; + +const FlipperAppPluginDescriptor* nfc_cli_plugin_ep(void) { + return &plugin_descriptor; } diff --git a/applications/main/nfc/nfc_start.c b/applications/main/nfc/nfc_start.c new file mode 100644 index 0000000000..d38a956c3f --- /dev/null +++ b/applications/main/nfc/nfc_start.c @@ -0,0 +1,11 @@ +#include + +static void nfc_cli_wrapper(Cli* cli, FuriString* args, void* context) { + cli_plugin_wrapper("nfc", cli, args, context); +} + +void nfc_on_system_start(void) { + Cli* cli = furi_record_open(RECORD_CLI); + cli_add_command(cli, "nfc", CliCommandFlagDefault, nfc_cli_wrapper, NULL); + furi_record_close(RECORD_CLI); +} diff --git a/applications/main/onewire/application.fam b/applications/main/onewire/application.fam index 3d35abce94..9fac2ff219 100644 --- a/applications/main/onewire/application.fam +++ b/applications/main/onewire/application.fam @@ -1,6 +1,16 @@ +App( + appid="onewire_cli", + targets=["f7"], + apptype=FlipperAppType.PLUGIN, + entry_point="onewire_cli_plugin_ep", + requires=["cli"], + sources=["onewire_cli.c"], +) + App( appid="onewire_start", apptype=FlipperAppType.STARTUP, entry_point="onewire_on_system_start", + sources=["onewire_start.c"], order=60, ) diff --git a/applications/main/onewire/onewire_cli.c b/applications/main/onewire/onewire_cli.c index 19e5842175..128b58743b 100644 --- a/applications/main/onewire/onewire_cli.c +++ b/applications/main/onewire/onewire_cli.c @@ -6,22 +6,10 @@ #include -static void onewire_cli(Cli* cli, FuriString* args, void* context); - -void onewire_on_system_start(void) { -#ifdef SRV_CLI - Cli* cli = furi_record_open(RECORD_CLI); - cli_add_command(cli, "onewire", CliCommandFlagDefault, onewire_cli, cli); - furi_record_close(RECORD_CLI); -#else - UNUSED(onewire_cli); -#endif -} - static void onewire_cli_print_usage(void) { printf("Usage:\r\n"); printf("onewire search\r\n"); -}; +} static void onewire_cli_search(Cli* cli) { UNUSED(cli); @@ -70,3 +58,16 @@ void onewire_cli(Cli* cli, FuriString* args, void* context) { furi_string_free(cmd); } + +#include +#include + +static const FlipperAppPluginDescriptor plugin_descriptor = { + .appid = CLI_PLUGIN_APP_ID, + .ep_api_version = CLI_PLUGIN_API_VERSION, + .entry_point = &onewire_cli, +}; + +const FlipperAppPluginDescriptor* onewire_cli_plugin_ep(void) { + return &plugin_descriptor; +} diff --git a/applications/main/onewire/onewire_start.c b/applications/main/onewire/onewire_start.c new file mode 100644 index 0000000000..219335411b --- /dev/null +++ b/applications/main/onewire/onewire_start.c @@ -0,0 +1,11 @@ +#include + +static void onewire_cli_wrapper(Cli* cli, FuriString* args, void* context) { + cli_plugin_wrapper("onewire", cli, args, context); +} + +void onewire_on_system_start(void) { + Cli* cli = furi_record_open(RECORD_CLI); + cli_add_command(cli, "onewire", CliCommandFlagDefault, onewire_cli_wrapper, cli); + furi_record_close(RECORD_CLI); +} diff --git a/applications/services/cli/cli.c b/applications/services/cli/cli.c index 709d69768f..a300009f5d 100644 --- a/applications/services/cli/cli.c +++ b/applications/services/cli/cli.c @@ -4,6 +4,10 @@ #include #include +#include +#include +#include + #define TAG "CliSrv" #define CLI_INPUT_LEN_LIMIT 256 @@ -482,3 +486,19 @@ int32_t cli_srv(void* p) { return 0; } + +void cli_plugin_wrapper(const char* name, Cli* cli, FuriString* args, void* context) { + PluginManager* manager = + plugin_manager_alloc(CLI_PLUGIN_APP_ID, CLI_PLUGIN_API_VERSION, firmware_api_interface); + FuriString* path = + furi_string_alloc_printf(EXT_PATH("apps_data/cli/plugins/%s_cli.fal"), name); + PluginManagerError error = plugin_manager_load_single(manager, furi_string_get_cstr(path)); + if(error == PluginManagerErrorNone) { + const CliCallback handler = plugin_manager_get_ep(manager, 0); + handler(cli, args, context); + } else { + printf("CLI plugin failed (code %" PRIu16 "), update firmware or check logs\r\n", error); + } + furi_string_free(path); + plugin_manager_free(manager); +} diff --git a/applications/services/cli/cli_i.h b/applications/services/cli/cli_i.h index 8a82d96194..4828bf7235 100644 --- a/applications/services/cli/cli_i.h +++ b/applications/services/cli/cli_i.h @@ -62,6 +62,13 @@ void cli_putc(Cli* cli, char c); void cli_stdout_callback(void* _cookie, const char* data, size_t size); +// Wraps CLI commands to load from plugin file +// Must call from CLI context, like dummy CLI command callback +// You need to setup the plugin to compile correctly separately +#define CLI_PLUGIN_APP_ID "cli" +#define CLI_PLUGIN_API_VERSION 1 +void cli_plugin_wrapper(const char* name, Cli* cli, FuriString* args, void* context); + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/applications/services/gui/canvas.c b/applications/services/gui/canvas.c index b67b2faba6..5defdadadc 100644 --- a/applications/services/gui/canvas.c +++ b/applications/services/gui/canvas.c @@ -170,7 +170,7 @@ void canvas_set_font(Canvas* canvas, Font font) { } else if(font == FontBigNumbers) { u8g2_SetFont(&canvas->fb, u8g2_font_profont22_tn); } else if(font == FontBatteryPercent) { - u8g2_SetFont(&canvas->fb, u8g2_font_5x7_tf); //u8g2_font_micro_tr); + u8g2_SetFont(&canvas->fb, u8g2_font_5x7_tr); //u8g2_font_micro_tr); } else { furi_crash(); }