Skip to content

Commit b2280e0

Browse files
authored
Merge pull request #87 from openppg/patch/ble-screen-theme
Add BLE characteristic for theme selection
2 parents 228d2a4 + 1c37e5c commit b2280e0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/sp140/extra-data.ino

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,25 @@ class PerformanceModeCallbacks: public BLECharacteristicCallbacks {
261261
}
262262
};
263263

264+
class ThemeCallbacks: public BLECharacteristicCallbacks {
265+
void onWrite(BLECharacteristic *pCharacteristic) {
266+
std::string value = pCharacteristic->getValue();
267+
268+
if (value.length() == 1) {
269+
uint8_t theme = value[0];
270+
if (theme <= 1) { // Ensure value is 0 or 1
271+
deviceData.theme = theme;
272+
writeDeviceData();
273+
USBSerial.println("Theme saved to Preferences");
274+
} else {
275+
USBSerial.println("Invalid theme value");
276+
}
277+
} else {
278+
USBSerial.println("Invalid value length - expected 1 byte");
279+
}
280+
}
281+
};
282+
264283
class ScreenRotationCallbacks: public BLECharacteristicCallbacks {
265284
void onWrite(BLECharacteristic *pCharacteristic) {
266285
std::string value = pCharacteristic->getValue();
@@ -432,6 +451,15 @@ void setupBLE() {
432451

433452
pPerformanceMode->setValue(performanceMode);
434453

454+
BLECharacteristic *pTheme = pConfigService->createCharacteristic(
455+
BLEUUID(THEME_UUID),
456+
BLECharacteristic::PROPERTY_READ |
457+
BLECharacteristic::PROPERTY_WRITE);
458+
459+
pTheme->setCallbacks(new ThemeCallbacks());
460+
int theme = deviceData.theme ? 1 : 0;
461+
pTheme->setValue(theme);
462+
435463
BLECharacteristic *pScreenRotation = pConfigService->createCharacteristic(
436464
BLEUUID(SCREEN_ROTATION_UUID),
437465
BLECharacteristic::PROPERTY_READ |

0 commit comments

Comments
 (0)