From e7965c6d95ceb465296f53b3a49f146b719d11e5 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Fri, 19 May 2023 06:33:15 +0300 Subject: [PATCH] De-libify name changer --- applications/services/application.fam | 2 +- .../services/namechanger/application.fam | 4 +- .../services/namechanger/namechange.c | 46 ------------------- .../services/namechanger}/namechanger.c | 46 ++++++++++++++++++- .../services/namechanger/namechanger.h | 5 ++ .../desktop_settings/desktop_settings_app.c | 2 +- lib/toolbox/namechanger.h | 18 -------- 7 files changed, 54 insertions(+), 69 deletions(-) delete mode 100644 applications/services/namechanger/namechange.c rename {lib/toolbox => applications/services/namechanger}/namechanger.c (60%) create mode 100644 applications/services/namechanger/namechanger.h delete mode 100644 lib/toolbox/namechanger.h diff --git a/applications/services/application.fam b/applications/services/application.fam index afa69301d..0b5009096 100644 --- a/applications/services/application.fam +++ b/applications/services/application.fam @@ -9,6 +9,6 @@ App( "desktop", "loader", "power", - "namechange_srv", + "namechanger_srv", ], ) diff --git a/applications/services/namechanger/application.fam b/applications/services/namechanger/application.fam index a4bc23938..0eaeab987 100644 --- a/applications/services/namechanger/application.fam +++ b/applications/services/namechanger/application.fam @@ -1,7 +1,7 @@ App( - appid="namechange_srv", + appid="namechanger_srv", apptype=FlipperAppType.STARTUP, - entry_point="namechange_on_system_start", + entry_point="namechanger_on_system_start", requires=["storage", "cli", "bt"], conflicts=["updater"], order=600, diff --git a/applications/services/namechanger/namechange.c b/applications/services/namechanger/namechange.c deleted file mode 100644 index 22cb0d9de..000000000 --- a/applications/services/namechanger/namechange.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -int32_t namechange_on_system_start(void* p) { - UNUSED(p); - if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { - return 0; - } - - // Wait for all required services to start and create their records - uint8_t timeout = 0; - while(!furi_record_exists(RECORD_CLI) || !furi_record_exists(RECORD_BT) || - !furi_record_exists(RECORD_STORAGE)) { - timeout++; - if(timeout > 250) { - return 0; - } - furi_delay_ms(5); - } - - // Hehe bad code now here, bad bad bad, very bad, bad example, dont take it, make it better - - if(NameChanger_Init()) { - Cli* cli = furi_record_open(RECORD_CLI); - cli_session_close(cli); - furi_delay_ms(2); // why i added delays here - cli_session_open(cli, &cli_vcp); - furi_record_close(RECORD_CLI); - - furi_delay_ms(3); - Bt* bt = furi_record_open(RECORD_BT); - if(!bt_set_profile(bt, BtProfileSerial)) { - //FURI_LOG_D(TAG, "Failed to touch bluetooth to name change"); - } - furi_record_close(RECORD_BT); - bt = NULL; - furi_delay_ms(3); - } - - return 0; -} \ No newline at end of file diff --git a/lib/toolbox/namechanger.c b/applications/services/namechanger/namechanger.c similarity index 60% rename from lib/toolbox/namechanger.c rename to applications/services/namechanger/namechanger.c index 94e08ac13..796dd2d3b 100644 --- a/lib/toolbox/namechanger.c +++ b/applications/services/namechanger/namechanger.c @@ -1,10 +1,15 @@ #include "namechanger.h" +#include #include +#include +#include +#include +#include #include #define TAG "NameChanger" -bool NameChanger_Init() { +static bool namechanger_init() { Storage* storage = furi_record_open(RECORD_STORAGE); // Kostil + velosiped = top ficha @@ -64,4 +69,43 @@ bool NameChanger_Init() { furi_string_free(str); return res; +} + +int32_t namechanger_on_system_start(void* p) { + UNUSED(p); + if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { + return 0; + } + + // Wait for all required services to start and create their records + uint8_t timeout = 0; + while(!furi_record_exists(RECORD_CLI) || !furi_record_exists(RECORD_BT) || + !furi_record_exists(RECORD_STORAGE)) { + timeout++; + if(timeout > 250) { + return 0; + } + furi_delay_ms(5); + } + + // Hehe bad code now here, bad bad bad, very bad, bad example, dont take it, make it better + + if(namechanger_init()) { + Cli* cli = furi_record_open(RECORD_CLI); + cli_session_close(cli); + furi_delay_ms(2); // why i added delays here + cli_session_open(cli, &cli_vcp); + furi_record_close(RECORD_CLI); + + furi_delay_ms(3); + Bt* bt = furi_record_open(RECORD_BT); + if(!bt_set_profile(bt, BtProfileSerial)) { + //FURI_LOG_D(TAG, "Failed to touch bluetooth to name change"); + } + furi_record_close(RECORD_BT); + bt = NULL; + furi_delay_ms(3); + } + + return 0; } \ No newline at end of file diff --git a/applications/services/namechanger/namechanger.h b/applications/services/namechanger/namechanger.h new file mode 100644 index 000000000..dac1b7952 --- /dev/null +++ b/applications/services/namechanger/namechanger.h @@ -0,0 +1,5 @@ +#pragma once + +#define NAMECHANGER_HEADER "Flipper Name File" +#define NAMECHANGER_VERSION 1 +#define NAMECHANGER_PATH EXT_PATH("dolphin/name.settings") diff --git a/applications/settings/desktop_settings/desktop_settings_app.c b/applications/settings/desktop_settings/desktop_settings_app.c index 317d57654..7e04271f2 100644 --- a/applications/settings/desktop_settings/desktop_settings_app.c +++ b/applications/settings/desktop_settings/desktop_settings_app.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/lib/toolbox/namechanger.h b/lib/toolbox/namechanger.h deleted file mode 100644 index bfaadec15..000000000 --- a/lib/toolbox/namechanger.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#define NAMECHANGER_HEADER "Flipper Name File" -#define NAMECHANGER_VERSION 1 -#define NAMECHANGER_PATH EXT_PATH("dolphin/name.settings") - -#include "stdbool.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Initializes the name changer. (Load name file, apply changes) -bool NameChanger_Init(); - -#ifdef __cplusplus -} -#endif \ No newline at end of file