Skip to content

Commit ca8af3f

Browse files
committed
mod: unique sketch for SJ app
1 parent 9aaf36f commit ca8af3f

7 files changed

+59
-555
lines changed

examples/ScienceJournal/ScienceJournal.ino

+43-22
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@
2323
String name;
2424
unsigned long lastNotify = 0;
2525
ScienceKitCarrier science_kit;
26+
27+
#ifdef ARDUINO_NANO_RP2040_CONNECT
2628
rtos::Thread thread_update_sensors;
29+
#endif
30+
31+
#ifdef ESP32
32+
TaskHandle_t update_base;
33+
#endif
2734

2835
bool ble_is_connected = false;
2936

3037

38+
3139
void setup(){
3240
science_kit.begin(NO_AUXILIARY_THREADS); // Doesn't start the BME688 and external temperature threads for the moment
3341

@@ -76,10 +84,14 @@ void setup(){
7684
service.addCharacteristic(humidityCharacteristic);
7785
/* _____________________________________________________________AIR_QUALITY */
7886
service.addCharacteristic(airQualityCharacteristic);
87+
88+
#ifdef ARDUINO_NANO_RP2040_CONNECT
7989
/* _________________________________________________________SOUND_INTENSITY */
8090
service.addCharacteristic(sndIntensityCharacteristic);
8191
/* _____________________________________________________________SOUND_PITCH */
8292
service.addCharacteristic(sndPitchCharacteristic);
93+
#endif
94+
8395
/* _________________________________________________________________INPUT_A */
8496
service.addCharacteristic(inputACharacteristic);
8597
/* _________________________________________________________________INPUT_B */
@@ -101,24 +113,39 @@ void setup(){
101113

102114
BLE.addService(service);
103115
BLE.advertise();
104-
116+
105117
science_kit.startAuxiliaryThreads(); // start the BME688 and External Temperature Probe threads
106118

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
108125
}
109126

110127

111128
void update(void){
112129
while(1){
113130
science_kit.update(ROUND_ROBIN_ENABLED);
114-
rtos::ThisThread::sleep_for(25);
131+
delay(25);
115132
}
116133
}
117134

135+
#ifdef ESP32
136+
static void freeRTOSUpdate(void * pvParameters){
137+
update();
138+
}
139+
#endif
140+
141+
118142
void loop(){
119143
BLEDevice central = BLE.central();
120144
if (central) {
121145
ble_is_connected = true;
146+
#ifdef ESP32
147+
science_kit.setStatusLed(STATUS_LED_BLE);
148+
#endif
122149
lastNotify=millis();
123150
while (central.connected()) {
124151
if (millis()-lastNotify>10){
@@ -130,6 +157,9 @@ void loop(){
130157
else {
131158
delay(100);
132159
ble_is_connected = false;
160+
#ifdef ESP32
161+
science_kit.setStatusLed(STATUS_LED_PAIRING);
162+
#endif
133163
}
134164
}
135165

@@ -199,7 +229,6 @@ void updateSubscribedCharacteristics(){
199229
/*
200230
* BME688
201231
*/
202-
203232
/* _____________________________________________________________TEMPERATURE */
204233
if(temperatureCharacteristic.subscribed()){
205234
temperatureCharacteristic.writeValue(science_kit.getTemperature());
@@ -219,10 +248,11 @@ void updateSubscribedCharacteristics(){
219248
if(airQualityCharacteristic.subscribed()){
220249
airQualityCharacteristic.writeValue(science_kit.getAirQuality());
221250
}
222-
251+
223252
/*
224253
* MICROPHONE
225254
*/
255+
#ifdef ARDUINO_NANO_RP2040_CONNECT
226256

227257
/* _________________________________________________________SOUND_INTENSITY */
228258
/* NOTE: raw value - value not in Db */
@@ -232,8 +262,9 @@ void updateSubscribedCharacteristics(){
232262

233263
/* _____________________________________________________________SOUND_PITCH */
234264
if(sndPitchCharacteristic.subscribed()){
235-
sndPitchCharacteristic.writeValue(science_kit.getExternalTemperature());
265+
sndPitchCharacteristic.writeValue(0.0);
236266
}
267+
#endif
237268

238269
/* _________________________________________________________________INPUT_A */
239270
if (inputACharacteristic.subscribed()){
@@ -269,26 +300,16 @@ void updateSubscribedCharacteristics(){
269300

270301
/* ________________________________________________________________DISTANCE */
271302
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());
280306
}
281307

282308
/* ____________________________________________________________________PING */
283309
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 );
292313
}
293314
}
294315

examples/ScienceJournal/ble_config.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ const int VERSION = 0x00000002;
3838
#define BLE_CH_TEMPERA "1009"
3939
#define BLE_CH_PRESSUR "1010"
4040
#define BLE_CH_HUMIDIT "1011"
41+
42+
#ifdef ARDUINO_NANO_RP2040_CONNECT
4143
#define BLE_CH_SOUNDIN "1012"
4244
#define BLE_CH_SOUNDPI "1013"
45+
#endif
46+
4347
#define BLE_CH_FUNGEN1 "1014"
4448
#define BLE_CH_DISTANC "1015"
4549
#define BLE_CH_INPUT_A "1016"
@@ -103,11 +107,12 @@ BLEFloatCharacteristic airQualityCharacteristic (SCIENCE_KIT_UUID(BLE_
103107
/*
104108
* MICROPHONE
105109
*/
106-
110+
#ifdef ARDUINO_NANO_RP2040_CONNECT
107111
/* ___________________________________________________________SOUND_INTENSITY */
108112
BLEUnsignedIntCharacteristic sndIntensityCharacteristic (SCIENCE_KIT_UUID(BLE_CH_SOUNDIN), BLENotify); // *** !
109113
/* ______!!! NOT AVAILABLE (should be delete?) !!!________________SOUND_PITCH */
110114
BLEUnsignedIntCharacteristic sndPitchCharacteristic (SCIENCE_KIT_UUID(BLE_CH_SOUNDPI), BLENotify);
115+
#endif
111116

112117
/*
113118
* INPUT A,B

0 commit comments

Comments
 (0)