c++ - Arduino ISR—— vector 的多种定义

标签 c++ arduino dmx512

我正在使用四个宇宙的 DMX 库,here .

在没有任何其他库的情况下使用这个库工作得很好。但是,当还使用标准 SPI.h 库时,我在以下代码行中与 ISR 发生冲突:

lib_dmx.ccp(第 3 行)

#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  #if defined(USE_UART0)
    ISR (USART_RX_vect)
    {
      ArduinoDmx0.Process_ISR_RX(0);
    }  
  #endif
#endif

HardwareSerial.cpp(第 2 行)

#if defined(USART_RX_vect)
  ISR(USART_RX_vect)

现在,我对 arduino 的中断服务相当陌生。 HardwareSerial.cpp 是一个 Arduino 核心,所以我想我无法真正更改此文件中的任何内容。

提前致谢。

更新 1

删除 ISR 并将其替换为 serialEvent() 会出现错误 error: invalid use of void expression。如果没有 void,serialEvent() 就不会正确声明。我必须包含某个库吗?

lib_dmx.ccp

#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  #if defined(USE_UART0)
    void serialEvent(){
        serialEvent(ArduinoDmx0.Process_ISR_RX(0));
    }
  #endif
#endif

更新 2:

lib_dmx.cpp

/***************************************************************************
*
* Title          : Arduino DMX512 library. 4 input/output universes.
* Version        : v 0.3 beta
* Last updated   : 07.07.2012
* Target         : Arduino mega 2560, Arduino mega 1280, Arduino nano (1 universe)  
* Author         : Toni Merino - merino.toni at gmail.com
* Web            : www.deskontrol.net/blog
*
* Based on ATmega8515 Dmx library written by Hendrik Hoelscher, www.hoelscher-hi.de
***************************************************************************

 This program is free software; you can redistribute it and/or 
 modify it under the terms of the GNU General Public License 
 as published by the Free Software Foundation; either version2 of 
 the License, or (at your option) any later version. 

 This program is distributed in the hope that it will be useful, 
 but WITHOUT ANY WARRANTY; without even the implied warranty of 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 General Public License for more details. 

 If you have no copy of the GNU General Public License, write to the 
 Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 

 For other license models, please contact the author.

;***************************************************************************/
#include "lib_dmx.h"
#include <SPI.h>

#if defined(USE_UART0)
  CArduinoDmx ArduinoDmx0(0);
#endif
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  #if defined(USE_UART1)
    CArduinoDmx ArduinoDmx1(1);
  #endif
  #if defined(USE_UART2)
    CArduinoDmx ArduinoDmx2(2);
  #endif
  #if defined(USE_UART3)
    CArduinoDmx ArduinoDmx3(3);
  #endif
#endif

// *************** DMX Transmision Initialisation ****************
void CArduinoDmx::init_tx(uint8_t mode)
{
  cli();          //disable interrupts
  stop_dmx();                         //stop uart
  dmx_mode = mode;
  set_speed(dmx_mode);

  if(control_pin != -1)
  {
    pinMode(control_pin,OUTPUT);        // max485 I/O control
    digitalWrite(control_pin, HIGH);    // set 485 as output
  }

  if(mUART == 0)
  {
    pinMode(1, OUTPUT);
    UBRR0H   = 0;
    UBRR0L   = speed_dmx;  
    UCSR0A  |= (1<<U2X0);
    UCSR0C  |= (3<<UCSZ00)|(1<<USBS0);
    UCSR0B  |= (1<<TXEN0) |(1<<TXCIE0);
    UDR0     = 0;                                     //start USART 0
  }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  else if(mUART == 1)
  {
    pinMode(18, OUTPUT); 
    UBRR1H   = 0;
    UBRR1L   = speed_dmx;   
    UCSR1A  |= (1<<U2X1);
    UCSR1C  |= (3<<UCSZ10)|(1<<USBS1);
    UCSR1B  |= (1<<TXEN1) |(1<<TXCIE1);
    UDR1     = 0;                                     //start USART 1
  }
  else if(mUART == 2)
  {
    pinMode(16, OUTPUT); 
    UBRR2H   = 0;
    UBRR2L   = speed_dmx;   
    UCSR2A  |= (1<<U2X2);
    UCSR2C  |= (3<<UCSZ20)|(1<<USBS2);
    UCSR2B  |= (1<<TXEN2) |(1<<TXCIE2);
    UDR2     = 0;                                     //start USART 2
  }
  else if(mUART == 3)
  {
    pinMode(14, OUTPUT); 
    UBRR3H   = 0;
    UBRR3L   = speed_dmx;    
    UCSR3A  |= (1<<U2X3);
    UCSR3C  |= (3<<UCSZ30)|(1<<USBS3);
    UCSR3B  |= (1<<TXEN3) |(1<<TXCIE3);
    UDR3     = 0;                                     //start USART 3
  }
#endif

  gTxState = BREAK;                                     // start with break
  TxBuffer = (uint8_t*)malloc(tx_channels);     // allocate mem for buffer
  memset((uint8_t*)TxBuffer, 0, tx_channels);   // fill buffer with 0's
  sei();          //enable interrupts
}

// ************************ DMX Stop ***************************
void CArduinoDmx::stop_dmx()
{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  if(mUART == 0)
  {
    UCSR0B &= ~((1<<RXCIE0) | (1<<TXCIE0) | (1<<RXEN0) | (1<<TXEN0));
  }
  else if(mUART == 1)
  {
    UCSR1B &= ~((1<<RXCIE1) | (1<<TXCIE1) | (1<<RXEN1) | (1<<TXEN1));
  }
  else if(mUART == 2)
  {
    UCSR2B &= ~((1<<RXCIE2) | (1<<TXCIE2) | (1<<RXEN2) | (1<<TXEN2));
  }
  else if(mUART == 3)
  {
    UCSR3B &= ~((1<<RXCIE3) | (1<<TXCIE3) | (1<<RXEN3) | (1<<TXEN3));
  }
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  if(mUART == 0)
  {
    UCSR0B &= ~((1<<RXCIE0) | (1<<TXCIE0) | (1<<RXEN0) | (1<<TXEN0));
  }
#endif
}

// *************** DMX Reception Initialisation ****************
void CArduinoDmx::init_rx(uint8_t mode)
{
  cli();          //disable interrupts
  stop_dmx();
  dmx_mode = mode;
  set_speed(dmx_mode);

  if(control_pin != -1)
  {
    pinMode(control_pin,OUTPUT);        //max485 I/O control
    digitalWrite(control_pin, LOW);     //set 485 as input
  }

  if(mUART == 0)
  {
    pinMode(0, INPUT); 
    UBRR0H   = 0;
    UBRR0L   = speed_dmx;
    UCSR0A  |= (1<<U2X0);
    UCSR0C  |= (3<<UCSZ00)|(1<<USBS0);
    UCSR0B  |= (1<<RXEN0) |(1<<RXCIE0);
  }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  else if(mUART == 1)
  {
    pinMode(19, INPUT); 
    UBRR1H   = 0;
    UBRR1L   = speed_dmx;
    UCSR1A  |= (1<<U2X1);
    UCSR1C  |= (3<<UCSZ10)|(1<<USBS1);
    UCSR1B  |= (1<<RXEN1) |(1<<RXCIE1);
  }
  else if(mUART == 2)
  {
    pinMode(17, INPUT); 
    UBRR2H   = 0;
    UBRR2L   = speed_dmx;
    UCSR2A  |= (1<<U2X2); 
    UCSR2C  |= (3<<UCSZ20)|(1<<USBS2);
    UCSR2B  |= (1<<RXEN2) |(1<<RXCIE2);
  }
  else if(mUART == 3)
  {
    pinMode(15, INPUT); 
    UBRR3H   = 0;
    UBRR3L   = speed_dmx; 
    UCSR3A  |= (1<<U2X3);
    UCSR3C  |= (3<<UCSZ30)|(1<<USBS3);
    UCSR3B  |= (1<<RXEN3) |(1<<RXCIE3);
  }
#endif

  gRxState = IDLE;
  RxBuffer = (uint8_t*)malloc(rx_channels);   // allocate mem for buffer
  memset((uint8_t*)RxBuffer, 0, rx_channels); // fill buffer with 0's
  sei();          //enable interrupts
}

// *************** DMX Reception ISR ****************
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  #if defined(USE_UART0)
    ISR (SIG_USART0_RECV)
    {
      ArduinoDmx0.Process_ISR_RX(0);
    }
  #endif
  #if defined(USE_UART1)
    ISR (SIG_USART1_RECV)
    {
      ArduinoDmx1.Process_ISR_RX(1);
    }
  #endif
  #if defined(USE_UART2)
    ISR (SIG_USART2_RECV)
    {
      ArduinoDmx2.Process_ISR_RX(2);
    }
  #endif
  #if defined(USE_UART3)
    ISR (SIG_USART3_RECV)
    {
      ArduinoDmx3.Process_ISR_RX(3);
    }
  #endif
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  #if defined(USE_UART0)
    /*ISR (USART_RX_vect)
    {
        ArduinoDmx0.Process_ISR_RX(0);
    }*/
    /*void serialEvent(){
        serialEvent(ArduinoDmx0.Process_ISR_RX(0));
    }*/  
  #endif
#endif

void CArduinoDmx::Process_ISR_RX(uint8_t rx_isr_number)
{
  if(rx_isr_number == 0)
  {
    USARTstate = UCSR0A;                  //get state
    RxByte     = UDR0;                //get data
    RxState    = gRxState;                    //just get once from SRAM!!!
    if (USARTstate &(1<<FE0))         //check for break
    {                   
      UCSR0A  &= ~(1<<FE0);                 //reset flag
      RxCount  = rx_address;                  //reset frame counter
      gRxState = BREAK;
    }
  }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

  else if(rx_isr_number == 1)
  {
    USARTstate = UCSR1A;                  //get state
    RxByte     = UDR1;                //get data
    RxState    = gRxState;                    //just get once from SRAM!!!
    if (USARTstate &(1<<FE1))         //check for break
    {                   
      UCSR1A  &= ~(1<<FE1);                 //reset flag
      RxCount  = rx_address;                  //reset frame counter
      gRxState = BREAK;
    }
  }
  else if(rx_isr_number == 2)
  {
    USARTstate = UCSR2A;                  //get state
    RxByte     = UDR2;                //get data
    RxState    = gRxState;                    //just get once from SRAM!!!
    if (USARTstate &(1<<FE2))         //check for break
    {                   
      UCSR2A  &= ~(1<<FE2);                 //reset flag
      RxCount  = rx_address;                  //reset frame counter
      gRxState = BREAK;
    }
  }
  else if(rx_isr_number == 3)
  {
    USARTstate = UCSR3A;                  //get state
    RxByte     = UDR3;                //get data
    RxState    = gRxState;                    //just get once from SRAM!!!
    if (USARTstate &(1<<FE3))         //check for break
    {                   
      UCSR3A  &= ~(1<<FE3);                 //reset flag
      RxCount  = rx_address;                  //reset frame counter
      gRxState = BREAK;
    }
  }
#endif

  if (RxState == BREAK)
  {
    if (RxByte == 0) 
    {
      gRxState = STARTB;                          //normal start code detected
      gRxPnt   = ((uint8_t*)RxBuffer + 1);
    }
    else 
      gRxState = IDLE;
  }
  else if (RxState == STARTB)
  {
    if (--RxCount == 0)                         //start address reached?
    {
      gRxState   = STARTADR;
      RxBuffer[0]= RxByte;
    }
  }
  else if (RxState == STARTADR)
  {
    RxPnt  = gRxPnt;
    *RxPnt = RxByte;
    if (++RxPnt >= (RxBuffer + rx_channels))    //all ch received?
    {
      gRxState= IDLE;
      if (*RXisrCallback) RXisrCallback(mUART);   // fire callback for read data
    }
    else 
    {
      gRxPnt = RxPnt;
    }
  }                         
}

// *************** DMX Transmision ISR ****************
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  #if defined(USE_UART0)
    ISR(SIG_USART0_TRANS)
    {
      ArduinoDmx0.Process_ISR_TX(0);
    }
  #endif
  #if defined(USE_UART1)
    ISR(SIG_USART1_TRANS)
    {
      ArduinoDmx1.Process_ISR_TX(1);
    }
  #endif
  #if defined(USE_UART2)
    ISR(SIG_USART2_TRANS)
    {
      ArduinoDmx2.Process_ISR_TX(2);
    }
  #endif
  #if defined(USE_UART3)
    ISR(SIG_USART3_TRANS)
    {
      ArduinoDmx3.Process_ISR_TX(3);
    }
  #endif
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  #if defined(USE_UART0)
    ISR(USART_TX_vect)
    {
      ArduinoDmx0.Process_ISR_TX(0);
    }
  #endif
#endif


void CArduinoDmx::Process_ISR_TX(uint8_t tx_isr_number)
{
  TxState = gTxState;

  if(tx_isr_number == 0)
  {
    if (TxState == TXBREAK) //BREAK + MAB
    {
      UBRR0H   = 0;
      UBRR0L   = speed_break;
      UDR0     = 0;                                 //send break
      gTxState = TXSTARTB;
    }
    else if (TxState == TXSTARTB)
    {
      UBRR0H   = 0;
      UBRR0L   = speed_dmx;
      UDR0     = 0;                                 //send start byte
      gTxState = TXDATA;
      gCurTxCh = 0;
    }
    else
    {
      #if defined(USE_INTERBYTE_DELAY)
        delay_gap();
      #endif    
      CurTxCh = gCurTxCh;
      UDR0 = TxBuffer[CurTxCh++];               //send data
      if (CurTxCh == tx_channels)
      {
        if (*TXisrCallback) TXisrCallback(0); // fire callback for update data
        gTxState = TXBREAK;   // new break if all ch sent
      }
      else 
      {
        gCurTxCh = CurTxCh;
      }
    }
  }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

  else if(tx_isr_number == 1)
  {
    if (TxState == TXBREAK)
    {
      UBRR1H   = 0;
      UBRR1L   = speed_break;
      UDR1     = 0;                                 //send break
      gTxState = TXSTARTB;
    }
    else if (TxState == TXSTARTB)
    {
      UBRR1H   = 0;
      UBRR1L   = speed_dmx;
      UDR1     = 0;                                 //send start byte
      gTxState = TXDATA;
      gCurTxCh = 0;
    }
    else
    {
      #if defined(USE_INTERBYTE_DELAY)
        delay_gap();
      #endif    
      CurTxCh = gCurTxCh;
      UDR1 = TxBuffer[CurTxCh++];               //send data
      if (CurTxCh == tx_channels)
      {
        if (*TXisrCallback) TXisrCallback(1); // fire callback for update data
        gTxState = TXBREAK;   // new break if all ch sent
      }
      else 
      {
        gCurTxCh = CurTxCh;
      }
    }
  }
  else if(tx_isr_number == 2)
  {
    if (TxState == TXBREAK)
    {
      UBRR2H   = 0;
      UBRR2L   = speed_break;
      UDR2     = 0;                                 //send break
      gTxState = TXSTARTB;
    }
    else if (TxState == TXSTARTB)
    {
      UBRR2H   = 0;
      UBRR2L   = speed_dmx;
      UDR2     = 0;                                 //send start byte
      gTxState = TXDATA;
      gCurTxCh = 0;
    }
    else
    {
      #if defined(USE_INTERBYTE_DELAY)
        delay_gap();
      #endif   
      CurTxCh = gCurTxCh;
      UDR2 = TxBuffer[CurTxCh++];               //send data
      if (CurTxCh == tx_channels)
      {
        if (*TXisrCallback) TXisrCallback(2); // fire callback for update data
        gTxState = TXBREAK;   // new break if all ch sent
      }
      else 
      {
        gCurTxCh = CurTxCh;
      }
    }
  }
  else if(tx_isr_number == 3)
  {
    if (TxState == TXBREAK)
    {
      UBRR3H   = 0;
      UBRR3L   = speed_break;
      UDR3     = 0;                                 //send break
      gTxState = TXSTARTB;
    }
    else if (TxState == TXSTARTB)
    {
      UBRR3H   = 0;
      UBRR3L   = speed_dmx;
      UDR3     = 0;                                 //send start byte
      gTxState = TXDATA;
      gCurTxCh = 0;
    }
    else
    {
      #if defined(USE_INTERBYTE_DELAY)
        delay_gap();
      #endif
      CurTxCh = gCurTxCh;
      UDR3 = TxBuffer[CurTxCh++];               //send data
      if (CurTxCh == tx_channels)
      {
        if (*TXisrCallback) TXisrCallback(3); // fire callback for update data
        gTxState = TXBREAK;   // new break if all ch sent
      }
      else 
      {
        gCurTxCh = CurTxCh;
      }
    }
  }
#endif
}

void CArduinoDmx::set_speed(uint8_t mode)
{
  if(mode == 0)
  {
    speed_dmx   = DMX_512;    // DMX-512  (250 kbaud - 512 channels) Standard USITT DMX-512
    speed_break = BREAK_512;
  }
  else if(mode == 1)
  {
    speed_dmx   = DMX_1024;   // DMX-1024 (500 kbaud - 1024 channels) Completely non standard, but usefull ;)
    speed_break = BREAK_1024;
  }
  else if(mode == 2)
  {
    speed_dmx   = DMX_2048;   // DMX-2048 (1000 kbaud - 2048 channels) Used by manufacturers as DMX1000K, DMX-4x or DMX-1M ???
    speed_break = BREAK_2048;
  }  
}

#if defined(USE_INTERBYTE_DELAY)

void CArduinoDmx::delay_gap() // rare cases of equipment non full DMX-512 compliant, need this
{
  if(dmx_mode == 0)
  {
    _delay_us(IBG_512);
  }
  else if(dmx_mode == 1)
  {
    _delay_us(IBG_1024);
  }
  else if(dmx_mode == 2)
  {
    _delay_us(IBG_2048);
  }
}
#endif

lib_dmx.h

/***************************************************************************
*
* Title          : Arduino DMX512 library. 4 input/output universes.
* Version        : v 0.3 beta
* Last updated   : 07.07.2012
* Target         : Arduino mega 2560, Arduino mega 1280, Arduino nano (1 universe)  
* Author         : Toni Merino - merino.toni at gmail.com
* Web            : www.deskontrol.net/blog
*
* Based on ATmega8515 Dmx library written by Hendrik Hoelscher, www.hoelscher-hi.de
***************************************************************************
 This program is free software; you can redistribute it and/or 
 modify it under the terms of the GNU General Public License 
 as published by the Free Software Foundation; either version2 of 
 the License, or (at your option) any later version. 

 This program is distributed in the hope that it will be useful, 
 but WITHOUT ANY WARRANTY; without even the implied warranty of 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 General Public License for more details. 

 If you have no copy of the GNU General Public License, write to the 
 Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 

 For other license models, please contact the author.

;***************************************************************************/
#ifndef __INC_DMX_H
#define __INC_DMX_H

#include <avr/io.h>
#include <stdint.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#if ARDUINO >= 100
  #include "Arduino.h"
#else
   #include "WProgram.h"
#endif

//#define        USE_INTERBYTE_DELAY     // rare cases of equipment non full DMX-512 compliant, need this

// *** comment UARTs not used ***
#define        USE_UART0
//#define        USE_UART1
//#define        USE_UART2
//#define        USE_UART3

// New DMX modes *** EXPERIMENTAL ***
#define        DMX512            (0)    // DMX-512 (250 kbaud - 512 channels) Standard USITT DMX-512
#define        DMX1024           (1)    // DMX-1024 (500 kbaud - 1024 channels) Completely non standard - TESTED ok
#define        DMX2048           (2)    // DMX-2048 (1000 kbaud - 2048 channels) called by manufacturers DMX1000K, DMX 4x or DMX 1M ???

// DMX-512  (250 kbaud - 512 channels) Standard USITT DMX-512
#define        IBG_512           (10)                      // interbyte gap [us]
#define        DMX_512           ((F_CPU/(250000*8))-1)    // 250 kbaud
#define        BREAK_512         ( F_CPU/(100000*8))       // 90.9 kbaud

// DMX-1024 (500 kbaud - 1024 channels) Completely non standard
#define        IBG_1024          (5)                       // interbyte gap [us]
#define        DMX_1024          ((F_CPU/(500000*8))-1)    // 500 kbaud
#define        BREAK_1024        ( F_CPU/(200000*8))       // 181.8 kbaud

// DMX-2048 (1000 kbaud - 2048 channels) Non standard, but used by manufacturers as DMX1000K or DMX-4x or DMX 1M ???
#define        IBG_2048          (2)                       // interbyte gap [us] + nop's to reach 2.5 uS
#define        DMX_2048          ((F_CPU/(1000000*8))-1)   // 1000 kbaud
#define        BREAK_2048        ( F_CPU/(400000*8))       // 363.6 kbaud

// Inline assembly: do nothing for one clock cycle.
#define        nop()             __asm__ __volatile__("nop")

#ifdef __cplusplus
extern "C" {
#endif
  #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    #if defined(USE_UART0)
      void SIG_USART0_RECV  (void) __attribute__((__always_inline__));
      void SIG_USART0_TRANS (void) __attribute__((__always_inline__));
    #endif
    #if defined(USE_UART1)
      void SIG_USART1_RECV  (void) __attribute__((__always_inline__));
      void SIG_USART1_TRANS (void) __attribute__((__always_inline__));
    #endif
    #if defined(USE_UART2)  
      void SIG_USART2_RECV  (void) __attribute__((__always_inline__));
      void SIG_USART2_TRANS (void) __attribute__((__always_inline__));
    #endif
    #if defined(USE_UART3)  
      void SIG_USART3_RECV  (void) __attribute__((__always_inline__));
      void SIG_USART3_TRANS (void) __attribute__((__always_inline__));
    #endif
  #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
    #if defined(USE_UART0)
      void USART_RX_vect    (void) __attribute__((__always_inline__));
      void USART_TX_vect    (void) __attribute__((__always_inline__));
    #endif
  #endif
#ifdef __cplusplus
};
#endif

class CArduinoDmx 
{ 
  #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    #if defined(USE_UART0)
      friend void SIG_USART0_RECV  (void);
      friend void SIG_USART0_TRANS (void);
    #endif
    #if defined(USE_UART1)
      friend void SIG_USART1_RECV  (void);
      friend void SIG_USART1_TRANS (void);
    #endif
    #if defined(USE_UART2)  
      friend void SIG_USART2_RECV  (void);
      friend void SIG_USART2_TRANS (void);
    #endif
    #if defined(USE_UART3)  
      friend void SIG_USART3_RECV  (void);
      friend void SIG_USART3_TRANS (void);
    #endif
  #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
    #if defined(USE_UART0)
      friend void USART_RX_vect    (void);
      friend void USART_TX_vect    (void);
    #endif
  #endif

public:
   enum {IDLE, BREAK, STARTB, STARTADR};     // RX DMX states
   enum {TXBREAK, TXSTARTB, TXDATA};         // TX DMX states

   volatile uint8_t    *RxBuffer;            // array of RX DMX values
   volatile uint8_t    *TxBuffer;            // array of TX DMX values

private:
   uint8_t     gRxState;
   uint8_t    *gRxPnt;
   uint8_t     IndicatorCount;
   uint8_t     USARTstate;      
   uint8_t     RxByte;     
   uint8_t     RxState;
   uint8_t     mUART;
   uint8_t     gTxState;
   uint16_t    RxCount;
   uint16_t    gCurTxCh;        
   uint16_t    rx_channels;                  // rx channels number
   uint16_t    tx_channels;                  // tx channels number
   uint16_t    rx_address;                   // rx start address
   uint16_t    tx_address;                   // tx start address
   int8_t      rx_led;                       // rx indicator led pin
   int8_t      tx_led;                       // tx indicator led pin
   int8_t      control_pin;                  // max485 input/output selection pin
   uint8_t     dmx_mode;                     // Standard USITT DMX512 = 0, non standard DMX1024 = 1, non standard DMX2048 (DMX1000K) = 2
   uint8_t     speed_dmx;
   uint8_t     speed_break;
   uint16_t    CurTxCh;
   uint8_t     TxState;
   uint8_t    *RxPnt;

#if defined(USE_INTERBYTE_DELAY)   
   void        delay_gap          ();
#endif

public:
   void        stop_dmx           ();
   void        set_speed          (uint8_t mode);
   void        set_control_pin    (int8_t  pin)        { control_pin     = pin;      }
   void        init_rx            (uint8_t mode);  // Standard USITT DMX512 = 0, non standard DMX1024 = 1, non standard DMX2048 (DMX1000K) = 2
   void        set_rx_address     (uint16_t address)   { rx_address      = address;  }
   void        set_rx_channels    (uint16_t channels)  { rx_channels     = channels; }
   void        init_tx            (uint8_t mode);  // Standard USITT DMX512 = 0, non standard DMX1024 = 1, non standard DMX2048 (DMX1000K) = 2
   void        set_tx_address     (uint16_t address)   { tx_address      = address;  }
   void        set_tx_channels    (uint16_t channels)  { tx_channels     = channels; }

   void        attachTXInterrupt  (void (*isr)(uint8_t uart))      { TXisrCallback   = isr; }   // register the user TX callback
   void        attachRXInterrupt  (void (*isr)(uint8_t uart))      { RXisrCallback   = isr; }   // register the user RX callback

   void        (*TXisrCallback)   (uint8_t uart);
   void        (*RXisrCallback)   (uint8_t uart);

   inline void Process_ISR_RX     (uint8_t  rx_isr_number);
   inline void Process_ISR_TX     (uint8_t  tx_isr_number);

public:
   CArduinoDmx                    (uint8_t uart)       { rx_address      = 1; 
                                                         rx_channels     = 8;
                                                         tx_address      = 1; 
                                                         tx_channels     = 8;
                                                         mUART           = uart; }

};

#if defined(USE_UART0)
  extern CArduinoDmx ArduinoDmx0;
#endif
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  #if defined(USE_UART1)
    extern CArduinoDmx ArduinoDmx1;
  #endif
  #if defined(USE_UART2)
    extern CArduinoDmx ArduinoDmx2;
  #endif
  #if defined(USE_UART3)
    extern CArduinoDmx ArduinoDmx3;
  #endif
#endif

#endif

myfile.ino

#include <SPI.h>
#include <Ethernet.h>
//#include <EthernetUdp.h>
#include <lib_dmx.h>

#define DMX512  (0)

byte mac[] = { 0xDD, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,0,0,2); // TODO: assign ip address from DHCP
unsigned int multicastPort = 8888;
IPAddress multicastIp(239,0,0,57);

char packetBuffer[UDP_TX_PACKET_MAX_SIZE];

//EthernetUDP Udp;

int sensorValue = 0;
int ledState = 0;
int DMXPin = 0;

void setup() {

  // DMX
  ArduinoDmx0.set_control_pin(DMXPin);
  ArduinoDmx0.set_rx_channels(1);
  ArduinoDmx0.set_tx_channels(5);
  ArduinoDmx0.init_tx(DMX512);

  Ethernet.begin(mac,ip);
  //Udp.beginMulti( multicastIp, multicastPort );
  Serial.begin(9600);

}

void loop() {
  /*int packetSize = Udp.parsePacket();
  if(packetSize){
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++){
      Serial.print(remote[i], DEC);
      if (i < 3){
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer[0]);

    ArduinoDmx0.TxBuffer[0] = (int)packetBuffer;
  }*/
}

这个库允许 DMX 有多个宇宙,虽然我现在只使用第一个(这就是为什么在 .h 文件中其中一些被转义了)。在 myfile.ino 中,我删除了某些内容,因为我还实现了一个 UDP 多播库(修改后的标准以太网库)。

最佳答案

您可以从 lib_dmx 中删除该 ISR 并将 ArduinoDmx0.Process_ISR_RX(0);进入serialEvent()

关于c++ - Arduino ISR—— vector 的多种定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22691264/

相关文章:

c++ - 没有 IDE 的 Arduino DUE 编程 (Linux)

c - OLED 128x64 位图显示问题 [ARDUINO]

serial-port - Arduino串行通讯输出

.net - 是否有用于 DMX 的 .Net 库,特别是 sACN(流 ACN)?

c - RGB 到 RGB 加琥珀色

c++ - VC++ 2010 : Compiling with/Wall

c++ - 重载赋值运算符 : if we return (*this),,它是指针/地址处的值,赋值运算符的正确语法是什么?

c++使用getline,输出在开头带有一个额外的空格

c++ - 如何从汇编代码中找出函数原型(prototype)?

c - 使用 DMXSerial Arduino 库发送和接收 DMX-512