Skip to content

Commit

Permalink
fix issue 1183 (#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickGuyver authored Oct 4, 2024
1 parent 6dc79d0 commit 995f6ce
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/addons/analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ void AnalogInput::setup() {

void AnalogInput::process() {
Gamepad * gamepad = Storage::getInstance().GetGamepad();

uint16_t joystickMid = GAMEPAD_JOYSTICK_MID;
if ( DriverManager::getInstance().getDriver() != nullptr ) {
joystickMid = DriverManager::getInstance().getDriver()->GetJoystickMidValue();
}

for(int i = 0; i < ADC_COUNT; i++) {
// Read X-Axis
if (isValidPin(adc_pairs[i].x_pin)) {
Expand Down Expand Up @@ -109,15 +115,15 @@ void AnalogInput::process() {
}

if (adc_pairs[i].analog_dpad == DpadMode::DPAD_MODE_LEFT_ANALOG) {
if ( DriverManager::getInstance().getDriver()->GetJoystickMidValue() == 0x8000 ) {
if ( joystickMid == 0x8000 ) {
gamepad->state.lx = static_cast<uint16_t>(std::ceil(65535.0f * adc_pairs[i].x_value));
gamepad->state.ly = static_cast<uint16_t>(std::ceil(65535.0f * adc_pairs[i].y_value));
} else { // 0x7FFF
gamepad->state.lx = static_cast<uint16_t>(65535.0f * adc_pairs[i].x_value);
gamepad->state.ly = static_cast<uint16_t>(65535.0f * adc_pairs[i].y_value);
}
} else if (adc_pairs[i].analog_dpad == DpadMode::DPAD_MODE_RIGHT_ANALOG) {
if ( DriverManager::getInstance().getDriver()->GetJoystickMidValue() == 0x8000 ) {
if ( joystickMid == 0x8000 ) {
gamepad->state.rx = static_cast<uint16_t>(std::ceil(65535.0f * adc_pairs[i].x_value));
gamepad->state.ry = static_cast<uint16_t>(std::ceil(65535.0f * adc_pairs[i].y_value));
} else { // 0x7FFF
Expand Down

0 comments on commit 995f6ce

Please sign in to comment.