from socket import WiiSocket
from general import main
import threading
import sys
from PyQt4 import QtGui
import time
class WiiButtons:
buttons = {"Up" : False,
"Down" : False,
"Left" : False,
"Right" : False,
"Plus" : False,
"Minus" : False,
"Home" : False,
"One" : False,
"Two" : False,
"A" : False,
"B" : False
}
def parse(self, data):
if data[:5] != "A1 30":
return
data = data[6:].split()
self.buttons["Left"] = bool(int(data[0],16)&0x01)
self.buttons["Right"] = bool(int(data[0],16)&0x02)
self.buttons["Down"] = bool(int(data[0],16)&0x04)
self.buttons["Up"] = bool(int(data[0],16)&0x08)
self.buttons["Plus"] = bool(int(data[0],16)&0x10)
self.buttons["Minus"] = bool(int(data[1],16)&0x10)
self.buttons["Home"] = bool(int(data[1],16)&0x80)
self.buttons["One"] = bool(int(data[1],16)&0x02)
self.buttons["Two"] = bool(int(data[1],16)&0x01)
self.buttons["A"] = bool(int(data[1],16)&0x08)
self.buttons["B"] = bool(int(data[1],16)&0x04)
def current(self):
return self.buttons
if __name__ == "__main__":
x = 0
y = 0
painter.drawPoint(self.x, self.y)
def get_info(handler, widget):
buttons = WiiButtons()
x = 300
y = 300
while handler.state == True:
data = handler.receive(32)
if len(data):
buttons.parse(data)
if buttons.current()["Up"]:
widget.y -= 1
widget.repaint()
print "Up"
if buttons.current()["Down"]:
widget.y += 1
widget.repaint()
print "Down"
if buttons.current()["Left"]:
widget.x -= 1
widget.repaint()
print "Left"
if buttons.current()["Right"]:
widget.x += 1
widget.repaint()
print "Right"
wiimote = main()
widget = MyWidget()
widget.resize(600, 600)
window.setCentralWidget(widget)
window.show()
thread = threading.Thread(None, get_info, None, (wiimote,widget))
thread.start()
app.exec_()
from socket import WiiSocket
from general import main
import threading
import sys
from PyQt4 import QtGui
import time
class WiiButtons:
buttons = {"Up" : False,
"Down" : False,
"Left" : False,
"Right" : False,
"Plus" : False,
"Minus" : False,
"Home" : False,
"One" : False,
"Two" : False,
"A" : False,
"B" : False
}
def parse(self, data):
if data[:5] != "A1 30":
return
data = data[6:].split()
self.buttons["Left"] = bool(int(data[0],16)&0x01)
self.buttons["Right"] = bool(int(data[0],16)&0x02)
self.buttons["Down"] = bool(int(data[0],16)&0x04)
self.buttons["Up"] = bool(int(data[0],16)&0x08)
self.buttons["Plus"] = bool(int(data[0],16)&0x10)
self.buttons["Minus"] = bool(int(data[1],16)&0x10)
self.buttons["Home"] = bool(int(data[1],16)&0x80)
self.buttons["One"] = bool(int(data[1],16)&0x02)
self.buttons["Two"] = bool(int(data[1],16)&0x01)
self.buttons["A"] = bool(int(data[1],16)&0x08)
self.buttons["B"] = bool(int(data[1],16)&0x04)
def current(self):
return self.buttons
if __name__ == "__main__":
class MyWidget(QtGui.QWidget):
x = 0
y = 0
def paintEvent(self, QPaintEvent):
painter = QtGui.QPainter(self)
painter.drawPoint(self.x, self.y)
def get_info(handler, widget):
buttons = WiiButtons()
x = 300
y = 300
while handler.state == True:
data = handler.receive(32)
if len(data):
buttons.parse(data)
if buttons.current()["Up"]:
widget.y -= 1
widget.repaint()
print "Up"
if buttons.current()["Down"]:
widget.y += 1
widget.repaint()
print "Down"
if buttons.current()["Left"]:
widget.x -= 1
widget.repaint()
print "Left"
if buttons.current()["Right"]:
widget.x += 1
widget.repaint()
print "Right"
wiimote = main()
app = QtGui.QApplication(sys.argv)
widget = MyWidget()
widget.resize(600, 600)
window = QtGui.QMainWindow()
window.setCentralWidget(widget)
window.show()
thread = threading.Thread(None, get_info, None, (wiimote,widget))
thread.start()
app.exec_()
To copy to clipboard, switch view to plain text mode
Bookmarks