Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for feather v2 and Squidbox PCB #20

Merged
merged 15 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

[platformio]

[env:nodemcu-32s]
[env:adafruit_feather_esp32_v2]
platform = espressif32
board = nodemcu-32s
board = adafruit_feather_esp32_v2
framework = arduino
monitor_speed = 115200

Expand Down
4 changes: 3 additions & 1 deletion src/Squidbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Squidbox::Squidbox() {
buttons[7] = new Button(PIN_BUTTON_7);

// Enable wakeup from deep sleep when button 0 is pressed
esp_sleep_enable_ext0_wakeup(static_cast<gpio_num_t>(PIN_BUTTON_0), 0);
esp_sleep_enable_ext0_wakeup(static_cast<gpio_num_t>(PIN_BACK_BUTTON), 0);
}

void Squidbox::init() {
Expand Down Expand Up @@ -58,6 +58,8 @@ void Squidbox::sleep() {
// Clear the screen and update it before going to deep sleep
screen->clear();
screen->update();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
esp_deep_sleep_start();
}

Expand Down
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
34 changes: 16 additions & 18 deletions src/config/pins.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#pragma once

#define PIN_SCREEN_SCL 22 // D22
#define PIN_SCREEN_SDA 21 // D21
#define PIN_JOYSTICK_X 36 // VP
#define PIN_JOYSTICK_Y 39 // VN
#define PIN_JOYSTICK_BUTTON 34 // D34
#define PIN_KNOB_A 33 // D33
#define PIN_KNOB_B 32 // D32
#define PIN_KNOB_BUTTON 35 // D35
#define PIN_BACK_BUTTON 27 // D27
#define PIN_OK_BUTTON 26 // D26
#define PIN_BUTTON_0 15 // D15
#define PIN_BUTTON_1 13 // D13
#define PIN_BUTTON_2 4 // D4
#define PIN_BUTTON_3 16 // RX2
#define PIN_BUTTON_4 17 // TX2
#define PIN_BUTTON_5 5 // D5
#define PIN_BUTTON_6 18 // D18
#define PIN_BUTTON_7 19 // D19
#define PIN_JOYSTICK_X 25
#define PIN_JOYSTICK_Y 34
#define PIN_JOYSTICK_BUTTON -1
#define PIN_KNOB_A 5
#define PIN_KNOB_B 4
#define PIN_KNOB_BUTTON -1
#define PIN_BACK_BUTTON 26
#define PIN_OK_BUTTON 13
#define PIN_BUTTON_0 21
#define PIN_BUTTON_1 19
#define PIN_BUTTON_2 12
#define PIN_BUTTON_3 27
#define PIN_BUTTON_4 33
#define PIN_BUTTON_5 15
#define PIN_BUTTON_6 32
#define PIN_BUTTON_7 14
Loading