Ajout des evenements sur entrée DMX
This commit is contained in:
parent
636106176a
commit
70bc875ea1
1 changed files with 69 additions and 28 deletions
|
|
@ -2,18 +2,19 @@ using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DMX2
|
namespace DMX2
|
||||||
{
|
{
|
||||||
public class DriverBoitierV2 : DriverDMX//, IEventProvider
|
public class DriverBoitierV2 : DriverDMX, IEventProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
struct buttonState {
|
struct dmxState {
|
||||||
public buttonState(byte _button, bool _pressed){
|
public dmxState(int _dmx, byte _value){
|
||||||
button=_button; pressed=_pressed;
|
value=_value; dmx=_dmx;
|
||||||
}
|
}
|
||||||
public byte button;
|
public int dmx;
|
||||||
public bool pressed;
|
public byte value;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum etatAutomate {
|
enum etatAutomate {
|
||||||
|
|
@ -313,6 +314,8 @@ namespace DMX2
|
||||||
if(serial.BytesToRead>0)
|
if(serial.BytesToRead>0)
|
||||||
serial.ReadExisting ();
|
serial.ReadExisting ();
|
||||||
|
|
||||||
|
ProcessData();
|
||||||
|
|
||||||
compteErreur= 0;
|
compteErreur= 0;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Console.WriteLine(serial.BytesToRead);
|
Console.WriteLine(serial.BytesToRead);
|
||||||
|
|
@ -382,6 +385,16 @@ namespace DMX2
|
||||||
etat = etatAutomate.Erreur;
|
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 ()
|
public override void Dispose ()
|
||||||
{
|
{
|
||||||
|
|
@ -403,25 +416,33 @@ namespace DMX2
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
#region IEventProvider implementation
|
#region IEventProvider implementation
|
||||||
|
|
||||||
|
List<int> watchdmx = new List<int>();
|
||||||
|
Dictionary<int,byte> lastVal = new Dictionary<int, byte>();
|
||||||
|
|
||||||
static System.Text.RegularExpressions.Regex regexEventID = new System.Text.RegularExpressions.Regex(
|
static System.Text.RegularExpressions.Regex regexEventID = new System.Text.RegularExpressions.Regex(
|
||||||
@"BV2-B(?<button>\d+)?",
|
@"BV2-D(?<dmx>\d+)?",
|
||||||
System.Text.RegularExpressions.RegexOptions.Compiled);
|
System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||||
|
|
||||||
System.Collections.Concurrent.ConcurrentQueue<buttonState> eventsPending =
|
System.Collections.Concurrent.ConcurrentQueue<dmxState> eventsPending =
|
||||||
new System.Collections.Concurrent.ConcurrentQueue<buttonState>();
|
new System.Collections.Concurrent.ConcurrentQueue<dmxState>();
|
||||||
|
|
||||||
bool IEventProvider.Bind (string eventId)
|
bool IEventProvider.Bind (string eventId)
|
||||||
{
|
{
|
||||||
var res = regexEventID.Match (eventId);
|
var res = regexEventID.Match (eventId);
|
||||||
if (res.Success) {
|
if (res.Success) {
|
||||||
int bt = int.Parse (res.Groups ["button"].Value);
|
int dmx = int.Parse (res.Groups ["dmx"].Value);
|
||||||
if(bt<0||bt>7) return false;
|
if(dmx<0||dmx>511) return false;
|
||||||
watchButtons[bt] = true;
|
lock(watchdmx){
|
||||||
|
if(!watchdmx.Contains(dmx))
|
||||||
|
{
|
||||||
|
watchdmx.Add(dmx);
|
||||||
|
lastVal[dmx] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -431,9 +452,10 @@ namespace DMX2
|
||||||
{
|
{
|
||||||
var res = regexEventID.Match (eventId);
|
var res = regexEventID.Match (eventId);
|
||||||
if (res.Success) {
|
if (res.Success) {
|
||||||
int bt = int.Parse (res.Groups ["button"].Value);
|
int dmx = int.Parse (res.Groups ["dmx"].Value);
|
||||||
if(bt<0||bt>7) return ;
|
if(dmx<1||dmx>512) return;
|
||||||
watchButtons[bt] = false;
|
lock(watchdmx) watchdmx.Remove (dmx);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -442,28 +464,47 @@ namespace DMX2
|
||||||
{
|
{
|
||||||
Gtk.Menu retmenu = new Gtk.Menu ();
|
Gtk.Menu retmenu = new Gtk.Menu ();
|
||||||
|
|
||||||
Gtk.MenuItem evmenuitem = new Gtk.MenuItem ("Boutons");
|
Gtk.MenuItem evmenuitem = new Gtk.MenuItem ("Entrée DMX");
|
||||||
retmenu.Add (evmenuitem);
|
retmenu.Add (evmenuitem);
|
||||||
Gtk.Menu evmenu = new Gtk.Menu ();
|
Gtk.Menu evmenu = new Gtk.Menu ();
|
||||||
evmenuitem.Submenu = evmenu;
|
evmenuitem.Submenu = evmenu;
|
||||||
|
|
||||||
for (int i= 0; i<8;i++ ) {
|
for (int c = 0; c<512; c+=100) {
|
||||||
Gtk.MenuItem item = new Gtk.MenuItem(string.Format("Bouton {0}",i+1));
|
Gtk.MenuItem citem = new Gtk.MenuItem(string.Format("De {0} à {1}", c==0?1:c, c==500?512:c+99 ));
|
||||||
item.Data[EventManager.EventIdKey] = string.Format("BV2-B{0}",i);
|
Gtk.Menu cmenu = new Gtk.Menu();
|
||||||
item.Data[EventManager.StateKey] = state;
|
citem.Submenu = cmenu;
|
||||||
item.ButtonPressEvent += handler;
|
evmenu.Add(citem);
|
||||||
evmenu.Add (item);
|
|
||||||
|
for(int d=0 ; d<100;d+=10){
|
||||||
|
if(c+d>512) break;
|
||||||
|
Gtk.MenuItem ditem = new Gtk.MenuItem(string.Format("De {0} à {1}", c+d==0?1:c+d, c+d==510?512:c+d+9 ));
|
||||||
|
Gtk.Menu dmenu = new Gtk.Menu();
|
||||||
|
ditem.Submenu = dmenu;
|
||||||
|
cmenu.Add(ditem);
|
||||||
|
|
||||||
|
for(int u=0; u<10;u++){
|
||||||
|
if(c+d+u==0) continue;
|
||||||
|
if(c+d+u>512) break;
|
||||||
|
Gtk.MenuItem uitem = new Gtk.MenuItem(string.Format("Entrée DMX {0}",c+d+u));
|
||||||
|
uitem.Data[EventManager.EventIdKey] = string.Format("BV2-D{0}",c+d+u);
|
||||||
|
uitem.Data[EventManager.StateKey] = state;
|
||||||
|
uitem.ButtonPressEvent += handler;
|
||||||
|
dmenu.Add (uitem);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retmenu;
|
return retmenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IEventProvider.ProcessEvents (EventManagerCallback callback)
|
void IEventProvider.ProcessEvents (EventManagerCallback callback)
|
||||||
{
|
{
|
||||||
buttonState bt;
|
dmxState dmxs;
|
||||||
EventData evd;
|
EventData evd;
|
||||||
while (eventsPending.TryDequeue(out bt)) {
|
while (eventsPending.TryDequeue(out dmxs)) {
|
||||||
evd.id= string.Format("BV2-B{0}",bt.button );
|
evd.id= string.Format("BV2-D{0}",dmxs.dmx );
|
||||||
evd.value = bt.pressed?(byte)0xFF:(byte)0x00;
|
evd.value = dmxs.value;
|
||||||
callback(evd);
|
callback(evd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -474,7 +515,7 @@ namespace DMX2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
*/
|
|
||||||
#region implemented abstract members of DMX2.DriverDMX
|
#region implemented abstract members of DMX2.DriverDMX
|
||||||
public override void Save (System.Xml.XmlElement parent)
|
public override void Save (System.Xml.XmlElement parent)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue