Commit 60fcb31e authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

Implementar tempo de amostragem e play/pause

parent c83156df
......@@ -221,6 +221,9 @@ QGroupBox {
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<item>
<property name="text">
<string>100 mseg</string>
......@@ -269,7 +272,7 @@ QGroupBox {
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="playPause">
<property name="text">
<string>PAUSA</string>
</property>
......
......@@ -17,7 +17,10 @@ class Graph():
self.graph = ui.mainGraph
self.plots = []
self.axis = []
self.config = Config().data
try:
self.config = Config().data
except FileNotFoundError:
logger("[FATAL]", "Arquivo de configuração não encontrado!")
self.device = self.config["device"]
today = datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
......@@ -33,7 +36,13 @@ class Graph():
self.interface = INTERFACES[self.device["type"]](logger, self.device["location"], self.device["channels"])
except:
self.running = False
logger("[FATAL", "Erro ao abrir a interface!")
logger("[FATAL]", "Erro ao abrir a interface!")
print(ui.samplingBox)
ui.min_amostra.valueChanged.connect(self.updateScale)
ui.min_pressao.valueChanged.connect(self.updateScale)
ui.max_amostra.valueChanged.connect(self.updateScale)
ui.max_pressao.valueChanged.connect(self.updateScale)
self.graph.setBackground((240, 240, 240))
......@@ -49,10 +58,18 @@ class Graph():
self.logFile.write("{}".format(self.dataX[0][-1]))
self.logFile.flush()
self.ui.forceLabel.setText("{:.2f} bar".format(self.dataY[1][-1]))
self.ui.calibratorLabel.setText("{:.4f} mV".format(self.dataY[0][-1] * 1000))
self.ui.forceLabel.setText("{:.0f} bar".format(self.dataY[1][-1]))
self.ui.calibratorLabel.setText("{:.2f} mV".format(self.dataY[0][-1] * 1000))
pg.QtGui.QApplication.processEvents()
def updateScale(self):
minX = self.ui.min_pressao.value()
minY = self.ui.min_amostra.value() / 1000.0
maxX = self.ui.max_pressao.value()
maxY = self.ui.max_amostra.value() / 1000.0
self.combinedPlot.getViewBox().setRange(xRange=(minX, maxX), yRange=(minY, maxY))
def setInterval(self, interval):
self.interval = interval
......@@ -71,20 +88,18 @@ class Graph():
self.debugLayout = self.graph.addLayout()
for i, channel in enumerate(self.device["channels"]):
plotItem = self.debugLayout.addPlot(row=i, col=1)
plotItem.setMenuEnabled(False) # Previne acesso ao menu do pyqtgraph pelos usuários
plot = plotItem.plot(pen=mkPen(mkColor(channel["color"]), width=2), name=channel["id"])
self.plots.append(plot)
plotItem.setClipToView(True)
plotItem.showGrid(True)
#plotItem.getViewBox().setMouseEnabled(False, False)
plotItem.getViewBox().enableAutoRange(plotItem.getViewBox().YAxis)
#plotItem.getViewBox().setAutoPan(x=True)
self.dataX.append([0])
self.dataY.append([0])
plotItem.setLabel("left", text=channel["name"], units=channel["unit"])
self.logger("[GRAPH]", "Added channel {}".format(channel["name"]))
self.logFile.write("{},".format(channel["name"]))
self.logFile.write("timestamp")
self.logFile.write("timestamp")
# Faz com que ambos eixos X se movam juntos sempre
# TODO: escrever de forma mais limpa
......@@ -96,6 +111,8 @@ class Graph():
self.combinedPlot.getViewBox().enableAutoRange(plotItem.getViewBox().YAxis)
self.combinedPlot.setLabel("left", text="Amostra", units="V")
self.combinedPlot.setLabel("bottom", text="Pressão", units="bar")
self.combinedPlot.getViewBox().setMouseEnabled(False, False) # Previne uso do mouse para controle do zoom
self.combinedPlot.setMenuEnabled(False) # Previne acesso ao menu do pyqtgraph pelos usuários
qGraphicsGridLayout = self.debugLayout.layout
qGraphicsGridLayout.setColumnStretchFactor(1, 1)
qGraphicsGridLayout.setColumnStretchFactor(2, 3)
......
......@@ -12,7 +12,7 @@ class MainThread():
#super(MainThread, self).__init__(parent)
self.ui = ui
self.data = []
self.graph = Graph(self.ui, 250, self._log)
self.graph = Graph(self.ui, 500, self._log)
#self.upTimer = Timer()
#self.downTimer = Timer(delay=10)
try:
......@@ -23,26 +23,14 @@ class MainThread():
self.graphTimer.timeout.connect(self.graph.updateGraphs)
self.graphTimer.start(self.graph.interval)
self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate)
def run(self):
#self.ui.startTimerButton.pressed.connect(self._startTimer)
#self.ui.stopTimerButton.pressed.connect(self._stopTimer)
#self.ui.startRegTimerButton.pressed.connect(self._startTimer)
#self.ui.stopRegTimerButton.pressed.connect(self._stopTimer)
#self.ui.playPauseButton.aboutToShow.connect(self._playPause)
#self.ui.finalizeButton.aboutToShow.connect(self._finalize)
while True:
#self._updateTimers()
#if self.graph.running:
# self.graph.updateGraphs()
QApplication.processEvents()
print(time())
sleep(self.graph.interval/1000.0) # Updates at 30FPS
self.ui.playPause.clicked.connect(self._playPause)
def _updateSamplingRate(self):
MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000]
self._log("[DEBUG]", self.ui.samplingCBox.currentText())
self.graph.setInterval(MAP[self.ui.samplingCBox.currentIndex()])
self.graphTimer.stop()
self.graphTimer.start(MAP[self.ui.samplingCBox.currentIndex()])
self.graph.interval = MAP[self.ui.samplingCBox.currentIndex()]
def _fatal(self, msg):
error = QMessageBox()
......@@ -58,9 +46,13 @@ class MainThread():
def _playPause(self):
if self.graph.running:
self.graph.stop()
self.graphTimer.stop()
self.graph.running = False
self.ui.playPause.setText("REINICIAR")
else:
self.graph.restart()
self.graph.running = True
self.graphTimer.start(self.graph.interval)
self.ui.playPause.setText("PAUSA")
def _finalize(self):
pass
......
......@@ -158,9 +158,9 @@ class Ui_Generico(object):
self.samplingCBox.addItem("")
self.samplingCBox.addItem("")
self.verticalLayout_3.addWidget(self.samplingCBox)
self.pushButton = QtWidgets.QPushButton(self.samplingBox)
self.pushButton.setObjectName("pushButton")
self.verticalLayout_3.addWidget(self.pushButton)
self.playPause = QtWidgets.QPushButton(self.samplingBox)
self.playPause.setObjectName("playPause")
self.verticalLayout_3.addWidget(self.playPause)
self.scaleGBox = QtWidgets.QGroupBox(self.samplingBox)
self.scaleGBox.setObjectName("scaleGBox")
self.gridLayoutWidget = QtWidgets.QWidget(self.scaleGBox)
......@@ -269,6 +269,7 @@ class Ui_Generico(object):
self.selectPortaUSB.setObjectName("selectPortaUSB")
self.retranslateUi(Generico)
self.samplingCBox.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(Generico)
def retranslateUi(self, Generico):
......@@ -288,7 +289,7 @@ class Ui_Generico(object):
self.samplingCBox.setItemText(6, _translate("Generico", "2.5 seg"))
self.samplingCBox.setItemText(7, _translate("Generico", "5 seg"))
self.samplingCBox.setItemText(8, _translate("Generico", "10 seg"))
self.pushButton.setText(_translate("Generico", "PAUSA"))
self.playPause.setText(_translate("Generico", "PAUSA"))
self.scaleGBox.setTitle(_translate("Generico", "Escala"))
self.min_pressao.setSuffix(_translate("Generico", " bar"))
self.min_amostra.setSuffix(_translate("Generico", " mV"))
......
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