2 Copyright 2020 Chris Tallon; 2012 Marten Richter
4 This file is part of VOMP.
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.
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.
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/>.
22 #include "wremoteconfig.h"
24 #ifdef VOMP_PLATFORM_RASPBERRY
25 #include "inputlinux.h"
29 #include "inputlirc.h"
38 static const char* TAG = "InputMan";
40 InputMan* InputMan::instance = NULL;
52 InputMan* InputMan::getInstance()
62 #ifdef VOMP_PLATFORM_RASPBERRY
63 inputLinux = new InputLinux();
64 ret = inputLinux->init();
68 { delete inputLinux; inputLinux = NULL; }
70 bool cecEnabled = true;
71 Config::getInstance()->getBool("input", "mod_cec_enabled", cecEnabled);
74 inputCEC = new InputCEC();
75 ret = inputCEC->init();
79 { delete inputCEC; inputCEC = NULL; }
83 bool udpEnabled = true;
84 Config::getInstance()->getBool("input", "mod_udp_enabled", udpEnabled);
87 inputUDP = new InputUDP();
88 ret = inputUDP->init();
92 { delete inputUDP; inputUDP = NULL; }
95 bool lircEnabled = false;
96 Config::getInstance()->getBool("input", "mod_lirc_enabled", lircEnabled);
99 inputLirc = new InputLIRC();
100 ret = inputLirc->init();
104 { delete inputLirc; inputLirc = NULL; }
108 inputWin = new InputWin();
109 ret = inputWin->init();
113 { delete inputWin; inputWin = NULL; }
118 LogNT::getInstance()->crit(TAG, "InputMan could not init any input module");
126 bool InputMan::start()
128 LogNT::getInstance()->debug(TAG, "Start");
132 #ifdef VOMP_PLATFORM_RASPBERRY
133 if (inputLinux && inputLinux->start()) oneOK = true;
136 if (inputUDP && inputUDP->start()) oneOK = true;
138 if (inputLirc && inputLirc->start()) oneOK = true;
141 LogNT::getInstance()->crit(TAG, "InputMan could not start any input module");
146 void InputMan::stop()
148 LogNT::getInstance()->debug(TAG, "Stop called");
150 #ifdef VOMP_PLATFORM_RASPBERRY
151 if (inputLinux) inputLinux->stop();
153 if (inputUDP) inputUDP->stop();
154 if (inputLirc) inputLirc->stop();
157 void InputMan::shutdown()
159 LogNT::getInstance()->debug(TAG, "Shutdown start");
161 #ifdef VOMP_PLATFORM_RASPBERRY
165 LogNT::getInstance()->debug(TAG, "Shutdown start - Linux");
167 inputLinux->shutdown();
174 LogNT::getInstance()->debug(TAG, "Shutdown start - CEC");
175 inputCEC->shutdown();
184 LogNT::getInstance()->debug(TAG, "Shutdown start - UDP");
186 inputUDP->shutdown();
193 LogNT::getInstance()->debug(TAG, "Shutdown start - LIRC");
195 inputLirc->shutdown();
203 bool InputMan::mayHaveFewButtons()
205 // 052 returned true if remotelinux was in effect - linux or CEC. What was it for?
207 if (inputLinux || inputCEC) return true;
211 bool InputMan::handlesVolume()
213 #ifdef VOMP_PLATFORM_RASPBERRY
214 if (!inputCEC) return false;
215 return inputCEC->handlesVolume();
221 void InputMan::volumeUp()
223 #ifdef VOMP_PLATFORM_RASPBERRY
224 if (inputCEC) inputCEC->volumeUp();
228 void InputMan::volumeDown()
230 #ifdef VOMP_PLATFORM_RASPBERRY
231 if (inputCEC) inputCEC->volumeDown();
235 void InputMan::volumeMute()
237 #ifdef VOMP_PLATFORM_RASPBERRY
238 if (inputCEC) inputCEC->volumeMute();
242 void InputMan::changePowerState(bool powerOn)
244 #ifdef VOMP_PLATFORM_RASPBERRY
245 if (inputCEC) inputCEC->changePowerState(powerOn);
249 bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane)
251 #ifdef VOMP_PLATFORM_RASPBERRY
252 if (inputLinux) inputLinux->addOptionsToPanes(panenumber, options, pane);
253 if (inputCEC) inputCEC->addOptionsToPanes(panenumber, options, pane);
256 return true; // FIXME
259 bool InputMan::addOptionPagesToWTB(WTabBar *wtb)
261 WRemoteConfig* wrc = new WRemoteConfig();
262 wtb->addTab(tr("Remote Control"), wrc);
264 return true; // FIXME
267 bool InputMan::loadOptionsFromServer(VDR* vdr)
269 #ifdef VOMP_PLATFORM_RASPBERRY
270 if (inputLinux) inputLinux->loadOptionsFromServer(vdr);
271 if (inputCEC) inputCEC->loadOptionsFromServer(vdr);
274 return true; // FIXME
277 bool InputMan::saveOptionstoServer()
279 #ifdef VOMP_PLATFORM_RASPBERRY
280 if (inputLinux) inputLinux->saveOptionstoServer();
281 if (inputCEC) inputCEC->saveOptionstoServer();
283 return true; // FIXME
286 const char* InputMan::getVompKeyName(u1 number)
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");
339 return tr("Reverse");
343 return tr("Forward");
350 case Input::SKIPBACK:
351 return tr("Skip back");
352 case Input::SKIPFORWARD:
353 return tr("Skip forward");
357 return tr("Fullscreen");
364 case Input::PICTURES:
365 return tr("Pictures");
376 case Input::PREVCHANNEL:
377 return tr("Previous Channel");
382 case Input::PLAYPAUSE:
383 return tr("Play/Pause");
390 u1 InputMan::getVompKeyNumber(const char* vompKeyName)
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;
444 std::string InputMan::getHardCodedHardwareKeyNamesForVompKey(u1 vompKey)
446 // Go through each active Input class and get the hardware key name for vompKey
448 // which doesn't make any sense
450 std::string keyNames;
452 #ifdef VOMP_PLATFORM_RASPBERRY
455 std::string k = inputLinux->getHardCodedHardwareKeyNamesForVompKey(vompKey);
456 if (k.size()) keyNames += k;
461 std::string k = inputCEC->getHardCodedHardwareKeyNamesForVompKey(vompKey);
462 if (k.size()) { keyNames += ", "; keyNames += k; }
468 std::string k = inputUDP->getHardCodedHardwareKeyNamesForVompKey(vompKey);
469 if (k.size()) { keyNames += ", "; keyNames += k; }
475 std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(u1 vompKey)
477 std::string keyNames;
479 #ifdef VOMP_PLATFORM_RASPBERRY
482 std::string k = inputLinux->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
483 if (k.size()) keyNames += k;
488 std::string k = inputCEC->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
489 if (k.size()) { keyNames += ", "; keyNames += k; }
495 std::string k = inputUDP->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
496 if (k.size()) { keyNames += ", "; keyNames += k; }
502 void InputMan::ResetToDefault()
504 #ifdef VOMP_PLATFORM_RASPBERRY
506 if (inputLinux) inputLinux->ResetToDefault();
508 if (inputCEC) inputCEC->ResetToDefault();
512 if (inputUDP) inputUDP->ResetToDefault();
515 void InputMan::EnterLearningMode(u1 vompKey)
517 #ifdef VOMP_PLATFORM_RASPBERRY
518 if (inputLinux) inputLinux->EnterLearningMode(vompKey);
520 // if (inputCEC) inputCEC->EnterLearningMode(); FIXME - is there any such thing?
524 void InputMan::cancelLearnMode()
526 #ifdef VOMP_PLATFORM_RASPBERRY
527 if (inputLinux) inputLinux->cancelLearnMode();
528 if (inputCEC) inputCEC->cancelLearnMode();
530 if (inputUDP) inputUDP->cancelLearnMode();