From c1fa09aa0bc6e87dde956f3a5fcd47087a953899 Mon Sep 17 00:00:00 2001 From: Jens True Date: Mon, 21 Jun 2021 19:53:42 +0200 Subject: [PATCH] Horn signal will now be extended on multiple requests... --- Tidstagning/Relay.cs | 17 ++++++++++++++--- Tidstagning/Tidstagning.csproj | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Tidstagning/Relay.cs b/Tidstagning/Relay.cs index ab6228a..5403226 100644 --- a/Tidstagning/Relay.cs +++ b/Tidstagning/Relay.cs @@ -9,6 +9,7 @@ namespace Tidstagning { SerialPort com; Timer cooldownTimer; + Queue signals = new Queue(); public Relay(string ComPort = null) { com = new SerialPort(); @@ -26,11 +27,13 @@ namespace Tidstagning private void On() { + Debug.WriteLine("Output on"); Set(0x00, 0x01); } private void Off() { + Debug.WriteLine("Output off"); Set(0x00, 0x00); } @@ -42,12 +45,20 @@ namespace Tidstagning public void Sound(int time) { Debug.WriteLine("Requesting horn for: " + time.ToString() + "ms"); + signals.Enqueue(time); On(); - cooldownTimer = new System.Threading.Timer(x => + if (signals.Count == 1) + { + cooldownTimer = new System.Threading.Timer(x => { - Debug.WriteLine("Delayed off"); Off(); - }, null, new TimeSpan(0, 0, time / 1000), new System.TimeSpan(0)); + signals.Dequeue(); + }, null, signals.Peek(), Timeout.Infinite); + } + else + { + cooldownTimer.Change(signals.Peek(), Timeout.Infinite); + } } private void Set(int output, byte state) { diff --git a/Tidstagning/Tidstagning.csproj b/Tidstagning/Tidstagning.csproj index 1bca86b..cfda512 100644 --- a/Tidstagning/Tidstagning.csproj +++ b/Tidstagning/Tidstagning.csproj @@ -29,7 +29,7 @@ LEAX Lemvig Sejlklub false - 24 + 25 1.1.2.%2a true true