this code needed help please
Dependencies: ADXL362_v3 BLE_API mbed nRF51822
Fork of BLENano_SimpleTemplate_adxl362_170813 by
Diff: main.cpp
- Revision:
- 10:c90237505549
- Parent:
- 9:ca9a58478ddd
diff -r ca9a58478ddd -r c90237505549 main.cpp --- a/main.cpp Tue Sep 05 06:20:07 2017 +0000 +++ b/main.cpp Thu Oct 19 11:59:32 2017 +0000 @@ -34,6 +34,16 @@ #include "ble/BLE.h" #include "ADXL362.h" +#include "ble/services/UARTService.h" + +#define NEED_CONSOLE_OUTPUT 0 /* 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(...) { printf(__VA_ARGS__); } +#else +#define DEBUG(...) /* nothing */ +#endif /* #if NEED_CONSOLE_OUTPUT */ //------------------------------------------------------------ //Definition @@ -46,10 +56,10 @@ //#define ANALOG_IN_PIN P0_4 //Set SPI Pin -#define CS P0_10 -#define MOSI P0_9 -#define MISO P0_11 -#define SCK P0_8 +#define CS P0_8 +#define MOSI P0_5 +#define MISO P0_6 +#define SCK P0_7 //------------------------------------------------------------ @@ -58,6 +68,7 @@ BLE ble; DigitalOut LED_SET(DIGITAL_OUT_PIN); //AnalogIn ANALOG(ANALOG_IN_PIN); +UARTService *uartServicePtr; //SPI pin setting and change header file.(see ADXL362.h line185) ADXL362 adxl362(CS, MOSI, MISO, SCK); @@ -93,6 +104,15 @@ ble.startAdvertising(); } +void onDataWritten(const GattWriteCallbackParams *params) +{ + if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) { + uint16_t bytesRead = params->len; + DEBUG("received %u bytes\n\r", bytesRead); + ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead); + } +} + //====================================================================== //onDataWritten @@ -164,7 +184,9 @@ Ticker ticker; ticker.attach_us(m_status_check_handle, TICKER_TIME); + //BLE init + DEBUG("Initialising the nRF51822\n\r"); ble.init(); //EventListener @@ -198,6 +220,9 @@ //Start Advertising ble.startAdvertising(); + UARTService uartService(ble); + uartServicePtr = &uartService; + //------------------------------------------------------------ //Loop //------------------------------------------------------------