Add configuration slider for double tapping

This commit is contained in:
2026-03-01 20:45:23 +01:00
parent ef97d8f32a
commit f155d16399
8 changed files with 248 additions and 52 deletions

View File

@@ -1,4 +1,5 @@
#include "ble_config.h"
#include "tap.h"
#include <Adafruit_LittleFS.h>
#include <InternalFileSystem.h>
@@ -8,7 +9,7 @@ extern File cfgFile;
// ─── BLE Config Service objects ───────────────────────────────────────────────
#ifdef FEATURE_CONFIG_SERVICE
BLEService cfgService (0x1234);
BLECharacteristic cfgBlob (0x1235); // ConfigBlob R/W 16 bytes
BLECharacteristic cfgBlob (0x1235); // ConfigBlob R/W 20 bytes
BLECharacteristic cfgCommand (0x1236); // Command W 1 byte
#ifdef FEATURE_TELEMETRY
BLECharacteristic cfgTelemetry(0x1237); // Telemetry R/N 24 bytes
@@ -54,9 +55,17 @@ void saveConfig() {
#ifdef FEATURE_CONFIG_SERVICE
void pushConfigBlob() {
ConfigBlob b;
b.sensitivity = cfg.sensitivity; b.deadZone = cfg.deadZone;
b.accelStrength = cfg.accelStrength; b.curve = (uint8_t)cfg.curve;
b.axisFlip = cfg.axisFlip; b.chargeMode = (uint8_t)cfg.chargeMode; b._pad = 0;
b.sensitivity = cfg.sensitivity;
b.deadZone = cfg.deadZone;
b.accelStrength = cfg.accelStrength;
b.curve = (uint8_t)cfg.curve;
b.axisFlip = cfg.axisFlip;
b.chargeMode = (uint8_t)cfg.chargeMode;
b.tapThreshold = cfg.tapThreshold;
b.tapAction = (uint8_t)cfg.tapAction;
b.tapKey = cfg.tapKey;
b.tapMod = cfg.tapMod;
b._pad = 0;
cfgBlob.write((uint8_t*)&b, sizeof(b));
}
#endif
@@ -64,6 +73,9 @@ void pushConfigBlob() {
void factoryReset() {
cfg = CFG_DEFAULTS; saveConfig();
applyChargeMode(cfg.chargeMode);
#ifdef FEATURE_TAP_DETECTION
applyTapThreshold();
#endif
#ifdef FEATURE_CONFIG_SERVICE
if (!safeMode) pushConfigBlob();
#endif
@@ -84,14 +96,23 @@ void onConfigBlobWrite(uint16_t h, BLECharacteristic* c, uint8_t* d, uint16_t l)
cfg.sensitivity = b->sensitivity;
cfg.deadZone = b->deadZone;
cfg.accelStrength = b->accelStrength;
if (b->curve <= 2) cfg.curve = (CurveType)b->curve;
if (b->curve <= 2) cfg.curve = (CurveType)b->curve;
cfg.axisFlip = b->axisFlip;
if (b->chargeMode <= 2) { cfg.chargeMode = (ChargeMode)b->chargeMode; applyChargeMode(cfg.chargeMode); }
#ifdef FEATURE_TAP_DETECTION
if (b->tapThreshold >= 1 && b->tapThreshold <= 31) {
cfg.tapThreshold = b->tapThreshold;
applyTapThreshold();
}
if (b->tapAction <= 3) cfg.tapAction = (TapAction)b->tapAction;
cfg.tapKey = b->tapKey;
cfg.tapMod = b->tapMod;
#endif
saveConfig();
Serial.print("[CFG] Written — sens="); Serial.print(cfg.sensitivity,0);
Serial.print(" dz="); Serial.print(cfg.deadZone,3);
Serial.print(" curve="); Serial.print(cfg.curve);
Serial.print(" chg="); Serial.println(cfg.chargeMode);
Serial.print(" tapThr="); Serial.print(cfg.tapThreshold);
Serial.print(" tapAction="); Serial.println(cfg.tapAction);
}
void onCommandWrite(uint16_t h, BLECharacteristic* c, uint8_t* d, uint16_t l) {