2 Copyright 2004-2020 Chris Tallon
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/>.
20 #include "wremoteconfig.h"
26 #include "messagequeue.h"
30 void Input::ResetToDefault()
33 InitHWCListwithDefaults();
36 UCHAR Input::TranslateHWC(HWC_TYPE code)
38 UCHAR ret = TranslateHWCFixed(code);
40 if (ret != NA_UNKNOWN) // Found in fixed list
42 InputMan::getInstance()->cancelLearnMode(); // Just in case
46 return TranslateHWCList(code);
49 UCHAR Input::TranslateHWCList(HWC_TYPE code)
51 if (learnMode != NOLEARNMODE)
53 setHWCtoCommand(code, static_cast<UCHAR>(learnMode));
54 InputMan::getInstance()->cancelLearnMode();
57 RemoteTranslationList::iterator it = translist.find(code);
58 if (it == translist.end())
68 void Input::setHWCtoCommand(HWC_TYPE hcw, UCHAR command)
70 translist[hcw] = command;
73 void Input::unsetHWC(HWC_TYPE hcw) // FIXME never used
78 void Input::LoadKeysConfig(VDR *vdr,const char *cfg)
81 if (sscanf(cfg,"%ld",&number) != 1) return;
82 Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys num keys %d",number);
84 for (ULONG i = 0; i < number; i++) {
85 sprintf(keybuf, "RemoteKey%lu", i);
86 const char *keytrans = vdr->configLoad(modName(), keybuf);
90 if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
91 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
99 // FIXME - These two still use the bit shifting stuff. Leave it for now, might still
100 // need it for Windows
102 void Input::SaveKeysConfig()
107 RemoteTranslationList::const_iterator it;
108 for (it = translist.begin(); it != translist.end(); it++)
110 sprintf(buffer,"%08lXI%08lXK%02X",
111 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
112 sprintf(keybuf,"RemoteKey%d",number);
113 VDR::getInstance()->configSave(modName(), keybuf, buffer);
116 sprintf(buffer,"%d",number);
117 VDR::getInstance()->configSave(modName(), "RemoteKeyNum", buffer);
120 bool Input::loadOptionsFromServer(VDR* vdr)
124 config = vdr->configLoad(modName(), "RemoteKeyNum");
128 Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys load");
129 LoadKeysConfig(vdr,config);
134 Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys not found");
135 InitHWCListwithDefaults();
140 bool Input::saveOptionstoServer()
146 void Input::sendInputKey(int key)
148 Message* m = new Message();
149 m->message = Message::INPUT_EVENT;
150 m->p_to = Message::CONTROL;
153 MessageQueue::getInstance()->postMessage(m);
156 std::string Input::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
158 std::string keyNames;
159 keyNames.reserve(50);
160 int keys = 0; // max 10
161 RemoteTranslationList::const_iterator it;
163 for (it = translist.begin(); it != translist.end(); it++)
165 if (it->second == vompKey)
167 if (!first) keyNames += ", ";
170 keyNames += getHardwareKeyName(it->first);
172 if (keys == 10) break;