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

Re-implement input history #602 #630

Merged
merged 8 commits into from
Nov 20, 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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ src/addons/slider_socd.cpp
src/addons/wiiext.cpp
src/addons/input_macro.cpp
src/addons/snes_input.cpp
src/addons/inputhistory.cpp
src/gamepad/GamepadDebouncer.cpp
src/gamepad/GamepadDescriptors.cpp
src/addons/tilt.cpp
Expand Down
4 changes: 4 additions & 0 deletions headers/addons/i2cdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "peripheralmanager.h"
#include "peripheral_i2c.h"
#include "peripheral_spi.h"
#include "addons/inputhistory.h"

#ifndef HAS_I2C_DISPLAY
#define HAS_I2C_DISPLAY -1
Expand Down Expand Up @@ -149,6 +150,7 @@ class I2CDisplayAddon : public GPAddon
virtual void preprocess() {}
virtual void process();
virtual std::string name() { return I2CDisplayName; }
virtual void attachInputHistoryAddon(InputHistoryAddon*);
private:
int initDisplay(int typeOverride);
bool isSH1106(int detectedDisplay);
Expand Down Expand Up @@ -222,6 +224,8 @@ class I2CDisplayAddon : public GPAddon
bool isFocusModeEnabled;
bool focusModePrevState;
bool turnOffWhenSuspended;
bool isInputHistoryEnabled;
InputHistoryAddon* inputHistoryAddon;
};

#endif
54 changes: 54 additions & 0 deletions headers/addons/inputhistory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef INPUT_HISTORY_H_
#define INPUT_HISTORY_H_

#include "OneBitDisplay.h"

#include <vector>
#include <string>
#include "gpaddon.h"
#include <deque>
#include <array>

#ifndef INPUT_HISTORY_ENABLED
#define INPUT_HISTORY_ENABLED 0
#endif

#ifndef INPUT_HISTORY_LENGTH
#define INPUT_HISTORY_LENGTH 21
#endif

#ifndef INPUT_HISTORY_COL
#define INPUT_HISTORY_COL 0
#endif

#ifndef INPUT_HISTORY_ROW
#define INPUT_HISTORY_ROW 7
#endif

#define InputHistoryName "InputHistory"

class InputHistoryAddon : public GPAddon
{
public:
virtual bool available();
virtual void setup();
virtual void preprocess() {}
virtual void process();
virtual std::string name() { return InputHistoryName; }
virtual void drawHistory(OBDISP *pOBD);
private:
uint32_t historyLength;
uint32_t col;
uint32_t row;
std::string historyString;
std::deque<std::string> inputHistory;
std::array<bool, 18> lastInput;
Gamepad* gamepad;
Gamepad* pGamepad;
bool pressedUp();
bool pressedDown();
bool pressedLeft();
bool pressedRight();
};

#endif
9 changes: 9 additions & 0 deletions proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,14 @@ message MacroOptions
repeated Macro macroList = 3 [(nanopb).max_count = 6];
}

message InputHistoryOptions
{
optional bool enabled = 1;
optional uint32 length = 2;
optional uint32 col = 3;
optional uint32 row = 4;
}

message AddonOptions
{
optional BootselButtonOptions bootselButtonOptions = 1;
Expand All @@ -682,6 +690,7 @@ message AddonOptions
optional TiltOptions tiltOptions = 18;
optional PSPassthroughOptions psPassthroughOptions = 19;
optional MacroOptions macroOptions = 20;
optional InputHistoryOptions inputHistoryOptions = 21;
}

message MigrationHistory
Expand Down
55 changes: 55 additions & 0 deletions site/docs/add-ons/input-history.mdx
InfraredAces marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: Input History
# tags:
# -
pagination_next: null
pagination_prev: null
description: "Add-on to show input history"
---

# Input History

Purpose: This add-on is intended to allow you to display input history

![GP2040-CE Configurator - Add-Ons Input History](../assets/images/gpc-add-ons-input-history.png)

## Web Configurator Options

- `History Length` - Set the max character length of the history.
- `Column` - Specify the column at which the history begins on the display. ( 0 - left, 20 - right )
- `Row` - Specify the row on which the history appears on the display. ( 0 - top, 7 - bottom )

## Hardware

### Requirements

An already configured [monochrome display](../web-configurator/menu-pages/07-display-configuration.mdx).

### Installation

None.

## Miscellaneous Notes

Input - Symbol mapping:

| GP2040-CE | PS3 | Switch | XINPUT | KEYBOARD | PS4 | CONFIG |
|-----------|:---:|:------:|:------:|:--------:|:---:|:------:|
| Up | U | U | U | U | U | U |
| Down | D | D | D | D | D | D |
| Left | L | L | L | L | L | L |
| Right | R | R | R | R | R | R |
| B1 | X | B | A | B1 | X | B1 |
| B2 | O | A | B | B2 | O | B2 |
| B3 | # | Y | X | B3 | # | B3 |
| B4 | ^ | X | Y | B4 | ^ | B4 |
| L1 | L1 | L | LB | L1 | L1 | L1 |
| R1 | R1 | R | RB | R1 | R1 | R1 |
| L2 | L2 | ZL | LT | L2 | L2 | L2 |
| R2 | R2 | ZR | RT | R2 | R2 | R2 |
| S1 | SL | - | BK | S1 | SH | S1 |
| S2 | ST | + | ST | S2 | OP | S2 |
| L3 | L3 | LS | LS | L3 | L3 | L3 |
| R3 | R3 | RS | RS | R3 | R3 | R3 |
| A1 | PS | H | G | A1 | PS | A1 |
| A2 | A2 | C | A2 | A2 | T | A2 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Some of these add-ons are experimental and not all add-ons are interoperable wit
- [Extra Button Configuration](../../add-ons/extra-button.mdx)
- [Focus Mode Configuration](../../add-ons/focus-mode.mdx)
- [I2C Analog ADS1219](../../add-ons/i2c-analog-ads1219.mdx)
- [Input History](../../add-ons/input-history.mdx)
- [Input Reverse](../../add-ons/input-reverse.mdx)
- [Joystick Selection Slider](../../add-ons/joystick-selection-slider.mdx)
- [Keyboard Host Configuration](../../add-ons/keyboard-host.mdx)
Expand Down
66 changes: 39 additions & 27 deletions src/addons/i2cdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ void I2CDisplayAddon::setup() {
displaySaverTimeout = displaySaverTimer;
configMode = Storage::getInstance().GetConfigMode();
turnOffWhenSuspended = options.turnOffWhenSuspended;

const InputHistoryOptions& inputHistoryOptions = Storage::getInstance().getAddonOptions().inputHistoryOptions;
isInputHistoryEnabled = inputHistoryOptions.enabled;
}

bool I2CDisplayAddon::isDisplayPowerOff()
Expand All @@ -75,7 +78,7 @@ bool I2CDisplayAddon::isDisplayPowerOff()
} else if (!!displaySaverTimeout && displaySaverTimer <= 0) {
setDisplayPower(0);
}

if (isFocusModeEnabled) {
const FocusModeOptions& focusModeOptions = Storage::getInstance().getAddonOptions().focusModeOptions;
bool isFocusModeActive = !gpio_get(focusModeOptions.pin);
Expand Down Expand Up @@ -131,37 +134,37 @@ void I2CDisplayAddon::process() {

switch (options.buttonLayout) {
case BUTTON_LAYOUT_STICK:
drawArcadeStick(8, 28, 8, 2);
drawArcadeStick(8, (isInputHistoryEnabled ? 22 : 28), 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, (isInputHistoryEnabled ? 22 : 28), 7, 3);
break;
case BUTTON_LAYOUT_BUTTONS_BASIC:
drawUDLR(8, 28, 8, 2);
drawUDLR(8, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_KEYBOARD_ANGLED:
drawKeyboardAngled(18, 28, 5, 2);
drawKeyboardAngled(18, (isInputHistoryEnabled ? 24 : 28), 5, 2);
break;
case BUTTON_LAYOUT_KEYBOARDA:
drawMAMEA(8, 28, 10, 1);
drawMAMEA(8, (isInputHistoryEnabled ? 22 : 28), 10, 1);
break;
case BUTTON_LAYOUT_OPENCORE0WASDA:
drawOpenCore0WASDA(16, 28, 10, 1);
drawOpenCore0WASDA(16, (isInputHistoryEnabled ? 22 : 28), 10, 1);
break;
case BUTTON_LAYOUT_DANCEPADA:
drawDancepadA(39, 12, 15, 2);
drawDancepadA(39, (isInputHistoryEnabled ? 10 : 12), (isInputHistoryEnabled ? 13 : 15), 2);
break;
case BUTTON_LAYOUT_TWINSTICKA:
drawTwinStickA(8, 28, 8, 2);
drawTwinStickA(8, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_BLANKA:
drawBlankA(0, 0, 0, 0);
break;
case BUTTON_LAYOUT_VLXA:
drawVLXA(7, 28, 7, 2);
drawVLXA(7, (isInputHistoryEnabled ? 22 : 28), 7, 2);
break;
case BUTTON_LAYOUT_CUSTOMA:
drawButtonLayoutLeft(buttonLayoutCustomOptions.paramsLeft);
Expand All @@ -176,52 +179,52 @@ void I2CDisplayAddon::process() {

switch (options.buttonLayoutRight) {
case BUTTON_LAYOUT_ARCADE:
drawArcadeButtons(8, 28, 8, 2);
drawArcadeButtons(8, (isInputHistoryEnabled ? 22 : 28), 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, (isInputHistoryEnabled ? 22 : 28), 7, 3);
break;
case BUTTON_LAYOUT_VEWLIX:
drawVewlix(8, 28, 8, 2);
drawVewlix(8, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_VEWLIX7:
drawVewlix7(8, 28, 8, 2);
drawVewlix7(8, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_CAPCOM:
drawCapcom(6, 28, 8, 2);
drawCapcom(6, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_CAPCOM6:
drawCapcom6(16, 28, 8, 2);
drawCapcom6(16, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_SEGA2P:
drawSega2p(8, 28, 8, 2);
drawSega2p(8, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_NOIR8:
drawNoir8(8, 28, 8, 2);
drawNoir8(8, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_KEYBOARDB:
drawMAMEB(68, 28, 10, 1);
drawMAMEB(68, (isInputHistoryEnabled ? 22 : 28), 10, 1);
break;
case BUTTON_LAYOUT_KEYBOARD8B:
drawMAME8B(68, 28, 10, 1);
drawMAME8B(68, (isInputHistoryEnabled ? 22 : 28), 10, 1);
break;
case BUTTON_LAYOUT_OPENCORE0WASDB:
drawOpenCore0WASDB(68, 28, 10, 1);
break;
drawOpenCore0WASDB(68, (isInputHistoryEnabled ? 22 : 28), 10, 1);
break;
case BUTTON_LAYOUT_DANCEPADB:
drawDancepadB(39, 12, 15, 2);
drawDancepadB(39, (isInputHistoryEnabled ? 10 : 12), (isInputHistoryEnabled ? 13 : 15), 2);
break;
case BUTTON_LAYOUT_TWINSTICKB:
drawTwinStickB(100, 28, 8, 2);
drawTwinStickB(100, (isInputHistoryEnabled ? 22 : 28), 8, 2);
break;
case BUTTON_LAYOUT_BLANKB:
drawSticklessButtons(0, 0, 0, 0);
break;
case BUTTON_LAYOUT_VLXB:
drawVLXB(6, 28, 7, 2);
drawVLXB(6, (isInputHistoryEnabled ? 22 : 28), 7, 2);
break;
case BUTTON_LAYOUT_CUSTOMB:
drawButtonLayoutRight(buttonLayoutCustomOptions.paramsRight);
Expand All @@ -233,6 +236,11 @@ void I2CDisplayAddon::process() {
drawArcadeStick(90, 22, 8, 2);
break;
}

if(isInputHistoryEnabled && inputHistoryAddon != nullptr) {
inputHistoryAddon->drawHistory(&obd);
}

break;
}

Expand Down Expand Up @@ -376,7 +384,7 @@ void I2CDisplayAddon::drawButtonLayoutLeft(ButtonLayoutParamsLeft& options)
break;
case BUTTON_LAYOUT_OPENCORE0WASDA:
drawOpenCore0WASDA(startX, startY, buttonRadius, buttonPadding);
break;
break;
case BUTTON_LAYOUT_DANCEPADA:
drawDancepadA(startX, startY, buttonRadius, buttonPadding);
break;
Expand Down Expand Up @@ -488,7 +496,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 * (isInputHistoryEnabled ? 1.875 : 2.25)), startY + buttonMargin * (isInputHistoryEnabled ? 1.5 : 1.875), buttonRadius, buttonRadius, 1, pressedUp());
}

void I2CDisplayAddon::drawWasdBox(int startX, int startY, int buttonRadius, int buttonPadding)
Expand Down Expand Up @@ -1103,3 +1111,7 @@ bool I2CDisplayAddon::pressedRight()

return false;
}

void I2CDisplayAddon::attachInputHistoryAddon(InputHistoryAddon* pInputHistoryAddon) {
inputHistoryAddon = pInputHistoryAddon;
}
Loading