The Shed / Mbed OS nRF52_Button_MWE
Committer:
Condo2k4
Date:
Fri Mar 01 10:03:10 2019 +0000
Revision:
0:f43a2a24edc2
Child:
1:628e1249eaa1
Initial Import

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Condo2k4 0:f43a2a24edc2 1 #include <events/mbed_events.h>
Condo2k4 0:f43a2a24edc2 2 #include <mbed.h>
Condo2k4 0:f43a2a24edc2 3 #include "BLE_EH.h"
Condo2k4 0:f43a2a24edc2 4
Condo2k4 0:f43a2a24edc2 5 static events::EventQueue event_queue(/* event count */ 16 * EVENTS_EVENT_SIZE);
Condo2k4 0:f43a2a24edc2 6
Condo2k4 0:f43a2a24edc2 7 //Serial serial(USBTX, USBRX);
Condo2k4 0:f43a2a24edc2 8 RawSerial serial(P0_6, P0_8, 115200);
Condo2k4 0:f43a2a24edc2 9
Condo2k4 0:f43a2a24edc2 10 /** Schedule processing of events from the BLE middleware in the event queue. */
Condo2k4 0:f43a2a24edc2 11 void schedule_ble_events(BLE::OnEventsToProcessCallbackContext *context) {
Condo2k4 0:f43a2a24edc2 12 event_queue.call(Callback<void()>(&context->ble, &BLE::processEvents));
Condo2k4 0:f43a2a24edc2 13 }
Condo2k4 0:f43a2a24edc2 14
Condo2k4 0:f43a2a24edc2 15 void buttonPress(int id) {
Condo2k4 0:f43a2a24edc2 16 serial.printf("Button Pressed: %d\n", id);
Condo2k4 0:f43a2a24edc2 17 }
Condo2k4 0:f43a2a24edc2 18
Condo2k4 0:f43a2a24edc2 19 InterruptIn b1(BUTTON1);
Condo2k4 0:f43a2a24edc2 20 InterruptIn b2(BUTTON2);
Condo2k4 0:f43a2a24edc2 21 InterruptIn b3(BUTTON3);
Condo2k4 0:f43a2a24edc2 22 InterruptIn b4(BUTTON4);
Condo2k4 0:f43a2a24edc2 23
Condo2k4 0:f43a2a24edc2 24 void alive() {
Condo2k4 0:f43a2a24edc2 25 serial.printf("Blink\n");
Condo2k4 0:f43a2a24edc2 26 }
Condo2k4 0:f43a2a24edc2 27
Condo2k4 0:f43a2a24edc2 28 int main() {
Condo2k4 0:f43a2a24edc2 29 // serial.getc(); //DEBUG ONLY - pauses until first keypress
Condo2k4 0:f43a2a24edc2 30 serial.set_flow_control(SerialBase::RTSCTS, P0_5, P0_7);
Condo2k4 0:f43a2a24edc2 31
Condo2k4 0:f43a2a24edc2 32 BLE &ble = BLE::Instance();
Condo2k4 0:f43a2a24edc2 33 ble.onEventsToProcess(schedule_ble_events);
Condo2k4 0:f43a2a24edc2 34 BLE_EH ble_eh(ble, event_queue);
Condo2k4 0:f43a2a24edc2 35 ble_eh.start();
Condo2k4 0:f43a2a24edc2 36 serial.printf("BLE started\n");
Condo2k4 0:f43a2a24edc2 37
Condo2k4 0:f43a2a24edc2 38 b1.rise(event_queue.event(&buttonPress, 1));
Condo2k4 0:f43a2a24edc2 39 b2.rise(event_queue.event(&buttonPress, 2));
Condo2k4 0:f43a2a24edc2 40 b3.rise(event_queue.event(&buttonPress, 3));
Condo2k4 0:f43a2a24edc2 41 b4.rise(event_queue.event(&buttonPress, 4));
Condo2k4 0:f43a2a24edc2 42
Condo2k4 0:f43a2a24edc2 43 event_queue.call_every(2000, &alive);
Condo2k4 0:f43a2a24edc2 44 event_queue.dispatch_forever();
Condo2k4 0:f43a2a24edc2 45 return 0;
Condo2k4 0:f43a2a24edc2 46 }