Skip to content

Commit 8a402ab

Browse files
committed
added gesture sensor, however attr memory is overflow
1 parent 6bb7576 commit 8a402ab

File tree

7 files changed

+133
-2
lines changed

7 files changed

+133
-2
lines changed

cores/nRF5/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void loop_task(void* arg)
4646

4747
#if CFG_DEBUG
4848
// If Serial is not begin(), call it to avoid hard fault
49-
if ( !Serial ) Serial.begin(115200);
49+
Serial.begin(115200);
5050

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

libraries/BLEAdafruitService/src/BLEAdafruitService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "services/BLEAdafruitBaro.h"
3636
#include "services/BLEAdafruitButton.h"
3737
#include "services/BLEAdafruitColor.h"
38+
#include "services/BLEAdafruitGesture.h"
3839
#include "services/BLEAdafruitGyro.h"
3940
#include "services/BLEAdafruitHumid.h"
4041
#include "services/BLEAdafruitLightSensor.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_ */

libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ err_t BLEAdafruitSensor::_begin(int32_t ms)
4242
VERIFY_STATUS( BLEService::begin() );
4343

4444
_measurement.setCccdWriteCallback(sensor_data_cccd_cb, true);
45-
4645
VERIFY_STATUS( _measurement.begin() );
46+
_measurement.write32(0); // zero 4 bytes could help to init some services
4747

4848
_period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
4949
_period.setPermission(SECMODE_OPEN, SECMODE_OPEN);

libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.feather52840sense.test.only

Whitespace-only changes.

libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
8585

8686
BLEAdafruitBaro bleBaro;
8787
BLEAdafruitColor bleColor;
88+
BLEAdafruitGesture bleGesture;
8889
BLEAdafruitHumid bleHumid;
8990
BLEAdafruitProximity bleProximity;
9091
BLEAdafruitQuaternion bleQuater;
@@ -149,6 +150,28 @@ uint16_t measure_color(uint8_t* buf, uint16_t bufsize)
149150
return sizeof(rgb);
150151
}
151152

153+
154+
155+
void gesture_enable_callback(uint16_t conn_hdl, bool enabled)
156+
{
157+
(void) conn_hdl;
158+
apds9960.enableProximity(enabled);
159+
apds9960.enableGesture(enabled);
160+
}
161+
162+
uint16_t measure_gesture(uint8_t* buf, uint16_t bufsize)
163+
{
164+
uint8_t gesture = apds9960.readGesture();
165+
if (gesture == 0) return 0; // skip no gesture value
166+
167+
// APDS9960 sensor position is rotated 90 degree left on CLUE
168+
// We will need to correct that by rotating right for user convenience
169+
uint8_t const clue_rotation[] = { 0, APDS9960_LEFT, APDS9960_RIGHT, APDS9960_DOWN, APDS9960_UP };
170+
buf[0] = clue_rotation[gesture];
171+
172+
return 1;
173+
}
174+
152175
void proximity_enable_callback(uint16_t conn_hdl, bool enabled)
153176
{
154177
(void) conn_hdl;
@@ -350,6 +373,10 @@ void setup()
350373
bleColor.begin(measure_color, 100);
351374
bleColor.setNotifyCallback(color_enable_callback);
352375

376+
bleGesture.begin(measure_gesture, 10); // sampling is 10 ms
377+
bleGesture.setPeriod(0); // notify on changes only
378+
bleGesture.setNotifyCallback(gesture_enable_callback);
379+
353380
bleHumid.begin(measure_humid, 100);
354381

355382
bleLight.begin(measure_light, 100);;

0 commit comments

Comments
 (0)