expansion settings read and store in ram

by @Willy-JL
This commit is contained in:
MX 2024-01-30 23:26:08 +03:00
parent a8651a2861
commit c31052848a
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83
5 changed files with 22 additions and 14 deletions

View file

@ -1,4 +1,5 @@
#include "expansion.h"
#include "expansion_i.h"
#include <furi_hal_power.h>
#include <furi_hal_serial.h>
@ -53,6 +54,8 @@ struct Expansion {
FuriHalSerialId serial_id;
FuriHalSerialHandle* serial_handle;
RpcSession* rpc_session;
ExpansionSettings settings;
};
static void expansion_detect_callback(void* context);
@ -394,16 +397,15 @@ void expansion_on_system_start(void* arg) {
Expansion* instance = expansion_alloc();
furi_record_create(RECORD_EXPANSION, instance);
expansion_settings_load(&instance->settings);
expansion_enable(instance);
}
// Public API functions
void expansion_enable(Expansion* instance) {
ExpansionSettings settings = {};
expansion_settings_load(&settings);
if(settings.uart_index < FuriHalSerialIdMax) {
expansion_set_listen_serial(instance, settings.uart_index);
if(instance->settings.uart_index < FuriHalSerialIdMax) {
expansion_set_listen_serial(instance, instance->settings.uart_index);
}
}
@ -438,3 +440,7 @@ void expansion_set_listen_serial(Expansion* instance, FuriHalSerialId serial_id)
FURI_LOG_D(TAG, "Detection enabled");
}
ExpansionSettings* expansion_get_settings(Expansion* instance) {
return &instance->settings;
}

View file

@ -0,0 +1,6 @@
#pragma once
#include "expansion_settings.h"
#include "expansion.h"
ExpansionSettings* expansion_get_settings(Expansion* instance);

View file

@ -10,7 +10,7 @@ static void expansion_settings_app_uart_changed(VariableItem* item) {
ExpansionSettingsApp* app = variable_item_get_context(item);
const uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, expansion_uart_text[index]);
app->settings.uart_index = index;
app->settings->uart_index = index;
if(index < FuriHalSerialIdMax) {
expansion_set_listen_serial(app->expansion, index);
@ -27,10 +27,9 @@ static uint32_t expansion_settings_app_exit(void* context) {
static ExpansionSettingsApp* expansion_settings_app_alloc() {
ExpansionSettingsApp* app = malloc(sizeof(ExpansionSettingsApp));
expansion_settings_load(&app->settings);
app->gui = furi_record_open(RECORD_GUI);
app->expansion = furi_record_open(RECORD_EXPANSION);
app->settings = expansion_get_settings(app->expansion);
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(app->view_dispatcher);
@ -49,7 +48,7 @@ static ExpansionSettingsApp* expansion_settings_app_alloc() {
COUNT_OF(expansion_uart_text),
expansion_settings_app_uart_changed,
app);
value_index = app->settings.uart_index;
value_index = app->settings->uart_index;
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, expansion_uart_text[value_index]);
@ -68,7 +67,7 @@ static ExpansionSettingsApp* expansion_settings_app_alloc() {
static void expansion_settings_app_free(ExpansionSettingsApp* app) {
furi_assert(app);
expansion_settings_save(&app->settings);
expansion_settings_save(app->settings);
view_dispatcher_remove_view(app->view_dispatcher, ExpansionSettingsViewVarItemList);
variable_item_list_free(app->var_item_list);

View file

@ -8,6 +8,7 @@
#include <gui/modules/variable_item_list.h>
#include <expansion/expansion.h>
#include <expansion/expansion_i.h>
#include <expansion/expansion_settings.h>
typedef struct {
@ -15,7 +16,7 @@ typedef struct {
ViewDispatcher* view_dispatcher;
VariableItemList* var_item_list;
Expansion* expansion;
ExpansionSettings settings;
ExpansionSettings* settings;
} ExpansionSettingsApp;
typedef enum {

View file

@ -28,10 +28,6 @@ static void storage_move_to_sd_remove_region() {
if(storage_common_exists(storage, INT_PATH(".region_data"))) {
storage_common_remove(storage, INT_PATH(".region_data"));
}
// No expansion modules yet
if(storage_common_exists(storage, INT_PATH(".expansion.settings"))) {
storage_common_remove(storage, INT_PATH(".expansion.settings"));
}
furi_record_close(RECORD_STORAGE);
}