Andriy Makukha
/
football_project_wo_output
football_project_wo_output
Fork of football_project by
Diff: main.cpp
- Revision:
- 92:a9ebe6d0a0fa
- Parent:
- 91:0fc897cccc06
- Child:
- 93:620dd0a7ddc7
--- a/main.cpp Sun Jun 12 09:03:16 2016 +0000 +++ b/main.cpp Mon Jun 13 02:00:34 2016 +0000 @@ -3,6 +3,7 @@ #include "output.h" #include <DebounceIn.h> #ifdef BLE_ENABLE + #include "ble/BLE.h" #include "ble/services/DFUService.h" #endif @@ -15,11 +16,11 @@ BLEDevice ble; // Optional: Device Name, add for human read-ability -const static char DEVICE_NAME[] = "PassiveCoach"; +//const static char DEVICE_NAME[] = "PassiveCoach"; // You have up to 26 bytes of advertising data to use. //const static uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x05}; /* Example of hex data */ -const static uint8_t AdvData[] = {"Keep the Space!"}; /* Example of character data */ +//const static uint8_t AdvData[] = {"Keep the Space!"}; /* Example of character data */ #endif // BLE_ENABLE /////////////////////////////////// PINS /////////////////////////////////// @@ -140,12 +141,20 @@ } #ifdef BLE_ENABLE +void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) +{ + //pc.printf("Disconnected \r\n"); + //pc.printf("Restart advertising \r\n"); + ble.startAdvertising(); +} + // Optional: Restart advertising when peer disconnects +/* void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { BLE::Instance().gap().startAdvertising(); } - +*/ // This function is called when the ble initialization process has failed void onBleInitError(BLE &ble, ble_error_t error) { @@ -296,6 +305,12 @@ int main() { +#ifdef BLE_ENABLE + // BLE initialization + ble.init(); + ble.onDisconnection(disconnectionCallback); +#endif // BLE_ENABLE + char tx_buff[100] = {0}; char rx_buff[100] = {0}; char rand_name[NAME_LEN+1] = {0}; @@ -333,10 +348,30 @@ bVLOld = 0; #ifdef BLE_ENABLE - // BLE initialization + // setup advertising + ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); + ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, + (const uint8_t *)"KeepTheSpace", sizeof("KeepTheSpace") - 1); + //ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, + // (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); + + // 100ms; in multiples of 0.625ms. + ble.setAdvertisingInterval(160); + + ble.addService(uartService); + + DFUService dfu(ble); + + ble.startAdvertising(); + //pc.printf("Advertising Start \r\n"); + + /* + // GAP version BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); ble.init(bleInitComplete); // Initialize BLE baselayer DFUService dfu( ble ); + */ #endif // BLE_ENABLE // Pick node number @@ -474,7 +509,7 @@ } #ifdef BLE_ENABLE - ble.waitForEvent(); +// ble.waitForEvent(); #endif // BLE_ENABLE } } \ No newline at end of file