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 InputMan* InputMan::instance = NULL;
50 InputMan* InputMan::getInstance()
60 #ifdef VOMP_PLATFORM_RASPBERRY
61 inputLinux = new InputLinux();
62 ret = inputLinux->init();
66 { delete inputLinux; inputLinux = NULL; }
68 bool cecEnabled = true;
69 Config::getInstance()->getBool("input", "mod_cec_enabled", cecEnabled);
72 inputCEC = new InputCEC();
73 ret = inputCEC->init();
77 { delete inputCEC; inputCEC = NULL; }
81 bool udpEnabled = true;
82 Config::getInstance()->getBool("input", "mod_udp_enabled", udpEnabled);
85 inputUDP = new InputUDP();
86 ret = inputUDP->init();
90 { delete inputUDP; inputUDP = NULL; }
93 bool lircEnabled = false;
94 Config::getInstance()->getBool("input", "mod_lirc_enabled", lircEnabled);
97 inputLirc = new InputLIRC();
98 ret = inputLirc->init();
102 { delete inputLirc; inputLirc = NULL; }
106 inputWin = new InputWin();
107 ret = inputWin->init();
111 { delete inputWin; inputWin = NULL; }
116 Log::getInstance()->log("InputMan", Log::CRIT, "InputMan could not init any input module");
124 bool InputMan::start()
126 Log::getInstance()->log("InputMan", Log::DEBUG, "Start");
130 #ifdef VOMP_PLATFORM_RASPBERRY
131 if (inputLinux && inputLinux->start()) oneOK = true;
134 if (inputUDP && inputUDP->start()) oneOK = true;
139 bool checkA = Config::getInstance()->getString("input", "lirc_ip", lircIP);
141 bool checkB = Config::getInstance()->getInt("input", "lirc_port", lircPort);
143 if (!checkA || !checkB)
150 if (inputLirc->start(lircIP, lircPort))
163 Log::getInstance()->log("InputMan", Log::CRIT, "InputMan could not start any input module");
168 void InputMan::stop()
170 Log::getInstance()->log("InputMan", Log::DEBUG, "Stop called");
172 #ifdef VOMP_PLATFORM_RASPBERRY
173 if (inputLinux) inputLinux->stop();
175 if (inputUDP) inputUDP->stop();
176 if (inputLirc) inputLirc->stop();
179 void InputMan::shutdown()
181 Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start");
183 #ifdef VOMP_PLATFORM_RASPBERRY
187 Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - Linux");
189 inputLinux->shutdown();
196 Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - CEC");
197 inputCEC->shutdown();
206 Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - UDP");
208 inputUDP->shutdown();
215 Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - LIRC");
217 inputLirc->shutdown();
225 bool InputMan::mayHaveFewButtons()
227 // 052 returned true if remotelinux was in effect - linux or CEC. What was it for?
229 if (inputLinux || inputCEC) return true;
233 bool InputMan::handlesVolume()
235 #ifdef VOMP_PLATFORM_RASPBERRY
236 if (!inputCEC) return false;
237 return inputCEC->handlesVolume();
243 void InputMan::volumeUp()
245 #ifdef VOMP_PLATFORM_RASPBERRY
246 if (inputCEC) inputCEC->volumeUp();
250 void InputMan::volumeDown()
252 #ifdef VOMP_PLATFORM_RASPBERRY
253 if (inputCEC) inputCEC->volumeDown();
257 void InputMan::volumeMute()
259 #ifdef VOMP_PLATFORM_RASPBERRY
260 if (inputCEC) inputCEC->volumeMute();
264 void InputMan::changePowerState(bool powerOn)
266 #ifdef VOMP_PLATFORM_RASPBERRY
267 if (inputCEC) inputCEC->changePowerState(powerOn);
271 bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane)
273 #ifdef VOMP_PLATFORM_RASPBERRY
274 if (inputLinux) inputLinux->addOptionsToPanes(panenumber, options, pane);
275 if (inputCEC) inputCEC->addOptionsToPanes(panenumber, options, pane);
278 return true; // FIXME
281 bool InputMan::addOptionPagesToWTB(WTabBar *wtb)
283 WRemoteConfig* wrc = new WRemoteConfig();
284 wtb->addTab(tr("Remote Control"), wrc);
286 return true; // FIXME
289 bool InputMan::loadOptionsFromServer(VDR* vdr)
291 #ifdef VOMP_PLATFORM_RASPBERRY
292 if (inputLinux) inputLinux->loadOptionsFromServer(vdr);
293 if (inputCEC) inputCEC->loadOptionsFromServer(vdr);
296 return true; // FIXME
299 bool InputMan::saveOptionstoServer()
301 #ifdef VOMP_PLATFORM_RASPBERRY
302 if (inputLinux) inputLinux->saveOptionstoServer();
303 if (inputCEC) inputCEC->saveOptionstoServer();
305 return true; // FIXME
308 const char* InputMan::getVompKeyName(UCHAR number)
312 case Input::VOLUMEUP:
313 return tr("Volume Up");
314 case Input::VOLUMEDOWN:
315 return tr("Volume Down");
316 case Input::CHANNELUP:
317 return tr("Channel up");
318 case Input::CHANNELDOWN:
319 return tr("Channel down");
361 return tr("Reverse");
365 return tr("Forward");
372 case Input::SKIPBACK:
373 return tr("Skip back");
374 case Input::SKIPFORWARD:
375 return tr("Skip forward");
379 return tr("Fullscreen");
386 case Input::PICTURES:
387 return tr("Pictures");
398 case Input::PREVCHANNEL:
399 return tr("Previous Channel");
404 case Input::PLAYPAUSE:
405 return tr("Play/Pause");
412 const UCHAR InputMan::getVompKeyNumber(const char* vompKeyName)
414 if (!strcmp(vompKeyName, "VOLUMEUP")) return Input::VOLUMEUP;
415 else if (!strcmp(vompKeyName, "VOLUMEDOWN")) return Input::VOLUMEDOWN;
416 else if (!strcmp(vompKeyName, "CHANNELUP")) return Input::CHANNELUP;
417 else if (!strcmp(vompKeyName, "CHANNELDOWN")) return Input::CHANNELDOWN;
418 else if (!strcmp(vompKeyName, "ZERO")) return Input::ZERO;
419 else if (!strcmp(vompKeyName, "ONE")) return Input::ONE;
420 else if (!strcmp(vompKeyName, "TWO")) return Input::TWO;
421 else if (!strcmp(vompKeyName, "THREE")) return Input::THREE;
422 else if (!strcmp(vompKeyName, "FOUR")) return Input::FOUR;
423 else if (!strcmp(vompKeyName, "FIVE")) return Input::FIVE;
424 else if (!strcmp(vompKeyName, "SIX")) return Input::SIX;
425 else if (!strcmp(vompKeyName, "SEVEN")) return Input::SEVEN;
426 else if (!strcmp(vompKeyName, "EIGHT")) return Input::EIGHT;
427 else if (!strcmp(vompKeyName, "NINE")) return Input::NINE;
428 else if (!strcmp(vompKeyName, "POWER")) return Input::POWER;
429 else if (!strcmp(vompKeyName, "GO")) return Input::GO;
430 else if (!strcmp(vompKeyName, "BACK")) return Input::BACK;
431 else if (!strcmp(vompKeyName, "MENU")) return Input::MENU;
432 else if (!strcmp(vompKeyName, "RED")) return Input::RED;
433 else if (!strcmp(vompKeyName, "GREEN")) return Input::GREEN;
434 else if (!strcmp(vompKeyName, "YELLOW")) return Input::YELLOW;
435 else if (!strcmp(vompKeyName, "BLUE")) return Input::BLUE;
436 else if (!strcmp(vompKeyName, "MUTE")) return Input::MUTE;
437 else if (!strcmp(vompKeyName, "RADIO")) return Input::RADIO;
438 else if (!strcmp(vompKeyName, "REVERSE")) return Input::REVERSE;
439 else if (!strcmp(vompKeyName, "PLAY")) return Input::PLAY;
440 else if (!strcmp(vompKeyName, "FORWARD")) return Input::FORWARD;
441 else if (!strcmp(vompKeyName, "RECORD")) return Input::RECORD;
442 else if (!strcmp(vompKeyName, "STOP")) return Input::STOP;
443 else if (!strcmp(vompKeyName, "PAUSE")) return Input::PAUSE;
444 else if (!strcmp(vompKeyName, "SKIPBACK")) return Input::SKIPBACK;
445 else if (!strcmp(vompKeyName, "SKIPFORWARD")) return Input::SKIPFORWARD;
446 else if (!strcmp(vompKeyName, "OK")) return Input::OK;
447 else if (!strcmp(vompKeyName, "FULL")) return Input::FULL;
448 else if (!strcmp(vompKeyName, "TV")) return Input::TV;
449 else if (!strcmp(vompKeyName, "VIDEOS")) return Input::VIDEOS;
450 else if (!strcmp(vompKeyName, "MUSIC")) return Input::MUSIC;
451 else if (!strcmp(vompKeyName, "PICTURES")) return Input::PICTURES;
452 else if (!strcmp(vompKeyName, "GUIDE")) return Input::GUIDE;
453 else if (!strcmp(vompKeyName, "UP")) return Input::UP;
454 else if (!strcmp(vompKeyName, "DOWN")) return Input::DOWN;
455 else if (!strcmp(vompKeyName, "LEFT")) return Input::LEFT;
456 else if (!strcmp(vompKeyName, "RIGHT")) return Input::RIGHT;
457 else if (!strcmp(vompKeyName, "PREVCHANNEL")) return Input::PREVCHANNEL;
458 else if (!strcmp(vompKeyName, "STAR")) return Input::STAR;
459 else if (!strcmp(vompKeyName, "HASH")) return Input::HASH;
460 else if (!strcmp(vompKeyName, "PLAYPAUSE")) return Input::PLAYPAUSE;
461 else if (!strcmp(vompKeyName, "POWERON")) return Input::POWERON;
462 else if (!strcmp(vompKeyName, "POWEROFF")) return Input::POWEROFF;
466 std::string InputMan::getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey)
468 // Go through each active Input class and get the hardware key name for vompKey
470 // which doesn't make any sense
472 std::string keyNames;
474 #ifdef VOMP_PLATFORM_RASPBERRY
477 std::string k = inputLinux->getHardCodedHardwareKeyNamesForVompKey(vompKey);
478 if (k.size()) keyNames += k;
483 std::string k = inputCEC->getHardCodedHardwareKeyNamesForVompKey(vompKey);
484 if (k.size()) { keyNames += ", "; keyNames += k; }
490 std::string k = inputUDP->getHardCodedHardwareKeyNamesForVompKey(vompKey);
491 if (k.size()) { keyNames += ", "; keyNames += k; }
497 std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
499 std::string keyNames;
501 #ifdef VOMP_PLATFORM_RASPBERRY
504 std::string k = inputLinux->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
505 if (k.size()) keyNames += k;
510 std::string k = inputCEC->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
511 if (k.size()) { keyNames += ", "; keyNames += k; }
517 std::string k = inputUDP->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
518 if (k.size()) { keyNames += ", "; keyNames += k; }
524 void InputMan::ResetToDefault()
526 #ifdef VOMP_PLATFORM_RASPBERRY
528 if (inputLinux) inputLinux->ResetToDefault();
530 if (inputCEC) inputCEC->ResetToDefault();
534 if (inputUDP) inputUDP->ResetToDefault();
537 void InputMan::EnterLearningMode(UCHAR vompKey)
539 #ifdef VOMP_PLATFORM_RASPBERRY
540 if (inputLinux) inputLinux->EnterLearningMode(vompKey);
542 // if (inputCEC) inputCEC->EnterLearningMode(); FIXME - is there any such thing?
546 void InputMan::cancelLearnMode()
548 #ifdef VOMP_PLATFORM_RASPBERRY
549 if (inputLinux) inputLinux->cancelLearnMode();
550 if (inputCEC) inputCEC->cancelLearnMode();
552 if (inputUDP) inputUDP->cancelLearnMode();