Rev 636 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 636 | Rev 653 | ||
|---|---|---|---|
| Line 57... | Line 57... | ||
| 57 | void action(uint8_t type); |
57 | void action(uint8_t type); |
| 58 | void alarm(void); |
58 | void alarm(void); |
| 59 | void refreshDisplay(void); |
59 | void refreshDisplay(void); |
| 60 | 60 | ||
| 61 | uint32_t timeBase = 0; |
61 | uint32_t timeBase = 0; |
| - | 62 | ||
| - | 63 | uint32_t timeBase_turnspeed = 0; |
|
| 62 | 64 | ||
| 63 | char lcdBuffer[5]; |
65 | char lcdBuffer[5]; |
| 64 | 66 | ||
| 65 | //Struct for countdown |
67 | //Struct for countdown |
| 66 | typedef struct |
68 | typedef struct |
| Line 149... | Line 151... | ||
| 149 | lcd_clrscr(); |
151 | lcd_clrscr(); |
| 150 | 152 | ||
| 151 | 153 | ||
| 152 | /* main loop */ |
154 | /* main loop */ |
| 153 | while(1){ |
155 | while(1){ |
| 154 | 156 | ||
| 155 | 157 | ||
| 156 | if( Timebase_PassedTimeMillis(timeBase) >= 1000 ){ |
158 | if( Timebase_PassedTimeMillis(timeBase) >= 1000 ){ |
| 157 | if (countTimer1.timerCnt != 0){ |
159 | if (countTimer1.timerCnt != 0){ |
| 158 | countTimer1.timerCnt--; |
160 | countTimer1.timerCnt--; |
| 159 | refreshDisplay(); |
161 | refreshDisplay(); |
| 160 | } else { |
162 | } else { |
| Line 219... | Line 221... | ||
| 219 | if( rot_data==0 || rot_data==3 ){ // Are both signals high or low? |
221 | if( rot_data==0 || rot_data==3 ){ // Are both signals high or low? |
| 220 | if( rot_data==0 && rot_laststate!=rot_data ){ // Are both signals low? In that case we are finished with one turn and should print out the direction it went. |
222 | if( rot_data==0 && rot_laststate!=rot_data ){ // Are both signals low? In that case we are finished with one turn and should print out the direction it went. |
| 221 | if( rot_lastdir&0x01 ){ |
223 | if( rot_lastdir&0x01 ){ |
| 222 | // Moving right |
224 | // Moving right |
| 223 | txMsg.Data.bytes[0]=RIGHT; |
225 | txMsg.Data.bytes[0]=RIGHT; |
| 224 | txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1; |
226 | txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1; |
| 225 | txMsg.DataLength=2; |
227 | txMsg.DataLength=2; |
| 226 | BIOS_CanSend(&txMsg); |
228 | BIOS_CanSend(&txMsg); |
| 227 | action(RIGHT); |
229 | action(RIGHT); |
| 228 | }else{ |
230 | }else{ |
| 229 | // Moving left |
231 | // Moving left |
| 230 | txMsg.Data.bytes[0]=LEFT; |
232 | txMsg.Data.bytes[0]=LEFT; |
| 231 | txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1; |
233 | txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1; |
| 232 | txMsg.DataLength=2; |
234 | txMsg.DataLength=2; |
| 233 | BIOS_CanSend(&txMsg); |
235 | BIOS_CanSend(&txMsg); |
| 234 | action(LEFT); |
236 | action(LEFT); |
| 235 | } |
237 | } |
| 236 | } |
238 | } |
| 237 | rot_laststate = rot_data; |
239 | rot_laststate = rot_data; |
| 238 | } else { // No, only one of the signals are high. We can use this to find out what direction we are moving. |
240 | } else { // No, only one of the signals are high. We can use this to find out what direction we are moving. |
| 239 | rot_lastdir = rot_data; |
241 | rot_lastdir = rot_data; |
| 240 | } |
242 | } |
| 241 | } |
243 | } |
| 242 | 244 | ||
| 243 | void action(uint8_t type){ |
245 | void action(uint8_t type){ |
| 244 | //Let's do something with something! |
246 | //Let's do something with something! |
| 245 | lcd_clrscr(); |
247 | lcd_clrscr(); |
| 246 | if (type == LEFT){ |
248 | if (type == LEFT){ |
| 247 | countTimer1.timerCnt- |
249 | countTimer1.timerCnt = countTimer1.timerCnt - 10; |
| 248 | refreshDisplay(); |
250 | refreshDisplay(); |
| 249 | } |
251 | } |
| 250 | if (type == RIGHT){ |
252 | if (type == RIGHT){ |
| 251 | countTimer1.timerCnt+ |
253 | countTimer1.timerCnt = countTimer1.timerCnt + 10; |
| 252 | if (countTimer1.timerCnt > countTimer1.timerMax){ |
254 | if (countTimer1.timerCnt > countTimer1.timerMax){ |
| 253 | countTimer1.timerMax = countTimer1.timerCnt; |
255 | countTimer1.timerMax = countTimer1.timerCnt; |
| 254 | } |
256 | } |
| 255 | refreshDisplay(); |
257 | refreshDisplay(); |
| 256 | } |
258 | } |