Commit ffbf973f authored by Alisson Claudino's avatar Alisson Claudino

Funcionando o código separado em classes, nomeação de componentes gráficos e...

Funcionando o código separado em classes, nomeação de componentes gráficos e alteração dinâmica de escala de gráficos
parent 337b1781
This diff is collapsed.
......@@ -3,7 +3,7 @@ import pyqtgraph
import serial
import time
import sys
from mainwindow import Ui_MainWindow
from CalibracaoP import Ui_MainWindow
class SerialManager(object):
def __init__(self):
......@@ -16,57 +16,100 @@ class SerialManager(object):
def read(self):
if(self.ser.inWaiting()==0):
pass
return self.ser.read()
return self.ser.readline()
class Graph(pyqtgraph.GraphicsLayout):
index=0
index=1
def __init__(self,x_range,y_range,x_size,y_size,color):
def __init__(self,x_range,y_range,x_size,y_size,color1,color2):
super(Graph,self).__init__()
self.x_range = x_range
self.y_range = y_range
self.x_size = x_size
self.y_size = y_size
self.color1 = color1
self.color2 = color2
self.p1 = self.addPlot()
self.curve1 = self.p1.plot(pen=color)
self.setPreferredSize(x_size,y_size)
self.p1.setXRange(0,x_range,padding=0)
self.p1.setYRange(0, y_range, padding=0)
self.curve1 = self.p1.plot(pen=color1)
self.curve2 = self.p1.plot(pen=color2)
self.setPreferredSize(self.x_size,self.y_size)
self.p1.setXRange(0,self.x_range,padding=0)
self.p1.setYRange(0, self.y_range, padding=0)
self.x1=[]
self.y1=[]
self.y2=[]
def updateGraph(self,value):
self.y1.append(value)
self.index += 1
if len(self.y1)>self.x_range-1:
#self.p1.enableAutoScale()
def updateGraph(self,y1,y2):
self.y1.append(y1)
self.y2.append(y2)
if len(self.y1)>self.x_range+1:
del self.y1[0]
del self.y2[0]
self.index = self.x_range
else:
self.x1.append(index)
self.x1.append(self.index)
self.index = self.index + 1
self.curve1.setData(self.x1, self.y1)
self.curve2.setData(self.x1,self.y2)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
dialog = QtWidgets.QMainWindow()
ser1 = SerialManager()
uiCalibra1=Ui_MainWindow()
uiCalibra1.setupUi(dialog)
layout = Graph(0,100,0,1023,'r')
scene = QtGui.QGraphicsScene()
scene.addItem(layout)
uiCalibra1.sceneSelector(scene)
def setGraphScale(self,x_range,y_range):
self.x_range=x_range
self.y_range=y_range
self.x1=[]
self.y1=[]
self.y2=[]
self.index=0
self.clear()
self.p1=self.addPlot()
self.p1.setXRange(0, self.x_range, padding=0)
self.p1.setYRange(0, self.y_range, padding=0)
self.curve1=self.p1.plot(pen=self.color1)
self.curve2=self.p1.plot(pen=self.color2)
class SystemEngine(object):
def __init__(self):
self.app = QtWidgets.QApplication(sys.argv)
self.dialog = QtWidgets.QMainWindow()
self.ser1 = SerialManager()
self.uiCalibra1 = Ui_MainWindow()
self.uiCalibra1.setupUi(self.dialog)
self.layout = Graph(100, 10230, 900, 600, 'r','g')
self.scene = QtGui.QGraphicsScene()
self.scene.addItem(self.layout)
self.uiCalibra1.sceneSelector(self.scene)
self.dialog.showMaximized()
self.prev_x_scale=100
self.x_scale=100
def updateData(self):
readData = self.ser1.read() # Lê o dado da serial
readData = readData.decode('utf8')
dado = readData.split(' ', 3)
self.x_scale=int(self.uiCalibra1.f_max.text())
if(self.x_scale != self.prev_x_scale):
self.layout.setGraphScale(int(self.x_scale),32700)
self.prev_x_scale = self.x_scale
self.layout.updateGraph(float(dado[0]),float(dado[1]))
if __name__ == '__main__':
engine=SystemEngine()
timer = QtCore.QTimer() #
timer.timeout.connect(layout.update(ser1.read())) #
timer.timeout.connect(engine.updateData) #
timer.start(0)
dialog.showMaximized()
sys.exit(app.exec_())
sys.exit(engine.app.exec_())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment