Rev 631 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 631 | Rev 636 | ||
|---|---|---|---|
| Line 54... | Line 54... | ||
| 54 | 54 | ||
| 55 | void send_dimensions(void); |
55 | void send_dimensions(void); |
| 56 | void rotenc(void); |
56 | void rotenc(void); |
| 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 | 60 | ||
| 60 | uint32_t timeBase = 0; |
61 | uint32_t timeBase = 0; |
| 61 | uint16_t timerVar= 0; |
- | |
| 62 | uint8_t alarmTimer = 0; |
- | |
| 63 | 62 | ||
| 64 | char lcdBuffer[5]; |
63 | char lcdBuffer[5]; |
| - | 64 | ||
| - | 65 | //Struct for countdown |
|
| - | 66 | typedef struct |
|
| - | 67 | { |
|
| - | 68 | uint16_t timerCnt; |
|
| - | 69 | uint8_t alarmTimer; |
|
| - | 70 | uint16_t timerMax; |
|
| - | 71 | } countDown; |
|
| - | 72 | ||
| - | 73 | countDown countTimer1; |
|
| - | 74 | ||
| 65 | 75 | ||
| 66 | // CAN message reception callback |
76 | // CAN message reception callback |
| 67 | // This function runs with interrupts disabled, keep it as short as possible |
77 | // This function runs with interrupts disabled, keep it as short as possible |
| 68 | void can_receive(Can_Message_t *msg){ |
78 | void can_receive(Can_Message_t *msg){ |
| 69 | if(!rxMsgFull){ |
79 | if(!rxMsgFull){ |
| Line 129... | Line 139... | ||
| 129 | // FIXME skicka app startad |
139 | // FIXME skicka app startad |
| 130 | BIOS_CanCallback = &can_receive; |
140 | BIOS_CanCallback = &can_receive; |
| 131 | 141 | ||
| 132 | lcd_init( LCD_DISP_ON ); |
142 | lcd_init( LCD_DISP_ON ); |
| 133 | lcd_clrscr(); |
143 | lcd_clrscr(); |
| 134 | lcd_puts(" |
144 | lcd_puts("CanEggWatch\n"); |
| 135 | 145 | ||
| 136 | send_dimensions(); |
146 | send_dimensions(); |
| 137 | lcd_puts("CAN Connected!\n"); |
147 | lcd_puts("CAN Connected!\n"); |
| - | 148 | ||
| - | 149 | lcd_clrscr(); |
|
| - | 150 | ||
| 138 | 151 | ||
| 139 | /* main loop */ |
152 | /* main loop */ |
| 140 | while(1){ |
153 | while(1){ |
| 141 | 154 | ||
| 142 | 155 | ||
| 143 | if( Timebase_PassedTimeMillis(timeBase) >= 1000 ){ |
156 | if( Timebase_PassedTimeMillis(timeBase) >= 1000 ){ |
| 144 | if ( |
157 | if (countTimer1.timerCnt != 0){ |
| 145 |
|
158 | countTimer1.timerCnt--; |
| 146 |
|
159 | refreshDisplay(); |
| 147 | itoa(timerVar/60,lcdBuffer,10); |
- | |
| 148 | lcd_puts(lcdBuffer); |
- | |
| 149 | lcd_puts(":"); |
- | |
| 150 | itoa(timerVar%60,lcdBuffer,10); |
- | |
| 151 | lcd_puts(lcdBuffer); |
- | |
| 152 | } else { |
160 | } else { |
| 153 | if (alarmTimer != 0){ |
161 | if (countTimer1.alarmTimer != 0){ |
| 154 | alarm(); |
162 | alarm(); |
| 155 | alarmTimer--; |
163 | countTimer1.alarmTimer--; |
| 156 | } |
164 | } |
| 157 | } |
165 | } |
| 158 | timeBase = Timebase_CurrentTime(); |
166 | timeBase = Timebase_CurrentTime(); |
| 159 | } |
167 | } |
| 160 | 168 | ||
| 161 | 169 | ||
| 162 | /* check if any messages have been received */ |
170 | /* check if any messages have been received */ |
| 163 | if(rxMsgFull){ |
171 | if(rxMsgFull){ |
| 164 | //Throw it away. We don't use them yet. TODO: Support for time and remote setting. |
172 | //Throw it away. We don't use them yet. TODO: Support for time and remote setting. |
| 165 | rxMsgFull = 0; |
173 | rxMsgFull = 0; |
| 166 | } |
174 | } |
| 167 | } |
175 | } |
| 168 | } |
176 | } |
| 169 | 177 | ||
| 170 | void send_dimensions(){ |
178 | void send_dimensions(){ |
| 171 | Can_Message_t txMsg; |
179 | Can_Message_t txMsg; |
| 172 | 180 | ||
| 173 | txMsg.ExtendedFlag=1; |
181 | txMsg.ExtendedFlag=1; |
| Line 234... | Line 242... | ||
| 234 | 242 | ||
| 235 | void action(uint8_t type){ |
243 | void action(uint8_t type){ |
| 236 | //Let's do something with something! |
244 | //Let's do something with something! |
| 237 | lcd_clrscr(); |
245 | lcd_clrscr(); |
| 238 | if (type == LEFT){ |
246 | if (type == LEFT){ |
| 239 |
|
247 | countTimer1.timerCnt--; |
| 240 |
|
248 | refreshDisplay(); |
| 241 | itoa(timerVar/60,lcdBuffer,10); |
- | |
| 242 | lcd_puts(lcdBuffer); |
- | |
| 243 | lcd_puts(":"); |
- | |
| 244 | itoa(timerVar%60,lcdBuffer,10); |
- | |
| 245 | lcd_puts(lcdBuffer); |
- | |
| 246 | } |
249 | } |
| 247 | if (type == RIGHT){ |
250 | if (type == RIGHT){ |
| 248 |
|
251 | countTimer1.timerCnt++; |
| 249 | lcd_clrscr(); |
- | |
| 250 |
|
252 | if (countTimer1.timerCnt > countTimer1.timerMax){ |
| 251 |
|
253 | countTimer1.timerMax = countTimer1.timerCnt; |
| 252 |
|
254 | } |
| 253 | itoa(timerVar%60,lcdBuffer,10); |
- | |
| 254 |
|
255 | refreshDisplay(); |
| 255 | } |
256 | } |
| 256 | if (type == BUTTON_PUSH){ |
257 | if (type == BUTTON_PUSH){ |
| 257 | lcd_puts("Init!"); |
258 | lcd_puts("Init!"); |
| 258 | } |
259 | } |
| 259 | if (type == BUTTON_RELEASE){ |
260 | if (type == BUTTON_RELEASE){ |
| 260 | timeBase = Timebase_CurrentTime(); |
261 | timeBase = Timebase_CurrentTime(); |
| - | 262 | countTimer1.timerCnt = 10; |
|
| 261 |
|
263 | countTimer1.timerMax = 10; |
| 262 | alarmTimer = 1; |
264 | countTimer1.alarmTimer = 1; |
| - | 265 | refreshDisplay(); |
|
| 263 | } |
266 | } |
| 264 | } |
267 | } |
| 265 | 268 | ||
| 266 | void alarm(void){ |
269 | void alarm(void){ |
| 267 | lcd_puts("Riing!"); |
270 | lcd_puts("Riing!"); |
| - | 271 | } |
|
| - | 272 | ||
| - | 273 | void refreshDisplay(void){ |
|
| - | 274 | lcd_clrscr(); |
|
| - | 275 | itoa(countTimer1.timerCnt/60,lcdBuffer,10); |
|
| - | 276 | lcd_puts(lcdBuffer); |
|
| - | 277 | lcd_puts(":"); |
|
| - | 278 | itoa(countTimer1.timerCnt%60,lcdBuffer,10); |
|
| - | 279 | lcd_puts(lcdBuffer); |
|
| - | 280 | ||
| - | 281 | lcd_gotoxy(0,1); |
|
| - | 282 | lcdProgressBar(countTimer1.timerCnt,countTimer1.timerMax,16); |
|
| 268 | } |
283 | } |