Commit f6397c49 authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

Timers are now working

parent 19b1556f
...@@ -595,7 +595,7 @@ background-color: rgb(80,80,80);</string> ...@@ -595,7 +595,7 @@ background-color: rgb(80,80,80);</string>
background-color: rgb(80,80,80);</string> background-color: rgb(80,80,80);</string>
</property> </property>
<property name="text"> <property name="text">
<string>Parar</string> <string>Reset</string>
</property> </property>
</widget> </widget>
</widget> </widget>
...@@ -733,7 +733,7 @@ font: 75 12pt &quot;Noto Serif&quot;;</string> ...@@ -733,7 +733,7 @@ font: 75 12pt &quot;Noto Serif&quot;;</string>
border: 1px solid rgb(255,255,255);</string> border: 1px solid rgb(255,255,255);</string>
</property> </property>
<property name="text"> <property name="text">
<string>Parar</string> <string>Reset</string>
</property> </property>
</widget> </widget>
</widget> </widget>
......
...@@ -27,6 +27,7 @@ class Graph(QThread): ...@@ -27,6 +27,7 @@ class Graph(QThread):
def run(self): def run(self):
while self.running: while self.running:
data = self.interface.readAll() data = self.interface.readAll()
#print(len(self.dataX[0]))
for i, channel in enumerate(self.plots): for i, channel in enumerate(self.plots):
self.dataX[i].append(self.dataX[i][-1] + self.interval) self.dataX[i].append(self.dataX[i][-1] + self.interval)
self.dataY[i].append(data[i]) self.dataY[i].append(data[i])
......
from datetime import datetime
from time import sleep
from sys import exit from sys import exit
from PyQt5.QtCore import QThread, QTimer from PyQt5.QtCore import QThread, QTimer
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QMessageBox
from threads.Graph import Graph from threads.Graph import Graph
from config import Config from config import Config
from util.Timer import Timer
class MainThread(QThread): class MainThread(QThread):
def __init__(self, ui, parent=None): def __init__(self, ui, parent=None):
...@@ -10,18 +13,24 @@ class MainThread(QThread): ...@@ -10,18 +13,24 @@ class MainThread(QThread):
self.ui = ui self.ui = ui
self.data = [] self.data = []
self.graph = Graph(self.ui.mainGraph, 100, self._log) self.graph = Graph(self.ui.mainGraph, 100, self._log)
#try: self.upTimer = Timer()
self.config = Config() self.downTimer = Timer(delay=10)
#except FileNotFoundError: try:
# self._fatal("Arquivo de configuração não encontrado!") self.config = Config()
except FileNotFoundError:
self._fatal("Arquivo de configuração não encontrado!")
def run(self): def run(self):
self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate) self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate)
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.graph.start() self.graph.start()
thread_instance = QThread() while True:
thread_instance.start() self._updateTimers()
thread_instance.exec_() sleep(1/30.0) # Updates at 30FPS
def _updateSamplingRate(self): def _updateSamplingRate(self):
MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000] MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000]
...@@ -36,4 +45,31 @@ class MainThread(QThread): ...@@ -36,4 +45,31 @@ class MainThread(QThread):
exit(-1) exit(-1)
def _log(self, tag, msg): def _log(self, tag, msg):
self.ui.consoleView.setText("{} {}\n{}".format(tag, msg, self.ui.consoleView.text())) self.ui.consoleView.setText("{} {}\n{}".format(tag, msg, self.ui.consoleView.text()))
\ No newline at end of file
def _updateTimers(self):
if self.upTimer.active:
self.upTimer.update()
if self.downTimer.active:
self.downTimer.update()
self.ui.currentTimeLabel.setText(datetime.now().strftime("%H:%M:%S"))
self.ui.timerLabel.setText(self.upTimer.getTimeString())
self.ui.regTimerLabel.setText(self.downTimer.getTimeString())
def _startTimer(self):
btn = self.sender()
timer = self.upTimer if btn == self.ui.startTimerButton else self.downTimer
if btn.text() == "Iniciar":
btn.setText("Parar")
timer.start()
else:
btn.setText("Iniciar")
timer.stop()
def _stopTimer(self):
if self.sender == self.ui.stopTimerButton:
self.upTimer.stop()
self.upTimer.clear()
else:
self.downTimer.stop()
self.downTimer.clear()
\ No newline at end of file
...@@ -361,7 +361,7 @@ class Ui_CalibracaoPressaoW(object): ...@@ -361,7 +361,7 @@ class Ui_CalibracaoPressaoW(object):
self.timerGBox.setTitle(_translate("CalibracaoPressaoW", "Cronômetro")) self.timerGBox.setTitle(_translate("CalibracaoPressaoW", "Cronômetro"))
self.timerLabel.setText(_translate("CalibracaoPressaoW", "0.00 s")) self.timerLabel.setText(_translate("CalibracaoPressaoW", "0.00 s"))
self.startTimerButton.setText(_translate("CalibracaoPressaoW", "Iniciar")) self.startTimerButton.setText(_translate("CalibracaoPressaoW", "Iniciar"))
self.stopTimerButton.setText(_translate("CalibracaoPressaoW", "Parar")) self.stopTimerButton.setText(_translate("CalibracaoPressaoW", "Reset"))
self.startTimeGBox.setTitle(_translate("CalibracaoPressaoW", "Horário de Início")) self.startTimeGBox.setTitle(_translate("CalibracaoPressaoW", "Horário de Início"))
self.startTimeLabel.setText(_translate("CalibracaoPressaoW", "00:00:00")) self.startTimeLabel.setText(_translate("CalibracaoPressaoW", "00:00:00"))
self.currentTimeGBox.setTitle(_translate("CalibracaoPressaoW", "Horário Atual")) self.currentTimeGBox.setTitle(_translate("CalibracaoPressaoW", "Horário Atual"))
...@@ -369,7 +369,7 @@ class Ui_CalibracaoPressaoW(object): ...@@ -369,7 +369,7 @@ class Ui_CalibracaoPressaoW(object):
self.regTimerGBox.setTitle(_translate("CalibracaoPressaoW", "Cont. Regressivo")) self.regTimerGBox.setTitle(_translate("CalibracaoPressaoW", "Cont. Regressivo"))
self.startRegTimerButton.setText(_translate("CalibracaoPressaoW", "Iniciar")) self.startRegTimerButton.setText(_translate("CalibracaoPressaoW", "Iniciar"))
self.regTimerLabel.setText(_translate("CalibracaoPressaoW", "0.00s")) self.regTimerLabel.setText(_translate("CalibracaoPressaoW", "0.00s"))
self.stopRegTimerButton.setText(_translate("CalibracaoPressaoW", "Parar")) self.stopRegTimerButton.setText(_translate("CalibracaoPressaoW", "Reset"))
self.fileMenu.setTitle(_translate("CalibracaoPressaoW", "Arquivo")) self.fileMenu.setTitle(_translate("CalibracaoPressaoW", "Arquivo"))
self.stageMenu.setTitle(_translate("CalibracaoPressaoW", "Etapa")) self.stageMenu.setTitle(_translate("CalibracaoPressaoW", "Etapa"))
self.serialMenu.setTitle(_translate("CalibracaoPressaoW", "Porta")) self.serialMenu.setTitle(_translate("CalibracaoPressaoW", "Porta"))
......
from time import time
class Timer(object):
UP = 0
DOWN = 1
def __init__(self, delay=0):
self.delay = delay
self.time = delay
self.active = False
self.direction = self.DOWN if delay else self.UP
self.lastUpdate = 0
def update(self):
if not self.lastUpdate:
self.stop()
now = time()
delta = now - self.lastUpdate
self.lastUpdate = now
if self.direction == self.UP:
self.time += delta
if self.direction == self.DOWN:
self.time -= delta
if self.time < 0:
self.time = 0
self.stop()
def clear(self):
self.time = self.delay
def getTime(self):
return self.time
def getTimeString(self):
return "{:02.0f}:{:05.2f}".format(self.time//60, self.time%60)
def setTime(self, time):
self.time = time
def start(self):
self.active = True
self.lastUpdate = time()
def stop(self):
self.active = False
\ No newline at end of file
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