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
|
|
|
|
|
|
|
#include "Project.h"
|
2013-03-27 01:38:14 +00:00
|
|
|
|
2013-04-05 15:25:23 +00:00
|
|
|
// Button state tracking
|
2013-03-27 01:38:14 +00:00
|
|
|
int okButtonState = 0;
|
|
|
|
int prevOkButtonState = okButtonState;
|
|
|
|
int cancelButtonState = 0;
|
2013-04-05 15:25:23 +00:00
|
|
|
int prevCancelButtonState = prevCancelButtonState;
|
|
|
|
|
|
|
|
// PSP joystick tracking
|
|
|
|
long pspUpCount = 0; // Used to slow down how fast we repeat up movement
|
|
|
|
long pspDownCount = 0; // Used to slow down how fast we repeat down movement
|
|
|
|
int pspXAxisValue;
|
|
|
|
int pspYAxisValue;
|
2013-03-13 20:29:54 +00:00
|
|
|
|
|
|
|
// Mode info needed
|
|
|
|
serialmode currentMode = none;
|
|
|
|
serialmode selectedMode = none;
|
|
|
|
linespeed currentLineSpeed = zero;
|
|
|
|
|
|
|
|
// Defaults
|
|
|
|
void setDefaults() {
|
2013-04-05 15:25:23 +00:00
|
|
|
//FIXME: Re-enable once new LCD is online
|
|
|
|
//setMode(phone);
|
|
|
|
//setSelection(phone);
|
|
|
|
//setLineSpeed(oneNineteenTwoK);
|
2013-03-13 20:29:54 +00:00
|
|
|
}
|
2013-03-10 18:26:41 +00:00
|
|
|
|
|
|
|
void setup() {
|
2013-04-05 15:25:23 +00:00
|
|
|
// Buttons
|
2013-03-27 01:38:14 +00:00
|
|
|
pinMode(okButtonPin, INPUT);
|
|
|
|
pinMode(cancelButtonPin, INPUT);
|
|
|
|
|
2013-04-05 15:25:23 +00:00
|
|
|
// Button LEDs
|
|
|
|
pinMode(okButtonLed, OUTPUT);
|
|
|
|
digitalWrite(okButtonLed, HIGH);
|
|
|
|
pinMode(cancelButtonLed, OUTPUT);
|
|
|
|
digitalWrite(cancelButtonLed, HIGH);
|
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-04-05 15:25:23 +00:00
|
|
|
// Read the x/y values from the joystick
|
|
|
|
pspXAxisValue=map(analogRead(pspXPin), 0, 1023, 0, 10);
|
|
|
|
pspYAxisValue=map(analogRead(pspYPin), 0, 1023, 0, 10);
|
|
|
|
|
|
|
|
// Move cursor Up
|
|
|
|
if (pspYAxisValue > 6 ) {
|
|
|
|
pspUpCount++;
|
|
|
|
if (pspUpCount > 768) {
|
|
|
|
pspUpCount = 0;
|
2013-03-27 01:38:14 +00:00
|
|
|
serialmode newMode = (serialmode)(selectedMode - 1);
|
|
|
|
if (newMode >= 0) {
|
2013-04-05 15:25:23 +00:00
|
|
|
//FIXME: Re-enable once new LCD is online
|
|
|
|
//setSelection(newMode);
|
2013-03-27 01:38:14 +00:00
|
|
|
}
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-04-05 15:25:23 +00:00
|
|
|
pspUpCount = 0;
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
|
2013-04-05 15:25:23 +00:00
|
|
|
// Move cursor Down
|
|
|
|
if (pspYAxisValue < 4 ) {
|
|
|
|
pspDownCount++;
|
|
|
|
if (pspDownCount > 768) {
|
2013-03-27 01:38:14 +00:00
|
|
|
serialmode newMode = (serialmode)(selectedMode + 1);
|
|
|
|
if (newMode <= modelinespeed) {
|
2013-04-05 15:25:23 +00:00
|
|
|
//FIXME: Re-enable once new LCD is online
|
|
|
|
//setSelection(newMode);
|
2013-03-27 01:38:14 +00:00
|
|
|
}
|
2013-04-05 15:25:23 +00:00
|
|
|
pspDownCount = 0;
|
2013-03-10 18:48:13 +00:00
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-04-05 15:25:23 +00:00
|
|
|
pspDownCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Select / Enter
|
|
|
|
if (digitalRead(okButtonPin)) {
|
|
|
|
//FIXME: Re-enable once new LCD is online
|
|
|
|
//setMode(selectedMode);
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-27 01:38:14 +00:00
|
|
|
|
2013-03-29 02:36:44 +00:00
|
|
|
|
|
|
|
|