ProDevelopTeam#MasterRace / Mbed 2 deprecated ArtnetDMX

Dependencies:   mbed DMX TextLCD mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
Ayrton_L
Date:
Wed Mar 09 03:53:02 2016 +0000
Parent:
19:e8b826ab28a8
Child:
21:74c951b62025
Commit message:
Optimized DMX (OOP == CLASS);

Changed in this revision

DMX.h Show annotated file Show diff for this revision Revisions of this file
Screen.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/DMX.h	Wed Mar 09 01:24:39 2016 +0000
+++ b/DMX.h	Wed Mar 09 03:53:02 2016 +0000
@@ -1,147 +1,150 @@
 //DMX geschreven door de koning zelve, Ayrton Leyssens
 
-enum status 
+class DMX
 {
-    BREAK,
-    MAB, 
-    STARTCODE, 
-    DATA
+    public:
+        DMX(PinName pin);
+        ~DMX();
+        
+        void V_SetBreak(uint32_t I32_BreakTime);
+        void V_SetMAB(uint32_t I32_MABTime);
+        void V_SetSC(uint32_t I32_StartCodeTime);
+        void V_SetBitTime(uint32_t I32_BitTime);
+        void V_SetData(uint8_t I8_Data[512]);
+        void V_SendDMX();
+        
+        
+    private:
+        DigitalOut _pin;
+        uint32_t I32_m_BreakTime;
+        uint32_t I32_m_MABTime;
+        uint32_t I32_m_StartCodeTime;
+        uint32_t I32_m_BitTime;
+        uint32_t I32_m_ChannelCounter;
+        uint32_t I32_m_BitCounter;
+        uint8_t I8_m_Data[512];
+        void V_SendMAB();
+        void V_SendSC();
+        void V_SendData();
+        Timeout t;
 };
-status DMX_MSG = BREAK;
 
-Timeout DMX_TIMING;
+DMX::DMX(PinName pin) : _pin(pin) 
+{
+    this->I32_m_BreakTime = 88;
+    this->I32_m_MABTime = 8;
+    this->I32_m_StartCodeTime = 44;
+    this->I32_m_BitTime = 4;
+    this->I32_m_ChannelCounter = 0;
+    this->I32_m_BitCounter = 0;
+    uint32_t i;
+    for(i = 0; i < 512; i++)
+    {
+        this->I8_m_Data[i] = 0;
+    }
+    this->_pin = 0;   
+    return;
+}
 
-DigitalOut XLR1(p9);
-DigitalOut XLR2(p13);
-DigitalOut XLR3(p28);
+DMX::~DMX()
+{
+    delete[] &I32_m_BreakTime;
+    delete[] &I32_m_MABTime;
+    delete[] &I32_m_StartCodeTime;
+    delete[] &I32_m_BitTime;
+    delete[] &_pin;
+    delete[] &I8_m_Data;
+    return;
+}
 
-void V_DMX();
+void DMX::V_SendDMX()
+{
+    _pin = 0;
+    t.attach_us(this, &DMX::V_SendMAB, 88);
+}
+
+void DMX::V_SendMAB()
+{
+    _pin = 1;
+    t.detach();
+    t.attach_us(this, &DMX::V_SendSC, 8);
+}
 
-uint8_t I8_Teller =0;
-uint8_t I8_BitCounter = 0;
-uint32_t I32_ChannelCounter =0;
+void DMX::V_SendSC()
+{
+    _pin = 0;
+    t.detach();
+    t.attach_us(this, &DMX::V_SendData, 44);
+}
 
-void V_DMX()
+void DMX::V_SendData()
 {
-    switch(DMX_MSG)
+    if(I32_m_BitCounter == 0)
+    {
+        _pin = 0;
+        I32_m_BitCounter++;
+        t.detach();
+        t.attach_us(this, &DMX::V_SendData, 4);
+    }
+    else if(I32_m_BitCounter == 9 )
     {
-        case (BREAK):
+        _pin = 1;
+        I32_m_BitCounter = 0;
+        I32_m_ChannelCounter++;
+        t.detach();
+        t.attach_us(this, &DMX::V_SendData, 8);
+    }
+    else
+    {
+        if(I32_m_ChannelCounter < 511)
         {
-           if(I8_BitCounter < 22)
-            {
-                XLR1=0;
-                XLR2=0;
-                XLR3=0;
-                I8_BitCounter++;
-            }
-            else
-            {
-                DMX_MSG = MAB;
-                I8_BitCounter = 0;
-            }
-            break;
-        }
-        
-        case (MAB):
-        {
-            if(I8_BitCounter < 2)
-            {
-                XLR1=1;
-                XLR2=1;
-                XLR3=1;
-                I8_BitCounter++;
-            }
-            else
-            {
-                DMX_MSG = STARTCODE;
-                I8_BitCounter = 0;
-            }
-            break;
-        }
-        
-        case (STARTCODE):
-        {
-            if(I8_BitCounter < 11)
-            {
-                XLR1=0;
-                XLR2=0;
-                XLR3=0;
-                I8_BitCounter++;
-            }
-            else
+            if(I8_m_Data[I32_m_ChannelCounter] & 0x01 == 0x01)
             {
-                DMX_MSG = DATA;
-                I8_BitCounter = 0;
+                _pin = 1;
             }
-            break;
-        }
-           
-        case (DATA):
-        {
-            if(I32_ChannelCounter < 512)
+            else if(I8_m_Data[I32_m_ChannelCounter] & 0x01 == 0x00)
             {
-                if(I8_BitCounter < 1)
-                {
-                    XLR1=0;
-                    XLR2=0;
-                    XLR3=0;
-                }
-                else if (0 < I8_BitCounter < 9)
-                {
-                    //XLR1
-                    if (I8_Data1[I8_Teller] & 0x01 == 0x01)
-                    {
-                        XLR1 = 1;
-                    }
-                    else
-                    {
-                        XLR1 = 0;
-                    }
-                    I8_Data1[I8_Teller] = I8_Data1[I8_Teller] >> 1;                     //bitjes shiften
-                    
-                    //XLR2
-                    if (I8_Data2[I8_Teller] & 0x01 == 0x01)
-                    {
-                        XLR2 = 1;
-                    }
-                    else
-                    {
-                        XLR2 = 0;
-                    }
-                    I8_Data2[I8_Teller] = I8_Data2[I8_Teller] >> 1;                     //bitjes shiften
-                    
-                    //XLR3
-                    if (I8_Data3[I8_Teller] & 0x01 == 0x01)
-                    {
-                        XLR3 = 1;
-                    }
-                    else
-                    {
-                        XLR3 = 0;
-                    }
-                    I8_Data3[I8_Teller] = I8_Data3[I8_Teller] >> 1;                     //bitjes shiften
-                }
-                else if (8 < I8_BitCounter) 
-                {
-                    XLR1 = 1;
-                    XLR2 = 1;
-                    XLR3 = 1;
-                }
-                if(I8_BitCounter < 11)
-                {
-                    I8_BitCounter++;
-                }
-                else
-                {
-                    I8_BitCounter = 0;
-                }
+                _pin =0;
             }
-            else
-            {
-                I32_ChannelCounter = 0;
-                DMX_MSG = BREAK;
-            }
-            break;
+            I8_m_Data[I32_m_ChannelCounter] = I8_m_Data[I32_m_ChannelCounter] >> 1;
         }
+        else
+        {
+            I32_m_ChannelCounter = 0;
+            I32_m_BitCounter = 0;
+            DMX::V_SendDMX();
+        }
+        I32_m_BitCounter++;
+        t.detach();
+        t.attach_us(this, &DMX::V_SendData, 4);
     }
 }
+
+void DMX::V_SetBreak(uint32_t I32_BreakTime)
+{
+    I32_m_BreakTime = I32_BreakTime;
+}
+
+void DMX::V_SetMAB(uint32_t I32_MABTime)
+{
+    I32_m_MABTime = I32_MABTime;
+}
+
+void DMX::V_SetSC(uint32_t I32_StartCodeTime)
+{
+    I32_m_StartCodeTime = I32_StartCodeTime;
+}
+
+void DMX::V_SetBitTime(uint32_t I32_BitTime)
+{
+    I32_m_BitTime = I32_BitTime;
+}
+
+void DMX::V_SetData(uint8_t I8_Data[512])
+{
+    uint32_t i;
+    for(i = 0; i < 512; i++)
+    {
+        I8_m_Data[i] = I8_Data[i];
+    }
+}
--- a/Screen.h	Wed Mar 09 01:24:39 2016 +0000
+++ b/Screen.h	Wed Mar 09 03:53:02 2016 +0000
@@ -19,7 +19,6 @@
         uint32_t I32_m_Rij;
         uint32_t I32_m_Kolom;
         char *C_m_Tekst[];
-        
 };
 
 Screen::Screen()
--- a/main.cpp	Wed Mar 09 01:24:39 2016 +0000
+++ b/main.cpp	Wed Mar 09 03:53:02 2016 +0000
@@ -1,12 +1,14 @@
 #include "main.h"
 
+DMX XLR1(p9);
 
 int main() 
 {
-    DMX_TIMING.attach_us(&V_DMX, 4);
+    XLR1.V_SendDMX();
+    
     
-    Screen *LCD;
-    LCD = new Screen;
+    /*Screen *LCD;
+    LCD = new Screen;*/
     //.....
     
 }
--- a/main.h	Wed Mar 09 01:24:39 2016 +0000
+++ b/main.h	Wed Mar 09 03:53:02 2016 +0000
@@ -7,20 +7,12 @@
 #include "stdint.h"
 
 #define DMX_CHANNELS 512
-
-uint8_t I8_Data1[DMX_CHANNELS];
-uint8_t I8_Data2[DMX_CHANNELS];
-uint8_t I8_Data3[DMX_CHANNELS];
-
  
 #include "DMX.h"
 #include "ArtNet.h"
 #include "Screen.h"
 
 
-/*void V_Powerup();
-void V_ShowSTDMenuScreen();*/
-
 #endif