Skip to content

Commit a5cf039

Browse files
committed
get science journal work with cpb
1 parent fa16e48 commit a5cf039

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/arduino_science_journal/arduino_science_journal.ino

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ Adafruit_APDS9960 apds9960; // Proximity, Light, Gesture, Color
6464
Adafruit_BMP280 bmp280; // Temperature, Barometric
6565
Adafruit_SHT31 sht30; // Humid
6666

67+
#else
68+
69+
#error "Board is not supported"
70+
6771
#endif
6872

6973
Adafruit_Sensor* accel_sensor;
@@ -94,11 +98,11 @@ void setupSensors(void)
9498

9599
#else
96100

97-
#ifdef ARDUINO_NRF52840_CLUE
101+
#ifdef ARDUINO_NRF52840_CLUE
98102
// White LEDs for color sensing
99103
pinMode(PIN_LED2, OUTPUT);
100104
digitalWrite(PIN_LED2, LOW);
101-
#endif
105+
#endif
102106

103107
apds9960.begin();
104108
apds9960.enableColor(true);
@@ -134,10 +138,8 @@ void setupSensors(void)
134138

135139
void setupBLEScience(void)
136140
{
137-
// Service
138141
service.begin();
139142

140-
// Version
141143
versionCharacteristic.setProperties(CHR_PROPS_READ);
142144
versionCharacteristic.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
143145
versionCharacteristic.setFixedLen(4);
@@ -149,6 +151,7 @@ void setupBLEScience(void)
149151
accelerationCharacteristic.setFixedLen(3 * sizeof(float));
150152
accelerationCharacteristic.begin();
151153

154+
#if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
152155
gyroscopeCharacteristic.setProperties(CHR_PROPS_NOTIFY);
153156
gyroscopeCharacteristic.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
154157
gyroscopeCharacteristic.setFixedLen(3 * sizeof(float));
@@ -159,11 +162,6 @@ void setupBLEScience(void)
159162
magneticFieldCharacteristic.setFixedLen(3 * sizeof(float));
160163
magneticFieldCharacteristic.begin();
161164

162-
temperatureCharacteristic.setProperties(CHR_PROPS_NOTIFY);
163-
temperatureCharacteristic.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
164-
temperatureCharacteristic.setFixedLen(sizeof(float));
165-
temperatureCharacteristic.begin();
166-
167165
pressureCharacteristic.setProperties(CHR_PROPS_NOTIFY);
168166
pressureCharacteristic.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
169167
pressureCharacteristic.setFixedLen(sizeof(float));
@@ -178,6 +176,12 @@ void setupBLEScience(void)
178176
proximityCharacteristic.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
179177
proximityCharacteristic.setFixedLen(sizeof(unsigned int));
180178
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();
181185

182186
colorCharacteristic.setProperties(CHR_PROPS_NOTIFY);
183187
colorCharacteristic.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
@@ -262,6 +266,21 @@ void updateSubscribedCharacteristics(void)
262266
accelerationCharacteristic.notify(event.data, accelerationCharacteristic.getMaxLen());
263267
}
264268

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)
265284
if ( gyroscopeCharacteristic.notifyEnabled() )
266285
{
267286
lsm6ds33.getGyroSensor()->getEvent(&event);
@@ -280,12 +299,6 @@ void updateSubscribedCharacteristics(void)
280299
magneticFieldCharacteristic.notify(event.data, magneticFieldCharacteristic.getMaxLen());
281300
}
282301

283-
if ( soundPressureCharacteristic.notifyEnabled() )
284-
{
285-
uint16_t sound = getSoundAverage();
286-
soundPressureCharacteristic.notify16(sound);
287-
}
288-
289302
if ( proximityCharacteristic.notifyEnabled() )
290303
{
291304
uint32_t proximity = 255 - apds9960.readProximity();
@@ -327,6 +340,13 @@ void updateSubscribedCharacteristics(void)
327340
apds9960.getColorData((uint16_t*) &color[0], (uint16_t*) &color[1], (uint16_t*) &color[2], (uint16_t*) &color[3]);
328341
colorCharacteristic.notify(color, colorCharacteristic.getMaxLen());
329342
}
343+
#endif
344+
345+
if ( soundPressureCharacteristic.notifyEnabled() )
346+
{
347+
uint16_t sound = getSoundAverage();
348+
soundPressureCharacteristic.notify16(sound);
349+
}
330350
}
331351

332352
// callback invoked when central connects

0 commit comments

Comments
 (0)