Skip to content

Commit cfe4d09

Browse files
committed
clean up
1 parent 0333b2a commit cfe4d09

File tree

1 file changed

+55
-36
lines changed

1 file changed

+55
-36
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@ BLEBas blebas; // battery
3333
BLEAdafruitTemperature bleTemp;
3434
BLEAdafruitAccel bleAccel;
3535
BLEAdafruitLightSensor bleLight;
36+
BLEAdafruitGyro bleGyro;
37+
BLEAdafruitMagnetic bleMagnetic;
38+
3639
BLEAdafruitButton bleButton;
3740
BLEAdafruitTone bleTone;
3841

3942
BLEAdafruitAddressablePixel blePixel;
4043

4144
// Circuit Playground Bluefruit
42-
#if defined ARDUINO_NRF52840_CIRCUITPLAY
45+
#if defined( ARDUINO_NRF52840_CIRCUITPLAY )
4346
#include <Adafruit_CircuitPlayground.h>
4447

4548
#define DEVICE_NAME "CPlay"
4649
#define NEOPIXEL_COUNT 10
4750

4851

49-
#elif defined ARDUINO_NRF52840_CLUE
52+
#elif defined( ARDUINO_NRF52840_CLUE ) || defined( ARDUINO_NRF52840_FEATHER_SENSE )
5053
#include <Adafruit_APDS9960.h>
5154
#include <Adafruit_LSM6DS33.h>
5255
#include <Adafruit_BMP280.h>
@@ -64,46 +67,49 @@ BLEAdafruitAddressablePixel blePixel;
6467

6568
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
6669

67-
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
70+
uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
6871
{
69-
uint32_t button = 0;
72+
float temp;
7073

7174
#if defined ARDUINO_NRF52840_CIRCUITPLAY
72-
button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 );
73-
button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 );
74-
button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 );
75+
temp = CircuitPlayground.temperature();
7576

7677
#elif defined ARDUINO_NRF52840_CLUE
77-
// Button is active LOW on most board except CPlay
78-
79-
// No slide switch
80-
button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 );
81-
button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 );
78+
temp = bmp280.readTemperature();
8279

8380
#endif
8481

85-
memcpy(buf, &button, 4);
82+
memcpy(buf, &temp, 4);
8683
return 4;
8784
}
8885

89-
uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
90-
{
91-
float temp;
86+
uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
87+
{
88+
float* accel_buf = (float*) buf;
9289

9390
#if defined ARDUINO_NRF52840_CIRCUITPLAY
94-
temp = CircuitPlayground.temperature();
91+
accel_buf[0] = CircuitPlayground.motionX();
92+
accel_buf[1] = CircuitPlayground.motionY();
93+
accel_buf[2] = CircuitPlayground.motionZ();
9594

9695
#elif defined ARDUINO_NRF52840_CLUE
97-
temp = bmp280.readTemperature();
96+
97+
sensors_event_t accel, gyro, temp;
98+
(void) gyro; (void) temp;
99+
100+
lsm6ds33.getEvent(&accel, &gyro, &temp);
101+
102+
accel_buf[0] = accel.acceleration.x;
103+
accel_buf[1] = accel.acceleration.y;
104+
accel_buf[2] = accel.acceleration.z;
98105

99106
#endif
100107

101-
memcpy(buf, &temp, 4);
102-
return 4;
108+
return 3*sizeof(float); // 12
103109
}
104110

105111
uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
106-
{
112+
{
107113
float lux;
108114

109115
#if defined ARDUINO_NRF52840_CIRCUITPLAY
@@ -119,29 +125,36 @@ uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
119125
return 4;
120126
}
121127

122-
uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
123-
{
124-
float* accel_buf = (float*) buf;
128+
uint16_t measure_gyro(uint8_t* buf, uint16_t bufsize)
129+
{
125130

126-
#if defined ARDUINO_NRF52840_CIRCUITPLAY
127-
accel_buf[0] = CircuitPlayground.motionX();
128-
accel_buf[1] = CircuitPlayground.motionY();
129-
accel_buf[2] = CircuitPlayground.motionZ();
131+
}
130132

131-
#elif defined ARDUINO_NRF52840_CLUE
133+
uint16_t measure_magnetic(uint8_t* buf, uint16_t bufsize)
134+
{
132135

133-
sensors_event_t accel, gyro, temp;
134-
(void) gyro; (void) temp;
136+
}
135137

136-
lsm6ds33.getEvent(&accel, &gyro, &temp);
138+
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
139+
{
140+
uint32_t button = 0;
137141

138-
accel_buf[0] = accel.acceleration.x;
139-
accel_buf[1] = accel.acceleration.y;
140-
accel_buf[2] = accel.acceleration.z;
142+
#if defined ARDUINO_NRF52840_CIRCUITPLAY
143+
button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 );
144+
button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 );
145+
button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 );
146+
147+
#elif defined ARDUINO_NRF52840_CLUE
148+
// Button is active LOW on most board except CPlay
149+
150+
// No slide switch
151+
button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 );
152+
button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 );
141153

142154
#endif
143155

144-
return 3*sizeof(float); // 12
156+
memcpy(buf, &button, 4);
157+
return 4;
145158
}
146159

147160
void setup()
@@ -215,6 +228,12 @@ void setup()
215228

216229
bleLight.begin();
217230
bleLight.setMeasureCallback(measure_light_sensor);
231+
232+
// bleGyro.begin();
233+
// bleGyro.setMeasureCallback(measure_gyro);
234+
//
235+
// bleMagnetic.begin();
236+
// bleMagnetic.setMeasureCallback(measure_magnetic);
218237

219238
bleButton.begin();
220239
bleButton.setMeasureCallback(measure_button);

0 commit comments

Comments
 (0)