@@ -107,25 +107,47 @@ Adafruit_FlashTransport_QSPI flashTransport;
107107Adafruit_SPIFlash flash (&flashTransport);
108108FatFileSystem fatfs;
109109
110+ void light_enable_callback (uint16_t conn_hdl, bool enabled)
111+ {
112+ (void ) conn_hdl;
113+ apds9960.enableColor (enabled);
114+ }
115+
110116uint16_t measure_light (uint8_t * buf, uint16_t bufsize)
111117{
112118 float lux;
113-
114119 uint16_t r, g, b, c;
120+
115121 apds9960.getColorData (&r, &g, &b, &c);
116122
117123 lux = c;
118-
119124 memcpy (buf, &lux, 4 );
120125 return 4 ;
121126}
122127
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+
123144uint16_t measure_color (uint8_t * buf, uint16_t bufsize)
124145{
125146 uint16_t rgb[3 ];
126147 uint16_t c;
127148 (void ) c;
128149
150+ apds9960.enableColor (true );
129151 apds9960.getColorData (rgb+0 , rgb+1 , rgb+2 , &c);
130152
131153 memcpy (buf, rgb, sizeof (rgb));
@@ -155,10 +177,11 @@ uint16_t measure_humid(uint8_t* buf, uint16_t bufsize)
155177
156178#else
157179 #error "Board is not supported"
158- #endif
180+
181+ #endif // end of board
159182
160183// --------------------------------------------------------------------+
161- // Common Services
184+ // Common for all Boards
162185// --------------------------------------------------------------------+
163186
164187// BLE Service
@@ -198,7 +221,9 @@ uint16_t measure_sound(uint8_t* buf, uint16_t bufsize)
198221}
199222
200223
201- // ------------- Setup -------------//
224+ // --------------------------------------------------------------------+
225+ // Codes
226+ // --------------------------------------------------------------------+
202227void setup ()
203228{
204229 Adafruit_Sensor* accel_sensor;
@@ -218,9 +243,13 @@ void setup()
218243 pinMode (PIN_BUTTON2, INPUT_PULLUP);
219244#endif
220245
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
223251
252+ apds9960.begin ();
224253 bmp280.begin ();
225254 sht30.begin (0x44 );
226255 lsm6ds33.begin_I2C ();
@@ -289,8 +318,6 @@ void setup()
289318 blebas.write (100 );
290319
291320 // ------------- Adafruit Service -------------//
292- bleLight.begin (measure_light);
293-
294321 bleButton.begin (measure_button, 100 );
295322 bleButton.setPeriod (0 ); // only notify if there is changes with buttons
296323
@@ -306,11 +333,18 @@ void setup()
306333
307334 // CPB doesn't support these on-board sensor
308335#ifdef ARDUINO_NRF52840_CIRCUITPLAY
309- bleTemp.begin (measure_temperature);
336+ bleTemp.begin (measure_temperature, 100 );
337+ bleLight.begin (measure_light, 100 );
310338
311339#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+
313345 bleColor.begin (measure_color, 100 );
346+ bleColor.setNotifyCallback (color_enable_callback);
347+
314348 bleHumid.begin (measure_humid);
315349 bleBaro.begin (bmp280.getPressureSensor ());
316350
0 commit comments