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