This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
IR test xy alrevez.py
154 lines (139 loc) · 5.26 KB
/
IR test xy alrevez.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
import random
from ctypes import *
import wiiuse
import time
import os
import math
import win32api, win32con
import time
class Grafico(QtGui.QWidget):
def __init__(self):
super(Grafico, self).__init__()
self.l1=0
self.l2=0
self.l3=0
self.nmotes = 1
self.wiimotes = wiiuse.init(self.nmotes)
found = wiiuse.find(self.wiimotes, self.nmotes, 5)
if not found:
print 'not found'
sys.exit(1)
connected = wiiuse.connect(self.wiimotes, self.nmotes)
if connected:
print 'Connected to %i wiimotes (of %i found).' % (connected, found)
else:
print 'failed to connect to any wiimote.'
sys.exit(1)
for i in range(self.nmotes):
wiiuse.set_leds(self.wiimotes[i], wiiuse.LED[i])
wiiuse.status(self.wiimotes[0])
wiiuse.set_ir(self.wiimotes[0], 1)
wiiuse.set_ir_vres(self.wiimotes[i], 1000, 1000)
wiiuse.rumble(self.wiimotes[0], 10)
time.sleep(0.5)
wiiuse.rumble(self.wiimotes[0], 0)
self.wm = self.wiimotes[0][0]
#wiiuse.motion_sensing(self.wiimotes, 0)
###############################
#######iniciando wii
def paintEvent(self, e):
qp = QtGui.QPainter()
qp.begin(self)
qp.setPen(QtGui.QColor(0, 0, 0))
qp.setBrush(QtGui.QColor(0, 0, 0, 160))
qp.drawRect(0,470,700,5)
qp.drawRect(0,0,5,700)
self.drawLines(qp)
qp.end()
def drawLines(self, qp): ## este metodo hay que editarlo para que pinte yn punto
wiiuse.motion_sensing(self.wiimotes, self.nmotes)
wiiuse.poll(self.wiimotes, self.nmotes)
pen = QtGui.QPen(QtCore.Qt.black, 10, QtCore.Qt.DotLine)
qp.setPen(pen)
try:
x=1024-self.wm.ir.x
y=768-self.wm.ir.y
#print str(x)+" "+str(y)
qp.drawPoint(x,y)
win32api.SetCursorPos((x,y))
"""win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,0,0)"""
self.l1.setText("x + "+str(self.wm.ir.x))
self.l2.setText("y + "+str(self.wm.ir.y))
self.l3=0
except:
print "error pintando"
def ingresaPuntoDeWiiMote(self):
self.repaint()
def setLabels(self,l1,l2,l3):
self.l1=l1
self.l2=l2
self.l3=l3
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.resize(1366, 768)
self.setWindowTitle('Data Logger')
self.initActions()
self.initMenus()
self.Widget = Grafico()
self.setCentralWidget(self.Widget)
"""self.glWidget = GLWidget(self)
self.setCentralWidget(self.glWidget)"""
#########
self.label1 = QtGui.QLabel('TEXTO',self)
self.label1.setGeometry(745,90,50,50)
self.label2 = QtGui.QLabel('TEXTO',self)
self.label2.setGeometry(745,190,50,50)
self.label3 = QtGui.QLabel('TEXTO',self)
self.label3.setGeometry(745,290,50,50)
self.Widget.setLabels(self.label1,self.label2,self.label3)
#########
self.boton = QtGui.QPushButton("congela eje X",self)
self.boton.setGeometry(745,150,70,50)
self.botonY=QtGui.QPushButton("congela eje Y",self)
self.botonY.setGeometry(745,250,70,50)
self.botonZ=QtGui.QPushButton("congela eje Z",self)
self.botonZ.setGeometry(745,350,70,50)
#self.boton.connect(self.boton,QtCore.SIGNAL('clicked()'), self.giracubo )
"""self.boton.connect(self.boton,QtCore.SIGNAL('clicked()'), self.Widget.congelaG1 )
self.botonY.connect(self.botonY,QtCore.SIGNAL('clicked()'),self.Widget.congelaG2)
self.botonZ.connect(self.botonZ,QtCore.SIGNAL('clicked()'),self.Widget.congelaG3)"""
timer = QtCore.QTimer(self)
timer.setInterval(0)
#QtCore.QObject.connect(timer, QtCore.SIGNAL('timeout()'), self.Widget.ingresaPuntoAleatorio)
QtCore.QObject.connect(timer, QtCore.SIGNAL('timeout()'), self.Widget.ingresaPuntoDeWiiMote)
timer.start()
"""timer = QtCore.QTimer(self)
timer.setInterval(1)
QtCore.QObject.connect(timer, QtCore.SIGNAL('timeout()'), self.glWidget.spin)
timer.start()"""
def initActions(self):
self.exitAction = QtGui.QAction('Quit', self)
self.exitAction.setShortcut('Ctrl+Q')
self.exitAction.setStatusTip('Exit application')
self.connect(self.exitAction, QtCore.SIGNAL('triggered()'), self.close)
def initMenus(self):
menuBar = self.menuBar()
fileMenu = menuBar.addMenu('&File')
fileMenu.addAction(self.exitAction)
def close(self):
QtGui.qApp.quit()
def keyPressEvent(self, e):
print e.key()
"""if e.key() == QtCore.Qt.Key_Escape:
print "dasa"
self.close()
if e.key() == QtCore.Qt.Key_Left:
print "izq"""
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
win = MainWindow()
win.show()
sys.exit(app.exec_())
"""app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())"""