diff --git a/DMX-2.0/DriverBoitierV2.cs b/DMX-2.0/DriverBoitierV2.cs index de2d508..47529ca 100644 --- a/DMX-2.0/DriverBoitierV2.cs +++ b/DMX-2.0/DriverBoitierV2.cs @@ -2,18 +2,19 @@ using System; using System.Threading; using System.IO.Ports; using System.Xml; +using System.Collections.Generic; namespace DMX2 { - public class DriverBoitierV2 : DriverDMX//, IEventProvider + public class DriverBoitierV2 : DriverDMX, IEventProvider { - struct buttonState { - public buttonState(byte _button, bool _pressed){ - button=_button; pressed=_pressed; + struct dmxState { + public dmxState(int _dmx, byte _value){ + value=_value; dmx=_dmx; } - public byte button; - public bool pressed; + public int dmx; + public byte value; } enum etatAutomate { @@ -313,6 +314,8 @@ namespace DMX2 if(serial.BytesToRead>0) serial.ReadExisting (); + ProcessData(); + compteErreur= 0; } catch (Exception ex) { Console.WriteLine(serial.BytesToRead); @@ -382,6 +385,16 @@ namespace DMX2 etat = etatAutomate.Erreur; } + void ProcessData () + { + lock(watchdmx) + foreach (int dmx in watchdmx) { + if( inputbuffer[dmx-1]!= lastVal[dmx]){ + lastVal[dmx] = inputbuffer[dmx-1]; + eventsPending.Enqueue(new dmxState(dmx,inputbuffer[dmx-1])); + } + } + } public override void Dispose () { @@ -403,25 +416,33 @@ namespace DMX2 } #endregion - /* + #region IEventProvider implementation + List watchdmx = new List(); + Dictionary lastVal = new Dictionary(); static System.Text.RegularExpressions.Regex regexEventID = new System.Text.RegularExpressions.Regex( - @"BV2-B(?