Re-implemented PSP joystick as dedicated class

This commit is contained in:
Mike C 2013-04-06 17:01:46 -04:00
parent 59eeabc785
commit c83891d765
3 changed files with 86 additions and 47 deletions

View file

@ -1,5 +1,5 @@
/* /*
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
@ -8,3 +8,58 @@
attribute. attribute.
*/ */
#include "Arduino.h"
#include "Project.h"
#include "UIJoystickPSP.h"
UIJoystickPSP::UIJoystickPSP(int xAxisPin, int yAxisPin) {
this->xAxisPin = xAxisPin;
this->yAxisPin = yAxisPin;
upCount = 0;
downCount = 0;
leftCount = 0;
rightCount = 0;
previousDirection = joyNone;
}
joyDirection UIJoystickPSP::direction() {
// Read the x/y values from the joystick
xAxisValue = map(analogRead(xAxisPin), 0, 1023, 0, 10);
yAxisValue = map(analogRead(yAxisPin), 0, 1023, 0, 10);
if (yAxisValue > 6 ) {
upCount++;
if (upCount > 768) {
upCount = 0;
return joyUp;
}
}
if (yAxisValue < 4 ) {
downCount++;
if (downCount > 768) {
downCount = 0;
return joyDown;
}
}
if (xAxisValue > 6) {
leftCount++;
if (leftCount > 768) {
leftCount = 0;
return joyLeft;
}
}
if (xAxisValue < 4) {
rightCount++;
if (rightCount > 768) {
rightCount = 0;
return joyRight;
}
}
return joyNone;
}

View file

@ -8,46 +8,28 @@
attribute. attribute.
*/ */
// PSP joystick tracking #include "Project.h"
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;
// void readPSPValues() { enum joyDirection {
// // Read the x/y values from the joystick joyUp,
// pspXAxisValue=map(analogRead(pspXPin), 0, 1023, 0, 10); joyDown,
// pspYAxisValue=map(analogRead(pspYPin), 0, 1023, 0, 10); joyLeft,
joyRight,
joyNone=-1
};
// // Move cursor Up class UIJoystickPSP {
// if (pspYAxisValue > 6 ) { private:
// pspUpCount++; int xAxisPin, yAxisPin; // Pins in use
// if (pspUpCount > 768) { int xAxisValue, yAxisValue; // Values read from pins
// pspUpCount = 0; int upCount, downCount, leftCount, rightCount; // Counts to slow down repeat
// serialmode newMode = (serialmode)(selectedMode - 1);
// if (newMode >= 0) {
// //FIXME: Re-enable once new LCD is online
// //setSelection(newMode);
// }
// }
// }
// else {
// pspUpCount = 0;
// }
// // Move cursor Down joyDirection previousDirection;
// if (pspYAxisValue < 4 ) {
// pspDownCount++; // int readXAxisValue();
// if (pspDownCount > 768) { // int readYAxisValue();
// serialmode newMode = (serialmode)(selectedMode + 1);
// if (newMode <= modelinespeed) { public:
// //FIXME: Re-enable once new LCD is online UIJoystickPSP(int xAxisPin, int yAxisPin);
// //setSelection(newMode); joyDirection direction();
// } };
// pspDownCount = 0;
// }
// }
// else {
// pspDownCount = 0;
// }
// }

View file

@ -9,9 +9,12 @@
*/ */
#include "Project.h" #include "Project.h"
#include "UIButton.h"
#include "UIJoystickPSP.h"
UIButton* okButton; UIButton* okButton;
UIButton* cancelButton; UIButton* cancelButton;
UIJoystickPSP* pspJoystick;
// Defaults // Defaults
void setDefaults() { void setDefaults() {
@ -30,14 +33,13 @@ void setup() {
okButton = new UIButton(okButtonPin, okButtonLed); okButton = new UIButton(okButtonPin, okButtonLed);
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed); cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
pspJoystick = new UIJoystickPSP(pspXPin, pspYPin);
} }
void loop() { void loop() {
if (okButton->isPressed()) { int direction = pspJoystick->direction();
Serial.println("OK Button Pressed"); if (direction != joyNone) {
} Serial.print("Joystick Direction: ");
Serial.println(direction);
if (cancelButton->isPressed()) {
Serial.println("Cancel button pressed");
} }
} }