@@ -96,7 +96,7 @@ void setupSensors(void)
9696 CircuitPlayground.begin ();
9797 accel_sensor = &CircuitPlayground.lis ;
9898
99- #else
99+ #elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
100100
101101 #ifdef ARDUINO_NRF52840_CLUE
102102 // White LEDs for color sensing
@@ -105,9 +105,6 @@ void setupSensors(void)
105105 #endif
106106
107107 apds9960.begin ();
108- apds9960.enableColor (true );
109- apds9960.enableProximity (true );
110-
111108 bmp280.begin ();
112109 sht30.begin (0x44 );
113110 lsm6ds33.begin_I2C ();
@@ -175,6 +172,7 @@ void setupBLEScience(void)
175172 proximityCharacteristic.setProperties (CHR_PROPS_NOTIFY);
176173 proximityCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
177174 proximityCharacteristic.setFixedLen (sizeof (unsigned int ));
175+ proximityCharacteristic.setCccdWriteCallback (science_notify_callback);
178176 proximityCharacteristic.begin ();
179177#endif
180178
@@ -186,6 +184,7 @@ void setupBLEScience(void)
186184 colorCharacteristic.setProperties (CHR_PROPS_NOTIFY);
187185 colorCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
188186 colorCharacteristic.setFixedLen (4 * sizeof (int ));
187+ colorCharacteristic.setCccdWriteCallback (science_notify_callback);
189188 colorCharacteristic.begin ();
190189
191190 soundPressureCharacteristic.setProperties (CHR_PROPS_NOTIFY);
@@ -326,16 +325,12 @@ void updateSubscribedCharacteristics(void)
326325
327326 if ( pressureCharacteristic.notifyEnabled () )
328327 {
329- float pressure = bmp280.readPressure ();
328+ float pressure = bmp280.readPressure () / 1000.0 ; // kilo pascal
330329 pressureCharacteristic.notify32 (pressure);
331330 }
332331
333332 if ( colorCharacteristic.notifyEnabled () )
334333 {
335- #ifdef ARDUINO_NRF52840_CLUE
336- digitalWrite (PIN_LED2, enabled);
337- #endif
338-
339334 int color[4 ] = { 0 };
340335 apds9960.getColorData ((uint16_t *) &color[0 ], (uint16_t *) &color[1 ], (uint16_t *) &color[2 ], (uint16_t *) &color[3 ]);
341336 colorCharacteristic.notify (color, colorCharacteristic.getMaxLen ());
@@ -349,6 +344,30 @@ void updateSubscribedCharacteristics(void)
349344 }
350345}
351346
347+ void science_notify_callback (uint16_t conn_hdl, BLECharacteristic* chr, uint16_t value)
348+ {
349+ (void ) conn_hdl;
350+
351+ bool enabled = (value == 0x0001 );
352+ (void ) enabled;
353+
354+ #if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
355+ if ( chr == &colorCharacteristic )
356+ {
357+ apds9960.enableColor (enabled);
358+
359+ #ifdef ARDUINO_NRF52840_CLUE
360+ digitalWrite (PIN_LED2, enabled);
361+ #endif
362+ }
363+
364+ if ( chr == &proximityCharacteristic)
365+ {
366+ apds9960.enableProximity (enabled);
367+ }
368+ #endif
369+ }
370+
352371// callback invoked when central connects
353372void connect_callback (uint16_t conn_handle)
354373{
0 commit comments