Skip to content

Commit bf4ac6b

Browse files
committed
adding Adafruit Neo Pixel service
1 parent 205587c commit bf4ac6b

File tree

4 files changed

+156
-6
lines changed

4 files changed

+156
-6
lines changed

libraries/Bluefruit52Lib/src/bluefruit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "services/EddyStone.h"
6262

6363
#include "services/BLEAdafruitTemperature.h"
64+
#include "services/BLEAdafruitNeopixel.h"
6465

6566
#include "clients/BLEAncs.h"
6667
#include "clients/BLEClientUart.h"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 "bluefruit.h"
26+
27+
//--------------------------------------------------------------------+
28+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
29+
//--------------------------------------------------------------------+
30+
31+
32+
//------------- IMPLEMENTATION -------------//
33+
/* Adafruit NeoPixel Service
34+
* - Service: ADAF-0002-C332-42A8-93BD-25E905756CB8
35+
* - Count : ADAF-0003-C332-42A8-93BD-25E905756CB8
36+
* - Type : ADAF-0004-C332-42A8-93BD-25E905756CB8
37+
* - Data : ADAF-0005-C332-42A8-93BD-25E905756CB8
38+
*/
39+
40+
const uint8_t BLEAdafruitNeopixel::UUID128_SERVICE[16] =
41+
{
42+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
43+
0xA8, 0x42, 0x32, 0xC3, 0x02, 0x00, 0xAF, 0xAD
44+
};
45+
46+
const uint8_t BLEAdafruitNeopixel::UUID128_CHR_COUNT[16] =
47+
{
48+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
49+
0xA8, 0x42, 0x32, 0xC3, 0x03, 0x00, 0xAF, 0xAD
50+
};
51+
52+
const uint8_t BLEAdafruitNeopixel::UUID128_CHR_TYPE[16] =
53+
{
54+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
55+
0xA8, 0x42, 0x32, 0xC3, 0x04, 0x00, 0xAF, 0xAD
56+
};
57+
58+
const uint8_t BLEAdafruitNeopixel::UUID128_CHR_DATA[16] =
59+
{
60+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
61+
0xA8, 0x42, 0x32, 0xC3, 0x05, 0x00, 0xAF, 0xAD
62+
};
63+
64+
// Constructor
65+
BLEAdafruitNeopixel::BLEAdafruitNeopixel(void)
66+
: BLEService(UUID128_SERVICE), Count(UUID128_CHR_COUNT), Type(UUID128_CHR_TYPE), Data(UUID128_CHR_DATA)
67+
{
68+
69+
}
70+
71+
err_t BLEAdafruitNeopixel::begin (void)
72+
{
73+
// Invoke base class begin()
74+
VERIFY_STATUS( BLEService::begin() );
75+
76+
// Add Characteristic
77+
Count.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
78+
Count.setPermission(SECMODE_OPEN, SECMODE_OPEN);
79+
Count.setFixedLen(2);
80+
Count.setUserDescriptor("Count");
81+
VERIFY_STATUS( Count.begin() );
82+
Count.write16(0);
83+
84+
// Add Characteristic
85+
Type.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
86+
Type.setPermission(SECMODE_OPEN, SECMODE_OPEN);
87+
Type.setFixedLen(2);
88+
Type.setUserDescriptor("Type");
89+
VERIFY_STATUS( Type.begin() );
90+
Type.write16(0);
91+
92+
// Add Characteristic
93+
Data.setProperties(CHR_PROPS_WRITE);
94+
Data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN);
95+
Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH));
96+
Data.setUserDescriptor("Data");
97+
VERIFY_STATUS( Data.begin() );
98+
99+
return ERROR_NONE;
100+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 BLEADAFRUITNEOPIXEL_H_
26+
#define BLEADAFRUITNEOPIXEL_H_
27+
28+
#include "bluefruit_common.h"
29+
30+
#include "BLECharacteristic.h"
31+
#include "BLEService.h"
32+
33+
class BLEAdafruitNeopixel : public BLEService
34+
{
35+
public:
36+
static const uint8_t UUID128_SERVICE[16];
37+
static const uint8_t UUID128_CHR_COUNT[16];
38+
static const uint8_t UUID128_CHR_TYPE[16];
39+
static const uint8_t UUID128_CHR_DATA[16];
40+
41+
BLECharacteristic Count;
42+
BLECharacteristic Type;
43+
BLECharacteristic Data;
44+
45+
BLEAdafruitNeopixel(void);
46+
virtual err_t begin(void);
47+
};
48+
49+
50+
51+
#endif /* BLEADAFRUITNEOPIXEL_H_ */

libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424

2525
#include "bluefruit.h"
2626

27-
#include "BLEAdafruitTemperature.h"
28-
2927
//--------------------------------------------------------------------+
3028
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3129
//--------------------------------------------------------------------+
3230

3331
/* Adafruit Temperature Service
34-
* - Service: 20E6-0001-C332-42A8-93BD-25E905756CB8
35-
* - Temperature Celsius : 0x2A6E
36-
* - Measurement Interval : 0x2A21
32+
* - Service: ADAF-0001-C332-42A8-93BD-25E905756CB8
33+
* - Temperature Celsius : 0x2A6E
34+
* - Measurement Interval : 0x2A21
3735
*
3836
* https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.temperature.xml
3937
* https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.measurement_interval.xml
@@ -42,7 +40,7 @@
4240
const uint8_t BLEAdafruitTemperature::UUID128_SERVICE[16] =
4341
{
4442
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
45-
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x00, 0xE6, 0x20
43+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x00, 0xAF, 0xAD
4644
};
4745

4846
// Constructor

0 commit comments

Comments
 (0)