Dissertation project, looking at BLE communication in cars. This project is BLE peripheral acting as car indicator stalk
Dependencies: BLE_API mbed nRF51822
Fork of BLE_GATT_test1 by
Diff: main.cpp
- Revision:
- 13:a578c382cb7d
- Parent:
- 12:f5b12e8b6043
- Child:
- 14:7225b50aaaf7
--- a/main.cpp Fri Mar 27 12:21:12 2015 +0000 +++ b/main.cpp Fri Mar 27 12:36:36 2015 +0000 @@ -12,31 +12,30 @@ Serial pc(USBTX, USBRX); /*Variable Declarations*/ -const static char DEVICE_NAME[] = "BLE_Broadcaster"; -static volatile bool indicatorOn = false; -static volatile bool indicatorSent = false; -uint8_t cmdOn[8] = { 0x4d,0x32,0x81,0xc0,0x4d,0x4d,0x4d,0x4d }; -uint8_t cmdOff[8] = { 0x4d,0x32,0x81,0xc0,0x32,0x32,0x32,0x32 }; +const static char DEVICE_NAME[] = "BLE_Broadcaster"; +static volatile bool indicatorOn = false; +static volatile bool indicatorSent = false; +uint8_t cmdIndicatorOn[8] = { 0x69,0x6e,0x64,0x69,0x7f,0x7f,0x7f,0x7f }; // = I N D I 127 127 127 127 +uint8_t cmdIndicatorOff[8] = { 0x69,0x6e,0x64,0x69,0x00,0x00,0x00,0x00 }; // = I N D I 0 0 0 0 /** Callback function for ticker */ void blink(void) { led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ - //pc.printf("Tick\r\n"); } /** Callback routine is interrupt activated by a debounced button hit*/ -void buttonPressed(void) { +void indicatorSwitchOn(void) { indicatorOn = true; indicatorSent = false; - pc.printf("Switch on. Is now %d \r\n", indicatorOn); + pc.printf("Indicator switch on.\r\n"); } -/** Callback function for button (indicatorIn) being released */ -void buttonReleased(void) { +/** Callback routine is interrupt activated by a debounced button release*/ +void indicatorSwitchOff(void) { indicatorOn = false; indicatorSent = false; - pc.printf("Switch off. Is now %d \r\n", indicatorOn); + pc.printf("Indicator switch off.\r\n"); } /** Callback function for BLE disconnection */ @@ -60,8 +59,8 @@ // Delay for initial pullup to take effect wait(.01); // Setup Interrupt callback function for a button hit - indicatorIn.fall(&buttonPressed); - indicatorIn.rise(&buttonReleased); + indicatorIn.fall(&indicatorSwitchOn); + indicatorIn.rise(&indicatorSwitchOff); /*Setup Blinky*/ led1 = 1; @@ -78,9 +77,9 @@ ErrorService errorService(ble); /* - **BREDR_NOT_SUPPORTED = BLE only - **LE_GENERAL_DISCOVERABLE = Device is discoverable at any moment (no time out) - **ADV_CONNECTABLE_UNDIRECTED = Any central device can connect + * BREDR_NOT_SUPPORTED = BLE only + * LE_GENERAL_DISCOVERABLE = Device is discoverable at any moment (no time out) + * ADV_CONNECTABLE_UNDIRECTED = Any central device can connect */ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); @@ -98,14 +97,14 @@ if(indicatorOn) { //if button is pressed if(!indicatorSent) { //should only fire the first time! - pc.printf("Command on = %u\r\n", cmdOn); - broadcasterService.sendCommand(cmdOn); + pc.printf("Command on = %u\r\n", cmdIndicatorOn); + broadcasterService.sendCommand(cmdIndicatorOn); indicatorSent = true; //set true to stop multiple firing } } else { if(!indicatorSent) { - pc.printf("Command off = %u\r\n", cmdOff); - broadcasterService.sendCommand(cmdOff); + pc.printf("Command off = %u\r\n", cmdIndicatorOff); + broadcasterService.sendCommand(cmdIndicatorOff); indicatorSent = true; //set true to stop multiple firing } }