@@ -96,7 +96,7 @@ void setupSensors(void)
96
96
CircuitPlayground.begin ();
97
97
accel_sensor = &CircuitPlayground.lis ;
98
98
99
- #else
99
+ #elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
100
100
101
101
#ifdef ARDUINO_NRF52840_CLUE
102
102
// White LEDs for color sensing
@@ -105,9 +105,6 @@ void setupSensors(void)
105
105
#endif
106
106
107
107
apds9960.begin ();
108
- apds9960.enableColor (true );
109
- apds9960.enableProximity (true );
110
-
111
108
bmp280.begin ();
112
109
sht30.begin (0x44 );
113
110
lsm6ds33.begin_I2C ();
@@ -175,6 +172,7 @@ void setupBLEScience(void)
175
172
proximityCharacteristic.setProperties (CHR_PROPS_NOTIFY);
176
173
proximityCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
177
174
proximityCharacteristic.setFixedLen (sizeof (unsigned int ));
175
+ proximityCharacteristic.setCccdWriteCallback (science_notify_callback);
178
176
proximityCharacteristic.begin ();
179
177
#endif
180
178
@@ -186,6 +184,7 @@ void setupBLEScience(void)
186
184
colorCharacteristic.setProperties (CHR_PROPS_NOTIFY);
187
185
colorCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
188
186
colorCharacteristic.setFixedLen (4 * sizeof (int ));
187
+ colorCharacteristic.setCccdWriteCallback (science_notify_callback);
189
188
colorCharacteristic.begin ();
190
189
191
190
soundPressureCharacteristic.setProperties (CHR_PROPS_NOTIFY);
@@ -326,16 +325,12 @@ void updateSubscribedCharacteristics(void)
326
325
327
326
if ( pressureCharacteristic.notifyEnabled () )
328
327
{
329
- float pressure = bmp280.readPressure ();
328
+ float pressure = bmp280.readPressure () / 1000.0 ; // kilo pascal
330
329
pressureCharacteristic.notify32 (pressure);
331
330
}
332
331
333
332
if ( colorCharacteristic.notifyEnabled () )
334
333
{
335
- #ifdef ARDUINO_NRF52840_CLUE
336
- digitalWrite (PIN_LED2, enabled);
337
- #endif
338
-
339
334
int color[4 ] = { 0 };
340
335
apds9960.getColorData ((uint16_t *) &color[0 ], (uint16_t *) &color[1 ], (uint16_t *) &color[2 ], (uint16_t *) &color[3 ]);
341
336
colorCharacteristic.notify (color, colorCharacteristic.getMaxLen ());
@@ -349,6 +344,30 @@ void updateSubscribedCharacteristics(void)
349
344
}
350
345
}
351
346
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
+
352
371
// callback invoked when central connects
353
372
void connect_callback (uint16_t conn_handle)
354
373
{
0 commit comments