source: trunk/src/testing/dim/devices/wiimote.py @ 4

Revision 4, 3.7 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1import device
2from globals import *
3import time
4from threading import Thread
5
6def makeNew(deviceId):
7    """ this is how we instantiate the device object from
8        the main program that loads this plugin """
9    return Wiimote(deviceId)
10
11
12# types of messages sent to the manager
13MOVE = 0
14TRANSLATE = 1
15ROTATE = 2
16RESIZE = 3
17CHANGE_Z = 4
18FULLSCREEN = 5
19
20class Wiimote(device.Device):
21   
22    def __init__(self, deviceId):
23        device.Device.__init__(self, "wiimote", deviceId, needPointer=True)
24        self.x = 0
25        self.y = 0
26       
27        self.dx = 0
28        self.dy = 0
29       
30        self.clickX = 0
31        self.clickY = 0
32       
33        self.translate = 0
34        self.resize = 0
35       
36        self.specialDevice = True
37       
38        getOverlayMgr().setSpecialDevice(1)
39       
40    def onMessage(self, data, firstMsg=False):
41        tokens = data.strip().split()
42        msgCode = int(tokens[0])
43
44        # click
45        if msgCode == MOVE:
46            x = float(tokens[1].strip())
47            y = float(tokens[2].strip())
48           
49            if x == -1 and y == -1:
50                if self.translate:   
51                    self.translate = False
52                    self.postEvtClick(self.x, self.y, TRANSLATE, False, EVT_CLICK)
53                if self.resize:
54                    self.resize = False
55                    self.postEvtClick(self.x, self.y, RESIZE, False, EVT_CLICK)
56                if self.pointer:
57                    self.pointer.movePointer(-50000,-50000)
58                    self.postEvtMove(-50000, -50000, 0, 0)
59            else:
60                x = self.bounds.getX() + int(round(float(x) * self.bounds.getWidth()))
61                y = self.bounds.getY() + int(round(float(y) * self.bounds.getHeight()))
62               
63    #            x,y = self.smooth(x,y)
64               
65                self.dx = self.dy = 0
66                if self.x != x or self.y != y:
67                    self.dx = x - self.x ;  self.x = x
68                    self.dy = y - self.y ;  self.y = y
69               
70    #            print "(%d,%d) -- [%d,%d] --> (%d,%d)" % (self.clickX, self.clickY, self.dx, self.dy, self.x, self.y)
71               
72                if self.pointer:
73                    self.pointer.movePointer(self.x, self.y)
74               
75                if self.translate:
76                    self.postEvtAnalog1(self.x, self.y, self.dx, self.dy, 0)
77                elif self.resize:
78                    self.postEvtAnalog1(self.x, self.y, self.dx, self.dy, 0)
79                else:
80                    self.postEvtMove(self.x, self.y, self.dx, self.dy)
81
82        elif msgCode == TRANSLATE or msgCode == RESIZE:
83            value = int(tokens[1])
84            isDown = False
85            if value == 1:
86                isDown = True
87            if isDown:
88                self.clickX, self.clickY = self.x, self.y
89            self.postEvtClick(self.x, self.y, msgCode, isDown, EVT_CLICK)
90            if msgCode == TRANSLATE:
91                self.translate = isDown
92            elif msgCode == RESIZE:
93                self.resize = isDown
94       
95        elif msgCode == ROTATE:
96            value = int(tokens[1])
97            if (value == -1):
98                self.postEvtAnalog2(self.x, self.y, self.dx, self.dy, 0, -90)
99            elif (value == 1):
100                self.postEvtAnalog2(self.x, self.y, self.dx, self.dy, 0, 90)
101               
102        elif msgCode == CHANGE_Z:
103            value = int(tokens[1])
104#            if (value == 0):
105#                for a in getSageData().getAllAppIDs():
106#                    print "APP: ",a," Z=",getSageData().getZvalue(a)
107#            else:
108            self.postEvtKey(value, self.x, self.y)
109        elif msgCode == FULLSCREEN:
110            self.postEvtKey(FULLSCREEN, self.x, self.y)
111           
112
Note: See TracBrowser for help on using the repository browser.