Rev 304 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 304 | Rev 305 | ||
|---|---|---|---|
| Line 37... | Line 37... | ||
| 37 | 37 | ||
| 38 | /*----------------------------------------------------------------------------- |
38 | /*----------------------------------------------------------------------------- |
| 39 | * Programs! This will most likely be improooved, but I have to start somewhere. |
39 | * Programs! This will most likely be improooved, but I have to start somewhere. |
| 40 | *---------------------------------------------------------------------------*/ |
40 | *---------------------------------------------------------------------------*/ |
| 41 | 41 | ||
| - | 42 | //Special combinations that means something special |
|
| - | 43 | //The combinations are useless for lighting anyway |
|
| - | 44 | //So we might as well use them! |
|
| 42 | //0x00, 0x00, 0x00, 0x00 means end of |
45 | //0x00, 0x00, 0x00, 0x00 means end of program, keep looping it |
| - | 46 | //0x00, 0x00, 0x00, 0x01 means end of program, halt |
|
| 43 | 47 | ||
| 44 | Color pgm1[] PROGMEM = { |
48 | Color pgm1[] PROGMEM = { |
| 45 | {0xff,0x00,0x00,0x00}, |
49 | {0xff,0x00,0x00,0x00}, |
| 46 | {0xff,0xff,0x00,0x00}, |
50 | {0xff,0xff,0x00,0x00}, |
| 47 | {0x00,0xff,0x00,0x00}, |
51 | {0x00,0xff,0x00,0x00}, |
| Line 67... | Line 71... | ||
| 67 | /*----------------------------------------------------------------------------- |
71 | /*----------------------------------------------------------------------------- |
| 68 | * Variables |
72 | * Variables |
| 69 | *---------------------------------------------------------------------------*/ |
73 | *---------------------------------------------------------------------------*/ |
| 70 | uint32_t timeStamp; //TimeStamp to keep track of time |
74 | uint32_t timeStamp; //TimeStamp to keep track of time |
| 71 | uint32_t dimStamp; //Timestamp to keep track of dimmer changes |
75 | uint32_t dimStamp; //Timestamp to keep track of dimmer changes |
| 72 | - | ||
| 73 | uint32_t tempStamp; //Timestamp to keep track of temp things during development |
- | |
| 74 | uint8_t temp; |
- | |
| 75 | 76 | ||
| 76 | Color currColor; //Current color |
77 | Color currColor; //Current color |
| 77 | Color destColor; //Destination color |
78 | Color destColor; //Destination color |
| 78 | 79 | ||
| 79 | uint16_t fadeSpeed; //Fadingspeed. 16bit for reaaaally slow fading. Sets the speed of colorchange. |
80 | uint16_t fadeSpeed; //Fadingspeed. 16bit for reaaaally slow fading. Sets the speed of colorchange. |
| 80 | uint8_t dimSpeed; //Dimmer speed. Sets the speed of intensitychange. |
81 | uint8_t dimSpeed; //Dimmer speed. Sets the speed of intensitychange. |
| 81 | 82 | ||
| 82 | uint8_t |
83 | uint8_t currProgram; //This variable keeps track of what program is currently running. |
| 83 | uint8_t programstate; //This variable keeps track of where in a program we currently are. Will probably be removed later on. |
- | |
| 84 | 84 | ||
| 85 | /*---------------------------------------------------------------------------- |
85 | /*---------------------------------------------------------------------------- |
| 86 | * Functions |
86 | * Functions |
| 87 | * -------------------------------------------------------------------------*/ |
87 | * -------------------------------------------------------------------------*/ |
| 88 | void updateLED(); |
88 | void updateLED(); |
| Line 128... | Line 128... | ||
| 128 | reformatRGB(0x00,0xff,0x00,1); |
128 | reformatRGB(0x00,0xff,0x00,1); |
| 129 | destColor.Intens = 100; |
129 | destColor.Intens = 100; |
| 130 | currColor = destColor; |
130 | currColor = destColor; |
| 131 | 131 | ||
| 132 | //Just temporary for now, they keep track of some kind of demo-program. |
132 | //Just temporary for now, they keep track of some kind of demo-program. |
| 133 |
|
133 | currProgram = 1; |
| 134 | temp = 1; |
- | |
| 135 | uint16_t temp_adress = pgm_read_word(&programs[ |
134 | uint16_t temp_adress = pgm_read_word(&programs[currProgram-1]); //Get adress for program 0 |
| 136 | 135 | ||
| 137 | 136 | ||
| 138 | sei(); |
137 | sei(); |
| 139 | 138 | ||
| 140 | /* main loop */ |
139 | /* main loop */ |
| 141 | while (1) { |
140 | while (1) { |
| 142 | /* service the CAN routines */ |
141 | /* service the CAN routines */ |
| 143 | Can_Service(); |
142 | Can_Service(); |
| 144 | 143 | ||
| 145 | /* Time to fade color? */ |
144 | /* Time to fade color? */ |
| 146 | if (Timebase_PassedTimeMillis(timeStamp) >= fadeSpeed) { |
145 | if (Timebase_PassedTimeMillis(timeStamp) >= fadeSpeed) { |
| 147 | fade(&currColor.R, &destColor.R); |
146 | fade(&currColor.R, &destColor.R); |
| 148 | fade(&currColor.G, &destColor.G); |
147 | fade(&currColor.G, &destColor.G); |
| 149 | fade(&currColor.B, &destColor.B); |
148 | fade(&currColor.B, &destColor.B); |
| Line 160... | Line 159... | ||
| 160 | updateLED(); |
159 | updateLED(); |
| 161 | } |
160 | } |
| 162 | 161 | ||
| 163 | 162 | ||
| 164 | /* Program management */ |
163 | /* Program management */ |
| 165 | if ( |
164 | if (currProgram != 0){ //Check if a program is currently running |
| - | 165 | if ((currColor.R == destColor.R)&(currColor.G == destColor.G)&(currColor.B == destColor.B)&(currColor.Intens == destColor.Intens)){//Is the current sequence finished? |
|
| 166 | / |
166 | //Now we have to check if the program is finished and if we should loop |
| - | 167 | if ((pgm_read_byte(temp_adress)==0)&(pgm_read_byte(temp_adress+1)==0)&(pgm_read_byte(temp_adress+2)==0)){ |
|
| - | 168 | //The program has ended! Shall we loop it? |
|
| - | 169 | if (pgm_read_byte(temp_adress+3)==0){ |
|
| 167 | / |
170 | //Yes, let's loop it |
| - | 171 | temp_adress = pgm_read_word(&programs[currProgram-1]); |
|
| 168 |
|
172 | } else { |
| - | 173 | //No, halt! |
|
| - | 174 | currProgram = 0; |
|
| 169 | } |
175 | } |
| 170 | - | ||
| 171 |
|
176 | } else { |
| 172 |
|
177 | //The program has not ended, let's get the next RGB-triplet! |
| 173 | tempStamp = Timebase_CurrentTime(); |
- | |
| 174 | reformatRGB(pgm_read_byte(temp_adress),pgm_read_byte(temp_adress + 1),pgm_read_byte(temp_adress + 2),0); |
178 | reformatRGB(pgm_read_byte(temp_adress),pgm_read_byte(temp_adress + 1),pgm_read_byte(temp_adress + 2),0); |
| 175 | temp_adress = temp_adress + 4; |
179 | temp_adress = temp_adress + 4; |
| 176 | } |
180 | } |
| - | 181 | } |
|
| 177 | 182 | } |
|
| 178 | 183 | ||
| 179 | /* check if any messages have been received */ |
184 | /* check if any messages have been received */ |
| 180 | /* A lot of remote control crap going on here now for testing */ |
185 | /* A lot of remote control crap going on here now for testing */ |
| 181 | while (Can_Receive(&rxMsg) == CAN_OK) { |
186 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| 182 | if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x20)){ |
187 | if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x20)){ |
| 183 | program |
188 | //program = 1; |
| 184 | fadeSpeed |
189 | //fadeSpeed = 0; |
| 185 | } |
190 | } |
| 186 | 191 | ||
| 187 | if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x21)){ |
192 | if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x21)){ |
| 188 | program |
193 | //program = 2; |
| 189 | fadeSpeed |
194 | //fadeSpeed = 0; |
| 190 | } |
195 | } |
| 191 | } |
196 | } |
| 192 | 197 | ||
| 193 | } |
198 | } |
| 194 | 199 | ||
| Line 214... | Line 219... | ||
| 214 | //Bara för debugcrap |
219 | //Bara för debugcrap |
| 215 | Can_Message_t txMsg; |
220 | Can_Message_t txMsg; |
| 216 | txMsg.Id = 0x55; |
221 | txMsg.Id = 0x55; |
| 217 | txMsg.RemoteFlag = 0; |
222 | txMsg.RemoteFlag = 0; |
| 218 | txMsg.ExtendedFlag = 1; |
223 | txMsg.ExtendedFlag = 1; |
| 219 | txMsg.DataLength = |
224 | txMsg.DataLength = 8; |
| 220 | txMsg.Data.bytes[0] = currColor.R |
225 | txMsg.Data.bytes[0] = currColor.R; |
| 221 | txMsg.Data.bytes[1] = currColor.G |
226 | txMsg.Data.bytes[1] = currColor.G; |
| 222 | txMsg.Data.bytes[2] = currColor.B |
227 | txMsg.Data.bytes[2] = currColor.B; |
| 223 | txMsg.Data.bytes[3] = currColor.Intens; |
228 | txMsg.Data.bytes[3] = currColor.Intens; |
| - | 229 | ||
| 224 | Can_Send(&txMsg); |
230 | Can_Send(&txMsg); |
| 225 | } |
231 | } |
| 226 | 232 | ||
| 227 | 233 | ||
| 228 | 234 | ||