Skip to content
Closed
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.
8 changes: 8 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[env:native]
platform = native
build_flags =
-Itest/stubs
-Isrc
-std=c++14
test_build_src = no

[env:m5stickc-plus]
platform = espressif32
board = m5stick-c
Expand Down
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: 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
17 changes: 17 additions & 0 deletions test/stubs/Arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
// Minimal Arduino type/function stubs for native (host) unit testing.
// Only the surface area used by stats.h is covered here.
#include <stdint.h>
#include <string.h>
#include <stdlib.h>

// Controllable clock — tests set this directly to simulate elapsed time.
static uint32_t _mock_millis = 0;
static inline uint32_t millis() { return _mock_millis; }

// Arduino uses a macro-style min that works on any type; provide the
// template version the compiler expects in C++ contexts.
template<typename T>
static inline T min(T a, T b) { return a < b ? a : b; }
template<typename T>
static inline T max(T a, T b) { return a > b ? a : b; }
29 changes: 29 additions & 0 deletions test/stubs/Preferences.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
// No-op Preferences stub for native (host) unit testing.
// All reads return their default, all writes are discarded.
#include <stdint.h>
#include <string.h>

class Preferences {
public:
void begin(const char*, bool) {}
void end() {}
void clear() {}

uint32_t getUInt(const char*, uint32_t d = 0) { return d; }
uint16_t getUShort(const char*, uint16_t d = 0) { return d; }
uint8_t getUChar(const char*, uint8_t d = 0) { return d; }
bool getBool(const char*, bool d = false) { return d; }
size_t getBytes(const char*, void*, size_t) { return 0; }
size_t getString(const char* k, char* buf, size_t len) {
if (buf && len) buf[0] = 0;
return 0;
}

void putUInt(const char*, uint32_t) {}
void putUShort(const char*, uint16_t) {}
void putUChar(const char*, uint8_t) {}
void putBool(const char*, bool) {}
void putBytes(const char*, const void*, size_t) {}
void putString(const char*, const char*) {}
};
Loading