This commit is contained in:
hathach committed 2020-02-18 12:08:53 +07:00
1 parent 0333b2adc2
commit cfe4d099cf
1 file changed
+60 -41
@@ -33,20 +33,23 @@ BLEBas blebas; // battery
BLEAdafruitTemperature bleTemp; BLEAdafruitTemperature bleTemp;
BLEAdafruitAccel bleAccel; BLEAdafruitAccel bleAccel;
BLEAdafruitLightSensor bleLight; BLEAdafruitLightSensor bleLight;
BLEAdafruitGyro bleGyro;
BLEAdafruitMagnetic bleMagnetic;
BLEAdafruitButton bleButton; BLEAdafruitButton bleButton;
BLEAdafruitTone bleTone; BLEAdafruitTone bleTone;
BLEAdafruitAddressablePixel blePixel; BLEAdafruitAddressablePixel blePixel;
// Circuit Playground Bluefruit // Circuit Playground Bluefruit
#if defined ARDUINO_NRF52840_CIRCUITPLAY #if defined( ARDUINO_NRF52840_CIRCUITPLAY )
#include <Adafruit_CircuitPlayground.h> #include <Adafruit_CircuitPlayground.h>
#define DEVICE_NAME "CPlay" #define DEVICE_NAME "CPlay"
#define NEOPIXEL_COUNT 10 #define NEOPIXEL_COUNT 10
#elif defined ARDUINO_NRF52840_CLUE #elif defined( ARDUINO_NRF52840_CLUE ) || defined( ARDUINO_NRF52840_FEATHER_SENSE )
#include <Adafruit_APDS9960.h> #include <Adafruit_APDS9960.h>
#include <Adafruit_LSM6DS33.h> #include <Adafruit_LSM6DS33.h>
#include <Adafruit_BMP280.h> #include <Adafruit_BMP280.h>
@@ -64,28 +67,6 @@ BLEAdafruitAddressablePixel blePixel;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
{
uint32_t button = 0;
#if defined ARDUINO_NRF52840_CIRCUITPLAY
button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 );
button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 );
button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 );
#elif defined ARDUINO_NRF52840_CLUE
// Button is active LOW on most board except CPlay
// No slide switch
button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 );
button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 );
#endif
memcpy(buf, &button, 4);
return 4;
}
uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
{ {
float temp; float temp;
@@ -102,23 +83,6 @@ uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
return 4; return 4;
} }
uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
{
float lux;
#if defined ARDUINO_NRF52840_CIRCUITPLAY
lux = CircuitPlayground.lightSensor();
#else
uint16_t r, g, b, c;
apds9960.getColorData(&r, &g, &b, &c);
lux = c;
#endif
memcpy(buf, &lux, 4);
return 4;
}
uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
{ {
float* accel_buf = (float*) buf; float* accel_buf = (float*) buf;
@@ -144,6 +108,55 @@ uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
return 3*sizeof(float); // 12 return 3*sizeof(float); // 12
} }
uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
{
float lux;
#if defined ARDUINO_NRF52840_CIRCUITPLAY
lux = CircuitPlayground.lightSensor();
#else
uint16_t r, g, b, c;
apds9960.getColorData(&r, &g, &b, &c);
lux = c;
#endif
memcpy(buf, &lux, 4);
return 4;
}
uint16_t measure_gyro(uint8_t* buf, uint16_t bufsize)
{
}
uint16_t measure_magnetic(uint8_t* buf, uint16_t bufsize)
{
}
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
{
uint32_t button = 0;
#if defined ARDUINO_NRF52840_CIRCUITPLAY
button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 );
button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 );
button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 );
#elif defined ARDUINO_NRF52840_CLUE
// Button is active LOW on most board except CPlay
// No slide switch
button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 );
button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 );
#endif
memcpy(buf, &button, 4);
return 4;
}
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@@ -215,6 +228,12 @@ void setup()
bleLight.begin(); bleLight.begin();
bleLight.setMeasureCallback(measure_light_sensor); bleLight.setMeasureCallback(measure_light_sensor);
// bleGyro.begin();
// bleGyro.setMeasureCallback(measure_gyro);
//
// bleMagnetic.begin();
// bleMagnetic.setMeasureCallback(measure_magnetic);
bleButton.begin(); bleButton.begin();
bleButton.setMeasureCallback(measure_button); bleButton.setMeasureCallback(measure_button);