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
+
0 commit comments