Skip to content

Commit 5afcadb

Browse files
committed
update adafruit services
1 parent f0ca568 commit 5afcadb

File tree

9 files changed

+78
-61
lines changed

9 files changed

+78
-61
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/cplay_bluefruit/cplay_bluefruit.ino

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@ BLEUart bleuart; // uart over ble
2323
BLEBas blebas; // battery
2424

2525
/* All Adafruit Service/Characteristic UUID128 share the same
26-
* Base UUID : ADAF0000-C332-42A8-93BD-25E905756CB8
26+
* Base UUID : ADAFxxx-C332-42A8-93BD-25E905756CB8
27+
*
28+
* Share Characteristics
29+
* - Measurement Period 0001 | int32_t | Read + Write | ms between measurements, -1: stop reading, 0: update when changes
2730
*
2831
* Temperature service 0100
2932
* - Temperature 0101 | float | Read + Notify | degree in Celsius
30-
* - Measurement Period 0001 | uint32_t | Read + Write
33+
* - Measurement Period 0001
3134
*
3235
* Accelerometer service 0200
3336
* - Accel Data 0201 | float (x, y, z) | Read + Notify | accel x, y, z
34-
* - Measurement Period 0001 | uint32_t | Read + Write
37+
* - Measurement Period 0001
3538
*
3639
* Light sensor service 0300
37-
* - Light Data 0301 | uint16_t | Read + Notify
38-
* - Measurement Period 0001 | uint32_t | Read + Write
40+
* - Lux Data 0301 | uint16_t | Read + Notify
41+
* - Measurement Period 0001
3942
*
4043
* Sound sensor service 0400
4144
* - Sound Data 0401 | int16_t | Read + Notify
42-
* - Measurement Period 0001 | uint32_t | Read + Write
45+
* - Measurement Period 0001
4346
*
4447
* Captouch service 0500
4548
* - Sensitivity 0501 | uint32_t | difference that Capn should report immediately
@@ -55,7 +58,7 @@ BLEBas blebas; // battery
5558
* PIN I/O service 0700
5659
* - Pin Dir 0701 | uint64_t | Read + Write | bit 1 is In, 0 is Out
5760
* - Pin Data 0702 | uint64_t | Read + Write |
58-
* - PWM Control 0710 | struct { uint8_t pin, uint16_t value, uint32_t period_ms} | as microbit value is 0-1024 for duty cycle
61+
* - PWM Control 0710 | struct { uint8_t pin, uint16_t value, uint32_t period_ms} | as microbit, value is 0-1024 for duty cycle
5962
*
6063
* PIN Analog 0800
6164
* - A0 0810 | uint16_t | Read + Notify
@@ -68,6 +71,17 @@ BLEBas blebas; // battery
6871
* - Pixel Count 0902 | uint16_t | Read + Write
6972
* - Pixel Type 0903 | uint16_t | Read + Write | NEO_RGB, NEO_GRB etc ..
7073
* - Pixel Data 0904 | RGB array| Write
74+
*
75+
* Gamepad Service 0A00
76+
* - Gamepad Button 0A01 | uint16_t | Write
77+
* - Left XY 0A02 | int8_t[2] | Write
78+
* - Right XY 0A03 | int8_t[2] | Write
79+
*
80+
* Image Service 0B00
81+
* - Format 0B01 | uint16_t[3] | Write | width + height + type, type is enum value e.g RGB_655, RGB_888, JPG, GIF etc ...
82+
* - Data 0B02 | pixel[] | Write | will save to flash as `default_image`, and auto load on reset ?
83+
* - Fill 0B03 | uint8_t[3] | Write | Fill with solid color
84+
* - Load File 0B04 | utf8_t | Write | Load image from qspi flash ?
7185
*/
7286

7387
/* Adafruit NeoPixel Service

libraries/Bluefruit52Lib/src/BLEUuid.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@
3636

3737
#include "BLEUuid.h"
3838

39-
//void reverse_uuid128(uint8_t const in[16], uint8_t out[16])
40-
//{
41-
// for(uint8_t i=0; i<16; i++)
42-
// {
43-
// out[i] = in[15-i];
44-
// }
45-
//}
39+
const uint8_t UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD[16] =
40+
{
41+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
42+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x00, 0xAF, 0xAD
43+
};
4644

4745
void BLEUuid::set(uint16_t uuid16)
4846
{

libraries/Bluefruit52Lib/src/BLEUuid.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class BLEUuid
7272
BLEUuid& operator=(ble_uuid_t uuid);
7373
};
7474

75+
//--------------------------------------------------------------------+
76+
// Custom UUID Service
77+
//--------------------------------------------------------------------+
78+
extern const uint8_t UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD[16];
79+
7580
/*------------------------------------------------------------------*/
7681
/* Service UUID
7782
* https://www.bluetooth.com/specifications/gatt/services

libraries/Bluefruit52Lib/src/bluefruit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "services/BLEAdafruitTemperature.h"
6464
#include "services/BLEAdafruitNeopixel.h"
6565
#include "services/BLEAdafruitAccel.h"
66+
#include "services/BLEAdafruitLightSensor.h"
6667

6768
#include "clients/BLEAncs.h"
6869
#include "clients/BLEClientUart.h"

libraries/Bluefruit52Lib/src/services/BLEAdafruitAccel.cpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,33 @@
2929
//--------------------------------------------------------------------+
3030

3131

32-
/* Adafruit Accelerometer Service
33-
* using micro:bit Accelerometer Service definition
34-
* https://lancaster-university.github.io/microbit-docs/resources/bluetooth/bluetooth_profile.html
32+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
33+
* ADAFxxx-C332-42A8-93BD-25E905756CB8
3534
*
36-
* - Service: E95D-0753-251D-470A-A062-FA1922DFA9A8
37-
* - Data : E95D-CA4B-251D-470A-A062-FA1922DFA9A8
38-
* - Period : E95D-FB24-251D-470A-A062-FA1922DFA9A8
35+
* Shared Characteristics
36+
* - Measurement Period 0001 | int32_t | Read + Write |
37+
* ms between measurements, -1: stop reading, 0: update when changes
38+
*
39+
* Accelerometer service 0200
40+
* - Accel 0201 | float[3] | Read + Notify | x, y, z
41+
* - Measurement Period 0001
3942
*/
43+
4044
const uint8_t BLEAdafruitAccel::UUID128_SERVICE[16] =
4145
{
42-
0xA8, 0xA9, 0xDF, 0x22, 0x19, 0xFA, 0x62, 0xA0,
43-
0x0A, 0x47, 0x1D, 0x25, 0x53, 0x07, 0x5D, 0xE9
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x02, 0xAF, 0xAD
4448
};
4549

4650
const uint8_t BLEAdafruitAccel::UUID128_CHR_DATA[16] =
4751
{
48-
0xA8, 0xA9, 0xDF, 0x22, 0x19, 0xFA, 0x62, 0xA0,
49-
0x0A, 0x47, 0x1D, 0x25, 0x4B, 0xCA, 0x5D, 0xE9
50-
};
51-
52-
const uint8_t BLEAdafruitAccel::UUID128_CHR_PERIOD[16] =
53-
{
54-
0xA8, 0xA9, 0xDF, 0x22, 0x19, 0xFA, 0x62, 0xA0,
55-
0x0A, 0x47, 0x1D, 0x25, 0x24, 0xFB, 0x5D, 0xE9
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x02, 0xAF, 0xAD
5654
};
5755

5856
// Constructor
5957
BLEAdafruitAccel::BLEAdafruitAccel(void)
60-
: BLEService(UUID128_SERVICE), Data(UUID128_CHR_DATA), Period(UUID128_CHR_PERIOD)
58+
: BLEService(UUID128_SERVICE), Accel(UUID128_CHR_DATA), Period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD)
6159
{
6260

6361
}
@@ -68,19 +66,17 @@ err_t BLEAdafruitAccel::begin (void)
6866
VERIFY_STATUS( BLEService::begin() );
6967

7068
// Add Characteristic
71-
Data.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
72-
Data.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
73-
Data.setFixedLen(6);
74-
Data.setUserDescriptor("Data");
75-
VERIFY_STATUS( Data.begin() );
69+
Accel.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
70+
Accel.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
71+
Accel.setFixedLen(4*3);
72+
VERIFY_STATUS( Accel.begin() );
7673

7774
// Add Characteristic
7875
Period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
7976
Period.setPermission(SECMODE_OPEN, SECMODE_OPEN);
80-
Period.setFixedLen(2);
81-
Period.setUserDescriptor("Period");
77+
Period.setFixedLen(4);
8278
VERIFY_STATUS( Period.begin() );
83-
Period.write16(10);
79+
Period.write32(10);
8480

8581
return ERROR_NONE;
8682
}

libraries/Bluefruit52Lib/src/services/BLEAdafruitAccel.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ class BLEAdafruitAccel : public BLEService
3535
public:
3636
static const uint8_t UUID128_SERVICE[16];
3737
static const uint8_t UUID128_CHR_DATA[16];
38-
static const uint8_t UUID128_CHR_PERIOD[16];
3938

40-
BLECharacteristic Data;
39+
BLECharacteristic Accel;
4140
BLECharacteristic Period;
4241

4342
BLEAdafruitAccel(void);

libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ err_t BLEAdafruitNeopixel::begin (void)
7777
Count.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
7878
Count.setPermission(SECMODE_OPEN, SECMODE_OPEN);
7979
Count.setFixedLen(2);
80-
Count.setUserDescriptor("Count");
8180
VERIFY_STATUS( Count.begin() );
8281
Count.write16(0);
8382

8483
// Add Characteristic
8584
Type.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
8685
Type.setPermission(SECMODE_OPEN, SECMODE_OPEN);
8786
Type.setFixedLen(2);
88-
Type.setUserDescriptor("Type");
8987
VERIFY_STATUS( Type.begin() );
9088
Type.write16(0);
9189

@@ -95,8 +93,6 @@ err_t BLEAdafruitNeopixel::begin (void)
9593
// Change to use VLOC STACK to USER due to lack of memroy
9694
// Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH));
9795
Data.setMaxLen(20);
98-
99-
Data.setUserDescriptor("Data");
10096
VERIFY_STATUS( Data.begin() );
10197

10298
return ERROR_NONE;

libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,33 @@
2828
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
2929
//--------------------------------------------------------------------+
3030

31-
/* Adafruit Temperature Service
32-
* - Service: ADAF-0001-C332-42A8-93BD-25E905756CB8
33-
* - Temperature Celsius : 0x2A6E
34-
* - Measurement Interval : 0x2A21
31+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
32+
* ADAFxxx-C332-42A8-93BD-25E905756CB8
3533
*
36-
* https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.temperature.xml
37-
* https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.measurement_interval.xml
34+
* Shared Characteristics
35+
* - Measurement Period 0001 | int32_t | Read + Write |
36+
* ms between measurements, -1: stop reading, 0: update when changes
37+
*
38+
* Temperature service 0100
39+
* - Temperature 0101 | float | Read + Notify | degree in Celsius
40+
* - Measurement Period 0001
3841
*/
3942

4043
const uint8_t BLEAdafruitTemperature::UUID128_SERVICE[16] =
4144
{
4245
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
43-
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x00, 0xAF, 0xAD
46+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x01, 0xAF, 0xAD
47+
};
48+
49+
const uint8_t BLEAdafruitTemperature::UUID128_CHR_TEMPERATURE[16] =
50+
{
51+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
52+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x01, 0xAF, 0xAD
4453
};
4554

4655
// Constructor
4756
BLEAdafruitTemperature::BLEAdafruitTemperature(void)
48-
: BLEService(UUID128_SERVICE), Temperature(UUID16_CHR_TEMPERATURE), MeasurementInterval(UUID16_CHR_MEASUREMENT_INTERVAL)
57+
: BLEService(UUID128_SERVICE), Temperature(UUID128_CHR_TEMPERATURE), Period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD)
4958
{
5059

5160
}
@@ -59,17 +68,15 @@ err_t BLEAdafruitTemperature::begin (void)
5968
Temperature.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
6069
Temperature.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
6170
Temperature.setFixedLen(2);
62-
Temperature.setUserDescriptor("Temperature");
6371
VERIFY_STATUS( Temperature.begin() );
6472

6573
// Add Measurement Interval Characteristic
66-
MeasurementInterval.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
67-
MeasurementInterval.setPermission(SECMODE_OPEN, SECMODE_OPEN);
68-
MeasurementInterval.setFixedLen(2);
69-
MeasurementInterval.setUserDescriptor("Measurement Interval");
70-
VERIFY_STATUS( MeasurementInterval.begin() );
74+
Period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
75+
Period.setPermission(SECMODE_OPEN, SECMODE_OPEN);
76+
Period.setFixedLen(4);
77+
VERIFY_STATUS( Period.begin() );
7178

72-
MeasurementInterval.write16(30); // measure every 30 seconds
79+
Period.write32(30); // measure every 30 seconds
7380

7481
return ERROR_NONE;
7582
}

libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ class BLEAdafruitTemperature : public BLEService
3434
{
3535
public:
3636
static const uint8_t UUID128_SERVICE[16];
37+
static const uint8_t UUID128_CHR_TEMPERATURE[16];
3738

3839
BLECharacteristic Temperature;
39-
BLECharacteristic MeasurementInterval;
40+
BLECharacteristic Period;
4041

4142
BLEAdafruitTemperature();
4243
virtual err_t begin(void);

0 commit comments

Comments
 (0)