Compare commits
4 commits
5d8bec255a
...
1c6e8b363b
Author | SHA1 | Date | |
---|---|---|---|
1c6e8b363b | |||
d0e4feb2c9 | |||
fa2cc9b5d3 | |||
187e017622 |
8 changed files with 147 additions and 16 deletions
5
.env
Normal file
5
.env
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
SERIAL_DEV="/dev/cu.usbserial-A700e0gN"
|
||||||
|
#SERIAL_DEV="/dev/ttyUSB0"
|
||||||
|
SERIAL_SPEED = 9600
|
||||||
|
#SERIAL_SPEED = 19200
|
||||||
|
#SERIAL_SPEED = 115200
|
|
@ -43,7 +43,7 @@ void setup() {
|
||||||
// Show README
|
// Show README
|
||||||
SCmd.addCommand("README", showReadMe);
|
SCmd.addCommand("README", showReadMe);
|
||||||
|
|
||||||
SCmd.addDefaultHandler(commandNotFound);
|
SCmd.setDefaultHandler(commandNotFound);
|
||||||
|
|
||||||
|
|
||||||
Serial.println("Ready.");
|
Serial.println("Ready.");
|
||||||
|
@ -72,7 +72,7 @@ void loop() {
|
||||||
SCmd.readSerial();
|
SCmd.readSerial();
|
||||||
}
|
}
|
||||||
|
|
||||||
void commandNotFound() {
|
void commandNotFound(char *cmd) {
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
//Serial.println("[ERROR @ TTY:IN] COMMAND NOT FOUND!");
|
//Serial.println("[ERROR @ TTY:IN] COMMAND NOT FOUND!");
|
||||||
Serial.println("[ERROR] COMMAND NOT FOUND!");
|
Serial.println("[ERROR] COMMAND NOT FOUND!");
|
||||||
|
@ -137,7 +137,7 @@ void showVersion() {
|
||||||
Serial.print(OS_NAME);
|
Serial.print(OS_NAME);
|
||||||
Serial.print(" v");
|
Serial.print(" v");
|
||||||
Serial.println(OS_VERSION);
|
Serial.println(OS_VERSION);
|
||||||
Serial.print("Hardware: ");
|
Serial.print("Hardware: Arduino ");
|
||||||
Serial.println(BOARD);
|
Serial.println(BOARD);
|
||||||
|
|
||||||
Serial.print(TTY_PROMPT);
|
Serial.print(TTY_PROMPT);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define _CONFIG_H_
|
#define _CONFIG_H_
|
||||||
|
|
||||||
#define OS_NAME "MAPID/CP"
|
#define OS_NAME "MAPID/CP"
|
||||||
#define OS_VERSION 3
|
#define OS_VERSION 4
|
||||||
|
|
||||||
#define PIN_LED LED_BUILTIN
|
#define PIN_LED LED_BUILTIN
|
||||||
#define PIN_LCD 2
|
#define PIN_LCD 2
|
||||||
|
|
10
README.md
10
README.md
|
@ -5,3 +5,13 @@ Info display powered by two parts:
|
||||||
1. Command line OS running on Arduino (MAPID/CP)
|
1. Command line OS running on Arduino (MAPID/CP)
|
||||||
2. Python pyserial script controlling the display over a serial connection
|
2. Python pyserial script controlling the display over a serial connection
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Arduino libraries
|
||||||
|
- SerialCommand Advanced
|
||||||
|
- serLCD
|
||||||
|
- Python libraries
|
||||||
|
- pyserial
|
||||||
|
- python-dotenv
|
||||||
|
|
||||||
|
|
||||||
|
|
49
fifo_bridge.py
Executable file
49
fifo_bridge.py
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import mapid
|
||||||
|
|
||||||
|
|
||||||
|
FIFO = "/tmp/mapid.fifo"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
global FIFO
|
||||||
|
if len(sys.argv) == 2:
|
||||||
|
FIFO = sys.argv[1]
|
||||||
|
|
||||||
|
m = mapid.MAPIDCP()
|
||||||
|
|
||||||
|
os.mkfifo(FIFO)
|
||||||
|
time.sleep(0.2)
|
||||||
|
print("Created FIFO " + FIFO, file=sys.stderr)
|
||||||
|
# f = open(FIFO, "w")
|
||||||
|
# f.write("\n")
|
||||||
|
# f.close()
|
||||||
|
# print("Created FIFO " + FIFO, file=sys.stderr)
|
||||||
|
f = open(FIFO, "r")
|
||||||
|
print("Opened FIFO for reading", file=sys.stderr)
|
||||||
|
m.cls()
|
||||||
|
m.line(1)
|
||||||
|
m.echo("fifo_bridge.py")
|
||||||
|
m.line(2)
|
||||||
|
m.echo(FIFO)
|
||||||
|
|
||||||
|
keep_going = True
|
||||||
|
while keep_going:
|
||||||
|
try:
|
||||||
|
line = f.readline().strip("\n")
|
||||||
|
m._cmd(line)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
keep_going = False
|
||||||
|
print()
|
||||||
|
|
||||||
|
os.remove(FIFO)
|
||||||
|
print("Removed FIFO.", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
35
mapid-count.py
Normal file → Executable file
35
mapid-count.py
Normal file → Executable file
|
@ -4,17 +4,16 @@ import time
|
||||||
import sys
|
import sys
|
||||||
import serial
|
import serial
|
||||||
|
|
||||||
|
import mapid
|
||||||
SERIAL_PORT = "/dev/cu.usbserial-A700e0gN"
|
|
||||||
SERIAL_SPEED = 9600
|
|
||||||
#SERIAL_SPEED = 19200
|
|
||||||
#SERIAL_SPEED = 115200
|
|
||||||
|
|
||||||
|
|
||||||
arduino = serial.Serial(port=SERIAL_PORT, baudrate=SERIAL_SPEED, timeout=.1)
|
# print(mapid.get_serial_dev()); sys.exit(1)
|
||||||
|
SERIAL_DEV = mapid.get_serial_dev()
|
||||||
|
SERIAL_SPEED = mapid.get_serial_speed()
|
||||||
|
|
||||||
|
|
||||||
def write_read(x):
|
def write_read(x):
|
||||||
|
arduino = serial.Serial(port=SERIAL_DEV, baudrate=SERIAL_SPEED, timeout=.1)
|
||||||
arduino.write(bytes(x, 'utf-8'))
|
arduino.write(bytes(x, 'utf-8'))
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
data = arduino.readline()
|
data = arduino.readline()
|
||||||
|
@ -22,6 +21,7 @@ def write_read(x):
|
||||||
|
|
||||||
|
|
||||||
def countdown(start: int):
|
def countdown(start: int):
|
||||||
|
arduino = serial.Serial(port=SERIAL_DEV, baudrate=SERIAL_SPEED, timeout=.1)
|
||||||
for i in range(start, -1, -1):
|
for i in range(start, -1, -1):
|
||||||
arduino.write(bytes("CLS\r\n", 'utf8'))
|
arduino.write(bytes("CLS\r\n", 'utf8'))
|
||||||
arduino.write(bytes("LINE 1\r\n", 'utf8'))
|
arduino.write(bytes("LINE 1\r\n", 'utf8'))
|
||||||
|
@ -35,16 +35,29 @@ def countdown(start: int):
|
||||||
arduino.write(bytes("ECHO BOOM!!!\r\n", 'utf8'))
|
arduino.write(bytes("ECHO BOOM!!!\r\n", 'utf8'))
|
||||||
|
|
||||||
|
|
||||||
|
def countdown2(start: int):
|
||||||
|
m = mapid.MAPID_CP()
|
||||||
|
m.cls()
|
||||||
|
for i in range(start, -1, -1):
|
||||||
|
m.cls()
|
||||||
|
m.line(1)
|
||||||
|
m.echo("Countdown")
|
||||||
|
m.line(2)
|
||||||
|
print("\t" + str(i))
|
||||||
|
m.echo(str(i))
|
||||||
|
time.sleep(1)
|
||||||
|
m.cls()
|
||||||
|
m.line(2)
|
||||||
|
m.echo("BOOM!!!")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
while True:
|
while True:
|
||||||
num = int(input("Enter a number (-1=exit): "))
|
num = int(input("Enter a number (-1=exit): "))
|
||||||
if num < 0:
|
if num < 0:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
#arduino.write(bytes("CLS\r\n", 'utf8'))
|
# countdown(num)
|
||||||
#arduino.write(bytes("LINE 1\r\n", 'utf8'))
|
countdown2(num)
|
||||||
#arduino.write(bytes("ECHO Countdown\r\n", 'utf8'))
|
|
||||||
# arduino.write(bytes("ECHO C " + str(num) + "\r\n", 'utf8'))
|
|
||||||
countdown(num)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
53
mapid.py
Normal file
53
mapid.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
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)
|
|
@ -1,4 +1,5 @@
|
||||||
# requirements.txt
|
# requirements.txt
|
||||||
|
|
||||||
serial
|
pyserial>=3.5
|
||||||
|
python-dotenv>=0.5
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue