Skip to content

Commit

Permalink
Fixed pin checks which also fixes our input latency (#152)
Browse files Browse the repository at this point in the history
Fixed pin checks for Reverse and Turbo, as well as a Web Config pin check that was missed.

Also decreased minimum Turbo shots from 5 to 2 (much slower).
  • Loading branch information
arntsonl committed Apr 16, 2023
1 parent 29ee73a commit ffb1bfb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/addons/reverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void ReverseInput::setup()
// Setup Reverse LED if available
AddonOptions options = Storage::getInstance().getAddonOptions();
pinLED = options.pinReverseLED;
if (pinLED != -1) {
if (pinLED != (uint8_t)-1) {
gpio_init(options.pinReverseLED);
gpio_set_dir(options.pinReverseLED, GPIO_OUT);
gpio_put(options.pinReverseLED, 1);
Expand Down Expand Up @@ -69,7 +69,7 @@ void ReverseInput::process()
| input(values & mapDpadRight->pinMask, mapDpadRight->buttonMask, mapDpadLeft->buttonMask, actionRight, invertXAxis)
;

if (pinLED != -1) {
if (pinLED != (uint8_t)-1) {
gpio_put(pinLED, !state);
}
}
18 changes: 9 additions & 9 deletions src/addons/turbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "storagemanager.h"

#define TURBO_SHOT_MIN 5
#define TURBO_SHOT_MIN 2
#define TURBO_SHOT_MAX 30

bool TurboInput::available() {
Expand All @@ -19,14 +19,14 @@ void TurboInput::setup()
uint32_t now = getMillis();

// Setup TURBO Key GPIO
if ( options.pinButtonTurbo != -1 ) {
if ( options.pinButtonTurbo != (uint8_t)-1 ) {
gpio_init( options.pinButtonTurbo); // Initialize pin
gpio_set_dir( options.pinButtonTurbo, GPIO_IN); // Set as INPUT
gpio_pull_up( options.pinButtonTurbo); // Set as PULLUP
}

// Turbo Dial
if ( options.pinShmupDial != -1 ) {
if ( options.pinShmupDial != (uint8_t)-1 ) {
adc_gpio_init(options.pinShmupDial);
adcShmupDial = 26 - options.pinShmupDial;
adc_select_input(adcShmupDial);
Expand All @@ -37,7 +37,7 @@ void TurboInput::setup()
}

// Setup Turbo LED if available
if (options.pinTurboLED != -1) {
if (options.pinTurboLED != (uint8_t)-1) {
gpio_init(options.pinTurboLED);
gpio_set_dir(options.pinTurboLED, GPIO_OUT);
gpio_put(options.pinTurboLED, 1);
Expand All @@ -50,7 +50,7 @@ void TurboInput::setup()
shmupBtnPin[2] = options.pinShmupBtn3;
shmupBtnPin[3] = options.pinShmupBtn4;
for (uint8_t i = 0; i < 4; i++) {
if ( shmupBtnPin[i] != -1 ) {
if ( shmupBtnPin[i] != (uint8_t)-1 ) {
gpio_init(shmupBtnPin[i]);
gpio_set_dir(shmupBtnPin[i], GPIO_IN);
gpio_pull_up(shmupBtnPin[i]);
Expand Down Expand Up @@ -89,7 +89,7 @@ void TurboInput::setup()
void TurboInput::read(AddonOptions & options)
{
// Get Charge Buttons
if ( options.shmupMode ) {
if ( options.shmupMode == 1 ) {
chargeState = 0;
for (uint8_t i = 0; i < 4; i++) {
if ( shmupBtnPin[i] != -1 ) { // if pin, get the GPIO
Expand Down Expand Up @@ -168,7 +168,7 @@ void TurboInput::process()
}

// Use the dial to modify our turbo shot speed (don't save on dial modify)
if ( options.pinShmupDial != -1 ) {
if ( options.pinShmupDial != (uint8_t)-1 ) {
adc_select_input(adcShmupDial);
uint16_t rawValue = adc_read();
if ( rawValue != dialValue ) {
Expand All @@ -180,7 +180,7 @@ void TurboInput::process()
}

// Set TURBO LED if a button is going or turbo is too fast
if ( options.pinTurboLED != -1 ) {
if ( options.pinTurboLED != (uint8_t)-1 ) {
if ((gamepad->state.buttons & turboButtonsPressed) && !bTurboFlicker) {
gpio_put(options.pinTurboLED, 0);
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,17 +418,17 @@ std::string getLedOptions()
usedPins.add(gamepad->mapButtonA2->pin);

BoardOptions boardOptions = Storage::getInstance().getBoardOptions();
if (boardOptions.i2cSDAPin != -1)
if (boardOptions.i2cSDAPin != (uint8_t)-1)
usedPins.add(boardOptions.i2cSDAPin);
if (boardOptions.i2cSCLPin != -1)
if (boardOptions.i2cSCLPin != (uint8_t)-1)
usedPins.add(boardOptions.i2cSCLPin);

AddonOptions addonOptions = Storage::getInstance().getAddonOptions();
if (addonOptions.analogAdcPinX != -1)
if (addonOptions.analogAdcPinX != (uint8_t)-1)
usedPins.add(addonOptions.analogAdcPinX);
if (addonOptions.analogAdcPinY != -1)
if (addonOptions.analogAdcPinY != (uint8_t)-1)
usedPins.add(addonOptions.analogAdcPinY);
if (addonOptions.buzzerPin != -1)
if (addonOptions.buzzerPin != (uint8_t)-1)
usedPins.add(addonOptions.buzzerPin);

return serialize_json(doc);
Expand Down

0 comments on commit ffb1bfb

Please sign in to comment.