Finalisation du mode synchrone

This commit is contained in:
tzim 2014-05-12 09:48:16 +00:00
parent f10d6d9b1d
commit a4c102d20b
2 changed files with 26 additions and 35 deletions

View file

@ -102,12 +102,12 @@ namespace DMX2
} }
} }
public bool Sync { public bool Sync {
get { get {
return sync; return sync;
} }
set { set {
flags = (byte)( (flags & 0xFD) | (value?2:0));
sync = value; sync = value;
} }
} }
@ -242,7 +242,7 @@ namespace DMX2
byte[] tmpBuffer = new byte[2]; byte[] tmpBuffer = new byte[2];
tmpBuffer [0] = 27; // Esc tmpBuffer [0] = 27; // Esc
tmpBuffer [1] = 69; // 'E' tmpBuffer [1] = 65; // 'A'
serial.Write (tmpBuffer, 0, tmpBuffer.Length); serial.Write (tmpBuffer, 0, tmpBuffer.Length);
@ -252,7 +252,7 @@ namespace DMX2
} }
serial.Read(tmpBuffer,0,1); serial.Read(tmpBuffer,0,1);
if(tmpBuffer[0] != 69) if(tmpBuffer[0] != 65)
etat = etatAutomate.Erreur; etat = etatAutomate.Erreur;
} }
@ -381,8 +381,8 @@ namespace DMX2
} }
serial.Read(inputbuffer,0,inputbuffer.Length); serial.Read(inputbuffer,0,inputbuffer.Length);
if (flag_input != inputbuffer[513]) { if (flag_input != inputbuffer[0]) {
flag_input = inputbuffer[513]; flag_input = inputbuffer[0];
Console.WriteLine(flag_input ); Console.WriteLine(flag_input );
} }
if(serial.BytesToRead>0) if(serial.BytesToRead>0)

View file

@ -25,7 +25,7 @@ int main(void)
// définitions // définitions
#define TEMPDMXRX 8 // Longueur de trame mini en reception #define TEMPDMXRX 8 // Longueur de trame mini en reception
#define IOUTDMX_FIN -4 #define IOUTDMX_FIN -4
#define IOUTDMX_WAIT -5 #define IOUTDMX_WAIT -5 // Attente du PC en mode synchrone
#define IOUTDMX_IDLE -1 #define IOUTDMX_IDLE -1
#define IOUTDMX_BRK -2 #define IOUTDMX_BRK -2
#define IOUTDMX_MAB -3 #define IOUTDMX_MAB -3
@ -123,16 +123,6 @@ void CDC_accept()
break; 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 // si aucune commande n'est trouvée (toujours à 1) on repart à 0
etat_input_pc=IINUSB_IDLE; etat_input_pc=IINUSB_IDLE;
break; break;
@ -140,12 +130,8 @@ void CDC_accept()
case IINUSB_DATA: // 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 if(index_input_pc<513) return;
if (index_input_pc > 512) { etat_input_pc=0;
etat_input_pc=0;
if(index_output_dmx==IOUTDMX_WAIT)
index_output_dmx=IOUTDMX_IDLE;
}
break; break;
case IINUSB_PARAM: case IINUSB_PARAM:
@ -156,6 +142,7 @@ void CDC_accept()
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;
syncflag = inbuffer[3] & 2;
dmx_frame_interval = inbuffer[4]; dmx_frame_interval = inbuffer[4];
etat_input_pc=0; etat_input_pc=0;
@ -184,6 +171,8 @@ void ecritUSB()
// Emission du tableau complet // Emission du tableau complet
index_output_pc+= USB_Send(CDC_TX,tab_input_dmx+index_output_pc, 517-index_output_pc); index_output_pc+= USB_Send(CDC_TX,tab_input_dmx+index_output_pc, 517-index_output_pc);
if (index_output_pc>516) { if (index_output_pc>516) {
if(index_output_dmx==IOUTDMX_WAIT)
index_output_dmx=IOUTDMX_IDLE;
emissionPc=0; emissionPc=0;
} }
} }
@ -232,10 +221,10 @@ 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) {
if(syncflag) { if(syncflag)
index_output_dmx=IOUTDMX_WAIT; index_output_dmx=IOUTDMX_WAIT;
} else
else index_output_dmx=IOUTDMX_IDLE; index_output_dmx=IOUTDMX_IDLE;
} }
} }
@ -323,16 +312,17 @@ void setup() {
// ********************************** BOUCLE ********************************* // // ********************************** BOUCLE ********************************* //
int tmptime;
void loop() { void loop() {
if(index_output_dmx==IOUTDMX_WAIT && interbrk >255) // en mode synchrone, dmx_frame_interval est un maximum
if(index_output_dmx==IOUTDMX_WAIT && interbrk >=dmx_frame_interval)
index_output_dmx=IOUTDMX_IDLE; index_output_dmx=IOUTDMX_IDLE;
// Lancement du Break : après fin de transmisson et ecoulement de "dmx_frame_interval" ms depuis le dernier 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 ) { // ou immediatement au passage en IDLE si mode synchrone
if (index_output_dmx==IOUTDMX_IDLE && (interbrk >= dmx_frame_interval||syncflag)) {
index_output_dmx=IOUTDMX_BRK; index_output_dmx=IOUTDMX_BRK;
tab_input_dmx[514]= (byte)tmptime ; tab_input_dmx[514]= (byte)interbrk ;
tmptime= interbrk=0; interbrk=0;
pinMode(TX1PIN, OUTPUT); // on met la broche en mode sortie pinMode(TX1PIN, OUTPUT); // on met la broche en mode sortie
cbi(UCSR1B, TXEN1); //on stop la transmission cbi(UCSR1B, TXEN1); //on stop la transmission
digitalWrite(TX1PIN, LOW); // on met la broche à 0 digitalWrite(TX1PIN, LOW); // on met la broche à 0
@ -351,10 +341,11 @@ tmptime= interbrk=0;
if(_usbLineInfo.lineState) { // Si port serie USB ouvert if(_usbLineInfo.lineState) { // Si port serie USB ouvert
blinkp=100, blinkon=70; // la led clignote plus vite blinkp=100, blinkon=70; // la led clignote plus vite
if((!syncflag || index_output_dmx==IOUTDMX_WAIT || index_output_dmx==IOUTDMX_IDLE ) && emissionPc!=0) if(emissionPc!=0)
{ {
syncflag=false; // en mode synchrone emission uniquement entre les transmissions DMX
ecritUSB(); if (!syncflag || index_output_dmx==IOUTDMX_WAIT || index_output_dmx==IOUTDMX_IDLE)
ecritUSB();
} }
} else { } else {
blinkon = 3500, blinkp=4000; blinkon = 3500, blinkp=4000;
@ -364,7 +355,7 @@ tmptime= interbrk=0;
int m = millis(); int m = millis();
if (m-blkl) { // Toutes les ms if (m-blkl) { // Toutes les ms
interbrk+=(m-blkl) ; tmptime+=(m-blkl); interbrk+=(m-blkl) ;
blkcpt++; blkl = m; blkcpt++; blkl = m;
if(rxledcpt) rxledcpt--; if(rxledcpt) rxledcpt--;
else RXLED0; else RXLED0;