work on C module

This commit is contained in:
Pavol Rusnak 2011-05-02 00:04:08 +02:00
parent 43ef244ff8
commit b5b2a30188
4 changed files with 229 additions and 17 deletions

View file

@ -89,10 +89,10 @@ class Device:
from random import randint from random import randint
from time import time from time import time
from math import sin from math import sin
return (randint(0,1023), # AD0 return (randint(0,1023), # AD0
int(sin(time())*511+512), randint(0,1023), randint(0,1023), # AD1 .. AD3 int(sin(6.2832*time())*511+512), randint(0,1023), randint(0,1023), # AD1 .. AD3
randint(0,1023), randint(0,1023), randint(0,1023), # AD4 .. AD6 randint(0,1023), randint(0,1023), int(sin(314.16*time())*511+512), # AD4 .. AD6
randint(0,1), randint(0,1), randint(0,1)) # IO1 .. IO3 randint(0,1), randint(0,1), randint(0,1)) # IO1 .. IO3
else: else:
i = self.epi.read(self.INSIZE) i = self.epi.read(self.INSIZE)
return (i[0] + (i[1]<<8), # AD0 return (i[0] + (i[1]<<8), # AD0

View file

@ -20,10 +20,7 @@ class ModuleAWidget(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.scene = QGraphicsScene() self.data = 200*[0.0]
self.ui.graphU.setScene(self.scene)
self.data = 100*[0.0]
def read_inputs(self): def read_inputs(self):
r = self.dev.read() r = self.dev.read()
@ -56,8 +53,8 @@ class ModuleAWidget(QWidget):
self.scene.addSimpleText('[U]').moveBy(-39, 430-10) self.scene.addSimpleText('[U]').moveBy(-39, 430-10)
path = QPainterPath() path = QPainterPath()
path.moveTo(0,400-self.data[0]*100) path.moveTo(0,400-self.data[0]*100)
for i in xrange(1,100): for i in xrange(1,200):
path.lineTo(6*(i+1), 400-self.data[i]*100) path.lineTo(3*(i+1), 400-self.data[i]*100)
self.scene.addPath(path, QPen(QColor(0,0,255), 3)) self.scene.addPath(path, QPen(QColor(0,0,255), 3))
self.ui.graphU.setScene(self.scene) self.ui.graphU.setScene(self.scene)
@ -69,7 +66,7 @@ class ModuleA():
def start(self): def start(self):
self.widget.dev = Device() self.widget.dev = Device()
self.widget.timer.start(50) self.widget.timer.start(40)
def stop(self): def stop(self):
self.widget.timer.stop() self.widget.timer.stop()

View file

@ -1,4 +1,8 @@
from PyQt4.QtGui import QWidget from PyQt4.QtGui import QWidget
from PyQt4.QtGui import QGraphicsScene
from PyQt4.QtGui import QPainterPath
from PyQt4.QtGui import QPen
from PyQt4.QtGui import QColor
from PyQt4.QtCore import pyqtSlot from PyQt4.QtCore import pyqtSlot
from PyQt4.QtCore import SIGNAL from PyQt4.QtCore import SIGNAL
from PyQt4.QtCore import QObject from PyQt4.QtCore import QObject
@ -16,12 +20,80 @@ 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.data2 = 100*[0.0]
self.data3 = 100*[0.0]
self.data4 = 100*[0.0]
def setup_scene(self, scene):
scene.addLine(-5, 200-0, 260, 200-0)
scene.addLine(0, 200+5, 0, 200-205)
scene.addLine(-5, 200- 50, 10, 200- 50)
scene.addLine(-5, 200-100, 10, 200-100)
scene.addLine(-5, 200-150, 10, 200-150)
scene.addSimpleText('4.0').moveBy(-40, 0-10)
scene.addSimpleText('3.0').moveBy(-40, 50-10)
scene.addSimpleText('2.0').moveBy(-40, 100-10)
scene.addSimpleText('1.0').moveBy(-40, 150-10)
scene.addSimpleText('0.0').moveBy(-40, 200-10)
def read_inputs(self): def read_inputs(self):
pass r = self.dev.read()
# r = self.dev.read() i = r[6]/1023.0 * 3.3
# v = r[0]/1023.0 * 3.3 a = r[0]/1023.0 * 3.3
# self.ui.labelV.setText('{:0.3f} V'.format(v)) b = r[1]/1023.0 * 3.3
# self.ui.progressV.setValue(1000*v) c = r[2]/1023.0 * 3.3
self.data1.pop(0)
self.data2.pop(0)
self.data3.pop(0)
self.data4.pop(0)
self.data1.append(i)
self.data2.append(a)
self.data3.append(b)
self.data4.append(c)
self.scene1 = QGraphicsScene()
self.scene2 = QGraphicsScene()
self.scene3 = QGraphicsScene()
self.scene4 = QGraphicsScene()
self.setup_scene(self.scene1)
self.setup_scene(self.scene2)
self.setup_scene(self.scene3)
self.setup_scene(self.scene4)
self.scene1.addSimpleText('[I]').moveBy(-39, 220-10)
path = QPainterPath()
path.moveTo(0,200-self.data1[0]*50)
for i in xrange(1,100):
path.lineTo(2.5*(i+1), 200-self.data1[i]*50)
self.scene1.addPath(path, QPen(QColor(0,0,255), 3))
self.scene2.addSimpleText('[A]').moveBy(-39, 220-10)
path = QPainterPath()
path.moveTo(0,200-self.data2[0]*50)
for i in xrange(1,100):
path.lineTo(2.5*(i+1), 200-self.data2[i]*50)
self.scene2.addPath(path, QPen(QColor(0,0,255), 3))
self.scene3.addSimpleText('[B]').moveBy(-39, 220-10)
path = QPainterPath()
path.moveTo(0,200-self.data3[0]*50)
for i in xrange(1,100):
path.lineTo(2.5*(i+1), 200-self.data3[i]*50)
self.scene3.addPath(path, QPen(QColor(0,0,255), 3))
self.scene4.addSimpleText('[C]').moveBy(-39, 220-10)
path = QPainterPath()
path.moveTo(0,200-self.data4[0]*50)
for i in xrange(1,100):
path.lineTo(2.5*(i+1), 200-self.data4[i]*50)
self.scene4.addPath(path, QPen(QColor(0,0,255), 3))
self.ui.graph1.setScene(self.scene1)
self.ui.graph2.setScene(self.scene2)
self.ui.graph3.setScene(self.scene3)
self.ui.graph4.setScene(self.scene4)
class ModuleC(): class ModuleC():
@ -31,7 +103,7 @@ class ModuleC():
def start(self): def start(self):
self.widget.dev = Device() self.widget.dev = Device()
self.widget.timer.start(50) self.widget.timer.start(25)
def stop(self): def stop(self):
self.widget.timer.stop() self.widget.timer.stop()

View file

@ -13,6 +13,149 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<widget class="QGraphicsView" name="graph1">
<property name="geometry">
<rect>
<x>100</x>
<y>10</y>
<width>331</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>
</rect>
</property>
</widget>
<widget class="QGraphicsView" name="graph2">
<property name="geometry">
<rect>
<x>440</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>
<width>331</width>
<height>251</height>
</rect>
</property>
</widget>
<widget class="QGroupBox" name="groupCurrent">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>81</width>
<height>80</height>
</rect>
</property>
<property name="title">
<string>Current</string>
</property>
<widget class="QRadioButton" name="radioDC">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>51</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>DC</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="radioAC">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>51</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>AC</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupMode">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>81</width>
<height>121</height>
</rect>
</property>
<property name="title">
<string>Mode</string>
</property>
<widget class="QRadioButton" name="radioL">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>51</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>L</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="radioC">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>51</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>C</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<widget class="QRadioButton" name="radioLC">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>51</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>LC</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</widget>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>