]> git.vomp.tv Git - vompclient.git/blob - remotewin.cc
Fix line endings
[vompclient.git] / remotewin.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "remotewin.h"
22 #include "vompreswin.h"
23
24
25 RemoteWin::RemoteWin()
26 {
27   initted = 0;
28   curevent=NA_NONE;
29   signal=false;
30 }
31
32 RemoteWin::~RemoteWin()
33 {
34 }
35
36 int RemoteWin::init(char* devName)
37 {
38   if (initted) return 0;
39   initted = 1;
40   event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL);
41
42
43   return 1;
44 }
45
46 int RemoteWin::shutdown()
47 {
48   if (!initted) return 0;
49   CloseHandle(event);
50   initted = 0;
51   return 1;
52 }
53
54 UCHAR RemoteWin::getButtonPress(int waitType)
55 {
56   /* how = 0 - block
57      how = 1 - start new wait
58      how = 2 - continue wait
59      how = 3 - no wait
60   */
61   DWORD wait;
62
63   if (curevent!=NA_NONE) {
64           UCHAR temp=curevent;
65           curevent=NA_NONE;
66           return temp;
67   }
68   if (waitType==3) {
69           return NA_NONE;
70   }
71   if (waitType==0) {
72           wait=INFINITE;
73   } else { //We do not distingish between 2 and 3
74           wait=1000;
75
76   }
77   WaitForSingleObject(event,wait);
78   ResetEvent(event);
79   if (curevent==NA_NONE) {
80           if (signal) {
81                   signal=false;
82                 return NA_SIGNAL; //Since we have no signals on windows, we simulate this
83           } else {
84                   return NA_NONE;
85           }
86   }
87   UCHAR temp2=curevent;
88   curevent=NA_NONE;
89   return temp2;
90   
91 }
92
93 void RemoteWin::clearBuffer()
94 {
95 }
96
97 int RemoteWin::ReceiveButtonVK(UINT button) {
98         UCHAR pb=NA_NONE;
99         //should we use a translation table ? No APPCOMMAND iS DWORD!
100         switch (button) { //Processing VK_Messages
101         case VK_DOWN:
102                 pb=DOWN; break;
103         case VK_RETURN:
104         case VK_SPACE:
105                 pb=OK;break;
106         case VK_LEFT:
107                 pb=LEFT;break;
108         case '9':
109         case VK_NUMPAD9:
110                 pb=NINE;break;
111         case '8':
112         case VK_NUMPAD8:
113                 pb=EIGHT;break;
114         case '7':
115         case VK_NUMPAD7:
116                 pb=SEVEN;break;
117         case '6':
118         case VK_NUMPAD6:
119                 pb=SIX;break;
120         case '5':
121         case VK_NUMPAD5:
122                 pb=FIVE;break;
123         case '4':
124         case VK_NUMPAD4:
125                 pb=FOUR;break;
126         case '3':
127         case VK_NUMPAD3:
128                 pb=THREE;break;
129         case '2':
130         case VK_NUMPAD2:
131                 pb=TWO;break;
132         case '1':
133         case VK_NUMPAD1:
134                 pb=ONE;break;
135         case '0':
136         case VK_NUMPAD0:
137                 pb=ZERO;break;
138         case VK_RIGHT:
139                 pb=RIGHT;break;
140         case VK_UP:
141                 pb=UP;break;
142         case VK_MULTIPLY:
143                 pb=STAR;break;
144         case 'J'://j for JUMP TO instead of go to
145                 pb=GO;break;
146         //case VK_ESCAPE:
147         //      pb=POWER;break;
148         case VK_BACK:
149                 pb=BACK;break;
150         case 'M':
151                 pb=MENU;break;
152         case 'R':
153                 pb=RED;break;
154         case 'G':
155                 pb=GREEN;break;
156         case 'Y':
157                 pb=YELLOW;break;
158         case 'B':
159                 pb=BLUE; break;
160
161
162         }; //All other commands are process via APPCOMMAND_MESSAGES
163         if (pb==NA_NONE) return 0;
164         curevent=pb;
165         //PulseEvent(event);
166         SetEvent(event);
167         return 1;
168 }
169
170 int RemoteWin::ReceiveButtonAP(UINT button) {
171         UCHAR pb=NA_NONE;
172         //should we use a translation table ? No APPCOMMAND iS DWORD!
173         switch (button) { //Processing VK_Messages
174         case APPCOMMAND_BROWSER_BACKWARD:
175                 pb=BACK;break;
176         case APPCOMMAND_MEDIA_CHANNEL_DOWN:
177                 pb=CHANNELDOWN;break;
178         case APPCOMMAND_MEDIA_CHANNEL_UP:
179                 pb=CHANNELUP;break;
180         case APPCOMMAND_MEDIA_FAST_FORWARD:
181                 pb=FORWARD;break;
182         case APPCOMMAND_VOLUME_MUTE:
183                 pb=MUTE;break;
184         case APPCOMMAND_MEDIA_PAUSE:
185                 pb=PAUSE;break;
186         case APPCOMMAND_MEDIA_PLAY:
187                 pb=PLAY;break;
188         case APPCOMMAND_MEDIA_RECORD:
189                 pb=RECORD;break;
190         case APPCOMMAND_MEDIA_PREVIOUSTRACK:
191                 pb=SKIPBACK;break;
192         case APPCOMMAND_MEDIA_REWIND:
193                 pb=REVERSE;break;
194         case APPCOMMAND_MEDIA_NEXTTRACK:
195                 pb=SKIPFORWARD;break;
196         case APPCOMMAND_MEDIA_STOP:
197                 pb=STOP;break;
198         case APPCOMMAND_VOLUME_DOWN:
199                 pb=VOLUMEDOWN;break;
200         case APPCOMMAND_VOLUME_UP:
201                 pb=VOLUMEUP;break;
202         case VOMP_YELLOW:
203                 pb=YELLOW; break;
204         case VOMP_BLUE:
205                 pb=BLUE;break;
206         case VOMP_RED:
207                 pb=RED;break;
208         case VOMP_GREEN:
209                 pb=GREEN;break;
210         case VOMP_ENTER:
211                 pb=OK;break;
212         case VOMP_CANCEL:
213                 pb=BACK;break;
214         case VOMP_UP:
215                 pb=UP;break;
216         case VOMP_DOWN:
217                 pb=DOWN;break;
218         case VOMP_LEFT:
219                 pb=LEFT;break;
220         case VOMP_RIGHT:
221                 pb=RIGHT;break;
222         };
223         if (pb==NA_NONE) return 0;
224         curevent=pb;
225         //PulseEvent(event);
226         SetEvent(event);
227         return 1;
228 }
229
230 int RemoteWin::ReceiveButtonRI(UINT button) {
231         UCHAR pb=NA_NONE;
232         //Raw Input
233         /* Note Codes above 0x29c are not listed in the specs on usb.org
234            therefore they are used by try, they might be device dependent
235            thus please supply codes of your remote control */
236         switch (button) { //Processing VK_Messages
237         case 0x35c: //Green
238                 pb=GREEN;break;
239         case 0x35b: //Red
240                 pb=RED;break;
241         case 0x35d: //Yellow
242                 pb=YELLOW;break;
243         case 0x35e: //Blue
244                 pb=BLUE;break;
245         case 0x30d: //MCE Button, used for Menu
246                 pb=MENU;break;
247         case 0x348: //Record Television
248                 pb=RECORD;break;
249         case 0x28d: //Attach File Mmh, how should we assign this
250                 pb=NA_NONE;break;
251         case 0x325: //Playback Televison
252                 pb=PLAY;break;
253         case 0x324: //Playback DVD
254                 pb=PLAY;break;
255         case 0x209: //Properties
256         case 0x35a: //Teletext?
257                 pb=OK;break;
258
259         
260         };
261         if (pb==NA_NONE) return 0;
262         curevent=pb;
263         //PulseEvent(event);
264         SetEvent(event);
265         return 1;
266 }
267
268 void RemoteWin::Signal() {
269         signal=true;
270         //PulseEvent(event);
271         SetEvent(event);
272 }
273
274 void RemoteWin::SendPower()
275 {
276
277         curevent=POWER;
278         SetEvent(event);
279 }
280