Skip to content

Commit

Permalink
Fix joystick directions, change default scene to main
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiNakamura committed May 1, 2024
1 parent bcc5708 commit 21809f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/Squidbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ class Squidbox {
const char *getName();

private:
Scene *scenes[NUM_SCENES]; ///< An array of pointers to the scenes in the
///< Squidbox
int currentScene = BUTTON_SCENE; ///< The index of the current scene
Screen *screen; ///< A pointer to the screen of the Squidbox
Joystick *joystick; ///< A pointer to the joystick of the Squidbox
Knob *knob; ///< A pointer to the knob of the Squidbox
Scene *scenes[NUM_SCENES]; ///< An array of pointers to the scenes in the
///< Squidbox
int currentScene = MAIN_SCENE; ///< The index of the current scene
Screen *screen; ///< A pointer to the screen of the Squidbox
Joystick *joystick; ///< A pointer to the joystick of the Squidbox
Knob *knob; ///< A pointer to the knob of the Squidbox
Button *backButton; ///< A pointer to the back button of the Squidbox
Button *okButton; ///< A pointer to the OK button of the Squidbox
Button *buttons[NUM_BUTTONS]; ///< An array of pointers to the buttons of the
Expand Down
24 changes: 8 additions & 16 deletions src/components/joystick/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,31 @@ float Joystick::map(float x, float inMin, float inMax, float outMin,
}

float Joystick::convertRawValue(int raw, int center, int min, int max) {
// Note that the raw value is inverted because the joystick is rotated 90
// degrees to the left.
if (raw > center) {
// If the raw value is greater than the center value, map it from the range
// [center, max] to [0, 1].
return map(raw, center, max, 0, 1);
return map(raw, center, max, 0, -1);
} else {
// If the raw value is less than or equal to the center value, map it from
// the range [min, center] to [-1, 0].
return map(raw, min, center, -1, 0);
return map(raw, min, center, 1, 0);
}
}

int Joystick::getRawX() {
// Read from the y pin because the joystick is rotated right 90 degrees.
return analogRead(yPin);
}
int Joystick::getRawX() { return analogRead(xPin); }

int Joystick::getRawY() {
// Read from the x pin because the joystick is rotated right 90 degrees.
return analogRead(xPin);
}
int Joystick::getRawY() { return analogRead(yPin); }

float Joystick::getX() {
// Convert the raw X value to a value in the range -1 to 1 and return it.
// X_MAX and X_MIN are swapped because the joystick is rotated right 90
// degrees.
return convertRawValue(getRawX(), X_CENTER, X_MAX, X_MIN);
return convertRawValue(getRawX(), X_CENTER, X_MIN, X_MAX);
}

float Joystick::getY() {
// Convert the raw Y value to a value in the range -1 to 1 and return it.
// Y_MAX and Y_MIN are swapped because the joystick is rotated right 90
// degrees.
return convertRawValue(getRawY(), Y_CENTER, Y_MAX, Y_MIN);
return convertRawValue(getRawY(), Y_CENTER, Y_MIN, Y_MAX);
}

bool Joystick::isPressed() {
Expand Down
1 change: 0 additions & 1 deletion src/config/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
#define PIN_BUTTON_5 15
#define PIN_BUTTON_6 32
#define PIN_BUTTON_7 14

0 comments on commit 21809f7

Please sign in to comment.