Sure, how about this? It is basically the same as your Posedge_toggle class except that it allows the update method to also return the switch state so you don't have to make the get call.
Code:
class ToggleSwitch
{
private:
bool switchValue;
bool prevInput;
public:
ToggleSwitch(void)
: switchValue(false)
, prevInput(false)
{
}
bool GetSwitchValue(void)
{
return switchValue;
}
bool UpdateSwitchValue(bool currInput)
{
if (currInput != prevInput)
{
if (currInput)
{
switchValue = !switchValue;
}
prevInput = currInput;
}
return switchValue;
}
};
...
...
ToggleSwitch tankMode;
while (IsOperatorControl())
{
//
// Check for button 6 press.
//
if (tankMode.UpdateSwitchValue(secondaryController->GetRawButton(6)))
{
//
// Do tank drive.
//
}
else
{
//
// Do arcade drive.
//
}
wait(0.02);
}