Skip to content

Commit d541810

Browse files
committed
add humid service
1 parent 7d7cb85 commit d541810

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
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/BLEAdafruitButton.h"
3636
#include "services/BLEAdafruitGyro.h"
37+
#include "services/BLEAdafruitHumid.h"
3738
#include "services/BLEAdafruitLightSensor.h"
3839
#include "services/BLEAdafruitMagnetic.h"
3940
#include "services/BLEAdafruitTemperature.h"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
* Humidity service 0700
40+
* - Humid 0701 | float[3] | Read + Notify | x, y, z
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitHumid::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x07, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitHumid::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x07, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitHumid::BLEAdafruitHumid(void)
58+
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
59+
{
60+
61+
}
62+
63+
err_t BLEAdafruitHumid::begin (void)
64+
{
65+
// Setup Measurement Characteristic
66+
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
67+
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
68+
_measurement.setFixedLen(4);
69+
70+
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
71+
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
72+
73+
return ERROR_NONE;
74+
}
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_HUMID_H_
26+
#define BLEADAFRUIT_HUMID_H_
27+
28+
class BLEAdafruitHumid : public BLEAdafruitSensor
29+
{
30+
public:
31+
static const uint8_t UUID128_SERVICE[16];
32+
static const uint8_t UUID128_CHR_DATA[16];
33+
static const int32_t DEFAULT_PERIOD = 1000;
34+
35+
BLEAdafruitHumid(void);
36+
virtual err_t begin(void);
37+
};
38+
39+
#endif /* BLEADAFRUIT_HUMID_H_ */

0 commit comments

Comments
 (0)