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:
- 30:243e095a69d9
- Parent:
- 29:e7d4922a4620
--- a/main.cpp Wed Jul 19 05:03:35 2017 +0000 +++ b/main.cpp Wed Jul 19 14:38:04 2017 +0000 @@ -48,9 +48,8 @@ //InterruptIn interruptEventSensor_0(PC_0); // Vibration //InterruptIn interruptEventSensor_1(PC_1); // Tilt -unsigned char byteOut = 0; -unsigned char prevByteOut = 0; -unsigned char byteIn = 0x08; +unsigned char byteIn = 0; +unsigned char prevByteIn = 0; uint8_t inputs = 0x00; uint8_t outputs = 0x00; @@ -85,10 +84,51 @@ } void onDataWrittenCallback(const GattWriteCallbackParams *params) { - //if (params->handle == BikeService.outputs.getValueAttribute().getHandle()) { - //BOB Should update the outputs. - outputs = *(params->data); - //} + //if (params->handle == BikeService.output_characteristic.getValueAttribute().getHandle()) { + outputs = *(params->data); + if (outputs & 0x01){ + led_0 = 1; + } + if ((outputs & 0x01) == 0){ + led_0 = 0; + } + + if (outputs & 0x02){ + led_1 = 1; + } + if ((outputs & 0x02) == 0){ + led_1 = 0; + } + + if (outputs & 0x04){ + buzzer = 1; + } + if ((outputs & 0x04) == 0){ + buzzer = 0; + } + + if (outputs & 0x08){ + rumblr = 1; + } + if ((outputs & 0x08) == 0){ + rumblr = 0; + } + + if (outputs & 0x10){ + alarm_activated = 1; + } + if ((outputs & 0x10) == 0){ + alarm_activated = 0; + alarm_on = 0; + } + + if (outputs & 0x20){ + alarm_on = 1; + } + if ((outputs & 0x20) == 0){ + alarm_on = 0; + } + //} } void alarm() { @@ -164,62 +204,24 @@ // check for trigger from periodicCallback() if (triggerSensorPolling && ble.getGapState().connected) { //if (ble.getGapState().connected) { - if (outputs & 0x01){ - led_0 = 1; - } - if ((outputs & 0x01) == 0){ - led_0 = 0; - } - - if (outputs & 0x02){ - led_1 = 1; - } - if ((outputs & 0x02) == 0){ - led_1 = 0; - } - - if (outputs & 0x04){ - buzzer = 1; - } - if ((outputs & 0x04) == 0){ - buzzer = 0; - } - - if (outputs & 0x08){ - rumblr = 1; - } - if ((outputs & 0x08) == 0){ - rumblr = 0; - } - - if (outputs & 0x10){ - alarm_activated = 1; - } - if ((outputs & 0x10) == 0){ - alarm_activated = 0; - } - if (outputs & 0x20){ - alarm_on = 1; - } - if ((outputs & 0x20) == 0){ - alarm_on = 0; - } triggerSensorPolling = false; - byteOut = sixButtons & buttonMask; + byteIn = sixButtons & buttonMask; // update the ble with the inputs - bikeService.updateInputs(byteOut); - bikeService.updateTimestamp(); - //if ((byteOut & 0x01) && alarm_activated==1) { - // alarm_on = 1; - // } - if (byteOut != prevByteOut){ + //bikeService.updateInputs(byteOut); + //bikeService.updateTimestamp(); + if (((byteIn & 0x01)==0) && alarm_activated==1 && alarm_on==0) { + alarm_on = 1; + outputs = outputs | 0x20; + bikeService.updateOutputs(outputs); + } + if (byteIn != prevByteIn){ // update the ble with the inputs - bikeService.updateInputs(byteOut); + bikeService.updateInputs(byteIn); bikeService.updateTimestamp(); } - prevByteOut = byteOut; + prevByteIn = byteIn; } else { ble.waitForEvent(); // low power wait for event @@ -244,7 +246,7 @@ Ticker ticker_CallBack; //ticker.attach(periodicCallback, 1); // blink LED every second - ticker_CallBack.attach(periodicCallback, 0.01); + ticker_CallBack.attach(periodicCallback, 0.1); BLE::Instance().init(bleInitComplete); }