@@ -24,17 +24,17 @@ unsigned long lastNotify = 0;
2424
2525ScienceKitCarrier science_kit;
2626
27- rtos::Thread _t (osPriorityHigh);
28- rtos::Thread _tu;
29-
27+ // rtos::Thread _thread_check_connection(osPriorityHigh);
28+ rtos::Thread _thread_update_sensors;
3029
30+ bool _is_connected = false ;
3131
3232
3333void setup () {
34- pinMode (8 ,OUTPUT);
35- pinMode (7 ,OUTPUT);
34+ // pinMode(8,OUTPUT);
35+ // pinMode(7,OUTPUT);
3636
37- science_kit.begin (NO_AUXILIARY_THREADS); // Doesn't start the BME688 thread for the moment
37+ science_kit.begin (NO_AUXILIARY_THREADS); // Doesn't start the BME688 and external temperature threads for the moment
3838
3939 if (!BLE.begin ()) {
4040 while (1 );
@@ -75,13 +75,14 @@ void setup() {
7575
7676 BLE.addService (service);
7777 BLE.advertise ();
78+
7879 science_kit.startAuxiliaryThreads (); // start the BME688 and External Temperature Probe threads
79- // _t.start(loop_data);
80- _tu.start (update);
81- }
8280
83- bool _is_connected = false ;
81+ // _thread_check_connection.start(loop_data);
82+ _thread_update_sensors.start (update); // this thread updates sensors
83+ }
8484
85+ /*
8586void loop_data() {
8687 bool last_connected_status = _is_connected;
8788 while (1) {
@@ -91,18 +92,18 @@ void loop_data() {
9192 }
9293 }
9394}
95+ */
9496
9597void update (void ){
9698 while (1 ){
97- digitalWrite (8 ,HIGH);
99+ // digitalWrite(8,HIGH);
98100 science_kit.update (ROUND_ROBIN_ENABLED);
99- digitalWrite (8 ,LOW);
101+ // digitalWrite(8,LOW);
100102 rtos::ThisThread::sleep_for (20 );
101103 }
102104}
103105
104- void loop () {
105-
106+ void loop (){
106107 BLEDevice central = BLE.central ();
107108 if (central) {
108109 _is_connected = true ;
@@ -113,7 +114,8 @@ void loop() {
113114 lastNotify=millis ();
114115 }
115116 }
116- } else {
117+ }
118+ else {
117119 delay (100 );
118120 _is_connected = false ;
119121 }
@@ -182,7 +184,12 @@ void updateSubscribedCharacteristics() {
182184 }
183185
184186 if (sndIntensityCharacteristic.subscribed ()) {
185- sndIntensityCharacteristic.writeValue (science_kit.getFrequency1 ());
187+ if (science_kit.getUltrasonicIsConnected ()){
188+ sndIntensityCharacteristic.writeValue (science_kit.getDistance ()*100.0 );
189+ }
190+ else {
191+ sndIntensityCharacteristic.writeValue (-1.0 );
192+ }
186193 }
187194
188195 if (sndPitchCharacteristic.subscribed ()) {
0 commit comments