Skip to content

Commit 0333b2a

Browse files
committed
add Magnetic service, add default period for sensor services
1 parent 74c91a8 commit 0333b2a

13 files changed

+129
-10
lines changed

libraries/BLEAdafruitService/src/BLEAdafruitService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "services/BLEAdafruitButton.h"
3636
#include "services/BLEAdafruitGyro.h"
3737
#include "services/BLEAdafruitLightSensor.h"
38+
#include "services/BLEAdafruitMagnetic.h"
3839
#include "services/BLEAdafruitTemperature.h"
3940
#include "services/BLEAdafruitTone.h"
4041

libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ err_t BLEAdafruitAccel::begin (void)
6868
_measurement.setFixedLen(4*3);
6969

7070
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
71-
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
71+
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
7272

7373
return ERROR_NONE;
7474
}

libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
*/
2424

2525
#ifndef BLEADAFRUITACCEL_H_
26-
#define BLEADAFRUITGYRO_H_
26+
#define BLEADAFRUITACCEL_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];
33+
static const int32_t DEFAULT_PERIOD = 1000;
3334

3435
BLEAdafruitAccel(void);
3536
virtual err_t begin(void);

libraries/BLEAdafruitService/src/services/BLEAdafruitButton.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ err_t BLEAdafruitButton::begin(void)
6767
_measurement.setFixedLen(4);
6868

6969
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
70-
VERIFY_STATUS( BLEAdafruitSensor::begin(100) );
70+
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
7171

7272
return ERROR_NONE;
7373
}

libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class BLEAdafruitButton : public BLEAdafruitSensor
3030
public:
3131
static const uint8_t UUID128_SERVICE[16];
3232
static const uint8_t UUID128_CHR_DATA[16];
33+
static const int32_t DEFAULT_PERIOD = 0;
3334

3435
BLEAdafruitButton(void);
3536
virtual err_t begin(void);

libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
* - Measurement Period 0001 | int32_t | Read + Write |
3737
* ms between measurements, -1: stop reading, 0: update when changes
3838
*
39-
* Accelerometer service 0400
40-
* - Accel 0401 | float[3] | Read + Notify | x, y, z
39+
* Gyroscope service 0400
40+
* - Gyro 0401 | float[3] | Read + Notify | x, y, z
4141
* - Measurement Period 0001
4242
*/
4343

@@ -68,7 +68,7 @@ err_t BLEAdafruitGyro::begin (void)
6868
_measurement.setFixedLen(4*3); // float[3]
6969

7070
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
71-
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
71+
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
7272

7373
return ERROR_NONE;
7474
}

libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
#ifndef BLEADAFRUITACCEL_H_
25+
#ifndef BLEADAFRUITGYRO_H_
2626
#define BLEADAFRUITGYRO_H_
2727

2828
class BLEAdafruitGyro : public BLEAdafruitSensor
2929
{
3030
public:
3131
static const uint8_t UUID128_SERVICE[16];
3232
static const uint8_t UUID128_CHR_DATA[16];
33+
static const int32_t DEFAULT_PERIOD = 1000;
3334

3435
BLEAdafruitGyro(void);
3536
virtual err_t begin(void);
3637
};
3738

38-
#endif /* BLEADAFRUITACCEL_H_ */
39+
#endif /* BLEADAFRUITGYRO_H_ */

libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ err_t BLEAdafruitLightSensor::begin (void)
6868
_measurement.setFixedLen(4);
6969

7070
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
71-
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
71+
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
7272

7373
return ERROR_NONE;
7474
}

libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class BLEAdafruitLightSensor : public BLEAdafruitSensor
3030
public:
3131
static const uint8_t UUID128_SERVICE[16];
3232
static const uint8_t UUID128_CHR_DATA[16];
33+
static const int32_t DEFAULT_PERIOD = 1000;
3334

3435
BLEAdafruitLightSensor(void);
3536
virtual err_t begin(void);
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+
* Magnetic service 0500
40+
* - Magnetic 0501 | float[3] | Read + Notify | x, y, z
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitMagnetic::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x05, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitMagnetic::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x05, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitMagnetic::BLEAdafruitMagnetic(void)
58+
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
59+
{
60+
61+
}
62+
63+
err_t BLEAdafruitMagnetic::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(DEFAULT_PERIOD) );
72+
73+
return ERROR_NONE;
74+
}

0 commit comments

Comments
 (0)