From 59eeabc7850c49f47e12fb0e195f627eb33fcd9a Mon Sep 17 00:00:00 2001 From: Mike C Date: Sat, 6 Apr 2013 16:31:44 -0400 Subject: [PATCH] Make compile, finish button programming -- Still mid-refactor --- Universal_Serial_Adapter/Project.h | 12 ++-- Universal_Serial_Adapter/UI.h | 18 ++--- Universal_Serial_Adapter/UIButton.cpp | 14 +++- Universal_Serial_Adapter/UIButton.h | 2 +- Universal_Serial_Adapter/UIJoystickPSP.h | 72 ++++++++++--------- .../Universal_Serial_Adapter.ino | 23 +++--- 6 files changed, 77 insertions(+), 64 deletions(-) diff --git a/Universal_Serial_Adapter/Project.h b/Universal_Serial_Adapter/Project.h index b95df17..eff0a91 100644 --- a/Universal_Serial_Adapter/Project.h +++ b/Universal_Serial_Adapter/Project.h @@ -11,11 +11,13 @@ #ifndef Project_h #define Project_h +#define DEBUG true // For controlling debug output via serial + // Pinout / things that need configuration -#define okButtonPin 23 -#define okButtonLed 22 -#define cancelButtonPin 25 -#define cancelButtonLed 24 +#define okButtonPin 22 +#define okButtonLed 23 +#define cancelButtonPin 24 +#define cancelButtonLed 25 #define pspXPin 0 // After GND / @ edge #define pspYPin 1 // Between VCC and gnd // LCD Pinouts @@ -56,7 +58,7 @@ enum voltage { onePointEight, threePointThree, five, - zero=-1 + negOne=-1 }; extern char* voltageToText[]; diff --git a/Universal_Serial_Adapter/UI.h b/Universal_Serial_Adapter/UI.h index 22145e8..51a1e99 100644 --- a/Universal_Serial_Adapter/UI.h +++ b/Universal_Serial_Adapter/UI.h @@ -8,17 +8,11 @@ attribute. */ -UI State machine (current element = config / stats / inline display of data) -Configuration state machine (speed, pinout, logic level, sd card on/off, boot logo on/off) -Message to config (element + new value) -Message to UI (element + success/fail) +// UI State machine (current element = config / stats / inline display of data) +// Configuration state machine (speed, pinout, logic level, sd card on/off, boot logo on/off) +// Message to config (element + new value) +// Message to UI (element + success/fail) // Button's controlling UI -UIButton* okButton = new UIButton(22, 23); -UIButton* cancelButton = new UIButton(24, 25); - - // Select / Enter - if (okButton->isPressed()) { - //FIXME: Re-enable once new LCD is online - //setMode(selectedMode); - } \ No newline at end of file +// UIButton* okButton = new UIButton(22, 23); +// UIButton* cancelButton = new UIButton(24, 25); diff --git a/Universal_Serial_Adapter/UIButton.cpp b/Universal_Serial_Adapter/UIButton.cpp index 9019258..8138fb0 100644 --- a/Universal_Serial_Adapter/UIButton.cpp +++ b/Universal_Serial_Adapter/UIButton.cpp @@ -10,10 +10,12 @@ #include "Arduino.h" #include "UIButton.h" +#include "Project.h" UIButton::UIButton(int buttonPin, int ledPin) { this->buttonPin = buttonPin; this->ledPin = ledPin; + setup(); } void UIButton::setup() { @@ -24,13 +26,23 @@ void UIButton::setup() { } void UIButton::turnOnLed() { + if (DEBUG) { + Serial.print("Turning on pin: "); + Serial.println(ledPin); + } digitalWrite(ledPin, HIGH); } void UIButton::turnOffLed() { + if (DEBUG) { + Serial.print("Turning off pin: "); + Serial.println(ledPin); + } digitalWrite(ledPin, LOW); } bool UIButton::isPressed() { - return digitalRead(buttonPin); + bool pressed = digitalRead(buttonPin); + while (digitalRead(buttonPin)); // Wait for release + return pressed; } diff --git a/Universal_Serial_Adapter/UIButton.h b/Universal_Serial_Adapter/UIButton.h index 25e9037..2521546 100644 --- a/Universal_Serial_Adapter/UIButton.h +++ b/Universal_Serial_Adapter/UIButton.h @@ -15,10 +15,10 @@ class UIButton { private: int buttonPin; int ledPin; + void setup(); public: UIButton(int buttonPin, int ledPin); - void setup(); void turnOnLed(); void turnOffLed(); bool isPressed(); diff --git a/Universal_Serial_Adapter/UIJoystickPSP.h b/Universal_Serial_Adapter/UIJoystickPSP.h index 63f043c..4b7e025 100644 --- a/Universal_Serial_Adapter/UIJoystickPSP.h +++ b/Universal_Serial_Adapter/UIJoystickPSP.h @@ -9,43 +9,45 @@ */ // 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 pspUpCount = 0; // Used to slow down how fast we repeat up movement +int pspDownCount = 0; // Used to slow down how fast we repeat down movement int pspXAxisValue; int pspYAxisValue; -// Read the x/y values from the joystick - pspXAxisValue=map(analogRead(pspXPin), 0, 1023, 0, 10); - pspYAxisValue=map(analogRead(pspYPin), 0, 1023, 0, 10); +// void readPSPValues() { +// // 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; - serialmode newMode = (serialmode)(selectedMode - 1); - if (newMode >= 0) { - //FIXME: Re-enable once new LCD is online - //setSelection(newMode); - } - } - } - else { - pspUpCount = 0; - } +// // Move cursor Up +// if (pspYAxisValue > 6 ) { +// pspUpCount++; +// if (pspUpCount > 768) { +// pspUpCount = 0; +// serialmode newMode = (serialmode)(selectedMode - 1); +// if (newMode >= 0) { +// //FIXME: Re-enable once new LCD is online +// //setSelection(newMode); +// } +// } +// } +// else { +// 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; - } \ No newline at end of file +// // 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; +// } +// } \ No newline at end of file diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index 3467ab7..f77e3f6 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -10,13 +10,8 @@ #include "Project.h" -// Mode info needed -serialmode currentMode = none; -serialmode selectedMode = none; -linespeed currentLineSpeed = zero; -linespeed selectedLineSpeed = zero; -voltage currentVoltage = zero; -voltage selectedVoltage = zero; +UIButton* okButton; +UIButton* cancelButton; // Defaults void setDefaults() { @@ -27,14 +22,22 @@ void setDefaults() { } void setup() { + Serial.begin(9600); + Serial.println("Setup!"); // Setup defaults setDefaults(); - Serial.begin(9600); - Serial1.begin(9600); + okButton = new UIButton(okButtonPin, okButtonLed); + cancelButton = new UIButton(cancelButtonPin, cancelButtonLed); } void loop() { - + if (okButton->isPressed()) { + Serial.println("OK Button Pressed"); + } + + if (cancelButton->isPressed()) { + Serial.println("Cancel button pressed"); + } }