diff options
Diffstat (limited to 'apps/screens.c')
-rw-r--r-- | apps/screens.c | 177 |
1 files changed, 100 insertions, 77 deletions
diff --git a/apps/screens.c b/apps/screens.c index a7a4b27ea8..65b64eab3e 100644 --- a/apps/screens.c +++ b/apps/screens.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #if defined(HAVE_USBSTACK) | 37 | #if defined(HAVE_USBSTACK) |
38 | #include "usb_core.h" | 38 | #include "usb_core.h" |
39 | #ifdef USB_ENABLE_HID | 39 | #ifdef USB_ENABLE_HID |
40 | #include "usbstack/usb_hid.h" | 40 | #include "usb_keymaps.h" |
41 | #endif | 41 | #endif |
42 | #endif | 42 | #endif |
43 | #include "settings.h" | 43 | #include "settings.h" |
@@ -93,59 +93,32 @@ static int clamp_value_wrap(int value, int max, int min) | |||
93 | #endif | 93 | #endif |
94 | 94 | ||
95 | #ifndef SIMULATOR | 95 | #ifndef SIMULATOR |
96 | |||
97 | #ifdef USB_ENABLE_HID | ||
98 | int usb_keypad_mode; | ||
99 | #endif | ||
100 | |||
96 | static int handle_usb_events(void) | 101 | static int handle_usb_events(void) |
97 | { | 102 | { |
98 | #if (CONFIG_STORAGE & STORAGE_MMC) | 103 | #if (CONFIG_STORAGE & STORAGE_MMC) |
99 | int next_update=0; | 104 | int next_update=0; |
100 | #endif /* STORAGE_MMC */ | 105 | #endif /* STORAGE_MMC */ |
101 | 106 | ||
102 | #ifdef HAVE_TOUCHSCREEN | ||
103 | enum touchscreen_mode old_mode = touchscreen_get_mode(); | ||
104 | |||
105 | /* TODO: Paint buttons on screens OR switch to point mode and use | ||
106 | * touchscreen as a touchpad to move the host's mouse cursor */ | ||
107 | touchscreen_set_mode(TOUCHSCREEN_BUTTON); | ||
108 | #endif | ||
109 | |||
110 | /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */ | 107 | /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */ |
111 | while(1) | 108 | while(1) |
112 | { | 109 | { |
113 | int button; | 110 | int button; |
114 | #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID) | 111 | #ifdef USB_ENABLE_HID |
115 | bool hid_enabled = usb_core_driver_enabled(USB_DRIVER_HID); | 112 | if (usb_core_driver_enabled(USB_DRIVER_HID)) |
116 | |||
117 | if (hid_enabled) | ||
118 | { | 113 | { |
119 | int id = HID_CONSUMER_USAGE_UNASSIGNED; | 114 | button = get_hid_usb_action(); |
120 | button = get_action(CONTEXT_USB_HID, HZ/2); | ||
121 | 115 | ||
122 | switch (button) | 116 | /* On mode change, we need to refresh the screen */ |
117 | if (button == ACTION_USB_HID_MODE || | ||
118 | button == ACTION_USB_HID_MODE_LONG) | ||
123 | { | 119 | { |
124 | case ACTION_USB_HID_PLAY: | 120 | break; |
125 | id = HID_CONSUMER_USAGE_PLAY_PAUSE; | ||
126 | break; | ||
127 | case ACTION_USB_HID_STOP: | ||
128 | id = HID_CONSUMER_USAGE_STOP; | ||
129 | break; | ||
130 | case ACTION_USB_HID_SKIPPREV: | ||
131 | id = HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK; | ||
132 | break; | ||
133 | case ACTION_USB_HID_SKIPNEXT: | ||
134 | id = HID_CONSUMER_USAGE_SCAN_NEXT_TRACK; | ||
135 | break; | ||
136 | case ACTION_USB_HID_VOLDOWN: | ||
137 | id = HID_CONSUMER_USAGE_VOLUME_DECREMENT; | ||
138 | break; | ||
139 | case ACTION_USB_HID_VOLUP: | ||
140 | id = HID_CONSUMER_USAGE_VOLUME_INCREMENT; | ||
141 | break; | ||
142 | case ACTION_USB_HID_MUTE: | ||
143 | id = HID_CONSUMER_USAGE_MUTE; | ||
144 | break; | ||
145 | } | 121 | } |
146 | |||
147 | if (id != HID_CONSUMER_USAGE_UNASSIGNED) | ||
148 | usb_hid_send(HID_USAGE_PAGE_CONSUMER, id); | ||
149 | } | 122 | } |
150 | else | 123 | else |
151 | #endif | 124 | #endif |
@@ -159,7 +132,7 @@ static int handle_usb_events(void) | |||
159 | { | 132 | { |
160 | case SYS_USB_DISCONNECTED: | 133 | case SYS_USB_DISCONNECTED: |
161 | usb_acknowledge(SYS_USB_DISCONNECTED_ACK); | 134 | usb_acknowledge(SYS_USB_DISCONNECTED_ACK); |
162 | goto Exit; | 135 | return 1; |
163 | case SYS_TIMEOUT: | 136 | case SYS_TIMEOUT: |
164 | break; | 137 | break; |
165 | } | 138 | } |
@@ -174,14 +147,12 @@ static int handle_usb_events(void) | |||
174 | } | 147 | } |
175 | #endif /* STORAGE_MMC */ | 148 | #endif /* STORAGE_MMC */ |
176 | } | 149 | } |
177 | Exit: | 150 | |
178 | #ifdef HAVE_TOUCHSCREEN | ||
179 | touchscreen_set_mode(old_mode); | ||
180 | #endif | ||
181 | return 0; | 151 | return 0; |
182 | } | 152 | } |
183 | #endif | 153 | #endif |
184 | 154 | ||
155 | #define MODE_NAME_LEN 32 | ||
185 | void usb_screen(void) | 156 | void usb_screen(void) |
186 | { | 157 | { |
187 | #ifdef USB_NONE | 158 | #ifdef USB_NONE |
@@ -190,55 +161,107 @@ void usb_screen(void) | |||
190 | int i; | 161 | int i; |
191 | int usb_bars = VP_SB_ALLSCREENS; /* force statusbars */ | 162 | int usb_bars = VP_SB_ALLSCREENS; /* force statusbars */ |
192 | int old_bars = viewportmanager_get_statusbar(); | 163 | int old_bars = viewportmanager_get_statusbar(); |
164 | #if defined HAVE_TOUCHSCREEN | ||
165 | enum touchscreen_mode old_mode = touchscreen_get_mode(); | ||
193 | 166 | ||
194 | FOR_NB_SCREENS(i) | 167 | /* TODO: Paint buttons on screens OR switch to point mode and use |
168 | * touchscreen as a touchpad to move the host's mouse cursor */ | ||
169 | touchscreen_set_mode(TOUCHSCREEN_BUTTON); | ||
170 | #endif | ||
171 | |||
172 | #ifndef SIMULATOR | ||
173 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
174 | #endif | ||
175 | |||
176 | #ifdef USB_ENABLE_HID | ||
177 | usb_keypad_mode = global_settings.usb_keypad_mode; | ||
178 | #endif | ||
179 | |||
180 | while (1) | ||
195 | { | 181 | { |
196 | screens[i].backdrop_show(BACKDROP_MAIN); | 182 | FOR_NB_SCREENS(i) |
197 | screens[i].backlight_on(); | ||
198 | screens[i].clear_display(); | ||
199 | #ifdef HAVE_REMOTE_LCD | ||
200 | if (i == SCREEN_REMOTE) | ||
201 | { | 183 | { |
202 | screens[i].bitmap(remote_usblogo, | 184 | screens[i].backdrop_show(BACKDROP_MAIN); |
203 | (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo), | 185 | screens[i].backlight_on(); |
204 | (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2, | 186 | screens[i].clear_display(); |
205 | BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo); | 187 | #ifdef HAVE_REMOTE_LCD |
206 | } | 188 | if (i == SCREEN_REMOTE) |
207 | else | 189 | { |
190 | screens[i].bitmap(remote_usblogo, | ||
191 | (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo), | ||
192 | (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2, | ||
193 | BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo); | ||
194 | } | ||
195 | else | ||
208 | #endif | 196 | #endif |
209 | { | 197 | { |
198 | char mode_name[MODE_NAME_LEN]; | ||
199 | |||
210 | #ifdef HAVE_LCD_BITMAP | 200 | #ifdef HAVE_LCD_BITMAP |
211 | screens[i].transparent_bitmap(usblogo, | 201 | screens[i].transparent_bitmap(usblogo, |
212 | (LCD_WIDTH-BMPWIDTH_usblogo), | 202 | (LCD_WIDTH-BMPWIDTH_usblogo), |
213 | (LCD_HEIGHT-BMPHEIGHT_usblogo)/2, | 203 | (LCD_HEIGHT-BMPHEIGHT_usblogo)/2, |
214 | BMPWIDTH_usblogo, BMPHEIGHT_usblogo); | 204 | BMPWIDTH_usblogo, BMPHEIGHT_usblogo); |
205 | |||
206 | #ifdef USB_ENABLE_HID | ||
207 | int y, w, h; | ||
208 | |||
209 | screens[i].getstringsize(str(LANG_USB_KEYPAD_MODE), &w, &h); | ||
210 | |||
211 | y = (LCD_HEIGHT - BMPHEIGHT_usblogo) / 2 + BMPHEIGHT_usblogo + h; | ||
212 | screens[i].putsxy((LCD_WIDTH - w) / 2, y, | ||
213 | str(LANG_USB_KEYPAD_MODE)); | ||
214 | y += 3 * h / 2; | ||
215 | |||
216 | snprintf(mode_name, MODE_NAME_LEN, "%s", | ||
217 | str(keypad_mode_name_get())); | ||
218 | screens[i].getstringsize(mode_name, &w, &h); | ||
219 | screens[i].putsxy((LCD_WIDTH - w) / 2, y, mode_name); | ||
220 | #endif /* HID */ | ||
221 | #else /* HAVE_LCD_BITMAP */ | ||
222 | screens[i].double_height(false); | ||
223 | #ifdef USB_ENABLE_HID | ||
224 | snprintf(mode_name, MODE_NAME_LEN, "[USB Mode; %s]", | ||
225 | str(keypad_mode_name_get())); | ||
226 | screens[i].puts_scroll(0, 0, mode_name); | ||
215 | #else | 227 | #else |
216 | screens[i].double_height(false); | 228 | screens[i].puts_scroll(0, 0, "[USB Mode]"); |
217 | screens[i].puts_scroll(0, 0, "[USB Mode]"); | 229 | #endif |
218 | status_set_param(false); | 230 | status_set_param(false); |
219 | status_set_audio(false); | 231 | status_set_audio(false); |
220 | status_set_usb(true); | 232 | status_set_usb(true); |
221 | #endif /* HAVE_LCD_BITMAP */ | 233 | #endif /* HAVE_LCD_BITMAP */ |
222 | } | 234 | } |
223 | screens[i].update(); | 235 | screens[i].update(); |
224 | 236 | ||
225 | /* force statusbar by ignoring the setting */ | 237 | /* force statusbar by ignoring the setting */ |
226 | usb_bars |= VP_SB_IGNORE_SETTING(i); | 238 | usb_bars |= VP_SB_IGNORE_SETTING(i); |
227 | } | 239 | } |
228 | 240 | ||
229 | viewportmanager_set_statusbar(usb_bars); | 241 | viewportmanager_set_statusbar(usb_bars); |
230 | 242 | ||
231 | #ifdef SIMULATOR | 243 | #ifdef SIMULATOR |
232 | while (1) | ||
233 | { | ||
234 | if (button_get_w_tmo(HZ/2)) | 244 | if (button_get_w_tmo(HZ/2)) |
235 | break; | 245 | break; |
236 | send_event(GUI_EVENT_ACTIONUPDATE, NULL); | 246 | send_event(GUI_EVENT_ACTIONUPDATE, NULL); |
237 | } | ||
238 | #else | 247 | #else |
239 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | 248 | if (handle_usb_events()) |
240 | while (handle_usb_events()); | 249 | break; |
241 | #endif /* SIMULATOR */ | 250 | #endif /* SIMULATOR */ |
251 | } | ||
252 | |||
253 | #ifdef USB_ENABLE_HID | ||
254 | if (global_settings.usb_keypad_mode != usb_keypad_mode) | ||
255 | { | ||
256 | global_settings.usb_keypad_mode = usb_keypad_mode; | ||
257 | settings_save(); | ||
258 | } | ||
259 | #endif | ||
260 | |||
261 | #ifdef HAVE_TOUCHSCREEN | ||
262 | touchscreen_set_mode(old_mode); | ||
263 | #endif | ||
264 | |||
242 | #ifdef HAVE_LCD_CHARCELLS | 265 | #ifdef HAVE_LCD_CHARCELLS |
243 | status_set_usb(false); | 266 | status_set_usb(false); |
244 | #endif /* HAVE_LCD_CHARCELLS */ | 267 | #endif /* HAVE_LCD_CHARCELLS */ |
@@ -248,7 +271,7 @@ void usb_screen(void) | |||
248 | } | 271 | } |
249 | viewportmanager_set_statusbar(old_bars); | 272 | viewportmanager_set_statusbar(old_bars); |
250 | send_event(GUI_EVENT_REFRESH, NULL); | 273 | send_event(GUI_EVENT_REFRESH, NULL); |
251 | 274 | ||
252 | #endif /* USB_NONE */ | 275 | #endif /* USB_NONE */ |
253 | } | 276 | } |
254 | 277 | ||