Skip to content

Commit

Permalink
Standalone Directional Input actions and Addon buttons as GpioAction (#…
Browse files Browse the repository at this point in the history
…1216)

* Initial commit of standalone directional inputs in addition to mode-specific and DDI.

* Moved directions experiment to feature branch.
Updated Tilt addon to remove pin allocation in favor of GpioAction usage.

* Removed Reverse button pin allocation in favor of GpioAction

* Deprecated Reverse button pin proto definition.

* Remove unused Reverse pin variable

* Added SUSTAIN_FOCUS_MODE definition for toggling Focus Mode state

* Removed Focus Mode pin allocation in favor of GpioAction

* Removed deprecated pins from webconfig Addon views

* Migrate previous addon pin settings to pin mappings and GpioActions

* Revert deprecated pin names for focus, tilt, and reverse to previous names

* Update tilt, focus, and reverse migrations to use fromProtoBuf

* Remove stray equals sign
  • Loading branch information
mikepparks authored Nov 25, 2024
1 parent 99099c6 commit d61073e
Show file tree
Hide file tree
Showing 17 changed files with 374 additions and 446 deletions.
2 changes: 1 addition & 1 deletion headers/addons/focus_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FocusModeAddon : public GPAddon {
virtual std::string name() { return FocusModeName; }
private:
uint32_t buttonLockMask;
uint8_t focusModePin;
GamepadButtonMapping *mapFocusMode;
};

#endif // _FocusMode_H_
3 changes: 1 addition & 2 deletions headers/addons/reverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ReverseInput : public GPAddon {
GamepadButtonMapping *mapDpadDown;
GamepadButtonMapping *mapDpadLeft;
GamepadButtonMapping *mapDpadRight;
GamepadButtonMapping *mapInputReverse;

bool invertXAxis;
bool invertYAxis;
Expand All @@ -64,8 +65,6 @@ class ReverseInput : public GPAddon {
uint8_t actionDown;
uint8_t actionLeft;
uint8_t actionRight;

uint8_t pinButtonReverse;
};

#endif // _Reverse_H_
21 changes: 11 additions & 10 deletions headers/addons/tilt.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class TiltInput : public GPAddon {
uint8_t SOCDCombine(SOCDMode, uint8_t);
uint8_t SOCDGamepadClean(uint8_t);
void OverrideGamepad(Gamepad*, uint8_t, uint8_t);
uint16_t getAnalogValue(bool isMin, bool isMax);
uint8_t tiltLeftState; // Tilt State
uint8_t tiltRightState; // Tilt Right Analog State
DpadDirection lastGPUD; // Gamepad Last Up-Down
Expand All @@ -109,25 +110,25 @@ class TiltInput : public GPAddon {
DpadDirection rightLastTiltUD; // Tilt Last Up-Down
DpadDirection rightLastTiltLR; // 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;
uint8_t pinTiltLeftAnalogRight;
uint8_t pinTiltRightAnalogDown;
uint8_t pinTiltRightAnalogUp;
uint8_t pinTiltRightAnalogLeft;
uint8_t pinTiltRightAnalogRight;
SOCDMode tiltSOCDMode;
GamepadButtonMapping *mapAnalogLSXNeg;
GamepadButtonMapping *mapAnalogLSXPos;
GamepadButtonMapping *mapAnalogLSYNeg;
GamepadButtonMapping *mapAnalogLSYPos;
GamepadButtonMapping *mapAnalogRSXNeg;
GamepadButtonMapping *mapAnalogRSXPos;
GamepadButtonMapping *mapAnalogRSYNeg;
GamepadButtonMapping *mapAnalogRSYPos;
GamepadButtonMapping *mapAnalogModLow;
GamepadButtonMapping *mapAnalogModHigh;
};

#endif // _Tilt_H
12 changes: 12 additions & 0 deletions headers/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ class Gamepad {
GamepadButtonMapping *mapButtonDP;
GamepadButtonMapping *mapButtonLS;
GamepadButtonMapping *mapButtonRS;
GamepadButtonMapping *mapDigitalUp;
GamepadButtonMapping *mapDigitalDown;
GamepadButtonMapping *mapDigitalLeft;
GamepadButtonMapping *mapDigitalRight;
GamepadButtonMapping *mapAnalogLSXNeg;
GamepadButtonMapping *mapAnalogLSXPos;
GamepadButtonMapping *mapAnalogLSYNeg;
GamepadButtonMapping *mapAnalogLSYPos;
GamepadButtonMapping *mapAnalogRSXNeg;
GamepadButtonMapping *mapAnalogRSXPos;
GamepadButtonMapping *mapAnalogRSYNeg;
GamepadButtonMapping *mapAnalogRSYPos;

// gamepad specific proxy of debounced buttons --- 1 = active (inverse of the raw GPIO)
// see GP2040::debounceGpioGetAll for details
Expand Down
26 changes: 13 additions & 13 deletions proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ message ReverseOptions
{
optional bool enabled = 1;

optional int32 buttonPin = 2;
optional int32 buttonPin = 2 [deprecated = true];
optional int32 ledPin = 3;

optional uint32 actionUp = 4;
Expand Down Expand Up @@ -475,17 +475,17 @@ message TiltOptions
{
optional bool enabled = 1;

optional int32 tilt1Pin = 2;
optional int32 tilt2Pin = 3;
optional int32 deprecatedTiltFunctionPin = 4 [deprecated = true];
optional int32 tiltLeftAnalogUpPin = 5;
optional int32 tiltLeftAnalogDownPin = 6;
optional int32 tiltLeftAnalogLeftPin = 7;
optional int32 tiltLeftAnalogRightPin = 8;
optional int32 tiltRightAnalogUpPin = 9;
optional int32 tiltRightAnalogDownPin = 10;
optional int32 tiltRightAnalogLeftPin = 11;
optional int32 tiltRightAnalogRightPin = 12;
optional int32 tilt1Pin = 2 [deprecated = true];
optional int32 tilt2Pin = 3 [deprecated = true];
optional int32 tiltFunctionPin = 4 [deprecated = true];
optional int32 tiltLeftAnalogUpPin = 5 [deprecated = true];
optional int32 tiltLeftAnalogDownPin = 6 [deprecated = true];
optional int32 tiltLeftAnalogLeftPin = 7 [deprecated = true];
optional int32 tiltLeftAnalogRightPin = 8 [deprecated = true];
optional int32 tiltRightAnalogUpPin = 9 [deprecated = true];
optional int32 tiltRightAnalogDownPin = 10 [deprecated = true];
optional int32 tiltRightAnalogLeftPin = 11 [deprecated = true];
optional int32 tiltRightAnalogRightPin = 12 [deprecated = true];

optional SOCDMode tiltSOCDMode = 13;

Expand Down Expand Up @@ -691,7 +691,7 @@ message KeyboardHostOptions
message FocusModeOptions
{
optional bool enabled = 1;
optional int32 pin = 2;
optional int32 pin = 2 [deprecated = true];
optional int32 buttonLockMask = 3;
optional bool oledLockEnabled = 4;
optional bool rgbLockEnabled = 5;
Expand Down
18 changes: 18 additions & 0 deletions proto/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ enum GpioAction
BUTTON_PRESS_E10 = 52;
BUTTON_PRESS_E11 = 53;
BUTTON_PRESS_E12 = 54;

DIGITAL_DIRECTION_UP = 55;
DIGITAL_DIRECTION_DOWN = 56;
DIGITAL_DIRECTION_LEFT = 57;
DIGITAL_DIRECTION_RIGHT = 58;
ANALOG_DIRECTION_LS_X_NEG = 59;
ANALOG_DIRECTION_LS_X_POS = 60;
ANALOG_DIRECTION_LS_Y_NEG = 61;
ANALOG_DIRECTION_LS_Y_POS = 62;
ANALOG_DIRECTION_RS_X_NEG = 63;
ANALOG_DIRECTION_RS_X_POS = 64;
ANALOG_DIRECTION_RS_Y_NEG = 65;
ANALOG_DIRECTION_RS_Y_POS = 66;
ANALOG_DIRECTION_MOD_LOW = 67;
ANALOG_DIRECTION_MOD_HIGH = 68;

BUTTON_PRESS_INPUT_REVERSE = 69;
SUSTAIN_FOCUS_MODE = 70;
}

enum GpioDirection
Expand Down
24 changes: 16 additions & 8 deletions src/addons/focus_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@

bool FocusModeAddon::available() {
const FocusModeOptions& options = Storage::getInstance().getAddonOptions().focusModeOptions;
return options.enabled &&
options.buttonLockMask != 0 &&
isValidPin(options.pin);
return options.enabled && options.buttonLockMask != 0;
}

void FocusModeAddon::setup() {
const FocusModeOptions& options = Storage::getInstance().getAddonOptions().focusModeOptions;
buttonLockMask = options.buttonLockMask;
focusModePin = options.pin;
gpio_init(focusModePin); // Initialize pin
gpio_set_dir(focusModePin, GPIO_IN); // Set as INPUT
gpio_pull_up(focusModePin); // Set as PULLUP

// Setup Focus Mode
mapFocusMode = new GamepadButtonMapping(0);

GpioMappingInfo* pinMappings = Storage::getInstance().getProfilePinMappings();
for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++)
{
switch (pinMappings[pin].action) {
case GpioAction::SUSTAIN_FOCUS_MODE: mapFocusMode->pinMask |= 1 << pin; break;
default: break;
}
}

}

void FocusModeAddon::process() {
Gamepad * gamepad = Storage::getInstance().GetGamepad();
if (!gpio_get(focusModePin)) {
Mask_t values = Storage::getInstance().GetGamepad()->debouncedGpio;
if (values & mapFocusMode->pinMask) {
if (buttonLockMask & GAMEPAD_MASK_DU) {
gamepad->state.dpad &= ~GAMEPAD_MASK_UP;
}
Expand Down
20 changes: 14 additions & 6 deletions src/addons/reverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@

bool ReverseInput::available() {
const ReverseOptions& options = Storage::getInstance().getAddonOptions().reverseOptions;
pinButtonReverse = options.buttonPin;
return options.enabled && isValidPin(options.buttonPin);
return options.enabled;
}

void ReverseInput::setup()
{
// Setup Reverse Input Button
gpio_init(pinButtonReverse); // Initialize pin
gpio_set_dir(pinButtonReverse, GPIO_IN); // Set as INPUT
gpio_pull_up(pinButtonReverse); // Set as PULLUP
mapInputReverse = new GamepadButtonMapping(0);

GpioMappingInfo* pinMappings = Storage::getInstance().getProfilePinMappings();
for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++)
{
switch (pinMappings[pin].action) {
case GpioAction::BUTTON_PRESS_INPUT_REVERSE: mapInputReverse->pinMask |= 1 << pin; break;
default: break;
}
}

// Setup Reverse LED if available
const ReverseOptions& options = Storage::getInstance().getAddonOptions().reverseOptions;
Expand Down Expand Up @@ -45,7 +51,9 @@ void ReverseInput::setup()
}

void ReverseInput::update() {
state = !gpio_get(pinButtonReverse);
Mask_t values = Storage::getInstance().GetGamepad()->debouncedGpio;

state = (values & mapInputReverse->pinMask);
}

uint8_t ReverseInput::input(uint32_t valueMask, uint16_t buttonMask, uint16_t buttonMaskReverse, uint8_t action, bool invertAxis) {
Expand Down
Loading

0 comments on commit d61073e

Please sign in to comment.