Skip to content

Commit

Permalink
Name changer as service + extra checks
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed May 19, 2023
1 parent 276020c commit a7ee5fe
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 23 deletions.
1 change: 1 addition & 0 deletions applications/services/application.fam
Expand Up @@ -9,5 +9,6 @@ App(
"desktop",
"loader",
"power",
"namechange_srv",
],
)
23 changes: 0 additions & 23 deletions applications/services/desktop/desktop.c
Expand Up @@ -9,9 +9,6 @@
#include <cli/cli.h>
#include <cli/cli_vcp.h>

#include <toolbox/namechanger.h>
#include <bt/bt_service/bt.h>

#include "animations/animation_manager.h"
#include "desktop/scenes/desktop_scene.h"
#include "desktop/scenes/desktop_scene_i.h"
Expand Down Expand Up @@ -429,26 +426,6 @@ int32_t desktop_srv(void* p) {
scene_manager_next_scene(desktop->scene_manager, DesktopSceneFault);
}

// I added some very bydlo kod here, and thrown some delays to make it worse, pls don't look at it, it will make you cry from laugh
if(furi_hal_rtc_get_boot_mode() == FuriHalRtcBootModeNormal) {
if(NameChanger_Init()) {
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_close(cli);
furi_delay_ms(2);
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);
}
}

view_dispatcher_run(desktop->view_dispatcher);
desktop_free(desktop);

Expand Down
8 changes: 8 additions & 0 deletions applications/services/namechanger/application.fam
@@ -0,0 +1,8 @@
App(
appid="namechange_srv",
apptype=FlipperAppType.STARTUP,
entry_point="namechange_on_system_start",
requires=["storage", "cli", "bt"],
conflicts=["updater"],
order=600,
)
46 changes: 46 additions & 0 deletions applications/services/namechanger/namechange.c
@@ -0,0 +1,46 @@
#include <furi_hal.h>
#include <cli/cli.h>
#include <cli/cli_vcp.h>
#include <storage/storage.h>

#include <toolbox/namechanger.h>
#include <bt/bt_service/bt.h>

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;
}
14 changes: 14 additions & 0 deletions lib/toolbox/namechanger.c
Expand Up @@ -6,6 +6,20 @@

bool NameChanger_Init() {
Storage* storage = furi_record_open(RECORD_STORAGE);

// Kostil + velosiped = top ficha
uint8_t timeout = 0;
while(timeout < 11) {
if(storage_sd_status(storage) == FSE_OK) break;
furi_delay_ms(250);
timeout++;
/*if(timeout == 10) {
// Failed to init namechanger, SD card not ready
furi_record_close(RECORD_STORAGE);
return false;
}*/
}

FuriString* str = furi_string_alloc();
FlipperFormat* file = flipper_format_file_alloc(storage);

Expand Down

0 comments on commit a7ee5fe

Please sign in to comment.