forked from legonigel/wii-drone-on
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiimoteAC.py
36 lines (32 loc) · 901 Bytes
/
wiimoteAC.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
#! /usr/bin/python
import cwiid
import time
class InputWiimoteAC(object):
def makeConnection(self):
print "Press 1 + 2 on the wiimote for Acceleration"
try:
wm = cwiid.Wiimote()
except RuntimeError:
wm = None
else:
wm.led = 2
#wm.enable(cwiid.FLAG_MOTIONPLUS)
wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_ACC
print "you be connected"
self.wm = wm
return wm
def determine(self):
if not self.wm:
return ""
#print "x: " + str(float((wm.state['acc'][0]-125))/30)
#print "y: " + str(float((wm.state['acc'][1]-125))/30)
directions = "lr " + str(float(self.wm.state['acc'][0]-125)/90) + " fb " + str(float(self.wm.state['acc'][1]-125)/-90)
return directions
def main():
myInputAC = InputWiimoteAC()
wiimote = myInputAC.makeConnection()
while True:
wiimote.led = (wiimote.state['led'] + 1) % 16
print myInputAC.determine()
if __name__ == "__main__":
main()