mapid/MAPID-CP/MAPID-CP.ino

206 lines
3.8 KiB
Arduino
Raw Normal View History

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
SCmd.addCommand("ECHO", lcdEcho);
SCmd.addCommand("CLS", lcdClear);
SCmd.addCommand("LINE", lcdLine);
// Show README
SCmd.addCommand("README", showReadMe);
SCmd.addDefaultHandler(commandNotFound);
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();
}
void commandNotFound() {
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);
Serial.print("Hardware: ");
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(" CLS");
Serial.println(" ON");
Serial.println(" OFF");
Serial.println(" ECHO Text");
Serial.println(" LINE i");
// Show prompt again
Serial.println();
Serial.print(TTY_PROMPT);
}
void ledOn() {
Serial.println("");
Serial.println("Turning LED to *ON*");
//lcd.println("LED on");
digitalWrite(PIN_LED, HIGH);
// Show prompt again
Serial.print(TTY_PROMPT);
}
void ledOff() {
Serial.println("");
Serial.println("Turning LED to *OFF*");
//lcd.println("LED off");
digitalWrite(PIN_LED, LOW);
// Show prompt again
Serial.print(TTY_PROMPT);
}