From 8e68a51ed4935272fcc04b02e768c39e18672d3b Mon Sep 17 00:00:00 2001 From: thrust26 Date: Wed, 8 May 2019 20:12:48 +0200 Subject: [PATCH] add first coarse stab at paddle anti-flicker --- src/emucore/Paddles.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/emucore/Paddles.cxx b/src/emucore/Paddles.cxx index b2426e049..81be0c501 100644 --- a/src/emucore/Paddles.cxx +++ b/src/emucore/Paddles.cxx @@ -260,13 +260,24 @@ void Paddles::update() bool sa_changed = false; int sa_xaxis = myEvent.get(myP0AxisValue); int sa_yaxis = myEvent.get(myP1AxisValue); + const double factor1 = 0.2; // TODO: configurable + const double factor2 = 1.0 / 256; + if(abs(myLastAxisX - sa_xaxis) > 10) { + // anti jitter + double dFactor = std::pow(factor1, 1 / (abs(sa_xaxis - myLastAxisX) * factor2)); + sa_xaxis = sa_xaxis * dFactor + myLastAxisX * (1 - dFactor); + setPin(AnalogPin::Nine, Int32(MAX_RESISTANCE * ((32767 - Int16(sa_xaxis)) / 65536.0))); sa_changed = true; } if(abs(myLastAxisY - sa_yaxis) > 10) { + // anti jitter + double dFactor = std::pow(factor1, 1 / (abs(sa_yaxis - myLastAxisY) * factor2)); + sa_yaxis = sa_yaxis * dFactor + myLastAxisY * (1 - dFactor); + setPin(AnalogPin::Five, Int32(MAX_RESISTANCE * ((32767 - Int16(sa_yaxis)) / 65536.0))); sa_changed = true; }