From 85dba3e775b10d1a653175318e79881e416db19a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 2 Feb 2015 19:40:43 +0200 Subject: [PATCH] Improve accessory switching logic The off command can be sent as soon as the current monitor indicates that the solenoid is no longer drawing power. This allows giving multi-bit accessories more time to accommodate quirks of the 74465 decoder. --- source/libr2c2/arducontrol.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/libr2c2/arducontrol.cpp b/source/libr2c2/arducontrol.cpp index 8e28ea6..6d75c75 100644 --- a/source/libr2c2/arducontrol.cpp +++ b/source/libr2c2/arducontrol.cpp @@ -459,8 +459,9 @@ void ArduControl::tick() if(active_accessory && off_timeout) { + bool success = (monitor.get_peak()>0.35f && monitor.get_current()off_timeout) + if(t>off_timeout || success) { Accessory &acc = *active_accessory; @@ -469,7 +470,7 @@ void ArduControl::tick() // Assume success if we were uncertain of the physical setting if(acc.uncertain&bit) acc.uncertain &= ~bit; - else if(acc.kind==Accessory::TURNOUT && monitor.get_peak()<0.5f) + else if(acc.kind==Accessory::TURNOUT && !success) { if(debug>=1) IO::print("Peak current only %.2f A\n", monitor.get_peak()); @@ -597,7 +598,7 @@ ArduControl::Accessory::Accessory(Kind k, unsigned a, unsigned b, unsigned s): state(0), uncertain((1<