The Shed / Mbed OS nRF52_Button_MWE
Revision:
0:f43a2a24edc2
Child:
1:628e1249eaa1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main.cpp	Fri Mar 01 10:03:10 2019 +0000
@@ -0,0 +1,46 @@
+#include <events/mbed_events.h>
+#include <mbed.h>
+#include "BLE_EH.h"
+
+static events::EventQueue event_queue(/* event count */ 16 * EVENTS_EVENT_SIZE);
+
+//Serial serial(USBTX, USBRX);
+RawSerial serial(P0_6, P0_8, 115200);
+
+/** Schedule processing of events from the BLE middleware in the event queue. */
+void schedule_ble_events(BLE::OnEventsToProcessCallbackContext *context) {
+    event_queue.call(Callback<void()>(&context->ble, &BLE::processEvents));
+}
+
+void buttonPress(int id) {
+    serial.printf("Button Pressed: %d\n", id);
+}
+
+InterruptIn b1(BUTTON1);
+InterruptIn b2(BUTTON2);
+InterruptIn b3(BUTTON3);
+InterruptIn b4(BUTTON4);
+
+void alive() {
+    serial.printf("Blink\n");
+}
+
+int main() {
+//    serial.getc(); //DEBUG ONLY - pauses until first keypress
+    serial.set_flow_control(SerialBase::RTSCTS, P0_5, P0_7);
+    
+    BLE &ble = BLE::Instance();
+    ble.onEventsToProcess(schedule_ble_events);
+    BLE_EH ble_eh(ble, event_queue);
+    ble_eh.start();
+    serial.printf("BLE started\n");
+    
+    b1.rise(event_queue.event(&buttonPress, 1));
+    b2.rise(event_queue.event(&buttonPress, 2));
+    b3.rise(event_queue.event(&buttonPress, 3));
+    b4.rise(event_queue.event(&buttonPress, 4));
+
+    event_queue.call_every(2000, &alive);
+    event_queue.dispatch_forever();
+    return 0;
+}