From db57f350bb309320411b9e55df77f22914ed4e55 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 17 Feb 2020 16:17:47 +0000 Subject: [PATCH] WIP --- abstractoption.cc | 2 +- abstractoption.h | 2 +- audioomx.cc | 2 +- audioomx.h | 2 +- audiowin.cc | 2 +- audiowin.h | 2 +- command.cc | 6 ++-- input.cc | 79 ++++++++++++++++------------------------------- input.h | 17 +++++----- inputcec.cc | 4 +-- inputcec.h | 4 ++- inputlinux.cc | 7 +++++ inputlinux.h | 5 ++- inputman.cc | 40 ++++++++++++++++++++---- inputman.h | 5 +++ inputudp.h | 6 ++-- mediaoptions.cc | 2 +- mediaoptions.h | 2 +- videoomx.cc | 2 +- videoomx.h | 2 +- videowin.cc | 2 +- videowin.h | 2 +- wremoteconfig.cc | 4 +-- 23 files changed, 110 insertions(+), 91 deletions(-) diff --git a/abstractoption.cc b/abstractoption.cc index 586a8f7..6e9d13a 100644 --- a/abstractoption.cc +++ b/abstractoption.cc @@ -22,7 +22,7 @@ #include "option.h" /* -bool AbstractOption::loadOptionsfromServer(VDR* vdr) +bool AbstractOption::loadOptionsFromServer(VDR* vdr) { return true; } diff --git a/abstractoption.h b/abstractoption.h index 21338dd..7933300 100644 --- a/abstractoption.h +++ b/abstractoption.h @@ -31,7 +31,7 @@ class AbstractOption { public: // inline definition allows plugins architecture for audio video - virtual bool loadOptionsfromServer(VDR*) { return true; }; + virtual bool loadOptionsFromServer(VDR*) { return true; }; virtual bool saveOptionstoServer() { return true; }; virtual bool addOptionPagesToWTB(WTabBar*) { return true; }; virtual bool addOptionsToPanes(int /* panenumber */, Options*, WOptionPane*) { return true; }; diff --git a/audioomx.cc b/audioomx.cc index b664925..f948e76 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -182,7 +182,7 @@ int AudioOMX::shutdown() return 1; } -bool AudioOMX::loadOptionsfromServer(VDR* vdr) +bool AudioOMX::loadOptionsFromServer(VDR* vdr) { Log::getInstance()->log("Audio", Log::DEBUG, "AudioOMX config load"); char *name=vdr->configLoad("AudioOMX","AC3DecodingMode"); diff --git a/audioomx.h b/audioomx.h index 3260380..c1a31a5 100644 --- a/audioomx.h +++ b/audioomx.h @@ -92,7 +92,7 @@ class AudioOMX : public Audio UCHAR getLastAType() {return lastAType;} - bool loadOptionsfromServer(VDR* vdr); + bool loadOptionsFromServer(VDR* vdr); bool saveOptionstoServer(); bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane); bool handleOptionChanges(Option* option); diff --git a/audiowin.cc b/audiowin.cc index 9903890..7e7a214 100644 --- a/audiowin.cc +++ b/audiowin.cc @@ -308,7 +308,7 @@ void AudioWin::initMp3FilterDatabase() filtmap->Release(); } -bool AudioWin::loadOptionsfromServer(VDR* vdr) +bool AudioWin::loadOptionsFromServer(VDR* vdr) { char *name=vdr->configLoad("DirectShow","AudioFilter"); diff --git a/audiowin.h b/audiowin.h index c3eed89..8617e6c 100644 --- a/audiowin.h +++ b/audiowin.h @@ -58,7 +58,7 @@ class AudioWin : public Audio int unMute(); int write(char *buf, int len); - bool loadOptionsfromServer(VDR* vdr); + bool loadOptionsFromServer(VDR* vdr); bool saveOptionstoServer(); bool addOptionPagesToWTB(WTabBar *wtb); diff --git a/command.cc b/command.cc index 96336f6..ab7b758 100644 --- a/command.cc +++ b/command.cc @@ -1010,9 +1010,9 @@ void Command::doJustConnected(VConnect* vconnect) Wol::getInstance()->setEnabled(true); } /* device dependend config */ - audio->loadOptionsfromServer(vdr); - video->loadOptionsfromServer(vdr); - inputMan->loadOptionsfromServer(vdr); + audio->loadOptionsFromServer(vdr); + video->loadOptionsFromServer(vdr); + inputMan->loadOptionsFromServer(vdr); video->executePendingModeChanges(); // config done diff --git a/input.cc b/input.cc index a7767c9..1314ca3 100644 --- a/input.cc +++ b/input.cc @@ -28,32 +28,31 @@ #include "inputman.h" #include "input.h" -Input::Input() +void Input::ResetToDefault() { - learnmode = NOLEARNMODE; + translist.clear(); + InitHWCListwithDefaults(); } -Input::~Input() +UCHAR Input::TranslateHWC(int code) { -} + UCHAR ret = TranslateHWCFixed(code); -void Input::EnterLearningMode(UCHAR command) -{ - learnmode = command; //Armed -} + if (ret != NA_UNKNOWN) // Found in fixed list + { + InputMan::getInstance()->cancelLearnMode(); // Just in case + return ret; + } -void Input::ResetToDefault() -{ - translist.clear(); - InitHWCListwithDefaults(); + return TranslateHWCList(code); } UCHAR Input::TranslateHWCList(int code) { - if (learnmode != NOLEARNMODE) + if (learnMode != NOLEARNMODE) { - setHWCtoCommand(code, learnmode); - learnmode = NOLEARNMODE; + setHWCtoCommand(code, learnMode); + InputMan::getInstance()->cancelLearnMode(); return NA_LEARN; } RemoteTranslationList::iterator it = translist.find(code); @@ -67,31 +66,12 @@ UCHAR Input::TranslateHWCList(int code) } } -UCHAR Input::TranslateHWC(int code) -{ - UCHAR ret = TranslateHWCFixed(code); - if (ret == NA_UNKNOWN) - { - ret = TranslateHWCList(code); - } - else - { - learnmode = NOLEARNMODE; - } - - if (ret == NA_UNKNOWN) - { - return NA_UNKNOWN; - } - return ret; -} - void Input::setHWCtoCommand(ULLONG hcw, UCHAR command) { translist[hcw] = command; } -void Input::unsetHWC(ULLONG hcw) +void Input::unsetHWC(ULLONG hcw) // FIXME never used { translist.erase(hcw); } @@ -100,11 +80,11 @@ void Input::LoadKeysConfig(VDR *vdr,const char *cfg) { ULONG number=0; if (sscanf(cfg,"%ld",&number) != 1) return; - Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys num keys %d",number); + Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys num keys %d",number); char keybuf[1024]; for (ULONG i = 0; i < number; i++) { sprintf(keybuf, "RemoteKey%lu", i); - const char *keytrans = vdr->configLoad("General", keybuf); + const char *keytrans = vdr->configLoad(modName(), keybuf); if (keytrans) { ULONG ul1, ul2; ULONG uc; @@ -117,6 +97,9 @@ void Input::LoadKeysConfig(VDR *vdr,const char *cfg) } } +// FIXME - These two still use the bit shifting stuff. Leave it for now, might still +// need it for Windows + void Input::SaveKeysConfig() { int number=0; @@ -128,36 +111,28 @@ void Input::SaveKeysConfig() sprintf(buffer,"%08lXI%08lXK%02X", (ULONG)it->first ,(ULONG) (it->first >> 32), it->second); sprintf(keybuf,"RemoteKey%d",number); - VDR::getInstance()->configSave("General",keybuf,buffer); + VDR::getInstance()->configSave(modName(), keybuf, buffer); number++; } sprintf(buffer,"%d",number); - VDR::getInstance()->configSave("General","RemoteKeyNum",buffer); + VDR::getInstance()->configSave(modName(), "RemoteKeyNum", buffer); } - -// bool Input::addOptionPagesToWTB(WTabBar *wtb) -// { -// WRemoteConfig* wrc = new WRemoteConfig(); -// wtb->addTab(tr("Remote Control"), wrc); -// return true; -// } - -bool Input::loadOptionsfromServer(VDR* vdr) +bool Input::loadOptionsFromServer(VDR* vdr) { // Set remote keys char * config; - config = vdr->configLoad("General", "RemoteKeyNum"); + config = vdr->configLoad(modName(), "RemoteKeyNum"); if (config) { - Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys load"); + Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys load"); LoadKeysConfig(vdr,config); delete[] config; } else { - Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys not found"); + Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys not found"); InitHWCListwithDefaults(); } return true; @@ -175,7 +150,7 @@ void Input::sendInputKey(int key) m->message = Message::INPUT_EVENT; m->to = Command::getInstance(); m->from = this; - m->parameter = TranslateHWC(key); + m->parameter = key; MessageQueue::getInstance()->postMessage(m); } diff --git a/input.h b/input.h index 37c7b6c..e7842ef 100644 --- a/input.h +++ b/input.h @@ -35,22 +35,17 @@ typedef std::map RemoteTranslationList; class Input: public AbstractOption { public: - Input(); - virtual ~Input(); - virtual bool start() { return false; } virtual void stop() {} // Abstract Option interface - // virtual bool addOptionPagesToWTB(WTabBar *wtb); - virtual bool loadOptionsfromServer(VDR* vdr); + virtual bool loadOptionsFromServer(VDR* vdr); virtual bool saveOptionstoServer(); void setHWCtoCommand(ULLONG hcw, UCHAR command); void unsetHWC(ULLONG hcw); void LoadKeysConfig(VDR* vdr, const char* keynum); void SaveKeysConfig(); - void EnterLearningMode(UCHAR command); virtual bool init()=0; virtual void shutdown()=0; @@ -64,7 +59,8 @@ class Input: public AbstractOption virtual void InitHWCListwithDefaults()=0; std::string getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey); char* CommandTranslateStr(UCHAR command); - void EnterLearnMode(UCHAR command); + void EnterLearnMode(UCHAR /* command */ ) {}; // Override and set lernMode to command + void cancelLearnMode() { learnMode = NOLEARNMODE; } void ResetToDefault(); virtual std::string getHardwareKeyName(int hardwareKey)=0; @@ -137,12 +133,13 @@ class Input: public AbstractOption const static UCHAR POWEROFF = 203; protected: + virtual const char* modName()=0; + RemoteTranslationList translist; + int learnMode{NOLEARNMODE}; + virtual UCHAR TranslateHWCFixed(int code)=0; UCHAR TranslateHWCList(int code); UCHAR TranslateHWC(int code); - - ULONG learnmode; - RemoteTranslationList translist; void sendInputKey(int key); }; diff --git a/inputcec.cc b/inputcec.cc index 97cec37..976101a 100644 --- a/inputcec.cc +++ b/inputcec.cc @@ -163,7 +163,7 @@ void InputCEC::volumeMute() cec_adap->AudioToggleMute(); } -bool InputCEC::loadOptionsfromServer(VDR* vdr) +bool InputCEC::loadOptionsFromServer(VDR* vdr) { // Set remote keys char* name; @@ -175,7 +175,7 @@ bool InputCEC::loadOptionsfromServer(VDR* vdr) else if (STRCASECMP(name, "Cec") == 0) cechandlesvolume = true; delete[] name; } - return Input::loadOptionsfromServer(vdr); + return Input::loadOptionsFromServer(vdr); } bool InputCEC::saveOptionstoServer() diff --git a/inputcec.h b/inputcec.h index 172ccfa..11f9973 100644 --- a/inputcec.h +++ b/inputcec.h @@ -36,7 +36,7 @@ class InputCEC : public Input void volumeMute(); void changePowerState(bool poweron); - bool loadOptionsfromServer(VDR* vdr); + bool loadOptionsFromServer(VDR* vdr); bool saveOptionstoServer(); bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane); bool handleOptionChanges(Option* option); @@ -45,6 +45,8 @@ class InputCEC : public Input const char* getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey); private: + constexpr static char* myModName = "InputCEC"; + const char* modName() { return myModName; } void InitKeymap(); void InitHWCListwithDefaults(); UCHAR TranslateHWCFixed(int code); diff --git a/inputlinux.cc b/inputlinux.cc index f7083d7..4c07644 100644 --- a/inputlinux.cc +++ b/inputlinux.cc @@ -129,6 +129,8 @@ UCHAR InputLinux::TranslateHWCFixed(int code) void InputLinux::InitHWCListwithDefaults() { + Log::getInstance()->log("InputLinux", Log::INFO, "InitHWCListwithDefaults"); + // Processing VK_Messages translist[KEY_9] = NINE; translist[KEY_8] = EIGHT; @@ -504,6 +506,11 @@ std::string InputLinux::getHardwareKeyName(int hardwareKey) return retval; } +void InputLinux::EnterLearningMode(UCHAR vompKey) +{ + learnMode = vompKey; // Armed +} + bool InputLinux::start() { Log::getInstance()->log("Input", Log::INFO, "start called"); diff --git a/inputlinux.h b/inputlinux.h index 5cbfe86..fd69f0c 100644 --- a/inputlinux.h +++ b/inputlinux.h @@ -36,18 +36,21 @@ class InputLinux : public Input std::string getHardwareKeyName(int hardwareKey); const char* getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey); + void EnterLearningMode(UCHAR vompKey); bool start(); void stop(); private: + constexpr static char* myModName = "InputLinux"; + const char* modName() { return myModName; } + int initted{}; void InitKeymap(); void InitHWCListwithDefaults(); UCHAR TranslateHWCFixed(int code); - std::vector devices; std::thread listenThread; diff --git a/inputman.cc b/inputman.cc index edbf4bd..ef13be5 100644 --- a/inputman.cc +++ b/inputman.cc @@ -54,9 +54,9 @@ bool InputMan::init() i1 = inputLinux->init(); if (!i1) { delete inputLinux; inputLinux = NULL; } -// inputCEC = new InputCEC(); -// i2 = inputCEC->init(); -// if (!i2) { delete inputCEC; inputCEC = NULL; } + inputCEC = new InputCEC(); + i2 = inputCEC->init(); + if (!i2) { delete inputCEC; inputCEC = NULL; } #endif inputUDP = new InputUDP(); @@ -176,15 +176,20 @@ bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* bool InputMan::addOptionPagesToWTB(WTabBar *wtb) { - //if (inputLinux) inputLinux->addOptionPagesToWTB(wtb); - //if (inputCEC) inputCEC->addOptionPagesToWTB(wtb); - WRemoteConfig* wrc = new WRemoteConfig(); wtb->addTab(tr("Remote Control"), wrc); return true; // FIXME } +bool InputMan::loadOptionsFromServer(VDR* vdr) +{ + if (inputLinux) inputLinux->loadOptionsFromServer(vdr); + if (inputCEC) inputCEC->loadOptionsFromServer(vdr); + + return true; // FIXME +} + bool InputMan::saveOptionstoServer() { if (inputLinux) inputLinux->saveOptionstoServer(); @@ -350,3 +355,26 @@ std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey) return keyNames; } + +void InputMan::ResetToDefault() +{ + if (inputLinux) inputLinux->ResetToDefault(); + + if (inputCEC) inputCEC->ResetToDefault(); + + if (inputUDP) inputUDP->ResetToDefault(); +} + +void InputMan::EnterLearningMode(UCHAR vompKey) +{ + if (inputLinux) inputLinux->EnterLearningMode(vompKey); + +// if (inputCEC) inputCEC->EnterLearningMode(); FIXME - is there any such thing? +} + +void InputMan::cancelLearnMode() +{ + if (inputLinux) inputLinux->cancelLearnMode(); + if (inputCEC) inputCEC->cancelLearnMode(); + if (inputUDP) inputUDP->cancelLearnMode(); +} diff --git a/inputman.h b/inputman.h index 1086bf2..f799afc 100644 --- a/inputman.h +++ b/inputman.h @@ -111,6 +111,7 @@ class InputMan: public AbstractOption // Abstract Option interface bool addOptionPagesToWTB(WTabBar* wtb); bool addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane); + bool loadOptionsFromServer(VDR*); bool saveOptionstoServer(); static const char* getVompKeyName(UCHAR vompKey); @@ -118,6 +119,10 @@ class InputMan: public AbstractOption std::string getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey); std::string getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey); + void EnterLearningMode(UCHAR vompKey); + void cancelLearnMode(); + void ResetToDefault(); + private: static InputMan* instance; diff --git a/inputudp.h b/inputudp.h index 1b634a0..1b61d1a 100644 --- a/inputudp.h +++ b/inputudp.h @@ -39,14 +39,16 @@ class InputUDP : public Input bool start(); void stop(); - // FIXME these 2.. + // InputUDP doesn't do any translation stuff so just keep everything happy here void InitHWCListwithDefaults() {}; UCHAR TranslateHWCFixed(int code) { return code; }; const char* getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey); std::string getHardwareKeyName(int hardwareKey); - private: + constexpr static char* myModName = "InputUDP"; + const char* modName() { return myModName; } + bool initted{}; DatagramSocket* ds{}; Log* log{}; diff --git a/mediaoptions.cc b/mediaoptions.cc index 2500354..8bbde18 100644 --- a/mediaoptions.cc +++ b/mediaoptions.cc @@ -59,7 +59,7 @@ MediaOptions::~MediaOptions() } -bool MediaOptions::loadOptionsfromServer(VDR* vdr) +bool MediaOptions::loadOptionsFromServer(VDR* vdr) { return true; } diff --git a/mediaoptions.h b/mediaoptions.h index f2ad8cb..5a9fe38 100644 --- a/mediaoptions.h +++ b/mediaoptions.h @@ -38,7 +38,7 @@ class MediaOptions: AbstractOption public: MediaOptions(); virtual ~MediaOptions(); - virtual bool loadOptionsfromServer(VDR* vdr); + virtual bool loadOptionsFromServer(VDR* vdr); virtual bool saveOptionstoServer(); //this can be called without the pane being active bool externSaveOptionstoServer(); diff --git a/videoomx.cc b/videoomx.cc index eed1f7c..8072910 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -241,7 +241,7 @@ int VideoOMX::shutdown() -bool VideoOMX::loadOptionsfromServer(VDR* vdr) +bool VideoOMX::loadOptionsFromServer(VDR* vdr) { Log::getInstance()->log("Video", Log::DEBUG, "VideoOMX config load"); char *name=vdr->configLoad("VideoOMX","SDDeinterlacing"); diff --git a/videoomx.h b/videoomx.h index 7b8ad14..a17b6b1 100644 --- a/videoomx.h +++ b/videoomx.h @@ -129,7 +129,7 @@ class VideoOMX : public Video long long SetStartAudioOffset(long long curreftime, bool *rsync); virtual void ResetTimeOffsets(); - bool loadOptionsfromServer(VDR* vdr); + bool loadOptionsFromServer(VDR* vdr); bool saveOptionstoServer(); bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane); bool handleOptionChanges(Option* option); diff --git a/videowin.cc b/videowin.cc index 2e73b7e..dcbf5dc 100644 --- a/videowin.cc +++ b/videowin.cc @@ -386,7 +386,7 @@ void VideoWin::initH264FilterDatabase() filtmap->Release(); } -bool VideoWin::loadOptionsfromServer(VDR* vdr) +bool VideoWin::loadOptionsFromServer(VDR* vdr) { char *name=vdr->configLoad("DirectShow","VideoFilter"); diff --git a/videowin.h b/videowin.h index 43ea009..f5a98c5 100644 --- a/videowin.h +++ b/videowin.h @@ -93,7 +93,7 @@ public: // ULLONG frameNumberToTimecode(ULONG framenumber); ULLONG getCurrentTimestamp(); - bool loadOptionsfromServer(VDR* vdr); + bool loadOptionsFromServer(VDR* vdr); bool saveOptionstoServer(); bool addOptionPagesToWTB(WTabBar *wtb); bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane); diff --git a/wremoteconfig.cc b/wremoteconfig.cc index 9eb5fb5..3aeef85 100644 --- a/wremoteconfig.cc +++ b/wremoteconfig.cc @@ -230,7 +230,7 @@ int WRemoteConfig::handleCommand(int command) case Input::OK: { learnmode = true; - // remote->EnterLearningMode(sl.getCurrentOptionData()); FIXME + InputMan::getInstance()->EnterLearningMode(sl.getCurrentOptionData()); return 1; } case Input::BACK: @@ -254,7 +254,7 @@ int WRemoteConfig::handleCommand(int command) } case Input::MENU: { - // remote->ResetToDefault(); FIXME + InputMan::getInstance()->ResetToDefault(); initSelectList(false); return 1; } -- 2.39.2