This commit is contained in:
parent
a4c102d20b
commit
e20ca3ba27
2 changed files with 23 additions and 14 deletions
|
|
@ -45,7 +45,7 @@ namespace DMX2
|
|||
const int timeout = 500;
|
||||
|
||||
// tampons Entrée/Sortie
|
||||
public byte[] inputbuffer = new byte[516];
|
||||
public byte[] inputbuffer = new byte[517];
|
||||
byte[] outputbuffer = new byte[514];
|
||||
|
||||
//Thread de boucle
|
||||
|
|
@ -381,8 +381,8 @@ namespace DMX2
|
|||
}
|
||||
|
||||
serial.Read(inputbuffer,0,inputbuffer.Length);
|
||||
if (flag_input != inputbuffer[0]) {
|
||||
flag_input = inputbuffer[0];
|
||||
if (flag_input != inputbuffer[512]) {
|
||||
flag_input = inputbuffer[512];
|
||||
Console.WriteLine(flag_input );
|
||||
}
|
||||
if(serial.BytesToRead>0)
|
||||
|
|
@ -465,9 +465,9 @@ namespace DMX2
|
|||
{
|
||||
lock(watchdmx)
|
||||
foreach (int dmx in watchdmx) {
|
||||
if( inputbuffer[dmx-1]!= lastVal[dmx]){
|
||||
lastVal[dmx] = inputbuffer[dmx-1];
|
||||
eventsPending.Enqueue(new dmxState(dmx,inputbuffer[dmx-1]));
|
||||
if( inputbuffer[dmx]!= lastVal[dmx]){
|
||||
lastVal[dmx] = inputbuffer[dmx];
|
||||
eventsPending.Enqueue(new dmxState(dmx,inputbuffer[dmx]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,11 @@ void CDC_accept()
|
|||
case IINUSB_IDLE:
|
||||
USB_Recv(CDC_RX,&c,1);
|
||||
// on attend un 'esc' pour commencer
|
||||
if (c==27) { etat_input_pc=IINUSB_ESC; break;}
|
||||
if (c==27) {
|
||||
etat_input_pc=IINUSB_ESC;
|
||||
RXLED1; rxledcpt=RX_TX_LED_TIME;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case IINUSB_ESC:
|
||||
|
|
@ -87,7 +91,7 @@ void CDC_accept()
|
|||
etat_input_pc=IINUSB_DATA;
|
||||
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)
|
||||
index_output_pc=0; // on init l'index d'emmission vers le pc
|
||||
emissionPc=1;
|
||||
break;
|
||||
}
|
||||
|
|
@ -162,7 +166,6 @@ void CDC_accept()
|
|||
|
||||
void ecritUSB()
|
||||
{
|
||||
TXLED1; txledcpt=RX_TX_LED_TIME;
|
||||
if(index_output_pc > 516){ // Emission d'un seul caractere (code etat)
|
||||
USB_Send(CDC_TX,tab_input_dmx+index_output_pc,1);
|
||||
emissionPc=0;
|
||||
|
|
@ -190,7 +193,7 @@ ISR(USART1_RX_vect)
|
|||
|
||||
if (r & (1<<FE1)) {index_input_dmx=0;return; } // Detection du BRK
|
||||
|
||||
if ( index_input_dmx==0 && c!=0 ) {index_input_dmx=513; } // Start code => doit etre 0
|
||||
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;
|
||||
|
|
@ -200,8 +203,9 @@ ISR(USART1_RX_vect)
|
|||
|
||||
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];
|
||||
tab_input_dmx[i]=tab_temp_dmx[i];
|
||||
RXLED1; rxledcpt=RX_TX_LED_TIME;
|
||||
tab_input_dmx[513]=0;
|
||||
}
|
||||
|
||||
if ( index_input_dmx<=512 )
|
||||
|
|
@ -259,7 +263,7 @@ ISR(TIMER4_COMPA_vect) {
|
|||
return;
|
||||
}
|
||||
if (index_output_dmx==IOUTDMX_MAB ) { // en cours de mab
|
||||
//TXLED1; txledcpt=RX_TX_LED_TIME;
|
||||
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
|
||||
|
|
@ -355,8 +359,13 @@ void loop() {
|
|||
|
||||
int m = millis();
|
||||
if (m-blkl) { // Toutes les ms
|
||||
interbrk+=(m-blkl) ;
|
||||
blkcpt++; blkl = m;
|
||||
int ival = (m-blkl) ;
|
||||
interbrk+=ival ;
|
||||
blkcpt+=ival ;
|
||||
if(tab_input_dmx[513]<200) tab_input_dmx[513]+=ival ; // "age" de la trame recue
|
||||
|
||||
blkl = m;
|
||||
|
||||
if(rxledcpt) rxledcpt--;
|
||||
else RXLED0;
|
||||
if(txledcpt) txledcpt--;
|
||||
|
|
|
|||
Loading…
Reference in a new issue