diff --git a/Universal_Serial_Adapter/Project.h b/Universal_Serial_Adapter/Project.h index fe206ac..5e84654 100644 --- a/Universal_Serial_Adapter/Project.h +++ b/Universal_Serial_Adapter/Project.h @@ -8,6 +8,9 @@ attribute. */ +#ifndef Project_h +#define Project_h + // Pinout / things that need configuration #define okButtonPin 23 #define okButtonLed 22 @@ -65,3 +68,4 @@ extern serialmode currentMode; extern serialmode selectedMode; extern linespeed currentLineSpeed; +#endif diff --git a/Universal_Serial_Adapter/UI.cpp b/Universal_Serial_Adapter/UI.cpp new file mode 100644 index 0000000..9e4d7f2 --- /dev/null +++ b/Universal_Serial_Adapter/UI.cpp @@ -0,0 +1,10 @@ +/* + 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. + */ + diff --git a/Universal_Serial_Adapter/UI.h b/Universal_Serial_Adapter/UI.h new file mode 100644 index 0000000..9e4d7f2 --- /dev/null +++ b/Universal_Serial_Adapter/UI.h @@ -0,0 +1,10 @@ +/* + 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. + */ + diff --git a/Universal_Serial_Adapter/UIButton.cpp b/Universal_Serial_Adapter/UIButton.cpp new file mode 100644 index 0000000..9019258 --- /dev/null +++ b/Universal_Serial_Adapter/UIButton.cpp @@ -0,0 +1,36 @@ +/* + 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 "Arduino.h" +#include "UIButton.h" + +UIButton::UIButton(int buttonPin, int ledPin) { + this->buttonPin = buttonPin; + this->ledPin = ledPin; +} + +void UIButton::setup() { + pinMode(buttonPin, INPUT); + pinMode(ledPin, OUTPUT); + + turnOnLed(); +} + +void UIButton::turnOnLed() { + digitalWrite(ledPin, HIGH); +} + +void UIButton::turnOffLed() { + digitalWrite(ledPin, LOW); +} + +bool UIButton::isPressed() { + return digitalRead(buttonPin); +} diff --git a/Universal_Serial_Adapter/UIButton.h b/Universal_Serial_Adapter/UIButton.h new file mode 100644 index 0000000..25e9037 --- /dev/null +++ b/Universal_Serial_Adapter/UIButton.h @@ -0,0 +1,27 @@ +/* + 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. + */ + +#ifndef UIButton_h +#define UIButton_h + +class UIButton { +private: + int buttonPin; + int ledPin; + +public: + UIButton(int buttonPin, int ledPin); + void setup(); + void turnOnLed(); + void turnOffLed(); + bool isPressed(); +}; + +#endif diff --git a/Universal_Serial_Adapter/UIJoystickPSP.cpp b/Universal_Serial_Adapter/UIJoystickPSP.cpp new file mode 100644 index 0000000..9e4d7f2 --- /dev/null +++ b/Universal_Serial_Adapter/UIJoystickPSP.cpp @@ -0,0 +1,10 @@ +/* + 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. + */ + diff --git a/Universal_Serial_Adapter/UIJoystickPSP.h b/Universal_Serial_Adapter/UIJoystickPSP.h new file mode 100644 index 0000000..9e4d7f2 --- /dev/null +++ b/Universal_Serial_Adapter/UIJoystickPSP.h @@ -0,0 +1,10 @@ +/* + 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. + */ + diff --git a/Universal_Serial_Adapter/UILCD.cpp b/Universal_Serial_Adapter/UILCD.cpp new file mode 100644 index 0000000..9e4d7f2 --- /dev/null +++ b/Universal_Serial_Adapter/UILCD.cpp @@ -0,0 +1,10 @@ +/* + 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. + */ + diff --git a/Universal_Serial_Adapter/UILCD.h b/Universal_Serial_Adapter/UILCD.h new file mode 100644 index 0000000..9e4d7f2 --- /dev/null +++ b/Universal_Serial_Adapter/UILCD.h @@ -0,0 +1,10 @@ +/* + 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. + */ + diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index c760334..3782cd2 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -9,12 +9,11 @@ */ #include "Project.h" +#include "UIButton.h" -// Button state tracking -int okButtonState = 0; -int prevOkButtonState = okButtonState; -int cancelButtonState = 0; -int prevCancelButtonState = prevCancelButtonState; +// Button's controlling UI +UIButton* okButton = new UIButton(22, 23); +UIButton* cancelButton = new UIButton(24, 25); // PSP joystick tracking long pspUpCount = 0; // Used to slow down how fast we repeat up movement @@ -36,15 +35,6 @@ void setDefaults() { } void setup() { - // Buttons - pinMode(okButtonPin, INPUT); - pinMode(cancelButtonPin, INPUT); - - // Button LEDs - pinMode(okButtonLed, OUTPUT); - digitalWrite(okButtonLed, HIGH); - pinMode(cancelButtonLed, OUTPUT); - digitalWrite(cancelButtonLed, HIGH); // Setup defaults setDefaults(); @@ -92,7 +82,7 @@ void loop() { // Select / Enter - if (digitalRead(okButtonPin)) { + if (okButton->isPressed()) { //FIXME: Re-enable once new LCD is online //setMode(selectedMode); }