Load FindMy and SubGHz settings on SD insert

This commit is contained in:
Willy-JL
2024-08-12 00:47:53 +02:00
parent 674956a476
commit e8ad079992
2 changed files with 70 additions and 11 deletions

View File

@@ -1,10 +1,16 @@
#include <furi.h>
#include <furi_hal.h>
#include <furi_hal_subghz_i.h>
#include <toolbox/run_parallel.h>
#include <subghz/subghz_last_settings.h>
#include <flipper_format/flipper_format_i.h>
void subghz_extended_freq() {
#define TAG "SubGhzExtendedFreq"
static int32_t subghz_extended_freq_apply(void* context) {
UNUSED(context);
FURI_LOG_D(TAG, "Loading settings");
bool is_extended_i = false;
bool is_bypassed = false;
Storage* storage = furi_record_open(RECORD_STORAGE);
@@ -13,6 +19,7 @@ void subghz_extended_freq() {
if(flipper_format_file_open_existing(file, "/ext/subghz/assets/extend_range.txt")) {
flipper_format_read_bool(file, "use_ext_range_at_own_risk", &is_extended_i, 1);
flipper_format_read_bool(file, "ignore_default_tx_region", &is_bypassed, 1);
flipper_format_file_close(file);
}
furi_hal_subghz_set_extended_range(is_extended_i);
@@ -20,11 +27,29 @@ void subghz_extended_freq() {
flipper_format_free(file);
furi_record_close(RECORD_STORAGE);
// Load external module power amp setting (TODO: move to other place)
// TODO: Disable this when external module is not CC1101 E07
SubGhzLastSettings* last_settings = subghz_last_settings_alloc();
subghz_last_settings_load(last_settings, 0);
subghz_last_settings_free(last_settings);
return 0;
}
static void subghz_extended_freq_mount_callback(const void* message, void* context) {
UNUSED(context);
const StorageEvent* event = message;
if(event->type == StorageEventTypeCardMount) {
run_parallel(subghz_extended_freq_apply, NULL, 1024);
}
}
void subghz_extended_freq() {
if(!furi_hal_is_normal_boot()) return;
Storage* storage = furi_record_open(RECORD_STORAGE);
furi_pubsub_subscribe(storage_get_pubsub(storage), subghz_extended_freq_mount_callback, NULL);
if(storage_sd_status(storage) != FSE_OK) {
FURI_LOG_D(TAG, "SD Card not ready, skipping settings");
} else {
subghz_extended_freq_apply(NULL);
}
furi_record_close(RECORD_STORAGE);
}

View File

@@ -1,17 +1,51 @@
#include "findmy_state.h"
#include <furi_hal.h>
#include <bt/bt_service/bt.h>
#include <storage/storage.h>
#include <toolbox/run_parallel.h>
void findmy_startup() {
if(!furi_hal_is_normal_boot()) return;
#define TAG "FindMyStartup"
static int32_t findmy_startup_apply(void* context) {
UNUSED(context);
FURI_LOG_D(TAG, "Loading state");
// Wait for BT init and check core2
furi_record_open(RECORD_BT);
furi_record_close(RECORD_BT);
if(!furi_hal_bt_is_gatt_gap_supported()) return;
if(!furi_hal_bt_is_gatt_gap_supported()) return 0;
FindMyState state;
if(findmy_state_load(&state)) {
FURI_LOG_D(TAG, "Activating beacon");
findmy_state_apply(&state);
} else {
FURI_LOG_D(TAG, "Beacon not active, bailing");
}
return 0;
}
static void findmy_startup_mount_callback(const void* message, void* context) {
UNUSED(context);
const StorageEvent* event = message;
if(event->type == StorageEventTypeCardMount) {
run_parallel(findmy_startup_apply, NULL, 2048);
}
}
void findmy_startup() {
if(!furi_hal_is_normal_boot()) return;
Storage* storage = furi_record_open(RECORD_STORAGE);
furi_pubsub_subscribe(storage_get_pubsub(storage), findmy_startup_mount_callback, NULL);
if(storage_sd_status(storage) != FSE_OK) {
FURI_LOG_D(TAG, "SD Card not ready, skipping startup hook");
} else {
findmy_startup_apply(NULL);
}
furi_record_close(RECORD_STORAGE);
}