From c1897410d492c9a0b1609cfcc6c5df7b5e178280 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 6 Mar 2020 00:13:49 +0700 Subject: [PATCH 01/19] add sound service --- .../src/BLEAdafruitService.h | 1 + .../src/services/BLEAdafruitSensor.cpp | 3 + .../src/services/BLEAdafruitSound.cpp | 88 ++++++++++++++++++ .../src/services/BLEAdafruitSound.h | 43 +++++++++ .../bluefruit_playground.ino | 92 +++++++++++++------ .../examples/Peripheral/neopixel/neopixel.ino | 10 +- 6 files changed, 209 insertions(+), 28 deletions(-) create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitSound.cpp create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitSound.h diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index 5ece5c2e..8d086f98 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -39,6 +39,7 @@ #include "services/BLEAdafruitLightSensor.h" #include "services/BLEAdafruitMagnetic.h" #include "services/BLEAdafruitQuaternion.h" +#include "services/BLEAdafruitSound.h" #include "services/BLEAdafruitTemperature.h" #include "services/BLEAdafruitTone.h" diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp index fdcab020..d5bc931e 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp @@ -135,6 +135,9 @@ void BLEAdafruitSensor::_measure_handler(void) return; // nothing to measure } + // no data to notify + if (!len) return; + // Period = 0, compare with old data, only update on changes if ( 0 == _period.read32() ) { diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSound.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitSound.cpp new file mode 100644 index 00000000..aec85fc5 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSound.cpp @@ -0,0 +1,88 @@ +/* + * 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; +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSound.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitSound.h new file mode 100644 index 00000000..e8972ba6 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSound.h @@ -0,0 +1,43 @@ +/* + * 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 BLEADAFRUIT_SOUND_H_ +#define BLEADAFRUIT_SOUND_H_ + +class BLEAdafruitSound : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + static const uint8_t UUID128_CHR_CHANNEL_COUNT[16]; + + BLEAdafruitSound(void); + + err_t begin(uint8_t channel_count, measure_callback_t fp, int32_t ms = DEFAULT_PERIOD); + + private: + BLECharacteristic _channel_count; +}; + +#endif /* BLEADAFRUIT_SOUND_H_ */ diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index d0258696..70425b98 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -21,26 +21,12 @@ #include #include +#include #include #include #include #include -// BLE Service -BLEDfu bledfu; // OTA DFU service -BLEDis bledis; // device information -BLEUart bleuart; // uart over ble -BLEBas blebas; // battery - -// Adafruit Service: ADAFxx-C332-42A8-93BD-25E905756CB8 -BLEAdafruitTemperature bleTemp; -BLEAdafruitAccel bleAccel; -BLEAdafruitLightSensor bleLight; -BLEAdafruitButton bleButton; -BLEAdafruitTone bleTone; - -BLEAdafruitAddressablePixel blePixel; - //------------- Circuit Playground Bluefruit -------------// #if defined(ARDUINO_NRF52840_CIRCUITPLAY) @@ -103,12 +89,10 @@ BLEAdafruitQuaternion bleQuater; Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel Adafruit_LIS3MDL lis3mdl; // Magnetometer - Adafruit_APDS9960 apds9960; // Proximity, Light, Gesture, Color Adafruit_BMP280 bmp280; // Temperature, Barometric Adafruit_SHT31 sht30; // Humid - // pick your filter! slower == better quality output //Adafruit_NXPSensorFusion filter; // slowest //Adafruit_Madgwick filter; // faster than NXP @@ -142,9 +126,9 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) uint32_t button = 0; button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 ); - #if defined(PIN_BUTTON2) - button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); - #endif +#if defined(PIN_BUTTON2) + button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); +#endif memcpy(buf, &button, 4); return 4; } @@ -160,7 +144,46 @@ uint16_t measure_humid(uint8_t* buf, uint16_t bufsize) #error "Board is not supported" #endif +//--------------------------------------------------------------------+ +// Common Services +//--------------------------------------------------------------------+ + +// BLE Service +BLEDfu bledfu; // OTA DFU service +BLEDis bledis; // device information +BLEUart bleuart; // uart over ble +BLEBas blebas; // battery + +// Adafruit Service: ADAFxx-C332-42A8-93BD-25E905756CB8 +BLEAdafruitTemperature bleTemp; +BLEAdafruitAccel bleAccel; +BLEAdafruitLightSensor bleLight; +BLEAdafruitButton bleButton; +BLEAdafruitTone bleTone; +BLEAdafruitAddressablePixel blePixel; +BLEAdafruitSound bleSound; + Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); +int16_t pdmSample[256]; // sound samples +uint16_t pdmByteCount = 0; + +//void pdm_plotter(uint16_t count) +//{ +// for (int i = 0; i < count/2; i++) Serial.println(pdmSample[i]); +//} + +uint16_t measure_sound(uint8_t* buf, uint16_t bufsize) +{ + uint16_t const len = min(bufsize, pdmByteCount); + + if ( len ) memcpy(buf, pdmSample, len); + pdmByteCount = 0; // clear count + +// if (len) ada_callback(NULL, 0, pdm_plotter, len); + + return len; +} + //------------- Setup -------------// void setup() @@ -178,9 +201,9 @@ void setup() // Button pinMode(PIN_BUTTON1, INPUT_PULLUP); - #if defined(PIN_BUTTON2) - pinMode(PIN_BUTTON2, INPUT_PULLUP); - #endif +#if defined(PIN_BUTTON2) + pinMode(PIN_BUTTON2, INPUT_PULLUP); +#endif apds9960.begin(); apds9960.enableColor(true); @@ -214,6 +237,10 @@ void setup() cal.loadCalibration(); #endif + // 1 channel (mono mode) with 16 kHz sample rate + PDM.onReceive(onPDMdata); + PDM.begin(1, 16000); + Serial.println("Bluefruit Playground Example"); Serial.println("---------------------------\n"); @@ -254,14 +281,15 @@ void setup() bleButton.begin(measure_button, 100); bleButton.setPeriod(0); // only notify if there is changes with buttons - #if defined(PIN_BUZZER) - bleTone.begin(PIN_BUZZER); - #endif +#if defined(PIN_BUZZER) + bleTone.begin(PIN_BUZZER); +#endif strip.begin(); blePixel.begin(&strip); - bleAccel.begin(accel_sensor); + bleAccel.begin(accel_sensor); // TODO dropped in favor to Quaternion service for CLUE & Sense + bleSound.begin(1, measure_sound, 100); // CPB doesn't support these on-board sensor #ifdef ARDUINO_NRF52840_CIRCUITPLAY @@ -354,3 +382,13 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason) Serial.println(); Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX); } + + +void onPDMdata() +{ + // query the number of bytes available + pdmByteCount = PDM.available(); + + // read into the sample buffer + PDM.read(pdmSample, pdmByteCount); +} diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/neopixel/neopixel.ino b/libraries/Bluefruit52Lib/examples/Peripheral/neopixel/neopixel.ino index 0da9a287..99449c30 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/neopixel/neopixel.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/neopixel/neopixel.ino @@ -29,7 +29,15 @@ #include #define NEOPIXEL_VERSION_STRING "Neopixel v2.0" -#define PIN 30 /* Pin used to drive the NeoPixels */ + +/* Pin used to drive the NeoPixels */ +#if defined ARDUINO_NRF52840_CIRCUITPLAY + #define PIN PIN_NEOPIXEL +#elif defined ARDUINO_NRF52832_FEATHER + #define PIN 30 +#else + #define PIN 6 +#endif #define MAXCOMPONENTS 4 uint8_t *pixelBuffer = NULL; From e87d1de07e14e295fc0bbad7a1a9cb4958d5bcd4 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 6 Mar 2020 18:26:08 +0700 Subject: [PATCH 02/19] adding color service --- .../src/BLEAdafruitService.h | 1 + .../src/services/BLEAdafruitColor.cpp | 64 +++++++++++++++++++ .../src/services/BLEAdafruitColor.h | 39 +++++++++++ .../bluefruit_playground.ino | 16 ++++- 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitColor.cpp create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitColor.h diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index 8d086f98..8842fc61 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -34,6 +34,7 @@ #include "services/BLEAdafruitAddressablePixel.h" #include "services/BLEAdafruitBaro.h" #include "services/BLEAdafruitButton.h" +#include "services/BLEAdafruitColor.h" #include "services/BLEAdafruitGyro.h" #include "services/BLEAdafruitHumid.h" #include "services/BLEAdafruitLightSensor.h" diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.cpp new file mode 100644 index 00000000..fec3399b --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.cpp @@ -0,0 +1,64 @@ +/* + * 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 + * + * Color service 0A00 + * - Color 0A01 | uint16_t[3] | Read + Notify | Red, Green, Blue each is 16-bit color + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitColor::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0A, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitColor::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0A, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitColor::BLEAdafruitColor(void) + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) +{ + // Setup Measurement Characteristic + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _measurement.setFixedLen(2*3); +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.h new file mode 100644 index 00000000..3c4b6013 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitColor.h @@ -0,0 +1,39 @@ +/* + * 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 BLEADAFRUIT_COLOR_H_ +#define BLEADAFRUIT_COLOR_H_ + +class BLEAdafruitColor : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + + BLEAdafruitColor(void); + + using BLEAdafruitSensor::begin; +}; + +#endif /* BLEADAFRUIT_COLOR_H_ */ diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 70425b98..59c7ec3b 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -83,8 +83,9 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) #define NEOPIXEL_COUNT 1 -BLEAdafruitHumid bleHumid; BLEAdafruitBaro bleBaro; +BLEAdafruitColor bleColor; +BLEAdafruitHumid bleHumid; BLEAdafruitQuaternion bleQuater; Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel @@ -119,6 +120,18 @@ uint16_t measure_light(uint8_t* buf, uint16_t bufsize) return 4; } +uint16_t measure_color(uint8_t* buf, uint16_t bufsize) +{ + uint16_t rgb[3]; + uint16_t c; + (void) c; + + apds9960.getColorData(rgb+0, rgb+1, rgb+2, &c); + + memcpy(buf, rgb, sizeof(rgb)); + return sizeof(rgb); +} + uint16_t measure_button(uint8_t* buf, uint16_t bufsize) { // Button is active LOW on most board except CPlay @@ -297,6 +310,7 @@ void setup() #else bleTemp.begin(bmp280.getTemperatureSensor()); + bleColor.begin(measure_color, 100); bleHumid.begin(measure_humid); bleBaro.begin(bmp280.getPressureSensor()); From 8097e50f1d9a792305532aa6619244fcfe40bc09 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 6 Mar 2020 21:00:16 +0700 Subject: [PATCH 03/19] add sensor service notify callback --- .../src/services/BLEAdafruitQuaternion.cpp | 4 ++-- .../src/services/BLEAdafruitQuaternion.h | 2 +- .../src/services/BLEAdafruitSensor.cpp | 15 ++++++++++++--- .../src/services/BLEAdafruitSensor.h | 7 ++++++- variants/clue_nrf52840/variant.h | 1 + 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.cpp index 04d02f4c..a53436c2 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.cpp @@ -95,7 +95,7 @@ void BLEAdafruitQuaternion::setCalibration(Adafruit_Sensor_Calibration* calib) _calib = calib; } -void BLEAdafruitQuaternion::_notify_cb(uint16_t conn_hdl, uint16_t value) +void BLEAdafruitQuaternion::_notify_handler(uint16_t conn_hdl, uint16_t value) { // Start/Stop filter timer if (value & BLE_GATT_HVX_NOTIFICATION) @@ -107,7 +107,7 @@ void BLEAdafruitQuaternion::_notify_cb(uint16_t conn_hdl, uint16_t value) } // Call SuperClass function - BLEAdafruitSensor::_notify_cb(conn_hdl, value); + BLEAdafruitSensor::_notify_handler(conn_hdl, value); } void BLEAdafruitQuaternion::_update_timer(int32_t ms) diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.h index a579d447..353b2d97 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.h @@ -43,7 +43,7 @@ class BLEAdafruitQuaternion : public BLEAdafruitSensor protected: void _update_timer(int32_t ms); void _measure_handler(void); - void _notify_cb(uint16_t conn_hdl, uint16_t value); + void _notify_handler(uint16_t conn_hdl, uint16_t value); void _fitler_update(void); diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp index d5bc931e..bfc931e0 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp @@ -31,8 +31,9 @@ BLEAdafruitSensor::BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid) : BLEService(service_uuid), _measurement(data_uuid), _period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD) { - _measure_cb = NULL; _sensor = NULL; + _measure_cb = NULL; + _notify_cb = NULL; } err_t BLEAdafruitSensor::_begin(int32_t ms) @@ -76,10 +77,15 @@ void BLEAdafruitSensor::setPeriod(int32_t period_ms) _update_timer(period_ms); } +void BLEAdafruitSensor::setNotifyCallback(notify_callback_t fp) +{ + _notify_cb = fp; +} + //--------------------------------------------------------------------+ // Internal API //--------------------------------------------------------------------+ -void BLEAdafruitSensor::_notify_cb(uint16_t conn_hdl, uint16_t value) +void BLEAdafruitSensor::_notify_handler(uint16_t conn_hdl, uint16_t value) { // notify enabled if (value & BLE_GATT_HVX_NOTIFICATION) @@ -90,6 +96,9 @@ void BLEAdafruitSensor::_notify_cb(uint16_t conn_hdl, uint16_t value) _timer.stop(); } + // invoke callback if any + if (_notify_cb) _notify_cb(conn_hdl, value); + // send initial notification if period = 0 // if ( 0 == svc._period.read32() ) // { @@ -178,6 +187,6 @@ void BLEAdafruitSensor::sensor_data_cccd_cb(uint16_t conn_hdl, BLECharacteristic { BLEAdafruitSensor* svc = (BLEAdafruitSensor*) &chr->parentService(); - svc->_notify_cb(conn_hdl, value); + svc->_notify_handler(conn_hdl, value); } diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h index 99b4f8d0..e7003286 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h @@ -31,6 +31,8 @@ class BLEAdafruitSensor : public BLEService { public: static const int32_t DEFAULT_PERIOD = 1000; + + typedef void (*notify_callback_t)(uint16_t conn_hdl, bool enabled); typedef uint16_t (*measure_callback_t )(uint8_t* buf, uint16_t bufsize); BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid); @@ -39,6 +41,7 @@ class BLEAdafruitSensor : public BLEService virtual err_t begin(Adafruit_Sensor* sensor, int32_t ms = DEFAULT_PERIOD); void setPeriod(int32_t period_ms); + void setNotifyCallback(notify_callback_t fp); protected: BLECharacteristic _period; @@ -47,13 +50,15 @@ class BLEAdafruitSensor : public BLEService Adafruit_Sensor* _sensor; measure_callback_t _measure_cb; + notify_callback_t _notify_cb; + SoftwareTimer _timer; err_t _begin(int32_t ms); virtual void _update_timer(int32_t ms); virtual void _measure_handler(void); - virtual void _notify_cb(uint16_t conn_hdl, uint16_t value); + virtual void _notify_handler(uint16_t conn_hdl, uint16_t value); static void sensor_timer_cb(TimerHandle_t xTimer); static void sensor_period_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len); diff --git a/variants/clue_nrf52840/variant.h b/variants/clue_nrf52840/variant.h index 7d77a576..39209752 100644 --- a/variants/clue_nrf52840/variant.h +++ b/variants/clue_nrf52840/variant.h @@ -43,6 +43,7 @@ extern "C" // LEDs #define PIN_LED1 (17) #define PIN_NEOPIXEL (18) +#define PIN_LED2 (43) // dual white LEDs #define LED_BUILTIN PIN_LED1 From 566eb65e81c1cf63296be04c69815f27104a4077 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 6 Mar 2020 21:50:55 +0700 Subject: [PATCH 04/19] enhancing color --- .../bluefruit_playground.ino | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 59c7ec3b..c577684e 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -107,25 +107,47 @@ Adafruit_FlashTransport_QSPI flashTransport; Adafruit_SPIFlash flash(&flashTransport); FatFileSystem fatfs; +void light_enable_callback(uint16_t conn_hdl, bool enabled) +{ + (void) conn_hdl; + apds9960.enableColor(enabled); +} + uint16_t measure_light(uint8_t* buf, uint16_t bufsize) { float lux; - uint16_t r, g, b, c; + apds9960.getColorData(&r, &g, &b, &c); lux = c; - memcpy(buf, &lux, 4); return 4; } +void color_enable_callback(uint16_t conn_hdl, bool enabled) +{ + (void) conn_hdl; + + apds9960.enableColor(enabled); + +#ifdef ARDUINO_NRF52840_CLUE + digitalWrite(PIN_LED2, enabled); + +#else + // Feather Sense use neopixel + + +#endif +} + uint16_t measure_color(uint8_t* buf, uint16_t bufsize) { uint16_t rgb[3]; uint16_t c; (void) c; + apds9960.enableColor(true); apds9960.getColorData(rgb+0, rgb+1, rgb+2, &c); memcpy(buf, rgb, sizeof(rgb)); @@ -155,10 +177,11 @@ uint16_t measure_humid(uint8_t* buf, uint16_t bufsize) #else #error "Board is not supported" -#endif + +#endif // end of board //--------------------------------------------------------------------+ -// Common Services +// Common for all Boards //--------------------------------------------------------------------+ // BLE Service @@ -198,7 +221,9 @@ uint16_t measure_sound(uint8_t* buf, uint16_t bufsize) } -//------------- Setup -------------// +//--------------------------------------------------------------------+ +// Codes +//--------------------------------------------------------------------+ void setup() { Adafruit_Sensor* accel_sensor; @@ -218,9 +243,13 @@ void setup() pinMode(PIN_BUTTON2, INPUT_PULLUP); #endif - apds9960.begin(); - apds9960.enableColor(true); +#ifdef ARDUINO_NRF52840_CLUE + // White LEDs for color sensing + pinMode(PIN_LED2, OUTPUT); + digitalWrite(PIN_LED2, LOW); +#endif + apds9960.begin(); bmp280.begin(); sht30.begin(0x44); lsm6ds33.begin_I2C(); @@ -289,8 +318,6 @@ void setup() blebas.write(100); //------------- Adafruit Service -------------// - bleLight.begin(measure_light); - bleButton.begin(measure_button, 100); bleButton.setPeriod(0); // only notify if there is changes with buttons @@ -306,11 +333,18 @@ void setup() // CPB doesn't support these on-board sensor #ifdef ARDUINO_NRF52840_CIRCUITPLAY - bleTemp.begin(measure_temperature); + bleTemp.begin(measure_temperature, 100); + bleLight.begin(measure_light, 100); #else - bleTemp.begin(bmp280.getTemperatureSensor()); + bleTemp.begin(bmp280.getTemperatureSensor(), 100); + + bleLight.begin(measure_light, 100);; + bleLight.setNotifyCallback(light_enable_callback); + bleColor.begin(measure_color, 100); + bleColor.setNotifyCallback(color_enable_callback); + bleHumid.begin(measure_humid); bleBaro.begin(bmp280.getPressureSensor()); From 9fb72b66a59c84ba1ef6db61cafc547ff409ec50 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 6 Mar 2020 22:07:28 +0700 Subject: [PATCH 05/19] wrap up color service --- .../bluefruit_playground/bluefruit_playground.ino | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index c577684e..b2b2f5c4 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -133,11 +133,6 @@ void color_enable_callback(uint16_t conn_hdl, bool enabled) #ifdef ARDUINO_NRF52840_CLUE digitalWrite(PIN_LED2, enabled); - -#else - // Feather Sense use neopixel - - #endif } @@ -147,7 +142,6 @@ uint16_t measure_color(uint8_t* buf, uint16_t bufsize) uint16_t c; (void) c; - apds9960.enableColor(true); apds9960.getColorData(rgb+0, rgb+1, rgb+2, &c); memcpy(buf, rgb, sizeof(rgb)); From 75f68b9994c4ca5679addc4e89ab12a4bf5eee2a Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 6 Mar 2020 22:17:52 +0700 Subject: [PATCH 06/19] turn off white led if disconnect without disable --- .../bluefruit_playground/bluefruit_playground.ino | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index b2b2f5c4..1c4d399e 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -421,6 +421,16 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason) (void) conn_handle; (void) reason; +#if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE) + apds9960.enableGesture(false); + apds9960.enableProximity(false); + apds9960.enableColor(false); +#endif + +#ifdef ARDUINO_NRF52840_CLUE + digitalWrite(PIN_LED2, LOW); +#endif + Serial.println(); Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX); } From 4ae66084d86b7ae0c53add7233b63d080824071a Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 7 Mar 2020 16:51:44 +0700 Subject: [PATCH 07/19] fix D13 pin --- variants/feather_nrf52840_sense/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/feather_nrf52840_sense/variant.h b/variants/feather_nrf52840_sense/variant.h index 5924cb16..18d1782d 100644 --- a/variants/feather_nrf52840_sense/variant.h +++ b/variants/feather_nrf52840_sense/variant.h @@ -42,7 +42,7 @@ extern "C" #define NUM_ANALOG_OUTPUTS (0) // LEDs -#define PIN_LED1 (3) +#define PIN_LED1 (13) #define PIN_LED2 (4) #define PIN_NEOPIXEL (8) From 49028ba75ab6abc388fb77dcee40f6b2293227ae Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 7 Mar 2020 17:19:11 +0700 Subject: [PATCH 08/19] update description --- variants/feather_nrf52840_sense/variant.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variants/feather_nrf52840_sense/variant.cpp b/variants/feather_nrf52840_sense/variant.cpp index bb845c79..82163aa7 100644 --- a/variants/feather_nrf52840_sense/variant.cpp +++ b/variants/feather_nrf52840_sense/variant.cpp @@ -29,7 +29,7 @@ const uint32_t g_ADigitalPinMap[] = 25, // D0 is P0.25 (UART TX) 24, // D1 is P0.24 (UART RX 10, // D2 is P0.10 (NFC2) - 43, // D3 is P1.11 (LED1) + 43, // D3 is P1.11 42, // D4 is P1.10 (LED2) 40, // D5 is P1.08 7, // D6 is P0.07 @@ -39,7 +39,7 @@ const uint32_t g_ADigitalPinMap[] = 27, // D10 is P0.27 6, // D11 is P0.06 8, // D12 is P0.08 - 41, // D13 is P1.09 + 41, // D13 is P1.09 (LED1) // D14 .. D21 (aka A0 .. A7) 4, // D14 is P0.04 (A0) From a557014d95ffa4df0a752f13b0f1bbbf259fc5a5 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 7 Mar 2020 17:19:56 +0700 Subject: [PATCH 09/19] skip wait for Serial in bleuart sketch --- cores/nRF5/main.cpp | 12 +++++++++--- .../examples/Peripheral/bleuart/bleuart.ino | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index f621e918..fc190f04 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -44,13 +44,19 @@ static void loop_task(void* arg) { (void) arg; - setup(); - #if CFG_DEBUG // If Serial is not begin(), call it to avoid hard fault if ( !Serial ) Serial.begin(115200); + + // Wait for Serial connection in debug mode + while ( !Serial ) yield(); + dbgPrintVersion(); - // dbgMemInfo(); +#endif + + setup(); + +#if CFG_DEBUG Bluefruit_printInfo(); #endif diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino index b1624fa4..739ff03c 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino @@ -24,7 +24,7 @@ BLEBas blebas; // battery void setup() { Serial.begin(115200); - while ( !Serial ) delay(10); // for nrf52840 with native usb +// while ( !Serial ) delay(10); // for nrf52840 with native usb Serial.println("Bluefruit52 BLEUART Example"); Serial.println("---------------------------\n"); From c7ace597fdca0cf5ee398944e55c7742b0895861 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 9 Mar 2020 18:28:05 +0700 Subject: [PATCH 10/19] adding Proximity sensor --- .../src/BLEAdafruitService.h | 1 + .../src/services/BLEAdafruitProximity.cpp | 64 +++++++++++++++++++ .../src/services/BLEAdafruitProximity.h | 39 +++++++++++ 3 files changed, 104 insertions(+) create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitProximity.cpp create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitProximity.h diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index 8842fc61..1c4f632c 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -39,6 +39,7 @@ #include "services/BLEAdafruitHumid.h" #include "services/BLEAdafruitLightSensor.h" #include "services/BLEAdafruitMagnetic.h" +#include "services/BLEAdafruitProximity.h" #include "services/BLEAdafruitQuaternion.h" #include "services/BLEAdafruitSound.h" #include "services/BLEAdafruitTemperature.h" diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitProximity.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitProximity.cpp new file mode 100644 index 00000000..eadd4a5b --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitProximity.cpp @@ -0,0 +1,64 @@ +/* + * 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 + * + * Accelerometer service 0E00 + * - Data 0E01 | uint16_t | Read + Notify | unit-less + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitProximity::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0E, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitProximity::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0E, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitProximity::BLEAdafruitProximity(void) + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) +{ + // Setup Measurement Characteristic + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _measurement.setFixedLen(2); +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitProximity.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitProximity.h new file mode 100644 index 00000000..b3050beb --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitProximity.h @@ -0,0 +1,39 @@ +/* + * 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 BLEADAFRUIT_PROXIMITY_H_ +#define BLEADAFRUIT_PROXIMITY_H_ + +class BLEAdafruitProximity : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + + BLEAdafruitProximity(void); + + using BLEAdafruitSensor::begin; +}; + +#endif /* BLEADAFRUIT_PROXIMITY_H_ */ From 6bb7576cec79b993655cc433f4bedcbea6b47fda Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 9 Mar 2020 18:54:42 +0700 Subject: [PATCH 11/19] add proximity service --- .../bluefruit_playground.ino | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 1c4d399e..24fec34c 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -86,6 +86,7 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) BLEAdafruitBaro bleBaro; BLEAdafruitColor bleColor; BLEAdafruitHumid bleHumid; +BLEAdafruitProximity bleProximity; BLEAdafruitQuaternion bleQuater; Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel @@ -148,6 +149,22 @@ uint16_t measure_color(uint8_t* buf, uint16_t bufsize) return sizeof(rgb); } +void proximity_enable_callback(uint16_t conn_hdl, bool enabled) +{ + (void) conn_hdl; + apds9960.enableProximity(enabled); +} + +uint16_t measure_proximity(uint8_t* buf, uint16_t bufsize) +{ + // APDS is only 8-bit, we better to map it to 16-bit value + uint8_t data8 = apds9960.readProximity(); + uint16_t data16 = (uint16_t) map(data8, 0, UINT8_MAX, 0, UINT16_MAX); + + memcpy(buf, &data16, 2); + return 2; +} + uint16_t measure_button(uint8_t* buf, uint16_t bufsize) { // Button is active LOW on most board except CPlay @@ -312,39 +329,44 @@ void setup() blebas.write(100); //------------- Adafruit Service -------------// + bleAccel.begin(accel_sensor, 100); // TODO dropped in favor to Quaternion service for CLUE & Sense + bleButton.begin(measure_button, 100); bleButton.setPeriod(0); // only notify if there is changes with buttons -#if defined(PIN_BUZZER) - bleTone.begin(PIN_BUZZER); -#endif - strip.begin(); blePixel.begin(&strip); - bleAccel.begin(accel_sensor); // TODO dropped in favor to Quaternion service for CLUE & Sense bleSound.begin(1, measure_sound, 100); // CPB doesn't support these on-board sensor #ifdef ARDUINO_NRF52840_CIRCUITPLAY - bleTemp.begin(measure_temperature, 100); bleLight.begin(measure_light, 100); + bleTemp.begin(measure_temperature, 100); #else - bleTemp.begin(bmp280.getTemperatureSensor(), 100); - - bleLight.begin(measure_light, 100);; - bleLight.setNotifyCallback(light_enable_callback); + bleBaro.begin(bmp280.getPressureSensor(), 100); bleColor.begin(measure_color, 100); bleColor.setNotifyCallback(color_enable_callback); - bleHumid.begin(measure_humid); - bleBaro.begin(bmp280.getPressureSensor()); + bleHumid.begin(measure_humid, 100); + + bleLight.begin(measure_light, 100);; + bleLight.setNotifyCallback(light_enable_callback); + + bleProximity.begin(measure_proximity, 100); + bleProximity.setNotifyCallback(proximity_enable_callback); // Quaternion with sensor calibration bleQuater.begin(&filter, accel_sensor, lsm6ds33.getGyroSensor(), &lis3mdl); bleQuater.setCalibration(&cal); + + bleTemp.begin(bmp280.getTemperatureSensor(), 100); +#endif + +#if defined(PIN_BUZZER) + bleTone.begin(PIN_BUZZER); #endif // Set up and start advertising From 8a402ab6e0c83360e681f3dc156cf04ae6fd8390 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Mar 2020 21:40:33 +0700 Subject: [PATCH 12/19] added gesture sensor, however attr memory is overflow --- cores/nRF5/main.cpp | 2 +- .../src/BLEAdafruitService.h | 1 + .../src/services/BLEAdafruitGesture.cpp | 64 +++++++++++++++++++ .../src/services/BLEAdafruitGesture.h | 39 +++++++++++ .../src/services/BLEAdafruitSensor.cpp | 2 +- .../.feather52840sense.test.only | 0 .../bluefruit_playground.ino | 27 ++++++++ 7 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.cpp create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.h create mode 100644 libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.feather52840sense.test.only diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index fc190f04..62f3ca30 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -46,7 +46,7 @@ static void loop_task(void* arg) #if CFG_DEBUG // If Serial is not begin(), call it to avoid hard fault - if ( !Serial ) Serial.begin(115200); + Serial.begin(115200); // Wait for Serial connection in debug mode while ( !Serial ) yield(); diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index 1c4f632c..ec04e703 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -35,6 +35,7 @@ #include "services/BLEAdafruitBaro.h" #include "services/BLEAdafruitButton.h" #include "services/BLEAdafruitColor.h" +#include "services/BLEAdafruitGesture.h" #include "services/BLEAdafruitGyro.h" #include "services/BLEAdafruitHumid.h" #include "services/BLEAdafruitLightSensor.h" diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.cpp new file mode 100644 index 00000000..ebac4321 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.cpp @@ -0,0 +1,64 @@ +/* + * 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 + * + * Gesture service 06F00 + * - Button 0F01 | unt8_t | Read + Notify | e.g 0: no gesture, 1: Up, 2: Down, 3: Left, 4: Right + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitGesture::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0F, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitGesture::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0F, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitGesture::BLEAdafruitGesture(void) + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) +{ + // Setup Measurement Characteristic + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _measurement.setFixedLen(1); +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.h new file mode 100644 index 00000000..db55bfab --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.h @@ -0,0 +1,39 @@ +/* + * 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 BLEADAFRUIT_GESTURE_H_ +#define BLEADAFRUIT_GESTURE_H_ + +class BLEAdafruitGesture : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + + BLEAdafruitGesture(void); + + using BLEAdafruitSensor::begin; +}; + +#endif /* BLEADAFRUIT_GESTURE_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp index bfc931e0..be3b7a86 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp @@ -42,8 +42,8 @@ err_t BLEAdafruitSensor::_begin(int32_t ms) VERIFY_STATUS( BLEService::begin() ); _measurement.setCccdWriteCallback(sensor_data_cccd_cb, true); - VERIFY_STATUS( _measurement.begin() ); + _measurement.write32(0); // zero 4 bytes could help to init some services _period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE); _period.setPermission(SECMODE_OPEN, SECMODE_OPEN); diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.feather52840sense.test.only b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.feather52840sense.test.only new file mode 100644 index 00000000..e69de29b diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 24fec34c..c346cf26 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -85,6 +85,7 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) BLEAdafruitBaro bleBaro; BLEAdafruitColor bleColor; +BLEAdafruitGesture bleGesture; BLEAdafruitHumid bleHumid; BLEAdafruitProximity bleProximity; BLEAdafruitQuaternion bleQuater; @@ -149,6 +150,28 @@ uint16_t measure_color(uint8_t* buf, uint16_t bufsize) return sizeof(rgb); } + + +void gesture_enable_callback(uint16_t conn_hdl, bool enabled) +{ + (void) conn_hdl; + apds9960.enableProximity(enabled); + apds9960.enableGesture(enabled); +} + +uint16_t measure_gesture(uint8_t* buf, uint16_t bufsize) +{ + uint8_t gesture = apds9960.readGesture(); + if (gesture == 0) return 0; // skip no gesture value + + // APDS9960 sensor position is rotated 90 degree left on CLUE + // We will need to correct that by rotating right for user convenience + uint8_t const clue_rotation[] = { 0, APDS9960_LEFT, APDS9960_RIGHT, APDS9960_DOWN, APDS9960_UP }; + buf[0] = clue_rotation[gesture]; + + return 1; +} + void proximity_enable_callback(uint16_t conn_hdl, bool enabled) { (void) conn_hdl; @@ -350,6 +373,10 @@ void setup() bleColor.begin(measure_color, 100); bleColor.setNotifyCallback(color_enable_callback); + bleGesture.begin(measure_gesture, 10); // sampling is 10 ms + bleGesture.setPeriod(0); // notify on changes only + bleGesture.setNotifyCallback(gesture_enable_callback); + bleHumid.begin(measure_humid, 100); bleLight.begin(measure_light, 100);; From 7c700435b6c0fa04415e0535533102caa59a58e8 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Mar 2020 21:59:29 +0700 Subject: [PATCH 13/19] better allocate neopixel service data --- .../src/services/BLEAdafruitAddressablePixel.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp index 4501f546..93ea634b 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp @@ -109,9 +109,7 @@ err_t BLEAdafruitAddressablePixel::begin(uint8_t pin, uint8_t type, uint16_t buf // Add Characteristic _data.setProperties(CHR_PROPS_WRITE); _data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN); - // Change to use VLOC STACK to USER due to lack of memroy - // Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH)); - _data.setMaxLen(BLE_GATTS_VAR_ATTR_LEN_MAX); + _data.setMaxLen(3 + bufsize); // start (2 byte) + flags (1 byte) VERIFY_STATUS( _data.begin() ); // Add Characteristic From 2d9c7036baabd7289cab9dd3403f3ab292bbdc55 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Mar 2020 23:10:58 +0700 Subject: [PATCH 14/19] enhance neopixel service hardcode pixel to 10 even for CLUE to prevent invalid len write to data --- .../services/BLEAdafruitAddressablePixel.cpp | 36 ++++++++++++------- .../services/BLEAdafruitAddressablePixel.h | 2 ++ variants/clue_nrf52840/variant.h | 2 +- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp index 93ea634b..750a16f0 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp @@ -109,7 +109,9 @@ err_t BLEAdafruitAddressablePixel::begin(uint8_t pin, uint8_t type, uint16_t buf // Add Characteristic _data.setProperties(CHR_PROPS_WRITE); _data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN); - _data.setMaxLen(3 + bufsize); // start (2 byte) + flags (1 byte) + // start (2 byte) + flags (1 byte) + // TODO: for backward compatible with current CPB app, force to at least 10 pixels + _data.setMaxLen(3 + 30 /* bufsize */); VERIFY_STATUS( _data.begin() ); // Add Characteristic @@ -124,28 +126,36 @@ err_t BLEAdafruitAddressablePixel::begin(uint8_t pin, uint8_t type, uint16_t buf return ERROR_NONE; } -//--------------------------------------------------------------------+ -// Static callbacks -//--------------------------------------------------------------------+ -void BLEAdafruitAddressablePixel::pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len) +void BLEAdafruitAddressablePixel::_pixel_write_handler(uint16_t conn_hdl, uint8_t* data, uint16_t len) { (void) conn_hdl; if (len < 3) return; - BLEAdafruitAddressablePixel& svc = (BLEAdafruitAddressablePixel&) chr->parentService(); - uint16_t index; memcpy(&index, data, 2); uint8_t flag = data[2]; - uint8_t* buffer = svc._neo->getPixels() + index; + // pixel staring buffer + uint8_t* pixbuf = _neo->getPixels() + index; - memcpy(buffer, data+3, len-3); + // limit copied bytes up to strip's boundary + uint16_t copied_count = max16(_bufsize.read16(), index) - index; + copied_count = min16(len-3, copied_count); + + PRINT_INT(copied_count); + + if (copied_count) memcpy(pixbuf, data+3, copied_count); // show flag - if ( flag & 0x01 ) - { - svc._neo->show(); - } + if ( flag & 0x01 ) _neo->show(); +} + +//--------------------------------------------------------------------+ +// Static callbacks +//--------------------------------------------------------------------+ +void BLEAdafruitAddressablePixel::pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len) +{ + BLEAdafruitAddressablePixel& svc = (BLEAdafruitAddressablePixel&) chr->parentService(); + svc._pixel_write_handler(conn_hdl, data, len); } diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h index 3165967a..a559b749 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h @@ -49,6 +49,8 @@ class BLEAdafruitAddressablePixel : public BLEService err_t begin(uint8_t pin, uint8_t type, uint16_t bufsize); + void _pixel_write_handler(uint16_t conn_hdl, uint8_t* data, uint16_t len); + static void pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len); }; diff --git a/variants/clue_nrf52840/variant.h b/variants/clue_nrf52840/variant.h index 39209752..7924b3ba 100644 --- a/variants/clue_nrf52840/variant.h +++ b/variants/clue_nrf52840/variant.h @@ -42,8 +42,8 @@ extern "C" // LEDs #define PIN_LED1 (17) -#define PIN_NEOPIXEL (18) #define PIN_LED2 (43) // dual white LEDs +#define PIN_NEOPIXEL (18) #define LED_BUILTIN PIN_LED1 From efda9cbf25674a7f55fcab0024713962ab5ebc4b Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Mar 2020 23:17:14 +0700 Subject: [PATCH 15/19] clean up debug code --- .../src/services/BLEAdafruitAddressablePixel.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp index 750a16f0..2ab9b410 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp @@ -143,8 +143,6 @@ void BLEAdafruitAddressablePixel::_pixel_write_handler(uint16_t conn_hdl, uint8_ uint16_t copied_count = max16(_bufsize.read16(), index) - index; copied_count = min16(len-3, copied_count); - PRINT_INT(copied_count); - if (copied_count) memcpy(pixbuf, data+3, copied_count); // show flag From f00e7cb26977ca0aac0fa73568b9ea5b3c5d28e5 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Mar 2020 23:40:28 +0700 Subject: [PATCH 16/19] fix ci build script --- .github/workflows/githubci.yml | 2 +- tools/build_all.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 497a5e81..9b1980a4 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - arduino-platform: ['feather52832', 'feather52840', 'feather52840sense', 'cplaynrf52840', 'itsybitsy52840', 'cluenrf52840' ] + arduino-platform: ['cluenrf52840', 'cplaynrf52840', 'feather52832', 'feather52840', 'feather52840sense', 'itsybitsy52840'] runs-on: ubuntu-latest diff --git a/tools/build_all.py b/tools/build_all.py index 390cb807..637269c1 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -13,7 +13,7 @@ skip_count = 0 build_format = '| {:20} | {:35} | {:9} ' build_separator = '-' * 83 -default_boards = [ 'feather52832', 'feather52840', 'cplaynrf52840', 'itsybitsy52840', 'cluenrf52840' ] +default_boards = [ 'cluenrf52840', 'cplaynrf52840', 'feather52832', 'feather52840', 'feather52840sense', 'itsybitsy52840' ] build_boards = [] @@ -44,7 +44,7 @@ def build_examples(variant): fqbn = "adafruit:nrf52:{}:softdevice={},debug=l0".format(variant, 's140v6' if variant != 'feather52832' else 's132v6') - for sketch in glob.iglob('libraries/**/*.ino', recursive=True): + for sketch in glob.iglob('libraries/**/bluefruit_playground.ino', recursive=True): start_time = time.monotonic() # Skip if contains: ".board.test.skip" or ".all.test.skip" @@ -52,7 +52,7 @@ def build_examples(variant): sketchdir = os.path.dirname(sketch) if os.path.exists(sketchdir + '/.all.test.skip') or os.path.exists(sketchdir + '/.' + variant + '.test.skip'): success = "\033[33mskipped\033[0m " - elif glob.glob(sketchdir+"/.*.test.only") and not os.path.exists(sketchdir + '/.build.' + variant + '.test.only'): + elif glob.glob(sketchdir+"/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only'): success = "\033[33mskipped\033[0m " else: # TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR. From 6922db93bba594e2633cde8cfd5ebbc75e818312 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Mar 2020 23:51:56 +0700 Subject: [PATCH 17/19] try fixing ci --- .github/workflows/githubci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 9b1980a4..3ada8574 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -52,8 +52,8 @@ jobs: rm -r $HOME/$BSP_PATH/* ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION # Install library dependency - arduino-cli lib install "Adafruit GFX Library" "Adafruit SSD1306" "Adafruit ILI9341" "Adafruit HX8357 Library" "Adafruit ST7735 and ST7789 Library" "Adafruit EPD" - arduino-cli lib install "Adafruit Circuit Playground" "Adafruit NeoPixel" "Adafruit NeoMatrix" "MIDI Library" "Firmata" + arduino-cli lib install "Adafruit AHRS" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit Sensor Calibration" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" + arduino-cli lib install "MIDI Library" "Firmata" "SdFat - Adafruit Fork" - name: Build examples run: python3 tools/build_all.py ${{ matrix.arduino-platform }} From 82de26420eb60bf5527e7e93d4a358307cc2b6a5 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 12 Mar 2020 00:01:07 +0700 Subject: [PATCH 18/19] fixing ci --- .github/workflows/githubci.yml | 3 +-- .../Peripheral/bluefruit_playground/bluefruit_playground.ino | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 3ada8574..e3542f9c 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -52,8 +52,7 @@ jobs: rm -r $HOME/$BSP_PATH/* ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION # Install library dependency - arduino-cli lib install "Adafruit AHRS" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit Sensor Calibration" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" - arduino-cli lib install "MIDI Library" "Firmata" "SdFat - Adafruit Fork" + arduino-cli lib install "Adafruit AHRS" "Adafruit APDS9960 Library" "Adafruit BMP280 Library" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit LIS3MDL" "Adafruit LSM6DS" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit Sensor Calibration" "Adafruit SHT31 Library" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" "Firmata" "MIDI Library" "SdFat - Adafruit Fork" - name: Build examples run: python3 tools/build_all.py ${{ matrix.arduino-platform }} diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index c346cf26..35dcf622 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -66,9 +66,9 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) #elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE) #include -#include -#include #include +#include +#include #include #include From 062a4d9f50d0161fd2374a3d22c31348cb30a9c4 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 12 Mar 2020 00:05:32 +0700 Subject: [PATCH 19/19] ci re-enable all examples --- tools/build_all.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_all.py b/tools/build_all.py index 637269c1..62f46757 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -44,7 +44,7 @@ def build_examples(variant): fqbn = "adafruit:nrf52:{}:softdevice={},debug=l0".format(variant, 's140v6' if variant != 'feather52832' else 's132v6') - for sketch in glob.iglob('libraries/**/bluefruit_playground.ino', recursive=True): + for sketch in glob.iglob('libraries/**/*.ino', recursive=True): start_time = time.monotonic() # Skip if contains: ".board.test.skip" or ".all.test.skip"