Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 74:365386b6655e, committed 2018-11-27
- Comitter:
- frunzl
- Date:
- Tue Nov 27 21:53:47 2018 +0000
- Parent:
- 73:9bedb952ab9c
- Commit message:
- assignment
Changed in this revision
| source/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/source/main.cpp Fri Nov 16 14:19:35 2018 +0000
+++ b/source/main.cpp Tue Nov 27 21:53:47 2018 +0000
@@ -20,6 +20,7 @@
#include "ble/DiscoveredCharacteristic.h"
#include "ble/DiscoveredService.h"
+InterruptIn button(USER_BUTTON);
DigitalOut alivenessLED(LED1, 1);
static DiscoveredCharacteristic ledCharacteristic;
static bool triggerLedCharacteristic;
@@ -27,10 +28,19 @@
static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE);
+volatile int isFall = 0;
void periodicCallback(void) {
alivenessLED = !alivenessLED; /* Do blinky on LED1 while we're waiting for BLE events */
}
+void rise() {
+ isFall = 0;
+}
+
+void fall() {
+ isFall = 1;
+}
+
void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) {
// parse the advertising payload, looking for data type COMPLETE_LOCAL_NAME
// The advertising payload is a collection of key/value records where
@@ -106,7 +116,7 @@
}
void triggerToggledWrite(const GattReadCallbackParams *response) {
- if (response->handle == ledCharacteristic.getValueHandle()) {
+ if (response->handle == ledCharacteristic.getValueHandle() && isFall) {
printf("triggerToggledWrite: handle %u, offset %u, len %u\r\n", response->handle, response->offset, response->len);
for (unsigned index = 0; index < response->len; index++) {
printf("%c[%02x]", response->data[index], response->data[index]);
@@ -189,11 +199,16 @@
triggerLedCharacteristic = false;
eventQueue.call_every(500, periodicCallback);
+ button.rise(&rise);
+ button.fall(&fall);
+
BLE &ble = BLE::Instance();
ble.onEventsToProcess(scheduleBleEventsProcessing);
ble.init(bleInitComplete);
eventQueue.dispatch_forever();
+
+
return 0;
}