Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Fix address settings reloading, and consequently dongle leds updates. #363

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion device/src/bt_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <zephyr/settings/settings.h>
#include "bt_conn.h"
#include "bt_scan.h"
#include "settings.h"

bool BtManager_Restarting = false;

Expand Down Expand Up @@ -99,7 +100,7 @@ void BtManager_RestartBt() {
printk("Bluetooth init failed (err %d)\n", err);
}

settings_load();
Settings_Reload();

BtManager_StartBt();

Expand Down
8 changes: 6 additions & 2 deletions device/src/bt_pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "bt_manager.h"
#include "bt_advertise.h"
#include "legacy/host_connection.h"
#include "settings.h"

bool BtPair_LastPairingSucceeded = true;
bool BtPair_OobPairingInProgress = false;
Expand Down Expand Up @@ -50,7 +51,7 @@ void BtPair_SetRemoteOob(const struct bt_le_oob* oob) {

void BtPair_PairCentral() {
pairingAsCentral = true;
settings_load();
Settings_Reload();
bt_le_oob_set_sc_flag(true);
BtScan_Start();
printk ("Scanning for pairable device\n");
Expand All @@ -59,7 +60,7 @@ void BtPair_PairCentral() {

void BtPair_PairPeripheral() {
pairingAsCentral = false;
settings_load();
Settings_Reload();
bt_le_oob_set_sc_flag(true);
BtAdvertise_Start(ADVERTISE_NUS);
printk ("Waiting for central to pair to me.\n");
Expand Down Expand Up @@ -168,6 +169,9 @@ void BtPair_Unpair(const bt_addr_le_t addr) {

// Iterate through all stored bonds
bt_foreach_bond(BT_ID_DEFAULT, bt_foreach_bond_cb_delete, (void*)&args);

// Update settings
Settings_Reload();
}

struct check_bonded_device_args_t {
Expand Down
24 changes: 16 additions & 8 deletions device/src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@

bool RightAddressIsSet = false;

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 char foo_val[BT_ADDR_SIZE];
read_cb(cb_arg, &foo_val, len);

bool rightAddressIsSet = false;

for (uint8_t i=0; i<PeerCount; i++) {
if (strcmp(name, Peers[i].name) == 0) {
printk("Settings: Found peer '%s' with address ", name);
Expand All @@ -24,17 +31,12 @@ static int peerAddressSet(const char *name, size_t len, settings_read_cb read_cb
}
printk("\n");
if (i == PeerIdRight) {
rightAddressIsSet = true;
setRightAddressIsSet(true);
}
break;
}
}

if (rightAddressIsSet != RightAddressIsSet) {
RightAddressIsSet = rightAddressIsSet;
DongleLeds_Update();
}

return 0;
}

Expand All @@ -49,3 +51,9 @@ void InitSettings(void)
settings_register(&settingsHandler);
settings_load();
}

void Settings_Reload(void)
{
setRightAddressIsSet(false);
settings_load();
}
3 changes: 2 additions & 1 deletion device/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

// Functions:

extern void InitSettings(void);
void InitSettings(void);
void Settings_Reload(void);

// Variables:

Expand Down