Skip to content

Commit

Permalink
Bugfix turbo presses not releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Electronicks committed Mar 29, 2021
1 parent f557954 commit c3d242b
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions JoyShockMapper/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,24 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
}

BtnEvent applyEvt, releaseEvt;
switch (actMod)
{
case ActionModifier::Toggle:
apply = bind(&DigitalButton::ApplyButtonToggle, placeholders::_1, key, apply, release);
release = OnEventAction();
break;
case ActionModifier::Instant:
{
OnEventAction action2 = bind(&DigitalButton::RegisterInstant, placeholders::_1, applyEvt);
apply = bind(&Mapping::RunBothActions, placeholders::_1, apply, action2);
releaseEvt = BtnEvent::OnInstantRelease;
}
break;
case ActionModifier::INVALID:
return false;
// None applies no modification... Hey!
}

switch (evtMod)
{
case EventModifier::StartPress:
Expand All @@ -786,30 +804,13 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
case EventModifier::TurboPress:
applyEvt = BtnEvent::OnTurbo;
releaseEvt = BtnEvent::OnTurbo;
InsertEventMapping(BtnEvent::OnRelease, release); // On turbo you also need to clear the turbo on release
break;
default: // EventModifier::INVALID or None
return false;
}

switch (actMod)
{
case ActionModifier::Toggle:
apply = bind(&DigitalButton::ApplyButtonToggle, placeholders::_1, key, apply, release);
release = OnEventAction();
break;
case ActionModifier::Instant:
{
OnEventAction action2 = bind(&DigitalButton::RegisterInstant, placeholders::_1, applyEvt);
apply = bind(&Mapping::RunBothActions, placeholders::_1, apply, action2);
releaseEvt = BtnEvent::OnInstantRelease;
}
break;
case ActionModifier::INVALID:
return false;
// None applies no modification... Hey!
}

// Insert release first because in turbo's case apply and release are the same but we want release to apply first
// Insert release first because in turbo's case apply and release are the same but we want release to happen first
InsertEventMapping(releaseEvt, release);
InsertEventMapping(applyEvt, apply);
return true;
Expand Down

0 comments on commit c3d242b

Please sign in to comment.