11/*
2- This file is part of the Arduino_GroveI2C_Ultrasonic library.
2+ This file is part of the Arduino_ScienceKitCarrier library.
33 Copyright (c) 2023 Arduino SA. All rights reserved.
44
55 This library is free software; you can redistribute it and/or
@@ -24,17 +24,14 @@ unsigned long lastNotify = 0;
2424
2525ScienceKitCarrier science_kit;
2626
27- rtos::Thread _t (osPriorityHigh);
28- rtos::Thread _tu;
29-
27+ rtos::Thread _thread_update_sensors;
3028
29+ bool _is_connected = false ;
3130
3231
3332void setup () {
34- pinMode (8 ,OUTPUT);
35- pinMode (7 ,OUTPUT);
3633
37- science_kit.begin (NO_AUXILIARY_THREADS); // Doesn't start the BME688 thread for the moment
34+ science_kit.begin (NO_AUXILIARY_THREADS); // Doesn't start the BME688 and external temperature threads for the moment
3835
3936 if (!BLE.begin ()) {
4037 while (1 );
@@ -75,34 +72,22 @@ void setup() {
7572
7673 BLE.addService (service);
7774 BLE.advertise ();
78- science_kit.startAuxiliaryThreads (); // start the BME688 thread
79- _t.start (loop_data);
80- _tu.start (update);
81- }
8275
83- bool _is_connected = false ;
76+ science_kit. startAuxiliaryThreads (); // start the BME688 and External Temperature Probe threads
8477
85- void loop_data () {
86- bool last_connected_status = _is_connected;
87- while (1 ) {
88- delay (1000 );
89- if (last_connected_status != _is_connected) {
90- digitalWrite (7 , _is_connected ? HIGH : LOW);
91- }
92- }
78+ // _thread_check_connection.start(loop_data);
79+ _thread_update_sensors.start (update); // this thread updates sensors
9380}
9481
82+
9583void update (void ){
9684 while (1 ){
97- digitalWrite (8 ,HIGH);
9885 science_kit.update (ROUND_ROBIN_ENABLED);
99- digitalWrite (8 ,LOW);
10086 rtos::ThisThread::sleep_for (20 );
10187 }
10288}
10389
104- void loop () {
105-
90+ void loop (){
10691 BLEDevice central = BLE.central ();
10792 if (central) {
10893 _is_connected = true ;
@@ -112,9 +97,9 @@ void loop() {
11297 updateSubscribedCharacteristics ();
11398 lastNotify=millis ();
11499 }
115-
116100 }
117- } else {
101+ }
102+ else {
118103 delay (100 );
119104 _is_connected = false ;
120105 }
@@ -182,12 +167,19 @@ void updateSubscribedCharacteristics() {
182167 humidityCharacteristic.writeValue (science_kit.getHumidity ());
183168 }
184169
170+ // need to be fix
185171 if (sndIntensityCharacteristic.subscribed ()) {
186- sndIntensityCharacteristic.writeValue (0 );
172+ if (science_kit.getUltrasonicIsConnected ()){
173+ sndIntensityCharacteristic.writeValue (science_kit.getDistance ()*100.0 );
174+ }
175+ else {
176+ sndIntensityCharacteristic.writeValue (-1.0 );
177+ }
187178 }
188179
180+ // need to be fix
189181 if (sndPitchCharacteristic.subscribed ()) {
190- sndPitchCharacteristic.writeValue (0 );
182+ sndPitchCharacteristic.writeValue (science_kit. getExternalTemperature () );
191183 }
192184
193185 if (inputACharacteristic.subscribed ()){
0 commit comments