1919
2020#include " ble_config.h"
2121#include " Arduino_ScienceKitCarrier.h"
22+
2223String name;
2324unsigned long lastNotify = 0 ;
24-
2525ScienceKitCarrier science_kit;
26+ rtos::Thread thread_update_sensors;
2627
27- rtos::Thread _thread_update_sensors;
28-
29- bool _is_connected = false ;
28+ bool ble_is_connected = false ;
3029
3130
3231void setup () {
3332
3433 science_kit.begin (NO_AUXILIARY_THREADS); // Doesn't start the BME688 and external temperature threads for the moment
3534
36- if (!BLE.begin ()) {
35+ if (!BLE.begin ()){
3736 while (1 );
3837 }
3938
@@ -75,8 +74,7 @@ void setup() {
7574
7675 science_kit.startAuxiliaryThreads (); // start the BME688 and External Temperature Probe threads
7776
78- // _thread_check_connection.start(loop_data);
79- _thread_update_sensors.start (update); // this thread updates sensors
77+ thread_update_sensors.start (update); // this thread updates sensors
8078}
8179
8280
@@ -90,7 +88,7 @@ void update(void){
9088void loop (){
9189 BLEDevice central = BLE.central ();
9290 if (central) {
93- _is_connected = true ;
91+ ble_is_connected = true ;
9492 lastNotify=millis ();
9593 while (central.connected ()) {
9694 if (millis ()-lastNotify>10 ){
@@ -101,24 +99,24 @@ void loop(){
10199 }
102100 else {
103101 delay (100 );
104- _is_connected = false ;
102+ ble_is_connected = false ;
105103 }
106104}
107105
108- void updateSubscribedCharacteristics () {
109- if (currentCharacteristic.subscribed ()) {
106+ void updateSubscribedCharacteristics (){
107+ if (currentCharacteristic.subscribed ()){
110108 currentCharacteristic.writeValue (science_kit.getCurrent ());
111109 }
112110
113- if (voltageCharacteristic.subscribed ()) {
111+ if (voltageCharacteristic.subscribed ()){
114112 voltageCharacteristic.writeValue (science_kit.getVoltage ());
115113 }
116114
117- if (resistanceCharacteristic.subscribed ()) {
115+ if (resistanceCharacteristic.subscribed ()){
118116 resistanceCharacteristic.writeValue (science_kit.getResistance ());
119117 }
120118
121- if (lightCharacteristic.subscribed ()) {
119+ if (lightCharacteristic.subscribed ()){
122120 long light[4 ];
123121 light[0 ] = science_kit.getRed ();
124122 light[1 ] = science_kit.getGreen ();
@@ -127,48 +125,48 @@ void updateSubscribedCharacteristics() {
127125 lightCharacteristic.writeValue ((byte*)light, sizeof (light));
128126 }
129127
130- if (proximityCharacteristic.subscribed ()) {
128+ if (proximityCharacteristic.subscribed ()){
131129 proximityCharacteristic.writeValue (science_kit.getProximity ());
132130 }
133131
134- if (accelerationCharacteristic.subscribed ()) {
132+ if (accelerationCharacteristic.subscribed ()){
135133 float acceleration[3 ];
136134 acceleration[0 ] = science_kit.getAccelerationX ();
137135 acceleration[1 ] = science_kit.getAccelerationY ();
138136 acceleration[2 ] = science_kit.getAccelerationZ ();
139137 accelerationCharacteristic.writeValue ((byte*)acceleration, sizeof (acceleration));
140138 }
141139
142- if (gyroscopeCharacteristic.subscribed ()) {
140+ if (gyroscopeCharacteristic.subscribed ()){
143141 float gyroscope[3 ];
144142 gyroscope[0 ] = science_kit.getAngularVelocityX ();
145143 gyroscope[1 ] = science_kit.getAngularVelocityY ();
146144 gyroscope[2 ] = science_kit.getAngularVelocityZ ();
147145 gyroscopeCharacteristic.writeValue ((byte*)gyroscope, sizeof (gyroscope));
148146 }
149147
150- if (magnetometerCharacteristic.subscribed ()) {
148+ if (magnetometerCharacteristic.subscribed ()){
151149 float magnetometer[3 ];
152150 magnetometer[0 ] = science_kit.getMagneticFieldX ();
153151 magnetometer[1 ] = science_kit.getMagneticFieldY ();
154152 magnetometer[2 ] = science_kit.getMagneticFieldZ ();
155153 magnetometerCharacteristic.writeValue ((byte*)magnetometer, sizeof (magnetometer));
156154 }
157155
158- if (temperatureCharacteristic.subscribed ()) {
156+ if (temperatureCharacteristic.subscribed ()){
159157 temperatureCharacteristic.writeValue (science_kit.getTemperature ());
160158 }
161159
162- if (pressureCharacteristic.subscribed ()) {
160+ if (pressureCharacteristic.subscribed ()){
163161 pressureCharacteristic.writeValue (science_kit.getPressure ());
164162 }
165163
166- if (humidityCharacteristic.subscribed ()) {
164+ if (humidityCharacteristic.subscribed ()){
167165 humidityCharacteristic.writeValue (science_kit.getHumidity ());
168166 }
169167
170168 // need to be fix
171- if (sndIntensityCharacteristic.subscribed ()) {
169+ if (sndIntensityCharacteristic.subscribed ()){
172170 if (science_kit.getUltrasonicIsConnected ()){
173171 sndIntensityCharacteristic.writeValue (science_kit.getDistance ()*100.0 );
174172 }
@@ -178,7 +176,7 @@ void updateSubscribedCharacteristics() {
178176 }
179177
180178 // need to be fix
181- if (sndPitchCharacteristic.subscribed ()) {
179+ if (sndPitchCharacteristic.subscribed ()){
182180 sndPitchCharacteristic.writeValue (science_kit.getExternalTemperature ());
183181 }
184182
0 commit comments