53 lines
994 B
Python
53 lines
994 B
Python
import os
|
|
import time
|
|
import dotenv #
|
|
import serial
|
|
|
|
|
|
DOTENV_LOADED = False
|
|
|
|
def load_dotenv():
|
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
dotenv.load_dotenv(os.path.join(basedir, ".env"))
|
|
global DOTENV_LOADED
|
|
DOTENV_LOADED = True
|
|
|
|
|
|
def get_serial_dev():
|
|
global DOTENV_LOADED
|
|
if not DOTENV_LOADED:
|
|
load_dotenv()
|
|
return os.environ.get("SERIAL_DEV")
|
|
|
|
|
|
def get_serial_speed():
|
|
global DOTENV_LOADED
|
|
if not DOTENV_LOADED:
|
|
load_dotenv()
|
|
return os.environ.get("SERIAL_SPEED")
|
|
|
|
|
|
class MAPIDCP:
|
|
arduino = None
|
|
|
|
def __init__(self):
|
|
self.arduino = serial.Serial(port=get_serial_dev(), baudrate=get_serial_speed(), timeout=.1)
|
|
|
|
def _cmd(self, cmd: str):
|
|
self.arduino.write(bytes(cmd + "\r\n", "utf8"))
|
|
time.sleep(0.1)
|
|
|
|
def cls(self):
|
|
self._cmd("CLS")
|
|
|
|
def led(self, state: bool):
|
|
if state:
|
|
self._cmd("ON")
|
|
else:
|
|
self._cmd("OFF")
|
|
|
|
def line(self, line_no: int):
|
|
self._cmd("LINE " + str(line_no))
|
|
|
|
def echo(self, text: str):
|
|
self._cmd("ECHO " + text)
|