import device from globals import * import time from threading import Thread def makeNew(deviceId): """ this is how we instantiate the device object from the main program that loads this plugin """ return Wiimote(deviceId) # types of messages sent to the manager MOVE = 0 TRANSLATE = 1 ROTATE = 2 RESIZE = 3 CHANGE_Z = 4 FULLSCREEN = 5 class Wiimote(device.Device): def __init__(self, deviceId): device.Device.__init__(self, "wiimote", deviceId, needPointer=True) self.x = 0 self.y = 0 self.dx = 0 self.dy = 0 self.clickX = 0 self.clickY = 0 self.translate = 0 self.resize = 0 self.specialDevice = True getOverlayMgr().setSpecialDevice(1) def onMessage(self, data, firstMsg=False): tokens = data.strip().split() msgCode = int(tokens[0]) # click if msgCode == MOVE: x = float(tokens[1].strip()) y = float(tokens[2].strip()) if x == -1 and y == -1: if self.translate: self.translate = False self.postEvtClick(self.x, self.y, TRANSLATE, False, EVT_CLICK) if self.resize: self.resize = False self.postEvtClick(self.x, self.y, RESIZE, False, EVT_CLICK) if self.pointer: self.pointer.movePointer(-50000,-50000) self.postEvtMove(-50000, -50000, 0, 0) else: x = self.bounds.getX() + int(round(float(x) * self.bounds.getWidth())) y = self.bounds.getY() + int(round(float(y) * self.bounds.getHeight())) # x,y = self.smooth(x,y) self.dx = self.dy = 0 if self.x != x or self.y != y: self.dx = x - self.x ; self.x = x self.dy = y - self.y ; self.y = y # print "(%d,%d) -- [%d,%d] --> (%d,%d)" % (self.clickX, self.clickY, self.dx, self.dy, self.x, self.y) if self.pointer: self.pointer.movePointer(self.x, self.y) if self.translate: self.postEvtAnalog1(self.x, self.y, self.dx, self.dy, 0) elif self.resize: self.postEvtAnalog1(self.x, self.y, self.dx, self.dy, 0) else: self.postEvtMove(self.x, self.y, self.dx, self.dy) elif msgCode == TRANSLATE or msgCode == RESIZE: value = int(tokens[1]) isDown = False if value == 1: isDown = True if isDown: self.clickX, self.clickY = self.x, self.y self.postEvtClick(self.x, self.y, msgCode, isDown, EVT_CLICK) if msgCode == TRANSLATE: self.translate = isDown elif msgCode == RESIZE: self.resize = isDown elif msgCode == ROTATE: value = int(tokens[1]) if (value == -1): self.postEvtAnalog2(self.x, self.y, self.dx, self.dy, 0, -90) elif (value == 1): self.postEvtAnalog2(self.x, self.y, self.dx, self.dy, 0, 90) elif msgCode == CHANGE_Z: value = int(tokens[1]) # if (value == 0): # for a in getSageData().getAllAppIDs(): # print "APP: ",a," Z=",getSageData().getZvalue(a) # else: self.postEvtKey(value, self.x, self.y) elif msgCode == FULLSCREEN: self.postEvtKey(FULLSCREEN, self.x, self.y)