Skip to content
Open
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
Binary file added characters/memes-src/attention.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes-src/busy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes-src/celebrate.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes-src/dizzy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes-src/heart.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes-src/idle.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions characters/memes-src/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "memes",
"colors": {
"bg": "#000000",
"text": "#FFFFFF",
"textDim": "#808080"
},
"states": {
"sleep": "sleep.gif",
"idle": "idle.gif",
"busy": "busy.gif",
"attention": "attention.gif",
"celebrate": "celebrate.gif",
"dizzy": "dizzy.gif",
"heart": "heart.gif"
}
}
Binary file added characters/memes-src/sleep.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes/attention.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes/busy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes/celebrate.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes/dizzy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes/heart.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characters/memes/idle.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions characters/memes/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "memes",
"colors": {
"bg": "#000000",
"text": "#FFFFFF",
"textDim": "#808080"
},
"states": {
"sleep": "sleep.gif",
"idle": "idle.gif",
"busy": "busy.gif",
"attention": "attention.gif",
"celebrate": "celebrate.gif",
"dizzy": "dizzy.gif",
"heart": "heart.gif"
}
}
Binary file added characters/memes/sleep.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions src/ble_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ static volatile bool secure = false;
static volatile uint32_t passkey = 0;
static volatile uint16_t mtu = 23;

// BD address of the currently connected peer. Set on connect, cleared on
// disconnect. Used by bleRemoveCurrentBond() so "unpair" only removes the
// host that sent the command rather than wiping all stored bonds.
static esp_bd_addr_t peerAddr;
static volatile bool hasPeer = false;

static void rxPush(const uint8_t* p, size_t n) {
for (size_t i = 0; i < n; i++) {
size_t next = (rxHead + 1) % RX_CAP;
Expand All @@ -47,15 +53,21 @@ class RxCallbacks : public BLECharacteristicCallbacks {
};

class ServerCallbacks : public BLEServerCallbacks {
void onConnect(BLEServer* s) override {
// Use the extended overload to capture the peer BD address.
void onConnect(BLEServer* s, esp_ble_gatts_cb_param_t* param) override {
connected = true;
Serial.println("[ble] connected");
memcpy((void*)peerAddr, param->connect.remote_bda, sizeof(esp_bd_addr_t));
hasPeer = true;
Serial.printf("[ble] connected %02x:%02x:%02x:%02x:%02x:%02x\n",
peerAddr[0], peerAddr[1], peerAddr[2],
peerAddr[3], peerAddr[4], peerAddr[5]);
}
void onDisconnect(BLEServer* s) override {
connected = false;
secure = false;
passkey = 0;
mtu = 23;
hasPeer = false;
Serial.println("[ble] disconnected");
// Restart advertising so the next client can find us.
BLEDevice::startAdvertising();
Expand Down Expand Up @@ -137,6 +149,17 @@ bool bleConnected() { return connected; }
bool bleSecure() { return secure; }
uint32_t blePasskey() { return passkey; }

void bleRemoveCurrentBond() {
if (!hasPeer) {
Serial.println("[ble] unpair: no peer to remove");
return;
}
esp_ble_remove_bond_device(peerAddr);
Serial.printf("[ble] removed bond %02x:%02x:%02x:%02x:%02x:%02x\n",
peerAddr[0], peerAddr[1], peerAddr[2],
peerAddr[3], peerAddr[4], peerAddr[5]);
}

void bleClearBonds() {
int n = esp_ble_get_bond_device_num();
if (n <= 0) return;
Expand Down
7 changes: 5 additions & 2 deletions src/ble_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ bool bleSecure();
// Non-zero while a 6-digit pairing passkey should be on screen. main.cpp
// renders it; cleared automatically on auth complete or disconnect.
uint32_t blePasskey();
// Erase all stored bonds (LTKs) from NVS. Called from the "unpair" cmd
// and from factory reset.
// Remove only the bond for the currently connected peer. Called from the
// "unpair" JSON command so a desktop can unpair itself without affecting
// bonds held by other hosts.
void bleRemoveCurrentBond();
// Erase ALL stored bonds from NVS. Called only from factory reset.
void bleClearBonds();
size_t bleAvailable();
int bleRead();
Expand Down
2 changes: 2 additions & 0 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ inline void dataPoll(TamaState* out) {
}
}

bool wasConnected = out->connected;
out->connected = dataConnected();
if (!out->connected) {
if (wasConnected) _rtcValid = false; // force re-sync on next connection
out->sessionsTotal=0; out->sessionsRunning=0; out->sessionsWaiting=0;
out->recentlyCompleted=false; out->lastUpdated=now;
strncpy(out->msg, "No Claude connected", sizeof(out->msg)-1);
Expand Down
2 changes: 1 addition & 1 deletion src/xfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ inline bool xferCommand(JsonDocument& doc) {
}

if (strcmp(cmd, "unpair") == 0) {
bleClearBonds();
bleRemoveCurrentBond();
_xAck("unpair", true);
return true;
}
Expand Down