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