Commit a1058a2f authored by Alisson Claudino's avatar Alisson Claudino

Adicionadas funções aos componentes gráficos e amostragem dinamicamente correta

parent 6785ac5f
......@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'Resources/CalibracaoP.ui'
#
# Created: Tue Nov 14 12:27:19 2017
# Created: Fri Nov 17 19:18:18 2017
# by: PyQt5 UI code generator 5.2.1
#
# WARNING! All changes made in this file will be lost!
......@@ -216,6 +216,8 @@ class Ui_MainWindow(object):
self.menuEtapa.setObjectName("menuEtapa")
self.menuPorta = QtWidgets.QMenu(self.menuBar)
self.menuPorta.setObjectName("menuPorta")
self.menuPlay_Pause = QtWidgets.QAction(MainWindow)
self.menuPlay_Pause.setObjectName("menuPlay_Pause")
MainWindow.setMenuBar(self.menuBar)
self.menuStatusBar = QtWidgets.QStatusBar(MainWindow)
self.menuStatusBar.setObjectName("menuStatusBar")
......@@ -248,7 +250,9 @@ class Ui_MainWindow(object):
self.menuBar.addAction(self.menuArquivo.menuAction())
self.menuBar.addAction(self.menuEtapa.menuAction())
self.menuBar.addAction(self.menuPorta.menuAction())
self.menuBar.addAction(self.menuPlay_Pause)
self.menuPlay_Pause.setCheckable(True)
self.menuPlay_Pause.toggled.connect(self.playPauseButtonAnimation)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
......@@ -297,6 +301,7 @@ class Ui_MainWindow(object):
self.menuArquivo.setTitle(_translate("MainWindow", "Arquivo"))
self.menuEtapa.setTitle(_translate("MainWindow", "Etapa"))
self.menuPorta.setTitle(_translate("MainWindow", "Porta"))
self.menuPlay_Pause.setText(_translate("MainWindow", "Play"))
self.alternaCalibraP.setText(_translate("MainWindow", "Calibração P"))
self.alternaCalibraT.setText(_translate("MainWindow", "Calibração T"))
self.alternaProc.setText(_translate("MainWindow", "Processamento"))
......@@ -310,11 +315,19 @@ class Ui_MainWindow(object):
def sceneSelector(self, scene):
self.CentralGraph.setScene(scene)
self.CentralGraph.setBackgroundBrush(QtCore.Qt.black)
self.CentralGraph.setInteractive(False)
def serialListPanel(self, seriaList):
self.usb=[]
self.usb = []
for i in range(0, len(seriaList)):
self.usb.append(QtWidgets.QAction(self.MainWindow))
self.usb[i].setText(seriaList[i].device)
self.usb[i].setCheckable(True)
self.menuPorta.addAction(self.usb[i])
\ No newline at end of file
self.menuPorta.addAction(self.usb[i])
def playPauseButtonAnimation(self):
if(self.menuPlay_Pause.text()=="Play"):
self.menuPlay_Pause.setText("Pause")
else:
self.menuPlay_Pause.setText("Play")
\ No newline at end of file
import pyqtgraph
from pyqtgraph import PlotItem
import time
class Graph(pyqtgraph.GraphicsLayout):
index=1
class Graph(PlotItem):
index = 0
def __init__(self,x_range,y_range,x_size,y_size,color1,color2,name1,name2):
super(Graph,self).__init__()
def __init__(self, x_range, y_min, y_max, x_size, y_size, color1, color2, name1, name2):
super(Graph, self).__init__(title="Curvas de Força e Calibrante")
self.x_range = x_range
self.y_range = y_range
self.y_min = y_min
self.y_max = y_max
self.x_size = x_size
self.y_size = y_size
self.color1 = color1
self.color2 = color2
self.name1=name1
self.name2=name2
self.p1 = self.addPlot()
self.p1.addLegend()
self.curve1 = self.p1.plot(pen=color1,name=self.name1)
self.curve2 = self.p1.plot(pen=color2,name=self.name2)
self.p1.showGrid(True, True)
self.name1 = name1
self.name2 = name2
self.addLegend()
self.curve1 = self.plot(pen=color1, name=self.name1)
self.curve2 = self.plot(pen=color2, name=self.name2)
self.showGrid(True, True)
self.setPreferredSize(self.x_size, self.y_size)
self.setXRange(0, self.x_range, padding=0)
self.setYRange(self.y_min, self.y_max, padding=0)
self.x1 = []
self.y1 = []
self.y2 = []
self.timeant = time.time()
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=[]
self.timeant=time.time()
def updateGraph(self,y1,y2):
#print(time.time()-self.timeant)
def updateGraph(self, y1, y2):
# print(time.time()-self.timeant)
self.y1.append(y1)
self.y2.append(y2)
if len(self.y1)>self.x_range+1:
del self.y1[0]
del self.y2[0]
if len(self.y1) > self.x_range + 1:
self.y1.pop(0)
self.y2.pop(0)
self.index = self.x_range
else:
self.x1.append(self.index)
self.index = self.index + 1
self.curve1.setData(self.x1, self.y1)
self.curve2.setData(self.x1,self.y2)
self.timeant = time.time()
def setGraphScale(self,x_range,y_range):
if(x_range==0):
x_range=1
if(y_range==0):
y_range=1
self.x_range=x_range
self.y_range=y_range
self.x1=[]
self.y1=[]
self.y2=[]
self.index=0
self.removeItem(self.p1)
self.p1=self.addPlot()
self.p1.setXRange(0, self.x_range, padding=0)
self.p1.setYRange(0, self.y_range, padding=0)
self.p1.addLegend()
self.curve1=self.p1.plot(pen=self.color1,name=self.name1)
self.curve2 = self.p1.plot(pen=self.color2,name=self.name2)
self.p1.showGrid(True,True)
\ No newline at end of file
self.curve2.setData(self.x1, self.y2)
#self.timeant = time.time()
from PyQt5 import QtCore,QtGui,QtWidgets # importação de classes
import time
import sys
from SystemEngine import SystemEngine
......@@ -7,7 +5,4 @@ if __name__ == '__main__':
engine=SystemEngine()
timer = QtCore.QTimer() #
timer.timeout.connect(engine.updateData) #
timer.start(0)
sys.exit(engine.app.exec_())
......@@ -701,9 +701,15 @@ font: 14pt &quot;Noto Serif&quot;;</string>
<string>Porta</string>
</property>
</widget>
<widget class="QMenu" name="menuPlay_Pause">
<property name="title">
<string>Play/Pause</string>
</property>
</widget>
<addaction name="menuArquivo"/>
<addaction name="menuEtapa"/>
<addaction name="menuPorta"/>
<addaction name="menuPlay_Pause"/>
</widget>
<widget class="QStatusBar" name="menuStatusBar"/>
<action name="alternaCalibraP">
......
......@@ -19,4 +19,5 @@ class SerialManager(object):
def read(self):
if(self.ser.inWaiting()==0):
pass
self.ser.flushInput()
return self.ser.readline()
\ No newline at end of file
from PyQt5 import QtCore,QtGui,QtWidgets # importação de classes
import pyqtgraph
import serial
import serial.tools.list_ports
import time
import sys
from SerialManager import SerialManager
......@@ -11,6 +9,7 @@ from Graph import Graph
class SystemEngine(object):
def __init__(self):
self.timer=QtCore.QTimer()
self.app = QtWidgets.QApplication(sys.argv)
self.dialog = QtWidgets.QMainWindow()
self.ser1 = SerialManager()
......@@ -18,7 +17,10 @@ class SystemEngine(object):
self.uiCalibra1 = Ui_MainWindow()
self.uiCalibra1.setupUi(self.dialog)
self.uiCalibra1.serialListPanel(self.ser1.portList)
self.layout = Graph(100, 30000, 900, 500, 'r','g',"Força","Tensão no Calibrante")
self.layout=pyqtgraph.GraphicsLayout()
self.graph = Graph(100,0, 30000, 900, 600, 'r','g',"Força","Tensão no Calibrante")
self.layout.addItem(self.graph)
self.scene = QtGui.QGraphicsScene()
self.scene.addItem(self.layout)
self.uiCalibra1.sceneSelector(self.scene)
......@@ -26,26 +28,64 @@ class SystemEngine(object):
self.prev_x_scale=100
self.x_scale=100
self.uiCalibra1.t_max.returnPressed.connect(self.updateScale)
self.uiCalibra1.f_max.returnPressed.connect(self.updateScale)
self.uiCalibra1.f_min.returnPressed.connect(self.updateScale)
self.uiCalibra1.p_max.returnPressed.connect(self.updateScale)
self.uiCalibra1.p_min.returnPressed.connect(self.updateScale)
self.uiCalibra1.amostragemCBox.currentIndexChanged.connect(self.updateTimer)
self.timeant=time.time()
self.timer.timeout.connect(self.updateData)
self.timer.start(100)
def updateData(self):
if(self.uiCalibra1.usb[0].isChecked()==True):
def updateData(self):
#print(time.time()-self.timeant)
if(self.uiCalibra1.menuPlay_Pause.isChecked()==True):
readData = self.ser1.read() # Lê o dado da serial
readData = readData.decode('utf8')
dado = readData.split(' ', 3)
try:
self.x_scale=int(self.uiCalibra1.t_max.text())
self.uiCalibra1.forcaLabel.setText(str(dado[0])+" Tonf")
self.uiCalibra1.calibranteLabel.setText(str(dado[1].split()[0])+" mV")
except IndexError:
print("Erro no Indice do Array Enviado pela Serial")
try:
self.graph.updateGraph(float(dado[0]),float(dado[1]))
except ValueError:
self.x_scale=100
print("Erro nos Valores do Array Enviado pela Serial")
if(self.x_scale != self.prev_x_scale):
self.layout.setGraphScale(int(self.x_scale),32700)
else:
pass
self.timeant=time.time()
self.prev_x_scale = self.x_scale
self.uiCalibra1.forcaLabel.setText(str(dado[0])+" Tonf")
self.uiCalibra1.calibranteLabel.setText(str(dado[1].split()[0])+" mV")
self.layout.updateGraph(float(dado[0]),float(dado[1]))
def updateScale(self):
try:
self.x_scale = int(self.uiCalibra1.t_max.text())
self.y_min = int(self.uiCalibra1.f_min.text())
self.y_max = int(self.uiCalibra1.f_max.text())
except ValueError:
self.x_scale = 100
self.y_min = 0
self.y_max = 32700
print("Erro!: Campos de Escala Vazios")
else:
pass
\ No newline at end of file
if(self.x_scale=="0"):
self.x_scale="1"
self.layout.clear()
self.graph = self.graph = Graph(self.x_scale, self.y_min , self.y_max, 900, 600, 'r', 'g', "Força", "Tensão no Calibrante")
self.layout.addItem(self.graph)
self.scene.focusItem()
def updateTimer(self):
self.time=self.uiCalibra1.amostragemCBox.currentText().split(" ")
self.time[0]=int(self.time[0])
print(self.time[0])
if(self.time[0]<100):
self.time[0]=1000*self.time[0]
self.timer.stop()
self.timer.start(self.time[0])
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