ProDevelopTeam#MasterRace / Mbed 2 deprecated ArtnetDMX

Dependencies:   mbed DMX TextLCD mbed-rtos

Committer:
Ayrton_L
Date:
Mon May 23 14:26:36 2016 +0000
Revision:
35:23656910be93
Parent:
34:fc85eeb84a93
Child:
36:dba7a0094213
latest stable

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ayrton_L 35:23656910be93 1 #include "main.h"
Ayrton_L 28:4b327f1cb9cb 2
Ayrton_L 34:fc85eeb84a93 3 void V_EnableRotary()
Ayrton_L 34:fc85eeb84a93 4 {
Ayrton_L 34:fc85eeb84a93 5 RightTwist.rise(&V_Right);
Ayrton_L 34:fc85eeb84a93 6 LeftTwist.rise(&V_Left);
Ayrton_L 34:fc85eeb84a93 7 }
Ayrton_L 34:fc85eeb84a93 8
Ayrton_L 29:4a11f841dae1 9 void V_InterruptMenu()
Ayrton_L 29:4a11f841dae1 10 {
Ayrton_L 35:23656910be93 11 //Error2 = 1;
Ayrton_L 35:23656910be93 12 //Error4 = 1;
Ayrton_L 29:4a11f841dae1 13 S.V_SetInterrupt(true);
Ayrton_L 29:4a11f841dae1 14 }
Ayrton_L 25:2f69b935060f 15
Ayrton_L 10:33faa2c71dad 16 int main()
Ayrton_L 10:33faa2c71dad 17 {
Ayrton_L 35:23656910be93 18 RightTwist.mode(PullUp);
Ayrton_L 35:23656910be93 19 LeftTwist.mode(PullUp);
Ayrton_L 30:51a4370a88bf 20 PushButton.rise(&V_InterruptMenu); //interrupt bij push op button, rising edge
Ayrton_L 35:23656910be93 21
Ayrton_L 35:23656910be93 22 XLR1.V_Start();
Ayrton_L 35:23656910be93 23 XLR2.V_Start();
Ayrton_L 35:23656910be93 24 XLR3.V_Start();
Ayrton_L 28:4b327f1cb9cb 25
Ayrton_L 28:4b327f1cb9cb 26 char C_Buf[572];
Ayrton_L 28:4b327f1cb9cb 27 uint16_t I16_Universe;
Ayrton_L 28:4b327f1cb9cb 28 while(1)
Ayrton_L 25:2f69b935060f 29 {
Ayrton_L 29:4a11f841dae1 30 if(S.B_GetInterrupt() == false)
Ayrton_L 29:4a11f841dae1 31 {
Ayrton_L 29:4a11f841dae1 32 int size = eth.receive();
Ayrton_L 35:23656910be93 33 if(size > 0)
Ayrton_L 35:23656910be93 34 {
Ayrton_L 35:23656910be93 35 Error2 = 1;
Ayrton_L 29:4a11f841dae1 36 eth.read(C_Buf, size);
Ayrton_L 35:23656910be93 37 Error8 = 1;
Ayrton_L 33:e0c7a6eeeedc 38 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
Ayrton_L 28:4b327f1cb9cb 39 {
Ayrton_L 35:23656910be93 40 Error1 = 1;
Ayrton_L 29:4a11f841dae1 41 char C_ID[7];
Ayrton_L 29:4a11f841dae1 42 memcpy(C_ID, &C_Buf[42], 7);
Ayrton_L 29:4a11f841dae1 43 if(I32_CheckHeader(C_ID) == 0) //Art-Net Header checken
Ayrton_L 28:4b327f1cb9cb 44 {
Ayrton_L 29:4a11f841dae1 45 if(C_Buf[50] == 0x00 and C_Buf[51]== 0x50) //OPcode checken
Ayrton_L 28:4b327f1cb9cb 46 {
Ayrton_L 29:4a11f841dae1 47 if(C_Buf[52] == 0x00 and C_Buf[53]== 0x0E) //Protocol Versie (14) checken
Ayrton_L 28:4b327f1cb9cb 48 {
Ayrton_L 29:4a11f841dae1 49 // 56/57 = universe
Ayrton_L 29:4a11f841dae1 50 I16_Universe = C_Buf[56];
Ayrton_L 29:4a11f841dae1 51 I16_Universe = I16_Universe << 8;
Ayrton_L 29:4a11f841dae1 52 I16_Universe = I16_Universe & 0xFF00;
Ayrton_L 29:4a11f841dae1 53 I16_Universe = I16_Universe + C_Buf[57];
Ayrton_L 29:4a11f841dae1 54
Ayrton_L 35:23656910be93 55 uint8_t I8_Values[511];
Ayrton_L 35:23656910be93 56 uint32_t I32_Teller;
Ayrton_L 35:23656910be93 57 Error4 = 1;
Ayrton_L 30:51a4370a88bf 58 if(I16_Universe == S.I32_GetOutput1())
Ayrton_L 29:4a11f841dae1 59 {
Ayrton_L 29:4a11f841dae1 60 memcpy(I8_Values, &C_Buf[60], 512);
Ayrton_L 35:23656910be93 61 Error8 = 1;
Ayrton_L 35:23656910be93 62 for (I32_Teller = 1; I32_Teller < 512; I32_Teller ++)
Ayrton_L 35:23656910be93 63 {
Ayrton_L 35:23656910be93 64 XLR1.V_PutData(I32_Teller, I8_Values[I32_Teller -1]);
Ayrton_L 35:23656910be93 65 }
Ayrton_L 29:4a11f841dae1 66 }
Ayrton_L 30:51a4370a88bf 67 else if(I16_Universe == S.I32_GetOutput2())
Ayrton_L 29:4a11f841dae1 68 {
Ayrton_L 29:4a11f841dae1 69 memcpy(I8_Values, &C_Buf[60], 512);
Ayrton_L 35:23656910be93 70 for (I32_Teller = 0; I32_Teller < 512; I32_Teller ++)
Ayrton_L 35:23656910be93 71 {
Ayrton_L 35:23656910be93 72 XLR2.V_PutData(I32_Teller, I8_Values[I32_Teller -1]);
Ayrton_L 35:23656910be93 73 }
Ayrton_L 29:4a11f841dae1 74 }
Ayrton_L 30:51a4370a88bf 75 else if(I16_Universe == S.I32_GetOutput3())
Ayrton_L 28:4b327f1cb9cb 76 {
Ayrton_L 29:4a11f841dae1 77 memcpy(I8_Values, &C_Buf[60], 512);
Ayrton_L 35:23656910be93 78 for (I32_Teller = 0; I32_Teller < 512; I32_Teller ++)
Ayrton_L 35:23656910be93 79 {
Ayrton_L 35:23656910be93 80 XLR3.V_PutData(I32_Teller, I8_Values[I32_Teller -1]);
Ayrton_L 35:23656910be93 81 }
Ayrton_L 29:4a11f841dae1 82 } //einde universes
Ayrton_L 29:4a11f841dae1 83 } //einde protocol
Ayrton_L 29:4a11f841dae1 84 }//einde OPCODE
Ayrton_L 29:4a11f841dae1 85 }//Einde Artnet
Ayrton_L 29:4a11f841dae1 86 }//Einde Poort checken
Ayrton_L 29:4a11f841dae1 87 }//einde if(size...
Ayrton_L 35:23656910be93 88 //Error4 = 1;
Ayrton_L 29:4a11f841dae1 89 }//wait_ms(1); //einde IF getinterrupt == false
Ayrton_L 29:4a11f841dae1 90 else
Ayrton_L 35:23656910be93 91 {
Ayrton_L 35:23656910be93 92 XLR1.V_Stop(); //Geen nut, waarom dmx uitsturen als er geen Art-Net binnenkomt?
Ayrton_L 35:23656910be93 93 XLR2.V_Stop(); //idem
Ayrton_L 35:23656910be93 94 XLR3.V_Stop(); //idem
Ayrton_L 29:4a11f841dae1 95
Ayrton_L 29:4a11f841dae1 96 S.V_SetInterrupt(false);
Ayrton_L 29:4a11f841dae1 97 wait(1);
Ayrton_L 29:4a11f841dae1 98
Ayrton_L 34:fc85eeb84a93 99 RightTwist.rise(&V_Right);
Ayrton_L 34:fc85eeb84a93 100 LeftTwist.rise(&V_Left);
Ayrton_L 34:fc85eeb84a93 101
Ayrton_L 30:51a4370a88bf 102 V_DisplayMenu();
Ayrton_L 29:4a11f841dae1 103
Ayrton_L 35:23656910be93 104 XLR1.V_Start(); //dmx terug starten
Ayrton_L 35:23656910be93 105 XLR2.V_Start();
Ayrton_L 35:23656910be93 106 XLR3.V_Start();
Ayrton_L 29:4a11f841dae1 107 }//einde IF getinterrupt != false
Ayrton_L 35:23656910be93 108 }//einde while
Ayrton_L 29:4a11f841dae1 109 }//einde main
Ayrton_L 29:4a11f841dae1 110
Ayrton_L 30:51a4370a88bf 111 void V_Reset()
Ayrton_L 29:4a11f841dae1 112 {
Ayrton_L 29:4a11f841dae1 113 Sc.V_Clear();
Ayrton_L 30:51a4370a88bf 114 delete &S;
Ayrton_L 29:4a11f841dae1 115 }
Ayrton_L 29:4a11f841dae1 116
Ayrton_L 33:e0c7a6eeeedc 117 uint32_t I32_GeneralTxt()
Ayrton_L 29:4a11f841dae1 118 {
Ayrton_L 33:e0c7a6eeeedc 119 Sc.V_Clear();
Ayrton_L 30:51a4370a88bf 120 uint32_t I32_Line;
Ayrton_L 30:51a4370a88bf 121 I32_Line = S.I32_GetLine();
Ayrton_L 30:51a4370a88bf 122 char *C_Line=new char[S_Menu[I32_Line].size()+1];
Ayrton_L 30:51a4370a88bf 123 C_Line[S_Menu[I32_Line].size()] = 0;
Ayrton_L 30:51a4370a88bf 124 memcpy(C_Line, S_Menu[I32_Line].c_str(), S_Menu[I32_Line].size());
Ayrton_L 33:e0c7a6eeeedc 125 V_WriteTxt(6, 0, C_Line);
Ayrton_L 33:e0c7a6eeeedc 126 return I32_Line;
Ayrton_L 33:e0c7a6eeeedc 127 }
Ayrton_L 33:e0c7a6eeeedc 128
Ayrton_L 33:e0c7a6eeeedc 129 void V_DisplayMenu()
Ayrton_L 33:e0c7a6eeeedc 130 {
Ayrton_L 33:e0c7a6eeeedc 131 uint32_t I32_Line;
Ayrton_L 33:e0c7a6eeeedc 132 I32_Line = I32_GeneralTxt();
Ayrton_L 33:e0c7a6eeeedc 133 switch(I32_Line)
Ayrton_L 33:e0c7a6eeeedc 134 {
Ayrton_L 33:e0c7a6eeeedc 135 case 0:
Ayrton_L 33:e0c7a6eeeedc 136 {
Ayrton_L 33:e0c7a6eeeedc 137 V_WriteTxt(6, 2, FIRMWARE);
Ayrton_L 33:e0c7a6eeeedc 138 break;
Ayrton_L 33:e0c7a6eeeedc 139 }
Ayrton_L 33:e0c7a6eeeedc 140
Ayrton_L 33:e0c7a6eeeedc 141 case 1:
Ayrton_L 33:e0c7a6eeeedc 142 {
Ayrton_L 35:23656910be93 143 V_WriteTxt(6, 2, "Universe");
Ayrton_L 33:e0c7a6eeeedc 144 break;
Ayrton_L 33:e0c7a6eeeedc 145 }
Ayrton_L 33:e0c7a6eeeedc 146
Ayrton_L 33:e0c7a6eeeedc 147 case 2:
Ayrton_L 33:e0c7a6eeeedc 148 {
Ayrton_L 35:23656910be93 149 V_WriteTxt(6, 2, "Universe");
Ayrton_L 33:e0c7a6eeeedc 150 break;
Ayrton_L 33:e0c7a6eeeedc 151 }
Ayrton_L 33:e0c7a6eeeedc 152
Ayrton_L 33:e0c7a6eeeedc 153 case 3:
Ayrton_L 33:e0c7a6eeeedc 154 {
Ayrton_L 35:23656910be93 155 V_WriteTxt(6, 2, "Universe");
Ayrton_L 33:e0c7a6eeeedc 156 break;
Ayrton_L 33:e0c7a6eeeedc 157 }
Ayrton_L 33:e0c7a6eeeedc 158
Ayrton_L 33:e0c7a6eeeedc 159 default:
Ayrton_L 33:e0c7a6eeeedc 160 {
Ayrton_L 35:23656910be93 161 V_WriteTxt(6, 2, "Error");
Ayrton_L 35:23656910be93 162 V_WriteTxt(6, 3, "Restart");
Ayrton_L 33:e0c7a6eeeedc 163 break;
Ayrton_L 33:e0c7a6eeeedc 164 }
Ayrton_L 33:e0c7a6eeeedc 165
Ayrton_L 33:e0c7a6eeeedc 166 }
Ayrton_L 29:4a11f841dae1 167 }
Ayrton_L 29:4a11f841dae1 168
Ayrton_L 33:e0c7a6eeeedc 169 void V_WriteTxt(uint32_t I32_Kolom, uint32_t I32_Rij, char * C_Tekst)
Ayrton_L 29:4a11f841dae1 170 {
Ayrton_L 33:e0c7a6eeeedc 171 Sc.V_SetRij(I32_Rij);
Ayrton_L 33:e0c7a6eeeedc 172 Sc.V_SetKolom(I32_Kolom);
Ayrton_L 33:e0c7a6eeeedc 173 Sc.V_SetTekst(C_Tekst);
Ayrton_L 33:e0c7a6eeeedc 174 Sc.V_Printit();
Ayrton_L 29:4a11f841dae1 175 }
Ayrton_L 29:4a11f841dae1 176
Ayrton_L 29:4a11f841dae1 177 void V_Right()
Ayrton_L 29:4a11f841dae1 178 {
Ayrton_L 29:4a11f841dae1 179 if(S.B_GetLeft() == true)
Ayrton_L 29:4a11f841dae1 180 {
Ayrton_L 31:f7f44632c3cd 181 uint32_t I32_Count = S.I32_GetLine();
Ayrton_L 34:fc85eeb84a93 182 if(I32_Count == 6)
Ayrton_L 31:f7f44632c3cd 183 {
Ayrton_L 31:f7f44632c3cd 184 I32_Count = 0;
Ayrton_L 31:f7f44632c3cd 185 }
Ayrton_L 31:f7f44632c3cd 186 else
Ayrton_L 31:f7f44632c3cd 187 {
Ayrton_L 31:f7f44632c3cd 188 I32_Count++;
Ayrton_L 31:f7f44632c3cd 189 }
Ayrton_L 31:f7f44632c3cd 190 S.V_SetCounter(I32_Count);
Ayrton_L 34:fc85eeb84a93 191 Error1 != Error1;
Ayrton_L 29:4a11f841dae1 192 }
Ayrton_L 29:4a11f841dae1 193 else
Ayrton_L 29:4a11f841dae1 194 {
Ayrton_L 29:4a11f841dae1 195 S.V_SetRight(true);
Ayrton_L 29:4a11f841dae1 196
Ayrton_L 29:4a11f841dae1 197 }
Ayrton_L 31:f7f44632c3cd 198
Ayrton_L 29:4a11f841dae1 199 S.V_SetLeft(false);
Ayrton_L 29:4a11f841dae1 200 }
Ayrton_L 29:4a11f841dae1 201
Ayrton_L 29:4a11f841dae1 202 void V_Left()
Ayrton_L 29:4a11f841dae1 203 {
Ayrton_L 29:4a11f841dae1 204 if(S.B_GetRight() == true)
Ayrton_L 29:4a11f841dae1 205 {
Ayrton_L 31:f7f44632c3cd 206 uint32_t I32_Count = S.I32_GetLine();
Ayrton_L 31:f7f44632c3cd 207 if(I32_Count == 0)
Ayrton_L 31:f7f44632c3cd 208 {
Ayrton_L 34:fc85eeb84a93 209 I32_Count = 6;
Ayrton_L 31:f7f44632c3cd 210 }
Ayrton_L 31:f7f44632c3cd 211 else
Ayrton_L 31:f7f44632c3cd 212 {
Ayrton_L 31:f7f44632c3cd 213 I32_Count--;
Ayrton_L 31:f7f44632c3cd 214 }
Ayrton_L 31:f7f44632c3cd 215 S.V_SetCounter(I32_Count);
Ayrton_L 34:fc85eeb84a93 216 Error8 != Error8;
Ayrton_L 29:4a11f841dae1 217 }
Ayrton_L 29:4a11f841dae1 218 else
Ayrton_L 29:4a11f841dae1 219 {
Ayrton_L 29:4a11f841dae1 220 S.V_SetLeft(true);
Ayrton_L 29:4a11f841dae1 221 }
Ayrton_L 29:4a11f841dae1 222 S.V_SetRight(false);
Ayrton_L 29:4a11f841dae1 223 }
Ayrton_L 29:4a11f841dae1 224
Ayrton_L 34:fc85eeb84a93 225 void V_DisableRotary()
Ayrton_L 34:fc85eeb84a93 226 {
Ayrton_L 34:fc85eeb84a93 227 RightTwist.rise(NULL);
Ayrton_L 34:fc85eeb84a93 228 LeftTwist.rise(NULL);
Ayrton_L 34:fc85eeb84a93 229 EnableRotary.attach(&V_EnableRotary, 0.01); // setup flipper to call flip after 2 seconds
Ayrton_L 34:fc85eeb84a93 230 }
Ayrton_L 34:fc85eeb84a93 231
Ayrton_L 28:4b327f1cb9cb 232 uint32_t I32_CheckHeader(char C_Header[6])
Ayrton_L 28:4b327f1cb9cb 233 {
Ayrton_L 28:4b327f1cb9cb 234 if(C_Header[0] == 'A')
Ayrton_L 28:4b327f1cb9cb 235 {
Ayrton_L 28:4b327f1cb9cb 236 if(C_Header[1] == 'r')
Ayrton_L 28:4b327f1cb9cb 237 {
Ayrton_L 28:4b327f1cb9cb 238 if(C_Header[2] == 't')
Ayrton_L 28:4b327f1cb9cb 239 {
Ayrton_L 28:4b327f1cb9cb 240 if(C_Header[3] == '-')
Ayrton_L 28:4b327f1cb9cb 241 {
Ayrton_L 28:4b327f1cb9cb 242 if(C_Header[4] == 'N')
Ayrton_L 28:4b327f1cb9cb 243 {
Ayrton_L 28:4b327f1cb9cb 244 if(C_Header[5] == 'e')
Ayrton_L 28:4b327f1cb9cb 245 {
Ayrton_L 28:4b327f1cb9cb 246 if(C_Header[6] == 't')
Ayrton_L 28:4b327f1cb9cb 247 {
Ayrton_L 28:4b327f1cb9cb 248 return 0;
Ayrton_L 28:4b327f1cb9cb 249 }
Ayrton_L 28:4b327f1cb9cb 250 else
Ayrton_L 28:4b327f1cb9cb 251 {
Ayrton_L 28:4b327f1cb9cb 252 return 1;
Ayrton_L 28:4b327f1cb9cb 253 }
Ayrton_L 28:4b327f1cb9cb 254 }
Ayrton_L 28:4b327f1cb9cb 255 else
Ayrton_L 28:4b327f1cb9cb 256 {
Ayrton_L 28:4b327f1cb9cb 257 return 1;
Ayrton_L 28:4b327f1cb9cb 258 }
Ayrton_L 28:4b327f1cb9cb 259 }
Ayrton_L 28:4b327f1cb9cb 260 else
Ayrton_L 28:4b327f1cb9cb 261 {
Ayrton_L 28:4b327f1cb9cb 262 return 1;
Ayrton_L 28:4b327f1cb9cb 263 }
Ayrton_L 28:4b327f1cb9cb 264 }
Ayrton_L 28:4b327f1cb9cb 265 else
Ayrton_L 28:4b327f1cb9cb 266 {
Ayrton_L 28:4b327f1cb9cb 267 return 1;
Ayrton_L 28:4b327f1cb9cb 268 }
Ayrton_L 28:4b327f1cb9cb 269 }
Ayrton_L 28:4b327f1cb9cb 270 else
Ayrton_L 28:4b327f1cb9cb 271 {
Ayrton_L 28:4b327f1cb9cb 272 return 1;
Ayrton_L 28:4b327f1cb9cb 273 }
Ayrton_L 28:4b327f1cb9cb 274 }
Ayrton_L 28:4b327f1cb9cb 275 else
Ayrton_L 28:4b327f1cb9cb 276 {
Ayrton_L 28:4b327f1cb9cb 277 return 1;
Ayrton_L 28:4b327f1cb9cb 278 }
Ayrton_L 28:4b327f1cb9cb 279 }
Ayrton_L 28:4b327f1cb9cb 280 else
Ayrton_L 28:4b327f1cb9cb 281 {
Ayrton_L 28:4b327f1cb9cb 282 return 1;
Ayrton_L 28:4b327f1cb9cb 283 }
Ayrton_L 28:4b327f1cb9cb 284 }