Skip to content

Commit 74c91a8

Browse files
committed
Add Gyro sensor
1 parent 8330bd9 commit 74c91a8

File tree

5 files changed

+118
-9
lines changed

5 files changed

+118
-9
lines changed

libraries/BLEAdafruitService/src/BLEAdafruitService.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
#include "bluefruit_common.h"
2929
#include "BLECharacteristic.h"
3030
#include "BLEService.h"
31-
3231
#include "services/BLEAdafruitSensor.h"
33-
#include "services/BLEAdafruitTemperature.h"
32+
3433
#include "services/BLEAdafruitAccel.h"
35-
#include "services/BLEAdafruitLightSensor.h"
34+
#include "services/BLEAdafruitAddressablePixel.h"
3635
#include "services/BLEAdafruitButton.h"
36+
#include "services/BLEAdafruitGyro.h"
37+
#include "services/BLEAdafruitLightSensor.h"
38+
#include "services/BLEAdafruitTemperature.h"
3739
#include "services/BLEAdafruitTone.h"
38-
#include "services/BLEAdafruitAddressablePixel.h"
3940

4041
#endif /* BLEADAFRUITSERVICE_H_ */

libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
*/
2424

2525
#ifndef BLEADAFRUITACCEL_H_
26-
#define BLEADAFRUITACCEL_H_
26+
#define BLEADAFRUITGYRO_H_
2727

2828
class BLEAdafruitAccel : public BLEAdafruitSensor
2929
{
3030
public:
3131
static const uint8_t UUID128_SERVICE[16];
3232
static const uint8_t UUID128_CHR_DATA[16];
3333

34-
BLECharacteristic Accel;
35-
3634
BLEAdafruitAccel(void);
3735
virtual err_t begin(void);
3836
};
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+
* Accelerometer service 0400
40+
* - Accel 0401 | float[3] | Read + Notify | x, y, z
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitGyro::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x04, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitGyro::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x04, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitGyro::BLEAdafruitGyro(void)
58+
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
59+
{
60+
61+
}
62+
63+
err_t BLEAdafruitGyro::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*3); // float[3]
69+
70+
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
71+
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
72+
73+
return ERROR_NONE;
74+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 BLEADAFRUITACCEL_H_
26+
#define BLEADAFRUITGYRO_H_
27+
28+
class BLEAdafruitGyro : public BLEAdafruitSensor
29+
{
30+
public:
31+
static const uint8_t UUID128_SERVICE[16];
32+
static const uint8_t UUID128_CHR_DATA[16];
33+
34+
BLEAdafruitGyro(void);
35+
virtual err_t begin(void);
36+
};
37+
38+
#endif /* BLEADAFRUITACCEL_H_ */

libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class BLEAdafruitLightSensor : public BLEAdafruitSensor
3131
static const uint8_t UUID128_SERVICE[16];
3232
static const uint8_t UUID128_CHR_DATA[16];
3333

34-
BLECharacteristic Lux;
35-
3634
BLEAdafruitLightSensor(void);
3735
virtual err_t begin(void);
3836
};

0 commit comments

Comments
 (0)