From 5bc94d60a17039dfd5d46caaa292d3667fa87fb3 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 1 Apr 2014 21:35:31 +0300 Subject: [PATCH] Use current monitoring to detect failed turnouts The turnout solenoid takes quite a bit of current, which is easy to detect. If there's no current spike after activating a solenoid, it may have a broken microswitch that prevents operation. --- source/libr2c2/arducontrol.cpp | 21 ++++++++++++++++++++- source/libr2c2/arducontrol.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/source/libr2c2/arducontrol.cpp b/source/libr2c2/arducontrol.cpp index dbe3013..fa95a69 100644 --- a/source/libr2c2/arducontrol.cpp +++ b/source/libr2c2/arducontrol.cpp @@ -405,6 +405,8 @@ void ArduControl::tick() acc.state.set(acc.state^lowest_bit); PendingCommand cmd(acc, Accessory::ACTIVATE, i); command_queue.push(cmd); + + monitor.reset_peak(); } else accessory_queue.pop_front(); @@ -415,8 +417,23 @@ void ArduControl::tick() Time::TimeStamp t = Time::now(); if(t>off_timeout) { + Accessory &acc = *active_accessory; + + if(acc.kind==Accessory::TURNOUT && monitor.get_peak()<0.5f) + { + unsigned bit = 1< state; + unsigned uncertain; unsigned target; Msp::Time::TimeDelta active_time; -- 2.43.0