Rough addition of PSP joystick and dedicated push button; Also ran Arduino IDE code formatter

This commit is contained in:
Mike C 2013-03-26 21:38:14 -04:00
parent 83d840ed39
commit 9c34d4ceaf
2 changed files with 89 additions and 36 deletions

View file

@ -8,7 +8,7 @@
attribute. attribute.
*/ */
#include <ColorLCDShield.h> #include "ColorLCDShield.h"
// Standard colors // Standard colors
#define BACKGROUND BLACK #define BACKGROUND BLACK

View file

@ -1,18 +1,44 @@
/* /*
Serial Adapter Project: Dynamic serial TTY passthroughs Serial Adapter Project: Dynamic serial TTY passthroughs
by: Mike Crosson by: Mike Crosson
Nusku Networks Nusku Networks
date: 2013/03/09 date: 2013/03/09
license: CC-BY SA 3.0 - Creative commons share-alike 3.0 license: CC-BY SA 3.0 - Creative commons share-alike 3.0
use this code however you'd like, just keep this license and use this code however you'd like, just keep this license and
attribute. attribute.
*/ */
#include <ColorLCDShield.h> #include "ColorLCDShield.h"
#include "Project.h" #include "Project.h"
#include "UI.h" #include "UI.h"
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;
// Map a mode -> text value // Map a mode -> text value
char* modeToText[4] = { char* modeToText[4] = {
"Phone UART", "Phone UART",
@ -23,19 +49,31 @@ char* modeToText[4] = {
// Known and supported line speeds // Known and supported line speeds
linespeedinfo linespeeds[6] = { linespeedinfo linespeeds[6] = {
{"2400b", 2400}, {
{"9600b", 9600}, "2400b", 2400 }
{"19.2k", 19200}, ,
{"38.4k", 38400}, {
{"57.5k", 57600}, "9600b", 9600 }
{"115k", 115200} ,
{
"19.2k", 19200 }
,
{
"38.4k", 38400 }
,
{
"57.5k", 57600 }
,
{
"115k", 115200 }
}; };
// LCD // LCD
LCDShield lcd; // Line length max is 16 LCDShield lcd; // Line length max is 16
// Buttons // Buttons
int buttonPins[3] = {3, 4, 5}; int buttonPins[3] = {
3, 4, 5};
// Mode info needed // Mode info needed
serialmode currentMode = none; serialmode currentMode = none;
@ -55,50 +93,65 @@ void setup() {
pinMode(buttonPins[i], INPUT); pinMode(buttonPins[i], INPUT);
digitalWrite(buttonPins[i], HIGH); digitalWrite(buttonPins[i], HIGH);
} }
pinMode(okButtonPin, INPUT);
pinMode(cancelButtonPin, INPUT);
/* Initialize the LCD, set the contrast, clear the screen */ /* Initialize the LCD, set the contrast, clear the screen */
lcd.init(PHILIPS); lcd.init(PHILIPS);
lcd.contrast(-63); lcd.contrast(-63);
lcd.clear(BACKGROUND); lcd.clear(BACKGROUND);
// Print the modes // Print the modes
// Uses enum trickery -- don't assign values to serialmode enum values // Uses enum trickery -- don't assign values to serialmode enum values
for (int i=0; i<modelinespeed; i++) { for (int i=0; i<modelinespeed; i++) {
printMode((serialmode)i); printMode((serialmode)i);
} }
// Print the Rx/Tx/Speed titles // Print the Rx/Tx/Speed titles
printTitles(); printTitles();
// Setup defaults // Setup defaults
setDefaults(); setDefaults();
} }
void loop() { void loop() {
xAxis=map(analogRead(xpin), 0, 1023, 0, 10);
yAxis=map(analogRead(ypin), 0, 1023, 0, 10);
// Up // Up
if (!digitalRead(buttonPins[2])) { if (yAxis > 6 ) {
serialmode newMode = (serialmode)(selectedMode - 1); upCount++;
if (newMode >= 0) { if (upCount > 768) {
setSelection(newMode); upCount = 0;
serialmode newMode = (serialmode)(selectedMode - 1);
if (newMode >= 0) {
setSelection(newMode);
}
} }
// Wait for release before going on }
while(!digitalRead(buttonPins[2])); else {
upCount = 0;
} }
// Select / Enter // Select / Enter
if (!digitalRead(buttonPins[1])) { if (digitalRead(okButtonPin)) {
setMode(selectedMode); setMode(selectedMode);
// Wait for release before going on
while(!digitalRead(buttonPins[1]));
} }
// Down // Down
if (!digitalRead(buttonPins[0])) { if (yAxis < 4 ) {
serialmode newMode = (serialmode)(selectedMode + 1); downCount++;
if (newMode <= modelinespeed) { if (downCount > 768) {
setSelection(newMode); serialmode newMode = (serialmode)(selectedMode + 1);
if (newMode <= modelinespeed) {
setSelection(newMode);
}
downCount = 0;
} }
// Wait for release before going on }
while(!digitalRead(buttonPins[0])); else {
downCount = 0;
} }
} }