FindMy: Fix battery level edge cases (eg. at boot) and cleanup

- Generate config struct only when necessary
- Centralize last few things to use state values
- Uniform state apply and save process
- Simplify battery level handling
This commit is contained in:
Willy-JL
2024-05-02 06:46:06 +01:00
parent f3c1c09e39
commit ff2bb16492
9 changed files with 61 additions and 118 deletions

View File

@@ -64,8 +64,7 @@ static const char* parse_nrf_connect(FindMy* app, const char* path) {
memcpy(app->state.mac, mac, sizeof(app->state.mac));
memcpy(app->state.data, data, sizeof(app->state.data));
findmy_state_sync_config(&app->state);
findmy_state_save(&app->state);
findmy_state_save_and_apply(&app->state);
error = NULL;
@@ -126,8 +125,7 @@ static const char* parse_open_haystack(FindMy* app, const char* path) {
memcpy(app->state.data, advertisement_template, sizeof(app->state.data));
memcpy(&app->state.data[7], &public_key[6], decoded_len - 6);
app->state.data[29] = public_key[0] >> 6;
findmy_state_sync_config(&app->state);
findmy_state_save(&app->state);
findmy_state_save_and_apply(&app->state);
free(public_key);
error = NULL;

View File

@@ -29,7 +29,7 @@ void findmy_scene_config_import_result_on_enter(void* context) {
popup_set_timeout(popup, 1500);
popup_set_context(popup, app);
popup_set_callback(popup, findmy_scene_config_import_result_callback);
findmy_main_update_active(app->findmy_main, furi_hal_bt_extra_beacon_is_active());
findmy_main_update_active(app->findmy_main, app->state.beacon_active);
findmy_main_update_mac(app->findmy_main, app->state.mac);
findmy_main_update_type(app->findmy_main, app->state.tag_type);
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewPopup);

View File

@@ -40,15 +40,7 @@ bool findmy_scene_config_mac_on_event(void* context, SceneManagerEvent event) {
case ByteInputResultOk:
furi_hal_bt_reverse_mac_addr(app->mac_buf);
memcpy(&app->state.mac, app->mac_buf, sizeof(app->state.mac));
findmy_state_sync_config(&app->state);
findmy_state_save(&app->state);
if(furi_hal_bt_extra_beacon_is_active()) {
furi_check(furi_hal_bt_extra_beacon_stop());
}
furi_check(furi_hal_bt_extra_beacon_set_config(&app->state.config));
if(app->state.beacon_active) {
furi_check(furi_hal_bt_extra_beacon_start());
}
findmy_state_save_and_apply(&app->state);
findmy_main_update_mac(app->findmy_main, app->state.mac);
scene_manager_next_scene(app->scene_manager, FindMySceneConfigPacket);
break;

View File

@@ -40,9 +40,7 @@ bool findmy_scene_config_packet_on_event(void* context, SceneManagerEvent event)
scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, FindMySceneConfig);
memcpy(app->state.data, app->packet_buf, findmy_state_data_size(app->state.tag_type));
findmy_state_save(&app->state);
furi_check(furi_hal_bt_extra_beacon_set_data(
app->state.data, findmy_state_data_size(app->state.tag_type)));
findmy_state_save_and_apply(&app->state);
break;
default:
break;

View File

@@ -25,10 +25,7 @@ bool findmy_scene_main_on_event(void* context, SceneManagerEvent event) {
break;
case FindMyMainEventBackground:
app->state.beacon_active = true;
findmy_state_save(&app->state);
if(!furi_hal_bt_extra_beacon_is_active()) {
furi_check(furi_hal_bt_extra_beacon_start());
}
findmy_state_save_and_apply(&app->state);
view_dispatcher_stop(app->view_dispatcher);
break;
case FindMyMainEventConfig:
@@ -42,10 +39,7 @@ bool findmy_scene_main_on_event(void* context, SceneManagerEvent event) {
break;
case FindMyMainEventQuit:
app->state.beacon_active = false;
findmy_state_save(&app->state);
if(furi_hal_bt_extra_beacon_is_active()) {
furi_check(furi_hal_bt_extra_beacon_stop());
}
findmy_state_save_and_apply(&app->state);
break;
default:
consumed = false;