@@ -47,25 +47,56 @@ void setup(){
47
47
48
48
BLE.setLocalName (name.c_str ());
49
49
BLE.setDeviceName (name.c_str ());
50
- BLE.setAdvertisedService (service);
51
50
51
+
52
+ BLE.setAdvertisedService (service);
53
+ /* ________________________________________________________________VERSION */
52
54
service.addCharacteristic (versionCharacteristic);
55
+ /* ________________________________________________________________CURRENT */
53
56
service.addCharacteristic (currentCharacteristic);
57
+ /* ________________________________________________________________VOLTAGE */
54
58
service.addCharacteristic (voltageCharacteristic);
59
+ /* ______________________________________________________________RESISTANCE */
55
60
service.addCharacteristic (resistanceCharacteristic);
61
+ /* _________________________________________________________________LIGHT */
56
62
service.addCharacteristic (lightCharacteristic);
63
+ /* _______________________________________________________________PROXIMITY */
57
64
service.addCharacteristic (proximityCharacteristic);
65
+ /* ____________________________________________________________ACCELERATION */
58
66
service.addCharacteristic (accelerationCharacteristic);
67
+ /* _______________________________________________________________GYROSCOPE */
59
68
service.addCharacteristic (gyroscopeCharacteristic);
69
+ /* ____________________________________________________________MAGNETOMETER */
60
70
service.addCharacteristic (magnetometerCharacteristic);
71
+ /* _____________________________________________________________TEMPERATURE */
61
72
service.addCharacteristic (temperatureCharacteristic);
73
+ /* ________________________________________________________________PRESSURE */
62
74
service.addCharacteristic (pressureCharacteristic);
75
+ /* ________________________________________________________________HUMIDITY */
63
76
service.addCharacteristic (humidityCharacteristic);
77
+ /* _____________________________________________________________AIR_QUALITY */
78
+ service.addCharacteristic (airQualityCharacteristic);
79
+ /* _________________________________________________________SOUND_INTENSITY */
64
80
service.addCharacteristic (sndIntensityCharacteristic);
81
+ /* ______!!! NOT AVAILABLE (should be delete?) !!!______________SOUND_PITCH */
65
82
service.addCharacteristic (sndPitchCharacteristic);
83
+ /* _________________________________________________________________INPUT_A */
66
84
service.addCharacteristic (inputACharacteristic);
85
+ /* _________________________________________________________________INPUT_B */
67
86
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
+
68
98
99
+ /* ________________________________________________________________VERSION */
69
100
versionCharacteristic.setValue (VERSION);
70
101
71
102
BLE.addService (service);
@@ -103,18 +134,25 @@ void loop(){
103
134
}
104
135
105
136
void updateSubscribedCharacteristics (){
137
+ /* ________________________________________________________________CURRENT */
106
138
if (currentCharacteristic.subscribed ()){
107
139
currentCharacteristic.writeValue (science_kit.getCurrent ());
108
140
}
109
141
142
+
143
+ /* ________________________________________________________________VOLTAGE */
110
144
if (voltageCharacteristic.subscribed ()){
111
145
voltageCharacteristic.writeValue (science_kit.getVoltage ());
112
146
}
113
-
147
+
148
+
149
+ /* ______________________________________________________________RESISTANCE */
114
150
if (resistanceCharacteristic.subscribed ()){
115
151
resistanceCharacteristic.writeValue (science_kit.getResistance ());
116
152
}
117
-
153
+
154
+
155
+ /* _________________________________________________________________LIGHT */
118
156
if (lightCharacteristic.subscribed ()){
119
157
long light[4 ];
120
158
light[0 ] = science_kit.getRed ();
@@ -124,18 +162,25 @@ void updateSubscribedCharacteristics(){
124
162
lightCharacteristic.writeValue ((byte*)light, sizeof (light));
125
163
}
126
164
165
+
166
+ /* _______________________________________________________________PROXIMITY */
127
167
if (proximityCharacteristic.subscribed ()){ // need to be fixed
128
- /*
168
+
129
169
proximityCharacteristic.writeValue (science_kit.getProximity ());
130
- */
170
+
171
+
172
+ /*
131
173
if (science_kit.getUltrasonicIsConnected()){
132
174
proximityCharacteristic.writeValue(science_kit.getDistance()*100.0);
133
175
}
134
176
else{
135
177
proximityCharacteristic.writeValue(-1.0);
136
178
}
179
+ */
137
180
}
138
-
181
+
182
+
183
+ /* ____________________________________________________________ACCELERATION */
139
184
if (accelerationCharacteristic.subscribed ()){
140
185
float acceleration[3 ];
141
186
acceleration[0 ] = science_kit.getAccelerationX ();
@@ -144,6 +189,7 @@ void updateSubscribedCharacteristics(){
144
189
accelerationCharacteristic.writeValue ((byte*)acceleration, sizeof (acceleration));
145
190
}
146
191
192
+ /* _______________________________________________________________GYROSCOPE */
147
193
if (gyroscopeCharacteristic.subscribed ()){
148
194
float gyroscope[3 ];
149
195
gyroscope[0 ] = science_kit.getAngularVelocityX ();
@@ -152,6 +198,7 @@ void updateSubscribedCharacteristics(){
152
198
gyroscopeCharacteristic.writeValue ((byte*)gyroscope, sizeof (gyroscope));
153
199
}
154
200
201
+ /* ____________________________________________________________MAGNETOMETER */
155
202
if (magnetometerCharacteristic.subscribed ()){
156
203
float magnetometer[3 ];
157
204
magnetometer[0 ] = science_kit.getMagneticFieldX ();
@@ -160,38 +207,105 @@ void updateSubscribedCharacteristics(){
160
207
magnetometerCharacteristic.writeValue ((byte*)magnetometer, sizeof (magnetometer));
161
208
}
162
209
210
+ /*
211
+ * BME688
212
+ */
213
+
214
+ /* _____________________________________________________________TEMPERATURE */
163
215
if (temperatureCharacteristic.subscribed ()){
164
216
temperatureCharacteristic.writeValue (science_kit.getTemperature ());
165
217
}
166
218
219
+ /* ________________________________________________________________PRESSURE */
167
220
if (pressureCharacteristic.subscribed ()){
168
221
pressureCharacteristic.writeValue (science_kit.getPressure ());
169
222
}
170
223
224
+ /* ________________________________________________________________HUMIDITY */
171
225
if (humidityCharacteristic.subscribed ()){
172
226
humidityCharacteristic.writeValue (science_kit.getHumidity ());
173
227
}
228
+
229
+ /* _____________________________________________________________AIR_QUALITY */
230
+ if (airQualityCharacteristic.subscribed ()){
231
+ airQualityCharacteristic.writeValue (science_kit.getAirQuality ());
232
+ }
174
233
175
- // need to be fixed
234
+ /*
235
+ * MICROPHONE
236
+ */
237
+
238
+ /* _________________________________________________________SOUND_INTENSITY */
239
+ /* NOTE: raw value - value not in Db */
176
240
if (sndIntensityCharacteristic.subscribed ()){
177
241
sndIntensityCharacteristic.writeValue (science_kit.getMicrophoneRMS ());
178
242
}
179
243
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) */
181
246
if (sndPitchCharacteristic.subscribed ()){
182
247
sndPitchCharacteristic.writeValue (science_kit.getExternalTemperature ());
183
248
}
184
249
250
+ /* _________________________________________________________________INPUT_A */
185
251
if (inputACharacteristic.subscribed ()){
186
- /*
187
252
inputACharacteristic.writeValue (science_kit.getInputA ());
253
+
254
+ /* NOTE_ OLD CODE USED FOR DEBUG
255
+ inputACharacteristic.writeValue(science_kit.getFrequency1());
188
256
*/
189
- inputACharacteristic.writeValue (science_kit.getFrequency1 ());
190
257
}
191
258
259
+ /* _________________________________________________________________INPUT_B */
192
260
if (inputBCharacteristic.subscribed ()){
193
261
inputBCharacteristic.writeValue (science_kit.getInputB ());
194
262
}
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
+ }
195
309
}
196
310
197
311
0 commit comments