From bf4ac6ba718a29eae0b798e51e8df824d7c9b3d2 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 6 Nov 2019 23:10:38 +0700 Subject: [PATCH] adding Adafruit Neo Pixel service --- libraries/Bluefruit52Lib/src/bluefruit.h | 1 + .../src/services/BLEAdafruitNeopixel.cpp | 100 ++++++++++++++++++ .../src/services/BLEAdafruitNeopixel.h | 51 +++++++++ .../src/services/BLEAdafruitTemperature.cpp | 10 +- 4 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.cpp create mode 100644 libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.h diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index 3eedc753..53393952 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -61,6 +61,7 @@ #include "services/EddyStone.h" #include "services/BLEAdafruitTemperature.h" +#include "services/BLEAdafruitNeopixel.h" #include "clients/BLEAncs.h" #include "clients/BLEClientUart.h" diff --git a/libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.cpp b/libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.cpp new file mode 100644 index 00000000..4fce213e --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.cpp @@ -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 +//--------------------------------------------------------------------+ + + +//------------- IMPLEMENTATION -------------// +/* Adafruit NeoPixel Service + * - Service: ADAF-0002-C332-42A8-93BD-25E905756CB8 + * - Count : ADAF-0003-C332-42A8-93BD-25E905756CB8 + * - Type : ADAF-0004-C332-42A8-93BD-25E905756CB8 + * - Data : ADAF-0005-C332-42A8-93BD-25E905756CB8 + */ + +const uint8_t BLEAdafruitNeopixel::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x02, 0x00, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitNeopixel::UUID128_CHR_COUNT[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x03, 0x00, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitNeopixel::UUID128_CHR_TYPE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x04, 0x00, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitNeopixel::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x05, 0x00, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitNeopixel::BLEAdafruitNeopixel(void) + : BLEService(UUID128_SERVICE), Count(UUID128_CHR_COUNT), Type(UUID128_CHR_TYPE), Data(UUID128_CHR_DATA) +{ + +} + +err_t BLEAdafruitNeopixel::begin (void) +{ + // Invoke base class begin() + VERIFY_STATUS( BLEService::begin() ); + + // Add Characteristic + Count.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE); + Count.setPermission(SECMODE_OPEN, SECMODE_OPEN); + Count.setFixedLen(2); + Count.setUserDescriptor("Count"); + VERIFY_STATUS( Count.begin() ); + Count.write16(0); + + // Add Characteristic + Type.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE); + Type.setPermission(SECMODE_OPEN, SECMODE_OPEN); + Type.setFixedLen(2); + Type.setUserDescriptor("Type"); + VERIFY_STATUS( Type.begin() ); + Type.write16(0); + + // Add Characteristic + Data.setProperties(CHR_PROPS_WRITE); + Data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN); + Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH)); + Data.setUserDescriptor("Data"); + VERIFY_STATUS( Data.begin() ); + + return ERROR_NONE; +} diff --git a/libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.h b/libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.h new file mode 100644 index 00000000..7e2ddce4 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEAdafruitNeopixel.h @@ -0,0 +1,51 @@ +/* + * 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 BLEADAFRUITNEOPIXEL_H_ +#define BLEADAFRUITNEOPIXEL_H_ + +#include "bluefruit_common.h" + +#include "BLECharacteristic.h" +#include "BLEService.h" + +class BLEAdafruitNeopixel : public BLEService +{ + public: + static const uint8_t UUID128_SERVICE[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 Type; + BLECharacteristic Data; + + BLEAdafruitNeopixel(void); + virtual err_t begin(void); +}; + + + +#endif /* BLEADAFRUITNEOPIXEL_H_ */ diff --git a/libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp b/libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp index 7465d5df..a8e423a8 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp @@ -24,16 +24,14 @@ #include "bluefruit.h" -#include "BLEAdafruitTemperature.h" - //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ /* Adafruit Temperature Service - * - Service: 20E6-0001-C332-42A8-93BD-25E905756CB8 - * - Temperature Celsius : 0x2A6E - * - Measurement Interval : 0x2A21 + * - Service: ADAF-0001-C332-42A8-93BD-25E905756CB8 + * - Temperature Celsius : 0x2A6E + * - Measurement Interval : 0x2A21 * * https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.temperature.xml * https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.measurement_interval.xml @@ -42,7 +40,7 @@ const uint8_t BLEAdafruitTemperature::UUID128_SERVICE[16] = { 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, - 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x00, 0xE6, 0x20 + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x00, 0xAF, 0xAD }; // Constructor