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

Rotate main #13

Merged
merged 7 commits into from
Nov 2, 2023
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
24 changes: 19 additions & 5 deletions configs/Pico/BoardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,17 @@
#define DUAL_DIRECTIONAL_STICK_MODE DPAD_MODE_DIGITAL
#define DUAL_DIRECTIONAL_COMBINE_MODE DUAL_COMBINE_MODE_MIXED

// TILTAdd-on Options
// TILT Add-on Options
#define PIN_TILT_1 -1
#define TILT1_FACTOR_LEFT_X 35 //Default value for the TILT button to function.
#define TILT1_FACTOR_LEFT_Y 35 //Default value for the TILT button to function.
#define TILT1_FACTOR_LEFT_Y 35 //Default value for the TILT button to function.
#define TILT1_FACTOR_RIGHT_X 35 //Default value for the TILT button to function.
#define TILT1_FACTOR_RIGHT_Y 35 //Default value for the TILT button to function.
#define TILT1_FACTOR_RIGHT_Y 35 //Default value for the TILT button to function.
#define PIN_TILT_2 -1
#define TILT2_FACTOR_LEFT_X 65 //Default value for the TILT button to function.
#define TILT2_FACTOR_LEFT_Y 65 //Default value for the TILT button to function.
#define TILT2_FACTOR_RIGHT_X 65 //Default value for the TILT button to function.
#define TILT2_FACTOR_RIGHT_Y 65 //Default value for the TILT button to function.
#define PIN_TILT_FUNCTION -1
#define PIN_TILT_LEFT_ANALOG_UP -1
#define PIN_TILT_LEFT_ANALOG_DOWN -1
#define PIN_TILT_LEFT_ANALOG_LEFT -1
Expand All @@ -258,7 +257,22 @@
#define PIN_TILT_RIGHT_ANALOG_DOWN -1
#define PIN_TILT_RIGHT_ANALOG_LEFT -1
#define PIN_TILT_RIGHT_ANALOG_RIGHT -1
#define TILT_SOCD_MODE SOCD_MODE_NEUTRAL
#define PIN_ROTATE_1 -1
#define PIN_ROTATE_2 -1
#define ROTATE1_FACTOR_LEFT 15 //Default value for the ROTATE button to function.
#define ROTATE2_FACTOR_LEFT 345 //Default value for the ROTATE button to function.
#define ROTATE3_FACTOR_LEFT 0 //Default value for the ROTATE button to function.
#define ROTATE4_FACTOR_LEFT 0 //Default value for the ROTATE button to function.
#define ROTATE5_FACTOR_LEFT 0 //Default value for the ROTATE button to function.
#define ROTATE6_FACTOR_LEFT 0 //Default value for the ROTATE button to function.
#define ROTATE1_FACTOR_RIGHT 15 //Default value for the ROTATE button to function.
#define ROTATE2_FACTOR_RIGHT 345 //Default value for the ROTATE button to function.
#define ROTATE3_FACTOR_RIGHT 0 //Default value for the ROTATE button to function.
#define ROTATE4_FACTOR_RIGHT 0 //Default value for the ROTATE button to function.
#define ROTATE5_FACTOR_RIGHT 0 //Default value for the ROTATE button to function.
#define ROTATE6_FACTOR_RIGHT 0 //Default value for the ROTATE button to function.
#define TILT_LEFT_SOCD_MODE SOCD_MODE_NEUTRAL
#define TILT_RIGHT_SOCD_MODE SOCD_MODE_NEUTRAL

// BOOTSEL Button Add-on setting
#define BOOTSEL_BUTTON_MASK 0 // 0 means none, get other mask from GamepadState.h
Expand Down
80 changes: 62 additions & 18 deletions docs/add-ons/tilt-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ Purpose: The Tilt Input add-on allows users to send analog inputs from the Left

![GP2040-CE Configuration - Add-Ons Tilt Input](../assets/images/gpc-add-ons-tilt.png)

* `Tilt 1 Pin` - The GPIO pin used for the Tilt 1 direction.
* `Tilt 1 Factor Left X` - The percentage of the X-axis input for the Left analog stick sent when `Tilt 1 Pin` is activated. (Min. 0, Max 100)
* `Tilt 1 Factor Left Y` - The percentage of the Y-axis input for the Left analog stick sent when `Tilt 1 Pin` is activated. (Min. 0, Max 100)
* `Tilt 1 Factor Left X` - The percentage of the X-axis input for the Right analog stick sent when `Tilt 1 Pin` is activated. (Min. 0, Max 100)
* `Tilt 1 Factor Left Y` - The percentage of the Y-axis input for the Right analog stick sent when `Tilt 1 Pin` is activated. (Min. 0, Max 100)
* `Tilt 2 Pin` - The GPIO pin used for the Tilt 2 direction.
* `Tilt 2 Factor Left X` - The percentage of the X-axis input for the Left analog stick sent when `Tilt 2 Pin` is activated. (Min. 0, Max 100)
* `Tilt 2 Factor Left Y` - The percentage of the Y-axis input for the Left analog stick sent when `Tilt 2 Pin` is activated. (Min. 0, Max 100)
* `Tilt 2 Factor Left X` - The percentage of the X-axis input for the Right analog stick sent when `Tilt 2 Pin` is activated. (Min. 0, Max 100)
* `Tilt 2 Factor Left Y` - The percentage of the Y-axis input for the Right analog stick sent when `Tilt 2 Pin` is activated. (Min. 0, Max 100)
## Dedicated Analog Stick Pins
User can set dedicated analog stick pins to work with Tilt and Rotate features.
If no dedicated analog stick pins are set, Tilt and Rotate features will function when DPad is used as Left or Right Analog.
Otherwise, dedicated analog stick pins will have priority over DPad used as left or right analog sticks
* `Tilt Left Analog Up Pin` - The GPIO pin used for the Up direction on the Left analog stick.
* `Tilt Left Analog Down Pin` - The GPIO pin used for the Down direction on the Left analog stick.
* `Tilt Left Analog Left Pin` - The GPIO pin used for the Left direction on the Left analog stick.
Expand All @@ -22,15 +16,65 @@ Purpose: The Tilt Input add-on allows users to send analog inputs from the Left
* `Tilt Right Analog Down Pin` - The GPIO pin used for the Down direction on the Right analog stick.
* `Tilt Right Analog Left Pin` - The GPIO pin used for the Left direction on the Right analog stick.
* `Tilt Right Analog Right Pin` - The GPIO pin used for the Right direction on the Right analog stick.
* `Tilt SOCD Mode` - Choose the default SOCD Cleaning Mode (Neutral, Last Win, First Win).

Hardware Requirements:
## Tilt
Tilt 1 and Tilt 2 buttons, when pressed with directional buttons, adjust the analog values.
Pressing Tilt 1 or 2 with a value of N results in an input that is N% of the maximum direction. (Min. 0, Max. 100)
Pressing Tilt 1 and Tilt 2 simultaneously with LS or RS directional buttons will make them function as the D-Pad.

- Additional buttons, switches, or joysticks, are recommended for this add-on as this add-on entirely prevents the primary Dpad from being set as the Left analog or Right analog stick.
* `Tilt 1 Pin` - The GPIO pin used for the Tilt 1.
* `Tilt 2 Pin` - The GPIO pin used for the Tilt 2.
* `Tilt 1 Factor Left X` - The percentage of the X-axis input for the Left Stick when pressing Tilt 1.
* `Tilt 1 Factor Left Y` - The percentage of the Y-axis input for the Left Stick when pressing Tilt 1.
* `Tilt 2 Factor Left X` - The percentage of the X-axis input for the Left Stick when pressing Tilt 2.
* `Tilt 2 Factor Left Y` - The percentage of the Y-axis input for the Left Stick when pressing Tilt 2.
* `Tilt 1 Factor Right X` - The percentage of the X-axis input for the Right Stick when pressing Tilt 1.
* `Tilt 1 Factor Right Y` - The percentage of the Y-axis input for the Right Stick when pressing Tilt 1.
* `Tilt 2 Factor Right X` - The percentage of the X-axis input for the Right Stick when pressing Tilt 2.
* `Tilt 2 Factor Right Y` - The percentage of the Y-axis input for the Right Stick when pressing Tilt 2.

Notes
## Rotate
Rotate 1 and Rotate 2 buttons, when pressed with directional buttons, adjust the analog values.
All Rotate functions will make analog sticks rotate clockwise by the set degree. (Min. 0, Max. 360)
Pressing Rotate 1 and Rotate 2 simultaneously with LS or RS directional buttons will make them function as the D-Pad.
* `Rotate 1 Pin` - The GPIO pin used for the Rotate 1.
* `Rotate 2 Pin` - The GPIO pin used for the Rotate 2.
* `Rotate 1 Degree Left` - Clockwise rotate degree for Left Stick when pressing Rotate 1
* `Rotate 2 Degree Left` - Clockwise rotate degree for Left Stick when pressing Rotate 2
* `Rotate 3 Degree Left` - Clockwise rotate degree for Left Stick when pressing Rotate 1 + Tilt 1
* `Rotate 4 Degree Left` - Clockwise rotate degree for Left Stick when pressing Rotate 1 + Tilt 2
* `Rotate 5 Degree Left` - Clockwise rotate degree for Left Stick when pressing Rotate 2 + Tilt 1
* `Rotate 6 Degree Left` - Clockwise rotate degree for Left Stick when pressing Rotate 2 + Tilt 2
* `Rotate 1 Degree Right` - Clockwise rotate degree for Right Stick when pressing Rotate 1
* `Rotate 2 Degree Right` - Clockwise rotate degree for Right Stick when pressing Rotate 2
* `Rotate 3 Degree Right` - Clockwise rotate degree for Right Stick when pressing Rotate 1 + Tilt 1
* `Rotate 4 Degree Right` - Clockwise rotate degree for Right Stick when pressing Rotate 1 + Tilt 2
* `Rotate 5 Degree Right` - Clockwise rotate degree for Right Stick when pressing Rotate 2 + Tilt 1
* `Rotate 6 Degree Right` - Clockwise rotate degree for Right Stick when pressing Rotate 2 + Tilt 2

- Because this add-on disables the Dpad from being set as Left analog and Right analog, using the hotkeys `Dpad Left Analog` and `Dpad Right Analog` deactivates the Dpad and using the `Dpad Digital` will reactivate the Dpad once more.
- Not all Tilt analog pins are required to be set, but not setting the pins will prevent you from using that input without using the Web Configurator to remap the inputs.
- Additionally, pressing Tilt 1 and Tilt 2 simultaneously while inputting Right analog stick directions allows the Right analog stick to function as the D-Pad directions.
- Pressing Tilt 1 and Tilt 2 simultaneously while inputting Left analog stick will prioritize Tilt 1 and ignore Tilt 2.
## SOCD
SOCD Cleaning Mode can be separately set for LS and RS. (Up Priority, Neutral, Last Win, First Win)
* `Tilt Left Stick SOCD Mode` - Choose the SOCD Cleaning Mode for Left Stick.
* `Tilt Right Stick SOCD Mode` - Choose the SOCD Cleaning Mode for Right Stick.

## Summary of Tilt Add-On
The table below provides a summary of all functions offered by Tilt Add-On.
`X` = button is pressed; `-` = button is not pressed
| Tilt1 | Tilt2 | Rotate1 | Rotate2 | | LS Behavior | RS Behavior |
|:-----:|:-----:|:-------:|:-------:|:-:|:-----------:|:-----------:|
| X | - | - | - | ⇨ | Tilt1 | Tilt1 |
| - | X | - | - | ⇨ | Tilt2 | Tilt2 |
| - | - | X | - | ⇨ | Rotate1 | Rotate1 |
| - | - | - | X | ⇨ | Rotate2 | Rotate2 |
| X | X | - | - | ⇨ | D-Pad | D-Pad |
| - | - | X | X | ⇨ | D-Pad | D-Pad |
| X | - | X | - | ⇨ | Rotate3 | Rotate3 |
| - | X | X | - | ⇨ | Rotate4 | Rotate4 |
| X | - | - | X | ⇨ | Rotate5 | Rotate5 |
| - | X | - | X | ⇨ | Rotate6 | Rotate6 |
| X | X | X | - | ⇨ | LS | RS |
| X | X | - | X | ⇨ | LS | RS |
| X | - | X | X | ⇨ | LS | RS |
| - | X | X | X | ⇨ | LS | RS |
| X | X | X | X | ⇨ | LS | RS |
| - | - | - | - | ⇨ | LS | RS |
Binary file modified docs/assets/images/gpc-add-ons-tilt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 79 additions & 8 deletions headers/addons/tilt.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,68 @@
#define PIN_TILT_RIGHT_ANALOG_RIGHT -1
#endif

#ifndef TILT_SOCD_MODE
#define TILT_SOCD_MODE SOCD_MODE_NEUTRAL
#ifndef PIN_ROTATE_1
#define PIN_ROTATE_1 -1
#endif

#ifndef PIN_ROTATE_2
#define PIN_ROTATE_2 -1
#endif

#ifndef ROTATE1_FACTOR_LEFT
#define ROTATE1_FACTOR_LEFT 15
#endif

#ifndef ROTATE2_FACTOR_LEFT
#define ROTATE2_FACTOR_LEFT 345
#endif

#ifndef ROTATE3_FACTOR_LEFT
#define ROTATE3_FACTOR_LEFT 0
#endif

#ifndef ROTATE4_FACTOR_LEFT
#define ROTATE4_FACTOR_LEFT 0
#endif

#ifndef ROTATE5_FACTOR_LEFT
#define ROTATE5_FACTOR_LEFT 0
#endif

#ifndef ROTATE6_FACTOR_LEFT
#define ROTATE6_FACTOR_LEFT 0
#endif

#ifndef ROTATE1_FACTOR_RIGHT
#define ROTATE1_FACTOR_RIGHT 15
#endif

#ifndef ROTATE2_FACTOR_RIGHT
#define ROTATE2_FACTOR_RIGHT 345
#endif

#ifndef ROTATE3_FACTOR_RIGHT
#define ROTATE3_FACTOR_RIGHT 0
#endif

#ifndef ROTATE4_FACTOR_RIGHT
#define ROTATE4_FACTOR_RIGHT 0
#endif

#ifndef ROTATE5_FACTOR_RIGHT
#define ROTATE5_FACTOR_RIGHT 0
#endif

#ifndef ROTATE6_FACTOR_RIGHT
#define ROTATE6_FACTOR_RIGHT 0
#endif

#ifndef TILT_LEFT_SOCD_MODE
#define TILT_LEFT_SOCD_MODE SOCD_MODE_NEUTRAL
#endif

#ifndef TILT_RIGHT_SOCD_MODE
#define TILT_RIGHT_SOCD_MODE SOCD_MODE_NEUTRAL
#endif

// Tilt Module Name
Expand All @@ -97,16 +157,12 @@ class TiltInput : public GPAddon {
virtual std::string name() { return TiltName; }
private:
void debounce();
void SOCDTiltClean(SOCDMode);
uint8_t SOCDCombine(SOCDMode, uint8_t);
uint8_t SOCDGamepadClean(uint8_t);
void SOCDTiltClean(SOCDMode, SOCDMode);
void OverrideGamepad(Gamepad*, uint8_t, uint8_t);
uint8_t dDebLeftState; // Debounce State (stored)
uint8_t dDebRightState; // Debounce State (stored)
uint8_t tiltLeftState; // Tilt State
uint8_t tiltRightState; // Tilt Right Analog State
DpadDirection lastGPUD; // Gamepad Last Up-Down
DpadDirection lastGPLR; // Gamepad Last Left-Right
DpadDirection leftLastTiltUD; // Tilt Last Up-Down
DpadDirection leftLastTiltLR; // Gamepad Last Left-Right
DpadDirection rightLastTiltUD; // Tilt Last Up-Down
Expand All @@ -130,7 +186,22 @@ class TiltInput : public GPAddon {
uint8_t pinTiltRightAnalogUp;
uint8_t pinTiltRightAnalogLeft;
uint8_t pinTiltRightAnalogRight;
SOCDMode tiltSOCDMode;
uint8_t pinRotate1;
uint8_t pinRotate2;
uint16_t rotate1FactorLeft;
uint16_t rotate2FactorLeft;
uint16_t rotate3FactorLeft;
uint16_t rotate4FactorLeft;
uint16_t rotate5FactorLeft;
uint16_t rotate6FactorLeft;
uint16_t rotate1FactorRight;
uint16_t rotate2FactorRight;
uint16_t rotate3FactorRight;
uint16_t rotate4FactorRight;
uint16_t rotate5FactorRight;
uint16_t rotate6FactorRight;
SOCDMode tiltLeftSOCDMode;
SOCDMode tiltRightSOCDMode;
};

#endif // _Tilt_H
19 changes: 19 additions & 0 deletions proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,25 @@ message TiltOptions
optional int32 factorTilt2LeftY = 19;
optional int32 factorTilt2RightX = 20;
optional int32 factorTilt2RightY = 21;

optional int32 rotate1Pin = 22;
optional int32 rotate2Pin = 23;

optional int32 factorRotate1Left = 24;
optional int32 factorRotate1Right = 25;
optional int32 factorRotate2Left = 26;
optional int32 factorRotate2Right = 27;
optional int32 factorRotate3Left = 28;
optional int32 factorRotate3Right = 29;
optional int32 factorRotate4Left = 30;
optional int32 factorRotate4Right = 31;
optional int32 factorRotate5Left = 32;
optional int32 factorRotate5Right = 33;
optional int32 factorRotate6Left = 34;
optional int32 factorRotate6Right = 35;

optional SOCDMode tiltLeftSOCDMode = 36;
optional SOCDMode tiltRightSOCDMode = 37;
}

message BuzzerOptions
Expand Down
Loading