From ce30d375c08da1181d77468fd69d43a3d891d951 Mon Sep 17 00:00:00 2001 From: thnikk Date: Sat, 14 Jan 2023 19:04:29 -0800 Subject: [PATCH 1/5] Added input history --- headers/addons/i2cdisplay.h | 6 ++- src/addons/i2cdisplay.cpp | 102 ++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/headers/addons/i2cdisplay.h b/headers/addons/i2cdisplay.h index 721efd160e..c56a5a2479 100644 --- a/headers/addons/i2cdisplay.h +++ b/headers/addons/i2cdisplay.h @@ -7,6 +7,7 @@ #define DISPLAY_H_ #include +#include #include #include "OneBitDisplay.h" #include "BoardConfig.h" @@ -69,6 +70,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 drawHistory(Gamepad*); void drawText(int startX, int startY, std::string text); void initMenu(char**); //Adding my stuff here, remember to sort before PR @@ -100,6 +102,8 @@ class I2CDisplayAddon : public GPAddon std::string statusBar; Gamepad* gamepad; Gamepad* pGamepad; + std::deque history; + bool last[17]; }; -#endif \ No newline at end of file +#endif diff --git a/src/addons/i2cdisplay.cpp b/src/addons/i2cdisplay.cpp index 2eeb071b48..32e8da3aa2 100644 --- a/src/addons/i2cdisplay.cpp +++ b/src/addons/i2cdisplay.cpp @@ -154,6 +154,7 @@ void I2CDisplayAddon::process() { } } + drawHistory(gamepad); obdDumpBuffer(&obd, NULL); } @@ -634,3 +635,104 @@ void I2CDisplayAddon::drawStatusBar(Gamepad * gamepad) } drawText(0, 0, statusBar); } + +void I2CDisplayAddon::drawHistory(Gamepad *gamepad) +{ + std::deque pressed; + + // Get key states + bool current[] = { + gamepad->pressedUp(), + gamepad->pressedDown(), + gamepad->pressedLeft(), + gamepad->pressedRight(), + gamepad->pressedB1(), + gamepad->pressedB2(), + gamepad->pressedR2(), + gamepad->pressedL2(), + gamepad->pressedB3(), + gamepad->pressedB4(), + gamepad->pressedR1(), + gamepad->pressedL1(), + gamepad->pressedL3(), + gamepad->pressedS1(), + gamepad->pressedA1(), + gamepad->pressedS2(), + gamepad->pressedR3(), + }; + + // Key names shown on display + std::string displayNames[][17] = { + { // DInput + "U", "D", "L", "R", + "2", "3", "8", "7", + "1", "4", "6", "5", + "11", "9", "13", "10", "12" + }, + { // Switch + "U", "D", "L", "R", + "B", "A", "ZR", "ZL", + "Y", "X", "R", "L", + "LS", "-", "H", "+", "RS" + }, + { // XInput + "U", "D", "L", "R", + "A", "B", "RT", "LT", + "X", "Y", "RB", "LB", + "L3", "S1", "A1", "S2", "R3" + } + }; + + uint8_t mode; + switch (gamepad->options.inputMode) + { + case INPUT_MODE_HID: mode=0; break; + case INPUT_MODE_SWITCH: mode=1; break; + case INPUT_MODE_XINPUT: mode=2; break; + } + + // Iterate through key list and add any pressed keys + for (uint8_t x=0; x<17; x++) { + if (current[x] != last[x]){ + if (current[x]) pressed.push_back(displayNames[mode][x]); + last[x] = current[x]; + } + } + + if (pressed.size() > 0) { + std::string newInput; + for(const auto &s : pressed) { + if(!newInput.empty()) + newInput += "+"; + newInput += s; + } + + history.push_back(newInput); + } + + if (history.size() > 10) { + history.pop_front(); + } + + std::string ret; + + for (auto it = history.crbegin(); it != history.crend(); ++it) { + if (ret.size() < 22) { + std::string newRet = ret; + if (!newRet.empty()) + newRet = " " + newRet; + + newRet = *it + newRet; + + if (newRet.size() < 22) { + ret = newRet; + } + else { + break; + } + } + } + + // Draw history at bottom of display + obdWriteString(&obd, 0, 0, 7, (char *)ret.c_str(), FONT_6x8, 0, 0); +} From c196172bc8dd5ed0843a60533fd5a7af27794ed5 Mon Sep 17 00:00:00 2001 From: thnikk Date: Sun, 15 Jan 2023 00:46:25 -0800 Subject: [PATCH 2/5] Updated directional values to include sticks --- src/addons/i2cdisplay.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/addons/i2cdisplay.cpp b/src/addons/i2cdisplay.cpp index 649d40c126..bbf43a4857 100644 --- a/src/addons/i2cdisplay.cpp +++ b/src/addons/i2cdisplay.cpp @@ -642,10 +642,10 @@ void I2CDisplayAddon::drawHistory(Gamepad *gamepad) // Get key states bool current[] = { - gamepad->pressedUp(), - gamepad->pressedDown(), - gamepad->pressedLeft(), - gamepad->pressedRight(), + pressedUp(), + pressedDown(), + pressedLeft(), + pressedRight(), gamepad->pressedB1(), gamepad->pressedB2(), gamepad->pressedR2(), From 513304705d0c03e5cacf995e199368baaccb5640 Mon Sep 17 00:00:00 2001 From: thnikk Date: Thu, 9 Feb 2023 03:13:35 -0800 Subject: [PATCH 3/5] History captures all simultaneous button presses --- headers/addons/i2cdisplay.h | 3 ++- src/addons/i2cdisplay.cpp | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/headers/addons/i2cdisplay.h b/headers/addons/i2cdisplay.h index 29c16a9247..c237e9a149 100644 --- a/headers/addons/i2cdisplay.h +++ b/headers/addons/i2cdisplay.h @@ -8,6 +8,7 @@ #include #include +#include #include #include "OneBitDisplay.h" #include "BoardConfig.h" @@ -130,7 +131,7 @@ class I2CDisplayAddon : public GPAddon Gamepad* gamepad; Gamepad* pGamepad; std::deque history; - bool last[17]; + std::array last; private: DisplayPreviewMode displayPreviewMode; uint16_t prevButtonState; diff --git a/src/addons/i2cdisplay.cpp b/src/addons/i2cdisplay.cpp index 193e6dc72e..6fe6b588c8 100644 --- a/src/addons/i2cdisplay.cpp +++ b/src/addons/i2cdisplay.cpp @@ -809,7 +809,7 @@ void I2CDisplayAddon::drawHistory(Gamepad *gamepad) std::deque pressed; // Get key states - bool current[] = { + std::array current = { pressedUp(), pressedDown(), pressedLeft(), @@ -859,13 +859,16 @@ void I2CDisplayAddon::drawHistory(Gamepad *gamepad) case INPUT_MODE_XINPUT: mode=2; break; } - // Iterate through key list and add any pressed keys - for (uint8_t x=0; x<17; x++) { - if (current[x] != last[x]){ - if (current[x]) pressed.push_back(displayNames[mode][x]); - last[x] = current[x]; - } - } + // Check if any new keys have been pressed + if (last != current) { + // Iterate through array + for (uint8_t x=0; x<17; x++) { + // Add any pressed keys to deque + if (current[x]) pressed.push_back(displayNames[mode][x]); + } + // Update the last keypress array + last = current; + } if (pressed.size() > 0) { std::string newInput; From e4bd21c70a4cd2e31743bf346b30e8d887c672cf Mon Sep 17 00:00:00 2001 From: thnikk Date: Wed, 15 Feb 2023 20:02:08 -0800 Subject: [PATCH 4/5] Moved some layouts up to make room for input history --- src/addons/i2cdisplay.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/addons/i2cdisplay.cpp b/src/addons/i2cdisplay.cpp index 69be7c5d19..4cd6901386 100644 --- a/src/addons/i2cdisplay.cpp +++ b/src/addons/i2cdisplay.cpp @@ -101,34 +101,34 @@ void I2CDisplayAddon::process() { switch (Storage::getInstance().GetButtonLayout()) { case BUTTON_LAYOUT_STICK: - drawArcadeStick(8, 28, 8, 2); + drawArcadeStick(8, 22, 8, 2); break; case BUTTON_LAYOUT_STICKLESS: drawStickless(8, 20, 8, 2); break; case BUTTON_LAYOUT_BUTTONS_ANGLED: - drawWasdBox(8, 28, 7, 3); + drawWasdBox(8, 22, 7, 3); break; case BUTTON_LAYOUT_BUTTONS_BASIC: - drawUDLR(8, 28, 8, 2); + drawUDLR(8, 22, 8, 2); break; case BUTTON_LAYOUT_KEYBOARD_ANGLED: - drawKeyboardAngled(18, 28, 5, 2); + drawKeyboardAngled(18, 24, 5, 2); break; case BUTTON_LAYOUT_KEYBOARDA: - drawMAMEA(8, 28, 10, 1); + drawMAMEA(8, 22, 10, 1); break; case BUTTON_LAYOUT_DANCEPADA: drawDancepadA(39, 12, 15, 2); break; case BUTTON_LAYOUT_TWINSTICKA: - drawTwinStickA(8, 28, 8, 2); + drawTwinStickA(8, 22, 8, 2); break; case BUTTON_LAYOUT_BLANKA: drawBlankA(0, 0, 0, 0); break; case BUTTON_LAYOUT_VLXA: - drawVLXA(7, 28, 7, 2); + drawVLXA(7, 22, 7, 2); break; case BUTTON_LAYOUT_FIGHTBOARD_STICK: drawArcadeStick(18, 22, 8, 2); @@ -141,46 +141,46 @@ void I2CDisplayAddon::process() { switch (Storage::getInstance().GetButtonLayoutRight()) { case BUTTON_LAYOUT_ARCADE: - drawArcadeButtons(8, 28, 8, 2); + drawArcadeButtons(8, 22, 8, 2); break; case BUTTON_LAYOUT_STICKLESSB: drawSticklessButtons(8, 20, 8, 2); break; case BUTTON_LAYOUT_BUTTONS_ANGLEDB: - drawWasdButtons(8, 28, 7, 3); + drawWasdButtons(8, 22, 7, 3); break; case BUTTON_LAYOUT_VEWLIX: - drawVewlix(8, 28, 8, 2); + drawVewlix(8, 22, 8, 2); break; case BUTTON_LAYOUT_VEWLIX7: - drawVewlix7(8, 28, 8, 2); + drawVewlix7(8, 22, 8, 2); break; case BUTTON_LAYOUT_CAPCOM: - drawCapcom(6, 28, 8, 2); + drawCapcom(6, 22, 8, 2); break; case BUTTON_LAYOUT_CAPCOM6: - drawCapcom6(16, 28, 8, 2); + drawCapcom6(16, 22, 8, 2); break; case BUTTON_LAYOUT_SEGA2P: - drawSega2p(8, 28, 8, 2); + drawSega2p(8, 22, 8, 2); break; case BUTTON_LAYOUT_NOIR8: - drawNoir8(8, 28, 8, 2); + drawNoir8(8, 22, 8, 2); break; case BUTTON_LAYOUT_KEYBOARDB: - drawMAMEB(68, 28, 10, 1); + drawMAMEB(68, 22, 10, 1); break; case BUTTON_LAYOUT_DANCEPADB: drawDancepadB(39, 12, 15, 2); break; case BUTTON_LAYOUT_TWINSTICKB: - drawTwinStickB(100, 28, 8, 2); + drawTwinStickB(100, 22, 8, 2); break; case BUTTON_LAYOUT_BLANKB: drawSticklessButtons(0, 0, 0, 0); break; case BUTTON_LAYOUT_VLXB: - drawVLXB(6, 28, 7, 2); + drawVLXB(6, 22, 7, 2); break; case BUTTON_LAYOUT_FIGHTBOARD: drawFightboard(8, 22, 7, 3); From ae48d4948553de3a31df7ee60297d3b12328ee12 Mon Sep 17 00:00:00 2001 From: thnikk Date: Fri, 17 Feb 2023 02:21:13 -0800 Subject: [PATCH 5/5] Shrunk dancepad layout and moved bottom button for stickless layout --- src/addons/i2cdisplay.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/addons/i2cdisplay.cpp b/src/addons/i2cdisplay.cpp index 4cd6901386..7d800725c5 100644 --- a/src/addons/i2cdisplay.cpp +++ b/src/addons/i2cdisplay.cpp @@ -119,7 +119,7 @@ void I2CDisplayAddon::process() { drawMAMEA(8, 22, 10, 1); break; case BUTTON_LAYOUT_DANCEPADA: - drawDancepadA(39, 12, 15, 2); + drawDancepadA(39, 10, 13, 2); break; case BUTTON_LAYOUT_TWINSTICKA: drawTwinStickA(8, 22, 8, 2); @@ -171,7 +171,7 @@ void I2CDisplayAddon::process() { drawMAMEB(68, 22, 10, 1); break; case BUTTON_LAYOUT_DANCEPADB: - drawDancepadB(39, 12, 15, 2); + drawDancepadB(39, 10, 13, 2); break; case BUTTON_LAYOUT_TWINSTICKB: drawTwinStickB(100, 22, 8, 2); @@ -290,7 +290,7 @@ void I2CDisplayAddon::drawStickless(int startX, int startY, int buttonRadius, in obdPreciseEllipse(&obd, startX, startY, buttonRadius, buttonRadius, 1, pressedLeft()); obdPreciseEllipse(&obd, startX + buttonMargin, startY, buttonRadius, buttonRadius, 1, pressedDown()); obdPreciseEllipse(&obd, startX + (buttonMargin * 1.875), startY + (buttonMargin / 2), buttonRadius, buttonRadius, 1, pressedRight()); - obdPreciseEllipse(&obd, startX + (buttonMargin * 2.25), startY + buttonMargin * 1.875, buttonRadius, buttonRadius, 1, pressedUp()); + obdPreciseEllipse(&obd, startX + (buttonMargin * 1.875), startY + (buttonMargin * 1.5), buttonRadius, buttonRadius, 1, pressedUp()); } void I2CDisplayAddon::drawWasdBox(int startX, int startY, int buttonRadius, int buttonPadding)