This commit is contained in:
tzim 2014-05-11 22:05:34 +00:00
parent a21161ed8b
commit c6e8d45679
5 changed files with 149 additions and 96 deletions

View file

@ -42,7 +42,7 @@ namespace DMX2
Fin
}
const int timeout = 50;
const int timeout = 500;
// tampons Entrée/Sortie
public byte[] inputbuffer = new byte[516];
@ -64,7 +64,7 @@ namespace DMX2
byte flags = 0;
byte dmxinterval= 40;
int usbrefresh = 40;
bool sync=false;
bool reinit=false ;
@ -102,15 +102,16 @@ namespace DMX2
}
}
public bool Sync {
get {
return (flags & 2)>0;
return sync;
}
set {
flags = (byte)((flags & 0xFD) | (value?2:0));
paramFlag = true;
sync = value;
}
}
public int NbCircuits {
get {
return nbc1;
@ -231,6 +232,30 @@ namespace DMX2
return false;
}
void DmxSync ()
{
if (!serial.IsOpen) {
etat = etatAutomate.Erreur;
return;
}
byte[] tmpBuffer = new byte[2];
tmpBuffer [0] = 27; // Esc
tmpBuffer [1] = 69; // 'E'
serial.Write (tmpBuffer, 0, tmpBuffer.Length);
if(!WaitForData (1)) {
etat = etatAutomate.Erreur;
return ;
}
serial.Read(tmpBuffer,0,1);
if(tmpBuffer[0] != 69)
etat = etatAutomate.Erreur;
}
volatile etatAutomate etat = etatAutomate.Deconnecte;
DateTime finAttente = DateTime.Now;
int compteErreur = 0;
@ -249,6 +274,7 @@ namespace DMX2
finAttente = DateTime.Now.AddMilliseconds (usbrefresh);
//Console.WriteLine(DateTime.Now-t);
//t = DateTime.Now;
if(sync)DmxSync();
EnvoiTrame ();
Reception ();
Attente (finAttente);
@ -355,8 +381,8 @@ namespace DMX2
}
serial.Read(inputbuffer,0,inputbuffer.Length);
if (flag_input != inputbuffer[0]) {
flag_input = inputbuffer[0];
if (flag_input != inputbuffer[513]) {
flag_input = inputbuffer[513];
Console.WriteLine(flag_input );
}
if(serial.BytesToRead>0)
@ -582,7 +608,7 @@ namespace DMX2
el.SetAttribute("mab",mab.ToString());
el.SetAttribute("brk",brk.ToString());
el.SetAttribute("merge1",((flags&1)>0).ToString());
el.SetAttribute("sync",((flags&2)>0).ToString());
el.SetAttribute("sync",sync.ToString());
el.SetAttribute("dmxinterval",dmxinterval.ToString());
el.SetAttribute("usbrefresh",usbrefresh.ToString());

View file

@ -46,6 +46,8 @@ namespace DMX2
chkMerge1.Active = drv.Merge;
chkSync.Active = drv.Sync;
//caseDMXInt.IsEditable = drv.Sync;
cbUnivers1.Model = lsCbUnivers1;
var cellCbUnivers1 = new CellRendererText ();
cbUnivers1.PackStart (cellCbUnivers1, false);
@ -88,7 +90,6 @@ namespace DMX2
drv.patch1 = lsCbUnivers1.GetValue (iter, 0) as UniversDMX;
}
int a, b, c,d, f;
if (!int.TryParse (caseBrk.Text, out a))
return;
@ -106,8 +107,8 @@ namespace DMX2
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;
if (d < 5 ) d = 22;
if (f < 5 || f > 255 ) f = 22;
drv.Break = a;
drv.Mab = b;
@ -123,6 +124,18 @@ namespace DMX2
{
drv.ReInit();
}
protected void OnChkSyncToggled (object sender, EventArgs e)
{
//SyncCheck();
}
protected void OnCaseUSBRefChanged (object sender, EventArgs e)
{
//SyncCheck();
}
}
}

View file

@ -16,13 +16,13 @@ namespace DMX2
private global::Gtk.CheckButton chkMerge1;
private global::Gtk.CheckButton chkSync;
private global::Gtk.Label label10;
private global::Gtk.Label label11;
private global::Gtk.Label label3;
private global::Gtk.Label label4;
private global::Gtk.Label label5;
private global::Gtk.Label label8;
private global::Gtk.Label label9;
private global::Gtk.Label labelsync;
private global::Gtk.Label lblDMX;
private global::Gtk.HBox hbox1;
private global::Gtk.Button btnValider;
private global::Gtk.Button btnInit;
@ -164,77 +164,77 @@ namespace DMX2
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
this.label3 = new global::Gtk.Label ();
this.label3.Name = "label3";
this.label3.LabelProp = "Univer associé";
this.table1.Add (this.label3);
global::Gtk.Table.TableChild w12 = ((global::Gtk.Table.TableChild)(this.table1 [this.label3]));
w12.XOptions = ((global::Gtk.AttachOptions)(4));
w12.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w11 = ((global::Gtk.Table.TableChild)(this.table1 [this.label3]));
w11.XOptions = ((global::Gtk.AttachOptions)(4));
w11.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.label4 = new global::Gtk.Label ();
this.label4.Name = "label4";
this.label4.LabelProp = "Break (µs)";
this.table1.Add (this.label4);
global::Gtk.Table.TableChild w13 = ((global::Gtk.Table.TableChild)(this.table1 [this.label4]));
w13.TopAttach = ((uint)(1));
w13.BottomAttach = ((uint)(2));
w13.XOptions = ((global::Gtk.AttachOptions)(4));
w13.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w12 = ((global::Gtk.Table.TableChild)(this.table1 [this.label4]));
w12.TopAttach = ((uint)(1));
w12.BottomAttach = ((uint)(2));
w12.XOptions = ((global::Gtk.AttachOptions)(4));
w12.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.label5 = new global::Gtk.Label ();
this.label5.Name = "label5";
this.label5.LabelProp = "MAB (µs)";
this.table1.Add (this.label5);
global::Gtk.Table.TableChild w14 = ((global::Gtk.Table.TableChild)(this.table1 [this.label5]));
w14.TopAttach = ((uint)(1));
w14.BottomAttach = ((uint)(2));
w14.LeftAttach = ((uint)(2));
w14.RightAttach = ((uint)(3));
w14.XOptions = ((global::Gtk.AttachOptions)(4));
w14.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w13 = ((global::Gtk.Table.TableChild)(this.table1 [this.label5]));
w13.TopAttach = ((uint)(1));
w13.BottomAttach = ((uint)(2));
w13.LeftAttach = ((uint)(2));
w13.RightAttach = ((uint)(3));
w13.XOptions = ((global::Gtk.AttachOptions)(4));
w13.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.label8 = new global::Gtk.Label ();
this.label8.Name = "label8";
this.label8.LabelProp = "Merge";
this.table1.Add (this.label8);
global::Gtk.Table.TableChild w15 = ((global::Gtk.Table.TableChild)(this.table1 [this.label8]));
w15.TopAttach = ((uint)(2));
w15.BottomAttach = ((uint)(3));
w15.LeftAttach = ((uint)(2));
w15.RightAttach = ((uint)(3));
w15.XOptions = ((global::Gtk.AttachOptions)(4));
w15.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w14 = ((global::Gtk.Table.TableChild)(this.table1 [this.label8]));
w14.TopAttach = ((uint)(2));
w14.BottomAttach = ((uint)(3));
w14.LeftAttach = ((uint)(2));
w14.RightAttach = ((uint)(3));
w14.XOptions = ((global::Gtk.AttachOptions)(4));
w14.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));
global::Gtk.Table.TableChild w15 = ((global::Gtk.Table.TableChild)(this.table1 [this.label9]));
w15.LeftAttach = ((uint)(2));
w15.RightAttach = ((uint)(3));
w15.XOptions = ((global::Gtk.AttachOptions)(4));
w15.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));
global::Gtk.Table.TableChild w16 = ((global::Gtk.Table.TableChild)(this.table1 [this.labelsync]));
w16.TopAttach = ((uint)(2));
w16.BottomAttach = ((uint)(3));
w16.XOptions = ((global::Gtk.AttachOptions)(4));
w16.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.lblDMX = new global::Gtk.Label ();
this.lblDMX.Name = "lblDMX";
this.lblDMX.LabelProp = "Intervale entre\ntrames DMX (ms)";
this.table1.Add (this.lblDMX);
global::Gtk.Table.TableChild w17 = ((global::Gtk.Table.TableChild)(this.table1 [this.lblDMX]));
w17.TopAttach = ((uint)(3));
w17.BottomAttach = ((uint)(4));
w17.LeftAttach = ((uint)(2));
w17.RightAttach = ((uint)(3));
w17.XOptions = ((global::Gtk.AttachOptions)(4));
w17.YOptions = ((global::Gtk.AttachOptions)(4));
this.vbox2.Add (this.table1);
@ -279,6 +279,8 @@ namespace DMX2
this.Child.ShowAll ();
}
this.Hide ();
this.chkSync.Toggled += new global::System.EventHandler (this.OnChkSyncToggled);
this.caseUSBRef.Changed += new global::System.EventHandler (this.OnCaseUSBRefChanged);
this.btnValider.Clicked += new global::System.EventHandler (this.OnButtonValider);
this.btnInit.Clicked += new global::System.EventHandler (this.OnBtnInitClicked);
}

View file

@ -2763,6 +2763,7 @@ Licence : GPL V2</property>
<property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
<signal name="Changed" handler="OnCaseUSBRefChanged" />
</widget>
<packing>
<property name="TopAttach">3</property>
@ -2832,6 +2833,7 @@ Licence : GPL V2</property>
<property name="DrawIndicator">True</property>
<property name="HasLabel">True</property>
<property name="UseUnderline">True</property>
<signal name="Toggled" handler="OnChkSyncToggled" />
</widget>
<packing>
<property name="TopAttach">2</property>
@ -2868,28 +2870,6 @@ Licence : GPL V2</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="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="label3">
<property name="MemberName" />
@ -3007,6 +2987,28 @@ DMX&lt;-&gt;USB</property>
<property name="YShrink">False</property>
</packing>
</child>
<child>
<widget class="Gtk.Label" id="lblDMX">
<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="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>
</widget>
<packing>
<property name="Position">1</property>

View file

@ -35,7 +35,7 @@ int main(void)
#define TX1PIN 1 // pin DMX serial 1
#define LEDPIN 13 // led interne
#define RX_TX_LED_TIME 3
#define RX_TX_LED_TIME 12
// tableaux de données
@ -50,7 +50,7 @@ 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
volatile int 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
@ -60,8 +60,7 @@ 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;
bool syncflag=false;
// ********************************** USB ***************************** //
// lancé par interruption USB sur reception d'un char <- Cette fonction nécessite une modif de la lib arduino
@ -88,7 +87,7 @@ void CDC_accept()
index_input_pc=1;
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)
emissionPc=1; // activation de l'intéruption registre emmission
emissionPc=1;
break;
}
// Esc 'C' réinit
@ -122,6 +121,16 @@ void CDC_accept()
emissionPc=1;
break;
}
// Esc 'E' SYNC
if (c==69) {
etat_input_pc=IINUSB_IDLE;
tab_input_dmx[517]=69;
index_output_pc=517; // on init l'index d'emmission vers le pc ( uniquement etat : 65 'A' )
emissionPc=1;
syncflag=true;
break;
}
// si aucune commande n'est trouvée (toujours à 1) on repart à 0
etat_input_pc=IINUSB_IDLE;
@ -133,7 +142,6 @@ void CDC_accept()
// si on arrive à 512
if (index_input_pc > 512) {
etat_input_pc=0;
if(flag_sync && (index_output_dmx==IOUTDMX_IDLE)) interbrk=1000;
}
break;
@ -145,7 +153,6 @@ void CDC_accept()
brk_timer_end = (inbuffer[1]/2);
mab_timer_end = (inbuffer[2]/2);
flag_merge1 = inbuffer[3] & 1;
flag_sync = inbuffer[3] & 2;
dmx_frame_interval = inbuffer[4];
etat_input_pc=0;
@ -241,6 +248,7 @@ ISR(USART1_UDRE_vect)
if (index_output_dmx>nb_circuits) {
index_output_dmx=IOUTDMX_FIN;
cbi(UCSR1B, UDRIE1);
syncflag=false;
}
}
@ -309,13 +317,14 @@ void setup() {
// ********************************** BOUCLE ********************************* //
int tmptime;
void loop() {
// 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;
tab_input_dmx[514]= (byte)tmptime ;
tmptime= 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
@ -327,24 +336,26 @@ void loop() {
}
// octets d'état. Pour le moment, tous à 0
tab_input_dmx[513]= 0;
tab_input_dmx[514]= 0;
tab_input_dmx[515]= 0;
tab_input_dmx[516]= 0;
//tab_input_dmx[513]= 0;
//tab_input_dmx[514]= 0;
//tab_input_dmx[515]= 0;
//tab_input_dmx[516]= 0;
if(_usbLineInfo.lineState) { // Si port serie USB ouvert
blinkp=10, blinkon=6; // la led clignote plus vite
if(emissionPc!=0)
blinkp=100, blinkon=70; // la led clignote plus vite
if(!syncflag && emissionPc!=0)
{
ecritUSB();
}
} else {
blinkon = 350, blinkp=400;
blinkon = 3500, blinkp=4000;
// dans le doute, on force l'etat d'entree
etat_input_pc=IINUSB_IDLE;
}
int m = millis()>>3;
if (m-blkl) { // Toutes les 8ms
interbrk+=8;
int m = millis();
if (m-blkl) { // Toutes les ms
interbrk+=(m-blkl) ; tmptime+=(m-blkl);
blkcpt++; blkl = m;
if(rxledcpt) rxledcpt--;
else RXLED0;
@ -356,4 +367,3 @@ void loop() {
}