From 82b20bcd0319d3dcb7460800f88d3fc3e154b408 Mon Sep 17 00:00:00 2001 From: Mike C Date: Fri, 5 Apr 2013 11:25:23 -0400 Subject: [PATCH] Start of massive refactor / rewrite to bring all of the various components and circuits online that were developed independent of the original code base / platform --- Universal_Serial_Adapter/Project.cpp | 29 +++ Universal_Serial_Adapter/Project.h | 17 +- .../Universal_Serial_Adapter.ino | 166 +++++------------- 3 files changed, 86 insertions(+), 126 deletions(-) create mode 100644 Universal_Serial_Adapter/Project.cpp diff --git a/Universal_Serial_Adapter/Project.cpp b/Universal_Serial_Adapter/Project.cpp new file mode 100644 index 0000000..628f786 --- /dev/null +++ b/Universal_Serial_Adapter/Project.cpp @@ -0,0 +1,29 @@ +/* + Serial Adapter Project: Dynamic serial TTY passthroughs + 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. +*/ + +#include "Project.h" + +// 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] = { + { "2400b", 2400 }, + { "9600b", 9600 }, + { "19.2k", 19200 }, + { "38.4k", 38400 }, + { "57.5k", 57600 }, + { "115k", 115200 } +}; \ No newline at end of file diff --git a/Universal_Serial_Adapter/Project.h b/Universal_Serial_Adapter/Project.h index 1163dbb..fe206ac 100644 --- a/Universal_Serial_Adapter/Project.h +++ b/Universal_Serial_Adapter/Project.h @@ -8,7 +8,16 @@ attribute. */ -#include "ColorLCDShield.h" +// Pinout / things that need configuration +#define okButtonPin 23 +#define okButtonLed 22 +#define cancelButtonPin 25 +#define cancelButtonLed 24 +#define pspXPin 0 // After GND / @ edge +#define pspYPin 1 // Between VCC and gnd + +// Don't change anything below here +// ----------------------------------------------------------------------------- // Standard colors #define BACKGROUND BLACK @@ -51,12 +60,6 @@ struct linespeedinfo { // Known and supported line speeds extern linespeedinfo linespeeds[]; -// LCD -extern LCDShield lcd; // Line length max is 16 - -// Buttons -extern int buttonPins[]; - // Mode info needed extern serialmode currentMode; extern serialmode selectedMode; diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index c13f889..c760334 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -8,72 +8,19 @@ attribute. */ -#include "ColorLCDShield.h" - #include "Project.h" -#include "UI.h" -const int okButtonPin= 22; -const int cancelButtonPin = 23; - -// variables will change: +// Button state tracking int okButtonState = 0; int prevOkButtonState = okButtonState; int cancelButtonState = 0; -int prevCancelButtonState = 0; +int prevCancelButtonState = prevCancelButtonState; -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; - -// 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] = { - { - "2400b", 2400 } - , - { - "9600b", 9600 } - , - { - "19.2k", 19200 } - , - { - "38.4k", 38400 } - , - { - "57.5k", 57600 } - , - { - "115k", 115200 } -}; - -// LCD -LCDShield lcd; // Line length max is 16 - -// Buttons -int buttonPins[3] = { - 3, 4, 5}; +// 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; // Mode info needed serialmode currentMode = none; @@ -82,34 +29,22 @@ linespeed currentLineSpeed = zero; // Defaults void setDefaults() { - setMode(phone); - setSelection(phone); - setLineSpeed(oneNineteenTwoK); + //FIXME: Re-enable once new LCD is online + //setMode(phone); + //setSelection(phone); + //setLineSpeed(oneNineteenTwoK); } 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); - } - + // Buttons pinMode(okButtonPin, INPUT); pinMode(cancelButtonPin, INPUT); - /* Initialize the LCD, set the contrast, clear the screen */ - lcd.init(PHILIPS); - lcd.contrast(-63); - lcd.clear(BACKGROUND); - - // Print the modes - // Uses enum trickery -- don't assign values to serialmode enum values - for (int i=0; i 6 ) { - upCount++; - if (upCount > 768) { - upCount = 0; + // Move cursor Up + if (pspYAxisValue > 6 ) { + pspUpCount++; + if (pspUpCount > 768) { + pspUpCount = 0; serialmode newMode = (serialmode)(selectedMode - 1); if (newMode >= 0) { - setSelection(newMode); + //FIXME: Re-enable once new LCD is online + //setSelection(newMode); } } } else { - upCount = 0; + pspUpCount = 0; } + // Move cursor Down + if (pspYAxisValue < 4 ) { + pspDownCount++; + if (pspDownCount > 768) { + serialmode newMode = (serialmode)(selectedMode + 1); + if (newMode <= modelinespeed) { + //FIXME: Re-enable once new LCD is online + //setSelection(newMode); + } + pspDownCount = 0; + } + } + else { + pspDownCount = 0; + } + + // Select / Enter if (digitalRead(okButtonPin)) { - setMode(selectedMode); - } - - // Down - if (yAxis < 4 ) { - downCount++; - if (downCount > 768) { - serialmode newMode = (serialmode)(selectedMode + 1); - if (newMode <= modelinespeed) { - setSelection(newMode); - } - downCount = 0; - } - } - else { - downCount = 0; + //FIXME: Re-enable once new LCD is online + //setMode(selectedMode); } }