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;
141 bool checkA = Config::getInstance()->getString("input", "lirc_ip", lircIP);
143 bool checkB = Config::getInstance()->getInt("input", "lirc_port", lircPort);
145 if (!checkA || !checkB)
152 if (inputLirc->start(lircIP, lircPort))
165 LogNT::getInstance()->crit(TAG, "InputMan could not start any input module");
170 void InputMan::stop()
172 LogNT::getInstance()->debug(TAG, "Stop called");
174 #ifdef VOMP_PLATFORM_RASPBERRY
175 if (inputLinux) inputLinux->stop();
177 if (inputUDP) inputUDP->stop();
178 if (inputLirc) inputLirc->stop();
181 void InputMan::shutdown()
183 LogNT::getInstance()->debug(TAG, "Shutdown start");
185 #ifdef VOMP_PLATFORM_RASPBERRY
189 LogNT::getInstance()->debug(TAG, "Shutdown start - Linux");
191 inputLinux->shutdown();
198 LogNT::getInstance()->debug(TAG, "Shutdown start - CEC");
199 inputCEC->shutdown();
208 LogNT::getInstance()->debug(TAG, "Shutdown start - UDP");
210 inputUDP->shutdown();
217 LogNT::getInstance()->debug(TAG, "Shutdown start - LIRC");
219 inputLirc->shutdown();
227 bool InputMan::mayHaveFewButtons()
229 // 052 returned true if remotelinux was in effect - linux or CEC. What was it for?
231 if (inputLinux || inputCEC) return true;
235 bool InputMan::handlesVolume()
237 #ifdef VOMP_PLATFORM_RASPBERRY
238 if (!inputCEC) return false;
239 return inputCEC->handlesVolume();
245 void InputMan::volumeUp()
247 #ifdef VOMP_PLATFORM_RASPBERRY
248 if (inputCEC) inputCEC->volumeUp();
252 void InputMan::volumeDown()
254 #ifdef VOMP_PLATFORM_RASPBERRY
255 if (inputCEC) inputCEC->volumeDown();
259 void InputMan::volumeMute()
261 #ifdef VOMP_PLATFORM_RASPBERRY
262 if (inputCEC) inputCEC->volumeMute();
266 void InputMan::changePowerState(bool powerOn)
268 #ifdef VOMP_PLATFORM_RASPBERRY
269 if (inputCEC) inputCEC->changePowerState(powerOn);
273 bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane)
275 #ifdef VOMP_PLATFORM_RASPBERRY
276 if (inputLinux) inputLinux->addOptionsToPanes(panenumber, options, pane);
277 if (inputCEC) inputCEC->addOptionsToPanes(panenumber, options, pane);
280 return true; // FIXME
283 bool InputMan::addOptionPagesToWTB(WTabBar *wtb)
285 WRemoteConfig* wrc = new WRemoteConfig();
286 wtb->addTab(tr("Remote Control"), wrc);
288 return true; // FIXME
291 bool InputMan::loadOptionsFromServer(VDR* vdr)
293 #ifdef VOMP_PLATFORM_RASPBERRY
294 if (inputLinux) inputLinux->loadOptionsFromServer(vdr);
295 if (inputCEC) inputCEC->loadOptionsFromServer(vdr);
298 return true; // FIXME
301 bool InputMan::saveOptionstoServer()
303 #ifdef VOMP_PLATFORM_RASPBERRY
304 if (inputLinux) inputLinux->saveOptionstoServer();
305 if (inputCEC) inputCEC->saveOptionstoServer();
307 return true; // FIXME
310 const char* InputMan::getVompKeyName(UCHAR number)
314 case Input::VOLUMEUP:
315 return tr("Volume Up");
316 case Input::VOLUMEDOWN:
317 return tr("Volume Down");
318 case Input::CHANNELUP:
319 return tr("Channel up");
320 case Input::CHANNELDOWN:
321 return tr("Channel down");
363 return tr("Reverse");
367 return tr("Forward");
374 case Input::SKIPBACK:
375 return tr("Skip back");
376 case Input::SKIPFORWARD:
377 return tr("Skip forward");
381 return tr("Fullscreen");
388 case Input::PICTURES:
389 return tr("Pictures");
400 case Input::PREVCHANNEL:
401 return tr("Previous Channel");
406 case Input::PLAYPAUSE:
407 return tr("Play/Pause");
414 const UCHAR InputMan::getVompKeyNumber(const char* vompKeyName)
416 if (!strcmp(vompKeyName, "VOLUMEUP")) return Input::VOLUMEUP;
417 else if (!strcmp(vompKeyName, "VOLUMEDOWN")) return Input::VOLUMEDOWN;
418 else if (!strcmp(vompKeyName, "CHANNELUP")) return Input::CHANNELUP;
419 else if (!strcmp(vompKeyName, "CHANNELDOWN")) return Input::CHANNELDOWN;
420 else if (!strcmp(vompKeyName, "ZERO")) return Input::ZERO;
421 else if (!strcmp(vompKeyName, "ONE")) return Input::ONE;
422 else if (!strcmp(vompKeyName, "TWO")) return Input::TWO;
423 else if (!strcmp(vompKeyName, "THREE")) return Input::THREE;
424 else if (!strcmp(vompKeyName, "FOUR")) return Input::FOUR;
425 else if (!strcmp(vompKeyName, "FIVE")) return Input::FIVE;
426 else if (!strcmp(vompKeyName, "SIX")) return Input::SIX;
427 else if (!strcmp(vompKeyName, "SEVEN")) return Input::SEVEN;
428 else if (!strcmp(vompKeyName, "EIGHT")) return Input::EIGHT;
429 else if (!strcmp(vompKeyName, "NINE")) return Input::NINE;
430 else if (!strcmp(vompKeyName, "POWER")) return Input::POWER;
431 else if (!strcmp(vompKeyName, "GO")) return Input::GO;
432 else if (!strcmp(vompKeyName, "BACK")) return Input::BACK;
433 else if (!strcmp(vompKeyName, "MENU")) return Input::MENU;
434 else if (!strcmp(vompKeyName, "RED")) return Input::RED;
435 else if (!strcmp(vompKeyName, "GREEN")) return Input::GREEN;
436 else if (!strcmp(vompKeyName, "YELLOW")) return Input::YELLOW;
437 else if (!strcmp(vompKeyName, "BLUE")) return Input::BLUE;
438 else if (!strcmp(vompKeyName, "MUTE")) return Input::MUTE;
439 else if (!strcmp(vompKeyName, "RADIO")) return Input::RADIO;
440 else if (!strcmp(vompKeyName, "REVERSE")) return Input::REVERSE;
441 else if (!strcmp(vompKeyName, "PLAY")) return Input::PLAY;
442 else if (!strcmp(vompKeyName, "FORWARD")) return Input::FORWARD;
443 else if (!strcmp(vompKeyName, "RECORD")) return Input::RECORD;
444 else if (!strcmp(vompKeyName, "STOP")) return Input::STOP;
445 else if (!strcmp(vompKeyName, "PAUSE")) return Input::PAUSE;
446 else if (!strcmp(vompKeyName, "SKIPBACK")) return Input::SKIPBACK;
447 else if (!strcmp(vompKeyName, "SKIPFORWARD")) return Input::SKIPFORWARD;
448 else if (!strcmp(vompKeyName, "OK")) return Input::OK;
449 else if (!strcmp(vompKeyName, "FULL")) return Input::FULL;
450 else if (!strcmp(vompKeyName, "TV")) return Input::TV;
451 else if (!strcmp(vompKeyName, "VIDEOS")) return Input::VIDEOS;
452 else if (!strcmp(vompKeyName, "MUSIC")) return Input::MUSIC;
453 else if (!strcmp(vompKeyName, "PICTURES")) return Input::PICTURES;
454 else if (!strcmp(vompKeyName, "GUIDE")) return Input::GUIDE;
455 else if (!strcmp(vompKeyName, "UP")) return Input::UP;
456 else if (!strcmp(vompKeyName, "DOWN")) return Input::DOWN;
457 else if (!strcmp(vompKeyName, "LEFT")) return Input::LEFT;
458 else if (!strcmp(vompKeyName, "RIGHT")) return Input::RIGHT;
459 else if (!strcmp(vompKeyName, "PREVCHANNEL")) return Input::PREVCHANNEL;
460 else if (!strcmp(vompKeyName, "STAR")) return Input::STAR;
461 else if (!strcmp(vompKeyName, "HASH")) return Input::HASH;
462 else if (!strcmp(vompKeyName, "PLAYPAUSE")) return Input::PLAYPAUSE;
463 else if (!strcmp(vompKeyName, "POWERON")) return Input::POWERON;
464 else if (!strcmp(vompKeyName, "POWEROFF")) return Input::POWEROFF;
465 else return Input::NA_UNKNOWN;
468 std::string InputMan::getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey)
470 // Go through each active Input class and get the hardware key name for vompKey
472 // which doesn't make any sense
474 std::string keyNames;
476 #ifdef VOMP_PLATFORM_RASPBERRY
479 std::string k = inputLinux->getHardCodedHardwareKeyNamesForVompKey(vompKey);
480 if (k.size()) keyNames += k;
485 std::string k = inputCEC->getHardCodedHardwareKeyNamesForVompKey(vompKey);
486 if (k.size()) { keyNames += ", "; keyNames += k; }
492 std::string k = inputUDP->getHardCodedHardwareKeyNamesForVompKey(vompKey);
493 if (k.size()) { keyNames += ", "; keyNames += k; }
499 std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
501 std::string keyNames;
503 #ifdef VOMP_PLATFORM_RASPBERRY
506 std::string k = inputLinux->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
507 if (k.size()) keyNames += k;
512 std::string k = inputCEC->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
513 if (k.size()) { keyNames += ", "; keyNames += k; }
519 std::string k = inputUDP->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
520 if (k.size()) { keyNames += ", "; keyNames += k; }
526 void InputMan::ResetToDefault()
528 #ifdef VOMP_PLATFORM_RASPBERRY
530 if (inputLinux) inputLinux->ResetToDefault();
532 if (inputCEC) inputCEC->ResetToDefault();
536 if (inputUDP) inputUDP->ResetToDefault();
539 void InputMan::EnterLearningMode(UCHAR vompKey)
541 #ifdef VOMP_PLATFORM_RASPBERRY
542 if (inputLinux) inputLinux->EnterLearningMode(vompKey);
544 // if (inputCEC) inputCEC->EnterLearningMode(); FIXME - is there any such thing?
548 void InputMan::cancelLearnMode()
550 #ifdef VOMP_PLATFORM_RASPBERRY
551 if (inputLinux) inputLinux->cancelLearnMode();
552 if (inputCEC) inputCEC->cancelLearnMode();
554 if (inputUDP) inputUDP->cancelLearnMode();