summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2008-05-16 13:52:14 +0200
committerGuillaume Seguin <guillaume@segu.in>2008-05-16 13:52:14 +0200
commitc5d1920ea143f1353934bfe73a2b24f2998ccb2b (patch)
tree38a34e9f6f11fea1c1e64e5b927cc3706c05169f
parent4d8ea4eb956d1f4629116c1d05e55737bfdb33c1 (diff)
downloadkuwii-c5d1920ea143f1353934bfe73a2b24f2998ccb2b.tar.gz
kuwii-c5d1920ea143f1353934bfe73a2b24f2998ccb2b.tar.bz2
Add leds support
-rw-r--r--kuwii/wiimote.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/kuwii/wiimote.py b/kuwii/wiimote.py
index 340c8a3..0ae78ee 100644
--- a/kuwii/wiimote.py
+++ b/kuwii/wiimote.py
@@ -1,7 +1,44 @@
import Queue
import thread
+import time
from bluetooth import BluetoothSocket, L2CAP, BluetoothError
from constants import *
+from misc import *
+
+class WiiMoteLeds:
+
+ state = [0, 0, 0, 0]
+
+ def __init__(self, wiimote):
+ self.wiimote = wiimote
+
+ def sync (self):
+ command_start = 0x521100
+ command_end = 0x00
+
+ for i in range(4):
+ if self.state[i]:
+ command_end += 2**i * 0x10
+
+ command = hex (command_start + command_end)
+ cmd = command[2:].decode("hex")
+
+ self.wiimote.fdout.send (cmd)
+
+ def toggle (self, *args):
+ for led in args:
+ self.state[led] = (self.state[led] + 1) % 2
+ self.sync ()
+
+ def on (self, *args):
+ for led in args:
+ if not self.state[led]:
+ self.toggle (led)
+
+ def off (self, *args):
+ for led in args:
+ if self.state[led]:
+ self.toggle (led)
class WiiMote:
@@ -49,6 +86,7 @@ class WiiMote:
self.bits = 0
self.rumble = False
self.speaker = False
+ self.leds = WiiMoteLeds (self)
# create the event queue
self.events = Queue.Queue()
@@ -110,6 +148,8 @@ class WiiMote:
self.fdin.settimeout(0.1)
+ self.leds.sync ()
+
while self.connected == 1:
try:
msg = self.fdin.recv(23)