Commit bf70fa43 authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper
Browse files

Add Arduino module using Alisson's protocol

parent 18fc550e
# Este arquivo define a interface a ser utilizada
type: mock
location: null
type: arduino
location: "/dev/ttyUSB0"
- id: 0
name: "Tensão"
from time import sleep
from serial import Serial
class Arduino(object):
def __init__(self, logger, location, channels):
logger("[ARDUINO]", "Opening serial port...")
self.ser = Serial(location, 115200)
logger("[ARDUINO]", "ERROR: Could not open serial port")
logger("[ARDUINO]", "Starting board...")
self._reset() # Reset do arduino para reinicio da leitura
self.ser.readline() # Espera o Arduino inicializar
logger("[ARDUINO]", "Board started, good luck!")
def read(self):
return 10
def readAll(self):
self.ser.flushInput() # Limpeza do buffer de entrada
data = self.ser.readline().split(bytes(" ", "utf-8")) # Leitura de todos os valores em uma linha
return [int(x) for x in data]
def _reset(self):
\ No newline at end of file
from random import random
class Mock(object):
def __init__(self, location, channels):
def __init__(self, logger, location, channels):
self.channels = len(channels)
def read(self):
logger("[MOCK]", "Generating fake data...")
def read(self, channel):
return random() * 20
def readAll(self):
return [ for i in range(self.channels)]
\ No newline at end of file
return [ 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 *
from interfaces.Arduino import *
'mock': Mock
'mock': Mock,
'arduino': Arduino
\ No newline at end of file
......@@ -19,7 +19,7 @@ class Graph(QThread):
self.config = Config().data
device = self.config["device"]
self.interface = INTERFACES[device["type"]](device["location"], device["channels"])
self.interface = INTERFACES[device["type"]](logger, device["location"], device["channels"])
def run(self):
while self.running:
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