![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TOF based Presence Detector
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
Diff: main.cpp
- Revision:
- 28:a23b16555909
- Parent:
- 27:32267cee7cb8
diff -r 32267cee7cb8 -r a23b16555909 main.cpp --- a/main.cpp Sat Jan 14 08:43:14 2017 +0000 +++ b/main.cpp Mon Aug 20 16:42:59 2018 +0000 @@ -1,7 +1,46 @@ -// S07_Detection - Easy GATT setup using bricks for DETECTION services +// S14_TOF_Detector - Easy GATT setup using bricks for DETECTION services #include "bricks/bricks.h" #include "detection.h" +#include "bricks/stop.h" +#include "shields/shields.h" + + typedef DisplayShield Dish; // a short hand for DisplayShield + + Dish *pShield; // to access our 6180XA1 DIsplay SHield + StopButton stop(USER_BUTTON); // press blue button for stop + +//============================================================================== +// Data Ready Callback +//============================================================================== + + static void cbReady(void) // called if measurement done, data ready + { + pShield->ready(); // forward IRQ callback to ready() + } + +//============================================================================== +// Simple Loop - Cannot Change Mode +//============================================================================== + + void loop(Dish &o) + { + int err = o.start(cbReady); // start measuement callback @ cbReady + + if (err == 0) + { +// while ( !stop.request() ) + { + if( o.request() ) // data service requested by 6180XA1 IRQ? + o.handle(); // handle data transfer + + o.refresh(); // refresh display + } + o.stop(); // stop all current measurements + } +// stop.clear(); // clear stop request (of stop button) + } + //============================================================================== // Callbacks @@ -30,7 +69,7 @@ onConnect(o,cbConnect); // setup connection callback onDisconnect(o,cbDisconnect); // setup disconnection callback - device(o,"S07 Detector #3.47"); // setup device name + device(o,"S14#0.15 ToF Detector"); // setup device name name(o,"Detector"); // setup advertising name data(o,"My Layout"); // setup advertising data @@ -42,14 +81,37 @@ // Main Program //============================================================================== +#define VL6180X_I2C_SDA D14 +#define VL6180X_I2C_SCL D15 + +#define RANGE 0 +#define ALS 1 + int main(void) { - O o; // declare a blob (BLE OBject) - verbose(o); // enable all trace messages - blinkIdle(o); // idle blinking - just started! + O o; // declare a blob (BLE OBject) + verbose(o); // enable all trace messages + blinkIdle(o); // idle blinking - just started! + + //pShield = new Dish; // create a DIsplay SHield class instance + //pShield->init("ToF",1000); + + + DevI2C *pDevice; + X_NUCLEO_6180XA1 *pBoard; - init(o,cbSetup,cbError); // init BLE base layer, always do first + pDevice = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL); + + // next we create the 6180XA1 expansion board singleton obj + // after that we are already able to display the init message - while (true) // Infinite loop waiting for BLE events - sleep(o); // low power waiting for BLE events + //pBoard = X_NUCLEO_6180XA1::Instance(pDevice, A3, A2, D13, D2); + + init(o,cbSetup,cbError); // init BLE base layer, always do first + sleep(o,5000); + + pBoard = X_NUCLEO_6180XA1::Instance(pDevice, A3, A2, D13, D2); + + while (true) // Infinite loop waiting for BLE events + sleep(o); // low power waiting for BLE events } \ No newline at end of file