Skip to content

Commit e87d1de

Browse files
committed
adding color service
1 parent c189741 commit e87d1de

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed

libraries/BLEAdafruitService/src/BLEAdafruitService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "services/BLEAdafruitAddressablePixel.h"
3535
#include "services/BLEAdafruitBaro.h"
3636
#include "services/BLEAdafruitButton.h"
37+
#include "services/BLEAdafruitColor.h"
3738
#include "services/BLEAdafruitGyro.h"
3839
#include "services/BLEAdafruitHumid.h"
3940
#include "services/BLEAdafruitLightSensor.h"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "BLEAdafruitService.h"
26+
27+
//--------------------------------------------------------------------+
28+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
29+
//--------------------------------------------------------------------+
30+
31+
32+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
33+
* ADAFxxx-C332-42A8-93BD-25E905756CB8
34+
*
35+
* Shared Characteristics
36+
* - Measurement Period 0001 | int32_t | Read + Write |
37+
* ms between measurements, -1: stop reading, 0: update when changes
38+
*
39+
* Color service 0A00
40+
* - Color 0A01 | uint16_t[3] | Read + Notify | Red, Green, Blue each is 16-bit color
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitColor::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0A, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitColor::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0A, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitColor::BLEAdafruitColor(void)
58+
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
59+
{
60+
// Setup Measurement Characteristic
61+
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
62+
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
63+
_measurement.setFixedLen(2*3);
64+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef BLEADAFRUIT_COLOR_H_
26+
#define BLEADAFRUIT_COLOR_H_
27+
28+
class BLEAdafruitColor : public BLEAdafruitSensor
29+
{
30+
public:
31+
static const uint8_t UUID128_SERVICE[16];
32+
static const uint8_t UUID128_CHR_DATA[16];
33+
34+
BLEAdafruitColor(void);
35+
36+
using BLEAdafruitSensor::begin;
37+
};
38+
39+
#endif /* BLEADAFRUIT_COLOR_H_ */

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
8383

8484
#define NEOPIXEL_COUNT 1
8585

86-
BLEAdafruitHumid bleHumid;
8786
BLEAdafruitBaro bleBaro;
87+
BLEAdafruitColor bleColor;
88+
BLEAdafruitHumid bleHumid;
8889
BLEAdafruitQuaternion bleQuater;
8990

9091
Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel
@@ -119,6 +120,18 @@ uint16_t measure_light(uint8_t* buf, uint16_t bufsize)
119120
return 4;
120121
}
121122

123+
uint16_t measure_color(uint8_t* buf, uint16_t bufsize)
124+
{
125+
uint16_t rgb[3];
126+
uint16_t c;
127+
(void) c;
128+
129+
apds9960.getColorData(rgb+0, rgb+1, rgb+2, &c);
130+
131+
memcpy(buf, rgb, sizeof(rgb));
132+
return sizeof(rgb);
133+
}
134+
122135
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
123136
{
124137
// Button is active LOW on most board except CPlay
@@ -297,6 +310,7 @@ void setup()
297310

298311
#else
299312
bleTemp.begin(bmp280.getTemperatureSensor());
313+
bleColor.begin(measure_color, 100);
300314
bleHumid.begin(measure_humid);
301315
bleBaro.begin(bmp280.getPressureSensor());
302316

0 commit comments

Comments
 (0)