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.
Dependencies: mbed DMX TextLCD mbed-rtos
main.cpp
00001 #include "main.h" 00002 00003 void V_EnableRotary() 00004 { 00005 RightTwist.rise(&V_Right); 00006 LeftTwist.rise(&V_Left); 00007 } 00008 00009 void V_GeneralTxt(uint32_t I32_Line) 00010 { 00011 Sc.V_Clear(); 00012 char *C_Line=new char[S_Menu[I32_Line].size()+1]; 00013 C_Line[S_Menu[I32_Line].size()] = 0; 00014 memcpy(C_Line, S_Menu[I32_Line].c_str(), S_Menu[I32_Line].size()); 00015 V_WriteTxt(6, 0, C_Line); 00016 } 00017 00018 void V_WriteTxt(uint32_t I32_Kolom, uint32_t I32_Rij, char * C_Tekst) 00019 { 00020 Sc.V_SetRij(I32_Rij); 00021 Sc.V_SetKolom(I32_Kolom); 00022 Sc.V_SetTekst(C_Tekst); 00023 Sc.V_Printit(); 00024 } 00025 00026 void V_InterruptMenu() 00027 { 00028 if(S.B_GetOK() == false) 00029 { 00030 S.V_SetOK(true); 00031 } 00032 else 00033 { 00034 S.V_SetMenu(true); 00035 } 00036 } 00037 00038 void V_MenuThread(void const *args) 00039 { 00040 PushButton.rise(&V_InterruptMenu); //interrupt bij push op button, rising edge 00041 RightTwist.rise(&V_Right); 00042 LeftTwist.rise(&V_Left); 00043 00044 while(1) 00045 { 00046 uint32_t I32_Line; 00047 I32_Line - S.I32_GetLine(); 00048 if(S.I32_GetOldLine() == I32_Line) 00049 { 00050 if(S.B_GetOK() == true) 00051 { 00052 switch (I32_Line) 00053 { 00054 case 0: 00055 { 00056 Sc.V_Clear(); 00057 V_WriteTxt(6, 1, FIRMWARE); 00058 } 00059 case 1: 00060 { 00061 Sc.V_Clear(); 00062 V_WriteTxt(6, 1, "Output 1:"); 00063 V_WriteTxt(6, 1, "Universe"); 00064 while (S.B_GetMenu() == false); 00065 { 00066 int32_t I32_InputCounter; 00067 if(S.I32_GetLine() <= I32_Line - 1) 00068 { 00069 I32_InputCounter--; 00070 if(I32_InputCounter == -1) 00071 { 00072 I32_InputCounter = 255; 00073 } 00074 } 00075 else if(S.I32_GetLine() >= I32_Line + 1) 00076 { 00077 I32_InputCounter++; 00078 if(I32_InputCounter == 256) 00079 { 00080 I32_InputCounter = 0; 00081 } 00082 } 00083 char C_Buffer [33]; 00084 sprintf (C_Buffer, "%d", I32_InputCounter); //itoa werkt niet, dus sprintf om conversie te maken 00085 V_WriteTxt(9, 2, C_Buffer); 00086 S.V_SetOutput1(I32_InputCounter); 00087 S.V_SetLine(I32_Line); 00088 } 00089 } 00090 case 2: 00091 { 00092 Sc.V_Clear(); 00093 V_WriteTxt(6, 1, "Output 2:"); 00094 V_WriteTxt(6, 1, "Universe"); 00095 while (S.B_GetMenu() == false); 00096 { 00097 int32_t I32_InputCounter; 00098 if(S.I32_GetLine() <= I32_Line - 1) 00099 { 00100 I32_InputCounter--; 00101 if(I32_InputCounter == -1) 00102 { 00103 I32_InputCounter = 255; 00104 } 00105 } 00106 else if(S.I32_GetLine() >= I32_Line + 1) 00107 { 00108 I32_InputCounter++; 00109 if(I32_InputCounter == 256) 00110 { 00111 I32_InputCounter = 0; 00112 } 00113 } 00114 char C_Buffer [33]; 00115 sprintf (C_Buffer, "%d", I32_InputCounter); 00116 V_WriteTxt(9, 2, C_Buffer); 00117 S.V_SetOutput2(I32_InputCounter); 00118 S.V_SetLine(I32_Line); 00119 } 00120 } 00121 case 3: 00122 { 00123 Sc.V_Clear(); 00124 V_WriteTxt(6, 1, "Output 3:"); 00125 V_WriteTxt(6, 1, "Universe"); 00126 while (S.B_GetMenu() == false); 00127 { 00128 int32_t I32_InputCounter; 00129 if(S.I32_GetLine() == I32_Line - 1) 00130 { 00131 I32_InputCounter--; 00132 if(I32_InputCounter <= -1) 00133 { 00134 I32_InputCounter = 255; 00135 } 00136 } 00137 else if(S.I32_GetLine() == I32_Line + 1) 00138 { 00139 I32_InputCounter++; 00140 if(I32_InputCounter >= 256) 00141 { 00142 I32_InputCounter = 0; 00143 } 00144 } 00145 char C_Buffer [33]; 00146 sprintf (C_Buffer, "%d", I32_InputCounter); 00147 V_WriteTxt(9, 2, C_Buffer); 00148 S.V_SetOutput3(I32_InputCounter); 00149 S.V_SetLine(I32_Line); 00150 } 00151 } 00152 default: 00153 { 00154 Error4 = !Error4; 00155 wait_ms(500); 00156 } 00157 } 00158 } 00159 } 00160 else 00161 { 00162 V_GeneralTxt(I32_Line); 00163 } 00164 } 00165 } 00166 00167 int main() 00168 { 00169 // RightTwist.mode(PullUp); 00170 // LeftTwist.mode(PullUp); 00171 00172 Thread T_Menu(V_MenuThread); 00173 00174 XLR1.V_Start(); 00175 XLR2.V_Start(); 00176 XLR3.V_Start(); 00177 00178 char C_Buf[572]; 00179 uint16_t I16_Universe; 00180 while(1) 00181 { 00182 int size = eth.receive(); 00183 if(size > 0) 00184 { 00185 Error2 = 1; 00186 eth.read(C_Buf, size); 00187 Error8 = 1; 00188 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 00189 { 00190 Error1 = 1; 00191 char C_ID[7]; 00192 memcpy(C_ID, &C_Buf[42], 7); 00193 if(I32_CheckHeader(C_ID) == 0) 00194 { //Art-Net Header checken 00195 if(C_Buf[50] == 0x00 and C_Buf[51]== 0x50) 00196 { //OPcode checken 00197 if(C_Buf[52] == 0x00 and C_Buf[53]== 0x0E) 00198 { //Protocol Versie (14) checken 00199 // 56/57 = universe 00200 I16_Universe = C_Buf[56]; 00201 I16_Universe = I16_Universe << 8; 00202 I16_Universe = I16_Universe & 0xFF00; 00203 I16_Universe = I16_Universe + C_Buf[57]; 00204 00205 uint8_t I8_Values[511]; 00206 uint32_t I32_Teller; 00207 Error4 = 1; 00208 if(I16_Universe == S.I32_GetOutput1()) 00209 { 00210 memcpy(I8_Values, &C_Buf[60], 512); 00211 Error8 = 1; 00212 for (I32_Teller = 1; I32_Teller < 512; I32_Teller ++) 00213 { 00214 XLR1.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); 00215 XLR2.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); 00216 } 00217 } 00218 if(I16_Universe == S.I32_GetOutput2()) 00219 { 00220 memcpy(I8_Values, &C_Buf[60], 512); 00221 for (I32_Teller = 0; I32_Teller < 512; I32_Teller ++) 00222 { 00223 XLR2.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); 00224 } 00225 } 00226 if(I16_Universe == S.I32_GetOutput3()) 00227 { 00228 memcpy(I8_Values, &C_Buf[60], 512); 00229 for (I32_Teller = 0; I32_Teller < 512; I32_Teller ++) 00230 { 00231 XLR3.V_PutData(I32_Teller, I8_Values[I32_Teller -1]); 00232 } 00233 } //einde universes 00234 } //einde protocol 00235 }//einde OPCODE 00236 }//Einde Artnet 00237 }//Einde Poort checken 00238 }//einde if(size... 00239 }//einde while 00240 }//einde main 00241 00242 void V_Reset() 00243 { 00244 Sc.V_Clear(); 00245 delete &S; 00246 } 00247 00248 void V_Right() 00249 { 00250 V_DisableRotary(); 00251 if(S.B_GetLeft() == true) 00252 { 00253 uint32_t I32_Count = S.I32_GetLine(); 00254 if(I32_Count == 4) 00255 { 00256 I32_Count = 0; 00257 } 00258 else 00259 { 00260 I32_Count++; 00261 } 00262 S.V_SetLine(I32_Count); 00263 } 00264 else 00265 { 00266 S.V_SetRight(true); 00267 } 00268 00269 S.V_SetLeft(false); 00270 } 00271 00272 void V_Left() 00273 { 00274 V_DisableRotary(); 00275 if(S.B_GetRight() == true) 00276 { 00277 uint32_t I32_Count = S.I32_GetLine(); 00278 if(I32_Count == 0) 00279 { 00280 I32_Count = 4; 00281 } 00282 else 00283 { 00284 I32_Count--; 00285 } 00286 S.V_SetLine(I32_Count); 00287 } 00288 else 00289 { 00290 S.V_SetLeft(true); 00291 } 00292 S.V_SetRight(false); 00293 } 00294 00295 void V_DisableRotary() 00296 { 00297 RightTwist.rise(NULL); 00298 LeftTwist.rise(NULL); 00299 EnableRotary.attach_us(&V_EnableRotary, 5000); //na 5 ms intterupts terug enablen 00300 } 00301 00302 uint32_t I32_CheckHeader(char C_Header[6]) 00303 { 00304 if(C_Header[0] == 'A') 00305 { 00306 if(C_Header[1] == 'r') 00307 { 00308 if(C_Header[2] == 't') 00309 { 00310 if(C_Header[3] == '-') 00311 { 00312 if(C_Header[4] == 'N') 00313 { 00314 if(C_Header[5] == 'e') 00315 { 00316 if(C_Header[6] == 't') 00317 { 00318 return 0; 00319 } 00320 else 00321 { 00322 return 1; 00323 } 00324 } 00325 else 00326 { 00327 return 1; 00328 } 00329 } 00330 else 00331 { 00332 return 1; 00333 } 00334 } 00335 else 00336 { 00337 return 1; 00338 } 00339 } 00340 else 00341 { 00342 return 1; 00343 } 00344 } 00345 else 00346 { 00347 return 1; 00348 } 00349 } 00350 else 00351 { 00352 return 1; 00353 } 00354 }
Generated on Fri Jul 15 2022 01:17:23 by
1.7.2