Skip to content

Commit

Permalink
Merge pull request #452 from adafruit/add-sound-service
Browse files Browse the repository at this point in the history
Add more sensor services
  • Loading branch information
ladyada authored Mar 11, 2020
2 parents 569b9b2 + 062a4d9 commit 70ff084
Show file tree
Hide file tree
Showing 25 changed files with 701 additions and 79 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 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 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 }}
14 changes: 10 additions & 4 deletions cores/nRF5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Serial.begin(115200);

// Wait for Serial connection in debug mode
while ( !Serial ) yield();

dbgPrintVersion();
// dbgMemInfo();
#endif

setup();

#if CFG_DEBUG
Bluefruit_printInfo();
#endif

Expand Down
4 changes: 4 additions & 0 deletions libraries/BLEAdafruitService/src/BLEAdafruitService.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@
#include "services/BLEAdafruitAddressablePixel.h"
#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"
#include "services/BLEAdafruitMagnetic.h"
#include "services/BLEAdafruitProximity.h"
#include "services/BLEAdafruitQuaternion.h"
#include "services/BLEAdafruitSound.h"
#include "services/BLEAdafruitTemperature.h"
#include "services/BLEAdafruitTone.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +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);
// 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);
// 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
Expand All @@ -126,28 +126,34 @@ 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);

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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
64 changes: 64 additions & 0 deletions libraries/BLEAdafruitService/src/services/BLEAdafruitColor.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
39 changes: 39 additions & 0 deletions libraries/BLEAdafruitService/src/services/BLEAdafruitColor.h
Original file line number Diff line number Diff line change
@@ -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_ */
64 changes: 64 additions & 0 deletions libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
39 changes: 39 additions & 0 deletions libraries/BLEAdafruitService/src/services/BLEAdafruitGesture.h
Original file line number Diff line number Diff line change
@@ -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_ */
Loading

0 comments on commit 70ff084

Please sign in to comment.