89 lines
3.3 KiB
C++
89 lines
3.3 KiB
C++
/*
|
|
* 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
|
|
*
|
|
* Sound service 0B00
|
|
* - Sound Samples 0B01 | int16_t[] | Read + Notify | samples, if dual channel then Left, Right, Left, Right ...
|
|
* - Number Channels 0B02 | uint8_t | Read | 1 for mono, 2 for dual
|
|
* - Measurement Period 0001
|
|
*/
|
|
|
|
const uint8_t BLEAdafruitSound::UUID128_SERVICE[16] =
|
|
{
|
|
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
|
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0B, 0xAF, 0xAD
|
|
};
|
|
|
|
const uint8_t BLEAdafruitSound::UUID128_CHR_DATA[16] =
|
|
{
|
|
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
|
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0B, 0xAF, 0xAD
|
|
};
|
|
|
|
const uint8_t BLEAdafruitSound::UUID128_CHR_CHANNEL_COUNT[16] =
|
|
{
|
|
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
|
|
0xA8, 0x42, 0x32, 0xC3, 0x02, 0x0B, 0xAF, 0xAD
|
|
};
|
|
|
|
// Constructor
|
|
BLEAdafruitSound::BLEAdafruitSound(void)
|
|
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA), _channel_count(UUID128_CHR_CHANNEL_COUNT)
|
|
{
|
|
// Setup Measurement Characteristic
|
|
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
|
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
|
_measurement.setMaxLen(BLE_GATTS_VAR_ATTR_LEN_MAX);
|
|
|
|
// channel count Characteristic
|
|
_channel_count.setProperties(CHR_PROPS_READ);
|
|
_channel_count.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
|
_channel_count.setFixedLen(1);
|
|
}
|
|
|
|
err_t BLEAdafruitSound::begin(uint8_t channel_count, measure_callback_t fp, int32_t ms)
|
|
{
|
|
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
|
|
VERIFY_STATUS( BLEAdafruitSensor::begin(fp, ms) );
|
|
|
|
// Add channel count Characteristic
|
|
VERIFY_STATUS( _channel_count.begin() );
|
|
_channel_count.write8(channel_count);
|
|
|
|
return ERROR_NONE;
|
|
}
|