DMX512 send/recv library http://mbed.org/users/okini3939/notebook/dmx512

Dependents:   dmx_test ArtNodeLED SPK-DVIMXR SPK-DMXer

DMX512 send/recv library

DMX512 is protocol for lighting.

調光プロトコル DMX512 を送受信するライブラリです。

see: http://mbed.org/users/okini3939/notebook/dmx512/

LPC1114 support is thanks to Stanly Chen

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Mon Jan 11 06:17:04 2016 +0000
Parent:
17:c9198630ba05
Commit message:
fix isReceived, isSent

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 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;
+}
--- a/DMX.h	Wed Sep 30 13:52:20 2015 +0000
+++ b/DMX.h	Mon Jan 11 06:17:04 2016 +0000
@@ -14,13 +14,14 @@
 #include "mbed.h"
 #include "RawSerial.h"
 
-#define DMX_UART_DIRECT
+//#define DMX_UART_DIRECT
 
-#define DMX_SIZE 512
-#define DMX_TIME_BREAK 100 // 100us (88us-1s)
-#define DMX_TIME_MAB 10 // 10us (8us-1s)
-#define DMX_TIME_BETWEEN 200 // 10us (0-1s)
-#define DMX_START_CODE 0
+#define DMX_SIZE        512
+#define DMX_START_CODE  0
+
+#define DMX_TIME_BREAK  100 // 100us (88us-1s)
+#define DMX_TIME_MAB    12 // 12us (8us-1s)
+#define DMX_TIME_MBB    200 // 10us (0-1s)
 
 enum DMX_MODE {
     DMX_MODE_BEGIN,
@@ -76,10 +77,11 @@
      */
     void clear ();
 
-    int isRecived ();
+    int isReceived ();
     int isSent ();
     unsigned char *getRxBuffer ();
     unsigned char *getTxBuffer ();
+    int setTimingParameters (int breaktime, int mab, int mbb);
 
 protected:
 
@@ -94,7 +96,8 @@
     volatile int addr_tx, addr_rx;
     unsigned char data_tx[DMX_SIZE];
     unsigned char data_rx[DMX_SIZE];
-    int is_recived, is_sent;
+    int is_received, is_sent;
+    int time_break, time_mab, time_mbb;
 
 private:
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)