Compare commits
No commits in common. "1c6e8b363be27dc2b66d6200bccadd810cb9d8e3" and "5d8bec255a425e6d10922ca9e9019c2d8c637130" have entirely different histories.
1c6e8b363b
...
5d8bec255a
8 changed files with 16 additions and 147 deletions
5
.env
5
.env
|
@ -1,5 +0,0 @@
|
|||
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
|
||||
SCmd.addCommand("README", showReadMe);
|
||||
|
||||
SCmd.setDefaultHandler(commandNotFound);
|
||||
SCmd.addDefaultHandler(commandNotFound);
|
||||
|
||||
|
||||
Serial.println("Ready.");
|
||||
|
@ -72,7 +72,7 @@ void loop() {
|
|||
SCmd.readSerial();
|
||||
}
|
||||
|
||||
void commandNotFound(char *cmd) {
|
||||
void commandNotFound() {
|
||||
Serial.println("");
|
||||
//Serial.println("[ERROR @ TTY:IN] COMMAND NOT FOUND!");
|
||||
Serial.println("[ERROR] COMMAND NOT FOUND!");
|
||||
|
@ -137,7 +137,7 @@ void showVersion() {
|
|||
Serial.print(OS_NAME);
|
||||
Serial.print(" v");
|
||||
Serial.println(OS_VERSION);
|
||||
Serial.print("Hardware: Arduino ");
|
||||
Serial.print("Hardware: ");
|
||||
Serial.println(BOARD);
|
||||
|
||||
Serial.print(TTY_PROMPT);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _CONFIG_H_
|
||||
|
||||
#define OS_NAME "MAPID/CP"
|
||||
#define OS_VERSION 4
|
||||
#define OS_VERSION 3
|
||||
|
||||
#define PIN_LED LED_BUILTIN
|
||||
#define PIN_LCD 2
|
||||
|
|
10
README.md
10
README.md
|
@ -5,13 +5,3 @@ Info display powered by two parts:
|
|||
1. Command line OS running on Arduino (MAPID/CP)
|
||||
2. Python pyserial script controlling the display over a serial connection
|
||||
|
||||
## Requirements
|
||||
|
||||
- Arduino libraries
|
||||
- SerialCommand Advanced
|
||||
- serLCD
|
||||
- Python libraries
|
||||
- pyserial
|
||||
- python-dotenv
|
||||
|
||||
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
#!/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
Executable file → Normal file
35
mapid-count.py
Executable file → Normal file
|
@ -4,16 +4,17 @@ import time
|
|||
import sys
|
||||
import serial
|
||||
|
||||
import mapid
|
||||
|
||||
SERIAL_PORT = "/dev/cu.usbserial-A700e0gN"
|
||||
SERIAL_SPEED = 9600
|
||||
#SERIAL_SPEED = 19200
|
||||
#SERIAL_SPEED = 115200
|
||||
|
||||
|
||||
# print(mapid.get_serial_dev()); sys.exit(1)
|
||||
SERIAL_DEV = mapid.get_serial_dev()
|
||||
SERIAL_SPEED = mapid.get_serial_speed()
|
||||
arduino = serial.Serial(port=SERIAL_PORT, baudrate=SERIAL_SPEED, timeout=.1)
|
||||
|
||||
|
||||
def write_read(x):
|
||||
arduino = serial.Serial(port=SERIAL_DEV, baudrate=SERIAL_SPEED, timeout=.1)
|
||||
arduino.write(bytes(x, 'utf-8'))
|
||||
time.sleep(0.05)
|
||||
data = arduino.readline()
|
||||
|
@ -21,7 +22,6 @@ def write_read(x):
|
|||
|
||||
|
||||
def countdown(start: int):
|
||||
arduino = serial.Serial(port=SERIAL_DEV, baudrate=SERIAL_SPEED, timeout=.1)
|
||||
for i in range(start, -1, -1):
|
||||
arduino.write(bytes("CLS\r\n", 'utf8'))
|
||||
arduino.write(bytes("LINE 1\r\n", 'utf8'))
|
||||
|
@ -35,29 +35,16 @@ def countdown(start: int):
|
|||
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():
|
||||
while True:
|
||||
num = int(input("Enter a number (-1=exit): "))
|
||||
if num < 0:
|
||||
sys.exit(0)
|
||||
# countdown(num)
|
||||
countdown2(num)
|
||||
#arduino.write(bytes("CLS\r\n", 'utf8'))
|
||||
#arduino.write(bytes("LINE 1\r\n", 'utf8'))
|
||||
#arduino.write(bytes("ECHO Countdown\r\n", 'utf8'))
|
||||
# arduino.write(bytes("ECHO C " + str(num) + "\r\n", 'utf8'))
|
||||
countdown(num)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
53
mapid.py
53
mapid.py
|
@ -1,53 +0,0 @@
|
|||
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,5 +1,4 @@
|
|||
# requirements.txt
|
||||
|
||||
pyserial>=3.5
|
||||
python-dotenv>=0.5
|
||||
serial
|
||||
|
||||
|
|
Loading…
Reference in a new issue