@@ -86,6 +86,7 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
86
86
BLEAdafruitBaro bleBaro;
87
87
BLEAdafruitColor bleColor;
88
88
BLEAdafruitHumid bleHumid;
89
+ BLEAdafruitProximity bleProximity;
89
90
BLEAdafruitQuaternion bleQuater;
90
91
91
92
Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel
@@ -148,6 +149,22 @@ uint16_t measure_color(uint8_t* buf, uint16_t bufsize)
148
149
return sizeof (rgb);
149
150
}
150
151
152
+ void proximity_enable_callback (uint16_t conn_hdl, bool enabled)
153
+ {
154
+ (void ) conn_hdl;
155
+ apds9960.enableProximity (enabled);
156
+ }
157
+
158
+ uint16_t measure_proximity (uint8_t * buf, uint16_t bufsize)
159
+ {
160
+ // APDS is only 8-bit, we better to map it to 16-bit value
161
+ uint8_t data8 = apds9960.readProximity ();
162
+ uint16_t data16 = (uint16_t ) map (data8, 0 , UINT8_MAX, 0 , UINT16_MAX);
163
+
164
+ memcpy (buf, &data16, 2 );
165
+ return 2 ;
166
+ }
167
+
151
168
uint16_t measure_button (uint8_t * buf, uint16_t bufsize)
152
169
{
153
170
// Button is active LOW on most board except CPlay
@@ -312,39 +329,44 @@ void setup()
312
329
blebas.write (100 );
313
330
314
331
// ------------- Adafruit Service -------------//
332
+ bleAccel.begin (accel_sensor, 100 ); // TODO dropped in favor to Quaternion service for CLUE & Sense
333
+
315
334
bleButton.begin (measure_button, 100 );
316
335
bleButton.setPeriod (0 ); // only notify if there is changes with buttons
317
336
318
- #if defined(PIN_BUZZER)
319
- bleTone.begin (PIN_BUZZER);
320
- #endif
321
-
322
337
strip.begin ();
323
338
blePixel.begin (&strip);
324
339
325
- bleAccel.begin (accel_sensor); // TODO dropped in favor to Quaternion service for CLUE & Sense
326
340
bleSound.begin (1 , measure_sound, 100 );
327
341
328
342
// CPB doesn't support these on-board sensor
329
343
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
330
- bleTemp.begin (measure_temperature, 100 );
331
344
bleLight.begin (measure_light, 100 );
345
+ bleTemp.begin (measure_temperature, 100 );
332
346
333
347
#else
334
- bleTemp.begin (bmp280.getTemperatureSensor (), 100 );
335
-
336
- bleLight.begin (measure_light, 100 );;
337
- bleLight.setNotifyCallback (light_enable_callback);
348
+ bleBaro.begin (bmp280.getPressureSensor (), 100 );
338
349
339
350
bleColor.begin (measure_color, 100 );
340
351
bleColor.setNotifyCallback (color_enable_callback);
341
352
342
- bleHumid.begin (measure_humid);
343
- bleBaro.begin (bmp280.getPressureSensor ());
353
+ bleHumid.begin (measure_humid, 100 );
354
+
355
+ bleLight.begin (measure_light, 100 );;
356
+ bleLight.setNotifyCallback (light_enable_callback);
357
+
358
+ bleProximity.begin (measure_proximity, 100 );
359
+ bleProximity.setNotifyCallback (proximity_enable_callback);
344
360
345
361
// Quaternion with sensor calibration
346
362
bleQuater.begin (&filter, accel_sensor, lsm6ds33.getGyroSensor (), &lis3mdl);
347
363
bleQuater.setCalibration (&cal);
364
+
365
+ bleTemp.begin (bmp280.getTemperatureSensor (), 100 );
366
+ #endif
367
+
368
+ #if defined(PIN_BUZZER)
369
+ bleTone.begin (PIN_BUZZER);
348
370
#endif
349
371
350
372
// Set up and start advertising
0 commit comments