Redbear Nano firmware using Sandroide and showing how to send custom strings and parameters to the Android application
Dependencies: BLE_API MbedJSONValue mbed nRF51822
Fork of BLE_RedBearNano-SAndroidEDevice by
Diff: main.cpp
- Revision:
- 4:2ef9b332fa7c
- Parent:
- 3:16b7d807fa8c
diff -r 16b7d807fa8c -r 2ef9b332fa7c main.cpp --- a/main.cpp Thu Oct 05 15:00:10 2017 +0000 +++ b/main.cpp Fri Oct 06 10:05:45 2017 +0000 @@ -475,10 +475,29 @@ enqueueItem(toSendQueue, buf, len); } +AnalogIn ain(P0_6); +void fnCustomParameter() { + unsigned short val,max; + int i; + if (ble.getGapState().connected) { + i=0; + max=0; + while(i++<300) { // read the max of 3 consecutive samples = 3*100 (100=10ms/100us) + val = ain.read_u16(); + if (val>max) max=val; + wait_us(100); + } + + // enqueue into bluetooth queue + uint8_t buf[TXRX_BUF_LEN]; + int len = sprintf((char *)buf,"W%d",val); + enqueueItem(toSendQueue, buf, len); + } +} + int main(void) { - for (int i=0;i<maxPins;i++) { pinTypes[i] = PIN_NOTSET; prevValues[i] = 0; @@ -488,6 +507,11 @@ pinGroups[i]=NO_GROUP; } + initPin(28,PIN_OUTPUT); + initPin(29,PIN_OUTPUT); + writeDigital(28,0); + writeDigital(29,1); + ble.init(); ble.onDisconnection(disconnectionCallback); ble.onDataWritten(WrittenHandler); @@ -520,6 +544,9 @@ Ticker gcdTicker; gcdTicker.attach(changeGcdTiming, 5); + + Ticker customParameterTicker; + customParameterTicker.attach(fnCustomParameter, 5); recvQueue = ConstructQueue(40); toSendQueue = ConstructQueue(40);