diff options
Diffstat (limited to 'firmware/drivers/lcd-player.c')
-rw-r--r-- | firmware/drivers/lcd-player.c | 183 |
1 files changed, 146 insertions, 37 deletions
diff --git a/firmware/drivers/lcd-player.c b/firmware/drivers/lcd-player.c index 64587b5319..54202a6f10 100644 --- a/firmware/drivers/lcd-player.c +++ b/firmware/drivers/lcd-player.c | |||
@@ -46,9 +46,16 @@ | |||
46 | #define LCD_CURSOR(x,y) ((char)(lcd_cram+((y)*16+(x)))) | 46 | #define LCD_CURSOR(x,y) ((char)(lcd_cram+((y)*16+(x)))) |
47 | #define LCD_ICON(i) ((char)(lcd_iram+i)) | 47 | #define LCD_ICON(i) ((char)(lcd_iram+i)) |
48 | 48 | ||
49 | #define SCROLLABLE_LINES 2 | ||
50 | |||
51 | #define SCROLL_MODE_OFF 0 | ||
52 | #define SCROLL_MODE_PAUSE 1 | ||
53 | #define SCROLL_MODE_RUN 2 | ||
54 | |||
49 | /*** generic code ***/ | 55 | /*** generic code ***/ |
50 | 56 | ||
51 | struct scrollinfo { | 57 | struct scrollinfo { |
58 | int mode; | ||
52 | char text[MAX_PATH]; | 59 | char text[MAX_PATH]; |
53 | char line[32]; | 60 | char line[32]; |
54 | int textlen; | 61 | int textlen; |
@@ -63,10 +70,10 @@ static char scroll_stack[DEFAULT_STACK_SIZE]; | |||
63 | static char scroll_name[] = "scroll"; | 70 | static char scroll_name[] = "scroll"; |
64 | static char scroll_speed = 8; /* updates per second */ | 71 | static char scroll_speed = 8; /* updates per second */ |
65 | static char scroll_spacing = 3; /* spaces between end and start of text */ | 72 | static char scroll_spacing = 3; /* spaces between end and start of text */ |
73 | static long scroll_start_tick; | ||
66 | 74 | ||
67 | 75 | ||
68 | static struct scrollinfo scroll; /* only one scroll line at the moment */ | 76 | static struct scrollinfo scroll[SCROLLABLE_LINES]; |
69 | static int scroll_count = 0; | ||
70 | 77 | ||
71 | static const unsigned char new_lcd_ascii[] = { | 78 | static const unsigned char new_lcd_ascii[] = { |
72 | 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, | 79 | 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, |
@@ -272,13 +279,26 @@ void lcd_init (void) | |||
272 | 279 | ||
273 | void lcd_puts_scroll(int x, int y, unsigned char* string ) | 280 | void lcd_puts_scroll(int x, int y, unsigned char* string ) |
274 | { | 281 | { |
275 | struct scrollinfo* s = &scroll; | 282 | struct scrollinfo* s; |
283 | int index; | ||
284 | |||
285 | scroll_start_tick = current_tick + HZ/2; | ||
286 | |||
287 | /* search for the next free entry */ | ||
288 | for (index = 0; index < SCROLLABLE_LINES; index++) { | ||
289 | s = &scroll[index]; | ||
290 | if (s->mode == SCROLL_MODE_OFF) { | ||
291 | break; | ||
292 | } | ||
293 | } | ||
294 | |||
276 | s->space = 11 - x; | 295 | s->space = 11 - x; |
277 | 296 | ||
278 | lcd_puts(x,y,string); | 297 | lcd_puts(x,y,string); |
279 | s->textlen = strlen(string); | 298 | s->textlen = strlen(string); |
280 | 299 | ||
281 | if ( s->textlen > s->space ) { | 300 | if ( s->textlen > s->space ) { |
301 | s->mode = SCROLL_MODE_RUN; | ||
282 | s->offset=s->space; | 302 | s->offset=s->space; |
283 | s->startx=x; | 303 | s->startx=x; |
284 | s->starty=y; | 304 | s->starty=y; |
@@ -289,31 +309,102 @@ void lcd_puts_scroll(int x, int y, unsigned char* string ) | |||
289 | s->space > (int)sizeof s->line ? | 309 | s->space > (int)sizeof s->line ? |
290 | (int)sizeof s->line : s->space ); | 310 | (int)sizeof s->line : s->space ); |
291 | s->line[sizeof s->line - 1] = 0; | 311 | s->line[sizeof s->line - 1] = 0; |
292 | scroll_count = 1; | ||
293 | } | 312 | } |
294 | } | 313 | } |
295 | 314 | ||
296 | |||
297 | void lcd_stop_scroll(void) | 315 | void lcd_stop_scroll(void) |
298 | { | 316 | { |
299 | if ( scroll_count ) { | 317 | struct scrollinfo* s; |
300 | struct scrollinfo* s = &scroll; | 318 | int index; |
301 | scroll_count = 0; | 319 | |
320 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { | ||
321 | s = &scroll[index]; | ||
322 | if ( s->mode == SCROLL_MODE_RUN || | ||
323 | s->mode == SCROLL_MODE_PAUSE ) { | ||
324 | /* restore scrolled row */ | ||
325 | lcd_puts(s->startx, s->starty, s->text); | ||
326 | s->mode = SCROLL_MODE_OFF; | ||
327 | } | ||
328 | } | ||
329 | |||
330 | lcd_update(); | ||
331 | } | ||
302 | 332 | ||
303 | /* restore scrolled row */ | 333 | void lcd_stop_scroll_line(int line) |
304 | lcd_puts(s->startx,s->starty,s->text); | 334 | { |
305 | lcd_update(); | 335 | struct scrollinfo* s; |
336 | int index; | ||
337 | |||
338 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { | ||
339 | s = &scroll[index]; | ||
340 | if ( s->startx == line && | ||
341 | ( s->mode == SCROLL_MODE_RUN || | ||
342 | s->mode == SCROLL_MODE_PAUSE )) { | ||
343 | /* restore scrolled row */ | ||
344 | lcd_puts(s->startx, s->starty, s->text); | ||
345 | s->mode = SCROLL_MODE_OFF; | ||
346 | } | ||
306 | } | 347 | } |
348 | |||
349 | lcd_update(); | ||
307 | } | 350 | } |
308 | 351 | ||
309 | void lcd_scroll_pause(void) | 352 | void lcd_scroll_pause(void) |
310 | { | 353 | { |
311 | scroll_count = 0; | 354 | struct scrollinfo* s; |
355 | int index; | ||
356 | |||
357 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { | ||
358 | s = &scroll[index]; | ||
359 | if ( s->mode == SCROLL_MODE_RUN ) { | ||
360 | s->mode = SCROLL_MODE_PAUSE; | ||
361 | } | ||
362 | } | ||
363 | } | ||
364 | |||
365 | void lcd_scroll_pause_line(int line) | ||
366 | { | ||
367 | struct scrollinfo* s; | ||
368 | int index; | ||
369 | |||
370 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { | ||
371 | s = &scroll[index]; | ||
372 | if ( s->startx == line && | ||
373 | s->mode == SCROLL_MODE_RUN ) { | ||
374 | s->mode = SCROLL_MODE_PAUSE; | ||
375 | } | ||
376 | } | ||
312 | } | 377 | } |
313 | 378 | ||
314 | void lcd_scroll_resume(void) | 379 | void lcd_scroll_resume(void) |
315 | { | 380 | { |
316 | scroll_count = 1; | 381 | struct scrollinfo* s; |
382 | int index; | ||
383 | |||
384 | scroll_start_tick = current_tick + HZ/2; | ||
385 | |||
386 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { | ||
387 | s = &scroll[index]; | ||
388 | if ( s->mode == SCROLL_MODE_PAUSE ) { | ||
389 | s->mode = SCROLL_MODE_RUN; | ||
390 | } | ||
391 | } | ||
392 | } | ||
393 | |||
394 | void lcd_scroll_resume_line(int line) | ||
395 | { | ||
396 | struct scrollinfo* s; | ||
397 | int index; | ||
398 | |||
399 | scroll_start_tick = current_tick + HZ/2; | ||
400 | |||
401 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { | ||
402 | s = &scroll[index]; | ||
403 | if ( s->startx == line && | ||
404 | s->mode == SCROLL_MODE_PAUSE ) { | ||
405 | s->mode = SCROLL_MODE_RUN; | ||
406 | } | ||
407 | } | ||
317 | } | 408 | } |
318 | 409 | ||
319 | void lcd_scroll_speed(int speed) | 410 | void lcd_scroll_speed(int speed) |
@@ -323,36 +414,54 @@ void lcd_scroll_speed(int speed) | |||
323 | 414 | ||
324 | static void scroll_thread(void) | 415 | static void scroll_thread(void) |
325 | { | 416 | { |
326 | struct scrollinfo* s = &scroll; | 417 | struct scrollinfo* s; |
418 | int index; | ||
419 | int i; | ||
420 | bool update; | ||
421 | |||
422 | /* initialize scroll struct array */ | ||
423 | for (index = 0; index < SCROLLABLE_LINES; index++) { | ||
424 | scroll[index].mode = SCROLL_MODE_OFF; | ||
425 | } | ||
426 | |||
427 | scroll_start_tick = current_tick; | ||
327 | 428 | ||
328 | while ( 1 ) { | 429 | while ( 1 ) { |
329 | if ( !scroll_count ) { | 430 | |
330 | yield(); | 431 | update = false; |
331 | continue; | 432 | |
332 | } | ||
333 | /* wait 0.5s before starting scroll */ | 433 | /* wait 0.5s before starting scroll */ |
334 | if ( scroll_count < scroll_speed/2 ) | 434 | if ( TIME_AFTER(current_tick, scroll_start_tick) ) { |
335 | scroll_count++; | 435 | |
336 | else { | 436 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { |
337 | int i; | 437 | s = &scroll[index]; |
338 | for ( i=0; i<s->space-1; i++ ) | 438 | if ( s->mode == SCROLL_MODE_RUN ) { |
339 | s->line[i] = s->line[i+1]; | 439 | update = true; |
340 | 440 | ||
341 | if ( s->offset < s->textlen ) { | 441 | for ( i = 0; i < s->space - 1; i++ ) |
342 | s->line[(int)s->space - 1] = s->text[(int)s->offset]; | 442 | s->line[i] = s->line[i+1]; |
343 | s->offset++; | 443 | |
344 | } | 444 | if ( s->offset < s->textlen ) { |
345 | else { | 445 | s->line[(int)s->space - 1] = s->text[(int)s->offset]; |
346 | s->line[s->space - 1] = ' '; | 446 | s->offset++; |
347 | if ( s->offset < s->textlen + scroll_spacing - 1 ) | 447 | } |
348 | s->offset++; | 448 | else { |
349 | else | 449 | s->line[s->space - 1] = ' '; |
350 | s->offset = 0; | 450 | if ( s->offset < s->textlen + scroll_spacing - 1 ) |
451 | s->offset++; | ||
452 | else | ||
453 | s->offset = 0; | ||
454 | } | ||
455 | |||
456 | lcd_puts(s->startx,s->starty,s->line); | ||
457 | } | ||
351 | } | 458 | } |
352 | 459 | ||
353 | lcd_puts(s->startx,s->starty,s->line); | 460 | if (update) { |
354 | lcd_update(); | 461 | lcd_update(); |
462 | } | ||
355 | } | 463 | } |
464 | |||
356 | sleep(HZ/scroll_speed); | 465 | sleep(HZ/scroll_speed); |
357 | } | 466 | } |
358 | } | 467 | } |