Ajout de parametrages au boitier v3 :

Raffraichissement, nb de circuits
et synchro PC / DMX
This commit is contained in:
tzim 2014-05-09 15:57:29 +00:00
parent eab625a3bf
commit a21161ed8b
7 changed files with 645 additions and 353 deletions

View file

@ -42,7 +42,7 @@ namespace DMX2
Fin Fin
} }
const int timeout = 100; const int timeout = 50;
// tampons Entrée/Sortie // tampons Entrée/Sortie
public byte[] inputbuffer = new byte[516]; public byte[] inputbuffer = new byte[516];
@ -61,38 +61,88 @@ namespace DMX2
int brk = 150; int brk = 150;
int mab = 50; int mab = 50;
int nbc1 = 512; int nbc1 = 512;
byte flag_merge1 = 1; byte flags = 0;
byte dmxinterval= 40;
int usbrefresh = 40;
bool reinit=false ; bool reinit=false ;
public void ReInit () { public void ReInit () {
reinit=true; reinit=true;
} }
public int Break { public int Break {
set {
brk = value;
paramFlag = true;
}
get { get {
return brk; return brk;
} }
} }
public int Mab { public int Mab {
set {
mab = value;
paramFlag = true;
}
get { get {
return mab; return mab;
} }
} }
public byte Flag_merge1 { public bool Merge {
set {
flags = (byte)( (flags & 0xFE) | (value?1:0));
paramFlag = true;
}
get { get {
return flag_merge1; return (flags&1)>0;
} }
} }
public bool Sync {
get {
return (flags & 2)>0;
}
set {
flags = (byte)((flags & 0xFD) | (value?2:0));
paramFlag = true;
}
}
public int NbCircuits {
get {
return nbc1;
}
set {
nbc1 = value;
paramFlag= true;
}
}
public byte DmxInterval {
get {
return dmxinterval;
}
set {
dmxinterval = value;
paramFlag= true;
}
}
public int UsbRefresh {
get {
return usbrefresh;
}
set {
usbrefresh = value;
}
}
public DriverBoitierV3 (string serialport, string id): base(id) public DriverBoitierV3 (string serialport, string id): base(id)
{ {
patch1 = Conduite.Courante.Patches[0];
portname = serialport; portname = serialport;
outputbuffer[0]=27; outputbuffer[0]=27;
outputbuffer[1]=68; outputbuffer[1]=68;
@ -102,14 +152,6 @@ namespace DMX2
bool paramFlag = false; bool paramFlag = false;
public void SetBreak( int _brk, int _mab, byte _merge1)
{
brk = _brk;
mab = _mab;
flag_merge1 = _merge1;
paramFlag = true;
}
void Start () void Start ()
{ {
if (loopthread == null) { if (loopthread == null) {
@ -165,20 +207,15 @@ namespace DMX2
if (!serial.IsOpen) if (!serial.IsOpen)
return false; return false;
// Au cas ou le boitier attends une fin de commande : envoi 1030 octets a 0 (le boitier ignorera tout seul la suite)
byte[] tmpBuffer = new byte[2]; byte[] tmpBuffer = new byte[2];
serial.Write (tmpBuffer, 0, tmpBuffer.Length);
// On attends un peu // On attends un peu
Thread.Sleep (50); Thread.Sleep (5);
// Vide le buffer d'entree // Vide le buffer d'entree
if (serial.BytesToRead > 0) if (serial.BytesToRead > 0)
serial.ReadExisting (); serial.ReadExisting ();
if(serial.BytesToWrite > 0)
Console.WriteLine("Les infos partent pas ...");
// on envoie Esc 'A' // on envoie Esc 'A'
tmpBuffer [0] = 27; tmpBuffer [0] = 27;
tmpBuffer [1] = 65; tmpBuffer [1] = 65;
@ -209,7 +246,7 @@ namespace DMX2
compteErreur = 0; compteErreur = 0;
break; break;
case etatAutomate.Transmission: case etatAutomate.Transmission:
finAttente = DateTime.Now.AddMilliseconds (22); finAttente = DateTime.Now.AddMilliseconds (usbrefresh);
//Console.WriteLine(DateTime.Now-t); //Console.WriteLine(DateTime.Now-t);
//t = DateTime.Now; //t = DateTime.Now;
EnvoiTrame (); EnvoiTrame ();
@ -345,7 +382,7 @@ namespace DMX2
return; return;
} }
byte[] tmpBuffer = new byte[6]; byte[] tmpBuffer = new byte[7];
tmpBuffer [0] = 27; // Esc tmpBuffer [0] = 27; // Esc
tmpBuffer [1] = 66; // 'B' tmpBuffer [1] = 66; // 'B'
@ -356,7 +393,8 @@ namespace DMX2
tmpBuffer [3] = (byte)brk; tmpBuffer [3] = (byte)brk;
tmpBuffer [4] = (byte)mab; tmpBuffer [4] = (byte)mab;
tmpBuffer [5] = (byte) (flag_merge1 ); tmpBuffer [5] = (byte) (flags );
tmpBuffer [6] = (byte) (dmxinterval);
serial.Write (tmpBuffer, 0, tmpBuffer.Length); serial.Write (tmpBuffer, 0, tmpBuffer.Length);
@ -540,10 +578,13 @@ namespace DMX2
if(patch1!=null) el.SetAttribute ("univers1", patch1.Nom); if(patch1!=null) el.SetAttribute ("univers1", patch1.Nom);
el.SetAttribute("circuits", nbc1.ToString());
el.SetAttribute("mab",mab.ToString()); el.SetAttribute("mab",mab.ToString());
el.SetAttribute("brk",brk.ToString()); el.SetAttribute("brk",brk.ToString());
el.SetAttribute("merge1",(flag_merge1!=0).ToString()); el.SetAttribute("merge1",((flags&1)>0).ToString());
el.SetAttribute("sync",((flags&2)>0).ToString());
el.SetAttribute("dmxinterval",dmxinterval.ToString());
el.SetAttribute("usbrefresh",usbrefresh.ToString());
} }
@ -571,16 +612,14 @@ namespace DMX2
} }
} }
drv.NbCircuits = int.Parse(el.TryGetAttribute("circuits","512"));
drv.Mab = int.Parse(el.TryGetAttribute("mab","150"));
drv.Break = int.Parse(el.TryGetAttribute("brk","50"));
drv.Merge = bool.Parse(el.TryGetAttribute("merge1","True"));
drv.Sync = bool.Parse(el.TryGetAttribute("sync","True"));
drv.DmxInterval = byte.Parse(el.TryGetAttribute("dmxinterval","22"));
drv.UsbRefresh = int.Parse(el.TryGetAttribute("usbrefresh","22"));
int mab,brk;
byte merge1;
mab = int.Parse(el.TryGetAttribute("mab","150"));
brk = int.Parse(el.TryGetAttribute("brk","50"));
merge1 = (byte)( bool.Parse(el.TryGetAttribute("merge1","True"))?1:0 );
drv.SetBreak(brk,mab,merge1);
return drv; return drv;
} }

View file

@ -40,8 +40,11 @@ namespace DMX2
{ {
caseBrk.Text = drv.Break.ToString (); caseBrk.Text = drv.Break.ToString ();
caseMab.Text = drv.Mab.ToString (); caseMab.Text = drv.Mab.ToString ();
caseCircuits.Text = drv.NbCircuits.ToString();
chkMerge1.Active = drv.Flag_merge1 == 1; caseDMXInt.Text = drv.DmxInterval.ToString();
caseUSBRef.Text = drv.UsbRefresh.ToString();
chkMerge1.Active = drv.Merge;
chkSync.Active = drv.Sync;
cbUnivers1.Model = lsCbUnivers1; cbUnivers1.Model = lsCbUnivers1;
var cellCbUnivers1 = new CellRendererText (); var cellCbUnivers1 = new CellRendererText ();
@ -86,18 +89,33 @@ namespace DMX2
} }
int a, b; int a, b, c,d, f;
if (!int.TryParse (caseBrk.Text, out a)) if (!int.TryParse (caseBrk.Text, out a))
return; return;
if (!int.TryParse (caseMab.Text, out b)) if (!int.TryParse (caseMab.Text, out b))
return; return;
if (a < 92) { if (!int.TryParse (caseCircuits.Text, out c))
a = 92; return;
}
if (b < 12) { if (!int.TryParse (caseUSBRef.Text, out d))
b = 12; return;
}
drv.SetBreak(a,b,(byte)(chkMerge1.Active?1:0)); if (!int.TryParse (caseDMXInt.Text, out f))
return;
if (a < 92) a = 92;
if (b < 12) b = 12;
if (c < 8 || c > 512 ) c = 512;
if (d < 22 ) d = 22;
if (f < 22 || f > 255 ) f = 22;
drv.Break = a;
drv.Mab = b;
drv.NbCircuits = c;
drv.UsbRefresh = d;
drv.DmxInterval = (byte)f;
drv.Merge = chkMerge1.Active;
drv.Sync = chkSync.Active;
} }
@ -105,9 +123,6 @@ namespace DMX2
{ {
drv.ReInit(); drv.ReInit();
} }
} }
} }

View file

@ -35,7 +35,6 @@ namespace DMX2
w1.Fill = false; w1.Fill = false;
// Container child vbox2.Gtk.Box+BoxChild // Container child vbox2.Gtk.Box+BoxChild
this.table1 = new global::Gtk.Table (((uint)(3)), ((uint)(2)), false); this.table1 = new global::Gtk.Table (((uint)(3)), ((uint)(2)), false);
this.table1.Name = "table1";
this.table1.RowSpacing = ((uint)(6)); this.table1.RowSpacing = ((uint)(6));
this.table1.ColumnSpacing = ((uint)(6)); this.table1.ColumnSpacing = ((uint)(6));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild

View file

@ -45,7 +45,6 @@ namespace DMX2
w1.Fill = false; w1.Fill = false;
// Container child vbox2.Gtk.Box+BoxChild // Container child vbox2.Gtk.Box+BoxChild
this.table1 = new global::Gtk.Table (((uint)(4)), ((uint)(5)), false); this.table1 = new global::Gtk.Table (((uint)(4)), ((uint)(5)), false);
this.table1.Name = "table1";
this.table1.RowSpacing = ((uint)(6)); this.table1.RowSpacing = ((uint)(6));
this.table1.ColumnSpacing = ((uint)(6)); this.table1.ColumnSpacing = ((uint)(6));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild

View file

@ -8,15 +8,21 @@ namespace DMX2
private global::Gtk.Label label1; private global::Gtk.Label label1;
private global::Gtk.Table table1; private global::Gtk.Table table1;
private global::Gtk.Entry caseBrk; private global::Gtk.Entry caseBrk;
private global::Gtk.Entry caseCircuits;
private global::Gtk.Entry caseDMXInt;
private global::Gtk.Entry caseMab; private global::Gtk.Entry caseMab;
private global::Gtk.Entry caseUSBRef;
private global::Gtk.ComboBox cbUnivers1; private global::Gtk.ComboBox cbUnivers1;
private global::Gtk.CheckButton chkMerge1; private global::Gtk.CheckButton chkMerge1;
private global::Gtk.Label label2; private global::Gtk.CheckButton chkSync;
private global::Gtk.Label label10;
private global::Gtk.Label label11;
private global::Gtk.Label label3; private global::Gtk.Label label3;
private global::Gtk.Label label4; private global::Gtk.Label label4;
private global::Gtk.Label label5; private global::Gtk.Label label5;
private global::Gtk.Label label6;
private global::Gtk.Label label8; private global::Gtk.Label label8;
private global::Gtk.Label label9;
private global::Gtk.Label labelsync;
private global::Gtk.HBox hbox1; private global::Gtk.HBox hbox1;
private global::Gtk.Button btnValider; private global::Gtk.Button btnValider;
private global::Gtk.Button btnInit; private global::Gtk.Button btnInit;
@ -41,8 +47,7 @@ namespace DMX2
w1.Expand = false; w1.Expand = false;
w1.Fill = false; w1.Fill = false;
// Container child vbox2.Gtk.Box+BoxChild // Container child vbox2.Gtk.Box+BoxChild
this.table1 = new global::Gtk.Table (((uint)(3)), ((uint)(5)), false); this.table1 = new global::Gtk.Table (((uint)(5)), ((uint)(4)), false);
this.table1.Name = "table1";
this.table1.RowSpacing = ((uint)(6)); this.table1.RowSpacing = ((uint)(6));
this.table1.ColumnSpacing = ((uint)(6)); this.table1.ColumnSpacing = ((uint)(6));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
@ -55,35 +60,70 @@ namespace DMX2
global::Gtk.Table.TableChild w2 = ((global::Gtk.Table.TableChild)(this.table1 [this.caseBrk])); global::Gtk.Table.TableChild w2 = ((global::Gtk.Table.TableChild)(this.table1 [this.caseBrk]));
w2.TopAttach = ((uint)(1)); w2.TopAttach = ((uint)(1));
w2.BottomAttach = ((uint)(2)); w2.BottomAttach = ((uint)(2));
w2.LeftAttach = ((uint)(2)); w2.LeftAttach = ((uint)(1));
w2.RightAttach = ((uint)(3)); w2.RightAttach = ((uint)(2));
w2.XOptions = ((global::Gtk.AttachOptions)(4)); w2.XOptions = ((global::Gtk.AttachOptions)(4));
w2.YOptions = ((global::Gtk.AttachOptions)(4)); w2.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
this.caseCircuits = new global::Gtk.Entry ();
this.caseCircuits.CanFocus = true;
this.caseCircuits.Name = "caseCircuits";
this.caseCircuits.IsEditable = true;
this.caseCircuits.InvisibleChar = '•';
this.table1.Add (this.caseCircuits);
global::Gtk.Table.TableChild w3 = ((global::Gtk.Table.TableChild)(this.table1 [this.caseCircuits]));
w3.LeftAttach = ((uint)(3));
w3.RightAttach = ((uint)(4));
w3.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.caseDMXInt = new global::Gtk.Entry ();
this.caseDMXInt.CanFocus = true;
this.caseDMXInt.Name = "caseDMXInt";
this.caseDMXInt.IsEditable = true;
this.caseDMXInt.InvisibleChar = '•';
this.table1.Add (this.caseDMXInt);
global::Gtk.Table.TableChild w4 = ((global::Gtk.Table.TableChild)(this.table1 [this.caseDMXInt]));
w4.TopAttach = ((uint)(3));
w4.BottomAttach = ((uint)(4));
w4.LeftAttach = ((uint)(3));
w4.RightAttach = ((uint)(4));
w4.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.caseMab = new global::Gtk.Entry (); this.caseMab = new global::Gtk.Entry ();
this.caseMab.CanFocus = true; this.caseMab.CanFocus = true;
this.caseMab.Name = "caseMab"; this.caseMab.Name = "caseMab";
this.caseMab.IsEditable = true; this.caseMab.IsEditable = true;
this.caseMab.InvisibleChar = '•'; this.caseMab.InvisibleChar = '•';
this.table1.Add (this.caseMab); this.table1.Add (this.caseMab);
global::Gtk.Table.TableChild w3 = ((global::Gtk.Table.TableChild)(this.table1 [this.caseMab])); global::Gtk.Table.TableChild w5 = ((global::Gtk.Table.TableChild)(this.table1 [this.caseMab]));
w3.TopAttach = ((uint)(1)); w5.TopAttach = ((uint)(1));
w3.BottomAttach = ((uint)(2)); w5.BottomAttach = ((uint)(2));
w3.LeftAttach = ((uint)(3)); w5.LeftAttach = ((uint)(3));
w3.RightAttach = ((uint)(4)); w5.RightAttach = ((uint)(4));
w3.XOptions = ((global::Gtk.AttachOptions)(4)); w5.YOptions = ((global::Gtk.AttachOptions)(4));
w3.YOptions = ((global::Gtk.AttachOptions)(4)); // Container child table1.Gtk.Table+TableChild
this.caseUSBRef = new global::Gtk.Entry ();
this.caseUSBRef.CanFocus = true;
this.caseUSBRef.Name = "caseUSBRef";
this.caseUSBRef.IsEditable = true;
this.caseUSBRef.InvisibleChar = '•';
this.table1.Add (this.caseUSBRef);
global::Gtk.Table.TableChild w6 = ((global::Gtk.Table.TableChild)(this.table1 [this.caseUSBRef]));
w6.TopAttach = ((uint)(3));
w6.BottomAttach = ((uint)(4));
w6.LeftAttach = ((uint)(1));
w6.RightAttach = ((uint)(2));
w6.XOptions = ((global::Gtk.AttachOptions)(4));
w6.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
this.cbUnivers1 = global::Gtk.ComboBox.NewText (); this.cbUnivers1 = global::Gtk.ComboBox.NewText ();
this.cbUnivers1.Name = "cbUnivers1"; this.cbUnivers1.Name = "cbUnivers1";
this.table1.Add (this.cbUnivers1); this.table1.Add (this.cbUnivers1);
global::Gtk.Table.TableChild w4 = ((global::Gtk.Table.TableChild)(this.table1 [this.cbUnivers1])); global::Gtk.Table.TableChild w7 = ((global::Gtk.Table.TableChild)(this.table1 [this.cbUnivers1]));
w4.TopAttach = ((uint)(1)); w7.LeftAttach = ((uint)(1));
w4.BottomAttach = ((uint)(2)); w7.RightAttach = ((uint)(2));
w4.LeftAttach = ((uint)(1)); w7.XOptions = ((global::Gtk.AttachOptions)(4));
w4.RightAttach = ((uint)(2)); w7.YOptions = ((global::Gtk.AttachOptions)(4));
w4.XOptions = ((global::Gtk.AttachOptions)(4));
w4.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
this.chkMerge1 = new global::Gtk.CheckButton (); this.chkMerge1 = new global::Gtk.CheckButton ();
this.chkMerge1.CanFocus = true; this.chkMerge1.CanFocus = true;
@ -92,74 +132,116 @@ namespace DMX2
this.chkMerge1.DrawIndicator = true; this.chkMerge1.DrawIndicator = true;
this.chkMerge1.UseUnderline = true; this.chkMerge1.UseUnderline = true;
this.table1.Add (this.chkMerge1); this.table1.Add (this.chkMerge1);
global::Gtk.Table.TableChild w5 = ((global::Gtk.Table.TableChild)(this.table1 [this.chkMerge1])); global::Gtk.Table.TableChild w8 = ((global::Gtk.Table.TableChild)(this.table1 [this.chkMerge1]));
w5.TopAttach = ((uint)(1)); w8.TopAttach = ((uint)(2));
w5.BottomAttach = ((uint)(2)); w8.BottomAttach = ((uint)(3));
w5.LeftAttach = ((uint)(4)); w8.LeftAttach = ((uint)(3));
w5.RightAttach = ((uint)(5)); w8.RightAttach = ((uint)(4));
w5.XOptions = ((global::Gtk.AttachOptions)(4)); w8.YOptions = ((global::Gtk.AttachOptions)(4));
w5.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
this.label2 = new global::Gtk.Label (); this.chkSync = new global::Gtk.CheckButton ();
this.label2.Name = "label2"; this.chkSync.CanFocus = true;
this.label2.LabelProp = "Etat"; this.chkSync.Name = "chkSync";
this.table1.Add (this.label2); this.chkSync.Label = "";
global::Gtk.Table.TableChild w6 = ((global::Gtk.Table.TableChild)(this.table1 [this.label2])); this.chkSync.DrawIndicator = true;
w6.XOptions = ((global::Gtk.AttachOptions)(4)); this.chkSync.UseUnderline = true;
w6.YOptions = ((global::Gtk.AttachOptions)(4)); this.table1.Add (this.chkSync);
global::Gtk.Table.TableChild w9 = ((global::Gtk.Table.TableChild)(this.table1 [this.chkSync]));
w9.TopAttach = ((uint)(2));
w9.BottomAttach = ((uint)(3));
w9.LeftAttach = ((uint)(1));
w9.RightAttach = ((uint)(2));
w9.XOptions = ((global::Gtk.AttachOptions)(4));
w9.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.label10 = new global::Gtk.Label ();
this.label10.Name = "label10";
this.label10.LabelProp = "Freq. USB (ms)";
this.table1.Add (this.label10);
global::Gtk.Table.TableChild w10 = ((global::Gtk.Table.TableChild)(this.table1 [this.label10]));
w10.TopAttach = ((uint)(3));
w10.BottomAttach = ((uint)(4));
w10.XOptions = ((global::Gtk.AttachOptions)(4));
w10.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.label11 = new global::Gtk.Label ();
this.label11.Name = "label11";
this.label11.LabelProp = "Intervale entre\ntrames DMX (ms)";
this.table1.Add (this.label11);
global::Gtk.Table.TableChild w11 = ((global::Gtk.Table.TableChild)(this.table1 [this.label11]));
w11.TopAttach = ((uint)(3));
w11.BottomAttach = ((uint)(4));
w11.LeftAttach = ((uint)(2));
w11.RightAttach = ((uint)(3));
w11.XOptions = ((global::Gtk.AttachOptions)(4));
w11.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
this.label3 = new global::Gtk.Label (); this.label3 = new global::Gtk.Label ();
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.LabelProp = "Univer associé"; this.label3.LabelProp = "Univer associé";
this.table1.Add (this.label3); this.table1.Add (this.label3);
global::Gtk.Table.TableChild w7 = ((global::Gtk.Table.TableChild)(this.table1 [this.label3])); global::Gtk.Table.TableChild w12 = ((global::Gtk.Table.TableChild)(this.table1 [this.label3]));
w7.LeftAttach = ((uint)(1)); w12.XOptions = ((global::Gtk.AttachOptions)(4));
w7.RightAttach = ((uint)(2)); w12.YOptions = ((global::Gtk.AttachOptions)(4));
w7.XOptions = ((global::Gtk.AttachOptions)(4));
w7.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
this.label4 = new global::Gtk.Label (); this.label4 = new global::Gtk.Label ();
this.label4.Name = "label4"; this.label4.Name = "label4";
this.label4.LabelProp = "Break"; this.label4.LabelProp = "Break (µs)";
this.table1.Add (this.label4); this.table1.Add (this.label4);
global::Gtk.Table.TableChild w8 = ((global::Gtk.Table.TableChild)(this.table1 [this.label4])); global::Gtk.Table.TableChild w13 = ((global::Gtk.Table.TableChild)(this.table1 [this.label4]));
w8.LeftAttach = ((uint)(2)); w13.TopAttach = ((uint)(1));
w8.RightAttach = ((uint)(3)); w13.BottomAttach = ((uint)(2));
w8.XOptions = ((global::Gtk.AttachOptions)(4)); w13.XOptions = ((global::Gtk.AttachOptions)(4));
w8.YOptions = ((global::Gtk.AttachOptions)(4)); w13.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
this.label5 = new global::Gtk.Label (); this.label5 = new global::Gtk.Label ();
this.label5.Name = "label5"; this.label5.Name = "label5";
this.label5.LabelProp = "MAB"; this.label5.LabelProp = "MAB (µs)";
this.table1.Add (this.label5); this.table1.Add (this.label5);
global::Gtk.Table.TableChild w9 = ((global::Gtk.Table.TableChild)(this.table1 [this.label5])); global::Gtk.Table.TableChild w14 = ((global::Gtk.Table.TableChild)(this.table1 [this.label5]));
w9.LeftAttach = ((uint)(3)); w14.TopAttach = ((uint)(1));
w9.RightAttach = ((uint)(4)); w14.BottomAttach = ((uint)(2));
w9.XOptions = ((global::Gtk.AttachOptions)(4)); w14.LeftAttach = ((uint)(2));
w9.YOptions = ((global::Gtk.AttachOptions)(4)); w14.RightAttach = ((uint)(3));
// Container child table1.Gtk.Table+TableChild w14.XOptions = ((global::Gtk.AttachOptions)(4));
this.label6 = new global::Gtk.Label (); w14.YOptions = ((global::Gtk.AttachOptions)(4));
this.label6.Name = "label6";
this.label6.LabelProp = "Block 1";
this.table1.Add (this.label6);
global::Gtk.Table.TableChild w10 = ((global::Gtk.Table.TableChild)(this.table1 [this.label6]));
w10.TopAttach = ((uint)(1));
w10.BottomAttach = ((uint)(2));
w10.XOptions = ((global::Gtk.AttachOptions)(4));
w10.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild // Container child table1.Gtk.Table+TableChild
this.label8 = new global::Gtk.Label (); this.label8 = new global::Gtk.Label ();
this.label8.Name = "label8"; this.label8.Name = "label8";
this.label8.LabelProp = "Merge"; this.label8.LabelProp = "Merge";
this.table1.Add (this.label8); this.table1.Add (this.label8);
global::Gtk.Table.TableChild w11 = ((global::Gtk.Table.TableChild)(this.table1 [this.label8])); global::Gtk.Table.TableChild w15 = ((global::Gtk.Table.TableChild)(this.table1 [this.label8]));
w11.LeftAttach = ((uint)(4)); w15.TopAttach = ((uint)(2));
w11.RightAttach = ((uint)(5)); w15.BottomAttach = ((uint)(3));
w11.XOptions = ((global::Gtk.AttachOptions)(4)); w15.LeftAttach = ((uint)(2));
w11.YOptions = ((global::Gtk.AttachOptions)(4)); w15.RightAttach = ((uint)(3));
w15.XOptions = ((global::Gtk.AttachOptions)(4));
w15.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.label9 = new global::Gtk.Label ();
this.label9.Name = "label9";
this.label9.LabelProp = "Circuits";
this.table1.Add (this.label9);
global::Gtk.Table.TableChild w16 = ((global::Gtk.Table.TableChild)(this.table1 [this.label9]));
w16.LeftAttach = ((uint)(2));
w16.RightAttach = ((uint)(3));
w16.XOptions = ((global::Gtk.AttachOptions)(4));
w16.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.labelsync = new global::Gtk.Label ();
this.labelsync.Name = "labelsync";
this.labelsync.LabelProp = "Syncro\nDMX<->USB";
this.table1.Add (this.labelsync);
global::Gtk.Table.TableChild w17 = ((global::Gtk.Table.TableChild)(this.table1 [this.labelsync]));
w17.TopAttach = ((uint)(2));
w17.BottomAttach = ((uint)(3));
w17.XOptions = ((global::Gtk.AttachOptions)(4));
w17.YOptions = ((global::Gtk.AttachOptions)(4));
this.vbox2.Add (this.table1); this.vbox2.Add (this.table1);
global::Gtk.Box.BoxChild w12 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.table1])); global::Gtk.Box.BoxChild w18 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.table1]));
w12.Position = 1; w18.Position = 1;
w18.Expand = false;
w18.Fill = false;
// Container child vbox2.Gtk.Box+BoxChild // Container child vbox2.Gtk.Box+BoxChild
this.hbox1 = new global::Gtk.HBox (); this.hbox1 = new global::Gtk.HBox ();
this.hbox1.Name = "hbox1"; this.hbox1.Name = "hbox1";
@ -171,10 +253,10 @@ namespace DMX2
this.btnValider.UseUnderline = true; this.btnValider.UseUnderline = true;
this.btnValider.Label = "Valider"; this.btnValider.Label = "Valider";
this.hbox1.Add (this.btnValider); this.hbox1.Add (this.btnValider);
global::Gtk.Box.BoxChild w13 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.btnValider])); global::Gtk.Box.BoxChild w19 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.btnValider]));
w13.Position = 1; w19.Position = 1;
w13.Expand = false; w19.Expand = false;
w13.Fill = false; w19.Fill = false;
// Container child hbox1.Gtk.Box+BoxChild // Container child hbox1.Gtk.Box+BoxChild
this.btnInit = new global::Gtk.Button (); this.btnInit = new global::Gtk.Button ();
this.btnInit.CanFocus = true; this.btnInit.CanFocus = true;
@ -182,16 +264,16 @@ namespace DMX2
this.btnInit.UseUnderline = true; this.btnInit.UseUnderline = true;
this.btnInit.Label = "Init Boitier"; this.btnInit.Label = "Init Boitier";
this.hbox1.Add (this.btnInit); this.hbox1.Add (this.btnInit);
global::Gtk.Box.BoxChild w14 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.btnInit])); global::Gtk.Box.BoxChild w20 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.btnInit]));
w14.Position = 2; w20.Position = 2;
w14.Expand = false; w20.Expand = false;
w14.Fill = false; w20.Fill = false;
this.vbox2.Add (this.hbox1); this.vbox2.Add (this.hbox1);
global::Gtk.Box.BoxChild w15 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.hbox1])); global::Gtk.Box.BoxChild w21 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.hbox1]));
w15.PackType = ((global::Gtk.PackType)(1)); w21.PackType = ((global::Gtk.PackType)(1));
w15.Position = 2; w21.Position = 2;
w15.Expand = false; w21.Expand = false;
w15.Fill = false; w21.Fill = false;
this.Add (this.vbox2); this.Add (this.vbox2);
if ((this.Child != null)) { if ((this.Child != null)) {
this.Child.ShowAll (); this.Child.ShowAll ();

View file

@ -2632,7 +2632,7 @@ Licence : GPL V2</property>
</widget> </widget>
</child> </child>
</widget> </widget>
<widget class="Gtk.Bin" id="DMX2.DriverBoitierV3UI" design-size="529 300"> <widget class="Gtk.Bin" id="DMX2.DriverBoitierV3UI" design-size="546 300">
<property name="MemberName" /> <property name="MemberName" />
<property name="Visible">False</property> <property name="Visible">False</property>
<child> <child>
@ -2654,8 +2654,8 @@ Licence : GPL V2</property>
<child> <child>
<widget class="Gtk.Table" id="table1"> <widget class="Gtk.Table" id="table1">
<property name="MemberName" /> <property name="MemberName" />
<property name="NRows">3</property> <property name="NRows">5</property>
<property name="NColumns">5</property> <property name="NColumns">4</property>
<property name="RowSpacing">6</property> <property name="RowSpacing">6</property>
<property name="ColumnSpacing">6</property> <property name="ColumnSpacing">6</property>
<child> <child>
@ -2670,9 +2670,6 @@ Licence : GPL V2</property>
<child> <child>
<placeholder /> <placeholder />
</child> </child>
<child>
<placeholder />
</child>
<child> <child>
<widget class="Gtk.Entry" id="caseBrk"> <widget class="Gtk.Entry" id="caseBrk">
<property name="MemberName" /> <property name="MemberName" />
@ -2683,8 +2680,8 @@ Licence : GPL V2</property>
<packing> <packing>
<property name="TopAttach">1</property> <property name="TopAttach">1</property>
<property name="BottomAttach">2</property> <property name="BottomAttach">2</property>
<property name="LeftAttach">2</property> <property name="LeftAttach">1</property>
<property name="RightAttach">3</property> <property name="RightAttach">2</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
<property name="XOptions">Fill</property> <property name="XOptions">Fill</property>
<property name="YOptions">Fill</property> <property name="YOptions">Fill</property>
@ -2696,6 +2693,48 @@ Licence : GPL V2</property>
<property name="YShrink">False</property> <property name="YShrink">False</property>
</packing> </packing>
</child> </child>
<child>
<widget class="Gtk.Entry" id="caseCircuits">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
</widget>
<packing>
<property name="LeftAttach">3</property>
<property name="RightAttach">4</property>
<property name="AutoSize">True</property>
<property name="YOptions">Fill</property>
<property name="XExpand">True</property>
<property name="XFill">True</property>
<property name="XShrink">False</property>
<property name="YExpand">False</property>
<property name="YFill">True</property>
<property name="YShrink">False</property>
</packing>
</child>
<child>
<widget class="Gtk.Entry" id="caseDMXInt">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
</widget>
<packing>
<property name="TopAttach">3</property>
<property name="BottomAttach">4</property>
<property name="LeftAttach">3</property>
<property name="RightAttach">4</property>
<property name="AutoSize">True</property>
<property name="YOptions">Fill</property>
<property name="XExpand">True</property>
<property name="XFill">True</property>
<property name="XShrink">False</property>
<property name="YExpand">False</property>
<property name="YFill">True</property>
<property name="YShrink">False</property>
</packing>
</child>
<child> <child>
<widget class="Gtk.Entry" id="caseMab"> <widget class="Gtk.Entry" id="caseMab">
<property name="MemberName" /> <property name="MemberName" />
@ -2709,6 +2748,28 @@ Licence : GPL V2</property>
<property name="LeftAttach">3</property> <property name="LeftAttach">3</property>
<property name="RightAttach">4</property> <property name="RightAttach">4</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
<property name="YOptions">Fill</property>
<property name="XExpand">True</property>
<property name="XFill">True</property>
<property name="XShrink">False</property>
<property name="YExpand">False</property>
<property name="YFill">True</property>
<property name="YShrink">False</property>
</packing>
</child>
<child>
<widget class="Gtk.Entry" id="caseUSBRef">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
</widget>
<packing>
<property name="TopAttach">3</property>
<property name="BottomAttach">4</property>
<property name="LeftAttach">1</property>
<property name="RightAttach">2</property>
<property name="AutoSize">True</property>
<property name="XOptions">Fill</property> <property name="XOptions">Fill</property>
<property name="YOptions">Fill</property> <property name="YOptions">Fill</property>
<property name="XExpand">False</property> <property name="XExpand">False</property>
@ -2726,8 +2787,6 @@ Licence : GPL V2</property>
<property name="Items" translatable="yes" /> <property name="Items" translatable="yes" />
</widget> </widget>
<packing> <packing>
<property name="TopAttach">1</property>
<property name="BottomAttach">2</property>
<property name="LeftAttach">1</property> <property name="LeftAttach">1</property>
<property name="RightAttach">2</property> <property name="RightAttach">2</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
@ -2751,10 +2810,34 @@ Licence : GPL V2</property>
<property name="UseUnderline">True</property> <property name="UseUnderline">True</property>
</widget> </widget>
<packing> <packing>
<property name="TopAttach">1</property> <property name="TopAttach">2</property>
<property name="BottomAttach">2</property> <property name="BottomAttach">3</property>
<property name="LeftAttach">4</property> <property name="LeftAttach">3</property>
<property name="RightAttach">5</property> <property name="RightAttach">4</property>
<property name="AutoSize">True</property>
<property name="YOptions">Fill</property>
<property name="XExpand">True</property>
<property name="XFill">True</property>
<property name="XShrink">False</property>
<property name="YExpand">False</property>
<property name="YFill">True</property>
<property name="YShrink">False</property>
</packing>
</child>
<child>
<widget class="Gtk.CheckButton" id="chkSync">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="Label" translatable="yes" />
<property name="DrawIndicator">True</property>
<property name="HasLabel">True</property>
<property name="UseUnderline">True</property>
</widget>
<packing>
<property name="TopAttach">2</property>
<property name="BottomAttach">3</property>
<property name="LeftAttach">1</property>
<property name="RightAttach">2</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
<property name="XOptions">Fill</property> <property name="XOptions">Fill</property>
<property name="YOptions">Fill</property> <property name="YOptions">Fill</property>
@ -2767,11 +2850,35 @@ Licence : GPL V2</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="Gtk.Label" id="label2"> <widget class="Gtk.Label" id="label10">
<property name="MemberName" /> <property name="MemberName" />
<property name="LabelProp" translatable="yes">Etat</property> <property name="LabelProp" translatable="yes">Freq. USB (ms)</property>
</widget> </widget>
<packing> <packing>
<property name="TopAttach">3</property>
<property name="BottomAttach">4</property>
<property name="AutoSize">True</property>
<property name="XOptions">Fill</property>
<property name="YOptions">Fill</property>
<property name="XExpand">False</property>
<property name="XFill">True</property>
<property name="XShrink">False</property>
<property name="YExpand">False</property>
<property name="YFill">True</property>
<property name="YShrink">False</property>
</packing>
</child>
<child>
<widget class="Gtk.Label" id="label11">
<property name="MemberName" />
<property name="LabelProp" translatable="yes">Intervale entre
trames DMX (ms)</property>
</widget>
<packing>
<property name="TopAttach">3</property>
<property name="BottomAttach">4</property>
<property name="LeftAttach">2</property>
<property name="RightAttach">3</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
<property name="XOptions">Fill</property> <property name="XOptions">Fill</property>
<property name="YOptions">Fill</property> <property name="YOptions">Fill</property>
@ -2789,8 +2896,6 @@ Licence : GPL V2</property>
<property name="LabelProp" translatable="yes">Univer associé</property> <property name="LabelProp" translatable="yes">Univer associé</property>
</widget> </widget>
<packing> <packing>
<property name="LeftAttach">1</property>
<property name="RightAttach">2</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
<property name="XOptions">Fill</property> <property name="XOptions">Fill</property>
<property name="YOptions">Fill</property> <property name="YOptions">Fill</property>
@ -2805,11 +2910,11 @@ Licence : GPL V2</property>
<child> <child>
<widget class="Gtk.Label" id="label4"> <widget class="Gtk.Label" id="label4">
<property name="MemberName" /> <property name="MemberName" />
<property name="LabelProp" translatable="yes">Break</property> <property name="LabelProp" translatable="yes">Break (µs)</property>
</widget> </widget>
<packing> <packing>
<property name="LeftAttach">2</property> <property name="TopAttach">1</property>
<property name="RightAttach">3</property> <property name="BottomAttach">2</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
<property name="XOptions">Fill</property> <property name="XOptions">Fill</property>
<property name="YOptions">Fill</property> <property name="YOptions">Fill</property>
@ -2824,30 +2929,13 @@ Licence : GPL V2</property>
<child> <child>
<widget class="Gtk.Label" id="label5"> <widget class="Gtk.Label" id="label5">
<property name="MemberName" /> <property name="MemberName" />
<property name="LabelProp" translatable="yes">MAB</property> <property name="LabelProp" translatable="yes">MAB (µs)</property>
</widget>
<packing>
<property name="LeftAttach">3</property>
<property name="RightAttach">4</property>
<property name="AutoSize">True</property>
<property name="XOptions">Fill</property>
<property name="YOptions">Fill</property>
<property name="XExpand">False</property>
<property name="XFill">True</property>
<property name="XShrink">False</property>
<property name="YExpand">False</property>
<property name="YFill">True</property>
<property name="YShrink">False</property>
</packing>
</child>
<child>
<widget class="Gtk.Label" id="label6">
<property name="MemberName" />
<property name="LabelProp" translatable="yes">Block 1</property>
</widget> </widget>
<packing> <packing>
<property name="TopAttach">1</property> <property name="TopAttach">1</property>
<property name="BottomAttach">2</property> <property name="BottomAttach">2</property>
<property name="LeftAttach">2</property>
<property name="RightAttach">3</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
<property name="XOptions">Fill</property> <property name="XOptions">Fill</property>
<property name="YOptions">Fill</property> <property name="YOptions">Fill</property>
@ -2865,8 +2953,49 @@ Licence : GPL V2</property>
<property name="LabelProp" translatable="yes">Merge</property> <property name="LabelProp" translatable="yes">Merge</property>
</widget> </widget>
<packing> <packing>
<property name="LeftAttach">4</property> <property name="TopAttach">2</property>
<property name="RightAttach">5</property> <property name="BottomAttach">3</property>
<property name="LeftAttach">2</property>
<property name="RightAttach">3</property>
<property name="AutoSize">True</property>
<property name="XOptions">Fill</property>
<property name="YOptions">Fill</property>
<property name="XExpand">False</property>
<property name="XFill">True</property>
<property name="XShrink">False</property>
<property name="YExpand">False</property>
<property name="YFill">True</property>
<property name="YShrink">False</property>
</packing>
</child>
<child>
<widget class="Gtk.Label" id="label9">
<property name="MemberName" />
<property name="LabelProp" translatable="yes">Circuits</property>
</widget>
<packing>
<property name="LeftAttach">2</property>
<property name="RightAttach">3</property>
<property name="AutoSize">True</property>
<property name="XOptions">Fill</property>
<property name="YOptions">Fill</property>
<property name="XExpand">False</property>
<property name="XFill">True</property>
<property name="XShrink">False</property>
<property name="YExpand">False</property>
<property name="YFill">True</property>
<property name="YShrink">False</property>
</packing>
</child>
<child>
<widget class="Gtk.Label" id="labelsync">
<property name="MemberName" />
<property name="LabelProp" translatable="yes">Syncro
DMX&lt;-&gt;USB</property>
</widget>
<packing>
<property name="TopAttach">2</property>
<property name="BottomAttach">3</property>
<property name="AutoSize">True</property> <property name="AutoSize">True</property>
<property name="XOptions">Fill</property> <property name="XOptions">Fill</property>
<property name="YOptions">Fill</property> <property name="YOptions">Fill</property>
@ -2881,7 +3010,9 @@ Licence : GPL V2</property>
</widget> </widget>
<packing> <packing>
<property name="Position">1</property> <property name="Position">1</property>
<property name="AutoSize">True</property> <property name="AutoSize">False</property>
<property name="Expand">False</property>
<property name="Fill">False</property>
</packing> </packing>
</child> </child>
<child> <child>

View file

@ -5,17 +5,11 @@
int main(void) int main(void)
{ {
init(); init();
#if defined(USBCON)
USBDevice.attach(); USBDevice.attach();
#endif
setup(); setup();
for (;;) { for (;;) {
loop(); loop();
} }
return 0; return 0;
} }
@ -28,45 +22,48 @@ int main(void)
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif #endif
#define TEMPDMXRX 8 // définitions
#define TEMPDMXRX 8 // Longueur de trame mini en reception
// déclaration des tableaux de données
byte tab_input_pc[514]; // venant du pc
byte tab_input_dmx[518]; // données venant de l'extérieur : les 512 premiers DMX; les 4 suivant 4x8 bp ;
byte tab_temp_dmx[TEMPDMXRX];
byte inbuffer[6];
// reception
volatile int index_input_pc=0; // entrée serial 0
volatile int index_output_pc=0; // sortie serial 0
volatile int index_input_dmx=513; // entrée dmx
volatile int index_output_dmx=0; //sortie dmx
#define IOUTDMX_FIN -4 #define IOUTDMX_FIN -4
#define IOUTDMX_IDLE -1 #define IOUTDMX_IDLE -1
#define IOUTDMX_BRK -2 #define IOUTDMX_BRK -2
#define IOUTDMX_MAB -3 #define IOUTDMX_MAB -3
#define IINUSB_IDLE 0
#define IINUSB_ESC 1
#define IINUSB_DATA 2
#define IINUSB_PARAM 10
volatile int etat_input_pc=0; // 0 raz ; 1 esc reçu ; 2 D reçu : pret à recevoir ; 3 prèt à emmetre #define TX1PIN 1 // pin DMX serial 1
#define LEDPIN 13 // led interne
int tx1pin = 1; // pin DMX serial 1
int ledPin = 13; // led interne
unsigned int blkl = 0, blkcpt=0, rxledcpt=0 ,txledcpt=0;
#define RX_TX_LED_TIME 3 #define RX_TX_LED_TIME 3
byte brk_timer_end=75; // def : 150us
byte mab_timer_end=25; //def : 50us
int nb_circuits=512;
int flag_merge1=1;
volatile bool emissionPc=0;
// Fonctions // tableaux de données
byte tab_input_pc[514]; // venant du pc
byte tab_input_dmx[518]; // données venant de l'extérieur : les 512 premiers DMX; les 4 suivant 4x8 bp ;
byte tab_temp_dmx[TEMPDMXRX];
byte inbuffer[7];
void ecritUSB(); // Variables d'état et compteurs
void CDC_accept(); volatile int index_input_pc=0; // entrée USB
volatile int index_output_pc=0; // sortie USB
volatile int index_input_dmx=513; // entrée dmx
volatile int index_output_dmx=0; // sortie dmx
volatile int etat_input_pc=IINUSB_IDLE; // etat entrée USB
volatile bool emissionPc=0; // flag : emission USB en attente
unsigned int blkl = 0, blkcpt=0, rxledcpt=0 ,txledcpt=0; // Gestion des leds
unsigned int blinkon, blinkp, interbrk=0; // idem
// Paramètres
byte brk_timer_end=75; // Duree Break (par 2µs) def : 150us
byte mab_timer_end=25; // Duree MAB (par 2µs) def : 50us
int nb_circuits=512; // Nombre de circuits DMX emis
int dmx_frame_interval=40; // Intervale entre trames DMX emises
bool flag_merge1=1;
bool flag_sync=0;
// ********************************** USB ***************************** //
// lancé par interruption USB sur reception d'un char <- Cette fonction nécessite une modif de la lib arduino // lancé par interruption USB sur reception d'un char <- Cette fonction nécessite une modif de la lib arduino
// l'interet est de ne pas utiliser le buffer de la classe Serial, trop petit (64o) // l'interet est de ne pas utiliser le buffer de la classe Serial, trop petit (64o)
void CDC_accept() void CDC_accept()
@ -77,25 +74,26 @@ void CDC_accept()
switch (etat_input_pc) { switch (etat_input_pc) {
case 0: case IINUSB_IDLE:
USB_Recv(CDC_RX,&c,1); USB_Recv(CDC_RX,&c,1);
// on attend un 'esc' pour commencer // on attend un 'esc' pour commencer
if (c==27) { etat_input_pc=1; break;} if (c==27) { etat_input_pc=IINUSB_ESC; break;}
break; break;
case 1: case IINUSB_ESC:
USB_Recv(CDC_RX,&c,1); USB_Recv(CDC_RX,&c,1);
// on attend 'D' pour recevoir // on attend 'D' pour recevoir
if (c==68) { if (c==68) {
etat_input_pc=2; etat_input_pc=IINUSB_DATA;
index_input_pc=1; index_input_pc=1;
tab_input_dmx[517]=68; tab_input_dmx[517]=68;
index_output_pc=1; // on init l'index d'emmission vers le pc ( le 0 n'est pas emit => start code) index_output_pc=1; // on init l'index d'emmission vers le pc ( le 0 n'est pas emit => start code)
emissionPc=1; // activation de l'intéruption registre emmission emissionPc=1; // activation de l'intéruption registre emmission
break;
} }
// Esc 'C' réinit // Esc 'C' réinit
if (c==67) { if (c==67) {
etat_input_pc=0; etat_input_pc=IINUSB_IDLE;
pe=tab_input_pc+514; pe=tab_input_pc+514;
for(pb=tab_input_pc;pb<pe;pb++) *pb=0; for(pb=tab_input_pc;pb<pe;pb++) *pb=0;
@ -110,37 +108,45 @@ void CDC_accept()
} }
// Esc 'B' parametrage // Esc 'B' parametrage
if (c==66) {etat_input_pc=10;index_input_pc=0; if (c==66) {
etat_input_pc=IINUSB_PARAM;
index_input_pc=0;
break;
} }
// Esc 'A' probe // Esc 'A' probe
if (c==65) {etat_input_pc=0; if (c==65) {
etat_input_pc=IINUSB_IDLE;
tab_input_dmx[517]=65; tab_input_dmx[517]=65;
index_output_pc=517; // on init l'index d'emmission vers le pc ( uniquement etat : 65 'A' ) index_output_pc=517; // on init l'index d'emmission vers le pc ( uniquement etat : 65 'A' )
emissionPc=1; emissionPc=1;
break;
} }
// si aucune commande n'est trouvée (toujours à 1) on repart à 0 // si aucune commande n'est trouvée (toujours à 1) on repart à 0
if (etat_input_pc==1) {etat_input_pc=0;} etat_input_pc=IINUSB_IDLE;
break; break;
case 2: // reception trame pc case IINUSB_DATA: // reception trame pc
// on rempli le tableau // on rempli le tableau
index_input_pc+=USB_Recv(CDC_RX,tab_input_pc+index_input_pc,513-index_input_pc); index_input_pc+=USB_Recv(CDC_RX,tab_input_pc+index_input_pc,513-index_input_pc);
// si on arrive à 512 // si on arrive à 512
if (index_input_pc > 512) { if (index_input_pc > 512) {
etat_input_pc=0; etat_input_pc=0;
if(flag_sync && (index_output_dmx==IOUTDMX_IDLE)) interbrk=1000;
} }
break; break;
case 10: case IINUSB_PARAM:
index_input_pc+=USB_Recv(CDC_RX,inbuffer+index_input_pc,4-index_input_pc); index_input_pc+=USB_Recv(CDC_RX,inbuffer+index_input_pc,5-index_input_pc);
if(index_input_pc<4) return; if(index_input_pc<5) return;
//nb_circuits= ((int)inbuffer[0])*2 + 2; nb_circuits= ((int)inbuffer[0])*2 + 2;
brk_timer_end = (inbuffer[1]/2); brk_timer_end = (inbuffer[1]/2);
mab_timer_end = (inbuffer[2]/2); mab_timer_end = (inbuffer[2]/2);
flag_merge1 = inbuffer[3] & 1; flag_merge1 = inbuffer[3] & 1;
flag_sync = inbuffer[3] & 2;
dmx_frame_interval = inbuffer[4];
etat_input_pc=0; etat_input_pc=0;
@ -159,173 +165,194 @@ void CDC_accept()
void ecritUSB() void ecritUSB()
{ {
TXLED1; txledcpt=RX_TX_LED_TIME; TXLED1; txledcpt=RX_TX_LED_TIME;
if(index_output_pc > 516){ if(index_output_pc > 516){ // Emission d'un seul caractere (code etat)
USB_Send(CDC_TX,tab_input_dmx+index_output_pc,1); USB_Send(CDC_TX,tab_input_dmx+index_output_pc,1);
emissionPc=0; emissionPc=0;
return; return;
} }
index_output_pc+= USB_Send(CDC_TX,tab_input_dmx+index_output_pc, 517-index_output_pc); // Emission du tableau complet
if (index_output_pc>516) { index_output_pc+= USB_Send(CDC_TX,tab_input_dmx+index_output_pc, 517-index_output_pc);
emissionPc=0; if (index_output_pc>516) {
} emissionPc=0;
}
} }
// ********************************** RECEPTION DMX ********************************* //
// vecteur d'intéruption pour reception dmx // vecteur d'intéruption pour reception dmx
// sur reception d'un caractere / erreur
ISR(USART1_RX_vect) ISR(USART1_RX_vect)
{ {
char c,r; char c,r;
r = UCSR1A; r = UCSR1A;
c = UDR1; c = UDR1;
if (r & (1<<FE1)) {index_input_dmx=0;return; }
if ( index_input_dmx==0 && c!=0 ) {index_input_dmx=513; }
if ( index_input_dmx<TEMPDMXRX) {
tab_temp_dmx[index_input_dmx]=c;
index_input_dmx++;
return;
}
if ( index_input_dmx==TEMPDMXRX) {
for(int i=0;i<TEMPDMXRX;i++)
tab_input_dmx[i]=tab_temp_dmx[i];
RXLED1; rxledcpt=RX_TX_LED_TIME;
}
if ( index_input_dmx<=512 )
{
tab_input_dmx[index_input_dmx]=c; if (r & (1<<FE1)) {index_input_dmx=0;return; } // Detection du BRK
index_input_dmx++;
} if ( index_input_dmx==0 && c!=0 ) {index_input_dmx=513; } // Start code => doit etre 0
if ( index_input_dmx<TEMPDMXRX) { // Les premiers codes sont stockés dans un tableau temporaire
tab_temp_dmx[index_input_dmx]=c;
index_input_dmx++;
return;
}
if ( index_input_dmx==TEMPDMXRX) { // La tramme a depassé le minimum => on copie ce qu'on a déja recu
for(int i=0;i<TEMPDMXRX;i++)
tab_input_dmx[i]=tab_temp_dmx[i];
RXLED1; rxledcpt=RX_TX_LED_TIME;
}
if ( index_input_dmx<=512 )
{
tab_input_dmx[index_input_dmx]=c;
index_input_dmx++;
}
} }
// ********************************** EMISSION DMX ********************************* //
// vecteur d'intéruption pour transmission DMX sur serial 1 // vecteur d'intéruption pour transmission DMX sur serial 1
// vecteur : USART 1 transmission buffer vide // vecteur : USART 1 transmission buffer vide
// => Permet d'attendre que tout soit parti avant de déclancher le break
ISR(USART1_TX_vect) ISR(USART1_TX_vect)
{ {
// si l'USART 1 est vide => break // si l'USART 1 est vide => break
if(index_output_dmx==IOUTDMX_FIN){ if(index_output_dmx==IOUTDMX_FIN)
index_output_dmx=IOUTDMX_IDLE; index_output_dmx=IOUTDMX_IDLE;
}
} }
// vecteur : USART 1 transmission registre vide // vecteur : USART 1 transmission registre vide
ISR(USART1_UDRE_vect) ISR(USART1_UDRE_vect)
{ {
if (index_output_dmx>=0) { //si index >=0 caratère suivant if (flag_merge1==1) {
if (flag_merge1==1) {UDR1 = max(tab_input_pc[index_output_dmx],tab_input_dmx[index_output_dmx]);} UDR1 = max(tab_input_pc[index_output_dmx],tab_input_dmx[index_output_dmx]);
else {UDR1 = tab_input_pc[index_output_dmx];} }
index_output_dmx++; else {
} UDR1 = tab_input_pc[index_output_dmx];
// si 512 transmits => mise en attente de fin de transmission }
// desactivation de l'intéruption sur le registre index_output_dmx++;
if (index_output_dmx>nb_circuits) {index_output_dmx=IOUTDMX_FIN;cbi(UCSR1B, UDRIE1);}
// si 512 transmits => mise en attente de fin de transmission
// desactivation de l'interruption sur le registre
if (index_output_dmx>nb_circuits) {
index_output_dmx=IOUTDMX_FIN;
cbi(UCSR1B, UDRIE1);
}
} }
// Timer 4 : gestion des temps de break et mab
ISR(TIMER4_COMPA_vect) { ISR(TIMER4_COMPA_vect) {
if (index_output_dmx==IOUTDMX_BRK ) { if (index_output_dmx==IOUTDMX_BRK ) { // en cours de break
digitalWrite(tx1pin, HIGH); // on met la broche à 1 index_output_dmx=IOUTDMX_MAB;
digitalWrite(TX1PIN, HIGH); // on met la broche à 1
// on relance le timer sur le temps du mab
OCR4A = mab_timer_end ;
TCNT4 = 0 ; // RAZ compteur timer
TIFR4 = 0 ; //Clear Flags timer
return;
}
if (index_output_dmx==IOUTDMX_MAB ) { // en cours de mab
//TXLED1; txledcpt=RX_TX_LED_TIME;
sbi(UCSR1B, TXEN1); // on reactive la transmission USART
index_output_dmx=0; // on se prépare à émmettre à partir du stat code ( 513 octets )
sbi(UCSR1B, UDRIE1); // on réactive l'intéruption du registre
index_output_dmx=IOUTDMX_MAB; // Arret du timer
OCR4A = mab_timer_end ; TIMSK4= 0 ; //desactivation intéruption
TCNT4 = 0 ;// RAZ compteur timer TCCR4B = 0; // arret du timer
TIFR4 = 0 ; //Clear Flags timer TIFR4 = 0 ; //Clear Flags timer
return; }
}
if (index_output_dmx==IOUTDMX_MAB ) {
sbi(UCSR1B, TXEN1); // on redémarre la transmission
index_output_dmx=0; // on se prépare à émmettre à partir du stat code ( 513 octets )
sbi(UCSR1B, UDRIE1); // on réactive l'intéruption du registre
TIMSK4= 0 ; //desactivation intéruption A &B
TCCR4B = 0;
}
} }
// ********************************** INIT ********************************* //
void setup() { void setup() {
// initialisation du stat code à 0 // Le startcode n'est jamais recu. On l'initialise ici
etat_input_pc=0; tab_input_pc[0]=0;
tab_input_pc[0]=0;
// init pin led interne en sortie // init pin led interne en sortie
pinMode(ledPin, OUTPUT); pinMode(LEDPIN, OUTPUT);
// initialisation à 250k de serial 1 // init USART
// baudrate // baudrate à 250k
UCSR1A = 1 << U2X1; UCSR1A = 1 << U2X1;
UBRR1H=0; UBRR1H=0;
UBRR1L = 7; UBRR1L = 7;
// 2 bit de stop; pas de parité; 8 bits de données // 2 bit de stop; pas de parité; 8 bits de données
UCSR1C = 14; UCSR1C = 14;
// activation reception et intéruptions serial 1
sbi(UCSR1B, RXEN1); //Reception
cbi(UCSR1B, TXEN1); //Pas de transmission avant 1er Break
sbi(UCSR1B, RXCIE1); //Interruption sur reception
sbi(UCSR1B, TXCIE1); //Interruption pour fin de transmission
// init timer 4 (break)
TIMSK4 = 0;
TCCR4C = 0;
TCCR4B = 0;
TCCR4A = 0; // 00000000
TCNT4 = 0; // compteur
TC4H=0;
// activation transmission et intéruption serial 1 sei();
sbi(UCSR1B, RXEN1); //Reception
sbi(UCSR1B, TXEN1); //Transmission
sbi(UCSR1B, RXCIE1); //Interruption sur reception
sbi(UCSR1B, TXCIE1); //Interruption pour fin de transmission
// init timer break
TIMSK4 = 0;
TCCR4C = 0;
TCCR4B = 0;
TCCR4A = 0; // 00000000
TCNT4 = 0; // compteur
TC4H=0;
sei();
// préparation du premier break
index_output_dmx=IOUTDMX_IDLE;
// préparation du premier break
index_output_dmx=IOUTDMX_IDLE;
} }
int blinkon = 350, blinkp=400; // ********************************** BOUCLE ********************************* //
void loop() { void loop() {
// lancement du break
// Lancement du Break : après fin de transmisson et ecoulement de "dmx_frame_interval" ms depuis le dernier break
if (index_output_dmx==IOUTDMX_IDLE && interbrk >= dmx_frame_interval ) {
index_output_dmx=IOUTDMX_BRK;
interbrk=0;
pinMode(TX1PIN, OUTPUT); // on met la broche en mode sortie
cbi(UCSR1B, TXEN1); //on stop la transmission
digitalWrite(TX1PIN, LOW); // on met la broche à 0
OCR4A = brk_timer_end ; // val 120 µs
TCNT4 = 0 ; // RAZ compteur timer
TIFR4 = 0 ; //Clear Flags timer
TIMSK4 = 64 ; //activation intéruption A &B
TCCR4B = 6; // 00000110 division par 32 de l'horloge base => 2µs
}
if (index_output_dmx==IOUTDMX_IDLE ) { // octets d'état. Pour le moment, tous à 0
index_output_dmx=IOUTDMX_BRK; tab_input_dmx[513]= 0;
pinMode(tx1pin, OUTPUT); // on met la broche en mode sortie tab_input_dmx[514]= 0;
cbi(UCSR1B, TXEN1); //on stop la transmission tab_input_dmx[515]= 0;
digitalWrite(tx1pin, LOW); // on met la broche à 0 tab_input_dmx[516]= 0;
OCR4A = brk_timer_end ; // val 120 µs
TCNT4 = 0 ;// RAZ compteur timer
TIFR4 = 0 ; //Clear Flags timer
TIMSK4 = 64 ; //activation intéruption A &B
TCCR4B = 6; // 00000110 division par 32 de l'horloge base => 2µs
}
// octets d'état. Pour le moment, tous à 0 if(_usbLineInfo.lineState) { // Si port serie USB ouvert
tab_input_dmx[513]= 0; blinkp=10, blinkon=6; // la led clignote plus vite
tab_input_dmx[514]= 0; if(emissionPc!=0)
tab_input_dmx[515]=0; ecritUSB();
tab_input_dmx[516]=0; } else {
blinkon = 350, blinkp=400;
// dans le doute, on force l'etat d'entree
etat_input_pc=IINUSB_IDLE;
}
if(_usbLineInfo.lineState) { // Si port serie USB ouvert int m = millis()>>3;
blinkp=10, blinkon=6; // led clignote plus vite if (m-blkl) { // Toutes les 8ms
if(emissionPc!=0) { interbrk+=8;
ecritUSB(); blkcpt++; blkl = m;
} if(rxledcpt) rxledcpt--;
} else { else RXLED0;
blinkon = 350, blinkp=400; if(txledcpt) txledcpt--;
etat_input_pc=0; else TXLED0;
} if(blkcpt>=blinkon) { digitalWrite(LEDPIN, HIGH); }
if(blkcpt>=blinkp){ digitalWrite(LEDPIN, LOW); blkcpt=0; }
int m = millis()>>3; }
if (m-blkl) {
blkcpt++; blkl = m;
if(rxledcpt) rxledcpt--;
else RXLED0;
if(txledcpt) txledcpt--;
else TXLED0;
if(blkcpt>=blinkon) { digitalWrite(ledPin, HIGH); }
if(blkcpt>=blinkp){ digitalWrite(ledPin, LOW); blkcpt=0; }
}
} }