Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:ce6be5c83dde, committed 2018-05-12
- Comitter:
- mirika
- Date:
- Sat May 12 02:42:06 2018 +0000
- Parent:
- 1:2237580e56f1
- Commit message:
- receive ???
Changed in this revision
source/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2237580e56f1 -r ce6be5c83dde source/main.cpp --- a/source/main.cpp Fri May 11 14:28:16 2018 +0000 +++ b/source/main.cpp Sat May 12 02:42:06 2018 +0000 @@ -23,6 +23,18 @@ DigitalOut led1(LED1, 1); DigitalOut led2(LED2, 1); +#define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console; + * it will have an impact on code-size and power consumption. */ + +#if NEED_CONSOLE_OUTPUT +#define DEBUG(STR) { if (uartServicePtr) uartServicePtr->write(STR, strlen(STR)); } +#else +#define DEBUG(...) /* nothing */ +#endif /* #if NEED_CONSOLE_OUTPUT */ + + + + static UARTService* uartServicePtr; static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE); @@ -33,6 +45,10 @@ } +void dataReadCallback( const GattReadCallbackParams *params ) +{ + DEBUG("Receive\r\n"); +} void blinkCallback(void) { @@ -40,7 +56,7 @@ BLE &ble = BLE::Instance(); if (ble.gap().getState().connected) { - // eventQueue.call(updateSensorValue); + // DEBUG("Ping \r\n"); } } @@ -52,18 +68,8 @@ /* Initialization error handling should go here */ } -void printMacAddress() -{ - /* Print out device MAC address to the console*/ - Gap::AddressType_t addr_type; - Gap::Address_t address; - BLE::Instance().gap().getAddress(&addr_type, address); - printf("DEVICE MAC ADDRESS: "); - for (int i = 5; i >= 1; i--){ - printf("%02x:", address[i]); - } - printf("%02x\r\n", address[0]); -} + + /** * Callback triggered when the ble initialization process has finished @@ -85,8 +91,11 @@ } ble.gap().onDisconnection(disconnectionCallback); - ble.gap().onDataWritten( DataWriteCallback ); - ble.gap().onDataRead( DataReadCallback ); + //ble.gattServer().onDataRead( dataReadCallback ); //const DataReadCallback_t & callback) + ble.onDataRead( dataReadCallback); + + // ble.gap().onDataWritten( DataWriteCallback ); + // ble.gap().onDataRead( DataReadCallback ); /* Setup primary service */ uartServicePtr = new UARTService(ble); @@ -108,10 +117,10 @@ ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); #endif - ble.gap().setAdvertisingInterval(1000); /* 1000ms */ + ble.gap().setAdvertisingInterval(100); /* 1000ms */ ble.gap().startAdvertising(); - printMacAddress(); + // printMacAddress(); } void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {