Skip to content

Commit 335cde0

Browse files
committed
add button service
1 parent 5afcadb commit 335cde0

File tree

6 files changed

+258
-1
lines changed

6 files changed

+258
-1
lines changed

libraries/Bluefruit52Lib/src/bluefruit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "services/BLEAdafruitNeopixel.h"
6565
#include "services/BLEAdafruitAccel.h"
6666
#include "services/BLEAdafruitLightSensor.h"
67+
#include "services/BLEAdafruitButton.h"
6768

6869
#include "clients/BLEAncs.h"
6970
#include "clients/BLEClientUart.h"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
/* 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+
* Board Button service 0600
40+
* - Button 0601 | uint32_t | Read + Notify | e.g slide (b0), button A (b1), button B (b2)
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitButton::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x06, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitButton::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x06, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitButton::BLEAdafruitButton(void)
58+
: BLEService(UUID128_SERVICE), Button(UUID128_CHR_DATA), Period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD)
59+
{
60+
61+
}
62+
63+
err_t BLEAdafruitButton::begin (void)
64+
{
65+
// Invoke base class begin()
66+
VERIFY_STATUS( BLEService::begin() );
67+
68+
// Add Characteristic
69+
Button.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
70+
Button.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
71+
Button.setFixedLen(4);
72+
VERIFY_STATUS( Button.begin() );
73+
74+
// Add Characteristic
75+
Period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
76+
Period.setPermission(SECMODE_OPEN, SECMODE_OPEN);
77+
Period.setFixedLen(4);
78+
VERIFY_STATUS( Period.begin() );
79+
Period.write32(10);
80+
81+
return ERROR_NONE;
82+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 BLE_ADAFRUIT_BUTTON_H_
26+
#define BLE_ADAFRUIT_BUTTON_H_
27+
28+
#include "bluefruit_common.h"
29+
30+
#include "BLECharacteristic.h"
31+
#include "BLEService.h"
32+
33+
class BLEAdafruitButton : public BLEService
34+
{
35+
public:
36+
static const uint8_t UUID128_SERVICE[16];
37+
static const uint8_t UUID128_CHR_DATA[16];
38+
39+
BLECharacteristic Button;
40+
BLECharacteristic Period;
41+
42+
BLEAdafruitButton(void);
43+
virtual err_t begin(void);
44+
};
45+
46+
#endif /* BLE_ADAFRUIT_BUTTON_H_ */
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
/* 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+
* Light Sensor service 0300
40+
* - Lux 0301 | float | Read + Notify |
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitLightSensor::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x03, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitLightSensor::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x03, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitLightSensor::BLEAdafruitLightSensor(void)
58+
: BLEService(UUID128_SERVICE), Lux(UUID128_CHR_DATA), Period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD)
59+
{
60+
61+
}
62+
63+
err_t BLEAdafruitLightSensor::begin (void)
64+
{
65+
// Invoke base class begin()
66+
VERIFY_STATUS( BLEService::begin() );
67+
68+
// Add Characteristic
69+
Lux.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
70+
Lux.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
71+
Lux.setFixedLen(4);
72+
VERIFY_STATUS( Lux.begin() );
73+
74+
// Add Characteristic
75+
Period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
76+
Period.setPermission(SECMODE_OPEN, SECMODE_OPEN);
77+
Period.setFixedLen(4);
78+
VERIFY_STATUS( Period.begin() );
79+
Period.write32(10);
80+
81+
return ERROR_NONE;
82+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 BLE_ADAFRUIT_LIGHT_SENSOR_H_
26+
#define BLE_ADAFRUIT_LIGHT_SENSOR_H_
27+
28+
#include "bluefruit_common.h"
29+
30+
#include "BLECharacteristic.h"
31+
#include "BLEService.h"
32+
33+
class BLEAdafruitLightSensor : public BLEService
34+
{
35+
public:
36+
static const uint8_t UUID128_SERVICE[16];
37+
static const uint8_t UUID128_CHR_DATA[16];
38+
39+
BLECharacteristic Lux;
40+
BLECharacteristic Period;
41+
42+
BLEAdafruitLightSensor(void);
43+
virtual err_t begin(void);
44+
};
45+
46+
#endif /* BLE_ADAFRUIT_LIGHT_SENSOR_H_ */

libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ err_t BLEAdafruitTemperature::begin (void)
6767
// Add Temperature Characteristic
6868
Temperature.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
6969
Temperature.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
70-
Temperature.setFixedLen(2);
70+
Temperature.setFixedLen(4);
7171
VERIFY_STATUS( Temperature.begin() );
7272

7373
// Add Measurement Interval Characteristic

0 commit comments

Comments
 (0)