forked from legonigel/wii-drone-on
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiimote.py
66 lines (61 loc) · 1.44 KB
/
wiimote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /usr/bin/python
import cwiid
import time
class InputWiimote(object):
def makeConnection(self):
print "Press 1 + 2 on the wiimote yo"
try:
wm = cwiid.Wiimote()
except RuntimeError:
wm = None
else:
wm.led = 1
wm.enable(cwiid.FLAG_MOTIONPLUS)
wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_MOTIONPLUS
print "you be connected"
self.wm = wm
return wm
def determine(self):
command = ""
if not self.wm:
return command
if self.wm.state['buttons'] & cwiid.BTN_PLUS:
#takeoff
command = "takeoff"
if self.wm.state['buttons'] & cwiid.BTN_MINUS:
#land
command = "land"
if self.wm.state['buttons'] & cwiid.BTN_HOME:
#panic and stop
command = "kill"
if self.wm.state['buttons'] & cwiid.BTN_B:
#flip
command = "flip"
if self.wm.state['buttons'] & cwiid.BTN_UP:
#foward
command = "forward"
if self.wm.state['buttons'] & cwiid.BTN_DOWN:
#back
command = "backward"
if self.wm.state['buttons'] & cwiid.BTN_LEFT:
#left
command = "left"
if self.wm.state['buttons'] & cwiid.BTN_RIGHT:
#right
command = "right"
if self.wm.state['buttons'] & cwiid.BTN_1:
#elevate
command = "up"
if self.wm.state['buttons'] & cwiid.BTN_2:
#lower
command = "down"
time.sleep(0.1)
return command
def main():
myInput = InputWiimote()
wiimote = myInput.makeConnection()
while True:
wiimote.led = (wiimote.state['led'] + 1) % 16
print myInput.determine()
if __name__ == "__main__":
main()