Skip to content

Commit 7892782

Browse files
author
Shawn Hymel
committedMay 6, 2015
Removed unused gestures.
·
V_1.0.2V_1.0.0
1 parent f150b9b commit 7892782

File tree

8 files changed

+257
-50
lines changed

8 files changed

+257
-50
lines changed
 

‎examples/I2C_Gesture_Demo/I2C_Gesture_Demo.ino

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ May 6, 2015
66
https://github.com/sparkfun/SparkFun_ZX_Distance_and_Gesture_Sensor_Arduino_Library
77
88
Tests the ZX sensor's ability to read ZX data over I2C. This demo
9-
configures the ZX sensor and periodically polls for gestures.
9+
configures the ZX sensor and periodically polls for gestures. The
10+
gesture is displayed along with its "speed" (how long it takes to
11+
complete the gesture). Note that higher numbers of "speed"
12+
indicate a slower speed.
1013
1114
Hardware Connections:
1215
@@ -40,6 +43,7 @@ const int ZX_ADDR = 0x10; // ZX Sensor I2C address
4043
// Global Variables
4144
ZX_Sensor zx_sensor = ZX_Sensor(ZX_ADDR);
4245
GestureType gesture;
46+
uint8_t gesture_speed;
4347

4448
void setup() {
4549

@@ -50,6 +54,7 @@ void setup() {
5054
Serial.println();
5155
Serial.println("----------------------------------------");
5256
Serial.println("SparkFun/GestureSense - I2C Gesture Demo");
57+
Serial.println("Note: higher 'speed' numbers mean slower");
5358
Serial.println("----------------------------------------");
5459

5560
// Initialize ZX Sensor (configure I2C and read model ID)
@@ -96,30 +101,22 @@ void loop() {
96101
// If there is gesture data available, read and print it
97102
if ( zx_sensor.gestureAvailable() ) {
98103
gesture = zx_sensor.readGesture();
104+
gesture_speed = zx_sensor.readGestureSpeed();
99105
switch ( gesture ) {
100106
case NO_GESTURE:
101107
Serial.println("No Gesture");
102108
break;
103109
case RIGHT_SWIPE:
104-
Serial.println("Right Swipe");
110+
Serial.print("Right Swipe. Speed: ");
111+
Serial.println(gesture_speed, DEC);
105112
break;
106113
case LEFT_SWIPE:
107-
Serial.println("Left Swipe");
114+
Serial.print("Left Swipe. Speed: ");
115+
Serial.println(gesture_speed, DEC);
108116
break;
109117
case UP_SWIPE:
110-
Serial.println("Up Swipe");
111-
break;
112-
case HOVER:
113-
Serial.println("Hover");
114-
break;
115-
case HOVER_LEFT:
116-
Serial.println("Hover-Left");
117-
break;
118-
case HOVER_RIGHT:
119-
Serial.println("Hover-Right");
120-
break;
121-
case HOVER_UP:
122-
Serial.println("Hover-Up");
118+
Serial.print("Up Swipe. Speed: ");
119+
Serial.println(gesture_speed, DEC);
123120
break;
124121
default:
125122
break;

‎examples/I2C_Gesture_Interrupt/I2C_Gesture_Interrupt.ino

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ https://github.com/sparkfun/SparkFun_ZX_Distance_and_Gesture_Sensor_Arduino_Libr
88
Tests the ZX sensor's ability to read gesture data over I2C using
99
an interrupt pin. This program configures I2C and sets up an
1010
interrupt to occur whenever the ZX Sensor throws its DR pin high.
11+
The gesture is displayed along with its "speed" (how long it takes
12+
to complete the gesture). Note that higher numbers of "speed"
13+
indicate a slower speed.
1114
1215
Hardware Connections:
1316
@@ -20,7 +23,7 @@ Hardware Connections:
2023
2 DR Data Ready
2124
2225
Resources:
23-
Include Wire.h and SFE_ZX_Sensor.h
26+
Include Wire.h and ZX_Sensor.h
2427
2528
Development environment specifics:
2629
Written in Arduino 1.6.3
@@ -44,6 +47,7 @@ const int INTERRUPT_NUM = 0; // Pin 2 on the UNO
4447
ZX_Sensor zx_sensor = ZX_Sensor(ZX_ADDR);
4548
volatile GestureType gesture;
4649
volatile bool interrupt_flag;
50+
uint8_t gesture_speed;
4751

4852
void setup() {
4953

@@ -57,6 +61,7 @@ void setup() {
5761
Serial.println();
5862
Serial.println("---------------------------------------------");
5963
Serial.println("SparkFun/GestureSense - I2C Gesture Interrupt");
64+
Serial.println("Note: higher 'speed' numbers mean slower");
6065
Serial.println("---------------------------------------------");
6166

6267
// Initialize ZX Sensor (configure I2C and read model ID)
@@ -116,30 +121,22 @@ void loop() {
116121

117122
// Read last gesture
118123
gesture = zx_sensor.readGesture();
124+
gesture_speed = zx_sensor.readGestureSpeed();
119125
switch ( gesture ) {
120126
case NO_GESTURE:
121127
Serial.println("No Gesture");
122128
break;
123129
case RIGHT_SWIPE:
124-
Serial.println("Right Swipe");
130+
Serial.print("Right Swipe. Speed: ");
131+
Serial.println(gesture_speed, DEC);
125132
break;
126133
case LEFT_SWIPE:
127-
Serial.println("Left Swipe");
134+
Serial.print("Left Swipe. Speed: ");
135+
Serial.println(gesture_speed, DEC);
128136
break;
129137
case UP_SWIPE:
130-
Serial.println("Up Swipe");
131-
break;
132-
case HOVER:
133-
Serial.println("Hover");
134-
break;
135-
case HOVER_LEFT:
136-
Serial.println("Hover-Left");
137-
break;
138-
case HOVER_RIGHT:
139-
Serial.println("Hover-Right");
140-
break;
141-
case HOVER_UP:
142-
Serial.println("Hover-Up");
138+
Serial.print("Up Swipe. Speed: ");
139+
Serial.println(gesture_speed, DEC);
143140
break;
144141
default:
145142
break;

‎examples/I2C_ZX_Demo/I2C_ZX_Demo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Hardware Connections:
1818
A5 CL I2C Clock
1919
2020
Resources:
21-
Include Wire.h and SFE_ZX_Sensor.h
21+
Include Wire.h and ZX_Sensor.h
2222
2323
Development environment specifics:
2424
Written in Arduino 1.6.3

‎examples/I2C_ZX_Interrupt/I2C_ZX_Interrupt.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Hardware Connections:
2020
2 DR Data Ready
2121
2222
Resources:
23-
Include Wire.h and SFE_ZX_Sensor.h
23+
Include Wire.h and ZX_Sensor.h
2424
2525
Development environment specifics:
2626
Written in Arduino 1.6.3
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/****************************************************************
2+
UART_Gesture_Demo.ino
3+
XYZ Interactive ZX Sensor
4+
Shawn Hymel @ SparkFun Electronics
5+
May 6, 2015
6+
https://github.com/sparkfun/SparkFun_ZX_Distance_and_Gesture_Sensor_Arduino_Library
7+
8+
Tests the ZX sensor's ability to read gesture data over UART using
9+
SoftwareSerial. The ZX_Sensor library is needed for the
10+
UART constants. As a result, we have to link the Wire library,
11+
even though it is not used.
12+
13+
Hardware Connections:
14+
15+
Arduino Pin ZX Sensor Board Function
16+
---------------------------------------
17+
5V VCC Power
18+
GND GND Ground
19+
10 TX Data
20+
21+
Resources:
22+
Include SoftwareSerial.h, Wire.h, and ZX_Constants.h
23+
24+
Development environment specifics:
25+
Written in Arduino 1.6.3
26+
Tested with a SparkFun RedBoard
27+
28+
This code is beerware; if you see me (or any other SparkFun
29+
employee) at the local, and you've found our code helpful, please
30+
buy us a round!
31+
32+
Distributed as-is; no warranty is given.
33+
****************************************************************/
34+
35+
#include <SoftwareSerial.h>
36+
#include <Wire.h>
37+
#include <ZX_Sensor.h>
38+
39+
// Global Variables
40+
SoftwareSerial soft_serial(10, 11); // RX, TX
41+
uint8_t c;
42+
43+
void setup() {
44+
45+
// Initialize hardware serial port. Note the baud rate.
46+
Serial.begin(115200);
47+
Serial.println();
48+
Serial.println("-----------------------------------------");
49+
Serial.println("SparkFun/GestureSense - UART Gesture Demo");
50+
Serial.println("Note: higher 'speed' numbers mean slower");
51+
Serial.println("-----------------------------------------");
52+
53+
// Initialize software serial port
54+
soft_serial.begin(115200);
55+
}
56+
57+
void loop() {
58+
59+
// Read in a character from the UART
60+
if ( soft_serial.available() ) {
61+
c = soft_serial.read();
62+
63+
// Determine type of message and print it
64+
switch ( c ) {
65+
case ZX_UART_GESTURE:
66+
67+
// Determine type of gesture
68+
c = soft_serial.read();
69+
switch ( c ) {
70+
case RIGHT_SWIPE:
71+
c = soft_serial.read();
72+
Serial.print("Right Swipe. Speed: ");
73+
Serial.println(c, DEC);
74+
break;
75+
case LEFT_SWIPE:
76+
c = soft_serial.read();
77+
Serial.print("Left Swipe. Speed: ");
78+
Serial.println(c, DEC);
79+
break;
80+
case UP_SWIPE:
81+
c = soft_serial.read();
82+
Serial.print("Up Swipe. Speed: ");
83+
Serial.println(c, DEC);
84+
default:
85+
break;
86+
}
87+
88+
break;
89+
case ZX_UART_ID:
90+
Serial.print("Sensor type: ");
91+
c = soft_serial.read();
92+
Serial.print(c, DEC);
93+
Serial.print(" HW version: ");
94+
c = soft_serial.read();
95+
Serial.print(c, DEC);
96+
Serial.print(" FW version: ");
97+
c = soft_serial.read();
98+
Serial.println(c, DEC);
99+
break;
100+
default:
101+
break;
102+
}
103+
}
104+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/****************************************************************
2+
UART_ZX_Demo.ino
3+
XYZ Interactive ZX Sensor
4+
Shawn Hymel @ SparkFun Electronics
5+
May 6, 2015
6+
https://github.com/sparkfun/SparkFun_ZX_Distance_and_Gesture_Sensor_Arduino_Library
7+
8+
Tests the ZX sensor's ability to read ZX data over UART using
9+
SoftwareSerial. The ZX_Sensor library is needed for the
10+
UART constants. As a result, we have to link the Wire library,
11+
even though it is not used.
12+
13+
Hardware Connections:
14+
15+
Arduino Pin ZX Sensor Board Function
16+
---------------------------------------
17+
5V VCC Power
18+
GND GND Ground
19+
10 TX Data
20+
21+
Resources:
22+
Include SoftwareSerial.h, Wire.h, and ZX_Constants.h
23+
24+
Development environment specifics:
25+
Written in Arduino 1.6.3
26+
Tested with a SparkFun RedBoard
27+
28+
This code is beerware; if you see me (or any other SparkFun
29+
employee) at the local, and you've found our code helpful, please
30+
buy us a round!
31+
32+
Distributed as-is; no warranty is given.
33+
****************************************************************/
34+
35+
#include <SoftwareSerial.h>
36+
#include <Wire.h>
37+
#include <ZX_Sensor.h>
38+
39+
// Global Variables
40+
SoftwareSerial soft_serial(10, 11); // RX, TX
41+
uint8_t c;
42+
43+
void setup() {
44+
45+
// Initialize hardware serial port. Note the baud rate.
46+
Serial.begin(115200);
47+
Serial.println();
48+
Serial.println("------------------------------------");
49+
Serial.println("SparkFun/GestureSense - UART ZX Demo");
50+
Serial.println("------------------------------------");
51+
52+
// Initialize software serial port
53+
soft_serial.begin(115200);
54+
}
55+
56+
void loop() {
57+
58+
// Read in a character from the UART
59+
if ( soft_serial.available() ) {
60+
c = soft_serial.read();
61+
62+
// Determine type of message and print it
63+
switch ( c ) {
64+
case ZX_UART_END:
65+
Serial.println("End of stream");
66+
break;
67+
case ZX_UART_RANGES:
68+
Serial.print("Ranges: ");
69+
c = soft_serial.read();
70+
Serial.print(c, DEC);
71+
Serial.print(", ");
72+
c = soft_serial.read();
73+
Serial.println(c, DEC);
74+
break;
75+
case ZX_UART_X:
76+
Serial.print("X: ");
77+
c = soft_serial.read();
78+
Serial.println(c, DEC);
79+
break;
80+
case ZX_UART_Z:
81+
Serial.print("Z: ");
82+
c = soft_serial.read();
83+
Serial.println(c, DEC);
84+
break;
85+
case ZX_UART_ID:
86+
Serial.print("Sensor type: ");
87+
c = soft_serial.read();
88+
Serial.print(c, DEC);
89+
Serial.print(" HW version: ");
90+
c = soft_serial.read();
91+
Serial.print(c, DEC);
92+
Serial.print(" FW version: ");
93+
c = soft_serial.read();
94+
Serial.println(c, DEC);
95+
break;
96+
default:
97+
break;
98+
}
99+
}
100+
}

‎src/ZX_Sensor.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,6 @@ uint8_t ZX_Sensor::readZ()
331331
* 0x01 Right Swipe
332332
* 0x02 Left Swipe
333333
* 0x03 Up Swipe
334-
* 0x05 Hover
335-
* 0x06 Hover-Left
336-
* 0x07 Hover-Right
337-
* 0x08 Hover-Up
338334
*
339335
* @return a number corresponding to a gesture. 0xFF on error.
340336
*/
@@ -357,19 +353,28 @@ GestureType ZX_Sensor::readGesture()
357353
return LEFT_SWIPE;
358354
case UP_SWIPE:
359355
return UP_SWIPE;
360-
case HOVER:
361-
return HOVER;
362-
case HOVER_LEFT:
363-
return HOVER_LEFT;
364-
case HOVER_RIGHT:
365-
return HOVER_RIGHT;
366-
case HOVER_UP:
367-
return HOVER_UP;
368356
default:
369357
return NO_GESTURE;
370358
}
371359
}
372360

361+
/**
362+
* @brief Reads the speed of the last gesture from the sensor
363+
*
364+
* @return a number corresponding to the speed of the gesture. 0xFF on error.
365+
*/
366+
uint8_t ZX_Sensor::readGestureSpeed()
367+
{
368+
uint8_t speed;
369+
370+
/* Read GESTURE register and return the value */
371+
if ( !wireReadDataByte(ZX_GSPEED, speed) ) {
372+
return ZX_ERROR;
373+
}
374+
375+
return speed;
376+
}
377+
373378
/*******************************************************************************
374379
* Bit Manipulation
375380
******************************************************************************/

‎src/ZX_Sensor.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
#define DRCFG_FORCE 6
5353
#define DRCFG_EN 7
5454

55+
/* ZX Sensor UART message headers */
56+
#define ZX_UART_END 0xFF
57+
#define ZX_UART_RANGES 0xFE
58+
#define ZX_UART_X 0xFA
59+
#define ZX_UART_Z 0xFB
60+
#define ZX_UART_GESTURE 0xFC
61+
#define ZX_UART_ID 0xF1
62+
5563
/* Constants */
5664
#define ZX_ERROR 0xFF
5765
#define MAX_X 240
@@ -63,10 +71,6 @@ typedef enum GestureType {
6371
RIGHT_SWIPE = 0x01,
6472
LEFT_SWIPE = 0x02,
6573
UP_SWIPE = 0x03,
66-
HOVER = 0x05,
67-
HOVER_LEFT = 0x06,
68-
HOVER_RIGHT = 0x07,
69-
HOVER_UP = 0x08,
7074
NO_GESTURE = 0xFF
7175
} GestureType;
7276

0 commit comments

Comments
 (0)
Failed to load comments.