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

Added display functionality for button profiles #451

Closed
Closed
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
1 change: 1 addition & 0 deletions headers/addons/i2cdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class I2CDisplayAddon : public GPAddon
void drawWasdBox(int startX, int startY, int buttonRadius, int buttonPadding);
void drawArcadeStick(int startX, int startY, int buttonRadius, int buttonPadding);
void drawStatusBar(Gamepad*);
void drawPinProfileIndicator(Gamepad * gamepad);
void drawText(int startX, int startY, std::string text);
void initMenu(char**);
//Adding my stuff here, remember to sort before PR
Expand Down
64 changes: 59 additions & 5 deletions headers/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern uint64_t getMicro();

struct GamepadButtonMapping
{
GamepadButtonMapping(uint8_t p, uint16_t bm) :
GamepadButtonMapping(uint8_t p, uint16_t bm) :
pin(p < NUM_BANK0_GPIOS ? p : 0xff),
pinMask(p < NUM_BANK0_GPIOS? (1 << p) : 0),
buttonMask(bm)
Expand Down Expand Up @@ -62,12 +62,12 @@ class Gamepad {
Gamepad(int debounceMS = 5);

void setup();
void teardown_and_reinit(const uint32_t profileNum);
void reassignPinsForProfile(const uint32_t profileNum);
void process();
void read();
void save();
void debounce();

void hotkey();

/**
Expand All @@ -94,17 +94,31 @@ class Gamepad {
PS4Report *getPS4Report();

/**
* @brief Check for a button press. Used by `pressed[Button]` helper methods.
* @brief Check for a button press (current pin profile). Used by `pressed[Button]` helper methods.
*/
inline bool __attribute__((always_inline)) pressedButton(const uint16_t mask) {
return (state.buttons & mask) == mask;
}

/**
* @brief Check for a dpad press. Used by `pressed[Dpad]` helper methods.
* @brief Check for a button press (as wired). Used by `activeWire[Button]` helper methods.
*/
inline bool __attribute__((always_inline)) activeWireB(const uint16_t mask) {
return (state.bwires & mask) == mask;
}

/**
* @brief Check for a dpad press (current pin profile). Used by `pressed[Dpad]` helper methods.
*/
inline bool __attribute__((always_inline)) pressedDpad(const uint8_t mask) { return (state.dpad & mask) == mask; }

/**
* @brief Check for a dpad press (as wired). Used by `activeWire[Direction]` helper methods.
*/
inline bool __attribute__((always_inline)) activeWireD(const uint8_t mask) {
return (state.dwires & mask) == mask;
}

/**
* @brief Check for an aux button press. Same idea as `pressedButton`.
*/
Expand Down Expand Up @@ -148,6 +162,26 @@ class Gamepad {
inline bool __attribute__((always_inline)) pressedA1() { return pressedButton(GAMEPAD_MASK_A1); }
inline bool __attribute__((always_inline)) pressedA2() { return pressedButton(GAMEPAD_MASK_A2); }

// TODO wireUDLR
inline bool __attribute__((always_inline)) activeWireUp() { return activeWireD(GAMEPAD_MASK_UP); }
inline bool __attribute__((always_inline)) activeWireDown() { return activeWireD(GAMEPAD_MASK_DOWN); }
inline bool __attribute__((always_inline)) activeWireLeft() { return activeWireD(GAMEPAD_MASK_LEFT); }
inline bool __attribute__((always_inline)) activeWireRight() { return activeWireD(GAMEPAD_MASK_RIGHT); }
inline bool __attribute__((always_inline)) activeWireB1() { return activeWireB(GAMEPAD_MASK_B1); }
inline bool __attribute__((always_inline)) activeWireB2() { return activeWireB(GAMEPAD_MASK_B2); }
inline bool __attribute__((always_inline)) activeWireB3() { return activeWireB(GAMEPAD_MASK_B3); }
inline bool __attribute__((always_inline)) activeWireB4() { return activeWireB(GAMEPAD_MASK_B4); }
inline bool __attribute__((always_inline)) activeWireL1() { return activeWireB(GAMEPAD_MASK_L1); }
inline bool __attribute__((always_inline)) activeWireR1() { return activeWireB(GAMEPAD_MASK_R1); }
inline bool __attribute__((always_inline)) activeWireL2() { return activeWireB(GAMEPAD_MASK_L2); }
inline bool __attribute__((always_inline)) activeWireR2() { return activeWireB(GAMEPAD_MASK_R2); }
inline bool __attribute__((always_inline)) activeWireS1() { return activeWireB(GAMEPAD_MASK_S1); }
inline bool __attribute__((always_inline)) activeWireS2() { return activeWireB(GAMEPAD_MASK_S2); }
inline bool __attribute__((always_inline)) activeWireL3() { return activeWireB(GAMEPAD_MASK_L3); }
inline bool __attribute__((always_inline)) activeWireR3() { return activeWireB(GAMEPAD_MASK_R3); }
inline bool __attribute__((always_inline)) activeWireA1() { return activeWireB(GAMEPAD_MASK_A1); }
inline bool __attribute__((always_inline)) activeWireA2() { return activeWireB(GAMEPAD_MASK_A2); }

const GamepadOptions& getOptions() const { return options; }

void setInputMode(InputMode inputMode) { options.inputMode = inputMode; }
Expand All @@ -158,6 +192,26 @@ class Gamepad {
const uint8_t debounceMS;
GamepadState rawState;
GamepadState state;
// Pin Wired Map
GamepadButtonMapping *mapWireUp;
GamepadButtonMapping *mapWireDown;
GamepadButtonMapping *mapWireLeft;
GamepadButtonMapping *mapWireRight;
GamepadButtonMapping *mapWireB1;
GamepadButtonMapping *mapWireB2;
GamepadButtonMapping *mapWireB3;
GamepadButtonMapping *mapWireB4;
GamepadButtonMapping *mapWireL1;
GamepadButtonMapping *mapWireR1;
GamepadButtonMapping *mapWireL2;
GamepadButtonMapping *mapWireR2;
GamepadButtonMapping *mapWireS1;
GamepadButtonMapping *mapWireS2;
GamepadButtonMapping *mapWireL3;
GamepadButtonMapping *mapWireR3;
GamepadButtonMapping *mapWireA1;
GamepadButtonMapping *mapWireA2;
// Pin Profile Map
GamepadButtonMapping *mapDpadUp;
GamepadButtonMapping *mapDpadDown;
GamepadButtonMapping *mapDpadLeft;
Expand Down
6 changes: 4 additions & 2 deletions headers/gamepad/GamepadState.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ const uint16_t buttonMasks[] =

struct GamepadState
{
uint8_t dpad {0};
uint16_t buttons {0};
uint8_t dpad {0}; // pin profile
uint16_t buttons {0}; // pin profile
uint8_t dwires {0}; // directional wires
uint16_t bwires {0}; // button wires
uint16_t aux {0};
uint16_t lx {GAMEPAD_JOYSTICK_MID};
uint16_t ly {GAMEPAD_JOYSTICK_MID};
Expand Down
2 changes: 1 addition & 1 deletion headers/storagemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Storage {

bool save();

PinMappings& getProfilePinMappings();
PinMappings& getPinProfileMappings();

// Perform saves that were enqueued from core1
void performEnqueuedSaves();
Expand Down
53 changes: 30 additions & 23 deletions proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ message GamepadOptions
optional bool switchTpShareForDs4 = 6;
optional bool lockHotkeys = 7;
optional bool fourWayMode = 8;
optional uint32 profileNumber = 9;
optional uint32 pinProfileNumber = 9;
}

message KeyboardMapping
Expand Down Expand Up @@ -142,27 +142,34 @@ message ProfileOptions
message DisplayOptions
{
optional bool enabled = 1;

optional int32 i2cBlock = 2;
optional int32 i2cSDAPin = 3;
optional int32 i2cSCLPin = 4;
optional int32 i2cAddress = 5;
optional int32 i2cSpeed = 6;

optional ButtonLayout buttonLayout = 7;
optional ButtonLayoutRight buttonLayoutRight = 8;
optional ButtonLayoutCustomOptions buttonLayoutCustomOptions = 9;

optional SplashMode splashMode = 10;
optional SplashChoice splashChoice = 11;
optional int32 splashDuration = 12;
optional bytes splashImage = 13 [(nanopb).max_size = 1024];

optional int32 size = 14;
optional int32 flip = 15;
optional bool invert = 16;

optional int32 displaySaverTimeout = 17;

optional PinProfileIndicatorChoice pinProfileIndicatorChoice = 18;
optional PinProfileIndicatorPositionHorizontal pinProfileIndicatorPositionHorizontal = 19;
optional PinProfileIndicatorPositionVertical pinProfileIndicatorPositionVertical = 20;
optional int32 pinProfileIndicatorPositionVerticalOffset = 21;

optional SocdDisplayChoice socdDisplayChoice = 22;
}

message LEDOptions
Expand All @@ -173,7 +180,7 @@ message LEDOptions
optional uint32 ledsPerButton = 4;
optional uint32 brightnessMaximum = 5;
optional uint32 brightnessSteps = 6;

optional int32 indexUp = 7;
optional int32 indexDown = 8;
optional int32 indexLeft = 9;
Expand All @@ -192,7 +199,7 @@ message LEDOptions
optional int32 indexR3 = 22;
optional int32 indexA1 = 23;
optional int32 indexA2 = 24;

optional PLEDType pledType = 25;
optional int32 pledPin1 = 26;
optional int32 pledPin2 = 27;
Expand All @@ -211,7 +218,7 @@ message AnimationOptions_Proto
optional int32 chaseCycleTime = 5;
optional int32 rainbowCycleTime = 6;
optional uint32 themeIndex = 7;

optional bool hasCustomTheme = 8;
optional uint32 customThemeUp = 9;
optional uint32 customThemeDown = 10;
Expand Down Expand Up @@ -266,7 +273,7 @@ message OnBoardLedOptions
message AnalogOptions
{
optional bool enabled = 1;

optional int32 analogAdc1PinX = 2;
optional int32 analogAdc1PinY = 3;
optional bool forced_circularity = 4;
Expand All @@ -283,12 +290,12 @@ message AnalogOptions
message TurboOptions
{
optional bool enabled = 1;

optional int32 buttonPin = 2;
optional int32 ledPin = 3;
optional uint32 shotCount = 4;
optional int32 shmupDialPin = 5;

optional bool shmupModeEnabled = 6;
optional uint32 shmupAlwaysOn1 = 7;
optional uint32 shmupAlwaysOn2 = 8;
Expand All @@ -308,18 +315,18 @@ message TurboOptions
message SliderOptions
{
optional bool enabled = 1;

optional int32 pinLS = 2;
optional int32 pinRS = 3;
}

message SOCDSliderOptions
{
optional bool enabled = 1;

optional int32 pinOne = 2;
optional int32 pinTwo = 3;

optional SOCDMode modeDefault = 4;
optional SOCDMode modeOne = 5;
optional SOCDMode modeTwo = 6;
Expand All @@ -328,10 +335,10 @@ message SOCDSliderOptions
message ReverseOptions
{
optional bool enabled = 1;

optional int32 buttonPin = 2;
optional int32 ledPin = 3;

optional uint32 actionUp = 4;
optional uint32 actionDown = 5;
optional uint32 actionLeft = 6;
Expand All @@ -341,7 +348,7 @@ message ReverseOptions
message AnalogADS1219Options
{
optional bool enabled = 1;

optional int32 i2cBlock = 2;
optional int32 i2cSDAPin = 3;
optional int32 i2cSCLPin = 4;
Expand All @@ -352,12 +359,12 @@ message AnalogADS1219Options
message DualDirectionalOptions
{
optional bool enabled = 1;

optional int32 upPin = 2;
optional int32 downPin = 3;
optional int32 leftPin = 4;
optional int32 rightPin = 5;

optional DpadMode dpadMode = 6;
optional uint32 combineMode = 7;
optional bool fourWayMode = 8;
Expand Down Expand Up @@ -385,15 +392,15 @@ message TiltOptions
message BuzzerOptions
{
optional bool enabled = 1;

optional int32 pin = 2;
optional uint32 volume = 3;
}

message ExtraButtonOptions
{
optional bool enabled = 1;

optional int32 pin = 2;
optional uint32 buttonMap = 3;
}
Expand Down Expand Up @@ -480,7 +487,7 @@ message AddonOptions
message Config
{
optional string boardVersion = 1 [(nanopb).max_length = 31];

optional GamepadOptions gamepadOptions = 2;
optional HotkeyOptions hotkeyOptions = 3;
optional PinMappings pinMappings = 4;
Expand Down
Loading