Finalisation du mode synchrone
This commit is contained in:
parent
f10d6d9b1d
commit
a4c102d20b
2 changed files with 26 additions and 35 deletions
|
|
@ -102,12 +102,12 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public bool Sync {
|
||||
get {
|
||||
return sync;
|
||||
}
|
||||
set {
|
||||
flags = (byte)( (flags & 0xFD) | (value?2:0));
|
||||
sync = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -242,7 +242,7 @@ namespace DMX2
|
|||
byte[] tmpBuffer = new byte[2];
|
||||
|
||||
tmpBuffer [0] = 27; // Esc
|
||||
tmpBuffer [1] = 69; // 'E'
|
||||
tmpBuffer [1] = 65; // 'A'
|
||||
|
||||
serial.Write (tmpBuffer, 0, tmpBuffer.Length);
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ namespace DMX2
|
|||
}
|
||||
|
||||
serial.Read(tmpBuffer,0,1);
|
||||
if(tmpBuffer[0] != 69)
|
||||
if(tmpBuffer[0] != 65)
|
||||
etat = etatAutomate.Erreur;
|
||||
}
|
||||
|
||||
|
|
@ -381,8 +381,8 @@ namespace DMX2
|
|||
}
|
||||
|
||||
serial.Read(inputbuffer,0,inputbuffer.Length);
|
||||
if (flag_input != inputbuffer[513]) {
|
||||
flag_input = inputbuffer[513];
|
||||
if (flag_input != inputbuffer[0]) {
|
||||
flag_input = inputbuffer[0];
|
||||
Console.WriteLine(flag_input );
|
||||
}
|
||||
if(serial.BytesToRead>0)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ int main(void)
|
|||
// définitions
|
||||
#define TEMPDMXRX 8 // Longueur de trame mini en reception
|
||||
#define IOUTDMX_FIN -4
|
||||
#define IOUTDMX_WAIT -5
|
||||
#define IOUTDMX_WAIT -5 // Attente du PC en mode synchrone
|
||||
#define IOUTDMX_IDLE -1
|
||||
#define IOUTDMX_BRK -2
|
||||
#define IOUTDMX_MAB -3
|
||||
|
|
@ -123,16 +123,6 @@ void CDC_accept()
|
|||
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;
|
||||
break;
|
||||
|
|
@ -140,12 +130,8 @@ void CDC_accept()
|
|||
case IINUSB_DATA: // reception trame pc
|
||||
// on rempli le tableau
|
||||
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 > 512) {
|
||||
etat_input_pc=0;
|
||||
if(index_output_dmx==IOUTDMX_WAIT)
|
||||
index_output_dmx=IOUTDMX_IDLE;
|
||||
}
|
||||
if(index_input_pc<513) return;
|
||||
etat_input_pc=0;
|
||||
break;
|
||||
|
||||
case IINUSB_PARAM:
|
||||
|
|
@ -156,6 +142,7 @@ void CDC_accept()
|
|||
brk_timer_end = (inbuffer[1]/2);
|
||||
mab_timer_end = (inbuffer[2]/2);
|
||||
flag_merge1 = inbuffer[3] & 1;
|
||||
syncflag = inbuffer[3] & 2;
|
||||
dmx_frame_interval = inbuffer[4];
|
||||
|
||||
etat_input_pc=0;
|
||||
|
|
@ -184,6 +171,8 @@ void ecritUSB()
|
|||
// Emission du tableau complet
|
||||
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_dmx==IOUTDMX_WAIT)
|
||||
index_output_dmx=IOUTDMX_IDLE;
|
||||
emissionPc=0;
|
||||
}
|
||||
}
|
||||
|
|
@ -232,10 +221,10 @@ ISR(USART1_TX_vect)
|
|||
{
|
||||
// si l'USART 1 est vide => break
|
||||
if(index_output_dmx==IOUTDMX_FIN) {
|
||||
if(syncflag) {
|
||||
if(syncflag)
|
||||
index_output_dmx=IOUTDMX_WAIT;
|
||||
}
|
||||
else index_output_dmx=IOUTDMX_IDLE;
|
||||
else
|
||||
index_output_dmx=IOUTDMX_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -323,16 +312,17 @@ void setup() {
|
|||
|
||||
// ********************************** BOUCLE ********************************* //
|
||||
|
||||
int tmptime;
|
||||
|
||||
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;
|
||||
|
||||
// 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;
|
||||
tab_input_dmx[514]= (byte)tmptime ;
|
||||
tmptime= interbrk=0;
|
||||
tab_input_dmx[514]= (byte)interbrk ;
|
||||
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
|
||||
|
|
@ -351,10 +341,11 @@ tmptime= interbrk=0;
|
|||
|
||||
if(_usbLineInfo.lineState) { // Si port serie USB ouvert
|
||||
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;
|
||||
ecritUSB();
|
||||
// en mode synchrone emission uniquement entre les transmissions DMX
|
||||
if (!syncflag || index_output_dmx==IOUTDMX_WAIT || index_output_dmx==IOUTDMX_IDLE)
|
||||
ecritUSB();
|
||||
}
|
||||
} else {
|
||||
blinkon = 3500, blinkp=4000;
|
||||
|
|
@ -364,7 +355,7 @@ tmptime= interbrk=0;
|
|||
|
||||
int m = millis();
|
||||
if (m-blkl) { // Toutes les ms
|
||||
interbrk+=(m-blkl) ; tmptime+=(m-blkl);
|
||||
interbrk+=(m-blkl) ;
|
||||
blkcpt++; blkl = m;
|
||||
if(rxledcpt) rxledcpt--;
|
||||
else RXLED0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue