summaryrefslogtreecommitdiff
path: root/apps/screens.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/screens.c')
-rw-r--r--apps/screens.c102
1 files changed, 89 insertions, 13 deletions
diff --git a/apps/screens.c b/apps/screens.c
index f811547e21..f7ee443f4b 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -470,26 +470,90 @@ bool f3_screen(void)
470 470
471#ifdef HAVE_LCD_BITMAP 471#ifdef HAVE_LCD_BITMAP
472#define SPACE 4 /* pixels between words */ 472#define SPACE 4 /* pixels between words */
473#define MAXLETTERS 128 /* 16*8 */
474#define MAXLINES 10
473#else 475#else
474#define SPACE 1 /* one letter space */ 476#define SPACE 1 /* one letter space */
475#undef LCD_WIDTH 477#undef LCD_WIDTH
476#define LCD_WIDTH 11 478#define LCD_WIDTH 11
477#undef LCD_HEIGHT 479#undef LCD_HEIGHT
478#define LCD_HEIGHT 2 480#define LCD_HEIGHT 2
481#define MAXLETTERS 22 /* 11 * 2 */
482#define MAXLINES 2
479#endif 483#endif
480 484
481void splash(char *text, /* what to say */ 485void splash(int ticks, /* how long */
482 int ticks, /* fow how long */ 486 int keymask, /* what keymask aborts the waiting (if any) */
483 int keymask) /* what keymask aborts the waiting (if any) */ 487 bool center, /* FALSE means left-justified, TRUE means
488 horizontal and vertical center */
489 char *fmt, /* what to say *printf style */
490 ...)
484{ 491{
485 char *next; 492 char *next;
486 char *store=NULL; 493 char *store=NULL;
487 int x=0; 494 int x=0;
488 int y=0; 495 int y=0;
489 int w, h; 496 int w, h;
497 unsigned char splash_buf[MAXLETTERS];
498 va_list ap;
499 unsigned char widths[MAXLINES];
500 int line=0;
501 bool first=true;
502
503 va_start( ap, fmt );
504 vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap );
505
490 lcd_clear_display(); 506 lcd_clear_display();
491 507
492 next = strtok_r(text, " ", &store); 508 if(center) {
509 /* first a pass to measure sizes */
510 next = strtok_r(splash_buf, " ", &store);
511 while (next) {
512#ifdef HAVE_LCD_BITMAP
513 lcd_getstringsize(next, &w, &h);
514#else
515 w = strlen(next);
516 h = 1;
517#endif
518 if(!first) {
519 if(x+w> LCD_WIDTH) {
520 /* too wide */
521 y+=h;
522 line++;
523 if((y > (LCD_HEIGHT-h)) || (line > MAXLINES))
524 /* STOP */
525 break;
526 x=0;
527 first=true;
528 }
529 }
530 else
531 first = false;
532
533 /* think of it as if the text was written here at position x,y
534 being w pixels/chars wide and h high */
535
536 x += w+SPACE;
537 widths[line]=x-SPACE; /* don't count the trailing space */
538 next = strtok_r(NULL, " ", &store);
539 }
540#ifdef HAVE_LCD_BITMAP
541 /* Start displaying the message at position y. The reason for the
542 added h here is that it isn't added until the end of lines in the
543 loop above and we always break the loop in the middle of a line. */
544 y = (LCD_HEIGHT - (y+h) )/2;
545#else
546 y = 0; /* vertical center on 2 lines would be silly */
547#endif
548 line=0;
549 first=true;
550 vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap );
551 }
552 va_end( ap );
553
554 if(center)
555 x = (LCD_WIDTH-widths[0])/2;
556 next = strtok_r(splash_buf, " ", &store);
493 while (next) { 557 while (next) {
494#ifdef HAVE_LCD_BITMAP 558#ifdef HAVE_LCD_BITMAP
495 lcd_getstringsize(next, &w, &h); 559 lcd_getstringsize(next, &w, &h);
@@ -497,16 +561,23 @@ void splash(char *text, /* what to say */
497 w = strlen(next); 561 w = strlen(next);
498 h = 1; 562 h = 1;
499#endif 563#endif
500 if(x) { 564 if(!first) {
501 if(x+w> LCD_WIDTH) { 565 if(x+w> LCD_WIDTH) {
502 /* too wide */ 566 /* too wide */
503 y+=h; 567 y+=h;
568 line++; /* goto next line */
569 first=true;
504 if(y > (LCD_HEIGHT-h)) 570 if(y > (LCD_HEIGHT-h))
505 /* STOP */ 571 /* STOP */
506 break; 572 break;
507 x=0; 573 if(center)
574 x = (LCD_WIDTH-widths[line])/2;
575 else
576 x=0;
508 } 577 }
509 } 578 }
579 else
580 first=false;
510#ifdef HAVE_LCD_BITMAP 581#ifdef HAVE_LCD_BITMAP
511 lcd_putsxy(x, y, next); 582 lcd_putsxy(x, y, next);
512 lcd_update(); /* DURING DEBUG ONLY */ 583 lcd_update(); /* DURING DEBUG ONLY */
@@ -519,12 +590,17 @@ void splash(char *text, /* what to say */
519 lcd_update(); 590 lcd_update();
520 591
521 if(ticks) { 592 if(ticks) {
522 int start = current_tick; 593 if(keymask) {
523 int done = ticks + current_tick + 1; 594 int start = current_tick;
524 while (TIME_BEFORE( current_tick, done)) { 595 int done = ticks + current_tick + 1;
525 int button = button_get_w_tmo(ticks - (current_tick-start)); 596 while (TIME_BEFORE( current_tick, done)) {
526 if((button & keymask) == keymask) 597 int button = button_get_w_tmo(ticks - (current_tick-start));
527 break; 598 if((button & keymask) == keymask)
599 break;
600 }
528 } 601 }
602 else
603 /* unbreakable! */
604 sleep(ticks);
529 } 605 }
530} 606}