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:
- 20:908740273e88
- Parent:
- 19:6534f3ffdfec
- Child:
- 21:36276a92303f
diff -r 6534f3ffdfec -r 908740273e88 DMX.cpp --- a/DMX.cpp Wed Apr 27 14:26:20 2016 +0000 +++ b/DMX.cpp Tue May 31 11:02:49 2016 +0000 @@ -19,8 +19,6 @@ mode_rx = DMX_MODE_BEGIN; 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; @@ -199,7 +197,7 @@ if (flg) { // Break Time if (addr_rx >= 24 && mode_rx == DMX_MODE_DATA) { - is_received = 1; + on_received(); } mode_rx = DMX_MODE_BREAK; return; @@ -219,11 +217,11 @@ if (mode_rx == DMX_MODE_DATA) { // Data - data_rx[addr_rx] = dat; + data_rx_working[addr_rx] = dat; addr_rx ++; if (addr_rx >= DMX_SIZE) { - is_received = 1; + on_received(); mode_rx = DMX_MODE_BEGIN; } } @@ -244,12 +242,9 @@ } void DMX::clear () { - int i; - - for (i = 0; i < DMX_SIZE; i ++) { - data_tx[i] = 0; - data_rx[i] = 0; - } + memset(data_rx, 0, sizeof(data_rx)); + memset(data_tx, 0, sizeof(data_rx)); + memset(data_rx_working, 0, sizeof(data_rx_working)); } int DMX::isReceived (){ @@ -282,3 +277,13 @@ time_mbb = mbb; return 0; } + +void DMX::attach(void (*function)(void)) { + on_rx.attach(function); +} + +void DMX::on_received() { + memcpy(data_rx, data_rx_working, sizeof(data_rx_working)); + is_received = 1; + on_rx.call(); +} \ No newline at end of file