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
32- void setup () {
33-
31+ void setup (){
3432 science_kit.begin (NO_AUXILIARY_THREADS); // Doesn't start the BME688 and external temperature threads for the moment
3533
36- if (!BLE.begin ()) {
34+ if (!BLE.begin ()){
3735 while (1 );
3836 }
3937
@@ -75,22 +73,21 @@ void setup() {
7573
7674 science_kit.startAuxiliaryThreads (); // start the BME688 and External Temperature Probe threads
7775
78- // _thread_check_connection.start(loop_data);
79- _thread_update_sensors.start (update); // this thread updates sensors
76+ thread_update_sensors.start (update); // this thread updates sensors
8077}
8178
8279
8380void update (void ){
8481 while (1 ){
8582 science_kit.update (ROUND_ROBIN_ENABLED);
86- rtos::ThisThread::sleep_for (20 );
83+ rtos::ThisThread::sleep_for (25 );
8784 }
8885}
8986
9087void loop (){
9188 BLEDevice central = BLE.central ();
9289 if (central) {
93- _is_connected = true ;
90+ ble_is_connected = true ;
9491 lastNotify=millis ();
9592 while (central.connected ()) {
9693 if (millis ()-lastNotify>10 ){
@@ -101,24 +98,24 @@ void loop(){
10198 }
10299 else {
103100 delay (100 );
104- _is_connected = false ;
101+ ble_is_connected = false ;
105102 }
106103}
107104
108- void updateSubscribedCharacteristics () {
109- if (currentCharacteristic.subscribed ()) {
105+ void updateSubscribedCharacteristics (){
106+ if (currentCharacteristic.subscribed ()){
110107 currentCharacteristic.writeValue (science_kit.getCurrent ());
111108 }
112109
113- if (voltageCharacteristic.subscribed ()) {
110+ if (voltageCharacteristic.subscribed ()){
114111 voltageCharacteristic.writeValue (science_kit.getVoltage ());
115112 }
116113
117- if (resistanceCharacteristic.subscribed ()) {
114+ if (resistanceCharacteristic.subscribed ()){
118115 resistanceCharacteristic.writeValue (science_kit.getResistance ());
119116 }
120117
121- if (lightCharacteristic.subscribed ()) {
118+ if (lightCharacteristic.subscribed ()){
122119 long light[4 ];
123120 light[0 ] = science_kit.getRed ();
124121 light[1 ] = science_kit.getGreen ();
@@ -127,66 +124,92 @@ void updateSubscribedCharacteristics() {
127124 lightCharacteristic.writeValue ((byte*)light, sizeof (light));
128125 }
129126
130- if (proximityCharacteristic.subscribed ()) {
127+ if (proximityCharacteristic.subscribed ()){ // need to be fixed
128+ /*
131129 proximityCharacteristic.writeValue(science_kit.getProximity());
130+ */
131+ if (science_kit.getUltrasonicIsConnected ()){
132+ proximityCharacteristic.writeValue (science_kit.getDistance ()*100.0 );
133+ }
134+ else {
135+ proximityCharacteristic.writeValue (-1.0 );
136+ }
132137 }
133138
134- if (accelerationCharacteristic.subscribed ()) {
139+ if (accelerationCharacteristic.subscribed ()){
135140 float acceleration[3 ];
136141 acceleration[0 ] = science_kit.getAccelerationX ();
137142 acceleration[1 ] = science_kit.getAccelerationY ();
138143 acceleration[2 ] = science_kit.getAccelerationZ ();
139144 accelerationCharacteristic.writeValue ((byte*)acceleration, sizeof (acceleration));
140145 }
141146
142- if (gyroscopeCharacteristic.subscribed ()) {
147+ if (gyroscopeCharacteristic.subscribed ()){
143148 float gyroscope[3 ];
144149 gyroscope[0 ] = science_kit.getAngularVelocityX ();
145150 gyroscope[1 ] = science_kit.getAngularVelocityY ();
146151 gyroscope[2 ] = science_kit.getAngularVelocityZ ();
147152 gyroscopeCharacteristic.writeValue ((byte*)gyroscope, sizeof (gyroscope));
148153 }
149154
150- if (magnetometerCharacteristic.subscribed ()) {
155+ if (magnetometerCharacteristic.subscribed ()){
151156 float magnetometer[3 ];
152157 magnetometer[0 ] = science_kit.getMagneticFieldX ();
153158 magnetometer[1 ] = science_kit.getMagneticFieldY ();
154159 magnetometer[2 ] = science_kit.getMagneticFieldZ ();
155160 magnetometerCharacteristic.writeValue ((byte*)magnetometer, sizeof (magnetometer));
156161 }
157162
158- if (temperatureCharacteristic.subscribed ()) {
163+ if (temperatureCharacteristic.subscribed ()){
159164 temperatureCharacteristic.writeValue (science_kit.getTemperature ());
160165 }
161166
162- if (pressureCharacteristic.subscribed ()) {
167+ if (pressureCharacteristic.subscribed ()){
163168 pressureCharacteristic.writeValue (science_kit.getPressure ());
164169 }
165170
166- if (humidityCharacteristic.subscribed ()) {
171+ if (humidityCharacteristic.subscribed ()){
167172 humidityCharacteristic.writeValue (science_kit.getHumidity ());
168173 }
169174
170- // need to be fix
171- if (sndIntensityCharacteristic.subscribed ()) {
172- if (science_kit.getUltrasonicIsConnected ()){
173- sndIntensityCharacteristic.writeValue (science_kit.getDistance ()*100.0 );
174- }
175- else {
176- sndIntensityCharacteristic.writeValue (-1.0 );
177- }
175+ // need to be fixed
176+ if (sndIntensityCharacteristic.subscribed ()){
177+ sndIntensityCharacteristic.writeValue (science_kit.getMicrophoneRMS ());
178178 }
179179
180- // need to be fix
181- if (sndPitchCharacteristic.subscribed ()) {
180+ // need to be fixed
181+ if (sndPitchCharacteristic.subscribed ()){
182182 sndPitchCharacteristic.writeValue (science_kit.getExternalTemperature ());
183183 }
184184
185185 if (inputACharacteristic.subscribed ()){
186+ /*
186187 inputACharacteristic.writeValue(science_kit.getInputA());
188+ */
189+ inputACharacteristic.writeValue (science_kit.getFrequency1 ());
187190 }
188191
189192 if (inputBCharacteristic.subscribed ()){
190193 inputBCharacteristic.writeValue (science_kit.getInputB ());
191194 }
192- }
195+ }
196+
197+
198+
199+
200+
201+ /* **
202+ * _ _
203+ * /\ | | (_)
204+ * / \ _ __ __| |_ _ _ _ __ ___
205+ * / /\ \ | '__/ _` | | | | | '_ \ / _ \
206+ * / ____ \| | | (_| | |_| | | | | | (_) |
207+ * /_/____\_\_| _\__,_|\__,_|_|_| |_|\___/ ___ _ _____ ____
208+ * / ____| (_) | |/ (_) | | __ \|___ \
209+ * | (___ ___ _ ___ _ __ ___ ___ | ' / _| |_ | |__) | __) |
210+ * \___ \ / __| |/ _ \ '_ \ / __/ _ \ | < | | __| | _ / |__ <
211+ * ____) | (__| | __/ | | | (_| __/ | . \| | |_ | | \ \ ___) |
212+ * |_____/ \___|_|\___|_| |_|\___\___| |_|\_\_|\__| |_| \_\____/
213+ *
214+ *
215+ */
0 commit comments