2013-03-10 18:26:41 +00:00
|
|
|
/*
|
|
|
|
Serial Adapter Project: Dynamic serial TTY passthroughs
|
2013-03-27 01:38:14 +00:00
|
|
|
by: Mike Crosson
|
|
|
|
Nusku Networks
|
|
|
|
date: 2013/03/09
|
|
|
|
license: CC-BY SA 3.0 - Creative commons share-alike 3.0
|
|
|
|
use this code however you'd like, just keep this license and
|
|
|
|
attribute.
|
|
|
|
*/
|
2013-03-10 18:26:41 +00:00
|
|
|
|
2013-03-27 01:38:14 +00:00
|
|
|
#include "ColorLCDShield.h"
|
2013-03-10 18:26:41 +00:00
|
|
|
|
|
|
|
#include "Project.h"
|
2013-03-13 20:29:54 +00:00
|
|
|
#include "UI.h"
|
|
|
|
|
2013-03-27 01:38:14 +00:00
|
|
|
const int okButtonPin= 22;
|
|
|
|
const int cancelButtonPin = 23;
|
|
|
|
|
|
|
|
// variables will change:
|
|
|
|
int okButtonState = 0;
|
|
|
|
int prevOkButtonState = okButtonState;
|
|
|
|
int cancelButtonState = 0;
|
|
|
|
int prevCancelButtonState = 0;
|
|
|
|
|
|
|
|
long upCount = 0;
|
|
|
|
long downCount = 0;
|
|
|
|
|
|
|
|
const int Left = 1;
|
|
|
|
const int Right = 2;
|
|
|
|
const int Up = 3;
|
|
|
|
const int Down = 4;
|
|
|
|
|
|
|
|
int xpin = 0; // After GND / @ edge
|
|
|
|
int ypin = 1; // Between VCC and gnd
|
|
|
|
|
|
|
|
int xAxis;
|
|
|
|
int yAxis;
|
|
|
|
char* myStrings[]={
|
|
|
|
"Left","Right","Up","Down"};
|
|
|
|
int button;
|
|
|
|
|
2013-03-13 20:29:54 +00:00
|
|
|
// Map a mode -> text value
|
|
|
|
char* modeToText[4] = {
|
|
|
|
"Phone UART",
|
|
|
|
"DB9 - Normal",
|
|
|
|
"DB9 - Null Mdm",
|
|
|
|
"Cisco console"
|
|
|
|
};
|
|
|
|
|
|
|
|
// Known and supported line speeds
|
|
|
|
linespeedinfo linespeeds[6] = {
|
2013-03-27 01:38:14 +00:00
|
|
|
{
|
2013-03-29 02:36:44 +00:00
|
|
|
"2400b", 2400 }
|
2013-03-27 01:38:14 +00:00
|
|
|
,
|
|
|
|
{
|
2013-03-29 02:36:44 +00:00
|
|
|
"9600b", 9600 }
|
2013-03-27 01:38:14 +00:00
|
|
|
,
|
|
|
|
{
|
2013-03-29 02:36:44 +00:00
|
|
|
"19.2k", 19200 }
|
2013-03-27 01:38:14 +00:00
|
|
|
,
|
|
|
|
{
|
2013-03-29 02:36:44 +00:00
|
|
|
"38.4k", 38400 }
|
2013-03-27 01:38:14 +00:00
|
|
|
,
|
|
|
|
{
|
2013-03-29 02:36:44 +00:00
|
|
|
"57.5k", 57600 }
|
2013-03-27 01:38:14 +00:00
|
|
|
,
|
|
|
|
{
|
2013-03-29 02:36:44 +00:00
|
|
|
"115k", 115200 }
|
2013-03-13 20:29:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// LCD
|
|
|
|
LCDShield lcd; // Line length max is 16
|
|
|
|
|
|
|
|
// Buttons
|
2013-03-27 01:38:14 +00:00
|
|
|
int buttonPins[3] = {
|
|
|
|
3, 4, 5};
|
2013-03-13 20:29:54 +00:00
|
|
|
|
|
|
|
// Mode info needed
|
|
|
|
serialmode currentMode = none;
|
|
|
|
serialmode selectedMode = none;
|
|
|
|
linespeed currentLineSpeed = zero;
|
|
|
|
|
|
|
|
// Defaults
|
|
|
|
void setDefaults() {
|
|
|
|
setMode(phone);
|
|
|
|
setSelection(phone);
|
|
|
|
setLineSpeed(oneNineteenTwoK);
|
|
|
|
}
|
2013-03-10 18:26:41 +00:00
|
|
|
|
|
|
|
void setup() {
|
|
|
|
/* Set up the button pins as inputs, set pull-up resistor */
|
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
pinMode(buttonPins[i], INPUT);
|
|
|
|
digitalWrite(buttonPins[i], HIGH);
|
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
|
|
|
|
pinMode(okButtonPin, INPUT);
|
|
|
|
pinMode(cancelButtonPin, INPUT);
|
|
|
|
|
2013-03-10 18:26:41 +00:00
|
|
|
/* Initialize the LCD, set the contrast, clear the screen */
|
|
|
|
lcd.init(PHILIPS);
|
|
|
|
lcd.contrast(-63);
|
|
|
|
lcd.clear(BACKGROUND);
|
2013-03-27 01:38:14 +00:00
|
|
|
|
2013-03-10 18:26:41 +00:00
|
|
|
// Print the modes
|
|
|
|
// Uses enum trickery -- don't assign values to serialmode enum values
|
2013-03-10 20:56:25 +00:00
|
|
|
for (int i=0; i<modelinespeed; i++) {
|
2013-03-10 18:26:41 +00:00
|
|
|
printMode((serialmode)i);
|
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
|
2013-03-10 20:23:07 +00:00
|
|
|
// Print the Rx/Tx/Speed titles
|
|
|
|
printTitles();
|
2013-03-27 01:38:14 +00:00
|
|
|
|
2013-03-10 18:26:41 +00:00
|
|
|
// Setup defaults
|
|
|
|
setDefaults();
|
2013-03-29 02:36:44 +00:00
|
|
|
|
|
|
|
Serial.begin(9600);
|
|
|
|
Serial1.begin(9600);
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2013-03-29 02:36:44 +00:00
|
|
|
// read from port 1, send to port 0:
|
|
|
|
if (Serial1.available()) {
|
|
|
|
int inByte = Serial1.read();
|
|
|
|
Serial.write(inByte);
|
|
|
|
}
|
|
|
|
|
|
|
|
// read from port 0, send to port 1:
|
|
|
|
if (Serial.available()) {
|
|
|
|
int inByte = Serial.read();
|
|
|
|
Serial1.write(inByte);
|
|
|
|
}
|
|
|
|
|
2013-03-27 01:38:14 +00:00
|
|
|
xAxis=map(analogRead(xpin), 0, 1023, 0, 10);
|
|
|
|
yAxis=map(analogRead(ypin), 0, 1023, 0, 10);
|
|
|
|
|
2013-03-10 18:48:13 +00:00
|
|
|
// Up
|
2013-03-27 01:38:14 +00:00
|
|
|
if (yAxis > 6 ) {
|
|
|
|
upCount++;
|
|
|
|
if (upCount > 768) {
|
|
|
|
upCount = 0;
|
|
|
|
serialmode newMode = (serialmode)(selectedMode - 1);
|
|
|
|
if (newMode >= 0) {
|
|
|
|
setSelection(newMode);
|
|
|
|
}
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
upCount = 0;
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 18:48:13 +00:00
|
|
|
// Select / Enter
|
2013-03-27 01:38:14 +00:00
|
|
|
if (digitalRead(okButtonPin)) {
|
2013-03-10 18:48:13 +00:00
|
|
|
setMode(selectedMode);
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
|
2013-03-10 18:48:13 +00:00
|
|
|
// Down
|
2013-03-27 01:38:14 +00:00
|
|
|
if (yAxis < 4 ) {
|
|
|
|
downCount++;
|
|
|
|
if (downCount > 768) {
|
|
|
|
serialmode newMode = (serialmode)(selectedMode + 1);
|
|
|
|
if (newMode <= modelinespeed) {
|
|
|
|
setSelection(newMode);
|
|
|
|
}
|
|
|
|
downCount = 0;
|
2013-03-10 18:48:13 +00:00
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
downCount = 0;
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
|
2013-03-29 02:36:44 +00:00
|
|
|
|
|
|
|
|