This commit is contained in:
tzim 2014-05-06 20:31:11 +00:00
parent be8b544963
commit e4c0d123cc
2 changed files with 37 additions and 20 deletions

View file

@ -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<<FE1)) {index_input_dmx=0;return; dmx_rx=false;;}
if ( index_input_dmx==0 && c!=0 ) {index_input_dmx=513; dmx_rx=false;; }
if (r & (1<<FE1)) {index_input_dmx=0;return; }
if ( index_input_dmx==0 && c!=0 ) {index_input_dmx=513; }
if ( index_input_dmx<TEMPDMXRX) {
tab_temp_dmx[index_input_dmx]=c;
index_input_dmx++;
return;
}
if ( index_input_dmx==TEMPDMXRX) {
for(int i=0;i<TEMPDMXRX;i++)
tab_input_dmx[i]=tab_temp_dmx[i];
RXLED1; rxledcpt=RX_TX_LED_TIME;
}
if ( index_input_dmx<=512 )
{
dmx_rx=true;;
tab_input_dmx[index_input_dmx]=c;
index_input_dmx++;
}
@ -281,8 +294,11 @@ void setup() {
}
int blinkon = 350, blinkp=400;
void loop() {
// lancement du break
if (index_output_dmx==-1 ) {
index_output_dmx=-2;
pinMode(tx1pin, OUTPUT); // on met la broche en mode sortie
@ -293,7 +309,6 @@ void loop() {
TIFR4 = 0 ; //Clear Flags timer
TIMSK4 = 64 ; //activation intéruption A &B
TCCR4B = 6; // 00000110 division par 32 de l'horloge base => 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; }
}

View file

@ -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 */