diff --git a/src/dmx_receiver.cpp b/src/dmx_receiver.cpp index 6ce87ca..3c25c0a 100644 --- a/src/dmx_receiver.cpp +++ b/src/dmx_receiver.cpp @@ -35,6 +35,10 @@ void DMX_Receiver::set_enable_pin(uint8_t pin) { digitalWrite(this->_rx_enable_pin, LOW); } +void DMX_Receiver::set_timeout(uint16_t time_milliseconds) { + _timeout_time = time_milliseconds; +} + void DMX_Receiver::receive() { // set flags // enable receive pin @@ -47,7 +51,7 @@ void DMX_Receiver::receive() { uint32_t begin_time = millis(); while(this->_flag_started) { if(this->_flag_receive == false) {break; } // done receiving - if((millis() - begin_time) > 1000 && this->_flag_payload == false) {break;} // time-out + if((millis() - begin_time) > _timeout_time && this->_flag_payload == false) {break;} // time-out }; } diff --git a/src/dmx_receiver.h b/src/dmx_receiver.h index c9b0349..280d9e9 100644 --- a/src/dmx_receiver.h +++ b/src/dmx_receiver.h @@ -25,15 +25,21 @@ class DMX_Receiver { // called when a byte has been received void interrupt(); + // sets a hold time (or timeout time) which is the time in milliseconds to wait for a new DMX packet + void set_timeout(uint16_t time_milliseconds); + void set_hold_time(uint16_t time_milliseconds) {set_timeout(time_milliseconds);} + // returns the value of a specific dmx channel uint8_t get_dmx_value(uint16_t channel); + private: uint8_t _rx_enable_pin = 6; uint8_t *_channel_values = (uint8_t*) calloc(513, sizeof(uint8_t)); uint16_t _byte_counter = 0; + uint16_t _timeout_time = 50; // 50 ms default wait time uint32_t _bit_counter = 0; diff --git a/src/dmx_transceiver.cpp b/src/dmx_transceiver.cpp index 59705b4..86e7b28 100644 --- a/src/dmx_transceiver.cpp +++ b/src/dmx_transceiver.cpp @@ -21,10 +21,13 @@ void DMX_Transceiver::set_tx_enable_pin(uint8_t pin) { } void DMX_Transceiver::set_rx_enable_pin(uint8_t pin) { - _dmx_receiver->set_enable_pin(pin); } +void DMX_Transceiver::set_rx_timeout(uint16_t time_milliseconds) { + _dmx_receiver->set_timeout(time_milliseconds); +}; + void DMX_Transceiver::transmit() { _dmx_transmitter->transmit(); } diff --git a/src/dmx_transceiver.h b/src/dmx_transceiver.h index 4719d0e..b0baa9a 100644 --- a/src/dmx_transceiver.h +++ b/src/dmx_transceiver.h @@ -35,6 +35,10 @@ class DMX_Transceiver { void set_tx_enable_pin(uint8_t pin); void set_rx_enable_pin(uint8_t pin); + // set RX hold time (pause time) + void set_rx_timeout(uint16_t time_milliseconds); + void set_rx_hold_time(uint16_t time_milliseconds) {set_rx_timeout(time_milliseconds);} + // set a dmx value for a specific channel // will be written when transmit or transceive function is called void set_dmx_value(uint16_t channel, uint8_t value);