diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index ed3a5244..61778bd7 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -64,6 +64,7 @@ #include "services/BLEAdafruitNeopixel.h" #include "services/BLEAdafruitAccel.h" #include "services/BLEAdafruitLightSensor.h" +#include "services/BLEAdafruitButton.h" #include "clients/BLEAncs.h" #include "clients/BLEClientUart.h" diff --git a/libraries/Bluefruit52Lib/src/services/BLEAdafruitButton.cpp b/libraries/Bluefruit52Lib/src/services/BLEAdafruitButton.cpp new file mode 100644 index 00000000..41702f9c --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEAdafruitButton.cpp @@ -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 +//--------------------------------------------------------------------+ + + +/* 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 + * + * Board Button service 0600 + * - Button 0601 | uint32_t | Read + Notify | e.g slide (b0), button A (b1), button B (b2) + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitButton::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x06, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitButton::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x06, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitButton::BLEAdafruitButton(void) + : BLEService(UUID128_SERVICE), Button(UUID128_CHR_DATA), Period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD) +{ + +} + +err_t BLEAdafruitButton::begin (void) +{ + // Invoke base class begin() + VERIFY_STATUS( BLEService::begin() ); + + // Add Characteristic + Button.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + Button.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + Button.setFixedLen(4); + VERIFY_STATUS( Button.begin() ); + + // Add Characteristic + Period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE); + Period.setPermission(SECMODE_OPEN, SECMODE_OPEN); + Period.setFixedLen(4); + VERIFY_STATUS( Period.begin() ); + Period.write32(10); + + return ERROR_NONE; +} diff --git a/libraries/Bluefruit52Lib/src/services/BLEAdafruitButton.h b/libraries/Bluefruit52Lib/src/services/BLEAdafruitButton.h new file mode 100644 index 00000000..b6e9f742 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEAdafruitButton.h @@ -0,0 +1,46 @@ +/* + * 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 BLE_ADAFRUIT_BUTTON_H_ +#define BLE_ADAFRUIT_BUTTON_H_ + +#include "bluefruit_common.h" + +#include "BLECharacteristic.h" +#include "BLEService.h" + +class BLEAdafruitButton : public BLEService +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + + BLECharacteristic Button; + BLECharacteristic Period; + + BLEAdafruitButton(void); + virtual err_t begin(void); +}; + +#endif /* BLE_ADAFRUIT_BUTTON_H_ */ diff --git a/libraries/Bluefruit52Lib/src/services/BLEAdafruitLightSensor.cpp b/libraries/Bluefruit52Lib/src/services/BLEAdafruitLightSensor.cpp new file mode 100644 index 00000000..1d21d7ba --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEAdafruitLightSensor.cpp @@ -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 +//--------------------------------------------------------------------+ + + +/* 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 + * + * Light Sensor service 0300 + * - Lux 0301 | float | Read + Notify | + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitLightSensor::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x03, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitLightSensor::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x03, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitLightSensor::BLEAdafruitLightSensor(void) + : BLEService(UUID128_SERVICE), Lux(UUID128_CHR_DATA), Period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD) +{ + +} + +err_t BLEAdafruitLightSensor::begin (void) +{ + // Invoke base class begin() + VERIFY_STATUS( BLEService::begin() ); + + // Add Characteristic + Lux.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + Lux.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + Lux.setFixedLen(4); + VERIFY_STATUS( Lux.begin() ); + + // Add Characteristic + Period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE); + Period.setPermission(SECMODE_OPEN, SECMODE_OPEN); + Period.setFixedLen(4); + VERIFY_STATUS( Period.begin() ); + Period.write32(10); + + return ERROR_NONE; +} diff --git a/libraries/Bluefruit52Lib/src/services/BLEAdafruitLightSensor.h b/libraries/Bluefruit52Lib/src/services/BLEAdafruitLightSensor.h new file mode 100644 index 00000000..c184113b --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEAdafruitLightSensor.h @@ -0,0 +1,46 @@ +/* + * 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 BLE_ADAFRUIT_LIGHT_SENSOR_H_ +#define BLE_ADAFRUIT_LIGHT_SENSOR_H_ + +#include "bluefruit_common.h" + +#include "BLECharacteristic.h" +#include "BLEService.h" + +class BLEAdafruitLightSensor : public BLEService +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + + BLECharacteristic Lux; + BLECharacteristic Period; + + BLEAdafruitLightSensor(void); + virtual err_t begin(void); +}; + +#endif /* BLE_ADAFRUIT_LIGHT_SENSOR_H_ */ diff --git a/libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp b/libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp index 812dfd67..a3f73c43 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEAdafruitTemperature.cpp @@ -67,7 +67,7 @@ err_t BLEAdafruitTemperature::begin (void) // Add Temperature Characteristic Temperature.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); Temperature.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); - Temperature.setFixedLen(2); + Temperature.setFixedLen(4); VERIFY_STATUS( Temperature.begin() ); // Add Measurement Interval Characteristic