We are making a bluetooth application for a vehicle.
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
Diff: main.cpp
- Revision:
- 26:3a1d82a26a83
- Parent:
- 25:cb54da929d9a
- Child:
- 27:49f379daad68
--- a/main.cpp Tue Jun 27 17:45:15 2017 +0000 +++ b/main.cpp Tue Jun 27 19:15:57 2017 +0000 @@ -19,14 +19,29 @@ #include "bike_service.h" #include "ble/services/BatteryService.h" +int alarm = 0; + +DigitalOut buzzer(PC_8); DigitalOut led1(LED1, 1); const static char DEVICE_NAME[] = "HeckBike"; static const uint16_t uuid16_list[] = {GattService::UUID_BATTERY_SERVICE, 0x8EC5};//made up UUID for the Heck bike +#define on 0xFFFF +#define off 0 + +#define buttonMask 0x006F + +PortIn sixButtons(PortC, buttonMask); + +unsigned char byteOut = 0; + +unsigned char byteIn = 0x08; + uint8_t inputs = 0x00; uint8_t outputs = 0x00; + uint8_t old_outputs = 0x00; uint32_t timestamp = 0x00; static volatile bool triggerSensorPolling = false; @@ -59,6 +74,7 @@ //} } + void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) { BLE& ble = params->ble; @@ -93,20 +109,44 @@ while (true) { // check for trigger from periodicCallback() if (triggerSensorPolling && ble.getGapState().connected) { + if (outputs & 0x80){ + if (alarm == 0) { + alarm = 1; + } + + } + else { + alarm = 0; + buzzer = 0; + } + triggerSensorPolling = false; - - // let's update our fake inputs. - inputs++; - if (inputs == 100) { - inputs = 0; - } + + byteOut = sixButtons & buttonMask; // update the ble with the inputs - bikeService.updateInputs(inputs); + bikeService.updateInputs(byteOut); bikeService.updateTimestamp(); } else { ble.waitForEvent(); // low power wait for event } + + if (alarm) { + + if (alarm++ < 500) { + buzzer = 1; + } + else { + buzzer = 0; + } + + if (alarm > 1000) { + alarm = 1; + } + + } + + } }