* DriverDMX.cs:

* DriverBoitierV2.cs:
* DriverBoitierV1.cs: Sauvegarde

* Conduite.cs:
* EventManager.cs:
* gui.stetic:
* DMX2.DriverBoitierV2UI.cs:
* DMX2.DriverBoitierV1UI.cs: 

* DriverBoitierV2UI.cs:
* DriverBoitierV1UI.cs: Affichage etat driver

* GestionDriversUI.cs: Gestion plusieurs drivers chargés
This commit is contained in:
manu 2013-12-27 16:01:34 +00:00
parent 0e518b2cff
commit 91a007d896
11 changed files with 314 additions and 88 deletions

View file

@ -143,6 +143,20 @@ namespace DMX2
}
}
public void DriversAdd (DriverDMX drv)
{
drivers.Add(drv);
IEventProvider evp = drv as IEventProvider;
if(evp!=null) eventManager.RegisterProvider(evp);
}
public void DriversRemove (DriverDMX drv)
{
drivers.Remove(drv);
IEventProvider evp = drv as IEventProvider;
if(evp!=null) eventManager.UnregisterProvider(evp);
}
public DriverDMX GetDriverByID(string ID){
foreach (var driver in drivers)
if(ID== driver.ID)
@ -320,23 +334,28 @@ namespace DMX2
xmlRoot.AppendChild (xmlCircuits);
foreach (Circuit c in circuits) {
c.Save(xmlCircuits);
c.Save (xmlCircuits);
}
XmlElement xmlSequenceurs = xmlDoc.CreateElement("Sequenceurs");
xmlRoot.AppendChild(xmlSequenceurs);
XmlElement xmlSequenceurs = xmlDoc.CreateElement ("Sequenceurs");
xmlRoot.AppendChild (xmlSequenceurs);
foreach(Sequenceur seq in sequenceurs)
{
seq.Save(xmlSequenceurs);
foreach (Sequenceur seq in sequenceurs) {
seq.Save (xmlSequenceurs);
}
XmlElement xmlUniversList = xmlDoc.CreateElement("ListeUnivers");
xmlRoot.AppendChild(xmlUniversList);
XmlElement xmlUniversList = xmlDoc.CreateElement ("ListeUnivers");
xmlRoot.AppendChild (xmlUniversList);
foreach(UniversDMX univ in univers)
{
univ.Save(xmlUniversList);
foreach (UniversDMX univ in univers) {
univ.Save (xmlUniversList);
}
XmlElement xmlDriverList = xmlDoc.CreateElement ("ListeDrivers");
xmlRoot.AppendChild (xmlDriverList);
foreach (DriverDMX drv in drivers) {
drv.Save(xmlDriverList);
}
XmlElement xmlMaster = xmlDoc.CreateElement("Master");
@ -349,7 +368,7 @@ namespace DMX2
return xmlDoc;
}
public Conduite(XmlDocument doc) : this(false)
public Conduite (XmlDocument doc) : this(false)
{
//TODO : Gestion d'erreurs
@ -365,18 +384,26 @@ namespace DMX2
foreach (var xs in root["Sequenceurs"].ChildNodes) {
Sequenceur s = Sequenceur.Load (this, xs as XmlElement);
if (s != null){
if (s != null) {
sequenceurs.Add (s);
s.Renamed += SequenceurRenomme;
}
}
univers.Clear();
univers.Clear ();
foreach (var xu in root["ListeUnivers"].ChildNodes) {
UniversDMX u = UniversDMX.Load(this,xu as XmlElement);
if(u!=null)
univers.Add(u);
UniversDMX u = UniversDMX.Load (this, xu as XmlElement);
if (u != null)
univers.Add (u);
}
if(root["ListeDrivers"]!=null)
foreach (var xd in root["ListeDrivers"].ChildNodes) {
DriverDMX drv = DriverDMX.Load(this,xd as XmlElement);
if(drv != null)
DriversAdd(drv);
}
XmlElement xmlMaster;

View file

@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.IO.Ports;
using System.Xml;
namespace DMX2
{
@ -43,7 +44,6 @@ namespace DMX2
public DriverBoitierV1 (string serialport, string id): base(id)
{
portname = serialport;
patch = Conduite.Courante.Patches[0];
Start();
//serial = serialport;
outputbuffer[0]=27;
@ -62,9 +62,15 @@ namespace DMX2
void Connection ()
{
Console.WriteLine ("DriverV1.Connection()");
if (serial != null) {
serial.Close();
serial.Dispose();
serial = null;
}
if (!System.IO.File.Exists (portname)) {
Thread.Sleep (200);
return;
}
serial = new SerialPort(portname, 460800,Parity.None,8,StopBits.One);
serial.DtrEnable = false;
@ -174,7 +180,7 @@ namespace DMX2
byte b = 1; bool pressed;
for (byte i = 0; i<8; i++) {
if(!watchButtons[i]) continue;
pressed = (inputbuffer[0] & b) != 0;
pressed = !((inputbuffer[0] & b) != 0);
if(buttons[i]^pressed)
{
eventsPending.Enqueue(new buttonState(i,pressed));
@ -274,8 +280,46 @@ namespace DMX2
return "Boitier V1";
}
}
#endregion
#region implemented abstract members of DMX2.DriverDMX
public override void Save (System.Xml.XmlElement parent)
{
System.Xml.XmlElement el = parent.OwnerDocument.CreateElement ("DriverBoitierV1");
System.Xml.XmlElement xmlEl;
parent.AppendChild (el);
el.SetAttribute ("portname", portname.ToString ());
el.SetAttribute ("id", ID);
if(patch!=null) el.SetAttribute ("univers", patch.Nom);
}
#endregion
public static new DriverDMX Load(Conduite conduite, XmlElement el) {
//System.Xml.XmlElement xmlE;
string port = el.GetAttribute("portname");
if(! System.IO.File.Exists(port)) return null;
string id = el.GetAttribute("id");
DriverBoitierV1 drv = new DriverBoitierV1(port,id);
if(el.HasAttribute("univers"))
{
string univ = el.GetAttribute("univers");
foreach (UniversDMX u in conduite.Patches){
if(u.Nom== univ){
drv.patch = u;
break;
}
}
}
return drv;
}
}
}

View file

@ -20,17 +20,21 @@ namespace DMX2
void ConstruitCBUnivers ()
{
cbUnivers.Model = lsCbUnivers;
var cellCbUnivers = new CellRendererText();
cbUnivers.PackStart(cellCbUnivers,false);
cbUnivers.SetCellDataFunc(cellCbUnivers, new CellLayoutDataFunc(RenderUniversName));
foreach(UniversDMX u in Conduite.Courante.Patches)
lsCbUnivers.AppendValues(u);
var cellCbUnivers = new CellRendererText ();
cbUnivers.PackStart (cellCbUnivers, false);
cbUnivers.SetCellDataFunc (cellCbUnivers, new CellLayoutDataFunc (RenderUniversName));
int indx = 0;
int i=0;
foreach (UniversDMX u in Conduite.Courante.Patches) {
lsCbUnivers.AppendValues (u);
if (u==drv.patch) indx=i;
i++;
}
TreeIter iter;
lsCbUnivers.GetIterFirst(out iter);
cbUnivers.SetActiveIter(iter);
cbUnivers.Active=indx;
}
@ -49,8 +53,15 @@ namespace DMX2
drv.patch = lsCbUnivers.GetValue(iter,0) as UniversDMX;
}
}
protected void OnBtnValiderClicked (object sender, EventArgs e)
{
TreeIter iter;
if (cbUnivers.GetActiveIter (out iter)) {
drv.patch = lsCbUnivers.GetValue (iter, 0) as UniversDMX;
}
}
}
}
}

View file

@ -1,10 +1,11 @@
using System;
using System.Threading;
using System.IO.Ports;
using System.Xml;
namespace DMX2
{
public class DriverBoitierV2 : DriverDMX, IEventProvider
public class DriverBoitierV2 : DriverDMX//, IEventProvider
{
struct buttonState {
@ -125,7 +126,7 @@ namespace DMX2
//serial.WriteTimeout = 200;
try {
serial.Open ();
Attente(DateTime.Now.AddMilliseconds(1000));
Attente(DateTime.Now.AddMilliseconds(2000));
if(Synchronisation())
etat = etatAutomate.Transmission;
@ -384,20 +385,6 @@ namespace DMX2
etat = etatAutomate.Erreur;
}
void ProcessInput ()
{
byte b = 1; bool pressed;
for (byte i = 0; i<8; i++) {
if(!watchButtons[i]) continue;
pressed = (inputbuffer[0] & b) != 0;
if(buttons[i]^pressed)
{
eventsPending.Enqueue(new buttonState(i,pressed));
buttons[i] = pressed;
}
b <<= 1;
}
}
public override void Dispose ()
{
@ -419,7 +406,7 @@ namespace DMX2
}
#endregion
/*
#region IEventProvider implementation
@ -490,7 +477,73 @@ namespace DMX2
}
}
#endregion
*/
#region implemented abstract members of DMX2.DriverDMX
public override void Save (System.Xml.XmlElement parent)
{
System.Xml.XmlElement el = parent.OwnerDocument.CreateElement ("DriverBoitierV2");
System.Xml.XmlElement xmlEl;
parent.AppendChild (el);
el.SetAttribute ("portname", portname.ToString ());
el.SetAttribute ("id", ID);
if(patch1!=null) el.SetAttribute ("univers1", patch1.Nom);
if(patch2!=null) el.SetAttribute ("univers2", patch2.Nom);
el.SetAttribute("mab",mab.ToString());
el.SetAttribute("brk",brk.ToString());
el.SetAttribute("merge1",(flag_merge1!=0).ToString());
el.SetAttribute("merge2",(flag_merge2!=0).ToString());
}
#endregion
public static new DriverDMX Load(Conduite conduite, XmlElement el) {
//System.Xml.XmlElement xmlE;
string port = el.GetAttribute("portname");
if(! System.IO.File.Exists(port)) return null;
string id = el.GetAttribute("id");
DriverBoitierV2 drv = new DriverBoitierV2(port,id);
if(el.HasAttribute("univers1"))
{
string univ = el.GetAttribute("univers1");
foreach (UniversDMX u in conduite.Patches){
if(u.Nom== univ){
drv.patch1 = u;
break;
}
}
}
if(el.HasAttribute("univers2"))
{
string univ = el.GetAttribute("univers2");
foreach (UniversDMX u in conduite.Patches){
if(u.Nom== univ){
drv.patch2 = u;
break;
}
}
}
int mab,brk;
byte merge1,merge2;
mab = int.Parse(el.TryGetAttribute("mab","150"));
brk = int.Parse(el.TryGetAttribute("brk","50"));
merge1 = (byte)( bool.Parse(el.TryGetAttribute("merge1","True"))?1:0 );
merge2 = (byte)( bool.Parse(el.TryGetAttribute("merge2","True"))?1:0 );
drv.SetBreak(brk,mab,merge1,merge2);
return drv;
}
}
}

View file

@ -20,37 +20,47 @@ namespace DMX2
ListStore lsCbUnivers2 = new ListStore(typeof(UniversDMX));
void ConstruitCBUnivers ()
{
caseBrk.Text = drv.Break.ToString();
caseMab.Text = drv.Mab.ToString();
caseBrk.Text = drv.Break.ToString ();
caseMab.Text = drv.Mab.ToString ();
chkMerge1.Active = drv.Flag_merge1 == 1;
chkMerge2.Active = drv.Flag_merge2 == 1;
cbUnivers1.Model = lsCbUnivers1;
var cellCbUnivers1 = new CellRendererText();
cbUnivers1.PackStart(cellCbUnivers1,false);
cbUnivers1.SetCellDataFunc(cellCbUnivers1, new CellLayoutDataFunc(RenderUniversName1));
var cellCbUnivers1 = new CellRendererText ();
cbUnivers1.PackStart (cellCbUnivers1, false);
cbUnivers1.SetCellDataFunc (cellCbUnivers1, new CellLayoutDataFunc (RenderUniversName1));
foreach(UniversDMX u in Conduite.Courante.Patches)
lsCbUnivers1.AppendValues(u);
int indx = 0;
int i = 0;
foreach (UniversDMX u in Conduite.Courante.Patches) {
lsCbUnivers1.AppendValues (u);
if (u==drv.patch1) indx=i;
i++;
}
TreeIter iter;
lsCbUnivers1.GetIterFirst(out iter);
cbUnivers1.SetActiveIter(iter);
lsCbUnivers1.GetIterFirst (out iter);
cbUnivers1.SetActiveIter (iter);
cbUnivers1.Active=indx;
cbUnivers2.Model = lsCbUnivers2;
var cellCbUnivers2 = new CellRendererText();
cbUnivers2.PackStart(cellCbUnivers2,false);
cbUnivers2.SetCellDataFunc(cellCbUnivers2, new CellLayoutDataFunc(RenderUniversName2));
var cellCbUnivers2 = new CellRendererText ();
cbUnivers2.PackStart (cellCbUnivers2, false);
cbUnivers2.SetCellDataFunc (cellCbUnivers2, new CellLayoutDataFunc (RenderUniversName2));
foreach(UniversDMX u in Conduite.Courante.Patches)
lsCbUnivers2.AppendValues(u);
indx = 0;
i = 0;
foreach (UniversDMX u in Conduite.Courante.Patches) {
lsCbUnivers2.AppendValues (u);
if (u==drv.patch2) indx=i;
i++;
}
//TreeIter iter;
lsCbUnivers2.GetIterFirst(out iter);
cbUnivers2.SetActiveIter(iter);
cbUnivers2.Active=indx;
}
@ -68,7 +78,7 @@ namespace DMX2
(cell as Gtk.CellRendererText).Text = univers.Nom;
}
protected void OnButton120Clicked (object sender, EventArgs e)
protected void OnButtonValider (object sender, EventArgs e)
{
TreeIter iter;
if (cbUnivers1.GetActiveIter (out iter)) {

View file

@ -1,5 +1,6 @@
using System;
using System.Threading;
using System.Xml;
namespace DMX2
{
@ -26,6 +27,19 @@ namespace DMX2
protected bool disposed = false;
public static DriverDMX Load (Conduite conduite, XmlElement el)
{
switch (el.Name) {
case "DriverBoitierV1":
return DriverBoitierV1.Load(conduite, el);
case "DriverBoitierV2":
return DriverBoitierV2.Load(conduite,el);
}
return null;
}
public abstract void Save (XmlElement parent);
#region IDisposable implementation
public virtual void Dispose()

View file

@ -132,6 +132,8 @@ namespace DMX2
public void RegisterProvider (IEventProvider prov)
{
providers.Add (prov);
foreach( var bind in bindings)
prov.Bind(bind.Key);
}
#region Menus

View file

@ -106,16 +106,7 @@ namespace DMX2
return;
drv = Conduite.Courante.GetDriverByID (fi.Name);
if (drv == null) {
btnConnect.Visible = btnConnect.Sensitive = true;
btnDisconnect.Visible = btnDisconnect.Sensitive = false;
comboDriver.Sensitive = true;
comboDriver.Active=-1;
if(frmDrvChild.Child!=null)
frmDrvChild.Remove(frmDrvChild.Child);
return;
}
AfficheDriverUI();
@ -141,11 +132,14 @@ namespace DMX2
switch (comboDriver.Active) {
case 0:
drv = new DriverBoitierV1(fi.FullName, fi.Name);
Conduite.Courante.Drivers.Add(drv);
Conduite.Courante.DriversAdd(drv);
break;
case 1:
drv = new DriverBoitierV2(fi.FullName, fi.Name);
Conduite.Courante.Drivers.Add(drv);
Conduite.Courante.DriversAdd(drv);
break;
default:
return;
@ -159,12 +153,26 @@ namespace DMX2
{
if (drv != null) {
drv.Dispose ();
Conduite.Courante.Drivers.Remove (drv);
Conduite.Courante.DriversRemove (drv);
}
drv=null;
AfficheDriverUI();
}
void AfficheDriverUI(){
if(frmDrvChild.Child!=null)
frmDrvChild.Remove(frmDrvChild.Child);
if (drv == null) {
btnConnect.Visible = btnConnect.Sensitive = true;
btnDisconnect.Visible = btnDisconnect.Sensitive = false;
comboDriver.Sensitive = true;
comboDriver.Active=-1;
listeUsb.QueueDraw();
return;
}
btnConnect.Visible = false;
comboDriver.Sensitive = false;
@ -172,7 +180,7 @@ namespace DMX2
frmDrvChild.Child = drv.GetUI();
frmDrvChild.ShowAll();
listeUsb.QueueDraw();
}
void EffaceDriverUI(){

View file

@ -11,6 +11,8 @@ namespace DMX2
private global::Gtk.Label label4;
private global::Gtk.Label label5;
private global::Gtk.Label lblEtat;
private global::Gtk.HBox hbox1;
private global::Gtk.Button btnValider;
protected virtual void Build ()
{
@ -78,11 +80,32 @@ namespace DMX2
this.vbox2.Add (this.table1);
global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.table1]));
w6.Position = 1;
// Container child vbox2.Gtk.Box+BoxChild
this.hbox1 = new global::Gtk.HBox ();
this.hbox1.Name = "hbox1";
this.hbox1.Spacing = 6;
// Container child hbox1.Gtk.Box+BoxChild
this.btnValider = new global::Gtk.Button ();
this.btnValider.CanFocus = true;
this.btnValider.Name = "btnValider";
this.btnValider.UseUnderline = true;
this.btnValider.Label = "Valider";
this.hbox1.Add (this.btnValider);
global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.btnValider]));
w7.Position = 1;
w7.Expand = false;
w7.Fill = false;
this.vbox2.Add (this.hbox1);
global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.hbox1]));
w8.Position = 2;
w8.Expand = false;
w8.Fill = false;
this.Add (this.vbox2);
if ((this.Child != null)) {
this.Child.ShowAll ();
}
this.Hide ();
this.btnValider.Clicked += new global::System.EventHandler (this.OnBtnValiderClicked);
}
}
}

View file

@ -21,7 +21,7 @@ namespace DMX2
private global::Gtk.Label label7;
private global::Gtk.Label label8;
private global::Gtk.HBox hbox1;
private global::Gtk.Button button120;
private global::Gtk.Button btnValider;
private global::Gtk.Button btnInit;
protected virtual void Build ()
@ -204,13 +204,13 @@ namespace DMX2
this.hbox1.Name = "hbox1";
this.hbox1.Spacing = 6;
// Container child hbox1.Gtk.Box+BoxChild
this.button120 = new global::Gtk.Button ();
this.button120.CanFocus = true;
this.button120.Name = "button120";
this.button120.UseUnderline = true;
this.button120.Label = "Valider";
this.hbox1.Add (this.button120);
global::Gtk.Box.BoxChild w16 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.button120]));
this.btnValider = new global::Gtk.Button ();
this.btnValider.CanFocus = true;
this.btnValider.Name = "btnValider";
this.btnValider.UseUnderline = true;
this.btnValider.Label = "Valider";
this.hbox1.Add (this.btnValider);
global::Gtk.Box.BoxChild w16 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.btnValider]));
w16.Position = 1;
w16.Expand = false;
w16.Fill = false;
@ -236,7 +236,7 @@ namespace DMX2
this.Child.ShowAll ();
}
this.Hide ();
this.button120.Clicked += new global::System.EventHandler (this.OnButton120Clicked);
this.btnValider.Clicked += new global::System.EventHandler (this.OnButtonValider);
this.btnInit.Clicked += new global::System.EventHandler (this.OnBtnInitClicked);
}
}

View file

@ -2017,7 +2017,7 @@ au sequenceur</property>
</widget>
</child>
</widget>
<widget class="Gtk.Bin" id="DMX2.DriverBoitierV1UI" design-size="342 105">
<widget class="Gtk.Bin" id="DMX2.DriverBoitierV1UI" design-size="342 233">
<property name="MemberName" />
<property name="Visible">False</property>
<child>
@ -2132,6 +2132,40 @@ au sequenceur</property>
<property name="AutoSize">True</property>
</packing>
</child>
<child>
<widget class="Gtk.HBox" id="hbox1">
<property name="MemberName" />
<property name="Spacing">6</property>
<child>
<placeholder />
</child>
<child>
<widget class="Gtk.Button" id="btnValider">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="Type">TextOnly</property>
<property name="Label" translatable="yes">Valider</property>
<property name="UseUnderline">True</property>
<signal name="Clicked" handler="OnBtnValiderClicked" />
</widget>
<packing>
<property name="Position">1</property>
<property name="AutoSize">True</property>
<property name="Expand">False</property>
<property name="Fill">False</property>
</packing>
</child>
<child>
<placeholder />
</child>
</widget>
<packing>
<property name="Position">2</property>
<property name="AutoSize">True</property>
<property name="Expand">False</property>
<property name="Fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
@ -2467,13 +2501,13 @@ au sequenceur</property>
<placeholder />
</child>
<child>
<widget class="Gtk.Button" id="button120">
<widget class="Gtk.Button" id="btnValider">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="Type">TextOnly</property>
<property name="Label" translatable="yes">Valider</property>
<property name="UseUnderline">True</property>
<signal name="Clicked" handler="OnButton120Clicked" />
<signal name="Clicked" handler="OnButtonValider" />
</widget>
<packing>
<property name="Position">1</property>