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
33 learnmode = NOLEARNMODE;
40 void Input::EnterLearningMode(UCHAR command)
42 learnmode = command; //Armed
45 void Input::ResetToDefault()
48 InitHWCListwithDefaults();
51 UCHAR Input::TranslateHWCList(int code)
53 if (learnmode != NOLEARNMODE)
55 setHWCtoCommand(code, learnmode);
56 learnmode = NOLEARNMODE;
59 RemoteTranslationList::iterator it = translist.find(code);
60 if (it == translist.end())
70 UCHAR Input::TranslateHWC(int code)
72 UCHAR ret = TranslateHWCFixed(code);
73 if (ret == NA_UNKNOWN)
75 ret = TranslateHWCList(code);
79 learnmode = NOLEARNMODE;
82 if (ret == NA_UNKNOWN)
89 void Input::setHWCtoCommand(ULLONG hcw, UCHAR command)
91 translist[hcw] = command;
94 void Input::unsetHWC(ULLONG hcw)
99 void Input::LoadKeysConfig(VDR *vdr,const char *cfg)
102 if (sscanf(cfg,"%ld",&number) != 1) return;
103 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys num keys %d",number);
105 for (ULONG i = 0; i < number; i++) {
106 sprintf(keybuf, "RemoteKey%lu", i);
107 const char *keytrans = vdr->configLoad("General", keybuf);
111 if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
112 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
120 void Input::SaveKeysConfig()
125 RemoteTranslationList::const_iterator it;
126 for (it = translist.begin(); it != translist.end(); it++)
128 sprintf(buffer,"%08lXI%08lXK%02X",
129 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
130 sprintf(keybuf,"RemoteKey%d",number);
131 VDR::getInstance()->configSave("General",keybuf,buffer);
134 sprintf(buffer,"%d",number);
135 VDR::getInstance()->configSave("General","RemoteKeyNum",buffer);
139 // bool Input::addOptionPagesToWTB(WTabBar *wtb)
141 // WRemoteConfig* wrc = new WRemoteConfig();
142 // wtb->addTab(tr("Remote Control"), wrc);
146 bool Input::loadOptionsfromServer(VDR* vdr)
150 config = vdr->configLoad("General", "RemoteKeyNum");
154 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys load");
155 LoadKeysConfig(vdr,config);
160 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys not found");
161 InitHWCListwithDefaults();
166 bool Input::saveOptionstoServer()
172 void Input::sendInputKey(int key)
174 Message* m = new Message();
175 m->message = Message::INPUT_EVENT;
176 m->to = Command::getInstance();
178 m->parameter = TranslateHWC(key);
179 MessageQueue::getInstance()->postMessage(m);
182 std::string Input::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
184 std::string keyNames;
185 keyNames.reserve(50);
186 int keys = 0; // max 10
187 RemoteTranslationList::const_iterator it;
189 for (it = translist.begin(); it != translist.end(); it++)
191 if (it->second == vompKey)
193 if (!first) keyNames += ", ";
196 keyNames += getHardwareKeyName(it->first);
198 if (keys == 10) break;