]> git.vomp.tv Git - vompclient.git/blob - remotemvp.cc
Fix text corruption in channel number display on live tv
[vompclient.git] / remotemvp.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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "remotemvp.h"
22
23 #include "log.h"
24
25 RemoteMVP::RemoteMVP()
26 {
27   if (instance) return;
28   initted = 0;
29   device = 0;
30   tv.tv_sec = 0;
31   tv.tv_usec = 0;
32 }
33
34 RemoteMVP::~RemoteMVP()
35 {
36 }
37
38 int RemoteMVP::init(const char* devName)
39 {
40   if (initted) return 0;
41   initted = 1;
42
43   device = open(devName, O_RDONLY);
44   if (device < 0)
45   {
46     initted = 0;
47     return 0;
48   }
49
50   return 1;
51 }
52
53 int RemoteMVP::shutdown()
54 {
55   if (!initted) return 0;
56   initted = 0;
57   close(device);
58   device = 0;
59   return 1;
60 }
61
62 int RemoteMVP::getDevice()
63 {
64   if (!initted) return 0;
65   return device;
66 }
67
68 UCHAR RemoteMVP::getButtonPress(int waitType)
69 {
70   /* how = 0 - block
71      how = 1 - start new wait
72      how = 2 - continue wait
73      how = 3 - no wait
74   */
75
76   unsigned long input;
77   struct timeval* passToSelect = NULL;
78   int retval;
79   fd_set readfds;
80
81   if (waitType == 0)
82   {
83     passToSelect = NULL;
84   }
85   else if (waitType == 1)
86   {
87     tv.tv_sec = 1;
88     tv.tv_usec = 000000;
89     passToSelect = &tv;
90   }
91   else if (waitType == 2)
92   {
93     if ((tv.tv_sec == 0) && (tv.tv_usec == 0))  // protection in case timer = 0
94     {
95       tv.tv_sec = 1;
96       tv.tv_usec = 000000;
97     }
98     passToSelect = &tv;
99   }
100   else if (waitType == 3)
101   {
102     tv.tv_sec = 0;
103     tv.tv_usec = 0;
104     passToSelect = &tv;
105   }
106   FD_ZERO(&readfds);
107   FD_SET(device, &readfds);
108
109   retval = select(device + 1, &readfds, NULL, NULL, &tv);
110   // 0 = nothing happened
111   // 1 = data arrived (actually num of descriptors that changed)
112   // other value = signal or error
113   if (retval == 0) return NA_NONE;
114   if (retval == -1) return NA_SIGNAL;
115
116   int count = read(device, &input, 4);
117   if (count == 4)
118   {
119     input = (0X00FF0000 & input) >> 16;
120     Log::getInstance()->log("Remote", Log::DEBUG, "Button %i", input);
121
122     if (remoteType == OLDREMOTE)
123     {
124       if (input == VOLUMEDOWN) return DF_LEFT;
125       if (input == VOLUMEUP) return DF_RIGHT;
126       if (input == CHANNELUP) return DF_UP;
127       if (input == CHANNELDOWN) return DF_DOWN;
128     }
129
130     return (UCHAR) TranslateHWC(input);
131   }
132   return NA_UNKNOWN;
133 }
134
135 void RemoteMVP::clearBuffer()
136 {
137   while(getButtonPress(3) != NA_NONE);
138 }