DMX512 send/recv library with STM32 slave support originally from http://mbed.org/users/okini3939/notebook/dmx512
Fork of DMX by
Diff: DMX.cpp
- Revision:
- 18:69d65ca92bcc
- Parent:
- 17:c9198630ba05
- Child:
- 19:6534f3ffdfec
--- a/DMX.cpp Wed Sep 30 13:52:20 2015 +0000 +++ b/DMX.cpp Mon Jan 11 06:17:04 2016 +0000 @@ -17,10 +17,13 @@ // mode_tx = DMX_MODE_BEGIN; mode_tx = DMX_MODE_STOP; mode_rx = DMX_MODE_BEGIN; - is_recived = 0; - is_sent = 0; + is_received = 0; + is_sent = 0; memset(data_tx, 0, sizeof(data_tx)); memset(data_rx, 0, sizeof(data_rx)); + time_break = DMX_TIME_BREAK; + time_mab = DMX_TIME_MAB; + time_mbb = DMX_TIME_MBB; #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) if (p_rx == P0_3) { @@ -110,7 +113,7 @@ timeout01.detach(); _uart->LCR |= (1 << 6); mode_tx = DMX_MODE_BREAK; - timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BREAK); + timeout01.attach_us(this, &DMX::int_timer, time_break); break; case DMX_MODE_BREAK: @@ -118,7 +121,7 @@ timeout01.detach(); _uart->LCR &= ~(1 << 6); mode_tx = DMX_MODE_MAB; - timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_MAB); + timeout01.attach_us(this, &DMX::int_timer, time_mab); break; case DMX_MODE_MAB: @@ -151,7 +154,7 @@ _dmx.attach(0, Serial::TxIrq); mode_tx = DMX_MODE_BEGIN; is_sent = 1; - timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BETWEEN); + timeout01.attach_us(this, &DMX::int_timer, time_mbb); } } } @@ -169,7 +172,7 @@ if (flg & ((1 << 7)|(1 << 3)|(1 << 4))) { // Break Time if (addr_rx >= 24 && mode_rx == DMX_MODE_DATA) { - is_recived = 1; + is_received = 1; } mode_rx = DMX_MODE_BREAK; return; @@ -193,7 +196,7 @@ addr_rx ++; if (addr_rx >= DMX_SIZE) { - is_recived = 1; + is_received = 1; mode_rx = DMX_MODE_BEGIN; } } @@ -203,7 +206,7 @@ if (mode_tx == DMX_MODE_STOP) { mode_tx = DMX_MODE_BEGIN; is_sent = 0; - timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BETWEEN); + timeout01.attach_us(this, &DMX::int_timer, time_mbb); } } @@ -222,9 +225,9 @@ } } -int DMX::isRecived (){ - int r = is_recived; - is_recived = 0; +int DMX::isReceived (){ + int r = is_received; + is_received = 0; return r; } @@ -241,3 +244,14 @@ unsigned char *DMX::getTxBuffer () { return data_tx; } + +int DMX::setTimingParameters (int breaktime, int mab, int mbb) { + if (breaktime < 88 || breaktime > 1000000) return -1; + if (mab < 8 || mab > 1000000) return -1; + if (mbb < 0 || mbb > 1000000) return -1; + + time_break = breaktime; + time_mab = mab; + time_mbb = mbb; + return 0; +}