Name changer as service + extra checks

This commit is contained in:
MX 2023-05-19 04:33:14 +03:00
parent 276020c482
commit a7ee5fea93
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
5 changed files with 69 additions and 23 deletions

View File

@ -9,5 +9,6 @@ App(
"desktop",
"loader",
"power",
"namechange_srv",
],
)

View File

@ -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"
@ -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);

View File

@ -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,
)

View File

@ -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;
}

View File

@ -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);