assignment

Files at this revision

API Documentation at this revision

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
diff -r 9bedb952ab9c -r 365386b6655e source/main.cpp
--- 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;
 }