Skip to content

Commit 481c931

Browse files
committed
Experiment with BLE
- clarify documentation how the close pass event service reports data - initialize close pass & distance service with empty event
1 parent 78e04bf commit 481c931

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

docs/software/firmware/bluetooth_services.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ Might get removed soon, prefer the "OBS Service".
9797
| ------------------- | -------------------------------------- | --------------- | ----------------------------------------------------------------------------------- |
9898
| Close Pass Events | `1FE7FAF9-CE63-4236-0003-000000000002` | `READ`,`NOTIFY` | Notifies of new close pass events |
9999

100-
The format of the transmitted string for the *distance characteristic* is `"timestamp;[leftSensor1, leftSensor2, ...];[rightSensor1, rightSensor2, ...]"`, e.g. `"43567893;100,30;400"` or `"43567893;100;"`.
101-
The list of sensor values for one side might be empty, but the entire transmitted string can be safely split on `";"` and each sensor value list safely on `","`.
102-
103-
The format of the transmitted string for the *event characteristic* is `"timestamp;eventName;[payload1, payload2, ...]"`, e.g. `"43567893;button;"` or `"43567893;avg2s;142,83"`.
100+
The format of the transmitted string for the *Close Pass Events* is `"timestamp;eventName;[payload1, payload2, ...]"`, e.g. `"43567893;button;123"`.
104101
The following events are defined:
105102
* `button`: Triggered using a physical button
106103
* Payload: last distance value

src/bluetooth/ClosePassService.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
void ClosePassService::setup(BLEServer *pServer) {
2727
mService = pServer->createService(SERVICE_CLOSEPASS_UUID);
2828
mEventCharacteristic = mService->createCharacteristic(SERVICE_CLOSEPASS_CHAR_EVENT_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);
29+
mEventCharacteristic->setValue((String(millis()) + ";button;").c_str());
2930
}
3031

3132
bool ClosePassService::shouldAdvertise() {
@@ -37,7 +38,7 @@ BLEService* ClosePassService::getService() {
3738
}
3839

3940
void ClosePassService::newPassEvent(const uint32_t millis, const uint16_t leftValue, const uint16_t rightValue) {
40-
auto transmitValue = String(millis) + ";button;" + valueAsString(leftValue) + ";" + valueAsString(rightValue);
41+
auto transmitValue = String(millis) + ";button;" + valueAsString(leftValue);
4142
mEventCharacteristic->setValue(transmitValue.c_str());
4243
mEventCharacteristic->notify();
4344
}

src/bluetooth/DistanceService.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void DistanceService::setup(BLEServer *pServer) {
2727
mService = pServer->createService(SERVICE_DISTANCE_UUID);
2828
mCharacteristic = mService->createCharacteristic(SERVICE_DISTANCE_CHAR_50MS_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);
2929
// SimRa does not like BLE2902
30+
mCharacteristic->setValue((String(millis()) + ";;").c_str());
3031
}
3132

3233
bool DistanceService::shouldAdvertise() {

0 commit comments

Comments
 (0)