From e4c0d123cce5b473695db0f1817ecf60e8734819 Mon Sep 17 00:00:00 2001 From: tzim Date: Tue, 6 May 2014 20:31:11 +0000 Subject: [PATCH] --- dmx512_micro/dmx512_micro.cpp | 53 +++++++++++++++++++++++------------ dmx512_micro/lib/USBCore.cpp | 4 +-- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/dmx512_micro/dmx512_micro.cpp b/dmx512_micro/dmx512_micro.cpp index 70264bb..8119d1d 100644 --- a/dmx512_micro/dmx512_micro.cpp +++ b/dmx512_micro/dmx512_micro.cpp @@ -28,10 +28,14 @@ int main(void) #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif +#define TEMPDMXRX 8 + // 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]; + // reception volatile int index_input_pc=0; // entrée serial 0 volatile int index_output_pc=0; // sortie serial 0 @@ -43,9 +47,8 @@ volatile int etat_input_pc=0; // 0 raz ; 1 esc reçu ; 2 D reçu : pret à recev int tx1pin = 1; // pin DMX serial 1 int ledPin = 13; // led interne -unsigned int blkl = 0, blkcpt=0; -volatile bool dmx_rx=0; -volatile bool pc_rx=0; +unsigned int blkl = 0, blkcpt=0, rxledcpt=0 ,txledcpt=0; +#define RX_TX_LED_TIME 3 byte brk_timer_end=75; // def : 150us byte mab_timer_end=25; //def : 50us @@ -128,7 +131,6 @@ void litUSB(char c) index_input_pc++; // si on arrive à 512 if (index_input_pc > 512) {// on se prépare à emmetre vers le pc - pc_rx=1; etat_input_pc=0; } break; @@ -168,6 +170,7 @@ void litUSB(char c) void ecritUSB() { + TXLED1; txledcpt=RX_TX_LED_TIME; if(index_output_pc > 516){ USB_Send(CDC_TX,tab_input_dmx+index_output_pc,1); emissionPc=0; @@ -186,11 +189,21 @@ ISR(USART1_RX_vect) char c,r; r = UCSR1A; c = UDR1; - if (r & (1< 2µs - dmx_rx=false; } // octets d'état. Pour le moment, tous à 0 @@ -303,21 +318,23 @@ void loop() { tab_input_dmx[516]=0; if(_usbLineInfo.lineState) { // Si port serie USB ouvert + blinkp=10, blinkon=6; // led clignote plus vite if(emissionPc!=0) { ecritUSB(); } - } else { - pc_rx=0; - etat_input_pc=0; + } else { + blinkon = 350, blinkp=400; + etat_input_pc=0; } - // Clignotement de la led a vitesse variable en fonction de l'etat - int blinkon = 15, blinkp=16; - if(pc_rx) blinkp=5, blinkon=4; - if(dmx_rx) blinkon=1; - - int m = millis()>>6; - if (m-blkl) { blkcpt++; blkl = m;} + 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; } } diff --git a/dmx512_micro/lib/USBCore.cpp b/dmx512_micro/lib/USBCore.cpp index 6915dcc..cbbd694 100644 --- a/dmx512_micro/lib/USBCore.cpp +++ b/dmx512_micro/lib/USBCore.cpp @@ -33,7 +33,7 @@ /** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */ #define TX_RX_LED_PULSE_MS 10 -/* + #undef TXLED1 #undef TXLED0 #undef RXLED1 @@ -42,7 +42,7 @@ #define TXLED0 #define RXLED1 #define RXLED0 -*/ + volatile u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */ volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */