From 4bb75e25fcc442e7851a921d073b02a0a5d49497 Mon Sep 17 00:00:00 2001 From: Mike C Date: Fri, 5 Apr 2013 12:41:21 -0400 Subject: [PATCH] Restarted UI refactor; Push button class compiles. --- Universal_Serial_Adapter/Project.h | 4 +++ Universal_Serial_Adapter/UI.cpp | 10 ++++++ Universal_Serial_Adapter/UI.h | 10 ++++++ Universal_Serial_Adapter/UIButton.cpp | 36 +++++++++++++++++++ Universal_Serial_Adapter/UIButton.h | 27 ++++++++++++++ Universal_Serial_Adapter/UIJoystickPSP.cpp | 10 ++++++ Universal_Serial_Adapter/UIJoystickPSP.h | 10 ++++++ Universal_Serial_Adapter/UILCD.cpp | 10 ++++++ Universal_Serial_Adapter/UILCD.h | 10 ++++++ .../Universal_Serial_Adapter.ino | 20 +++-------- 10 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 Universal_Serial_Adapter/UI.cpp create mode 100644 Universal_Serial_Adapter/UI.h create mode 100644 Universal_Serial_Adapter/UIButton.cpp create mode 100644 Universal_Serial_Adapter/UIButton.h create mode 100644 Universal_Serial_Adapter/UIJoystickPSP.cpp create mode 100644 Universal_Serial_Adapter/UIJoystickPSP.h create mode 100644 Universal_Serial_Adapter/UILCD.cpp create mode 100644 Universal_Serial_Adapter/UILCD.h 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); }