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>
background-color: rgb(80,80,80);</string>
</property>
<property name="text">
<string>Parar</string>
<string>Reset</string>
</property>
</widget>
</widget>
......@@ -733,7 +733,7 @@ font: 75 12pt &quot;Noto Serif&quot;;</string>
border: 1px solid rgb(255,255,255);</string>
</property>
<property name="text">
<string>Parar</string>
<string>Reset</string>
</property>
</widget>
</widget>
......
......@@ -27,6 +27,7 @@ class Graph(QThread):
def run(self):
while self.running:
data = self.interface.readAll()
#print(len(self.dataX[0]))
for i, channel in enumerate(self.plots):
self.dataX[i].append(self.dataX[i][-1] + self.interval)
self.dataY[i].append(data[i])
......
from datetime import datetime
from time import sleep
from sys import exit
from PyQt5.QtCore import QThread, QTimer
from PyQt5.QtWidgets import QMessageBox
from threads.Graph import Graph
from config import Config
from util.Timer import Timer
class MainThread(QThread):
def __init__(self, ui, parent=None):
......@@ -10,18 +13,24 @@ class MainThread(QThread):
self.ui = ui
self.data = []
self.graph = Graph(self.ui.mainGraph, 100, self._log)
#try:
self.config = Config()
#except FileNotFoundError:
# self._fatal("Arquivo de configuração não encontrado!")
self.upTimer = Timer()
self.downTimer = Timer(delay=10)
try:
self.config = Config()
except FileNotFoundError:
self._fatal("Arquivo de configuração não encontrado!")
def run(self):
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()
thread_instance = QThread()
thread_instance.start()
thread_instance.exec_()
while True:
self._updateTimers()
sleep(1/30.0) # Updates at 30FPS
def _updateSamplingRate(self):
MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000]
......@@ -36,4 +45,31 @@ class MainThread(QThread):
exit(-1)
def _log(self, tag, msg):
self.ui.consoleView.setText("{} {}\n{}".format(tag, msg, self.ui.consoleView.text()))
\ No newline at end of file
self.ui.consoleView.setText("{} {}\n{}".format(tag, msg, self.ui.consoleView.text()))
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):
self.timerGBox.setTitle(_translate("CalibracaoPressaoW", "Cronômetro"))
self.timerLabel.setText(_translate("CalibracaoPressaoW", "0.00 s"))
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.startTimeLabel.setText(_translate("CalibracaoPressaoW", "00:00:00"))
self.currentTimeGBox.setTitle(_translate("CalibracaoPressaoW", "Horário Atual"))
......@@ -369,7 +369,7 @@ class Ui_CalibracaoPressaoW(object):
self.regTimerGBox.setTitle(_translate("CalibracaoPressaoW", "Cont. Regressivo"))
self.startRegTimerButton.setText(_translate("CalibracaoPressaoW", "Iniciar"))
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.stageMenu.setTitle(_translate("CalibracaoPressaoW", "Etapa"))
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