23
23
String name;
24
24
unsigned long lastNotify = 0 ;
25
25
ScienceKitCarrier science_kit;
26
+
27
+ #ifdef ARDUINO_NANO_RP2040_CONNECT
26
28
rtos::Thread thread_update_sensors;
29
+ #endif
30
+
31
+ #ifdef ESP32
32
+ TaskHandle_t update_base;
33
+ #endif
27
34
28
35
bool ble_is_connected = false ;
29
36
30
37
38
+
31
39
void setup (){
32
40
science_kit.begin (NO_AUXILIARY_THREADS); // Doesn't start the BME688 and external temperature threads for the moment
33
41
@@ -76,10 +84,14 @@ void setup(){
76
84
service.addCharacteristic (humidityCharacteristic);
77
85
/* _____________________________________________________________AIR_QUALITY */
78
86
service.addCharacteristic (airQualityCharacteristic);
87
+
88
+ #ifdef ARDUINO_NANO_RP2040_CONNECT
79
89
/* _________________________________________________________SOUND_INTENSITY */
80
90
service.addCharacteristic (sndIntensityCharacteristic);
81
91
/* _____________________________________________________________SOUND_PITCH */
82
92
service.addCharacteristic (sndPitchCharacteristic);
93
+ #endif
94
+
83
95
/* _________________________________________________________________INPUT_A */
84
96
service.addCharacteristic (inputACharacteristic);
85
97
/* _________________________________________________________________INPUT_B */
@@ -101,24 +113,39 @@ void setup(){
101
113
102
114
BLE.addService (service);
103
115
BLE.advertise ();
104
-
116
+
105
117
science_kit.startAuxiliaryThreads (); // start the BME688 and External Temperature Probe threads
106
118
107
- thread_update_sensors.start (update); // this thread updates sensors
119
+ #ifdef ARDUINO_NANO_RP2040_CONNECT
120
+ thread_update_sensors.start (update); // this thread updates sensors
121
+ #endif
122
+ #ifdef ESP32
123
+ xTaskCreatePinnedToCore (&freeRTOSUpdate, " update_base" , 10000 , NULL , 1 , &update_base, 1 ); // starts the update sensors thread on core 1 (user)
124
+ #endif
108
125
}
109
126
110
127
111
128
void update (void ){
112
129
while (1 ){
113
130
science_kit.update (ROUND_ROBIN_ENABLED);
114
- rtos::ThisThread::sleep_for (25 );
131
+ delay (25 );
115
132
}
116
133
}
117
134
135
+ #ifdef ESP32
136
+ static void freeRTOSUpdate (void * pvParameters){
137
+ update ();
138
+ }
139
+ #endif
140
+
141
+
118
142
void loop (){
119
143
BLEDevice central = BLE.central ();
120
144
if (central) {
121
145
ble_is_connected = true ;
146
+ #ifdef ESP32
147
+ science_kit.setStatusLed (STATUS_LED_BLE);
148
+ #endif
122
149
lastNotify=millis ();
123
150
while (central.connected ()) {
124
151
if (millis ()-lastNotify>10 ){
@@ -130,6 +157,9 @@ void loop(){
130
157
else {
131
158
delay (100 );
132
159
ble_is_connected = false ;
160
+ #ifdef ESP32
161
+ science_kit.setStatusLed (STATUS_LED_PAIRING);
162
+ #endif
133
163
}
134
164
}
135
165
@@ -199,7 +229,6 @@ void updateSubscribedCharacteristics(){
199
229
/*
200
230
* BME688
201
231
*/
202
-
203
232
/* _____________________________________________________________TEMPERATURE */
204
233
if (temperatureCharacteristic.subscribed ()){
205
234
temperatureCharacteristic.writeValue (science_kit.getTemperature ());
@@ -219,10 +248,11 @@ void updateSubscribedCharacteristics(){
219
248
if (airQualityCharacteristic.subscribed ()){
220
249
airQualityCharacteristic.writeValue (science_kit.getAirQuality ());
221
250
}
222
-
251
+
223
252
/*
224
253
* MICROPHONE
225
254
*/
255
+ #ifdef ARDUINO_NANO_RP2040_CONNECT
226
256
227
257
/* _________________________________________________________SOUND_INTENSITY */
228
258
/* NOTE: raw value - value not in Db */
@@ -232,8 +262,9 @@ void updateSubscribedCharacteristics(){
232
262
233
263
/* _____________________________________________________________SOUND_PITCH */
234
264
if (sndPitchCharacteristic.subscribed ()){
235
- sndPitchCharacteristic.writeValue (science_kit. getExternalTemperature () );
265
+ sndPitchCharacteristic.writeValue (0.0 );
236
266
}
267
+ #endif
237
268
238
269
/* _________________________________________________________________INPUT_A */
239
270
if (inputACharacteristic.subscribed ()){
@@ -269,26 +300,16 @@ void updateSubscribedCharacteristics(){
269
300
270
301
/* ________________________________________________________________DISTANCE */
271
302
if (distanceCharacteristic.subscribed ()){
272
- if (science_kit.getUltrasonicIsConnected ()){
273
- /* NOTE: getDistance() calls getMeters()
274
- Requested value is in meters */
275
- distanceCharacteristic.writeValue (science_kit.getDistance ());
276
- }
277
- else {
278
- distanceCharacteristic.writeValue (-1.0 );
279
- }
303
+ /* NOTE: getDistance() calls getMeters() */
304
+ /* Requested value is in meters */
305
+ distanceCharacteristic.writeValue (science_kit.getDistance ());
280
306
}
281
307
282
308
/* ____________________________________________________________________PING */
283
309
if (pingCharacteristic.subscribed ()){
284
- if (science_kit.getUltrasonicIsConnected ()){
285
- /* NOTE: getTravelTime() returns micro seconds */
286
- /* Converted to milliseconds (agreed with RF 20230719) */
287
- pingCharacteristic.writeValue (science_kit.getTravelTime () * 1000.0 );
288
- }
289
- else {
290
- pingCharacteristic.writeValue (-1.0 );
291
- }
310
+ /* NOTE: getTravelTime() returns micro seconds */
311
+ /* Converted to milliseconds (agreed with RF 20230719) */
312
+ pingCharacteristic.writeValue (science_kit.getTravelTime () * 1000.0 );
292
313
}
293
314
}
294
315
0 commit comments