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

Graphs are now customizable using a configuration file

parent 2133ac4b
......@@ -10,6 +10,7 @@ pyqtgraph = "*"
numpy = "*"
pyserial = "*"
pyqt5 = "*"
pyyaml = "*"
[requires]
python_version = "3.5"
{
"_meta": {
"hash": {
"sha256": "30dea57a72419f03ba8fa2b200f07989bc2533149c22ede769bd46ea39ad48c6"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.5"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"numpy": {
"hashes": [
"sha256:1980f8d84548d74921685f68096911585fee393975f53797614b34d4f409b6da",
"sha256:22752cd809272671b273bb86df0f505f505a12368a3a5fc0aa811c7ece4dfd5c",
"sha256:23cc40313036cffd5d1873ef3ce2e949bdee0646c5d6f375bf7ee4f368db2511",
"sha256:2b0b118ff547fecabc247a2668f48f48b3b1f7d63676ebc5be7352a5fd9e85a5",
"sha256:3a0bd1edf64f6a911427b608a894111f9fcdb25284f724016f34a84c9a3a6ea9",
"sha256:3f25f6c7b0d000017e5ac55977a3999b0b1a74491eacb3c1aa716f0e01f6dcd1",
"sha256:4061c79ac2230594a7419151028e808239450e676c39e58302ad296232e3c2e8",
"sha256:560ceaa24f971ab37dede7ba030fc5d8fa173305d94365f814d9523ffd5d5916",
"sha256:62be044cd58da2a947b7e7b2252a10b42920df9520fc3d39f5c4c70d5460b8ba",
"sha256:6c692e3879dde0b67a9dc78f9bfb6f61c666b4562fd8619632d7043fb5b691b0",
"sha256:6f65e37b5a331df950ef6ff03bd4136b3c0bbcf44d4b8e99135d68a537711b5a",
"sha256:7a78cc4ddb253a55971115f8320a7ce28fd23a065fc33166d601f51760eecfa9",
"sha256:80a41edf64a3626e729a62df7dd278474fc1726836552b67a8c6396fd7e86760",
"sha256:893f4d75255f25a7b8516feb5766c6b63c54780323b9bd4bc51cdd7efc943c73",
"sha256:972ea92f9c1b54cc1c1a3d8508e326c0114aaf0f34996772a30f3f52b73b942f",
"sha256:9f1d4865436f794accdabadc57a8395bd3faa755449b4f65b88b7df65ae05f89",
"sha256:9f4cd7832b35e736b739be03b55875706c8c3e5fe334a06210f1a61e5c2c8ca5",
"sha256:adab43bf657488300d3aeeb8030d7f024fcc86e3a9b8848741ea2ea903e56610",
"sha256:bd2834d496ba9b1bdda3a6cf3de4dc0d4a0e7be306335940402ec95132ad063d",
"sha256:d20c0360940f30003a23c0adae2fe50a0a04f3e48dc05c298493b51fd6280197",
"sha256:d3b3ed87061d2314ff3659bb73896e622252da52558f2380f12c421fbdee3d89",
"sha256:dc235bf29a406dfda5790d01b998a1c01d7d37f449128c0b1b7d1c89a84fae8b",
"sha256:fb3c83554f39f48f3fa3123b9c24aecf681b1c289f9334f8215c1d3c8e2f6e5b"
],
"index": "pypi",
"version": "==1.16.2"
},
"pyqt5": {
"hashes": [
"sha256:020e8771ad66429587d3db6cceb028be3435e2c65f417dcc8e3b3e644b6ab1d7",
"sha256:399fd9c3b3786210d9d2a86bc73255cc03c997b454480b7c0daf3e1a09e1ab58",
"sha256:c0565737d1d5fd40a7e14b6692bfec1f1e1f0be082ae70d1776c44561980e3c4",
"sha256:d4e88208dfd017636e4b1f407990d0c3b6cf47afed6be4f2fb6ca887ef513e4b"
],
"index": "pypi",
"version": "==5.12.1"
},
"pyqt5-sip": {
"hashes": [
"sha256:0aed4266e52f4d11947439d9df8c57d4578e92258ad0d70645f9f69b627b35c7",
"sha256:15750a4a3718c68ba662eede7310612aedad70c9727497908bf2eeddd255d16f",
"sha256:2071265b7a603354b624b6cfae4ea032719e341799fb925961fd192f328fd203",
"sha256:31a59f76168df007b480b9382256c20f8898c642e1394df2990559f0f6389f66",
"sha256:39ce455bf5be5c1b20db10d840a536f70c3454be3baa7adca22f67ed90507853",
"sha256:5d8a4b8e75fa6c9f837ea92793f1aeacbf3929f1d11cdf36f9604c1876182aca",
"sha256:6bf9bacac776257390dd3f8a703d12c8228e4eb1aa0b191f1550965f44e4c23a",
"sha256:87a76841e07e6dae5df34dded427708b5ea8d605c017e0bb6e56a7354959271e",
"sha256:9f0ad4198f2657da9d59a393c266959362c517445cace842051e5ad564fa8fb0",
"sha256:cbb0f24e3bfa1403bf3a05f30066d4457509aa411d6c6823d02b0508b787b8ea",
"sha256:d38d379fa4f5c86a8ea92b8fab42748f37de093d21a25c34b2339eb2764ee5d5",
"sha256:f24413d34707525a0fe1448b9574089242b9baa7c604ae5714abef9ad1749839"
],
"version": "==4.19.15"
},
"pyqtgraph": {
"hashes": [
"sha256:4c08ab34881fae5ecf9ddfe6c1220b9e41e6d3eb1579a7d8ef501abb8e509251"
],
"index": "pypi",
"version": "==0.10.0"
},
"pyserial": {
"hashes": [
"sha256:6e2d401fdee0eab996cf734e67773a0143b932772ca8b42451440cfed942c627",
"sha256:e0770fadba80c31013896c7e6ef703f72e7834965954a78e71a3049488d4d7d8"
],
"index": "pypi",
"version": "==3.4"
},
"pyyaml": {
"hashes": [
"sha256:1adecc22f88d38052fb787d959f003811ca858b799590a5eaa70e63dca50308c",
"sha256:436bc774ecf7c103814098159fbb84c2715d25980175292c648f2da143909f95",
"sha256:460a5a4248763f6f37ea225d19d5c205677d8d525f6a83357ca622ed541830c2",
"sha256:5a22a9c84653debfbf198d02fe592c176ea548cccce47553f35f466e15cf2fd4",
"sha256:7a5d3f26b89d688db27822343dfa25c599627bc92093e788956372285c6298ad",
"sha256:9372b04a02080752d9e6f990179a4ab840227c6e2ce15b95e1278456664cf2ba",
"sha256:a5dcbebee834eaddf3fa7366316b880ff4062e4bcc9787b78c7fbb4a26ff2dd1",
"sha256:aee5bab92a176e7cd034e57f46e9df9a9862a71f8f37cad167c6fc74c65f5b4e",
"sha256:c51f642898c0bacd335fc119da60baae0824f2cde95b0330b56c0553439f0673",
"sha256:c68ea4d3ba1705da1e0d85da6684ac657912679a649e8868bd850d2c299cce13",
"sha256:e23d0cc5299223dcc37885dae624f382297717e459ea24053709675a976a3e19"
],
"index": "pypi",
"version": "==5.1"
}
},
"develop": {}
}
from yaml import load, dump
class Config(object):
CONFIG_LOCATION = "config.yaml"
def __init__(self):
self.data = load(open(self.CONFIG_LOCATION, 'r'))
\ No newline at end of file
# Este arquivo define a interface a ser utilizada
device:
type: mock
location: null
channels:
- id: 0
name: "Tensão"
color: "#FF0000"
unit: "mV"
- id: 1
name: "Corrente"
color: "#0000FF"
unit: "mA"
\ 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 config import Config
class Graph(QThread):
def __init__(self, graph, interval, parent=None):
def __init__(self, graph, interval, logger, parent=None):
super(Graph, self).__init__(parent)
self.running = True
self.logger = logger
self.interval = interval/1000.0
self.dataX = []
self.dataY = []
self.graph = graph
self.plots = []
self.axis = []
self.config = Config().data
self._configurePlots()
self.interface = Interface()
self.dataX = [0]
self.dataY = [0]
self.plot = graph.plot()
def run(self):
print("RUNNING")
while self.running:
self.dataX.append(self.dataX[-1] + self.interval)
self.dataY.append(self.interface.read())
self.plot.setData(self.dataX, self.dataY)
for i, channel in enumerate(self.plots):
self.dataX[i].append(self.dataX[i][-1] + self.interval)
self.dataY[i].append(self.interface.read())
channel.setData(self.dataX[i], self.dataY[i])
sleep(self.interval)
def setInterval(self, interval):
self.interval = interval/1000.0
def stop(self):
self.running = False
\ No newline at end of file
self.running = False
def _configurePlots(self):
self.logger("[GRAPH]", "Found new device {}".format(self.config["device"]["type"]))
for channel in self.config["device"]["channels"]:
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.axis.append(AxisItem("right", channel["color"]))
self.axis[-1].setLabel(channel["name"], channel["unit"])
\ No newline at end of file
from sys import exit
from PyQt5.QtCore import QThread, QTimer
from PyQt5.QtWidgets import QMessageBox
from threads.Graph import Graph
from config import Config
class MainThread(QThread):
def __init__(self, ui, parent=None):
super(MainThread, self).__init__(parent)
self.ui = ui
self.data = []
self.graph = Graph(self.ui.mainGraph, 100)
self.graph = Graph(self.ui.mainGraph, 100, self._log)
#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)
......@@ -20,6 +27,13 @@ class MainThread(QThread):
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()])
def _fatal(self, msg):
error = QMessageBox()
error.setText(msg)
error.setWindowTitle("Erro")
error.exec()
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
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