Skip to content

Commit 70ff084

Browse files
authored
Merge pull request #452 from adafruit/add-sound-service
Add more sensor services
2 parents 569b9b2 + 062a4d9 commit 70ff084

25 files changed

+701
-79
lines changed

.github/workflows/githubci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
arduino-platform: ['feather52832', 'feather52840', 'feather52840sense', 'cplaynrf52840', 'itsybitsy52840', 'cluenrf52840' ]
10+
arduino-platform: ['cluenrf52840', 'cplaynrf52840', 'feather52832', 'feather52840', 'feather52840sense', 'itsybitsy52840']
1111

1212
runs-on: ubuntu-latest
1313

@@ -52,8 +52,7 @@ jobs:
5252
rm -r $HOME/$BSP_PATH/*
5353
ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION
5454
# Install library dependency
55-
arduino-cli lib install "Adafruit GFX Library" "Adafruit SSD1306" "Adafruit ILI9341" "Adafruit HX8357 Library" "Adafruit ST7735 and ST7789 Library" "Adafruit EPD"
56-
arduino-cli lib install "Adafruit Circuit Playground" "Adafruit NeoPixel" "Adafruit NeoMatrix" "MIDI Library" "Firmata"
55+
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"
5756
5857
- name: Build examples
5958
run: python3 tools/build_all.py ${{ matrix.arduino-platform }}

cores/nRF5/main.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ static void loop_task(void* arg)
4444
{
4545
(void) arg;
4646

47-
setup();
48-
4947
#if CFG_DEBUG
5048
// If Serial is not begin(), call it to avoid hard fault
51-
if ( !Serial ) Serial.begin(115200);
49+
Serial.begin(115200);
50+
51+
// Wait for Serial connection in debug mode
52+
while ( !Serial ) yield();
53+
5254
dbgPrintVersion();
53-
// dbgMemInfo();
55+
#endif
56+
57+
setup();
58+
59+
#if CFG_DEBUG
5460
Bluefruit_printInfo();
5561
#endif
5662

libraries/BLEAdafruitService/src/BLEAdafruitService.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@
3434
#include "services/BLEAdafruitAddressablePixel.h"
3535
#include "services/BLEAdafruitBaro.h"
3636
#include "services/BLEAdafruitButton.h"
37+
#include "services/BLEAdafruitColor.h"
38+
#include "services/BLEAdafruitGesture.h"
3739
#include "services/BLEAdafruitGyro.h"
3840
#include "services/BLEAdafruitHumid.h"
3941
#include "services/BLEAdafruitLightSensor.h"
4042
#include "services/BLEAdafruitMagnetic.h"
43+
#include "services/BLEAdafruitProximity.h"
4144
#include "services/BLEAdafruitQuaternion.h"
45+
#include "services/BLEAdafruitSound.h"
4246
#include "services/BLEAdafruitTemperature.h"
4347
#include "services/BLEAdafruitTone.h"
4448

libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ err_t BLEAdafruitAddressablePixel::begin(uint8_t pin, uint8_t type, uint16_t buf
109109
// Add Characteristic
110110
_data.setProperties(CHR_PROPS_WRITE);
111111
_data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN);
112-
// Change to use VLOC STACK to USER due to lack of memroy
113-
// Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH));
114-
_data.setMaxLen(BLE_GATTS_VAR_ATTR_LEN_MAX);
112+
// start (2 byte) + flags (1 byte)
113+
// TODO: for backward compatible with current CPB app, force to at least 10 pixels
114+
_data.setMaxLen(3 + 30 /* bufsize */);
115115
VERIFY_STATUS( _data.begin() );
116116

117117
// Add Characteristic
@@ -126,28 +126,34 @@ err_t BLEAdafruitAddressablePixel::begin(uint8_t pin, uint8_t type, uint16_t buf
126126
return ERROR_NONE;
127127
}
128128

129-
//--------------------------------------------------------------------+
130-
// Static callbacks
131-
//--------------------------------------------------------------------+
132-
void BLEAdafruitAddressablePixel::pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
129+
void BLEAdafruitAddressablePixel::_pixel_write_handler(uint16_t conn_hdl, uint8_t* data, uint16_t len)
133130
{
134131
(void) conn_hdl;
135132

136133
if (len < 3) return;
137134

138-
BLEAdafruitAddressablePixel& svc = (BLEAdafruitAddressablePixel&) chr->parentService();
139-
140135
uint16_t index;
141136
memcpy(&index, data, 2);
142137
uint8_t flag = data[2];
143138

144-
uint8_t* buffer = svc._neo->getPixels() + index;
139+
// pixel staring buffer
140+
uint8_t* pixbuf = _neo->getPixels() + index;
145141

146-
memcpy(buffer, data+3, len-3);
142+
// limit copied bytes up to strip's boundary
143+
uint16_t copied_count = max16(_bufsize.read16(), index) - index;
144+
copied_count = min16(len-3, copied_count);
145+
146+
if (copied_count) memcpy(pixbuf, data+3, copied_count);
147147

148148
// show flag
149-
if ( flag & 0x01 )
150-
{
151-
svc._neo->show();
152-
}
149+
if ( flag & 0x01 ) _neo->show();
150+
}
151+
152+
//--------------------------------------------------------------------+
153+
// Static callbacks
154+
//--------------------------------------------------------------------+
155+
void BLEAdafruitAddressablePixel::pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
156+
{
157+
BLEAdafruitAddressablePixel& svc = (BLEAdafruitAddressablePixel&) chr->parentService();
158+
svc._pixel_write_handler(conn_hdl, data, len);
153159
}

libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class BLEAdafruitAddressablePixel : public BLEService
4949

5050
err_t begin(uint8_t pin, uint8_t type, uint16_t bufsize);
5151

52+
void _pixel_write_handler(uint16_t conn_hdl, uint8_t* data, uint16_t len);
53+
5254
static void pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
5355
};
5456

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "BLEAdafruitService.h"
26+
27+
//--------------------------------------------------------------------+
28+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
29+
//--------------------------------------------------------------------+
30+
31+
32+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
33+
* ADAFxxx-C332-42A8-93BD-25E905756CB8
34+
*
35+
* Shared Characteristics
36+
* - Measurement Period 0001 | int32_t | Read + Write |
37+
* ms between measurements, -1: stop reading, 0: update when changes
38+
*
39+
* Color service 0A00
40+
* - Color 0A01 | uint16_t[3] | Read + Notify | Red, Green, Blue each is 16-bit color
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitColor::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0A, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitColor::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0A, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitColor::BLEAdafruitColor(void)
58+
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
59+
{
60+
// Setup Measurement Characteristic
61+
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
62+
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
63+
_measurement.setFixedLen(2*3);
64+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef BLEADAFRUIT_COLOR_H_
26+
#define BLEADAFRUIT_COLOR_H_
27+
28+
class BLEAdafruitColor : public BLEAdafruitSensor
29+
{
30+
public:
31+
static const uint8_t UUID128_SERVICE[16];
32+
static const uint8_t UUID128_CHR_DATA[16];
33+
34+
BLEAdafruitColor(void);
35+
36+
using BLEAdafruitSensor::begin;
37+
};
38+
39+
#endif /* BLEADAFRUIT_COLOR_H_ */
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "BLEAdafruitService.h"
26+
27+
//--------------------------------------------------------------------+
28+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
29+
//--------------------------------------------------------------------+
30+
31+
32+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
33+
* ADAFxxx-C332-42A8-93BD-25E905756CB8
34+
*
35+
* Shared Characteristics
36+
* - Measurement Period 0001 | int32_t | Read + Write |
37+
* ms between measurements, -1: stop reading, 0: update when changes
38+
*
39+
* Gesture service 06F00
40+
* - Button 0F01 | unt8_t | Read + Notify | e.g 0: no gesture, 1: Up, 2: Down, 3: Left, 4: Right
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitGesture::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0F, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitGesture::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0F, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitGesture::BLEAdafruitGesture(void)
58+
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
59+
{
60+
// Setup Measurement Characteristic
61+
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
62+
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
63+
_measurement.setFixedLen(1);
64+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef BLEADAFRUIT_GESTURE_H_
26+
#define BLEADAFRUIT_GESTURE_H_
27+
28+
class BLEAdafruitGesture : public BLEAdafruitSensor
29+
{
30+
public:
31+
static const uint8_t UUID128_SERVICE[16];
32+
static const uint8_t UUID128_CHR_DATA[16];
33+
34+
BLEAdafruitGesture(void);
35+
36+
using BLEAdafruitSensor::begin;
37+
};
38+
39+
#endif /* BLEADAFRUIT_GESTURE_H_ */

0 commit comments

Comments
 (0)