we have 2 charts

This commit is contained in:
Pavol Rusnak 2011-05-03 20:21:13 +02:00
parent cb366284dd
commit d731fab0ac
2 changed files with 23 additions and 33 deletions

View file

@ -20,10 +20,8 @@ class ModuleCWidget(QWidget):
self.timer = QTimer() self.timer = QTimer()
QObject.connect(self.timer, SIGNAL("timeout()"), self.read_inputs) QObject.connect(self.timer, SIGNAL("timeout()"), self.read_inputs)
self.data1 = 100*[0.0] self.data1 = 200*[0.0]
self.data2 = 100*[0.0] self.data2 = 200*[0.0]
self.data3 = 100*[0.0]
self.data4 = 100*[0.0]
self.mode = ['DC', 'L'] self.mode = ['DC', 'L']
@ -83,7 +81,7 @@ class ModuleCWidget(QWidget):
self.dev.switches(1<<2) self.dev.switches(1<<2)
def setup_scene(self, scene): def setup_scene(self, scene):
scene.addLine(-5, 200-0, 260, 200-0) scene.addLine(-5, 200-0, 610, 200-0)
scene.addLine(0, 200+5, 0, 200-205) scene.addLine(0, 200+5, 0, 200-205)
scene.addLine(-5, 200- 50, 10, 200- 50) scene.addLine(-5, 200- 50, 10, 200- 50)
scene.addLine(-5, 200-100, 10, 200-100) scene.addLine(-5, 200-100, 10, 200-100)
@ -94,25 +92,37 @@ class ModuleCWidget(QWidget):
scene.addSimpleText('1.0').moveBy(-40, 150-10) scene.addSimpleText('1.0').moveBy(-40, 150-10)
scene.addSimpleText('0.0').moveBy(-40, 200-10) scene.addSimpleText('0.0').moveBy(-40, 200-10)
def tick_DC(self, u): def tick_DC(self, u, i):
self.data1.pop(0) self.data1.pop(0)
self.data2.pop(0)
self.data1.append(u) self.data1.append(u)
self.data2.append(i)
self.scene1 = QGraphicsScene() self.scene1 = QGraphicsScene()
self.scene2 = QGraphicsScene()
self.setup_scene(self.scene1) self.setup_scene(self.scene1)
self.setup_scene(self.scene2)
self.scene1.addSimpleText('[U]').moveBy(-39, 220-10) self.scene1.addSimpleText('[U]').moveBy(-39, 220-10)
self.scene2.addSimpleText('[I]').moveBy(-39, 220-10)
path = QPainterPath() path = QPainterPath()
path.moveTo(0,200-self.data1[0]*50) path.moveTo(0,200-self.data1[0]*50)
for i in xrange(1,100): for i in xrange(1,200):
path.lineTo(2.5*(i+1), 200-self.data1[i]*50) path.lineTo(3*(i+1), 200-self.data1[i]*50)
self.scene1.addPath(path, QPen(QColor(0,0,255), 3)) self.scene1.addPath(path, QPen(QColor(0,0,255), 3))
path = QPainterPath()
path.moveTo(0,200-self.data2[0]*50)
for i in xrange(1,200):
path.lineTo(3*(i+1), 200-self.data2[i]*50)
self.scene2.addPath(path, QPen(QColor(0,0,255), 3))
self.ui.graph1.setScene(self.scene1) self.ui.graph1.setScene(self.scene1)
self.ui.graph2.setScene(self.scene2)
def read_inputs(self): def read_inputs(self):
r = self.dev.read() r = self.dev.read()
if self.mode[0] == 'DC': if self.mode[0] == 'DC':
u = r[0]/1023.0 * 3.3 # change this if we change opamp u = r[0]/1023.0 * 3.3 # TODO: change this if we change opamp
self.tick_DC(u) i = 1 # TODO: read real current
self.tick_DC(u, i)
class ModuleC(): class ModuleC():

View file

@ -18,17 +18,7 @@
<rect> <rect>
<x>100</x> <x>100</x>
<y>10</y> <y>10</y>
<width>331</width> <width>671</width>
<height>251</height>
</rect>
</property>
</widget>
<widget class="QGraphicsView" name="graph3">
<property name="geometry">
<rect>
<x>100</x>
<y>270</y>
<width>331</width>
<height>251</height> <height>251</height>
</rect> </rect>
</property> </property>
@ -36,19 +26,9 @@
<widget class="QGraphicsView" name="graph2"> <widget class="QGraphicsView" name="graph2">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>440</x> <x>100</x>
<y>10</y>
<width>321</width>
<height>251</height>
</rect>
</property>
</widget>
<widget class="QGraphicsView" name="graph4">
<property name="geometry">
<rect>
<x>440</x>
<y>270</y> <y>270</y>
<width>331</width> <width>671</width>
<height>251</height> <height>251</height>
</rect> </rect>
</property> </property>