diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index 8d086f98..8842fc61 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -34,6 +34,7 @@ #include "services/BLEAdafruitAddressablePixel.h" #include "services/BLEAdafruitBaro.h" #include "services/BLEAdafruitButton.h" +#include "services/BLEAdafruitColor.h" #include "services/BLEAdafruitGyro.h" #include "services/BLEAdafruitHumid.h" #include "services/BLEAdafruitLightSensor.h" diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.cpp new file mode 100644 index 00000000..fec3399b --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.cpp @@ -0,0 +1,64 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "BLEAdafruitService.h" + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + + +/* All Adafruit Service/Characteristic UUID128 share the same Base UUID: + * ADAFxxx-C332-42A8-93BD-25E905756CB8 + * + * Shared Characteristics + * - Measurement Period 0001 | int32_t | Read + Write | + * ms between measurements, -1: stop reading, 0: update when changes + * + * Color service 0A00 + * - Color 0A01 | uint16_t[3] | Read + Notify | Red, Green, Blue each is 16-bit color + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitColor::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0A, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitColor::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0A, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitColor::BLEAdafruitColor(void) + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) +{ + // Setup Measurement Characteristic + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _measurement.setFixedLen(2*3); +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.h new file mode 100644 index 00000000..3c4b6013 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.h @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef BLEADAFRUIT_COLOR_H_ +#define BLEADAFRUIT_COLOR_H_ + +class BLEAdafruitColor : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + + BLEAdafruitColor(void); + + using BLEAdafruitSensor::begin; +}; + +#endif /* BLEADAFRUIT_COLOR_H_ */ diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 70425b98..59c7ec3b 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -83,8 +83,9 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) #define NEOPIXEL_COUNT 1 -BLEAdafruitHumid bleHumid; BLEAdafruitBaro bleBaro; +BLEAdafruitColor bleColor; +BLEAdafruitHumid bleHumid; BLEAdafruitQuaternion bleQuater; Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel @@ -119,6 +120,18 @@ uint16_t measure_light(uint8_t* buf, uint16_t bufsize) return 4; } +uint16_t measure_color(uint8_t* buf, uint16_t bufsize) +{ + uint16_t rgb[3]; + uint16_t c; + (void) c; + + apds9960.getColorData(rgb+0, rgb+1, rgb+2, &c); + + memcpy(buf, rgb, sizeof(rgb)); + return sizeof(rgb); +} + uint16_t measure_button(uint8_t* buf, uint16_t bufsize) { // Button is active LOW on most board except CPlay @@ -297,6 +310,7 @@ void setup() #else bleTemp.begin(bmp280.getTemperatureSensor()); + bleColor.begin(measure_color, 100); bleHumid.begin(measure_humid); bleBaro.begin(bmp280.getPressureSensor());