Skip to content

Commit 8c33072

Browse files
committed
v1.0 Library & Example file
1 parent 8a7ae73 commit 8c33072

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed

Diff for: Hover_example.py

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# ===========================================================================
2+
# This is an example for Hover.
3+
#
4+
# Hover is a development kit that lets you control your hardware projects in a whole new way.
5+
# Wave goodbye to physical buttons. Hover detects hand movements in the air for touch-less interaction.
6+
# It also features five touch-sensitive regions for even more options.
7+
# Hover uses I2C and 2 digital pins. It is compatible with Arduino, Raspberry Pi and more.
8+
#
9+
# Hover can be purchased here: http://www.justhover.com
10+
#
11+
# Written by Emran Mahbub and Jonathan Li for Gearseven Studios.
12+
# BSD license, all text above must be included in any redistribution
13+
# ===========================================================================
14+
#
15+
# HOOKUP GUIDE (For Raspberry Pi)
16+
#
17+
# =============================
18+
# | 1 2 3 4 5 6 7 |
19+
# | HOVER |
20+
# | |
21+
# | +++++++++++++++++++++++++++ |
22+
# | + + |
23+
# | + + |
24+
# | * + |
25+
# | * + |
26+
# | * + |
27+
# |_+++++++++++++++++++++++++++_|
28+
#
29+
# PIN 1 - HOST_V+ ---- 3V3 pin
30+
# PIN 2 - RESET ---- Any Digital Pin. This example uses GPIO 24 (BCM Mode).
31+
# PIN 3 - SCL ---- SCL pin
32+
# PIN 4 - SDA ---- SDA pin
33+
# PIN 5 - GND ---- Ground Pin
34+
# PIN 6 - 3V3 ---- 3V3 pin
35+
# PIN 7 - TS ---- Any Digital Pin. This example uses GPIO 23 (BCM Mode).
36+
#
37+
# =============================================================================
38+
#
39+
# OUTPUT DEFINITION
40+
# The message variable outputs an 8-bit binary value to indicate the event type, gesture direction, and tap location.
41+
# Upper 3 bits indicates the event type: gesture or tap.
42+
# Lower 5 bits indicates the gesture direction or tap location.
43+
#
44+
# EVENT TYPE DIRECTION
45+
# 000 00000
46+
# ---------------------------------------------------------
47+
# GESTURES DIRECTION FOR GESTURE
48+
# 001 00010 - Right Swipe
49+
# 00100 - Left Swipe
50+
# 01000 - Up Swipe
51+
# 10000 - Down Swipe
52+
#
53+
# TAP DIRECTION FOR TAP
54+
# 010 00001 - South Tap
55+
# 00010 - West Tap
56+
# 00100 - North Tap
57+
# 01000 - East Tap
58+
# 10000 - Center Tap
59+
# ----------------------------------------------------------
60+
#
61+
# HISTORY
62+
# v1.0 - Initial Release
63+
#
64+
# INSTALLATION
65+
# Place the Hover_library.py file in the same folder as the Hover_example.py file.
66+
# Then run Hover_example.py by typing: sudo python Hover_example.py
67+
#
68+
# SUPPORT
69+
# For questions and comments, email us at [email protected]
70+
#
71+
# ============================================================================================================
72+
73+
74+
import time
75+
from Hover_library import Hover
76+
77+
hover = Hover(address=0x42, ts=23, reset=24)
78+
79+
try:
80+
while True:
81+
82+
# Check if hover is ready to send gesture or touch events
83+
if (hover.getStatus() == 0):
84+
85+
# Read i2c data and print the type of gesture or touch event
86+
event = hover.getEvent()
87+
88+
if event is not None:
89+
print event,
90+
print "= " + hover.getEventString(event) #This line can be commented out if you don't want to see the event in text format
91+
92+
# Release the ts pin until Hover is ready to send the next event
93+
hover.setRelease()
94+
time.sleep(0.001) #sleep for 1ms
95+
96+
except KeyboardInterrupt:
97+
print "Exiting..."
98+
hover.end()
99+
100+
except:
101+
print "Something has gone wrong...:("
102+
hover.end()

Diff for: Hover_library.py

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# ===========================================================================
2+
# This is the library for Hover.
3+
#
4+
# Hover is a development kit that lets you control your hardware projects in a whole new way.
5+
# Wave goodbye to physical buttons. Hover detects hand movements in the air for touch-less interaction.
6+
# It also features five touch-sensitive regions for even more options.
7+
# Hover uses I2C and 2 digital pins. It is compatible with Arduino, Raspberry Pi and more.
8+
#
9+
# Hover can be purchased here: http://www.justhover.com
10+
#
11+
# Written by Emran Mahbub and Jonathan Li for Gearseven Studios.
12+
# BSD license, all text above must be included in any redistribution
13+
# ===========================================================================
14+
#
15+
# INSTALLATION
16+
# Place the Hover_library.py file in the same folder as the Hover_example.py file.
17+
# Then run Hover_example.py by typing: sudo python Hover_example.py
18+
#
19+
# SUPPORT
20+
# For questions and comments, email us at [email protected]
21+
# ===========================================================================
22+
23+
import smbus
24+
import time
25+
26+
#For Raspberry Pi rev1, change this to smbus.SMBus(0). Raspberry Pi rev2 uses smbus.SMBus(1)
27+
bus = smbus.SMBus(1)
28+
29+
dict = {'00100010':'Right Swipe', '00100100':'Left Swipe', '00101000':'Up Swipe', '00110000':'Down Swipe', '01001000':'East Tap', '01000001':'South Tap', '01000010':'West Tap', '01000100':'North Tap', '01010000':'Center Tap'}
30+
31+
class Hover(object):
32+
33+
def __init__(self, address, ts, reset):
34+
print "Initializing Hover...please wait."
35+
self.address = address
36+
self.ts = ts
37+
self.reset = reset
38+
39+
40+
import RPi.GPIO as GPIO
41+
42+
self.GPIO = GPIO
43+
self.GPIO.setmode(GPIO.BCM)
44+
self.GPIO.setup(self.ts, GPIO.IN) #ts
45+
self.GPIO.setup(self.reset, GPIO.OUT) #mclr
46+
self.GPIO.output(self.reset, False)
47+
48+
time.sleep(5)
49+
50+
self.GPIO.output(self.reset, True)
51+
self.GPIO.setup(self.reset, GPIO.IN)
52+
53+
time.sleep(5)
54+
print "Hover is ready! To exit the program, hit Ctrl+C"
55+
56+
57+
def getStatus(self):
58+
59+
if (self.GPIO.input(self.ts)):
60+
return 1
61+
else:
62+
self.GPIO.setup(self.ts, self.GPIO.OUT) #ts
63+
self.GPIO.output(self.ts, self.GPIO.LOW)
64+
return 0
65+
66+
def getEvent(self):
67+
68+
busData = bus.read_i2c_block_data(self.address,0,18)
69+
70+
gestureEvent = busData[10]
71+
touchEvent = (((busData[14] & 0b11100000) >> 5) | ((busData[15] & 0b00000011) << 3))
72+
73+
if gestureEvent > 1:
74+
event = "{:08b}".format((1<<(busData[10]-1)) | 0b00100000)
75+
return event
76+
elif touchEvent > 0:
77+
event = "{:08b}".format(touchEvent | 0b01000000)
78+
return event
79+
80+
81+
def setRelease(self):
82+
83+
self.GPIO.output(self.ts, self.GPIO.HIGH)
84+
self.GPIO.setup(self.ts, self.GPIO.IN) #ts
85+
86+
def end(self):
87+
88+
self.GPIO.cleanup()
89+
90+
def getEventString(self, event):
91+
return dict[event]
92+

Diff for: README.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
hover_raspberrypi
22
=================
3+
4+
Hover is a development kit that lets you control your hardware projects in a whole new way.
5+
Wave goodbye to physical buttons. Hover detects hand movements in the air for touch-less interaction.
6+
It also features five touch-sensitive regions for even more options.
7+
Hover uses I2C and 2 digital pins. It is compatible with Arduino, Raspberry Pi and more.
8+
9+
Hover can be purchased here: http://www.justhover.com
10+
11+
Written by Emran Mahbub and Jonathan Li for Gearseven Studios.
12+
BSD license, all text above must be included in any redistribution

0 commit comments

Comments
 (0)