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@28:4b327f1cb9cb, 2016-03-18 (annotated)
- Committer:
- Ayrton_L
- Date:
- Fri Mar 18 00:44:33 2016 +0000
- Revision:
- 28:4b327f1cb9cb
- Parent:
- 27:1bd34c90e0a9
- Child:
- 29:4a11f841dae1
DMX Update;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Ayrton_L | 6:d48f410e7a2d | 1 | #include "main.h" |
| Ayrton_L | 6:d48f410e7a2d | 2 | |
| Ayrton_L | 28:4b327f1cb9cb | 3 | |
| Ayrton_L | 20:bcaba3ecc235 | 4 | DMX XLR1(p9); |
| Ayrton_L | 28:4b327f1cb9cb | 5 | DMX XLR2(p13); |
| Ayrton_L | 28:4b327f1cb9cb | 6 | DMX XLR3(p28); |
| Ayrton_L | 28:4b327f1cb9cb | 7 | //ArtNet X; |
| Ayrton_L | 10:33faa2c71dad | 8 | |
| Ayrton_L | 28:4b327f1cb9cb | 9 | DigitalOut DMXled1(LED1); |
| Ayrton_L | 28:4b327f1cb9cb | 10 | DigitalOut DMXled2(LED2); |
| Ayrton_L | 28:4b327f1cb9cb | 11 | DigitalOut DMXled3(LED3); |
| Ayrton_L | 28:4b327f1cb9cb | 12 | DigitalOut MAINled(LED4); |
| Ayrton_L | 28:4b327f1cb9cb | 13 | Ethernet eth; |
| Ayrton_L | 28:4b327f1cb9cb | 14 | uint32_t I32_CheckHeader(char C_Header[7]); |
| Ayrton_L | 23:2ed8390eaf32 | 15 | |
| Ayrton_L | 23:2ed8390eaf32 | 16 | |
| Ayrton_L | 28:4b327f1cb9cb | 17 | |
| Ayrton_L | 28:4b327f1cb9cb | 18 | typedef struct { |
| Ayrton_L | 28:4b327f1cb9cb | 19 | uint32_t Universe[2]; |
| Ayrton_L | 28:4b327f1cb9cb | 20 | uint8_t I8_Values[511]; |
| Ayrton_L | 28:4b327f1cb9cb | 21 | }DMX_Data; |
| Ayrton_L | 28:4b327f1cb9cb | 22 | |
| Ayrton_L | 28:4b327f1cb9cb | 23 | void V_DMXThread1(void const *args) |
| Ayrton_L | 25:2f69b935060f | 24 | { |
| Ayrton_L | 28:4b327f1cb9cb | 25 | wait_ms(10); |
| Ayrton_L | 25:2f69b935060f | 26 | while(1) |
| Ayrton_L | 25:2f69b935060f | 27 | { |
| Ayrton_L | 25:2f69b935060f | 28 | XLR1.V_SendDMX(); |
| Ayrton_L | 28:4b327f1cb9cb | 29 | } |
| Ayrton_L | 28:4b327f1cb9cb | 30 | } |
| Ayrton_L | 28:4b327f1cb9cb | 31 | |
| Ayrton_L | 28:4b327f1cb9cb | 32 | void V_DMXThread2(void const *args) |
| Ayrton_L | 28:4b327f1cb9cb | 33 | { |
| Ayrton_L | 28:4b327f1cb9cb | 34 | wait_ms(15); |
| Ayrton_L | 28:4b327f1cb9cb | 35 | while(1) |
| Ayrton_L | 28:4b327f1cb9cb | 36 | { |
| Ayrton_L | 28:4b327f1cb9cb | 37 | XLR2.V_SendDMX(); |
| Ayrton_L | 28:4b327f1cb9cb | 38 | } |
| Ayrton_L | 28:4b327f1cb9cb | 39 | } |
| Ayrton_L | 28:4b327f1cb9cb | 40 | |
| Ayrton_L | 28:4b327f1cb9cb | 41 | void V_DMXThread3(void const *args) |
| Ayrton_L | 28:4b327f1cb9cb | 42 | { |
| Ayrton_L | 28:4b327f1cb9cb | 43 | |
| Ayrton_L | 28:4b327f1cb9cb | 44 | wait_ms(15); |
| Ayrton_L | 28:4b327f1cb9cb | 45 | while(1) |
| Ayrton_L | 28:4b327f1cb9cb | 46 | { |
| Ayrton_L | 28:4b327f1cb9cb | 47 | XLR3.V_SendDMX(); |
| Ayrton_L | 25:2f69b935060f | 48 | } |
| Ayrton_L | 25:2f69b935060f | 49 | } |
| Ayrton_L | 25:2f69b935060f | 50 | |
| Ayrton_L | 10:33faa2c71dad | 51 | int main() |
| Ayrton_L | 10:33faa2c71dad | 52 | { |
| Ayrton_L | 28:4b327f1cb9cb | 53 | DMXled1 = 0; |
| Ayrton_L | 28:4b327f1cb9cb | 54 | DMXled2 = 0; |
| Ayrton_L | 28:4b327f1cb9cb | 55 | DMXled3 = 0; |
| Ayrton_L | 28:4b327f1cb9cb | 56 | Thread T_DMX1(V_DMXThread1); |
| Ayrton_L | 28:4b327f1cb9cb | 57 | Thread T_DMX2(V_DMXThread2); |
| Ayrton_L | 28:4b327f1cb9cb | 58 | Thread T_DMX3(V_DMXThread3); |
| Ayrton_L | 28:4b327f1cb9cb | 59 | |
| Ayrton_L | 28:4b327f1cb9cb | 60 | char C_Buf[572]; |
| Ayrton_L | 28:4b327f1cb9cb | 61 | uint16_t I16_Universe; |
| Ayrton_L | 28:4b327f1cb9cb | 62 | while(1) |
| Ayrton_L | 25:2f69b935060f | 63 | { |
| Ayrton_L | 28:4b327f1cb9cb | 64 | int size = eth.receive(); |
| Ayrton_L | 28:4b327f1cb9cb | 65 | if(size > 0) { |
| Ayrton_L | 28:4b327f1cb9cb | 66 | eth.read(C_Buf, size); |
| Ayrton_L | 28:4b327f1cb9cb | 67 | 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 | 68 | { |
| Ayrton_L | 28:4b327f1cb9cb | 69 | char C_ID[7]; |
| Ayrton_L | 28:4b327f1cb9cb | 70 | memcpy(C_ID, &C_Buf[42], 7); |
| Ayrton_L | 28:4b327f1cb9cb | 71 | if(I32_CheckHeader(C_ID) == 0) //Art-Net Header checken |
| Ayrton_L | 28:4b327f1cb9cb | 72 | { |
| Ayrton_L | 28:4b327f1cb9cb | 73 | if(C_Buf[50] == 0x00 and C_Buf[51]== 0x50) //OPcode checken |
| Ayrton_L | 28:4b327f1cb9cb | 74 | { |
| Ayrton_L | 28:4b327f1cb9cb | 75 | if(C_Buf[52] == 0x00 and C_Buf[53]== 0x0E) //Protocol Versie (14) checken |
| Ayrton_L | 28:4b327f1cb9cb | 76 | { |
| Ayrton_L | 28:4b327f1cb9cb | 77 | // 56/57 = universe |
| Ayrton_L | 28:4b327f1cb9cb | 78 | I16_Universe = C_Buf[56]; |
| Ayrton_L | 28:4b327f1cb9cb | 79 | I16_Universe = I16_Universe << 8; |
| Ayrton_L | 28:4b327f1cb9cb | 80 | I16_Universe = I16_Universe & 0xFF00; |
| Ayrton_L | 28:4b327f1cb9cb | 81 | I16_Universe = I16_Universe + C_Buf[57]; |
| Ayrton_L | 28:4b327f1cb9cb | 82 | |
| Ayrton_L | 28:4b327f1cb9cb | 83 | Settings S; |
| Ayrton_L | 28:4b327f1cb9cb | 84 | uint8_t I8_Values[512]; |
| Ayrton_L | 28:4b327f1cb9cb | 85 | |
| Ayrton_L | 28:4b327f1cb9cb | 86 | if(I16_Universe == S.I32_GetUniverse(1)) |
| Ayrton_L | 28:4b327f1cb9cb | 87 | { |
| Ayrton_L | 28:4b327f1cb9cb | 88 | MAINled = 1; |
| Ayrton_L | 28:4b327f1cb9cb | 89 | if(C_Buf[60] == 255) |
| Ayrton_L | 28:4b327f1cb9cb | 90 | { |
| Ayrton_L | 28:4b327f1cb9cb | 91 | if(DMXled2 == 1) |
| Ayrton_L | 28:4b327f1cb9cb | 92 | { |
| Ayrton_L | 28:4b327f1cb9cb | 93 | DMXled2 = 0; |
| Ayrton_L | 28:4b327f1cb9cb | 94 | DMXled1 = 1; |
| Ayrton_L | 28:4b327f1cb9cb | 95 | } |
| Ayrton_L | 28:4b327f1cb9cb | 96 | else |
| Ayrton_L | 28:4b327f1cb9cb | 97 | { |
| Ayrton_L | 28:4b327f1cb9cb | 98 | DMXled1 = 0; |
| Ayrton_L | 28:4b327f1cb9cb | 99 | DMXled2 = 1; |
| Ayrton_L | 28:4b327f1cb9cb | 100 | } |
| Ayrton_L | 28:4b327f1cb9cb | 101 | } |
| Ayrton_L | 28:4b327f1cb9cb | 102 | memcpy(I8_Values, &C_Buf[60], 512); |
| Ayrton_L | 28:4b327f1cb9cb | 103 | XLR1.V_SetData(I8_Values); |
| Ayrton_L | 28:4b327f1cb9cb | 104 | } |
| Ayrton_L | 28:4b327f1cb9cb | 105 | else if(I16_Universe == S.I32_GetUniverse(2)) |
| Ayrton_L | 28:4b327f1cb9cb | 106 | { |
| Ayrton_L | 28:4b327f1cb9cb | 107 | memcpy(I8_Values, &C_Buf[60], 512); |
| Ayrton_L | 28:4b327f1cb9cb | 108 | XLR2.V_SetData(I8_Values); |
| Ayrton_L | 28:4b327f1cb9cb | 109 | } |
| Ayrton_L | 28:4b327f1cb9cb | 110 | else if(I16_Universe == S.I32_GetUniverse(3)) |
| Ayrton_L | 28:4b327f1cb9cb | 111 | { |
| Ayrton_L | 28:4b327f1cb9cb | 112 | memcpy(I8_Values, &C_Buf[60], 512); |
| Ayrton_L | 28:4b327f1cb9cb | 113 | XLR3.V_SetData(I8_Values); |
| Ayrton_L | 28:4b327f1cb9cb | 114 | } |
| Ayrton_L | 28:4b327f1cb9cb | 115 | } |
| Ayrton_L | 28:4b327f1cb9cb | 116 | } |
| Ayrton_L | 28:4b327f1cb9cb | 117 | } |
| Ayrton_L | 28:4b327f1cb9cb | 118 | } |
| Ayrton_L | 28:4b327f1cb9cb | 119 | } |
| Ayrton_L | 28:4b327f1cb9cb | 120 | wait_ms(1); |
| Ayrton_L | 25:2f69b935060f | 121 | } |
| Ayrton_L | 18:8deebaf09ba3 | 122 | } |
| Ayrton_L | 18:8deebaf09ba3 | 123 | |
| Ayrton_L | 28:4b327f1cb9cb | 124 | uint32_t I32_CheckHeader(char C_Header[6]) |
| Ayrton_L | 28:4b327f1cb9cb | 125 | { |
| Ayrton_L | 28:4b327f1cb9cb | 126 | if(C_Header[0] == 'A') |
| Ayrton_L | 28:4b327f1cb9cb | 127 | { |
| Ayrton_L | 28:4b327f1cb9cb | 128 | if(C_Header[1] == 'r') |
| Ayrton_L | 28:4b327f1cb9cb | 129 | { |
| Ayrton_L | 28:4b327f1cb9cb | 130 | if(C_Header[2] == 't') |
| Ayrton_L | 28:4b327f1cb9cb | 131 | { |
| Ayrton_L | 28:4b327f1cb9cb | 132 | if(C_Header[3] == '-') |
| Ayrton_L | 28:4b327f1cb9cb | 133 | { |
| Ayrton_L | 28:4b327f1cb9cb | 134 | if(C_Header[4] == 'N') |
| Ayrton_L | 28:4b327f1cb9cb | 135 | { |
| Ayrton_L | 28:4b327f1cb9cb | 136 | if(C_Header[5] == 'e') |
| Ayrton_L | 28:4b327f1cb9cb | 137 | { |
| Ayrton_L | 28:4b327f1cb9cb | 138 | if(C_Header[6] == 't') |
| Ayrton_L | 28:4b327f1cb9cb | 139 | { |
| Ayrton_L | 28:4b327f1cb9cb | 140 | return 0; |
| Ayrton_L | 28:4b327f1cb9cb | 141 | } |
| Ayrton_L | 28:4b327f1cb9cb | 142 | else |
| Ayrton_L | 28:4b327f1cb9cb | 143 | { |
| Ayrton_L | 28:4b327f1cb9cb | 144 | return 1; |
| Ayrton_L | 28:4b327f1cb9cb | 145 | } |
| Ayrton_L | 28:4b327f1cb9cb | 146 | } |
| Ayrton_L | 28:4b327f1cb9cb | 147 | else |
| Ayrton_L | 28:4b327f1cb9cb | 148 | { |
| Ayrton_L | 28:4b327f1cb9cb | 149 | return 1; |
| Ayrton_L | 28:4b327f1cb9cb | 150 | } |
| Ayrton_L | 28:4b327f1cb9cb | 151 | } |
| Ayrton_L | 28:4b327f1cb9cb | 152 | else |
| Ayrton_L | 28:4b327f1cb9cb | 153 | { |
| Ayrton_L | 28:4b327f1cb9cb | 154 | return 1; |
| Ayrton_L | 28:4b327f1cb9cb | 155 | } |
| Ayrton_L | 28:4b327f1cb9cb | 156 | } |
| Ayrton_L | 28:4b327f1cb9cb | 157 | else |
| Ayrton_L | 28:4b327f1cb9cb | 158 | { |
| Ayrton_L | 28:4b327f1cb9cb | 159 | return 1; |
| Ayrton_L | 28:4b327f1cb9cb | 160 | } |
| Ayrton_L | 28:4b327f1cb9cb | 161 | } |
| Ayrton_L | 28:4b327f1cb9cb | 162 | else |
| Ayrton_L | 28:4b327f1cb9cb | 163 | { |
| Ayrton_L | 28:4b327f1cb9cb | 164 | return 1; |
| Ayrton_L | 28:4b327f1cb9cb | 165 | } |
| Ayrton_L | 28:4b327f1cb9cb | 166 | } |
| Ayrton_L | 28:4b327f1cb9cb | 167 | else |
| Ayrton_L | 28:4b327f1cb9cb | 168 | { |
| Ayrton_L | 28:4b327f1cb9cb | 169 | return 1; |
| Ayrton_L | 28:4b327f1cb9cb | 170 | } |
| Ayrton_L | 28:4b327f1cb9cb | 171 | } |
| Ayrton_L | 28:4b327f1cb9cb | 172 | else |
| Ayrton_L | 28:4b327f1cb9cb | 173 | { |
| Ayrton_L | 28:4b327f1cb9cb | 174 | return 1; |
| Ayrton_L | 28:4b327f1cb9cb | 175 | } |
| Ayrton_L | 28:4b327f1cb9cb | 176 | } |
| Ayrton_L | 28:4b327f1cb9cb | 177 | |
| Ayrton_L | 28:4b327f1cb9cb | 178 |