Skip to content

Commit

Permalink
JSlider single-pin fix (#420)
Browse files Browse the repository at this point in the history
* Modifying jslider to fix single-pin assignment issue.

* Fixed variable names
  • Loading branch information
arntsonl authored Jul 21, 2023
1 parent 368f942 commit 76aa664
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
2 changes: 0 additions & 2 deletions headers/addons/jslider.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class JSliderInput : public GPAddon {
DpadMode dpadState; // Saved locally for debounce
DpadMode dDebState; // Debounce JSlider State
uint32_t uDebTime; // Debounce JSlider Time
uint8_t pinSliderLS;
uint8_t pinSliderRS;
};

#endif // _JSlider_H_
33 changes: 17 additions & 16 deletions src/addons/jslider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@

bool JSliderInput::available() {
const SliderOptions& options = Storage::getInstance().getAddonOptions().sliderOptions;
return ( options.enabled && isValidPin(options.pinLS) && isValidPin(options.pinRS) );
return ( options.enabled && (isValidPin(options.pinLS) || isValidPin(options.pinRS)) );
}

void JSliderInput::setup()
{
const SliderOptions& options = Storage::getInstance().getAddonOptions().sliderOptions;
pinSliderLS = options.pinLS;
pinSliderRS = options.pinRS;

gpio_init(pinSliderLS); // Initialize pin
gpio_set_dir(pinSliderLS, GPIO_IN); // Set as INPUT
gpio_pull_up(pinSliderLS); // Set as PULLUP
gpio_init(pinSliderRS);
gpio_set_dir(pinSliderRS, GPIO_IN); // Set as INPUT
gpio_pull_up(pinSliderRS); // Set as PULLUP
if ( isValidPin(options.pinLS)) {
gpio_init(options.pinLS); // Initialize pin
gpio_set_dir(options.pinLS, GPIO_IN); // Set as INPUT
gpio_pull_up(options.pinLS); // Set as PULLUP
}
if ( isValidPin(options.pinRS)) {
gpio_init(options.pinRS);
gpio_set_dir(options.pinRS, GPIO_IN); // Set as INPUT
gpio_pull_up(options.pinRS); // Set as PULLUP
}
}

DpadMode JSliderInput::read() {
if ( pinSliderLS != (uint8_t)-1 && pinSliderRS != (uint8_t)-1) {
if ( !gpio_get(pinSliderLS)) {
return DPAD_MODE_LEFT_ANALOG;
} else if ( !gpio_get(pinSliderRS)) {
return DPAD_MODE_RIGHT_ANALOG;
}
const SliderOptions& options = Storage::getInstance().getAddonOptions().sliderOptions;
if ( isValidPin(options.pinLS) && !gpio_get(options.pinLS)) {
return DPAD_MODE_LEFT_ANALOG;
}
if ( isValidPin(options.pinRS) && !gpio_get(options.pinRS)) {
return DPAD_MODE_RIGHT_ANALOG;
}
return DPAD_MODE_DIGITAL;
}
Expand Down

0 comments on commit 76aa664

Please sign in to comment.