|
| 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 "bluefruit.h" |
| 26 | + |
| 27 | +//--------------------------------------------------------------------+ |
| 28 | +// MACRO TYPEDEF CONSTANT ENUM DECLARATION |
| 29 | +//--------------------------------------------------------------------+ |
| 30 | + |
| 31 | + |
| 32 | +//------------- IMPLEMENTATION -------------// |
| 33 | +/* Adafruit NeoPixel Service |
| 34 | + * - Service: ADAF-0002-C332-42A8-93BD-25E905756CB8 |
| 35 | + * - Count : ADAF-0003-C332-42A8-93BD-25E905756CB8 |
| 36 | + * - Type : ADAF-0004-C332-42A8-93BD-25E905756CB8 |
| 37 | + * - Data : ADAF-0005-C332-42A8-93BD-25E905756CB8 |
| 38 | + */ |
| 39 | + |
| 40 | +const uint8_t BLEAdafruitNeopixel::UUID128_SERVICE[16] = |
| 41 | +{ |
| 42 | + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, |
| 43 | + 0xA8, 0x42, 0x32, 0xC3, 0x02, 0x00, 0xAF, 0xAD |
| 44 | +}; |
| 45 | + |
| 46 | +const uint8_t BLEAdafruitNeopixel::UUID128_CHR_COUNT[16] = |
| 47 | +{ |
| 48 | + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, |
| 49 | + 0xA8, 0x42, 0x32, 0xC3, 0x03, 0x00, 0xAF, 0xAD |
| 50 | +}; |
| 51 | + |
| 52 | +const uint8_t BLEAdafruitNeopixel::UUID128_CHR_TYPE[16] = |
| 53 | +{ |
| 54 | + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, |
| 55 | + 0xA8, 0x42, 0x32, 0xC3, 0x04, 0x00, 0xAF, 0xAD |
| 56 | +}; |
| 57 | + |
| 58 | +const uint8_t BLEAdafruitNeopixel::UUID128_CHR_DATA[16] = |
| 59 | +{ |
| 60 | + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, |
| 61 | + 0xA8, 0x42, 0x32, 0xC3, 0x05, 0x00, 0xAF, 0xAD |
| 62 | +}; |
| 63 | + |
| 64 | +// Constructor |
| 65 | +BLEAdafruitNeopixel::BLEAdafruitNeopixel(void) |
| 66 | + : BLEService(UUID128_SERVICE), Count(UUID128_CHR_COUNT), Type(UUID128_CHR_TYPE), Data(UUID128_CHR_DATA) |
| 67 | +{ |
| 68 | + |
| 69 | +} |
| 70 | + |
| 71 | +err_t BLEAdafruitNeopixel::begin (void) |
| 72 | +{ |
| 73 | + // Invoke base class begin() |
| 74 | + VERIFY_STATUS( BLEService::begin() ); |
| 75 | + |
| 76 | + // Add Characteristic |
| 77 | + Count.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE); |
| 78 | + Count.setPermission(SECMODE_OPEN, SECMODE_OPEN); |
| 79 | + Count.setFixedLen(2); |
| 80 | + Count.setUserDescriptor("Count"); |
| 81 | + VERIFY_STATUS( Count.begin() ); |
| 82 | + Count.write16(0); |
| 83 | + |
| 84 | + // Add Characteristic |
| 85 | + Type.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE); |
| 86 | + Type.setPermission(SECMODE_OPEN, SECMODE_OPEN); |
| 87 | + Type.setFixedLen(2); |
| 88 | + Type.setUserDescriptor("Type"); |
| 89 | + VERIFY_STATUS( Type.begin() ); |
| 90 | + Type.write16(0); |
| 91 | + |
| 92 | + // Add Characteristic |
| 93 | + Data.setProperties(CHR_PROPS_WRITE); |
| 94 | + Data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN); |
| 95 | + Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH)); |
| 96 | + Data.setUserDescriptor("Data"); |
| 97 | + VERIFY_STATUS( Data.begin() ); |
| 98 | + |
| 99 | + return ERROR_NONE; |
| 100 | +} |
0 commit comments