|
|
@ -26,6 +26,8 @@ EXTENSION_8BYTES = 0x32 |
|
|
|
|
|
|
|
|
|
|
|
BUTTON_DOWN_MASK = 8 |
|
|
|
BUTTON_DOWN_MASK = 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BATTERY_MAX = 0xD0 # Taken from cwiid source |
|
|
|
|
|
|
|
|
|
|
|
TOP_RIGHT = 0 |
|
|
|
TOP_RIGHT = 0 |
|
|
|
BOTTOM_RIGHT = 1 |
|
|
|
BOTTOM_RIGHT = 1 |
|
|
|
TOP_LEFT = 2 |
|
|
|
TOP_LEFT = 2 |
|
|
@ -55,6 +57,7 @@ class Wiiboard: |
|
|
|
self.LED = False |
|
|
|
self.LED = False |
|
|
|
self.address = None |
|
|
|
self.address = None |
|
|
|
self.buttonDown = False |
|
|
|
self.buttonDown = False |
|
|
|
|
|
|
|
self.reportingTypeSet = False |
|
|
|
self.battery = None |
|
|
|
self.battery = None |
|
|
|
for i in range(3): |
|
|
|
for i in range(3): |
|
|
|
self.calibration.append([]) |
|
|
|
self.calibration.append([]) |
|
|
@ -91,6 +94,7 @@ class Wiiboard: |
|
|
|
self.status = "Connected" |
|
|
|
self.status = "Connected" |
|
|
|
self.address = address |
|
|
|
self.address = address |
|
|
|
_thread.start_new_thread(self.receivethread, ()) |
|
|
|
_thread.start_new_thread(self.receivethread, ()) |
|
|
|
|
|
|
|
_thread.start_new_thread(self.statusthread, ()) |
|
|
|
self.calibrate() |
|
|
|
self.calibrate() |
|
|
|
useExt = bytes([COMMAND_REGISTER, 0x04, 0xA4, 0x00, 0x40, 0x00]) |
|
|
|
useExt = bytes([COMMAND_REGISTER, 0x04, 0xA4, 0x00, 0x40, 0x00]) |
|
|
|
self.send(useExt) |
|
|
|
self.send(useExt) |
|
|
@ -181,6 +185,8 @@ class Wiiboard: |
|
|
|
data = self.datasocket.recv(25) |
|
|
|
data = self.datasocket.recv(25) |
|
|
|
intype = data[1] |
|
|
|
intype = data[1] |
|
|
|
if intype == INPUT_STATUS: |
|
|
|
if intype == INPUT_STATUS: |
|
|
|
|
|
|
|
self.battery = data[7]/BATTERY_MAX |
|
|
|
|
|
|
|
if not self.reportingTypeSet: |
|
|
|
self.setReportingType() |
|
|
|
self.setReportingType() |
|
|
|
elif intype == INPUT_READ_DATA: |
|
|
|
elif intype == INPUT_READ_DATA: |
|
|
|
if self.calibrationRequested == True: |
|
|
|
if self.calibrationRequested == True: |
|
|
@ -200,6 +206,11 @@ class Wiiboard: |
|
|
|
self.status = "Disconnected" |
|
|
|
self.status = "Disconnected" |
|
|
|
self.disconnect() |
|
|
|
self.disconnect() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def statusthread(self): |
|
|
|
|
|
|
|
while self.status == "Connected": |
|
|
|
|
|
|
|
time.sleep(30) |
|
|
|
|
|
|
|
self.requestStatus() |
|
|
|
|
|
|
|
|
|
|
|
def parseCalibrationResponse(self, bytes): |
|
|
|
def parseCalibrationResponse(self, bytes): |
|
|
|
index = 0 |
|
|
|
index = 0 |
|
|
|
if len(bytes) == 16: |
|
|
|
if len(bytes) == 16: |
|
|
@ -213,7 +224,7 @@ class Wiiboard: |
|
|
|
index += 2 |
|
|
|
index += 2 |
|
|
|
|
|
|
|
|
|
|
|
# Send <data> to the Wiiboard |
|
|
|
# Send <data> to the Wiiboard |
|
|
|
# <data> should be an array of strings, each string representing a single hex byte |
|
|
|
# <data> should be of type bytes |
|
|
|
def send(self, data): |
|
|
|
def send(self, data): |
|
|
|
if self.status != "Connected": |
|
|
|
if self.status != "Connected": |
|
|
|
return |
|
|
|
return |
|
|
@ -238,5 +249,9 @@ class Wiiboard: |
|
|
|
def setReportingType(self): |
|
|
|
def setReportingType(self): |
|
|
|
msg = bytes([COMMAND_REPORTING, CONTINUOUS_REPORTING, EXTENSION_8BYTES]) |
|
|
|
msg = bytes([COMMAND_REPORTING, CONTINUOUS_REPORTING, EXTENSION_8BYTES]) |
|
|
|
self.send(msg) |
|
|
|
self.send(msg) |
|
|
|
|
|
|
|
self.reportingTypeSet = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def requestStatus(self): |
|
|
|
|
|
|
|
msg = bytes([INPUT_REQUEST_STATUS, 0x00]) |
|
|
|
|
|
|
|
self.send(msg) |
|
|
|
|
|
|
|
|
|
|
|