@@ -86,6 +86,7 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
8686BLEAdafruitBaro bleBaro;
8787BLEAdafruitColor bleColor;
8888BLEAdafruitHumid bleHumid;
89+ BLEAdafruitProximity bleProximity;
8990BLEAdafruitQuaternion bleQuater;
9091
9192Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel
@@ -148,6 +149,22 @@ uint16_t measure_color(uint8_t* buf, uint16_t bufsize)
148149 return sizeof (rgb);
149150}
150151
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+
151168uint16_t measure_button (uint8_t * buf, uint16_t bufsize)
152169{
153170 // Button is active LOW on most board except CPlay
@@ -312,39 +329,44 @@ void setup()
312329 blebas.write (100 );
313330
314331 // ------------- Adafruit Service -------------//
332+ bleAccel.begin (accel_sensor, 100 ); // TODO dropped in favor to Quaternion service for CLUE & Sense
333+
315334 bleButton.begin (measure_button, 100 );
316335 bleButton.setPeriod (0 ); // only notify if there is changes with buttons
317336
318- #if defined(PIN_BUZZER)
319- bleTone.begin (PIN_BUZZER);
320- #endif
321-
322337 strip.begin ();
323338 blePixel.begin (&strip);
324339
325- bleAccel.begin (accel_sensor); // TODO dropped in favor to Quaternion service for CLUE & Sense
326340 bleSound.begin (1 , measure_sound, 100 );
327341
328342 // CPB doesn't support these on-board sensor
329343#ifdef ARDUINO_NRF52840_CIRCUITPLAY
330- bleTemp.begin (measure_temperature, 100 );
331344 bleLight.begin (measure_light, 100 );
345+ bleTemp.begin (measure_temperature, 100 );
332346
333347#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 );
338349
339350 bleColor.begin (measure_color, 100 );
340351 bleColor.setNotifyCallback (color_enable_callback);
341352
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);
344360
345361 // Quaternion with sensor calibration
346362 bleQuater.begin (&filter, accel_sensor, lsm6ds33.getGyroSensor (), &lis3mdl);
347363 bleQuater.setCalibration (&cal);
364+
365+ bleTemp.begin (bmp280.getTemperatureSensor (), 100 );
366+ #endif
367+
368+ #if defined(PIN_BUZZER)
369+ bleTone.begin (PIN_BUZZER);
348370#endif
349371
350372 // Set up and start advertising
0 commit comments