Author Topic: first key action switches backlight on  (Read 6260 times)

kay1234

  • Jr. Member
  • **
  • Posts: 88
  • Gender: Male
first key action switches backlight on
« on: 02.03.2007 at 02:01:44 »
In the state when the backlight is switched off the first action on the key should do nothing except for switching it back on again. At the moment the backlight is switched on and the assigned function is carried out. That means you can't just switch the backlight back on without changing the volume or switching to the menu at the same time.

Jesper Hansen

  • Administrator
  • YaBB God
  • *****
  • Posts: 1618
  • ypod? ynot?
Re: first key action switches backlight on
« Reply #1 on: 02.03.2007 at 03:09:36 »
Yep, good point, will implement that.
If electricity comes from electrons, does morality come from morons ?

Botosu

  • Full Member
  • ***
  • Posts: 230
  • Gender: Male
  • Fight Fire With the Fire
Re: first key action switches backlight on
« Reply #2 on: 05.03.2007 at 21:30:08 »
A suggestion (when yPod is in Play Mode):

long press -> turn on the backlight
and
up / down -> control the volume

In this way we can modify the volume with minimal power consumption (backlight  stay off)

What do you think about this?
« Last Edit: 05.03.2007 at 21:35:53 by Botosu »

kay1234

  • Jr. Member
  • **
  • Posts: 88
  • Gender: Male
Re: first key action switches backlight on
« Reply #3 on: 06.03.2007 at 12:47:41 »
Cool.  8) Nice idea. Short press should activate the backlight as well, makes handling faster.

Botosu

  • Full Member
  • ***
  • Posts: 230
  • Gender: Male
  • Fight Fire With the Fire
Re: first key action switches backlight on
« Reply #4 on: 06.03.2007 at 14:07:15 »
I thought that will be better to ignore a short press,
in order to avoid an accidental press of the button.

(if the player is in the pocket, or in some similar cases)

kay1234

  • Jr. Member
  • **
  • Posts: 88
  • Gender: Male
Re: first key action switches backlight on
« Reply #5 on: 13.03.2007 at 21:52:32 »
I did it myself. The code below provides the follwing functionality:

While the playwindow is active
  • if the backlight is not fully switched off (read: it is on or dimming is in progress) any key event will be passed through and the backlight is switched back on
  • if the backlight is fully switched off a long press will turn the backlight back on (doing nothing else)
  • if the backlight is fully switched off up/down will control the volume and leave the backlight off (only full (fast) up and full (fast) down at the moment to prevent accidental actions)

While any other window is active
  • if the backlight is not fully switched off (read: it is on or dimming is in progress) any key event will be passed through and the backlight is switched back on
  • if the backlight is fully switched off a long press will turn the backlight back on (doing nothing else)
  • if the backlight is fully switched off no other key event will be passed through to prevent accidental menu actions

Drawbacks of this approach
  • The events passed through are independent of the mode selected in the graphical play menu. This is not an issue at the moment since the menu reverts to volume mode after a few seconds (fewer than backlight timeout) but I for myself am not so sure if I really like that behavior. If it does not revert to volume mode and the current mode requires up/down instead of full up/full down this code has to be patched.
  • Handling requires an additional long press pretty often, maybe you need to increase the BACKLIGHT_ON_TIME (5 seconds is really short now...)

Here is the diff of the changes. I am aware of the fact that defining MS_PLAYWINDOW again is pretty dirty but I couldn't find a way to define it as extern. It should be moved to global.h but that would require changing main.c as well. I tried to keep it simple here, so maybe someone with repository access will do that change?


Code: [Select]
--- helpers.c (revision 165)
+++ helpers.c (working copy)
@@ -69,6 +69,11 @@
 #define BATT_LOW 2 //!< Battery under voltage
 //@}
 
+
+extern uint16_t mainstate;
+#define MS_PLAYWINDOW 0x0002 // info about current song (from main.c)
+
+
 /** \fn void init_lowlevel_io(void)
  * Low level initialization of the controller
  *
@@ -447,17 +452,48 @@
  }
 
  //
- // if any event has been created,
- // post it and turn on display light
+ // handle events different from EV_IDLE and the display backlight
  //
+ // If we are in charge info screen, power down
+ //
+ // If backlight is on (tlight) or dimming in progress (pwm>127) post
+ // event and turn backlight on (will implicitly reset display off counter) 
+ //
+ // If the backlight is completely off,
+ // - and we are in play window,
+ //   - EV_LONGPRESS will turn backlight on
+ //   - EV_UPFAST or EV_DOWNFAST will be passed through (backlight stays off)
+ // - and we are in any other window,
+ //   - EV_LONGPRESS will turn backlight on
+ // anything else will be ignored to prevent accidental actions.
+ //
+ int pwm = *AT91C_PWMC_CH0_CDTYR;
  if (event != EV_IDLE)
  {
- light_on();
  if (charge_info_screen)
  power_off();
  //set_event(EV_RESET);
  else
- set_event(event);
+ if ((tLight) || ((!tLight) && (pwm < 127)))
+ {
+ light_on();
+ set_event(event);
+ }
+ else if (mainstate!=MS_PLAYWINDOW)
+ {
+ if (event == EV_LONGPRESS)
+ light_on();
+ }
+ else
+ switch (event)
+ {
+ case EV_LONGPRESS:
+ light_on();
+ break;
+ case EV_UPFAST:
+ case EV_DOWNFAST:
+ set_event(event);
+ }
 
  tOffTime = POWER_OFF_TIMEOUT; // rekick the poweroff timeout
  }
« Last Edit: 13.03.2007 at 21:54:33 by kay1234 »