diff options
| author | Linus Nielsen Feltzing <linus@haxx.se> | 2002-07-27 19:38:20 +0000 |
|---|---|---|
| committer | Linus Nielsen Feltzing <linus@haxx.se> | 2002-07-27 19:38:20 +0000 |
| commit | e1a97288fc490558b0e55bb417aa8f8ac7c38c14 (patch) | |
| tree | fae1ee280c69f775f2c2e3600cfaf9e4a6393027 /firmware/drivers/button.c | |
| parent | 42df5849609c726c2c8190ffc61f7474b458c126 (diff) | |
| download | rockbox-e1a97288fc490558b0e55bb417aa8f8ac7c38c14.zip rockbox-e1a97288fc490558b0e55bb417aa8f8ac7c38c14.tar.gz rockbox-e1a97288fc490558b0e55bb417aa8f8ac7c38c14.tar.bz2 rockbox-e1a97288fc490558b0e55bb417aa8f8ac7c38c14.tar.xz | |
Reworked the button code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1462 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/button.c')
| -rw-r--r-- | firmware/drivers/button.c | 105 |
1 files changed, 58 insertions, 47 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 24e4588..878f041 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -37,7 +37,6 @@ struct event_queue button_queue; static int repeat_mask = DEFAULT_REPEAT_MASK; static int release_mask = DEFAULT_RELEASE_MASK; -static int locked_mask = DEFAULT_LOCKED_MASK; static int button_read(void); @@ -50,73 +49,92 @@ static void button_tick(void) int diff; /* only poll every X ticks */ - if ( ++tick >= POLL_FREQUENCY ) { + if ( ++tick >= POLL_FREQUENCY ) + { bool post = false; int btn = button_read(); - + + /* Find out if a key has been released */ + diff = btn ^ lastbtn; + if((btn & diff) == 0) + { + if(diff & release_mask) + queue_post(&button_queue, BUTTON_REL | diff, NULL); + } + if ( btn ) { - /* Find out if a key has been released */ - diff = btn ^ lastbtn; - if((btn & diff) == 0) - { - if(diff & release_mask) - queue_post(&button_queue, BUTTON_REL | diff, NULL); - } - /* normal keypress */ - if ( btn != lastbtn ) { + if ( btn != lastbtn ) + { post = true; + repeat = false; } - /* repeat? */ - else { - if ( repeat ) { + else /* repeat? */ + { + if ( repeat ) + { if ( ! --count ) { post = true; count = REPEAT_INTERVAL; } } - else if (count++ > REPEAT_START) { - /* Only repeat if a repeatable key is pressed */ - if(btn & repeat_mask) + else + { + if(btn & repeat_mask || +#ifdef HAVE_RECORDER_KEYPAD + btn == BUTTON_OFF) +#else + btn == BUTTON_STOP) +#endif { - post = true; - repeat = true; - count = REPEAT_INTERVAL; - } - /* If the OFF button is pressed long enough, and we are - still alive, then the unit must be connected to a - charger. Therefore we will reboot and let the original - firmware handle the charging. */ + if (count++ > REPEAT_START) + { + /* Only repeat if a repeatable key is pressed */ + if(btn & repeat_mask) + { + post = true; + repeat = true; + count = REPEAT_INTERVAL; + } + /* If the OFF button is pressed long enough, + and we are still alive, then the unit must be + connected to a charger. Therefore we will + reboot and let the original firmware handle + the charging. */ #ifdef HAVE_RECORDER_KEYPAD - if(btn == BUTTON_OFF) + if(btn == BUTTON_OFF) #elif HAVE_PLAYER_KEYPAD - if(btn == BUTTON_STOP) + if(btn == BUTTON_STOP) #endif - system_reboot(); + system_reboot(); + } + } + else + { + count = 0; + } } } if ( post ) { - queue_post(&button_queue, btn, NULL); + if(repeat) + queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); + else + queue_post(&button_queue, btn, NULL); backlight_on(); } } - else { + else + { repeat = false; count = 0; - /* Report that the key has been released */ - if(lastbtn != btn) - { - if(lastbtn & release_mask) - queue_post(&button_queue, BUTTON_REL | lastbtn, NULL); - } } - - lastbtn = btn; + + lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); tick = 0; } - + backlight_tick(); } @@ -145,13 +163,6 @@ int button_set_release(int newmask) return oldmask; } -int button_set_locked(int newmask) -{ - int oldmask = locked_mask; - locked_mask = newmask; - return oldmask; -} - #ifdef HAVE_RECORDER_KEYPAD /* AJBR buttons are connected to the CPU as follows: |