Skip to content

Commit

Permalink
Add UsbCommand_EraseAllSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
kareltucek committed Jan 9, 2025
1 parent 866ad00 commit 26039ca
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 8 deletions.
29 changes: 21 additions & 8 deletions device/src/settings.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#include <zephyr/bluetooth/addr.h>
#include <zephyr/settings/settings.h>
#include <zephyr/storage/flash_map.h>
#include <zephyr/device.h>
#include "bt_conn.h"
#include "dongle_leds.h"
#include "stubs.h"

bool RightAddressIsSet = false;

static void setRightAddressIsSet(bool isSet)
{
static void setRightAddressIsSet(bool isSet) {
if (RightAddressIsSet != isSet) {
RightAddressIsSet = isSet;
DongleLeds_Update();
}
}

// (This isn't getting called at all when there is no "uhk/addr" settings present.)
static int peerAddressSet(const char *name, size_t len, settings_read_cb read_cb, void *cb_arg)
{
static int peerAddressSet(const char *name, size_t len, settings_read_cb read_cb, void *cb_arg) {
static char foo_val[BT_ADDR_SIZE];
read_cb(cb_arg, &foo_val, len);

Expand Down Expand Up @@ -45,15 +45,28 @@ struct settings_handler settingsHandler = {
.h_set = peerAddressSet,
};

void InitSettings(void)
{
void InitSettings(void) {
settings_subsys_init();
settings_register(&settingsHandler);
settings_load();
}

void Settings_Reload(void)
{
void Settings_Reload(void) {
setRightAddressIsSet(false);
settings_load();
}

static int delete_handler(const char *key, size_t len, settings_read_cb read_cb, void *cb_arg, void *param) {
settings_delete(key);
return 0;
}

void Settings_Erase(void) {
settings_load();
settings_load_subtree_direct(NULL, delete_handler, NULL);
settings_save();

printk("Settings: Erased all settings\n");

Settings_Reload();
}
1 change: 1 addition & 0 deletions device/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

void InitSettings(void);
void Settings_Reload(void);
void Settings_Erase(void);

// Variables:

Expand Down
1 change: 1 addition & 0 deletions right/src/usb_commands/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
target_sources(${PROJECT_NAME} PRIVATE
usb_command_apply_config.c
usb_command_draw_oled.c
usb_command_erase_ble_settings.c
usb_command_exec_macro_command.c
#usb_command_get_adc_value.c
usb_command_get_debug_buffer.c
Expand Down
11 changes: 11 additions & 0 deletions right/src/usb_commands/usb_command_erase_ble_settings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifdef __ZEPHYR__

#include "settings.h"
#include "usb_command_erase_ble_settings.h"

void UsbCommand_EraseAllSettings(void) {
Settings_Erase();
}

#endif

14 changes: 14 additions & 0 deletions right/src/usb_commands/usb_command_erase_ble_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __USB_COMMAND_ERASE_BLE_SETTINGS_H__
#define __USB_COMMAND_ERASE_BLE_SETTINGS_H__

// Includes:

// Includes:

// Typedefs:

// Functions:

void UsbCommand_EraseAllSettings(void);

#endif
10 changes: 10 additions & 0 deletions right/src/usb_protocol_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifdef __ZEPHYR__
#include "usb_commands/usb_command_draw_oled.h"
#include "usb_commands/usb_command_pairing.h"
#include "usb_commands/usb_command_erase_ble_settings.h"
#include "bt_conn.h"
#else
#include "usb_commands/usb_command_set_test_led.h"
Expand Down Expand Up @@ -106,6 +107,9 @@ void UsbProtocolHandler(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidI
case UsbCommandId_EnterPairingMode:
UsbCommand_EnterPairingMode(GenericHidOutBuffer, GenericHidInBuffer);
break;
case UsbCommandId_EraseBleSettings:
UsbCommand_EraseAllSettings();
break;
#else
case UsbCommandId_JumpToModuleBootloader:
UsbCommand_JumpToModuleBootloader(GenericHidOutBuffer, GenericHidInBuffer);
Expand Down Expand Up @@ -153,4 +157,10 @@ void SetBufferBleAddress(uint8_t *GenericHidInBuffer, uint32_t offset, const bt_
GenericHidInBuffer[offset + i] = addr->a.val[i];
}
}


// void UsbCommand_EraseBleSettings(void) {
// Settings_Erase();
// }

#endif
1 change: 1 addition & 0 deletions right/src/usb_protocol_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
UsbCommandId_UnpairAll = 0x1a,
UsbCommandId_IsPaired = 0x1b,
UsbCommandId_EnterPairingMode = 0x1c,
UsbCommandId_EraseBleSettings = 0x1d,
} usb_command_id_t;

typedef enum {
Expand Down

0 comments on commit 26039ca

Please sign in to comment.