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 static const char* TAG = "Input";
32 void Input::ResetToDefault()
35 InitHWCListwithDefaults();
38 UCHAR Input::TranslateHWC(HWC_TYPE code)
40 UCHAR ret = TranslateHWCFixed(code);
42 if (ret != NA_UNKNOWN) // Found in fixed list
44 InputMan::getInstance()->cancelLearnMode(); // Just in case
48 return TranslateHWCList(code);
51 UCHAR Input::TranslateHWCList(HWC_TYPE code)
53 if (learnMode != NOLEARNMODE)
55 setHWCtoCommand(code, static_cast<UCHAR>(learnMode));
56 InputMan::getInstance()->cancelLearnMode();
59 RemoteTranslationList::iterator it = translist.find(code);
60 if (it == translist.end())
70 void Input::setHWCtoCommand(HWC_TYPE hcw, UCHAR command)
72 translist[hcw] = command;
75 void Input::unsetHWC(HWC_TYPE hcw) // FIXME never used
80 void Input::LoadKeysConfig(VDR *vdr,const char *cfg)
83 if (sscanf(cfg,"%ld",&number) != 1) return;
84 LogNT::getInstance()->info(TAG, "Config Input/Remote keys num keys {}", number);
86 for (ULONG i = 0; i < number; i++) {
87 sprintf(keybuf, "RemoteKey%lu", i);
88 const char *keytrans = vdr->configLoad(modName(), keybuf);
92 if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
93 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
101 // FIXME - These two still use the bit shifting stuff. Leave it for now, might still
102 // need it for Windows
104 void Input::SaveKeysConfig()
109 RemoteTranslationList::const_iterator it;
110 for (it = translist.begin(); it != translist.end(); it++)
112 sprintf(buffer,"%08lXI%08lXK%02X",
113 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
114 sprintf(keybuf,"RemoteKey%d",number);
115 VDR::getInstance()->configSave(modName(), keybuf, buffer);
118 sprintf(buffer,"%d",number);
119 VDR::getInstance()->configSave(modName(), "RemoteKeyNum", buffer);
122 bool Input::loadOptionsFromServer(VDR* vdr)
126 config = vdr->configLoad(modName(), "RemoteKeyNum");
130 LogNT::getInstance()->info(TAG, "Config Input/Remote keys load");
131 LoadKeysConfig(vdr,config);
136 LogNT::getInstance()->info(TAG, "Config Input/Remote keys not found");
137 InitHWCListwithDefaults();
142 bool Input::saveOptionstoServer()
148 void Input::sendInputKey(int key)
150 Message* m = new Message();
151 m->message = Message::INPUT_EVENT;
152 m->p_to = Message::CONTROL;
155 MessageQueue::getInstance()->postMessage(m);
158 std::string Input::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
160 std::string keyNames;
161 keyNames.reserve(50);
162 int keys = 0; // max 10
163 RemoteTranslationList::const_iterator it;
165 for (it = translist.begin(); it != translist.end(); it++)
167 if (it->second == vompKey)
169 if (!first) keyNames += ", ";
172 keyNames += getHardwareKeyName(it->first);
174 if (keys == 10) break;