]> git.vomp.tv Git - vompclient.git/blob - inputman.cc
11 CWFs
[vompclient.git] / inputman.cc
1 /*
2     Copyright 2020 Chris Tallon; 2012 Marten Richter
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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "log.h"
21 #include "wremoteconfig.h"
22 #include "wtabbar.h"
23 #ifdef VOMP_PLATFORM_RASPBERRY
24 #include "inputlinux.h"
25 #include "inputcec.h"
26 #endif
27 #include "inputudp.h"
28 #include "inputlirc.h"
29 #ifdef WIN32
30 #include "inputwin.h"
31 #endif
32 #include "i18n.h"
33 #include "input.h"
34
35 #include "inputman.h"
36
37 InputMan* InputMan::instance = NULL;
38
39 InputMan::InputMan()
40 {
41   instance = this;
42 }
43
44 InputMan::~InputMan()
45 {
46   instance = NULL;
47 }
48
49 InputMan* InputMan::getInstance()
50 {
51   return instance;
52 }
53
54 bool InputMan::init()
55 {
56   bool ret;
57   bool oneOK{};
58
59 #ifdef VOMP_PLATFORM_RASPBERRY
60   inputLinux = new InputLinux();
61   ret = inputLinux->init();
62   if (ret)
63     oneOK = true;
64   else
65     { delete inputLinux; inputLinux = NULL; }
66
67   // FIXME enable modules by new config system NCONFIG
68
69 //  inputCEC = new InputCEC();
70 //  ret = inputCEC->init();
71 //  if (ret)
72 //    oneOK = true;
73 //  else
74 //    { delete inputCEC; inputCEC = NULL; }
75 #endif
76
77   inputUDP = new InputUDP();
78   ret = inputUDP->init();
79   if (ret)
80     oneOK = true;
81   else
82     { delete inputUDP; inputUDP = NULL; }
83
84   inputLirc = new InputLIRC();
85   ret = inputLirc->init();
86   if (ret)
87     oneOK = true;
88   else
89     { delete inputLirc; inputLirc = NULL; }
90
91 #ifdef WIN32
92   inputWin = new InputWin();
93   ret = inputWin->init();
94   if (ret)
95     oneOK = true;
96   else
97     { delete inputWin; inputWin = NULL; }
98 #endif
99
100   if (!oneOK)
101   {
102     Log::getInstance()->log("InputMan", Log::CRIT, "InputMan could not init any input module");
103     return false;
104   }
105
106   initted = true;
107   return true;
108 }
109
110 bool InputMan::start()
111 {
112   Log::getInstance()->log("InputMan", Log::DEBUG, "Start");
113
114   bool oneOK{};
115
116 #ifdef VOMP_PLATFORM_RASPBERRY
117   if (inputLinux && inputLinux->start()) oneOK = true;
118 #endif
119
120   if (inputUDP && inputUDP->start()) oneOK = true;
121
122
123   // FIXME
124   std::string lircIP;
125   USHORT lircPort = 8765;
126   // Override lircIP in inputlirc.conf2
127 #include "inputlirc.conf2"
128   if (inputLirc && inputLirc->start(lircIP, lircPort)) oneOK = true;
129
130
131   if (!oneOK)
132     Log::getInstance()->log("InputMan", Log::CRIT, "InputMan could not start any input module");
133
134   return oneOK;
135 }
136
137 void InputMan::stop()
138 {
139   Log::getInstance()->log("InputMan", Log::DEBUG, "Stop called");
140
141 #ifdef VOMP_PLATFORM_RASPBERRY
142   if (inputLinux) inputLinux->stop();
143 #endif
144   if (inputUDP) inputUDP->stop();
145   if (inputLirc) inputLirc->stop();
146 }
147
148 void InputMan::shutdown()
149 {
150   Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start");
151
152 #ifdef VOMP_PLATFORM_RASPBERRY
153
154   if (inputLinux)
155   {
156     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - Linux");
157     inputLinux->stop();
158     inputLinux->shutdown();
159     delete inputLinux;
160     inputLinux = NULL;
161   }
162
163   if (inputCEC)
164   {
165     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - CEC");
166     inputCEC->shutdown();
167     delete inputCEC;
168     inputCEC = NULL;
169   }
170
171 #endif
172
173   if (inputUDP)
174   {
175     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - UDP");
176     inputUDP->stop();
177     inputUDP->shutdown();
178     delete inputUDP;
179     inputUDP = NULL;
180   }
181
182   if (inputLirc)
183   {
184     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - LIRC");
185     inputLirc->stop();
186     inputLirc->shutdown();
187     delete inputLirc;
188     inputLirc = NULL;
189   }
190
191   initted = false;
192 }
193
194 bool InputMan::mayHaveFewButtons()
195 {
196   // 052 returned true if remotelinux was in effect - linux or CEC. What was it for?
197
198   if (inputLinux || inputCEC) return true;
199   return false;
200 }
201
202 bool InputMan::handlesVolume()
203 {
204 #ifdef VOMP_PLATFORM_RASPBERRY
205   if (!inputCEC) return false;
206   return inputCEC->handlesVolume();
207 #else
208   return false;
209 #endif
210 }
211
212 void InputMan::volumeUp()
213 {
214 #ifdef VOMP_PLATFORM_RASPBERRY
215         if (inputCEC) inputCEC->volumeUp();
216 #endif
217 }
218
219 void InputMan::volumeDown()
220 {
221 #ifdef VOMP_PLATFORM_RASPBERRY
222         if (inputCEC) inputCEC->volumeDown();
223 #endif
224 }
225
226 void InputMan::volumeMute()
227 {
228 #ifdef VOMP_PLATFORM_RASPBERRY
229   if (inputCEC) inputCEC->volumeMute();
230 #endif
231 }
232
233 void InputMan::changePowerState(bool powerOn)
234 {
235 #ifdef VOMP_PLATFORM_RASPBERRY
236   if (inputCEC) inputCEC->changePowerState(powerOn);
237 #endif
238 }
239
240 bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane)
241 {
242 #ifdef VOMP_PLATFORM_RASPBERRY
243   if (inputLinux) inputLinux->addOptionsToPanes(panenumber, options, pane);
244   if (inputCEC) inputCEC->addOptionsToPanes(panenumber, options, pane);
245 #endif
246
247   return true; // FIXME
248 }
249
250 bool InputMan::addOptionPagesToWTB(WTabBar *wtb)
251 {
252   WRemoteConfig* wrc = new WRemoteConfig();
253   wtb->addTab(tr("Remote Control"), wrc);
254
255   return true; // FIXME
256 }
257
258 bool InputMan::loadOptionsFromServer(VDR* vdr)
259 {
260 #ifdef VOMP_PLATFORM_RASPBERRY
261   if (inputLinux) inputLinux->loadOptionsFromServer(vdr);
262   if (inputCEC) inputCEC->loadOptionsFromServer(vdr);
263 #endif
264
265   return true; // FIXME
266 }
267
268 bool InputMan::saveOptionstoServer()
269 {
270 #ifdef VOMP_PLATFORM_RASPBERRY
271   if (inputLinux) inputLinux->saveOptionstoServer();
272   if (inputCEC) inputCEC->saveOptionstoServer();
273 #endif
274   return true; // FIXME
275 }
276
277 const char* InputMan::getVompKeyName(UCHAR number)
278 {
279   switch (number)
280   {
281     case Input::VOLUMEUP:
282       return tr("Volume Up");
283     case Input::VOLUMEDOWN:
284       return tr("Volume Down");
285     case Input::CHANNELUP:
286       return tr("Channel up");
287     case Input::CHANNELDOWN:
288       return tr("Channel down");
289     case Input::ZERO:
290       return "0";
291     case Input::ONE:
292       return "1";
293     case Input::TWO:
294       return "2";
295     case Input::THREE:
296       return "3";
297     case Input::FOUR:
298       return "4";
299     case Input::FIVE:
300       return "5";
301     case Input::SIX:
302       return "6";
303     case Input::SEVEN:
304       return "7";
305     case Input::EIGHT:
306       return "8";
307     case Input::NINE:
308       return "9";
309     case Input::POWER:
310       return tr("Power");
311     case Input::GO:
312       return tr("Go");
313     case Input::BACK:
314       return tr("Back");
315     case Input::MENU:
316       return tr("Menu");
317     case Input::RED:
318       return tr("Red");
319     case Input::GREEN:
320       return tr("Green");
321     case Input::YELLOW:
322       return tr("Yellow");
323     case Input::BLUE:
324       return tr("Blue");
325     case Input::MUTE:
326       return tr("Mute");
327     case Input::RADIO:
328       return tr("Radio");
329     case Input::REVERSE:
330       return tr("Reverse");
331     case Input::PLAY:
332       return tr("Play");
333     case Input::FORWARD:
334       return tr("Forward");
335     case Input::RECORD:
336       return tr("Record");
337     case Input::STOP:
338       return tr("Stop");
339     case Input::PAUSE:
340       return tr("Pause");
341     case Input::SKIPBACK:
342       return tr("Skip back");
343     case Input::SKIPFORWARD:
344       return tr("Skip forward");
345     case Input::OK:
346       return tr("Ok");
347     case Input::FULL:
348       return tr("Fullscreen");
349     case Input::TV:
350       return tr("TV");
351     case Input::VIDEOS:
352       return tr("Videos");
353     case Input::MUSIC:
354       return tr("Music");
355     case Input::PICTURES:
356       return tr("Pictures");
357     case Input::GUIDE:
358       return tr("Guide");
359     case Input::UP:
360       return tr("Up");
361     case Input::DOWN:
362       return tr("Down");
363     case Input::LEFT:
364       return tr("Left");
365     case Input::RIGHT:
366       return tr("Right");
367     case Input::PREVCHANNEL:
368       return tr("Previous Channel");
369     case Input::STAR:
370       return tr("Star");
371     case Input::HASH:
372       return tr("Hash");
373     case Input::PLAYPAUSE:
374        return tr("Play/Pause");
375
376     default:
377       return NULL;
378   }
379 }
380
381 std::string InputMan::getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey)
382 {
383   // Go through each active Input class and get the hardware key name for vompKey
384
385   // which doesn't make any sense
386
387   std::string keyNames;
388
389 #ifdef VOMP_PLATFORM_RASPBERRY
390   if (inputLinux)
391   {
392     std::string k = inputLinux->getHardCodedHardwareKeyNamesForVompKey(vompKey);
393     if (k.size()) keyNames += k;
394   }
395
396   if (inputCEC)
397   {
398     std::string k = inputCEC->getHardCodedHardwareKeyNamesForVompKey(vompKey);
399     if (k.size()) { keyNames += ", "; keyNames += k; }
400   }
401 #endif
402
403   if (inputUDP)
404   {
405     std::string k = inputUDP->getHardCodedHardwareKeyNamesForVompKey(vompKey);
406     if (k.size()) { keyNames += ", "; keyNames += k; }
407   }
408
409   return keyNames;
410 }
411
412 std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
413 {
414   std::string keyNames;
415
416 #ifdef VOMP_PLATFORM_RASPBERRY
417   if (inputLinux)
418   {
419     std::string k = inputLinux->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
420     if (k.size()) keyNames += k;
421   }
422
423   if (inputCEC)
424   {
425     std::string k = inputCEC->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
426     if (k.size()) { keyNames += ", "; keyNames += k; }
427   }
428 #endif
429
430   if (inputUDP)
431   {
432     std::string k = inputUDP->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
433     if (k.size()) { keyNames += ", "; keyNames += k; }
434   }
435
436   return keyNames;
437 }
438
439 void InputMan::ResetToDefault()
440 {
441 #ifdef VOMP_PLATFORM_RASPBERRY
442
443   if (inputLinux) inputLinux->ResetToDefault();
444
445   if (inputCEC) inputCEC->ResetToDefault();
446
447 #endif
448
449   if (inputUDP) inputUDP->ResetToDefault();
450 }
451
452 void InputMan::EnterLearningMode(UCHAR vompKey)
453 {
454 #ifdef VOMP_PLATFORM_RASPBERRY
455   if (inputLinux) inputLinux->EnterLearningMode(vompKey);
456
457 //  if (inputCEC) inputCEC->EnterLearningMode();  FIXME - is there any such thing?
458 #endif
459 }
460
461 void InputMan::cancelLearnMode()
462 {
463 #ifdef VOMP_PLATFORM_RASPBERRY
464   if (inputLinux) inputLinux->cancelLearnMode();
465   if (inputCEC) inputCEC->cancelLearnMode();
466 #endif
467   if (inputUDP) inputUDP->cancelLearnMode();
468 }