Artnet to DMX
Dependencies: mbed DMX TextLCD mbed-rtos
Art-NET to DMX converter.
Read Art-NET and process the data so it can be send by 3 XLR3 outputs for DMX. With a 4x20 display you can choose some options. For example what universe you would like on what output.
This is a project we make as our final project of our 2nd year of university. We study Electronics-ICT / Embedded ICT.
We chose for this amazing platform (MBED LPC1768) because it has al the interfaces and pins we need.
Revision 36:dba7a0094213, committed 2016-05-23
- Comitter:
- Ayrton_L
- Date:
- Mon May 23 17:39:39 2016 +0000
- Parent:
- 35:23656910be93
- Commit message:
- Menu fixed
Changed in this revision
--- a/Screen.h Mon May 23 14:26:36 2016 +0000 +++ b/Screen.h Mon May 23 17:39:39 2016 +0000 @@ -1,7 +1,7 @@ #include "string.h" #include "stdint.h" #include "TextLCD.h" -TextLCD lcd(p21, p26, p22, p23, p24, p25, TextLCD::LCD20x4); +TextLCD lcd(p25, p24, p23, p22, p21, p26, TextLCD::LCD20x4); class Screen {
--- a/Settings.h Mon May 23 14:26:36 2016 +0000 +++ b/Settings.h Mon May 23 17:39:39 2016 +0000 @@ -7,49 +7,49 @@ Settings(); ~Settings(); - void V_SetInterrupt(bool B_Interrupt); void V_SetLeft(bool B_Left); void V_SetRight(bool B_Right); void V_SetLine(uint32_t I32_Line); - void V_SetInMenu(bool B_Menu); + void V_SetOldLine(uint32_t I32_OldLine); void V_SetOK(bool B_OK); - void V_SetCounter(uint32_t I32_LineCounter); + //void V_SetCounter(uint32_t I32_LineCounter); void V_SetOutput1(uint32_t I32_Universe); void V_SetOutput2(uint32_t I32_Universe); void V_SetOutput3(uint32_t I32_Universe); + void V_SetMenu(bool B_Menu); - bool B_GetInterrupt(); bool B_GetLeft(); bool B_GetRight(); + bool B_GetOK(); bool B_GetMenu(); - bool B_GetOK(); uint32_t I32_GetLine(); uint32_t I32_GetOutput1(); uint32_t I32_GetOutput2(); uint32_t I32_GetOutput3(); + uint32_t I32_GetOldLine(); private: uint32_t I32_m_Output1; uint32_t I32_m_Output2; uint32_t I32_m_Output3; uint32_t I32_m_Line; - bool B_m_Interrupt; + uint32_t I32_m_OldLine; bool B_m_Left; bool B_m_Right; + bool B_m_OK; bool B_m_Menu; - bool B_m_OK; }; #endif Settings::Settings() { - B_m_Interrupt = false; B_m_Left = false; B_m_Right = false; + B_m_OK = false; B_m_Menu = false; - B_m_OK = false; I32_m_Line = 0; + I32_m_OldLine = 0; I32_m_Output1 = 0; I32_m_Output2 = 0; I32_m_Output3 = 0; @@ -57,15 +57,25 @@ Settings::~Settings() { - delete &B_m_Interrupt; delete &B_m_Right; delete &B_m_Left; delete &B_m_OK; - delete &B_m_Menu; + delete &B_m_Menu; delete &I32_m_Line; delete &I32_m_Output1; delete &I32_m_Output2; delete &I32_m_Output3; + delete &I32_m_OldLine; +} + +void Settings::V_SetLine(uint32_t I32_Line) +{ + I32_m_Line = I32_Line; +} + +void Settings::V_SetMenu(bool B_Menu) +{ + B_m_Menu = B_Menu; } void Settings::V_SetOutput1(uint32_t I32_Universe) @@ -78,6 +88,11 @@ I32_m_Output2 = I32_Universe; } +void Settings::V_SetOldLine(uint32_t I32_OldLine) +{ + I32_m_OldLine = I32_OldLine; +} + void Settings::V_SetOutput3(uint32_t I32_Universe) { I32_m_Output3 = I32_Universe; @@ -88,21 +103,6 @@ B_m_OK = B_OK; } -void Settings::V_SetInMenu(bool B_Menu) -{ - B_m_Menu = B_Menu; -} - -void Settings::V_SetCounter(uint32_t I32_LineCounter) -{ - I32_m_Line = I32_LineCounter; -} - -void Settings::V_SetInterrupt(bool B_Interrupt) -{ - this->B_m_Interrupt = B_Interrupt; -} - void Settings::V_SetLeft(bool B_Left) { B_m_Left = B_Left; @@ -118,26 +118,21 @@ return B_m_OK; } +bool Settings::B_GetLeft() +{ + return B_m_Left; +} + bool Settings::B_GetMenu() { return B_m_Menu; } -bool Settings::B_GetLeft() -{ - return B_m_Left; -} - bool Settings::B_GetRight() { return B_m_Right; } -bool Settings::B_GetInterrupt() -{ - return B_m_Interrupt; -} - uint32_t Settings::I32_GetLine() { return I32_m_Line; @@ -156,4 +151,9 @@ uint32_t Settings::I32_GetOutput3() { return I32_m_Output3; +} + +uint32_t Settings::I32_GetOldLine() +{ + return I32_m_OldLine; } \ No newline at end of file
--- a/main.cpp Mon May 23 14:26:36 2016 +0000 +++ b/main.cpp Mon May 23 17:39:39 2016 +0000 @@ -6,18 +6,170 @@ LeftTwist.rise(&V_Left); } +void V_GeneralTxt(uint32_t I32_Line) +{ + Sc.V_Clear(); + char *C_Line=new char[S_Menu[I32_Line].size()+1]; + C_Line[S_Menu[I32_Line].size()] = 0; + memcpy(C_Line, S_Menu[I32_Line].c_str(), S_Menu[I32_Line].size()); + V_WriteTxt(6, 0, C_Line); +} + +void V_WriteTxt(uint32_t I32_Kolom, uint32_t I32_Rij, char * C_Tekst) +{ + Sc.V_SetRij(I32_Rij); + Sc.V_SetKolom(I32_Kolom); + Sc.V_SetTekst(C_Tekst); + Sc.V_Printit(); +} + void V_InterruptMenu() { - //Error2 = 1; - //Error4 = 1; - S.V_SetInterrupt(true); + if(S.B_GetOK() == false) + { + S.V_SetOK(true); + } + else + { + S.V_SetMenu(true); + } +} + +void V_MenuThread(void const *args) +{ + PushButton.rise(&V_InterruptMenu); //interrupt bij push op button, rising edge + RightTwist.rise(&V_Right); + LeftTwist.rise(&V_Left); + + while(1) + { + uint32_t I32_Line; + I32_Line - S.I32_GetLine(); + if(S.I32_GetOldLine() == I32_Line) + { + if(S.B_GetOK() == true) + { + switch (I32_Line) + { + case 0: + { + Sc.V_Clear(); + V_WriteTxt(6, 1, FIRMWARE); + } + case 1: + { + Sc.V_Clear(); + V_WriteTxt(6, 1, "Output 1:"); + V_WriteTxt(6, 1, "Universe"); + while (S.B_GetMenu() == false); + { + int32_t I32_InputCounter; + if(S.I32_GetLine() <= I32_Line - 1) + { + I32_InputCounter--; + if(I32_InputCounter == -1) + { + I32_InputCounter = 255; + } + } + else if(S.I32_GetLine() >= I32_Line + 1) + { + I32_InputCounter++; + if(I32_InputCounter == 256) + { + I32_InputCounter = 0; + } + } + char C_Buffer [33]; + sprintf (C_Buffer, "%d", I32_InputCounter); //itoa werkt niet, dus sprintf om conversie te maken + V_WriteTxt(9, 2, C_Buffer); + S.V_SetOutput1(I32_InputCounter); + S.V_SetLine(I32_Line); + } + } + case 2: + { + Sc.V_Clear(); + V_WriteTxt(6, 1, "Output 2:"); + V_WriteTxt(6, 1, "Universe"); + while (S.B_GetMenu() == false); + { + int32_t I32_InputCounter; + if(S.I32_GetLine() <= I32_Line - 1) + { + I32_InputCounter--; + if(I32_InputCounter == -1) + { + I32_InputCounter = 255; + } + } + else if(S.I32_GetLine() >= I32_Line + 1) + { + I32_InputCounter++; + if(I32_InputCounter == 256) + { + I32_InputCounter = 0; + } + } + char C_Buffer [33]; + sprintf (C_Buffer, "%d", I32_InputCounter); + V_WriteTxt(9, 2, C_Buffer); + S.V_SetOutput2(I32_InputCounter); + S.V_SetLine(I32_Line); + } + } + case 3: + { + Sc.V_Clear(); + V_WriteTxt(6, 1, "Output 3:"); + V_WriteTxt(6, 1, "Universe"); + while (S.B_GetMenu() == false); + { + int32_t I32_InputCounter; + if(S.I32_GetLine() == I32_Line - 1) + { + I32_InputCounter--; + if(I32_InputCounter <= -1) + { + I32_InputCounter = 255; + } + } + else if(S.I32_GetLine() == I32_Line + 1) + { + I32_InputCounter++; + if(I32_InputCounter >= 256) + { + I32_InputCounter = 0; + } + } + char C_Buffer [33]; + sprintf (C_Buffer, "%d", I32_InputCounter); + V_WriteTxt(9, 2, C_Buffer); + S.V_SetOutput3(I32_InputCounter); + S.V_SetLine(I32_Line); + } + } + default: + { + Error4 = !Error4; + wait_ms(500); + } + } + } + } + else + { + V_GeneralTxt(I32_Line); + } + } } int main() { - RightTwist.mode(PullUp); - LeftTwist.mode(PullUp); - PushButton.rise(&V_InterruptMenu); //interrupt bij push op button, rising edge +// RightTwist.mode(PullUp); +// LeftTwist.mode(PullUp); + + Thread T_Menu(V_MenuThread); XLR1.V_Start(); XLR2.V_Start(); @@ -27,84 +179,63 @@ uint16_t I16_Universe; while(1) { - if(S.B_GetInterrupt() == false) + int size = eth.receive(); + if(size > 0) { - int size = eth.receive(); - if(size > 0) + Error2 = 1; + eth.read(C_Buf, size); + Error8 = 1; + if(C_Buf[34] == 0x19 and C_Buf[35] == 0x36 and C_Buf[36] == 0x19 and C_Buf[37] == 0x36) //Poort checken (6465 = 0x1936 // deel van udp protocol { - Error2 = 1; - eth.read(C_Buf, size); - Error8 = 1; - if(C_Buf[34] == 0x19 and C_Buf[35] == 0x36 and C_Buf[36] == 0x19 and C_Buf[37] == 0x36) //Poort checken (6465 = 0x1936 // deel van udp protocol - { - Error1 = 1; - char C_ID[7]; - memcpy(C_ID, &C_Buf[42], 7); - if(I32_CheckHeader(C_ID) == 0) //Art-Net Header checken - { - if(C_Buf[50] == 0x00 and C_Buf[51]== 0x50) //OPcode checken - { - if(C_Buf[52] == 0x00 and C_Buf[53]== 0x0E) //Protocol Versie (14) checken + Error1 = 1; + char C_ID[7]; + memcpy(C_ID, &C_Buf[42], 7); + if(I32_CheckHeader(C_ID) == 0) + { //Art-Net Header checken + if(C_Buf[50] == 0x00 and C_Buf[51]== 0x50) + { //OPcode checken + if(C_Buf[52] == 0x00 and C_Buf[53]== 0x0E) + { //Protocol Versie (14) checken + // 56/57 = universe + I16_Universe = C_Buf[56]; + I16_Universe = I16_Universe << 8; + I16_Universe = I16_Universe & 0xFF00; + I16_Universe = I16_Universe + C_Buf[57]; + + uint8_t I8_Values[511]; + uint32_t I32_Teller; + Error4 = 1; + if(I16_Universe == S.I32_GetOutput1()) { - // 56/57 = universe - I16_Universe = C_Buf[56]; - I16_Universe = I16_Universe << 8; - I16_Universe = I16_Universe & 0xFF00; - I16_Universe = I16_Universe + C_Buf[57]; - - uint8_t I8_Values[511]; - uint32_t I32_Teller; - Error4 = 1; - if(I16_Universe == S.I32_GetOutput1()) - { - memcpy(I8_Values, &C_Buf[60], 512); - Error8 = 1; - for (I32_Teller = 1; I32_Teller < 512; I32_Teller ++) - { - XLR1.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); - } - } - else if(I16_Universe == S.I32_GetOutput2()) + memcpy(I8_Values, &C_Buf[60], 512); + Error8 = 1; + for (I32_Teller = 1; I32_Teller < 512; I32_Teller ++) { - memcpy(I8_Values, &C_Buf[60], 512); - for (I32_Teller = 0; I32_Teller < 512; I32_Teller ++) - { - XLR2.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); - } + XLR1.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); + XLR2.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); } - else if(I16_Universe == S.I32_GetOutput3()) + } + if(I16_Universe == S.I32_GetOutput2()) + { + memcpy(I8_Values, &C_Buf[60], 512); + for (I32_Teller = 0; I32_Teller < 512; I32_Teller ++) { - memcpy(I8_Values, &C_Buf[60], 512); - for (I32_Teller = 0; I32_Teller < 512; I32_Teller ++) - { - XLR3.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); - } - } //einde universes - } //einde protocol - }//einde OPCODE - }//Einde Artnet - }//Einde Poort checken - }//einde if(size... - //Error4 = 1; - }//wait_ms(1); //einde IF getinterrupt == false - else - { - XLR1.V_Stop(); //Geen nut, waarom dmx uitsturen als er geen Art-Net binnenkomt? - XLR2.V_Stop(); //idem - XLR3.V_Stop(); //idem - - S.V_SetInterrupt(false); - wait(1); - - RightTwist.rise(&V_Right); - LeftTwist.rise(&V_Left); - - V_DisplayMenu(); - - XLR1.V_Start(); //dmx terug starten - XLR2.V_Start(); - XLR3.V_Start(); - }//einde IF getinterrupt != false + XLR2.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); + } + } + if(I16_Universe == S.I32_GetOutput3()) + { + memcpy(I8_Values, &C_Buf[60], 512); + for (I32_Teller = 0; I32_Teller < 512; I32_Teller ++) + { + XLR3.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); + } + } //einde universes + } //einde protocol + }//einde OPCODE + }//Einde Artnet + }//Einde Poort checken + }//einde if(size... }//einde while }//einde main @@ -114,72 +245,13 @@ delete &S; } -uint32_t I32_GeneralTxt() -{ - Sc.V_Clear(); - uint32_t I32_Line; - I32_Line = S.I32_GetLine(); - char *C_Line=new char[S_Menu[I32_Line].size()+1]; - C_Line[S_Menu[I32_Line].size()] = 0; - memcpy(C_Line, S_Menu[I32_Line].c_str(), S_Menu[I32_Line].size()); - V_WriteTxt(6, 0, C_Line); - return I32_Line; -} - -void V_DisplayMenu() -{ - uint32_t I32_Line; - I32_Line = I32_GeneralTxt(); - switch(I32_Line) - { - case 0: - { - V_WriteTxt(6, 2, FIRMWARE); - break; - } - - case 1: - { - V_WriteTxt(6, 2, "Universe"); - break; - } - - case 2: - { - V_WriteTxt(6, 2, "Universe"); - break; - } - - case 3: - { - V_WriteTxt(6, 2, "Universe"); - break; - } - - default: - { - V_WriteTxt(6, 2, "Error"); - V_WriteTxt(6, 3, "Restart"); - break; - } - - } -} - -void V_WriteTxt(uint32_t I32_Kolom, uint32_t I32_Rij, char * C_Tekst) -{ - Sc.V_SetRij(I32_Rij); - Sc.V_SetKolom(I32_Kolom); - Sc.V_SetTekst(C_Tekst); - Sc.V_Printit(); -} - void V_Right() { + V_DisableRotary(); if(S.B_GetLeft() == true) { uint32_t I32_Count = S.I32_GetLine(); - if(I32_Count == 6) + if(I32_Count == 4) { I32_Count = 0; } @@ -187,13 +259,11 @@ { I32_Count++; } - S.V_SetCounter(I32_Count); - Error1 != Error1; + S.V_SetLine(I32_Count); } else { S.V_SetRight(true); - } S.V_SetLeft(false); @@ -201,19 +271,19 @@ void V_Left() { + V_DisableRotary(); if(S.B_GetRight() == true) { uint32_t I32_Count = S.I32_GetLine(); if(I32_Count == 0) { - I32_Count = 6; + I32_Count = 4; } else { I32_Count--; } - S.V_SetCounter(I32_Count); - Error8 != Error8; + S.V_SetLine(I32_Count); } else { @@ -226,7 +296,7 @@ { RightTwist.rise(NULL); LeftTwist.rise(NULL); - EnableRotary.attach(&V_EnableRotary, 0.01); // setup flipper to call flip after 2 seconds + EnableRotary.attach_us(&V_EnableRotary, 5000); //na 5 ms intterupts terug enablen } uint32_t I32_CheckHeader(char C_Header[6])
--- a/main.h Mon May 23 14:26:36 2016 +0000 +++ b/main.h Mon May 23 17:39:39 2016 +0000 @@ -13,7 +13,7 @@ #include "Screen.h" #define FIRMWARE "B-01-10" -const string S_Menu[] {"Firmware", "Output 1", "Output 2", "Output 3", "Save"}; +const string S_Menu[] {"Firmware", "Output 1", "Output 2", "Output 3"}; DMX XLR1(p9, p10); DMX XLR2(p13, p14); @@ -29,9 +29,9 @@ DigitalOut Error8(LED4); -InterruptIn PushButton(p5); -InterruptIn LeftTwist(p6); -InterruptIn RightTwist(p7); +InterruptIn PushButton(p8); +InterruptIn LeftTwist(p7); +InterruptIn RightTwist(p6); Timeout EnableRotary; @@ -45,11 +45,10 @@ void V_DisableRotary(); void V_WriteTxt(uint32_t I32_Kolom, uint32_t I32_Rij, char * C_Tekst); -uint32_t I32_GeneralTxt(); - -void V_SEND(); +void V_GeneralTxt(uint32_t I32_Line); #endif +