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"
27 #include "command.h" // FIXME - get rid after predefined message targets
31 void Input::ResetToDefault()
34 InitHWCListwithDefaults();
37 UCHAR Input::TranslateHWC(HWC_TYPE code)
39 UCHAR ret = TranslateHWCFixed(code);
41 if (ret != NA_UNKNOWN) // Found in fixed list
43 InputMan::getInstance()->cancelLearnMode(); // Just in case
47 return TranslateHWCList(code);
50 UCHAR Input::TranslateHWCList(HWC_TYPE code)
52 if (learnMode != NOLEARNMODE)
54 setHWCtoCommand(code, learnMode);
55 InputMan::getInstance()->cancelLearnMode();
58 RemoteTranslationList::iterator it = translist.find(code);
59 if (it == translist.end())
69 void Input::setHWCtoCommand(HWC_TYPE hcw, UCHAR command)
71 translist[hcw] = command;
74 void Input::unsetHWC(HWC_TYPE hcw) // FIXME never used
79 void Input::LoadKeysConfig(VDR *vdr,const char *cfg)
82 if (sscanf(cfg,"%ld",&number) != 1) return;
83 Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys num keys %d",number);
85 for (ULONG i = 0; i < number; i++) {
86 sprintf(keybuf, "RemoteKey%lu", i);
87 const char *keytrans = vdr->configLoad(modName(), keybuf);
91 if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
92 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
100 // FIXME - These two still use the bit shifting stuff. Leave it for now, might still
101 // need it for Windows
103 void Input::SaveKeysConfig()
108 RemoteTranslationList::const_iterator it;
109 for (it = translist.begin(); it != translist.end(); it++)
111 sprintf(buffer,"%08lXI%08lXK%02X",
112 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
113 sprintf(keybuf,"RemoteKey%d",number);
114 VDR::getInstance()->configSave(modName(), keybuf, buffer);
117 sprintf(buffer,"%d",number);
118 VDR::getInstance()->configSave(modName(), "RemoteKeyNum", buffer);
121 bool Input::loadOptionsFromServer(VDR* vdr)
125 config = vdr->configLoad(modName(), "RemoteKeyNum");
129 Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys load");
130 LoadKeysConfig(vdr,config);
135 Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys not found");
136 InitHWCListwithDefaults();
141 bool Input::saveOptionstoServer()
147 void Input::sendInputKey(int key)
149 Message* m = new Message();
150 m->message = Message::INPUT_EVENT;
151 m->to = Command::getInstance();
154 MessageQueue::getInstance()->postMessage(m);
157 std::string Input::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
159 std::string keyNames;
160 keyNames.reserve(50);
161 int keys = 0; // max 10
162 RemoteTranslationList::const_iterator it;
164 for (it = translist.begin(); it != translist.end(); it++)
166 if (it->second == vompKey)
168 if (!first) keyNames += ", ";
171 keyNames += getHardwareKeyName(it->first);
173 if (keys == 10) break;