2023-10-15 11:11:56 +02:00
|
|
|
/**
|
|
|
|
* MAPID/CP
|
|
|
|
*
|
|
|
|
* Malte's Arduino-Powered Info Display Control Program
|
|
|
|
*/
|
|
|
|
#include <SoftwareSerial.h>
|
|
|
|
#include <serLCD.h>
|
|
|
|
#include <SerialCommand.h>
|
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
|
|
|
|
#include "boards.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "readme.h"
|
|
|
|
|
|
|
|
#ifndef README_PROGMEM
|
|
|
|
#pragma warning "README_PROGMEM not set. The command README will not work."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SerialCommand SCmd;
|
|
|
|
serLCD lcd(PIN_LCD);
|
|
|
|
int line;
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
pinMode(PIN_LED, OUTPUT);
|
|
|
|
digitalWrite(PIN_LED, LOW);
|
|
|
|
|
|
|
|
Serial.begin(TTY_SPEED);
|
|
|
|
while (!Serial);
|
|
|
|
|
|
|
|
Serial.print("Booting...");
|
|
|
|
|
|
|
|
// Generic
|
|
|
|
SCmd.addCommand("VER", showVersion);
|
|
|
|
SCmd.addCommand("GETTY", showGetty);
|
|
|
|
SCmd.addCommand("HELP", help);
|
|
|
|
// LED
|
|
|
|
SCmd.addCommand("ON", ledOn);
|
|
|
|
SCmd.addCommand("OFF", ledOff);
|
|
|
|
// LCD
|
2023-10-26 20:43:47 +02:00
|
|
|
SCmd.addCommand("LCDON", lcdOn);
|
|
|
|
SCmd.addCommand("LCDOFF", lcdOff);
|
|
|
|
|
2023-10-15 11:11:56 +02:00
|
|
|
SCmd.addCommand("ECHO", lcdEcho);
|
|
|
|
SCmd.addCommand("CLS", lcdClear);
|
|
|
|
SCmd.addCommand("LINE", lcdLine);
|
|
|
|
// Show README
|
|
|
|
SCmd.addCommand("README", showReadMe);
|
|
|
|
|
2023-10-15 18:00:37 +02:00
|
|
|
SCmd.setDefaultHandler(commandNotFound);
|
2023-10-15 11:11:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Ready.");
|
|
|
|
Serial.print("Running ");
|
|
|
|
Serial.print(OS_NAME);
|
|
|
|
Serial.print(" v");
|
|
|
|
Serial.println(OS_VERSION);
|
|
|
|
Serial.println("Connected to TTY");
|
|
|
|
|
|
|
|
Serial.println("[INFO] Commands are all uppercase!");
|
|
|
|
line = 1;
|
|
|
|
lcd.clear();
|
|
|
|
lcd.selectLine(line);
|
|
|
|
lcd.print("Welcome to");
|
|
|
|
lcd.selectLine(2);
|
|
|
|
lcd.print(OS_NAME);
|
|
|
|
lcd.print(" v");
|
|
|
|
lcd.print(OS_VERSION);
|
|
|
|
|
|
|
|
// Show prompt
|
|
|
|
Serial.println();
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
SCmd.readSerial();
|
|
|
|
}
|
|
|
|
|
2023-10-15 18:00:37 +02:00
|
|
|
void commandNotFound(char *cmd) {
|
2023-10-15 11:11:56 +02:00
|
|
|
Serial.println("");
|
|
|
|
//Serial.println("[ERROR @ TTY:IN] COMMAND NOT FOUND!");
|
|
|
|
Serial.println("[ERROR] COMMAND NOT FOUND!");
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lcdEcho() {
|
|
|
|
Serial.println("");
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
//lcd.clear();
|
|
|
|
Serial.print(" [INFO] Writing text to LCD: ");
|
|
|
|
for (int i=0; i<16; i++) {
|
|
|
|
// Loop repeats once per token
|
|
|
|
//text = text = SCmd.next();
|
|
|
|
text = SCmd.next();
|
|
|
|
|
|
|
|
if (text == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Since tokens don't include SPACE, print it to debug OUTPUT
|
|
|
|
if (i > 0)
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(text);
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
lcd.print(" ");
|
|
|
|
lcd.print(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.println();
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcdLine() {
|
|
|
|
Serial.println("");
|
|
|
|
line = atoi(SCmd.next());
|
|
|
|
Serial.print(" [INFO] Select line ");
|
|
|
|
Serial.print(line);
|
|
|
|
Serial.println("");
|
|
|
|
lcd.selectLine(line);
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcdClear() {
|
|
|
|
Serial.println("");
|
|
|
|
lcd.clear();
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.println();
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void showVersion() {
|
|
|
|
Serial.println("");
|
|
|
|
Serial.print(OS_NAME);
|
|
|
|
Serial.print(" v");
|
|
|
|
Serial.println(OS_VERSION);
|
2023-10-15 18:00:37 +02:00
|
|
|
Serial.print("Hardware: Arduino ");
|
2023-10-15 11:11:56 +02:00
|
|
|
Serial.println(BOARD);
|
|
|
|
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void showGetty() {
|
|
|
|
Serial.println("");
|
|
|
|
lcd.clear();
|
|
|
|
lcd.selectLine(1);
|
|
|
|
lcd.print("Welcome to");
|
|
|
|
lcd.selectLine(2);
|
|
|
|
lcd.print(OS_NAME);
|
|
|
|
lcd.print(" v");
|
|
|
|
lcd.print(OS_VERSION);
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void showReadMe() {
|
|
|
|
#ifdef README_PROGMEM
|
|
|
|
Serial.print(readme);
|
|
|
|
#else
|
|
|
|
Serial.println("Option README_PROGMEM not set in config.h!");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void help() {
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("Commands:");
|
|
|
|
Serial.println(" VER");
|
|
|
|
Serial.println(" GETTY");
|
|
|
|
Serial.println(" HELP");
|
|
|
|
Serial.println(" ON");
|
|
|
|
Serial.println(" OFF");
|
2023-10-26 20:43:47 +02:00
|
|
|
Serial.println(" LCDON");
|
|
|
|
Serial.println(" LCDOFF");
|
2023-10-15 11:11:56 +02:00
|
|
|
Serial.println(" ECHO Text");
|
2023-10-26 20:43:47 +02:00
|
|
|
Serial.println(" CLS");
|
2023-10-15 11:11:56 +02:00
|
|
|
Serial.println(" LINE i");
|
2023-10-26 20:43:47 +02:00
|
|
|
#ifdef README_PROGMEM
|
|
|
|
Serial.println(" README");
|
|
|
|
#endif
|
2023-10-15 11:11:56 +02:00
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.println();
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ledOn() {
|
|
|
|
Serial.println("");
|
|
|
|
|
2023-10-26 20:43:47 +02:00
|
|
|
Serial.println("Turning LED to *ON*");
|
2023-10-15 11:11:56 +02:00
|
|
|
//lcd.println("LED on");
|
|
|
|
digitalWrite(PIN_LED, HIGH);
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ledOff() {
|
|
|
|
Serial.println("");
|
|
|
|
|
2023-10-26 20:43:47 +02:00
|
|
|
Serial.println("Turning LED to *OFF*");
|
2023-10-15 11:11:56 +02:00
|
|
|
//lcd.println("LED off");
|
|
|
|
digitalWrite(PIN_LED, LOW);
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
2023-10-26 20:43:47 +02:00
|
|
|
|
|
|
|
void lcdOn() {
|
|
|
|
Serial.println("");
|
|
|
|
|
|
|
|
// Turn display on
|
|
|
|
Serial.println("Turning LCD screen to *ON*");
|
|
|
|
lcd.display();
|
|
|
|
lcd.setBrightness(30);
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcdOff() {
|
|
|
|
Serial.println("");
|
|
|
|
|
|
|
|
// Turn display on
|
|
|
|
Serial.println("Turning LCD screen to *OFF*");
|
|
|
|
lcd.noDisplay();
|
|
|
|
lcd.setBrightness(1);
|
|
|
|
|
|
|
|
// Show prompt again
|
|
|
|
Serial.print(TTY_PROMPT);
|
|
|
|
}
|