diff options
Diffstat (limited to 'src/ble.cpp')
-rw-r--r-- | src/ble.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ble.cpp b/src/ble.cpp index a7bb73b..854ac82 100644 --- a/src/ble.cpp +++ b/src/ble.cpp @@ -5,6 +5,8 @@ #include "badge/config.h" #include "badge/log.h" +using de::uvok::badge::DisplayIndicator; + static NimBLEServer *server; static NimBLEAdvertising *pAdvertising; static NimBLECharacteristic *selectorCharacteristic; @@ -15,6 +17,8 @@ static volatile struct uint8_t value; } value_changed; +static volatile DisplayIndicator ble_indicator = DisplayIndicator::Uninit; + #define IMAGE_DATA(_, display) display const char *templates[] = { @@ -25,10 +29,14 @@ class BadgeServerCallbacks : public NimBLEServerCallbacks { void onConnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo) override { + LOG_F("Connected!\n"); + ble_indicator = DisplayIndicator::Connected; NimBLEServerCallbacks::onConnect(pServer, connInfo); } void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason) override { + LOG_F("Disconnected!\n"); + ble_indicator = DisplayIndicator::None; NimBLEServerCallbacks::onDisconnect(pServer, connInfo, reason); } } badgeServerCallbacks; @@ -104,6 +112,10 @@ void de::uvok::badge::ble_init(void) pAdvertising = NimBLEDevice::getAdvertising(); pAdvertising->setName("NimBLE Badge"); pAdvertising->setManufacturerData("\xff\xffuvok"); + pAdvertising->setAdvertisingCompleteCallback([](NimBLEAdvertising *) { + LOG_F("Finished advertising\n"); + ble_indicator = DisplayIndicator::None; + }); } bool de::uvok::badge::ble_is_active(void) @@ -118,6 +130,7 @@ void de::uvok::badge::ble_advertise(void) { Serial.println("Long press detected. Starting advertising..."); pAdvertising->start(10000); + ble_indicator = DisplayIndicator::Advertising; } } @@ -129,6 +142,12 @@ de::uvok::badge::ble_poll_result_t de::uvok::badge::ble_poll(void) value_changed.changed = false; return (ble_poll_result_t){.action_type = BleActionType::Template, .new_template = val}; } + if (ble_indicator != DisplayIndicator::Uninit) + { + DisplayIndicator ind = ble_indicator; + ble_indicator = DisplayIndicator::Uninit; + return (ble_poll_result_t){.action_type = BleActionType::Indicator, .new_indicator = ind}; + } return (ble_poll_result_t){.action_type = BleActionType::None}; } |