move BLEAdafruit service to its own library due to neopixel/dotstar dependency
This commit is contained in:
1 parent
583ad02a7d
commit
8b60180b45
14 files changed
+7
-1
No files matched your search
@@ -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 "bluefruit.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
|
||||
*
|
||||
* Accelerometer service 0200
|
||||
* - Accel 0201 | float[3] | Read + Notify | x, y, z
|
||||
* - Measurement Period 0001
|
||||
*/
|
||||
|
||||
const uint8_t BLEAdafruitAccel::UUID128_SERVICE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x02, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitAccel::UUID128_CHR_DATA[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x02, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
// Constructor
|
||||
BLEAdafruitAccel::BLEAdafruitAccel(void)
|
||||
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t BLEAdafruitAccel::begin (void)
|
||||
{
|
||||
// Setup Measurement Characteristic
|
||||
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
||||
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_measurement.setFixedLen(4*3);
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 BLEADAFRUITACCEL_H_
|
||||
#define BLEADAFRUITACCEL_H_
|
||||
|
||||
#include "bluefruit_common.h"
|
||||
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
#include "BLEAdafruitSensor.h"
|
||||
|
||||
class BLEAdafruitAccel : public BLEAdafruitSensor
|
||||
{
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
|
||||
BLECharacteristic Accel;
|
||||
|
||||
BLEAdafruitAccel(void);
|
||||
virtual err_t begin(void);
|
||||
};
|
||||
|
||||
#endif /* BLEADAFRUITACCEL_H_ */
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 "bluefruit.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
|
||||
*
|
||||
* Board Button service 0600
|
||||
* - Button 0601 | uint32_t | Read + Notify | e.g slide (b0), button A (b1), button B (b2)
|
||||
* - Measurement Period 0001
|
||||
*/
|
||||
|
||||
const uint8_t BLEAdafruitButton::UUID128_SERVICE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x06, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitButton::UUID128_CHR_DATA[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x06, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
// Constructor
|
||||
BLEAdafruitButton::BLEAdafruitButton(void)
|
||||
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
|
||||
{
|
||||
}
|
||||
|
||||
err_t BLEAdafruitButton::begin(void)
|
||||
{
|
||||
// Setup Measurement Characteristic
|
||||
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
||||
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_measurement.setFixedLen(4);
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(100) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 BLE_ADAFRUIT_BUTTON_H_
|
||||
#define BLE_ADAFRUIT_BUTTON_H_
|
||||
|
||||
#include "bluefruit_common.h"
|
||||
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
#include "BLEAdafruitSensor.h"
|
||||
|
||||
class BLEAdafruitButton : public BLEAdafruitSensor
|
||||
{
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
|
||||
BLEAdafruitButton(void);
|
||||
virtual err_t begin(void);
|
||||
};
|
||||
|
||||
#endif /* BLE_ADAFRUIT_BUTTON_H_ */
|
||||
@@ -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 "bluefruit.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
|
||||
*
|
||||
* Light Sensor service 0300
|
||||
* - Lux 0301 | float | Read + Notify |
|
||||
* - Measurement Period 0001
|
||||
*/
|
||||
|
||||
const uint8_t BLEAdafruitLightSensor::UUID128_SERVICE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x03, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitLightSensor::UUID128_CHR_DATA[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x03, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
// Constructor
|
||||
BLEAdafruitLightSensor::BLEAdafruitLightSensor(void)
|
||||
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t BLEAdafruitLightSensor::begin (void)
|
||||
{
|
||||
// Setup Measurement Characteristic
|
||||
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
||||
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_measurement.setFixedLen(4);
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 BLE_ADAFRUIT_LIGHT_SENSOR_H_
|
||||
#define BLE_ADAFRUIT_LIGHT_SENSOR_H_
|
||||
|
||||
#include "bluefruit_common.h"
|
||||
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
#include "BLEAdafruitSensor.h"
|
||||
|
||||
class BLEAdafruitLightSensor : public BLEAdafruitSensor
|
||||
{
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
|
||||
BLECharacteristic Lux;
|
||||
|
||||
BLEAdafruitLightSensor(void);
|
||||
virtual err_t begin(void);
|
||||
};
|
||||
|
||||
#endif /* BLE_ADAFRUIT_LIGHT_SENSOR_H_ */
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 "bluefruit.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
|
||||
* ADAFxxx-C332-42A8-93BD-25E905756CB8
|
||||
*
|
||||
* Adafruit NeoPixel Service 0900
|
||||
* - Pin 0901 | uint8_t | Read + Write |
|
||||
* - Type 0902 | uint8_t | Read + Write | 0: neopixel, 1: dotstar
|
||||
* - Data 0903 | { uint16_t start, uint8_t flags, data }
|
||||
* - Count
|
||||
*/
|
||||
|
||||
const uint8_t BLEAdafruitRgbPixel::UUID128_SERVICE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x09, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitRgbPixel::UUID128_CHR_PIN[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x09, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitRgbPixel::UUID128_CHR_TYPE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x02, 0x09, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitRgbPixel::UUID128_CHR_DATA[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x03, 0x09, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
// Constructor
|
||||
BLEAdafruitRgbPixel::BLEAdafruitRgbPixel(void)
|
||||
: BLEService(UUID128_SERVICE), Pin(UUID128_CHR_PIN), Type(UUID128_CHR_TYPE), Data(UUID128_CHR_DATA)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t BLEAdafruitRgbPixel::begin (Adafruit_NeoPixel* neo_pixel)
|
||||
{
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
// Add Characteristic
|
||||
Pin.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
|
||||
Pin.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
Pin.setFixedLen(1);
|
||||
VERIFY_STATUS( Pin.begin() );
|
||||
Pin.write8(0);
|
||||
|
||||
// Add Characteristic
|
||||
Type.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
|
||||
Type.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
Type.setFixedLen(1);
|
||||
VERIFY_STATUS( Type.begin() );
|
||||
Type.write16(0);
|
||||
|
||||
// Add Characteristic
|
||||
Data.setProperties(CHR_PROPS_WRITE);
|
||||
Data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN);
|
||||
// Change to use VLOC STACK to USER due to lack of memroy
|
||||
// Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH));
|
||||
Data.setMaxLen(20);
|
||||
VERIFY_STATUS( Data.begin() );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 BLEADAFRUITRGBPIXEL_H_
|
||||
#define BLEADAFRUITRGBPIXEL_H_
|
||||
|
||||
#include "bluefruit_common.h"
|
||||
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
class BLEAdafruitRgbPixel : public BLEService
|
||||
{
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_PIN[16];
|
||||
// static const uint8_t UUID128_CHR_COUNT[16];
|
||||
static const uint8_t UUID128_CHR_TYPE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
|
||||
// BLECharacteristic Count;
|
||||
BLECharacteristic Pin;
|
||||
BLECharacteristic Type;
|
||||
BLECharacteristic Data;
|
||||
|
||||
BLEAdafruitRgbPixel(void);
|
||||
virtual err_t begin(void);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* BLEADAFRUITRGBPIXEL_H_ */
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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 "bluefruit.h"
|
||||
#include "BLEAdafruitSensor.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
BLEAdafruitSensor::BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid)
|
||||
: BLEService(service_uuid), _measurement(data_uuid), _period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD)
|
||||
{
|
||||
_measure_cb = NULL;
|
||||
}
|
||||
|
||||
void BLEAdafruitSensor::setMeasureCallback(measure_callback_t fp)
|
||||
{
|
||||
_measure_cb = fp;
|
||||
}
|
||||
|
||||
err_t BLEAdafruitSensor::begin(int32_t ms)
|
||||
{
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
_measurement.setCccdWriteCallback(sensor_data_cccd_cb, true);
|
||||
|
||||
VERIFY_STATUS( _measurement.begin() );
|
||||
|
||||
_period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
|
||||
_period.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
_period.setFixedLen(4);
|
||||
VERIFY_STATUS( _period.begin() );
|
||||
_period.write32(ms);
|
||||
|
||||
_period.setWriteCallback(sensor_period_write_cb, true);
|
||||
|
||||
// setup timer
|
||||
_timer.begin(ms, sensor_timer_cb, this, true);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
void BLEAdafruitSensor::setPeriod(int32_t period_ms)
|
||||
{
|
||||
_period.write32(period_ms);
|
||||
_update_timer(period_ms);
|
||||
}
|
||||
|
||||
|
||||
void BLEAdafruitSensor::startMeasuring(void)
|
||||
{
|
||||
_timer.start();
|
||||
}
|
||||
|
||||
void BLEAdafruitSensor::stopMeasuring(void)
|
||||
{
|
||||
_timer.stop();
|
||||
}
|
||||
|
||||
|
||||
void BLEAdafruitSensor::_update_timer(int32_t ms)
|
||||
{
|
||||
// TODO handle period = 0 which notify on changes ASAP
|
||||
if ( ms < 0 )
|
||||
{
|
||||
_timer.stop();
|
||||
}else if ( ms > 0)
|
||||
{
|
||||
_timer.setPeriod(ms);
|
||||
}else
|
||||
{
|
||||
// Period = 0: keeping the current interval, but report on changes only
|
||||
}
|
||||
}
|
||||
|
||||
void BLEAdafruitSensor::_timer_callback(void)
|
||||
{
|
||||
if (_measure_cb)
|
||||
{
|
||||
uint8_t buf[_measurement.getMaxLen()];
|
||||
uint16_t len = _measure_cb(buf, sizeof(buf));
|
||||
len = min(len, sizeof(buf));
|
||||
|
||||
// Period = 0, compare with old data, only update on changes
|
||||
if ( 0 == _period.read32() )
|
||||
{
|
||||
uint8_t prev_buf[_measurement.getMaxLen()];
|
||||
_measurement.read(prev_buf, sizeof(prev_buf));
|
||||
|
||||
// skip notify if there is no changes
|
||||
if ( 0 == memcmp(prev_buf, buf, len) ) return;
|
||||
}
|
||||
|
||||
_measurement.notify(buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Static Callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void BLEAdafruitSensor::sensor_timer_cb(TimerHandle_t xTimer)
|
||||
{
|
||||
BLEAdafruitSensor* svc = (BLEAdafruitSensor*) pvTimerGetTimerID(xTimer);
|
||||
svc->_timer_callback();
|
||||
}
|
||||
|
||||
// Client update period, adjust timer accordingly
|
||||
void BLEAdafruitSensor::sensor_period_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
|
||||
{
|
||||
BLEAdafruitSensor& svc = (BLEAdafruitSensor&) chr->parentService();
|
||||
|
||||
int32_t ms = 0;
|
||||
memcpy(&ms, data, len);
|
||||
|
||||
svc._update_timer(ms);
|
||||
}
|
||||
|
||||
void BLEAdafruitSensor::sensor_data_cccd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint16_t value)
|
||||
{
|
||||
BLEAdafruitSensor& svc = (BLEAdafruitSensor&) chr->parentService();
|
||||
|
||||
// notify enabled
|
||||
if (value & BLE_GATT_HVX_NOTIFICATION)
|
||||
{
|
||||
svc._timer.start();
|
||||
}else
|
||||
{
|
||||
svc._timer.stop();
|
||||
}
|
||||
|
||||
// send initial notification if period = 0
|
||||
// if ( 0 == svc._period.read32() )
|
||||
// {
|
||||
// svc._measurement.notify();
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 BLE_ADAFRUIT_SENSOR_H_
|
||||
#define BLE_ADAFRUIT_SENSOR_H_
|
||||
|
||||
#include "bluefruit_common.h"
|
||||
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
class BLEAdafruitSensor : public BLEService
|
||||
{
|
||||
public:
|
||||
typedef uint16_t (*measure_callback_t )(uint8_t* buf, uint16_t bufsize);
|
||||
|
||||
BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid);
|
||||
virtual err_t begin(int32_t ms);
|
||||
|
||||
void setMeasureCallback(measure_callback_t fp);
|
||||
void setPeriod(int32_t period_ms);
|
||||
|
||||
void startMeasuring(void);
|
||||
void stopMeasuring(void);
|
||||
|
||||
protected:
|
||||
BLECharacteristic _period;
|
||||
BLECharacteristic _measurement;
|
||||
|
||||
measure_callback_t _measure_cb;
|
||||
SoftwareTimer _timer;
|
||||
|
||||
void _update_timer(int32_t ms);
|
||||
void _timer_callback(void);
|
||||
|
||||
static void sensor_timer_cb(TimerHandle_t xTimer);
|
||||
static void sensor_period_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
|
||||
static void sensor_data_cccd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint16_t value);
|
||||
};
|
||||
|
||||
#endif /* BLE_ADAFRUIT_SENSOR_H_ */
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 "bluefruit.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
|
||||
*
|
||||
* Temperature service 0100
|
||||
* - Temperature 0101 | float | Read + Notify | degree in Celsius
|
||||
* - Measurement Period 0001
|
||||
*/
|
||||
|
||||
const uint8_t BLEAdafruitTemperature::UUID128_SERVICE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x01, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitTemperature::UUID128_CHR_DATA[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x01, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
// Constructor
|
||||
BLEAdafruitTemperature::BLEAdafruitTemperature(void)
|
||||
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t BLEAdafruitTemperature::begin (void)
|
||||
{
|
||||
// Setup Measurement Characteristic
|
||||
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
||||
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_measurement.setFixedLen(4);
|
||||
|
||||
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
||||
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 BLEADAFRUITTEMPERATURE_H_
|
||||
#define BLEADAFRUITTEMPERATURE_H_
|
||||
|
||||
#include "bluefruit_common.h"
|
||||
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
#include "BLEAdafruitSensor.h"
|
||||
|
||||
class BLEAdafruitTemperature : public BLEAdafruitSensor
|
||||
{
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_DATA[16];
|
||||
|
||||
BLEAdafruitTemperature();
|
||||
virtual err_t begin(void);
|
||||
};
|
||||
|
||||
#endif /* BLEADAFRUITTEMPERATURE_H_ */
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 "bluefruit.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
const uint8_t BLEAdafruitTone::UUID128_SERVICE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0C, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
const uint8_t BLEAdafruitTone::UUID128_CHR_TONE[16] =
|
||||
{
|
||||
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
||||
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0C, 0xAF, 0xAD
|
||||
};
|
||||
|
||||
BLEAdafruitTone::BLEAdafruitTone(void)
|
||||
: BLEService(UUID128_SERVICE), _tone(UUID128_CHR_TONE)
|
||||
{
|
||||
_pin = -1;
|
||||
}
|
||||
|
||||
err_t BLEAdafruitTone::begin(int pin)
|
||||
{
|
||||
_pin = pin;
|
||||
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
// Setup Characteristic
|
||||
_tone.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
|
||||
_tone.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
_tone.setFixedLen(6); // uint16_t freq, uint32_t duration
|
||||
_tone.setWriteCallback(tone_write_cb, true);
|
||||
VERIFY_STATUS( _tone.begin() );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
void BLEAdafruitTone::tone_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
|
||||
{
|
||||
BLEAdafruitTone& svc = (BLEAdafruitTone&) chr->parentService();
|
||||
|
||||
struct ATTR_PACKED {
|
||||
uint16_t freq;
|
||||
uint32_t duration;
|
||||
} tone_data;
|
||||
|
||||
PRINT_LOCATION();
|
||||
// invalid length
|
||||
if (len != sizeof(tone_data)) return;
|
||||
memcpy(&tone_data, data, len);
|
||||
|
||||
PRINT_LOCATION();
|
||||
tone(svc._pin, tone_data.freq, tone_data.duration);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 BLEADAFRUITTONE_H_
|
||||
#define BLEADAFRUITTONE_H_
|
||||
|
||||
#include "bluefruit_common.h"
|
||||
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
class BLEAdafruitTone : public BLEService
|
||||
{
|
||||
public:
|
||||
static const uint8_t UUID128_SERVICE[16];
|
||||
static const uint8_t UUID128_CHR_TONE[16];
|
||||
|
||||
BLEAdafruitTone(void);
|
||||
virtual err_t begin(int pin);
|
||||
|
||||
private:
|
||||
int _pin;
|
||||
BLECharacteristic _tone;
|
||||
|
||||
static void tone_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
|
||||
};
|
||||
|
||||
#endif /* BLEADAFRUITTONE_H_ */
|
||||
Reference in new issue
Block a user