add Magnetic service, add default period for sensor services
This commit is contained in:
1 parent
74c91a8215
commit
0333b2adc2
13 files changed
+129
-10
No files matched your search
@@ -35,6 +35,7 @@
|
||||
#include "services/BLEAdafruitButton.h"
|
||||
#include "services/BLEAdafruitGyro.h"
|
||||
#include "services/BLEAdafruitLightSensor.h"
|
||||
#include "services/BLEAdafruitMagnetic.h"
|
||||
#include "services/BLEAdafruitTemperature.h"
|
||||
#include "services/BLEAdafruitTone.h"
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ err_t BLEAdafruitAccel::begin (void)
|
||||
_measurement.setFixedLen(4*3);
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -23,13 +23,14 @@
|
||||
*/
|
||||
|
||||
#ifndef BLEADAFRUITACCEL_H_
|
||||
#define BLEADAFRUITGYRO_H_
|
||||
#define BLEADAFRUITACCEL_H_
|
||||
|
||||
class BLEAdafruitAccel : public BLEAdafruitSensor
|
||||
{
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
static const int32_t DEFAULT_PERIOD = 1000;
|
||||
|
||||
BLEAdafruitAccel(void);
|
||||
virtual err_t begin(void);
|
||||
|
||||
@@ -67,7 +67,7 @@ err_t BLEAdafruitButton::begin(void)
|
||||
_measurement.setFixedLen(4);
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(100) );
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -30,6 +30,7 @@ class BLEAdafruitButton : public BLEAdafruitSensor
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
static const int32_t DEFAULT_PERIOD = 0;
|
||||
|
||||
BLEAdafruitButton(void);
|
||||
virtual err_t begin(void);
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
* - Measurement Period 0001 | int32_t | Read + Write |
|
||||
* ms between measurements, -1: stop reading, 0: update when changes
|
||||
*
|
||||
* Accelerometer service 0400
|
||||
* - Accel 0401 | float[3] | Read + Notify | x, y, z
|
||||
* Gyroscope service 0400
|
||||
* - Gyro 0401 | float[3] | Read + Notify | x, y, z
|
||||
* - Measurement Period 0001
|
||||
*/
|
||||
|
||||
@@ -68,7 +68,7 @@ err_t BLEAdafruitGyro::begin (void)
|
||||
_measurement.setFixedLen(4*3); // float[3]
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BLEADAFRUITACCEL_H_
|
||||
#ifndef BLEADAFRUITGYRO_H_
|
||||
#define BLEADAFRUITGYRO_H_
|
||||
|
||||
class BLEAdafruitGyro : public BLEAdafruitSensor
|
||||
@@ -30,9 +30,10 @@ class BLEAdafruitGyro : public BLEAdafruitSensor
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
static const int32_t DEFAULT_PERIOD = 1000;
|
||||
|
||||
BLEAdafruitGyro(void);
|
||||
virtual err_t begin(void);
|
||||
};
|
||||
|
||||
#endif /* BLEADAFRUITACCEL_H_ */
|
||||
#endif /* BLEADAFRUITGYRO_H_ */
|
||||
@@ -68,7 +68,7 @@ err_t BLEAdafruitLightSensor::begin (void)
|
||||
_measurement.setFixedLen(4);
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -30,6 +30,7 @@ class BLEAdafruitLightSensor : public BLEAdafruitSensor
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
static const int32_t DEFAULT_PERIOD = 1000;
|
||||
|
||||
BLEAdafruitLightSensor(void);
|
||||
virtual err_t begin(void);
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "BLEAdafruitService.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
|
||||
* ADAFxxx-C332-42A8-93BD-25E905756CB8
|
||||
*
|
||||
* Shared Characteristics
|
||||
* - Measurement Period 0001 | int32_t | Read + Write |
|
||||
* ms between measurements, -1: stop reading, 0: update when changes
|
||||
*
|
||||
* Magnetic service 0500
|
||||
* - Magnetic 0501 | float[3] | Read + Notify | x, y, z
|
||||
* - Measurement Period 0001
|
||||
*/
|
||||
|
||||
const uint8_t BLEAdafruitMagnetic::UUID128_SERVICE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x05, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitMagnetic::UUID128_CHR_DATA[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x05, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
// Constructor
|
||||
BLEAdafruitMagnetic::BLEAdafruitMagnetic(void)
|
||||
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t BLEAdafruitMagnetic::begin (void)
|
||||
{
|
||||
// Setup Measurement Characteristic
|
||||
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
||||
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_measurement.setFixedLen(4*3); // float[3]
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BLEADAFRUITMAGNETIC_H_
|
||||
#define BLEADAFRUITMAGNETIC_H_
|
||||
|
||||
class BLEAdafruitMagnetic : public BLEAdafruitSensor
|
||||
{
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
static const int32_t DEFAULT_PERIOD = 1000;
|
||||
|
||||
BLEAdafruitMagnetic(void);
|
||||
virtual err_t begin(void);
|
||||
};
|
||||
|
||||
#endif /* BLEADAFRUITMAGNETIC_H_ */
|
||||
@@ -67,7 +67,7 @@ err_t BLEAdafruitTemperature::begin (void)
|
||||
_measurement.setFixedLen(4);
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -30,6 +30,7 @@ class BLEAdafruitTemperature : public BLEAdafruitSensor
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
static const int32_t DEFAULT_PERIOD = 1000;
|
||||
|
||||
BLEAdafruitTemperature();
|
||||
virtual err_t begin(void);
|
||||
|
||||
Reference in new issue
Block a user