Skip to content

Commit 6da419f

Browse files
committed
adding quaternion service
1 parent 6e80d7d commit 6da419f

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

libraries/BLEAdafruitService/library.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ category=Communication
88
url=https://github.com/adafruit/Adafruit_nRF52_Arduino
99
architectures=*
1010
includes=BLEAdafruitService.h
11+
depends=Adafruit NeoPixel, Adafruit Unified Sensor, Adafruit AHRS

libraries/BLEAdafruitService/src/BLEAdafruitService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "services/BLEAdafruitHumid.h"
3939
#include "services/BLEAdafruitLightSensor.h"
4040
#include "services/BLEAdafruitMagnetic.h"
41+
#include "services/BLEAdafruitQuaternion.h"
4142
#include "services/BLEAdafruitTemperature.h"
4243
#include "services/BLEAdafruitTone.h"
4344

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
#include <Adafruit_AHRS.h>
27+
28+
//--------------------------------------------------------------------+
29+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
30+
//--------------------------------------------------------------------+
31+
32+
33+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
34+
* ADAFxxx-C332-42A8-93BD-25E905756CB8
35+
*
36+
* Shared Characteristics
37+
* - Measurement Period 0001 | int32_t | Read + Write |
38+
* ms between measurements, -1: stop reading, 0: update when changes
39+
*
40+
* Quaternion service 0D00
41+
* - Quater 0D01 | float[4] | Read + Notify | qw, qx, qy, qz
42+
* - Measurement Period 0001
43+
*/
44+
45+
const uint8_t BLEAdafruitQuaternion::UUID128_SERVICE[16] =
46+
{
47+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
48+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0D, 0xAF, 0xAD
49+
};
50+
51+
const uint8_t BLEAdafruitQuaternion::UUID128_CHR_DATA[16] =
52+
{
53+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
54+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0D, 0xAF, 0xAD
55+
};
56+
57+
// Constructor
58+
BLEAdafruitQuaternion::BLEAdafruitQuaternion(void)
59+
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
60+
{
61+
_accel = _gyro = _mag = NULL;
62+
_filter = NULL;
63+
}
64+
65+
err_t BLEAdafruitQuaternion::begin(Adafruit_AHRS_FusionInterface* filter, Adafruit_Sensor* accel, Adafruit_Sensor* gyro, Adafruit_Sensor* mag)
66+
{
67+
_filter = filter;
68+
_accel = accel;
69+
_gyro = gyro;
70+
_mag = mag;
71+
72+
// Setup Measurement Characteristic
73+
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
74+
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
75+
_measurement.setFixedLen(4*4);
76+
77+
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
78+
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
79+
80+
return ERROR_NONE;
81+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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_QUATERNION_H_
26+
#define BLEADAFRUIT_QUATERNION_H_
27+
28+
#include <Adafruit_Sensor.h>
29+
30+
class Adafruit_AHRS_FusionInterface;
31+
32+
class BLEAdafruitQuaternion : public BLEAdafruitSensor
33+
{
34+
public:
35+
static const uint8_t UUID128_SERVICE[16];
36+
static const uint8_t UUID128_CHR_DATA[16];
37+
static const int32_t DEFAULT_PERIOD = 100;
38+
39+
BLEAdafruitQuaternion(void);
40+
virtual err_t begin(Adafruit_AHRS_FusionInterface* filter, Adafruit_Sensor* accel, Adafruit_Sensor* gyro, Adafruit_Sensor* mag);
41+
42+
private:
43+
Adafruit_Sensor* _accel;
44+
Adafruit_Sensor* _gyro;
45+
Adafruit_Sensor* _mag;
46+
47+
Adafruit_AHRS_FusionInterface* _filter;
48+
};
49+
50+
#endif /* BLEADAFRUIT_QUATERNION_H_ */

libraries/Bluefruit52Lib/library.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ category=Communication
88
url=https://github.com/adafruit/Adafruit_nRF52_Arduino
99
architectures=*
1010
includes=bluefruit.h
11+
depends=Adafruit nRFCrypto

0 commit comments

Comments
 (0)