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,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);
|
||||
}
|
||||
Reference in new issue
Block a user