@@ -47,25 +47,56 @@ void setup(){
4747
4848 BLE.setLocalName (name.c_str ());
4949 BLE.setDeviceName (name.c_str ());
50- BLE.setAdvertisedService (service);
5150
51+
52+ BLE.setAdvertisedService (service);
53+ /* ________________________________________________________________VERSION */
5254 service.addCharacteristic (versionCharacteristic);
55+ /* ________________________________________________________________CURRENT */
5356 service.addCharacteristic (currentCharacteristic);
57+ /* ________________________________________________________________VOLTAGE */
5458 service.addCharacteristic (voltageCharacteristic);
59+ /* ______________________________________________________________RESISTANCE */
5560 service.addCharacteristic (resistanceCharacteristic);
61+ /* _________________________________________________________________LIGHT */
5662 service.addCharacteristic (lightCharacteristic);
63+ /* _______________________________________________________________PROXIMITY */
5764 service.addCharacteristic (proximityCharacteristic);
65+ /* ____________________________________________________________ACCELERATION */
5866 service.addCharacteristic (accelerationCharacteristic);
67+ /* _______________________________________________________________GYROSCOPE */
5968 service.addCharacteristic (gyroscopeCharacteristic);
69+ /* ____________________________________________________________MAGNETOMETER */
6070 service.addCharacteristic (magnetometerCharacteristic);
71+ /* _____________________________________________________________TEMPERATURE */
6172 service.addCharacteristic (temperatureCharacteristic);
73+ /* ________________________________________________________________PRESSURE */
6274 service.addCharacteristic (pressureCharacteristic);
75+ /* ________________________________________________________________HUMIDITY */
6376 service.addCharacteristic (humidityCharacteristic);
77+ /* _____________________________________________________________AIR_QUALITY */
78+ service.addCharacteristic (airQualityCharacteristic);
79+ /* _________________________________________________________SOUND_INTENSITY */
6480 service.addCharacteristic (sndIntensityCharacteristic);
81+ /* ______!!! NOT AVAILABLE (should be delete?) !!!______________SOUND_PITCH */
6582 service.addCharacteristic (sndPitchCharacteristic);
83+ /* _________________________________________________________________INPUT_A */
6684 service.addCharacteristic (inputACharacteristic);
85+ /* _________________________________________________________________INPUT_B */
6786 service.addCharacteristic (inputBCharacteristic);
87+ /* ____________________________________________________EXTERNAL_TEMPERATURE */
88+ service.addCharacteristic (extTempCharacteristic);
89+ /* ____________________________________________________FUNCTION_GENERATOR_1 */
90+ service.addCharacteristic (funcGenOneCharacteristic);
91+ /* ____________________________________________________FUNCTION_GENERATOR_2 */
92+ service.addCharacteristic (funcGenTwoCharacteristic);
93+ /* ________________________________________________________________DISTANCE */
94+ service.addCharacteristic (distanceCharacteristic);
95+ /* ____________________________________________________________________PING */
96+ service.addCharacteristic (pingCharacteristic);
97+
6898
99+ /* ________________________________________________________________VERSION */
69100 versionCharacteristic.setValue (VERSION);
70101
71102 BLE.addService (service);
@@ -103,18 +134,25 @@ void loop(){
103134}
104135
105136void updateSubscribedCharacteristics (){
137+ /* ________________________________________________________________CURRENT */
106138 if (currentCharacteristic.subscribed ()){
107139 currentCharacteristic.writeValue (science_kit.getCurrent ());
108140 }
109141
142+
143+ /* ________________________________________________________________VOLTAGE */
110144 if (voltageCharacteristic.subscribed ()){
111145 voltageCharacteristic.writeValue (science_kit.getVoltage ());
112146 }
113-
147+
148+
149+ /* ______________________________________________________________RESISTANCE */
114150 if (resistanceCharacteristic.subscribed ()){
115151 resistanceCharacteristic.writeValue (science_kit.getResistance ());
116152 }
117-
153+
154+
155+ /* _________________________________________________________________LIGHT */
118156 if (lightCharacteristic.subscribed ()){
119157 long light[4 ];
120158 light[0 ] = science_kit.getRed ();
@@ -124,18 +162,25 @@ void updateSubscribedCharacteristics(){
124162 lightCharacteristic.writeValue ((byte*)light, sizeof (light));
125163 }
126164
165+
166+ /* _______________________________________________________________PROXIMITY */
127167 if (proximityCharacteristic.subscribed ()){ // need to be fixed
128- /*
168+
129169 proximityCharacteristic.writeValue (science_kit.getProximity ());
130- */
170+
171+
172+ /*
131173 if (science_kit.getUltrasonicIsConnected()){
132174 proximityCharacteristic.writeValue(science_kit.getDistance()*100.0);
133175 }
134176 else{
135177 proximityCharacteristic.writeValue(-1.0);
136178 }
179+ */
137180 }
138-
181+
182+
183+ /* ____________________________________________________________ACCELERATION */
139184 if (accelerationCharacteristic.subscribed ()){
140185 float acceleration[3 ];
141186 acceleration[0 ] = science_kit.getAccelerationX ();
@@ -144,6 +189,7 @@ void updateSubscribedCharacteristics(){
144189 accelerationCharacteristic.writeValue ((byte*)acceleration, sizeof (acceleration));
145190 }
146191
192+ /* _______________________________________________________________GYROSCOPE */
147193 if (gyroscopeCharacteristic.subscribed ()){
148194 float gyroscope[3 ];
149195 gyroscope[0 ] = science_kit.getAngularVelocityX ();
@@ -152,6 +198,7 @@ void updateSubscribedCharacteristics(){
152198 gyroscopeCharacteristic.writeValue ((byte*)gyroscope, sizeof (gyroscope));
153199 }
154200
201+ /* ____________________________________________________________MAGNETOMETER */
155202 if (magnetometerCharacteristic.subscribed ()){
156203 float magnetometer[3 ];
157204 magnetometer[0 ] = science_kit.getMagneticFieldX ();
@@ -160,38 +207,105 @@ void updateSubscribedCharacteristics(){
160207 magnetometerCharacteristic.writeValue ((byte*)magnetometer, sizeof (magnetometer));
161208 }
162209
210+ /*
211+ * BME688
212+ */
213+
214+ /* _____________________________________________________________TEMPERATURE */
163215 if (temperatureCharacteristic.subscribed ()){
164216 temperatureCharacteristic.writeValue (science_kit.getTemperature ());
165217 }
166218
219+ /* ________________________________________________________________PRESSURE */
167220 if (pressureCharacteristic.subscribed ()){
168221 pressureCharacteristic.writeValue (science_kit.getPressure ());
169222 }
170223
224+ /* ________________________________________________________________HUMIDITY */
171225 if (humidityCharacteristic.subscribed ()){
172226 humidityCharacteristic.writeValue (science_kit.getHumidity ());
173227 }
228+
229+ /* _____________________________________________________________AIR_QUALITY */
230+ if (airQualityCharacteristic.subscribed ()){
231+ airQualityCharacteristic.writeValue (science_kit.getAirQuality ());
232+ }
174233
175- // need to be fixed
234+ /*
235+ * MICROPHONE
236+ */
237+
238+ /* _________________________________________________________SOUND_INTENSITY */
239+ /* NOTE: raw value - value not in Db */
176240 if (sndIntensityCharacteristic.subscribed ()){
177241 sndIntensityCharacteristic.writeValue (science_kit.getMicrophoneRMS ());
178242 }
179243
180- // need to be fixed
244+ /* ______!!! NOT AVAILABLE (should be delete?) !!!______________SOUND_PITCH */
245+ /* NOTE: pith is frequency (not available because FFT cannot be performed) */
181246 if (sndPitchCharacteristic.subscribed ()){
182247 sndPitchCharacteristic.writeValue (science_kit.getExternalTemperature ());
183248 }
184249
250+ /* _________________________________________________________________INPUT_A */
185251 if (inputACharacteristic.subscribed ()){
186- /*
187252 inputACharacteristic.writeValue (science_kit.getInputA ());
253+
254+ /* NOTE_ OLD CODE USED FOR DEBUG
255+ inputACharacteristic.writeValue(science_kit.getFrequency1());
188256 */
189- inputACharacteristic.writeValue (science_kit.getFrequency1 ());
190257 }
191258
259+ /* _________________________________________________________________INPUT_B */
192260 if (inputBCharacteristic.subscribed ()){
193261 inputBCharacteristic.writeValue (science_kit.getInputB ());
194262 }
263+
264+ /* _____________________________________________________EXTERNAL_TEMPERATURE */
265+ if (extTempCharacteristic.subscribed ()){
266+ extTempCharacteristic.writeValue (science_kit.getExternalTemperature ());
267+ }
268+
269+
270+ /* ____________________________________________________FUNCTION_GENERATOR_1 */
271+ if (funcGenOneCharacteristic.subscribed ()){
272+ long f1[2 ];
273+ f1[0 ] = (science_kit.getFrequency1 () * science_kit.getRange1 ());
274+ f1[1 ] = science_kit.getPhase1 ();
275+ funcGenOneCharacteristic.writeValue ((byte*)f1, sizeof (f1));
276+ }
277+
278+ /* ____________________________________________________FUNCTION_GENERATOR_2 */
279+ if (funcGenTwoCharacteristic.subscribed ()){
280+ long f2[2 ];
281+ f2[0 ] = (science_kit.getFrequency2 () * science_kit.getRange2 ());
282+ f2[1 ] = science_kit.getPhase2 ();
283+ funcGenTwoCharacteristic.writeValue ((byte*)f2, sizeof (f2));
284+ }
285+
286+ /* ________________________________________________________________DISTANCE */
287+ if (distanceCharacteristic.subscribed ()){
288+ if (science_kit.getUltrasonicIsConnected ()){
289+ /* NOTE: getDistance() calls getMeters()
290+ Requested value is in meters */
291+ distanceCharacteristic.writeValue (science_kit.getDistance ());
292+ }
293+ else {
294+ distanceCharacteristic.writeValue (-1.0 );
295+ }
296+ }
297+
298+ /* ____________________________________________________________________PING */
299+ if (pingCharacteristic.subscribed ()){
300+ if (science_kit.getUltrasonicIsConnected ()){
301+ /* NOTE: getTravelTime() returns micro seconds */
302+ /* Converted to milliseconds (agreed with RF 20230719) */
303+ pingCharacteristic.writeValue (science_kit.getTravelTime () * 1000.0 );
304+ }
305+ else {
306+ pingCharacteristic.writeValue (-1.0 );
307+ }
308+ }
195309}
196310
197311
0 commit comments