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.
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
main.cpp
00001 // S14_TOF_Detector - Easy GATT setup using bricks for DETECTION services 00002 00003 #include "bricks/bricks.h" 00004 #include "detection.h" 00005 #include "bricks/stop.h" 00006 #include "shields/shields.h" 00007 00008 typedef DisplayShield Dish; // a short hand for DisplayShield 00009 00010 Dish *pShield; // to access our 6180XA1 DIsplay SHield 00011 StopButton stop(USER_BUTTON); // press blue button for stop 00012 00013 //============================================================================== 00014 // Data Ready Callback 00015 //============================================================================== 00016 00017 static void cbReady(void) // called if measurement done, data ready 00018 { 00019 pShield->ready(); // forward IRQ callback to ready() 00020 } 00021 00022 //============================================================================== 00023 // Simple Loop - Cannot Change Mode 00024 //============================================================================== 00025 00026 void loop(Dish &o) 00027 { 00028 int err = o.start(cbReady); // start measuement callback @ cbReady 00029 00030 if (err == 0) 00031 { 00032 // while ( !stop.request() ) 00033 { 00034 if( o.request() ) // data service requested by 6180XA1 IRQ? 00035 o.handle(); // handle data transfer 00036 00037 o.refresh(); // refresh display 00038 } 00039 o.stop(); // stop all current measurements 00040 } 00041 // stop.clear(); // clear stop request (of stop button) 00042 } 00043 00044 00045 //============================================================================== 00046 // Callbacks 00047 //============================================================================== 00048 00049 void cbError(O&o) // Error Reporting Callback 00050 { 00051 blinkError(o); // 'error' blink sequence 00052 } 00053 00054 void cbConnect(O&o) // Connection Callback 00055 { 00056 blinkConnected(o); // 'error' blink sequence 00057 } 00058 00059 void cbDisconnect(O&o) // Disconnection Callback 00060 { 00061 advertise(o); // start advertising on client disconnect 00062 blinkAdvertise(o); // 'advertise' blink sequence 00063 } 00064 00065 void cbSetup(O&o) // Immediately After Initializing BLE 00066 { 00067 services(o); // enroll all services & setup callbacks 00068 00069 onConnect(o,cbConnect); // setup connection callback 00070 onDisconnect(o,cbDisconnect); // setup disconnection callback 00071 00072 device(o,"S14#0.15 ToF Detector"); // setup device name 00073 name(o,"Detector"); // setup advertising name 00074 data(o,"My Layout"); // setup advertising data 00075 00076 advertise(o,"C:ng",100); // start advertising @ 100 msec interval 00077 blinkAdvertise(o); // 'advertise' blink sequence 00078 } 00079 00080 //============================================================================== 00081 // Main Program 00082 //============================================================================== 00083 00084 #define VL6180X_I2C_SDA D14 00085 #define VL6180X_I2C_SCL D15 00086 00087 #define RANGE 0 00088 #define ALS 1 00089 00090 int main(void) 00091 { 00092 O o; // declare a blob (BLE OBject) 00093 verbose(o); // enable all trace messages 00094 blinkIdle(o); // idle blinking - just started! 00095 00096 //pShield = new Dish; // create a DIsplay SHield class instance 00097 //pShield->init("ToF",1000); 00098 00099 00100 DevI2C *pDevice; 00101 X_NUCLEO_6180XA1 *pBoard; 00102 00103 pDevice = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL); 00104 00105 // next we create the 6180XA1 expansion board singleton obj 00106 // after that we are already able to display the init message 00107 00108 //pBoard = X_NUCLEO_6180XA1::Instance(pDevice, A3, A2, D13, D2); 00109 00110 init(o,cbSetup,cbError); // init BLE base layer, always do first 00111 sleep(o,5000); 00112 00113 pBoard = X_NUCLEO_6180XA1::Instance(pDevice, A3, A2, D13, D2); 00114 00115 while (true) // Infinite loop waiting for BLE events 00116 sleep(o); // low power waiting for BLE events 00117 }
Generated on Tue Jul 12 2022 21:31:05 by
1.7.2
