mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
BadKB better name and settings handling
This commit is contained in:
@@ -30,11 +30,9 @@ static void bad_kb_app_tick_event_callback(void* context) {
|
||||
|
||||
static void bad_kb_load_settings(BadKbApp* app) {
|
||||
furi_string_reset(app->keyboard_layout);
|
||||
strcpy(app->config.bt_name, "");
|
||||
memcpy(
|
||||
app->config.bt_mac,
|
||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_MAC_LEN);
|
||||
BadKbConfig* cfg = &app->config;
|
||||
strcpy(cfg->bt_name, "");
|
||||
memcpy(cfg->bt_mac, BAD_KB_EMPTY_MAC, BAD_KB_MAC_LEN);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
@@ -44,16 +42,12 @@ static void bad_kb_load_settings(BadKbApp* app) {
|
||||
furi_string_reset(app->keyboard_layout);
|
||||
}
|
||||
if(flipper_format_read_string(file, "Bt_Name", tmp_str) && !furi_string_empty(tmp_str)) {
|
||||
strcpy(app->config.bt_name, furi_string_get_cstr(tmp_str));
|
||||
strcpy(cfg->bt_name, furi_string_get_cstr(tmp_str));
|
||||
} else {
|
||||
strcpy(app->config.bt_name, "");
|
||||
strcpy(cfg->bt_name, "");
|
||||
}
|
||||
if(!flipper_format_read_hex(
|
||||
file, "Bt_Mac", (uint8_t*)&app->config.bt_mac, BAD_KB_MAC_LEN)) {
|
||||
memcpy(
|
||||
app->config.bt_mac,
|
||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_MAC_LEN);
|
||||
if(!flipper_format_read_hex(file, "Bt_Mac", (uint8_t*)&cfg->bt_mac, BAD_KB_MAC_LEN)) {
|
||||
memcpy(cfg->bt_mac, BAD_KB_EMPTY_MAC, BAD_KB_MAC_LEN);
|
||||
}
|
||||
furi_string_free(tmp_str);
|
||||
flipper_format_file_close(file);
|
||||
@@ -77,12 +71,13 @@ static void bad_kb_load_settings(BadKbApp* app) {
|
||||
}
|
||||
|
||||
static void bad_kb_save_settings(BadKbApp* app) {
|
||||
BadKbConfig* cfg = &app->config;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
if(flipper_format_file_open_always(file, BAD_KB_SETTINGS_PATH)) {
|
||||
flipper_format_write_string(file, "Keyboard_Layout", app->keyboard_layout);
|
||||
flipper_format_write_string_cstr(file, "Bt_Name", app->config.bt_name);
|
||||
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&app->config.bt_mac, BAD_KB_MAC_LEN);
|
||||
flipper_format_write_string_cstr(file, "Bt_Name", cfg->bt_name);
|
||||
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&cfg->bt_mac, BAD_KB_MAC_LEN);
|
||||
flipper_format_file_close(file);
|
||||
}
|
||||
flipper_format_free(file);
|
||||
|
||||
@@ -531,11 +531,6 @@ int32_t bad_kb_conn_apply(BadKbApp* app) {
|
||||
// Set profile, restart BT, adjust defaults
|
||||
furi_check(bt_set_profile(app->bt, BtProfileHidKeyboard));
|
||||
|
||||
// What was empty is now adjusted by furi_hal_bt so save the new defaults
|
||||
if(strcmp(app->config.bt_name, "") == 0) {
|
||||
strcpy(app->config.bt_name, furi_hal_bt_get_profile_adv_name(kbd));
|
||||
}
|
||||
|
||||
// Advertise even if BT is off in settings
|
||||
furi_hal_bt_start_advertising();
|
||||
|
||||
@@ -589,6 +584,11 @@ void bad_kb_conn_reset(BadKbApp* app) {
|
||||
}
|
||||
|
||||
void bad_kb_config_adjust(BadKbConfig* cfg) {
|
||||
// Avoid empty name
|
||||
if(strcmp(cfg->bt_name, "") == 0) {
|
||||
snprintf(cfg->bt_name, BAD_KB_NAME_LEN, "Control %s", furi_hal_version_get_name_ptr());
|
||||
}
|
||||
|
||||
// MAC is adjusted by furi_hal_bt, adjust here too so it matches after applying
|
||||
const uint8_t* normal_mac = furi_hal_version_get_ble_mac();
|
||||
uint8_t empty_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
||||
|
||||
Reference in New Issue
Block a user