summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-08-10 21:55:48 +0000
committerJens Arnold <amiconn@rockbox.org>2007-08-10 21:55:48 +0000
commitffeaea65c8c2e90c6baea06bd94adc0292a90b90 (patch)
tree6191dd03052fa41c19137810e243559bd180b86f
parentb597165dcd1e5af41d9a11c2e1c9765cba177671 (diff)
downloadrockbox-ffeaea65c8c2e90c6baea06bd94adc0292a90b90.tar.gz
rockbox-ffeaea65c8c2e90c6baea06bd94adc0292a90b90.zip
Backlight rework: * More compact and straightforward implementation of backlight on hold which also fixes some quirks (e.g. Backlight: Off and Backlight on hold: On didn't work as expected). * Removed special code for the iriver non-LCD remote which didn't make sense and couldn't have worked anyway (hold isn't detectable for the iriver non-LCD remote). * Use SYS_CHARGER_CONNECTED and SYS_CHARGER_DISCONNECTED messages instead of monitoring ourselves.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14271 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/backlight.c173
1 files changed, 51 insertions, 122 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c
index 9277f34681..21d3ce945e 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -97,7 +97,8 @@ static const char backlight_thread_name[] = "backlight";
97static struct event_queue backlight_queue; 97static struct event_queue backlight_queue;
98 98
99static int backlight_timer; 99static int backlight_timer;
100static int backlight_timeout = 5*HZ; 100static int backlight_timeout;
101static int backlight_timeout_normal = 5*HZ;
101#if CONFIG_CHARGING 102#if CONFIG_CHARGING
102static int backlight_timeout_plugged = 5*HZ; 103static int backlight_timeout_plugged = 5*HZ;
103#endif 104#endif
@@ -173,7 +174,8 @@ void button_backlight_set_timeout(int index)
173 174
174#ifdef HAVE_REMOTE_LCD 175#ifdef HAVE_REMOTE_LCD
175static int remote_backlight_timer; 176static int remote_backlight_timer;
176static int remote_backlight_timeout = 5*HZ; 177static int remote_backlight_timeout;
178static int remote_backlight_timeout_normal = 5*HZ;
177#if CONFIG_CHARGING 179#if CONFIG_CHARGING
178static int remote_backlight_timeout_plugged = 5*HZ; 180static int remote_backlight_timeout_plugged = 5*HZ;
179#endif 181#endif
@@ -395,37 +397,32 @@ static void __remote_backlight_off(void)
395/* Update state of backlight according to timeout setting */ 397/* Update state of backlight according to timeout setting */
396static void backlight_update_state(void) 398static void backlight_update_state(void)
397{ 399{
400#ifdef HAS_BUTTON_HOLD
401 if (button_hold() && (backlight_on_button_hold != 0))
402 backlight_timeout = (backlight_on_button_hold == 2) ? 0 : -1;
403 /* always on or always off */
404 else
405#endif
398#if CONFIG_CHARGING 406#if CONFIG_CHARGING
399 if (charger_inserted() 407 if (charger_inserted()
400#ifdef HAVE_USB_POWER 408#ifdef HAVE_USB_POWER
401 || usb_powered() 409 || usb_powered()
402#endif 410#endif
403 ) 411 )
404 backlight_timer = backlight_timeout_plugged; 412 backlight_timeout = backlight_timeout_plugged;
405 else 413 else
406#endif 414#endif
407 backlight_timer = backlight_timeout; 415 backlight_timeout = backlight_timeout_normal;
408 416
409 /* Backlight == OFF in the setting? */ 417 /* Backlight == OFF in the setting? */
410 if (backlight_timer < 0) 418 if (backlight_timeout < 0)
411 { 419 {
412 backlight_timer = 0; /* Disable the timeout */ 420 backlight_timer = 0; /* Disable the timeout */
413#ifdef HAS_BUTTON_HOLD
414 if (backlight_on_button_hold == 2 && button_hold())
415 return; /* Keep on if "On" */
416#endif
417 _backlight_off(); 421 _backlight_off();
418 } 422 }
419 else 423 else
420 { 424 {
421#ifdef HAS_BUTTON_HOLD 425 backlight_timer = backlight_timeout;
422 if (backlight_on_button_hold == 1 && button_hold())
423 {
424 /* Keep off if "Off". */
425 backlight_timer = 0; /* Disable the timeout */
426 return;
427 }
428#endif
429 _backlight_on(); 426 _backlight_on();
430 } 427 }
431} 428}
@@ -434,47 +431,33 @@ static void backlight_update_state(void)
434/* Update state of remote backlight according to timeout setting */ 431/* Update state of remote backlight according to timeout setting */
435static void remote_backlight_update_state(void) 432static void remote_backlight_update_state(void)
436{ 433{
434#ifdef HAS_REMOTE_BUTTON_HOLD
435 if (remote_button_hold() && (remote_backlight_on_button_hold != 0))
436 remote_backlight_timeout = (remote_backlight_on_button_hold == 2)
437 ? 0 : -1; /* always on or always off */
438 else
439#endif
437#if CONFIG_CHARGING 440#if CONFIG_CHARGING
438 if (charger_inserted() 441 if (charger_inserted()
439#ifdef HAVE_USB_POWER 442#ifdef HAVE_USB_POWER
440 || usb_powered() 443 || usb_powered()
441#endif 444#endif
442 ) 445 )
443 remote_backlight_timer = remote_backlight_timeout_plugged; 446 remote_backlight_timeout = remote_backlight_timeout_plugged;
444 else 447 else
445#endif 448#endif
446 remote_backlight_timer = remote_backlight_timeout; 449 remote_backlight_timeout = remote_backlight_timeout_normal;
447 450
448 /* Backlight == OFF in the setting? */ 451 /* Backlight == OFF in the setting? */
449 if (remote_backlight_timer < 0) 452 if (remote_backlight_timeout < 0)
450 { 453 {
451 remote_backlight_timer = 0; /* Disable the timeout */ 454 remote_backlight_timer = 0; /* Disable the timeout */
452#ifdef HAS_REMOTE_BUTTON_HOLD
453 if (remote_backlight_on_button_hold == 2 && remote_button_hold())
454 return; /* Keep on if "On" */
455#endif
456 __remote_backlight_off(); 455 __remote_backlight_off();
457 } 456 }
458 else 457 else
459 { 458 {
460#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) 459 remote_backlight_timer = remote_backlight_timeout;
461 if (remote_type() == REMOTETYPE_H300_NONLCD) 460 __remote_backlight_on();
462 {
463 backlight_update_state();
464 }
465 else
466#endif
467 {
468#ifdef HAS_REMOTE_BUTTON_HOLD
469 if (remote_backlight_on_button_hold == 1 && remote_button_hold())
470 {
471 /* Keep off if "Off". */
472 remote_backlight_timer = 0; /* Disable the timeout */
473 return;
474 }
475#endif
476 __remote_backlight_on();
477 }
478 } 461 }
479} 462}
480#endif /* HAVE_REMOTE_LCD */ 463#endif /* HAVE_REMOTE_LCD */
@@ -495,11 +478,6 @@ void backlight_thread(void)
495 478
496 case REMOTE_BACKLIGHT_OFF: 479 case REMOTE_BACKLIGHT_OFF:
497 remote_backlight_timer = 0; /* Disable the timeout */ 480 remote_backlight_timer = 0; /* Disable the timeout */
498#ifdef HAS_REMOTE_BUTTON_HOLD
499 if (remote_backlight_on_button_hold == 2 &&
500 remote_button_hold())
501 break; /* Keep on if "On" */
502#endif
503 __remote_backlight_off(); 481 __remote_backlight_off();
504 break; 482 break;
505#endif /* HAVE_REMOTE_LCD */ 483#endif /* HAVE_REMOTE_LCD */
@@ -510,10 +488,6 @@ void backlight_thread(void)
510 488
511 case BACKLIGHT_OFF: 489 case BACKLIGHT_OFF:
512 backlight_timer = 0; /* Disable the timeout */ 490 backlight_timer = 0; /* Disable the timeout */
513#ifdef HAS_BUTTON_HOLD
514 if (backlight_on_button_hold == 2 && button_hold())
515 break; /* Keep on if "On" */
516#endif
517 _backlight_off(); 491 _backlight_off();
518 break; 492 break;
519 493
@@ -557,6 +531,16 @@ void backlight_thread(void)
557 break; 531 break;
558#endif /* defined(HAVE_REMOTE_LCD) && !defined(SIMULATOR) */ 532#endif /* defined(HAVE_REMOTE_LCD) && !defined(SIMULATOR) */
559 533
534#if CONFIG_CHARGING
535 case SYS_CHARGER_CONNECTED:
536 case SYS_CHARGER_DISCONNECTED:
537 backlight_update_state();
538#ifdef HAVE_REMOTE_LCD
539 remote_backlight_update_state();
540#endif
541 break;
542#endif /* CONFIG_CHARGING */
543
560 case SYS_USB_CONNECTED: 544 case SYS_USB_CONNECTED:
561 /* Tell the USB thread that we are safe */ 545 /* Tell the USB thread that we are safe */
562 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n"); 546 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
@@ -572,24 +556,6 @@ void backlight_thread(void)
572 556
573static void backlight_tick(void) 557static void backlight_tick(void)
574{ 558{
575#if CONFIG_CHARGING
576 static bool charger_was_inserted = false;
577 bool charger_is_inserted = charger_inserted()
578#ifdef HAVE_USB_POWER
579 || usb_powered()
580#endif
581 ;
582
583 if( charger_was_inserted != charger_is_inserted )
584 {
585 backlight_on();
586#ifdef HAVE_REMOTE_LCD
587 remote_backlight_on();
588#endif
589 }
590 charger_was_inserted = charger_is_inserted;
591#endif /* CONFIG_CHARGING */
592
593 if(backlight_timer) 559 if(backlight_timer)
594 { 560 {
595 backlight_timer--; 561 backlight_timer--;
@@ -689,7 +655,7 @@ void backlight_off(void)
689/* returns true when the backlight is on OR when it's set to always off */ 655/* returns true when the backlight is on OR when it's set to always off */
690bool is_backlight_on(void) 656bool is_backlight_on(void)
691{ 657{
692 if (backlight_timer || backlight_get_current_timeout() <= 0) 658 if (backlight_timer || backlight_timeout <= 0)
693 return true; 659 return true;
694 else 660 else
695 return false; 661 return false;
@@ -698,18 +664,7 @@ bool is_backlight_on(void)
698/* return value in ticks; 0 means always on, <0 means always off */ 664/* return value in ticks; 0 means always on, <0 means always off */
699int backlight_get_current_timeout(void) 665int backlight_get_current_timeout(void)
700{ 666{
701#if CONFIG_CHARGING
702 if (charger_inserted()
703#ifdef HAVE_USB_POWER
704 || usb_powered()
705#endif
706 )
707 return backlight_timeout_plugged;
708 else
709 return backlight_timeout;
710#else
711 return backlight_timeout; 667 return backlight_timeout;
712#endif
713} 668}
714 669
715void backlight_set_timeout(int index) 670void backlight_set_timeout(int index)
@@ -717,7 +672,7 @@ void backlight_set_timeout(int index)
717 if((unsigned)index >= sizeof(backlight_timeout_value)) 672 if((unsigned)index >= sizeof(backlight_timeout_value))
718 /* if given a weird value, use default */ 673 /* if given a weird value, use default */
719 index = 6; 674 index = 6;
720 backlight_timeout = HZ * backlight_timeout_value[index]; 675 backlight_timeout_normal = HZ * backlight_timeout_value[index];
721 backlight_update_state(); 676 backlight_update_state();
722} 677}
723 678
@@ -736,12 +691,8 @@ void backlight_set_timeout_plugged(int index)
736/* Hold button change event handler. */ 691/* Hold button change event handler. */
737void backlight_hold_changed(bool hold_button) 692void backlight_hold_changed(bool hold_button)
738{ 693{
739 /* Hold switch overrides all backlight behavior except when 694 if (!hold_button || (backlight_on_button_hold > 0))
740 set to "Normal" */ 695 /* if unlocked or override in effect */
741 /* Queue or freeze */
742 if (hold_button && backlight_on_button_hold == 1)
743 backlight_off(); /* setting == Off */
744 else /* setting == On, Normal, no hold button, or anything else */
745 backlight_on(); 696 backlight_on();
746} 697}
747 698
@@ -751,11 +702,8 @@ void backlight_set_on_button_hold(int index)
751 /* if given a weird value, use default */ 702 /* if given a weird value, use default */
752 index = 0; 703 index = 0;
753 704
754 if (index == backlight_on_button_hold)
755 return;
756
757 backlight_on_button_hold = index; 705 backlight_on_button_hold = index;
758 backlight_hold_changed(button_hold()); 706 backlight_update_state();
759} 707}
760#endif /* HAS_BUTTON_HOLD */ 708#endif /* HAS_BUTTON_HOLD */
761 709
@@ -796,7 +744,7 @@ void remote_backlight_set_timeout(int index)
796 if((unsigned)index >= sizeof(backlight_timeout_value)) 744 if((unsigned)index >= sizeof(backlight_timeout_value))
797 /* if given a weird value, use default */ 745 /* if given a weird value, use default */
798 index=6; 746 index=6;
799 remote_backlight_timeout = HZ * backlight_timeout_value[index]; 747 remote_backlight_timeout_normal = HZ * backlight_timeout_value[index];
800 remote_backlight_update_state(); 748 remote_backlight_update_state();
801} 749}
802 750
@@ -815,12 +763,8 @@ void remote_backlight_set_timeout_plugged(int index)
815/* Remote hold button change event handler. */ 763/* Remote hold button change event handler. */
816void remote_backlight_hold_changed(bool rc_hold_button) 764void remote_backlight_hold_changed(bool rc_hold_button)
817{ 765{
818 /* Hold switch overrides all backlight behavior except when 766 if (!rc_hold_button || (remote_backlight_on_button_hold > 0))
819 set to "Normal" */ 767 /* if unlocked or override */
820 /* Queue or freeze */
821 if (rc_hold_button && remote_backlight_on_button_hold == 1)
822 remote_backlight_off(); /* setting == Off */
823 else /* setting == On, Normal, no hold button, or anything else */
824 remote_backlight_on(); 768 remote_backlight_on();
825} 769}
826 770
@@ -830,36 +774,21 @@ void remote_backlight_set_on_button_hold(int index)
830 /* if given a weird value, use default */ 774 /* if given a weird value, use default */
831 index = 0; 775 index = 0;
832 776
833 if (index == remote_backlight_on_button_hold)
834 return;
835
836 remote_backlight_on_button_hold = index; 777 remote_backlight_on_button_hold = index;
837 remote_backlight_hold_changed(remote_button_hold()); 778 remote_backlight_update_state();
838} 779}
839#endif /* HAS_REMOTE_BUTTON_HOLD */ 780#endif /* HAS_REMOTE_BUTTON_HOLD */
840 781
841/* return value in ticks; 0 means always on, <0 means always off */ 782/* return value in ticks; 0 means always on, <0 means always off */
842int remote_backlight_get_current_timeout(void) 783int remote_backlight_get_current_timeout(void)
843{ 784{
844#if CONFIG_CHARGING
845 if (charger_inserted()
846#ifdef HAVE_USB_POWER
847 || usb_powered()
848#endif
849 )
850 return remote_backlight_timeout_plugged;
851 else
852 return remote_backlight_timeout;
853#else
854 return remote_backlight_timeout; 785 return remote_backlight_timeout;
855#endif
856} 786}
857 787
858/* returns true when the backlight is on OR when it's set to always off */ 788/* returns true when the backlight is on OR when it's set to always off */
859bool is_remote_backlight_on(void) 789bool is_remote_backlight_on(void)
860{ 790{
861 if (remote_backlight_timer != 0 || 791 if (remote_backlight_timer != 0 || remote_backlight_timeout <= 0)
862 remote_backlight_get_current_timeout() <= 0)
863 return true; 792 return true;
864 else 793 else
865 return false; 794 return false;