Processamento.py 3.49 KB
Newer Older
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
1
2
3
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#      Classe Main (Principal)                                                                              #
#      Autores: Pedro Henrique Kopper (pedro.kopper@ufrgs.br) -> https://lief.if.ufrgs.br/~phckopper        #
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
4
#      Licença: GNU GPLv3                                                                                   #
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
5
6
7
8
9
10
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

import sys
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import QTimer
from util.Graph import Graph
11
from util.Mock import Mock
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
12
from util.Stopwatch import Stopwatch
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
13
14
from ui.MainWindow import Ui_MainWindow

15
UPDATE_INTERVAL = 250 # milisegundos
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
16
17
18

class App(object):
    def __init__(self):
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
19
        # Inicializa algumas flags globais pra renderização em HiDPI funcionar
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
20
21
22
        QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) #enable highdpi scaling
        QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True) #use highdpi icons

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
23
        # Inicializa as coisas do Qt
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
24
25
26
27
        self.app = QtWidgets.QApplication(sys.argv)
        self.mainWindow = QtWidgets.QMainWindow()
        self.dialog = QtWidgets.QDialog(self.mainWindow)
        self.timer = QTimer(self.app)
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
28
        self.stopwatch = Stopwatch()
29
30
31
32
        
        # Inicializa a aquisiçao de dados como mock durante o desenvolvimento
        # Na vida real utilizaremos o SACADA
        self.DAQ = Mock("mock") 
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
33

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
34
        # Seta as variáveis de estado da aplicação
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
35
36
        self.running = False

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
37
        # Cria a interface principal
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
38
39
40
41
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self.mainWindow)
        self.setupConnections()

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
42
        # Inicializa os dois gráficos
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
43
        self.pressurePlot = Graph(self.ui.pressaoGraph, "Pressão", "bar")
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
44
        self.temperaturePlot = Graph(self.ui.temperaturaGraph, "Temperatura", "ºC")
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
45

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
46
        # Exibe a tela maximizada
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
47
48
        self.mainWindow.showMaximized()

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
49
    # Liga os slots de eventos dos componentes das interfaces nas respectivas funções
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
50
51
52
53
    def setupConnections(self):
        self.ui.controlBtn.clicked.connect(self.startStop)
        self.timer.timeout.connect(self.updateData)
    
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
54
55
    # Gerencia o pressionamento de começar/pausar, (des)ligando o timer de acordo
    # e atualizando o texto do botão
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
56
57
58
59
60
    def startStop(self):
        if self.running:
            self.timer.stop()
            self.running = False
            self.ui.controlBtn.setText("COMEÇAR")
61
            self.ui.controlBtn.setStyleSheet("background-color: green")
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
62
            self.stopwatch.stop()
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
63
        else:
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
64
            self.timer.start(UPDATE_INTERVAL)
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
65
66
            self.running = True
            self.ui.controlBtn.setText("PARAR")
67
            self.ui.controlBtn.setStyleSheet("background-color: red")
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
68
            self.stopwatch.start()
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
69

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
70
    # É chamada a cada UPDATE_INTERVAL milisegundos e é responsável por atualizar as informações da tela
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
71
    def updateData(self):
72
73
74
75
76
77
78
79
80
        time = self.stopwatch.readFormatted()
        power = self.DAQ.readPower()
        pressure = self.DAQ.readPressure()

        displayString = "{:.2f}ºC | {:.2f} bar | {}".format(power, pressure, time)
        self.ui.infos.setText(displayString)

        self.pressurePlot.addPoint((self.stopwatch.readSeconds(), pressure))
        self.temperaturePlot.addPoint((self.stopwatch.readSeconds(), power))
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
81
82
83
84
85


if __name__ == '__main__':
    app = App()
    sys.exit(app.app.exec_())