|
| 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 | +#include <Adafruit_AHRS.h> |
| 27 | + |
| 28 | +//--------------------------------------------------------------------+ |
| 29 | +// MACRO TYPEDEF CONSTANT ENUM DECLARATION |
| 30 | +//--------------------------------------------------------------------+ |
| 31 | + |
| 32 | + |
| 33 | +/* All Adafruit Service/Characteristic UUID128 share the same Base UUID: |
| 34 | + * ADAFxxx-C332-42A8-93BD-25E905756CB8 |
| 35 | + * |
| 36 | + * Shared Characteristics |
| 37 | + * - Measurement Period 0001 | int32_t | Read + Write | |
| 38 | + * ms between measurements, -1: stop reading, 0: update when changes |
| 39 | + * |
| 40 | + * Quaternion service 0D00 |
| 41 | + * - Quater 0D01 | float[4] | Read + Notify | qw, qx, qy, qz |
| 42 | + * - Measurement Period 0001 |
| 43 | + */ |
| 44 | + |
| 45 | +const uint8_t BLEAdafruitQuaternion::UUID128_SERVICE[16] = |
| 46 | +{ |
| 47 | + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, |
| 48 | + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0D, 0xAF, 0xAD |
| 49 | +}; |
| 50 | + |
| 51 | +const uint8_t BLEAdafruitQuaternion::UUID128_CHR_DATA[16] = |
| 52 | +{ |
| 53 | + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, |
| 54 | + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0D, 0xAF, 0xAD |
| 55 | +}; |
| 56 | + |
| 57 | +// Constructor |
| 58 | +BLEAdafruitQuaternion::BLEAdafruitQuaternion(void) |
| 59 | + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) |
| 60 | +{ |
| 61 | + _accel = _gyro = _mag = NULL; |
| 62 | + _filter = NULL; |
| 63 | +} |
| 64 | + |
| 65 | +err_t BLEAdafruitQuaternion::begin(Adafruit_AHRS_FusionInterface* filter, Adafruit_Sensor* accel, Adafruit_Sensor* gyro, Adafruit_Sensor* mag) |
| 66 | +{ |
| 67 | + _filter = filter; |
| 68 | + _accel = accel; |
| 69 | + _gyro = gyro; |
| 70 | + _mag = mag; |
| 71 | + |
| 72 | + // Setup Measurement Characteristic |
| 73 | + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); |
| 74 | + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); |
| 75 | + _measurement.setFixedLen(4*4); |
| 76 | + |
| 77 | + // Invoke base class begin(), this will add Service, Measurement and Period characteristics |
| 78 | + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); |
| 79 | + |
| 80 | + return ERROR_NONE; |
| 81 | +} |
0 commit comments