@@ -107,25 +107,47 @@ Adafruit_FlashTransport_QSPI flashTransport;
107
107
Adafruit_SPIFlash flash (&flashTransport);
108
108
FatFileSystem fatfs;
109
109
110
+ void light_enable_callback (uint16_t conn_hdl, bool enabled)
111
+ {
112
+ (void ) conn_hdl;
113
+ apds9960.enableColor (enabled);
114
+ }
115
+
110
116
uint16_t measure_light (uint8_t * buf, uint16_t bufsize)
111
117
{
112
118
float lux;
113
-
114
119
uint16_t r, g, b, c;
120
+
115
121
apds9960.getColorData (&r, &g, &b, &c);
116
122
117
123
lux = c;
118
-
119
124
memcpy (buf, &lux, 4 );
120
125
return 4 ;
121
126
}
122
127
128
+ void color_enable_callback (uint16_t conn_hdl, bool enabled)
129
+ {
130
+ (void ) conn_hdl;
131
+
132
+ apds9960.enableColor (enabled);
133
+
134
+ #ifdef ARDUINO_NRF52840_CLUE
135
+ digitalWrite (PIN_LED2, enabled);
136
+
137
+ #else
138
+ // Feather Sense use neopixel
139
+
140
+
141
+ #endif
142
+ }
143
+
123
144
uint16_t measure_color (uint8_t * buf, uint16_t bufsize)
124
145
{
125
146
uint16_t rgb[3 ];
126
147
uint16_t c;
127
148
(void ) c;
128
149
150
+ apds9960.enableColor (true );
129
151
apds9960.getColorData (rgb+0 , rgb+1 , rgb+2 , &c);
130
152
131
153
memcpy (buf, rgb, sizeof (rgb));
@@ -155,10 +177,11 @@ uint16_t measure_humid(uint8_t* buf, uint16_t bufsize)
155
177
156
178
#else
157
179
#error "Board is not supported"
158
- #endif
180
+
181
+ #endif // end of board
159
182
160
183
// --------------------------------------------------------------------+
161
- // Common Services
184
+ // Common for all Boards
162
185
// --------------------------------------------------------------------+
163
186
164
187
// BLE Service
@@ -198,7 +221,9 @@ uint16_t measure_sound(uint8_t* buf, uint16_t bufsize)
198
221
}
199
222
200
223
201
- // ------------- Setup -------------//
224
+ // --------------------------------------------------------------------+
225
+ // Codes
226
+ // --------------------------------------------------------------------+
202
227
void setup ()
203
228
{
204
229
Adafruit_Sensor* accel_sensor;
@@ -218,9 +243,13 @@ void setup()
218
243
pinMode (PIN_BUTTON2, INPUT_PULLUP);
219
244
#endif
220
245
221
- apds9960.begin ();
222
- apds9960.enableColor (true );
246
+ #ifdef ARDUINO_NRF52840_CLUE
247
+ // White LEDs for color sensing
248
+ pinMode (PIN_LED2, OUTPUT);
249
+ digitalWrite (PIN_LED2, LOW);
250
+ #endif
223
251
252
+ apds9960.begin ();
224
253
bmp280.begin ();
225
254
sht30.begin (0x44 );
226
255
lsm6ds33.begin_I2C ();
@@ -289,8 +318,6 @@ void setup()
289
318
blebas.write (100 );
290
319
291
320
// ------------- Adafruit Service -------------//
292
- bleLight.begin (measure_light);
293
-
294
321
bleButton.begin (measure_button, 100 );
295
322
bleButton.setPeriod (0 ); // only notify if there is changes with buttons
296
323
@@ -306,11 +333,18 @@ void setup()
306
333
307
334
// CPB doesn't support these on-board sensor
308
335
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
309
- bleTemp.begin (measure_temperature);
336
+ bleTemp.begin (measure_temperature, 100 );
337
+ bleLight.begin (measure_light, 100 );
310
338
311
339
#else
312
- bleTemp.begin (bmp280.getTemperatureSensor ());
340
+ bleTemp.begin (bmp280.getTemperatureSensor (), 100 );
341
+
342
+ bleLight.begin (measure_light, 100 );;
343
+ bleLight.setNotifyCallback (light_enable_callback);
344
+
313
345
bleColor.begin (measure_color, 100 );
346
+ bleColor.setNotifyCallback (color_enable_callback);
347
+
314
348
bleHumid.begin (measure_humid);
315
349
bleBaro.begin (bmp280.getPressureSensor ());
316
350
0 commit comments