diff --git a/configs/Pico/BoardConfig.h b/configs/Pico/BoardConfig.h
index 733ab6fef..fe8623640 100644
--- a/configs/Pico/BoardConfig.h
+++ b/configs/Pico/BoardConfig.h
@@ -239,7 +239,15 @@
// TILTAdd-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 45 //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 170 //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 35 //Default value for the TILT button to function.
+#define TILT2_FACTOR_RIGHT_X 30 //Default value for the TILT button to function.
+#define TILT2_FACTOR_RIGHT_Y 30 //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
diff --git a/headers/addons/tilt.h b/headers/addons/tilt.h
index 75411274b..92e83abcc 100644
--- a/headers/addons/tilt.h
+++ b/headers/addons/tilt.h
@@ -13,10 +13,43 @@
#define PIN_TILT_1 -1
#endif
+#ifndef TILT1_FACTOR_LEFT_X
+#define TILT1_FACTOR_LEFT_X -1
+#endif
+
+#ifndef TILT1_FACTOR_LEFT_Y
+#define TILT1_FACTOR_LEFT_Y -1
+#endif
+
+#ifndef TILT1_FACTOR_RIGHT_X
+#define TILT1_FACTOR_RIGHT_X -1
+#endif
+
+#ifndef TILT1_FACTOR_RIGHT_Y
+#define TILT1_FACTOR_RIGHT_Y -1
+#endif
+
#ifndef PIN_TILT_2
#define PIN_TILT_2 -1
#endif
+#ifndef TILT2_FACTOR_LEFT_X
+#define TILT2_FACTOR_LEFT_X -1
+#endif
+
+#ifndef TILT2_FACTOR_LEFT_Y
+#define TILT2_FACTOR_LEFT_Y -1
+#endif
+
+#ifndef TILT2_FACTOR_RIGHT_X
+#define TILT2_FACTOR_RIGHT_X -1
+#endif
+
+#ifndef TILT2_FACTOR_RIGHT_Y
+#define TILT2_FACTOR_RIGHT_Y -1
+#endif
+
+
#ifndef PIN_TILT_LEFT_ANALOG_UP
#define PIN_TILT_LEFT_ANALOG_UP -1
#endif
@@ -79,7 +112,15 @@ class TiltInput : public GPAddon {
DpadDirection lastTiltLR; // Gamepad Last Left-Right
uint32_t dpadTime[4];
uint8_t pinTilt1;
+ uint8_t tilt1FactorLeftX;
+ uint8_t tilt1FactorLeftY;
+ uint8_t tilt1FactorRightX;
+ uint8_t tilt1FactorRightY;
uint8_t pinTilt2;
+ uint8_t tilt2FactorLeftX;
+ uint8_t tilt2FactorLeftY;
+ uint8_t tilt2FactorRightX;
+ uint8_t tilt2FactorRightY;
uint8_t pinTiltLeftAnalogDown;
uint8_t pinTiltLeftAnalogUp;
uint8_t pinTiltLeftAnalogLeft;
diff --git a/proto/config.proto b/proto/config.proto
index 5bfb0cdd9..3f5ed50c5 100644
--- a/proto/config.proto
+++ b/proto/config.proto
@@ -384,6 +384,15 @@ message TiltOptions
optional int32 tiltRightAnalogRightPin = 12;
optional SOCDMode tiltSOCDMode = 13;
+
+ optional int32 factorTilt1LeftX = 14;
+ optional int32 factorTilt1LeftY = 15;
+ optional int32 factorTilt1RightX = 16;
+ optional int32 factorTilt1RightY = 17;
+ optional int32 factorTilt2LeftX = 18;
+ optional int32 factorTilt2LeftY = 19;
+ optional int32 factorTilt2RightX = 20;
+ optional int32 factorTilt2RightY = 21;
}
message BuzzerOptions
diff --git a/src/addons/tilt.cpp b/src/addons/tilt.cpp
index a1a92aac3..738575ead 100644
--- a/src/addons/tilt.cpp
+++ b/src/addons/tilt.cpp
@@ -3,23 +3,6 @@
#include "helper.h"
#include "config.pb.h"
-// These constants define the adjustment factors for gamepad analog inputs under different tilt states.
-// Defines the behavior of the left analog stick when the Tilt1 and Tilt2 buttons are pressed.
-// The main purpose of the left analog stick is to move the character.
-// Pressing it simultaneously with Tilt 1 will make the character walk.
-// Pressing it simultaneously with Tilt 2 will make the character walk more slowly.
-const double TILT1_FACTOR_LEFT_X = 0.35; // Adjustment factor for left analog stick X direction
-const double TILT1_FACTOR_LEFT_Y = 0.45; // Adjustment factor for left analog stick Y direction
-const double TILT2_FACTOR_LEFT_X = 0.65; // Adjustment factor for left analog stick X direction
-const double TILT2_FACTOR_LEFT_Y = 0.35; // Adjustment factor for left analog stick Y direction
-
-// The Right analog stick has 8 directions, which can be handled by pressing up, down, left, right, and simultaneously.
-// This function adds to that the ability to tilt it at an angle closer to horizontal than diagonal.
-const double TILT1_FACTOR_RIGHT_X = 0.3; // Adjustment factor for right analog stick X direction
-const double TILT1_FACTOR_RIGHT_Y = 1.7; // Adjustment factor for right analog stick Y direction
-const double TILT2_FACTOR_RIGHT_X = 0.3; // Adjustment factor for right analog stick X direction
-const double TILT2_FACTOR_RIGHT_Y = 0.3; // Adjustment factor for right analog stick Y direction
-
bool TiltInput::available() {
return Storage::getInstance().getAddonOptions().tiltOptions.enabled;
}
@@ -29,7 +12,15 @@ void TiltInput::setup() {
tiltSOCDMode = options.tiltSOCDMode;
pinTilt1 = options.tilt1Pin;
+ tilt1FactorLeftX = options.factorTilt1LeftX;
+ tilt1FactorLeftY = options.factorTilt1LeftY;
+ tilt1FactorRightX = options.factorTilt1RightX;
+ tilt1FactorRightY = options.factorTilt1RightY;
pinTilt2 = options.tilt2Pin;
+ tilt2FactorLeftX = options.factorTilt2LeftX;
+ tilt2FactorLeftY = options.factorTilt2LeftY;
+ tilt2FactorRightX = options.factorTilt2RightX;
+ tilt2FactorRightY = options.factorTilt2RightY;
pinTiltLeftAnalogDown = options.tiltLeftAnalogDownPin;
pinTiltLeftAnalogUp = options.tiltLeftAnalogUpPin;
pinTiltLeftAnalogLeft = options.tiltLeftAnalogLeftPin;
@@ -168,14 +159,24 @@ void TiltInput::OverrideGamepad(Gamepad* gamepad, uint8_t dpad1, uint8_t dpad2)
bool pinTilt1Pressed = (pinTilt1 != (uint8_t)-1) ? !gpio_get(pinTilt1) : false;
bool pinTilt2Pressed = (pinTilt2 != (uint8_t)-1) ? !gpio_get(pinTilt2) : false;
- if (pinTilt1Pressed) {
- gamepad->state.lx = dpadToAnalogX(dpad1) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogX(dpad1)) * TILT1_FACTOR_LEFT_X;
- gamepad->state.ly = dpadToAnalogY(dpad1) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogY(dpad1)) * TILT1_FACTOR_LEFT_Y;
- }
- else if (pinTilt2Pressed) {
- gamepad->state.lx = dpadToAnalogX(dpad1) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogX(dpad1)) * TILT2_FACTOR_LEFT_X;
- gamepad->state.ly = dpadToAnalogY(dpad1) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogY(dpad1)) * TILT2_FACTOR_LEFT_Y;
- }
+ double scaledTilt1FactorLeftX = tilt1FactorLeftX / 100.0;
+ double scaledTilt1FactorLeftY = tilt1FactorLeftY / 100.0;
+ double scaledTilt1FactorRightX = tilt1FactorRightX / 100.0;
+ double scaledTilt1FactorRightY = tilt1FactorRightY / 100.0;
+ double scaledTilt2FactorLeftX = tilt2FactorLeftX / 100.0;
+ double scaledTilt2FactorLeftY = tilt2FactorLeftY / 100.0;
+ double scaledTilt2FactorRightX = tilt2FactorRightX / 100.0;
+ double scaledTilt2FactorRightY = tilt2FactorRightY / 100.0;
+
+
+ if (pinTilt1Pressed) {
+ gamepad->state.lx = dpadToAnalogX(dpad1) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogX(dpad1)) * scaledTilt1FactorLeftX;
+ gamepad->state.ly = dpadToAnalogY(dpad1) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogY(dpad1)) * scaledTilt1FactorLeftY;
+ }
+ else if (pinTilt2Pressed) {
+ gamepad->state.lx = dpadToAnalogX(dpad1) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogX(dpad1)) * scaledTilt2FactorLeftX;
+ gamepad->state.ly = dpadToAnalogY(dpad1) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogY(dpad1)) * scaledTilt2FactorLeftY;
+ }
else {
gamepad->state.lx = dpadToAnalogX(dpad1);
gamepad->state.ly = dpadToAnalogY(dpad1);
@@ -186,8 +187,8 @@ void TiltInput::OverrideGamepad(Gamepad* gamepad, uint8_t dpad1, uint8_t dpad2)
}
else if (pinTilt1Pressed) {
if (dpad2 & (GAMEPAD_MASK_LEFT | GAMEPAD_MASK_RIGHT)) {
- gamepad->state.rx = dpadToAnalogX(dpad2) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogX(dpad2)) * TILT1_FACTOR_RIGHT_X;
- gamepad->state.ry = GAMEPAD_JOYSTICK_MID * TILT1_FACTOR_RIGHT_Y;
+ gamepad->state.rx = dpadToAnalogX(dpad2) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogX(dpad2)) * scaledTilt1FactorRightX;
+ gamepad->state.ry = GAMEPAD_JOYSTICK_MID * scaledTilt1FactorRightY;
}
else {
gamepad->state.rx = dpadToAnalogX(dpad2);
@@ -196,8 +197,8 @@ void TiltInput::OverrideGamepad(Gamepad* gamepad, uint8_t dpad1, uint8_t dpad2)
}
else if (pinTilt2Pressed) {
if (dpad2 & (GAMEPAD_MASK_LEFT | GAMEPAD_MASK_RIGHT)) {
- gamepad->state.rx = dpadToAnalogX(dpad2) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogX(dpad2)) * TILT2_FACTOR_RIGHT_X;
- gamepad->state.ry = GAMEPAD_JOYSTICK_MID * TILT2_FACTOR_RIGHT_Y;
+ gamepad->state.rx = dpadToAnalogX(dpad2) + (GAMEPAD_JOYSTICK_MID - dpadToAnalogX(dpad2)) * scaledTilt2FactorRightX;
+ gamepad->state.ry = GAMEPAD_JOYSTICK_MID * scaledTilt2FactorRightY;
}
else {
gamepad->state.rx = dpadToAnalogX(dpad2);
diff --git a/src/config_utils.cpp b/src/config_utils.cpp
index 5dd7c263d..c252affe7 100644
--- a/src/config_utils.cpp
+++ b/src/config_utils.cpp
@@ -438,7 +438,15 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
// addonOptions.tiltOptions
INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, enabled, !!TILT_ENABLED);
INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tilt1Pin, PIN_TILT_1);
+ INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt1LeftX, TILT1_FACTOR_LEFT_X);
+ INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt1LeftY, TILT1_FACTOR_LEFT_Y);
+ INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt1RightX, TILT1_FACTOR_RIGHT_X);
+ INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt1RightY, TILT1_FACTOR_RIGHT_Y);
INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tilt2Pin, PIN_TILT_2);
+ INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt2LeftX, TILT2_FACTOR_LEFT_X);
+ INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt2LeftY, TILT2_FACTOR_LEFT_Y);
+ INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt2RightX, TILT2_FACTOR_RIGHT_X);
+ INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt2RightY, TILT2_FACTOR_RIGHT_Y);
INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogDownPin, PIN_TILT_LEFT_ANALOG_DOWN);
INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogUpPin, PIN_TILT_LEFT_ANALOG_UP);
INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogLeftPin, PIN_TILT_LEFT_ANALOG_LEFT);
diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp
index 54780f322..49ae3dc63 100644
--- a/src/configs/webconfig.cpp
+++ b/src/configs/webconfig.cpp
@@ -1002,7 +1002,15 @@ std::string setAddonOptions()
TiltOptions& tiltOptions = Storage::getInstance().getAddonOptions().tiltOptions;
docToPin(tiltOptions.tilt1Pin, doc, "tilt1Pin");
+ docToValue(tiltOptions.factorTilt1LeftX, doc, "factorTilt1LeftX");
+ docToValue(tiltOptions.factorTilt1LeftY, doc, "factorTilt1LeftY");
+ docToValue(tiltOptions.factorTilt1RightX, doc, "factorTilt1RightX");
+ docToValue(tiltOptions.factorTilt1RightY, doc, "factorTilt1RightY");
docToPin(tiltOptions.tilt2Pin, doc, "tilt2Pin");
+ docToValue(tiltOptions.factorTilt2LeftX, doc, "factorTilt2LeftX");
+ docToValue(tiltOptions.factorTilt2LeftY, doc, "factorTilt2LeftY");
+ docToValue(tiltOptions.factorTilt2RightX, doc, "factorTilt2RightX");
+ docToValue(tiltOptions.factorTilt2RightY, doc, "factorTilt2RightY");
docToPin(tiltOptions.tiltLeftAnalogUpPin, doc, "tiltLeftAnalogUpPin");
docToPin(tiltOptions.tiltLeftAnalogDownPin, doc, "tiltLeftAnalogDownPin");
docToPin(tiltOptions.tiltLeftAnalogLeftPin, doc, "tiltLeftAnalogLeftPin");
@@ -1414,7 +1422,15 @@ std::string getAddonOptions()
const TiltOptions& tiltOptions = Storage::getInstance().getAddonOptions().tiltOptions;
writeDoc(doc, "tilt1Pin", cleanPin(tiltOptions.tilt1Pin));
+ writeDoc(doc, "factorTilt1LeftX", tiltOptions.factorTilt1LeftX);
+ writeDoc(doc, "factorTilt1LeftY", tiltOptions.factorTilt1LeftY);
+ writeDoc(doc, "factorTilt1RightX", tiltOptions.factorTilt1RightX);
+ writeDoc(doc, "factorTilt1RightY", tiltOptions.factorTilt1RightY);
writeDoc(doc, "tilt2Pin", cleanPin(tiltOptions.tilt2Pin));
+ writeDoc(doc, "factorTilt2LeftX", tiltOptions.factorTilt2LeftX);
+ writeDoc(doc, "factorTilt2LeftY", tiltOptions.factorTilt2LeftY);
+ writeDoc(doc, "factorTilt2RightX", tiltOptions.factorTilt2RightX);
+ writeDoc(doc, "factorTilt2RightY", tiltOptions.factorTilt2RightY);
writeDoc(doc, "tiltLeftAnalogUpPin", cleanPin(tiltOptions.tiltLeftAnalogUpPin));
writeDoc(doc, "tiltLeftAnalogDownPin", cleanPin(tiltOptions.tiltLeftAnalogDownPin));
writeDoc(doc, "tiltLeftAnalogLeftPin", cleanPin(tiltOptions.tiltLeftAnalogLeftPin));
diff --git a/www/server/app.js b/www/server/app.js
index 709b680cf..b214339cf 100644
--- a/www/server/app.js
+++ b/www/server/app.js
@@ -381,7 +381,15 @@ app.get('/api/getAddonsOptions', (req, res) => {
dualDirCombineMode: 0,
dualDirFourWayMode: 0,
tilt1Pin: -1,
+ factorTilt1LeftX: -1,
+ factorTilt1LeftY: -1,
+ factorTilt1RightX: -1,
+ factorTilt1RightY: -1,
tilt2Pin: -1,
+ factorTilt2LeftX: -1,
+ factorTilt2LeftY: -1,
+ factorTilt2RightX: -1,
+ factorTilt2RightY: -1,
tiltLeftAnalogUpPin: -1,
tiltLeftAnalogDownPin: -1,
tiltLeftAnalogLeftPin: -1,
diff --git a/www/src/Addons/Tilt.tsx b/www/src/Addons/Tilt.tsx
index 688da03b2..253932c98 100644
--- a/www/src/Addons/Tilt.tsx
+++ b/www/src/Addons/Tilt.tsx
@@ -14,11 +14,43 @@ export const tiltScheme = {
tilt1Pin: yup
.number()
.label('Tilt 1 Pin')
- .validatePinWhenValue('TiltInputEnabled'),
+ .validatePinWhenValue('TiltInputEnabled'),
+ factorTilt1LeftX: yup
+ .number()
+ .label('Tilt 1 Factor Left X')
+ .validateNumberWhenValue('TiltInputEnabled'),
+ factorTilt1LeftY: yup
+ .number()
+ .label('Tilt 1 Factor Left Y')
+ .validateNumberWhenValue('TiltInputEnabled'),
+ factorTilt1RightX: yup
+ .number()
+ .label('Tilt 1 Factor Right X')
+ .validateNumberWhenValue('TiltInputEnabled'),
+ factorTilt1RightY: yup
+ .number()
+ .label('Tilt 1 Factor Right Y')
+ .validateNumberWhenValue('TiltInputEnabled'),
tilt2Pin: yup
.number()
.label('Tilt 2 Pin')
.validatePinWhenValue('TiltInputEnabled'),
+ factorTilt2LeftX: yup
+ .number()
+ .label('Tilt 2 Factor Left X')
+ .validateNumberWhenValue('TiltInputEnabled'),
+ factorTilt2LeftY: yup
+ .number()
+ .label('Tilt 2 Factor Left Y')
+ .validateNumberWhenValue('TiltInputEnabled'),
+ factorTilt2RightX: yup
+ .number()
+ .label('Tilt 2 Factor Right X')
+ .validateNumberWhenValue('TiltInputEnabled'),
+ factorTilt2RightY: yup
+ .number()
+ .label('Tilt 2 Factor Right Y')
+ .validateNumberWhenValue('TiltInputEnabled'),
tiltLeftAnalogUpPin: yup
.number()
.label('Tilt Left Analog Up Pin')
@@ -60,7 +92,15 @@ export const tiltScheme = {
export const tiltState = {
TiltInputEnabled: 0,
tilt1Pin: -1,
+ factorTilt1LeftX: -1,
+ factorTilt1LeftY: -1,
+ factorTilt1RightX: -1,
+ factorTilt1ightY: -1,
tilt2Pin: -1,
+ factorTilt2LeftX: -1,
+ factorTilt2LeftY: -1,
+ factorTilt2RightX: -1,
+ factorTilt2RightY: -1,
tiltLeftAnalogUpPin: -1,
tiltLeftAnalogDownPin: -1,
tiltLeftAnalogLeftPin: -1,
@@ -90,6 +130,62 @@ const Tilt = ({ values, errors, handleChange, handleCheckbox }) => {
min={-1}
max={29}
/>
+
+
+
+
+
+
+
+
{
max={29}
/>
+
+
+
+
+
+