summaryrefslogtreecommitdiff
path: root/apps/screens.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/screens.c')
-rw-r--r--apps/screens.c70
1 files changed, 64 insertions, 6 deletions
diff --git a/apps/screens.c b/apps/screens.c
index 8c2b145550..be7e29a0c9 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -34,6 +34,12 @@
34#include "audio.h" 34#include "audio.h"
35#include "mp3_playback.h" 35#include "mp3_playback.h"
36#include "usb.h" 36#include "usb.h"
37#if defined(HAVE_USBSTACK)
38#include "usb_core.h"
39#ifdef USB_CLASS_HID
40#include "usbstack/usb_hid.h"
41#endif
42#endif
37#include "settings.h" 43#include "settings.h"
38#include "status.h" 44#include "status.h"
39#include "playlist.h" 45#include "playlist.h"
@@ -90,23 +96,70 @@ static int clamp_value_wrap(int value, int max, int min)
90#endif 96#endif
91 97
92#ifndef SIMULATOR 98#ifndef SIMULATOR
93static int handle_usb_events(struct event_queue *q) 99static int handle_usb_events(void)
94{ 100{
95 struct queue_event ev;
96 int next_update=0; 101 int next_update=0;
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
97 109
98 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */ 110 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
99 while(1) 111 while(1)
100 { 112 {
101 queue_wait_w_tmo(q, &ev, HZ/4); 113 int button;
102 switch(ev.id) 114#if defined(HAVE_USBSTACK) && defined(USB_CLASS_HID)
115 bool hid_enabled = usb_core_driver_enabled(USB_DRIVER_HID);
116
117 if (hid_enabled)
118 {
119 consumer_usage_page_t cmd = UNASSIGNED;
120 button = get_action(CONTEXT_USB_HID, HZ/4);
121
122 switch (button)
123 {
124 case ACTION_USB_HID_PLAY:
125 cmd = PLAY_PAUSE;
126 break;
127 case ACTION_USB_HID_STOP:
128 cmd = STOP;
129 break;
130 case ACTION_USB_HID_SKIPPREV:
131 cmd = SCAN_PREVIOUS_TRACK;
132 break;
133 case ACTION_USB_HID_SKIPNEXT:
134 cmd = SCAN_NEXT_TRACK;
135 break;
136 case ACTION_USB_HID_VOLDOWN:
137 cmd = VOLUME_DECREMENT;
138 break;
139 case ACTION_USB_HID_VOLUP:
140 cmd = VOLUME_INCREMENT;
141 break;
142 case ACTION_USB_HID_MUTE:
143 cmd = MUTE;
144 break;
145 }
146
147 if (cmd != UNASSIGNED)
148 usb_hid_send_consumer_usage(cmd);
149 }
150 else
151#endif
152 button = button_get_w_tmo(HZ/4);
153
154 switch(button)
103 { 155 {
104 case SYS_USB_DISCONNECTED: 156 case SYS_USB_DISCONNECTED:
105 usb_acknowledge(SYS_USB_DISCONNECTED_ACK); 157 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
106 return 0; 158 goto Exit;
107 case SYS_TIMEOUT: 159 case SYS_TIMEOUT:
108 break; 160 break;
109 } 161 }
162
110 if(TIME_AFTER(current_tick,next_update)) 163 if(TIME_AFTER(current_tick,next_update))
111 { 164 {
112 if(usb_inserted()) { 165 if(usb_inserted()) {
@@ -118,6 +171,11 @@ static int handle_usb_events(struct event_queue *q)
118 next_update=current_tick+HZ/2; 171 next_update=current_tick+HZ/2;
119 } 172 }
120 } 173 }
174Exit:
175#ifdef HAVE_TOUCHSCREEN
176 touchscreen_set_mode(old_mode);
177#endif
178 return 0;
121} 179}
122#endif 180#endif
123 181
@@ -172,7 +230,7 @@ void usb_screen(void)
172 while (button_get(true) & BUTTON_REL); 230 while (button_get(true) & BUTTON_REL);
173#else 231#else
174 usb_acknowledge(SYS_USB_CONNECTED_ACK); 232 usb_acknowledge(SYS_USB_CONNECTED_ACK);
175 while(handle_usb_events(&button_queue)); 233 while (handle_usb_events());
176#endif /* SIMULATOR */ 234#endif /* SIMULATOR */
177#ifdef HAVE_LCD_CHARCELLS 235#ifdef HAVE_LCD_CHARCELLS
178 status_set_usb(false); 236 status_set_usb(false);