Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DMX by
Revision 20:908740273e88, committed 2016-05-31
- Comitter:
- Ingram
- Date:
- Tue May 31 11:02:49 2016 +0000
- Parent:
- 19:6534f3ffdfec
- Child:
- 21:36276a92303f
- Commit message:
- Add function pointer for "on dmx frame received" and use memset in clear()
Changed in this revision
| DMX.cpp | Show annotated file Show diff for this revision Revisions of this file |
| DMX.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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
--- a/DMX.h Wed Apr 27 14:26:20 2016 +0000
+++ b/DMX.h Tue May 31 11:02:49 2016 +0000
@@ -82,12 +82,15 @@
unsigned char *getRxBuffer ();
unsigned char *getTxBuffer ();
int setTimingParameters (int breaktime, int mab, int mbb);
+
+ void attach(void (*function)(void));
protected:
void int_timer ();
void int_tx ();
void int_rx ();
+ void on_received();
// Serial _dmx;
RawSerial _dmx;
@@ -95,9 +98,11 @@
volatile DMX_MODE mode_tx, mode_rx;
volatile int addr_tx, addr_rx;
unsigned char data_tx[DMX_SIZE];
+ unsigned char data_rx_working[DMX_SIZE];
unsigned char data_rx[DMX_SIZE];
int is_received, is_sent;
int time_break, time_mab, time_mbb;
+ FunctionPointer on_rx;
private:
#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
