@@ -64,6 +64,10 @@ Adafruit_APDS9960 apds9960; // Proximity, Light, Gesture, Color
64
64
Adafruit_BMP280 bmp280; // Temperature, Barometric
65
65
Adafruit_SHT31 sht30; // Humid
66
66
67
+ #else
68
+
69
+ #error "Board is not supported"
70
+
67
71
#endif
68
72
69
73
Adafruit_Sensor* accel_sensor;
@@ -94,11 +98,11 @@ void setupSensors(void)
94
98
95
99
#else
96
100
97
- #ifdef ARDUINO_NRF52840_CLUE
101
+ #ifdef ARDUINO_NRF52840_CLUE
98
102
// White LEDs for color sensing
99
103
pinMode (PIN_LED2, OUTPUT);
100
104
digitalWrite (PIN_LED2, LOW);
101
- #endif
105
+ #endif
102
106
103
107
apds9960.begin ();
104
108
apds9960.enableColor (true );
@@ -134,10 +138,8 @@ void setupSensors(void)
134
138
135
139
void setupBLEScience (void )
136
140
{
137
- // Service
138
141
service.begin ();
139
142
140
- // Version
141
143
versionCharacteristic.setProperties (CHR_PROPS_READ);
142
144
versionCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
143
145
versionCharacteristic.setFixedLen (4 );
@@ -149,6 +151,7 @@ void setupBLEScience(void)
149
151
accelerationCharacteristic.setFixedLen (3 * sizeof (float ));
150
152
accelerationCharacteristic.begin ();
151
153
154
+ #if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
152
155
gyroscopeCharacteristic.setProperties (CHR_PROPS_NOTIFY);
153
156
gyroscopeCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
154
157
gyroscopeCharacteristic.setFixedLen (3 * sizeof (float ));
@@ -159,11 +162,6 @@ void setupBLEScience(void)
159
162
magneticFieldCharacteristic.setFixedLen (3 * sizeof (float ));
160
163
magneticFieldCharacteristic.begin ();
161
164
162
- temperatureCharacteristic.setProperties (CHR_PROPS_NOTIFY);
163
- temperatureCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
164
- temperatureCharacteristic.setFixedLen (sizeof (float ));
165
- temperatureCharacteristic.begin ();
166
-
167
165
pressureCharacteristic.setProperties (CHR_PROPS_NOTIFY);
168
166
pressureCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
169
167
pressureCharacteristic.setFixedLen (sizeof (float ));
@@ -178,6 +176,12 @@ void setupBLEScience(void)
178
176
proximityCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
179
177
proximityCharacteristic.setFixedLen (sizeof (unsigned int ));
180
178
proximityCharacteristic.begin ();
179
+ #endif
180
+
181
+ temperatureCharacteristic.setProperties (CHR_PROPS_NOTIFY);
182
+ temperatureCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
183
+ temperatureCharacteristic.setFixedLen (sizeof (float ));
184
+ temperatureCharacteristic.begin ();
181
185
182
186
colorCharacteristic.setProperties (CHR_PROPS_NOTIFY);
183
187
colorCharacteristic.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
@@ -262,6 +266,21 @@ void updateSubscribedCharacteristics(void)
262
266
accelerationCharacteristic.notify (event.data , accelerationCharacteristic.getMaxLen ());
263
267
}
264
268
269
+ #ifdef ARDUINO_NRF52840_CIRCUITPLAY
270
+ if ( temperatureCharacteristic.notifyEnabled () )
271
+ {
272
+ float temperature = CircuitPlayground.temperature ();
273
+ temperatureCharacteristic.notify32 (temperature);
274
+ }
275
+
276
+ if ( colorCharacteristic.notifyEnabled () )
277
+ {
278
+ int color[4 ] = { 0 };
279
+ color[3 ] = CircuitPlayground.lightSensor ();
280
+ colorCharacteristic.notify (color, colorCharacteristic.getMaxLen ());
281
+ }
282
+
283
+ #elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
265
284
if ( gyroscopeCharacteristic.notifyEnabled () )
266
285
{
267
286
lsm6ds33.getGyroSensor ()->getEvent (&event);
@@ -280,12 +299,6 @@ void updateSubscribedCharacteristics(void)
280
299
magneticFieldCharacteristic.notify (event.data , magneticFieldCharacteristic.getMaxLen ());
281
300
}
282
301
283
- if ( soundPressureCharacteristic.notifyEnabled () )
284
- {
285
- uint16_t sound = getSoundAverage ();
286
- soundPressureCharacteristic.notify16 (sound);
287
- }
288
-
289
302
if ( proximityCharacteristic.notifyEnabled () )
290
303
{
291
304
uint32_t proximity = 255 - apds9960.readProximity ();
@@ -327,6 +340,13 @@ void updateSubscribedCharacteristics(void)
327
340
apds9960.getColorData ((uint16_t *) &color[0 ], (uint16_t *) &color[1 ], (uint16_t *) &color[2 ], (uint16_t *) &color[3 ]);
328
341
colorCharacteristic.notify (color, colorCharacteristic.getMaxLen ());
329
342
}
343
+ #endif
344
+
345
+ if ( soundPressureCharacteristic.notifyEnabled () )
346
+ {
347
+ uint16_t sound = getSoundAverage ();
348
+ soundPressureCharacteristic.notify16 (sound);
349
+ }
330
350
}
331
351
332
352
// callback invoked when central connects
0 commit comments