Skip to content

Commit

Permalink
integrate option to change timeout for receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
Marthaarman committed Feb 27, 2023
1 parent bc8af6a commit ea19a11
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/dmx_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
};
}

Expand Down
6 changes: 6 additions & 0 deletions src/dmx_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion src/dmx_transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/dmx_transceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ea19a11

Please sign in to comment.