Commit 1677fc75 authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

We can now dynamically load interfaces using the configuration file

parent 5710db41
from random import random
class Interface(object):
class Mock(object):
def __init__(self, location, channels):
self.channels = len(channels)
def read(self):
return random() * 20
\ No newline at end of file
return random() * 20
def readAll(self):
return [self.read() for i in range(self.channels)]
\ No newline at end of file
# Comente fora as interfaces não utilizadas para reduzir o tamanho do programa
from interfaces.Mock import *
\ No newline at end of file
from time import sleep
from PyQt5.QtCore import QThread
from pyqtgraph import AxisItem
from interfaces.Mock import Interface
from pyqtgraph import AxisItem, mkColor, mkPen
from interfaces import *
from config import Config
class Graph(QThread):
INTERFACES = {
'mock': Mock
}
def __init__(self, graph, interval, logger, parent=None):
super(Graph, self).__init__(parent)
self.running = True
......@@ -18,14 +21,15 @@ class Graph(QThread):
self.config = Config().data
self._configurePlots()
self.interface = Interface()
device = self.config["device"]
self.interface = self.INTERFACES[device["type"]](device["location"], device["channels"])
def run(self):
print("RUNNING")
while self.running:
data = self.interface.readAll()
for i, channel in enumerate(self.plots):
self.dataX[i].append(self.dataX[i][-1] + self.interval)
self.dataY[i].append(self.interface.read())
self.dataY[i].append(data[i])
channel.setData(self.dataX[i], self.dataY[i])
sleep(self.interval)
......@@ -41,6 +45,6 @@ class Graph(QThread):
self.logger("[GRAPH]", "Added channel {}".format(channel["name"]))
self.dataX.append([0])
self.dataY.append([0])
self.plots.append(self.graph.plot(pen=channel["color"], name=channel["name"]))
self.plots.append(self.graph.plot(pen=mkPen(mkColor(channel["color"]), width=2), name=channel["name"]))
self.axis.append(AxisItem("right", channel["color"]))
self.axis[-1].setLabel(channel["name"], channel["unit"])
\ 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