summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/button.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 69d041f65e..025c8cf77d 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -47,6 +47,9 @@ long last_keypress;
47/* speed repeat finishes at */ 47/* speed repeat finishes at */
48#define REPEAT_INTERVAL_FINISH 2 48#define REPEAT_INTERVAL_FINISH 2
49 49
50/* Number of repeated keys before shutting off */
51#define POWEROFF_COUNT 8
52
50static int button_read(void); 53static int button_read(void);
51 54
52static void button_tick(void) 55static void button_tick(void)
@@ -55,6 +58,7 @@ static void button_tick(void)
55 static int count = 0; 58 static int count = 0;
56 static int lastbtn = 0; 59 static int lastbtn = 0;
57 static int repeat_speed = REPEAT_INTERVAL_START; 60 static int repeat_speed = REPEAT_INTERVAL_START;
61 static int repeat_count = 0;
58 static bool repeat = false; 62 static bool repeat = false;
59 int diff; 63 int diff;
60 int btn; 64 int btn;
@@ -103,6 +107,27 @@ static void button_tick(void)
103 if (repeat_speed < REPEAT_INTERVAL_FINISH) 107 if (repeat_speed < REPEAT_INTERVAL_FINISH)
104 repeat_speed = REPEAT_INTERVAL_FINISH; 108 repeat_speed = REPEAT_INTERVAL_FINISH;
105 count = repeat_speed; 109 count = repeat_speed;
110
111 repeat_count++;
112
113 /* Shutdown if we have a device which doesn't shut
114 down easily with the OFF key */
115#ifdef HAVE_POWEROFF_ON_PB5
116 if(btn == BUTTON_OFF && !charger_inserted() &&
117 repeat_count > POWEROFF_COUNT)
118 power_off();
119#endif
120
121 /* Reboot if the OFF button is pressed long enough
122 and we are connected to a charger. */
123#ifdef HAVE_RECORDER_KEYPAD
124 if(btn == BUTTON_OFF && charger_inserted() &&
125 repeat_count > POWEROFF_COUNT)
126#elif HAVE_PLAYER_KEYPAD
127 if(btn == BUTTON_STOP && charger_inserted() &&
128 repeat_count > POWEROFF_COUNT)
129#endif
130 system_reboot();
106 } 131 }
107 } 132 }
108 else 133 else
@@ -111,17 +136,9 @@ static void button_tick(void)
111 { 136 {
112 post = true; 137 post = true;
113 repeat = true; 138 repeat = true;
139 repeat_count = 0;
114 /* initial repeat */ 140 /* initial repeat */
115 count = REPEAT_INTERVAL_START; 141 count = REPEAT_INTERVAL_START;
116
117 /* Reboot if the OFF button is pressed long enough
118 and we are connected to a charger. */
119#ifdef HAVE_RECORDER_KEYPAD
120 if(btn == BUTTON_OFF && charger_inserted())
121#elif HAVE_PLAYER_KEYPAD
122 if(btn == BUTTON_STOP && charger_inserted())
123#endif
124 system_reboot();
125 } 142 }
126 } 143 }
127 } 144 }