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"
27 Input* Input::instance = NULL;
33 remoteType = OLDREMOTE;
34 learnmode = NOLEARNMODE;
42 Input* Input::getInstance()
47 void Input::setRemoteType(UCHAR newType)
49 if ((newType != OLDREMOTE) && (newType != NEWREMOTE)) return;
53 void Input::EnterLearningMode(UCHAR command)
55 learnmode = command; //Armed
58 void Input::ResetToDefault()
61 InitHWCListwithDefaults();
65 UCHAR Input::TranslateHWCFixed(ULLONG code)
96 const char* Input::HardcodedTranslateStr(UCHAR command)
119 UCHAR Input::TranslateHWCList(ULLONG code)
121 if (learnmode != NOLEARNMODE)
123 setHWCtoCommand(code, learnmode);
124 learnmode = NOLEARNMODE;
127 RemoteTranslationList::iterator it = translist.find(code);
128 if (it == translist.end())
138 UCHAR Input::TranslateHWC(ULLONG code)
140 UCHAR ret = TranslateHWCFixed(code);
141 if (ret == NA_UNKNOWN)
143 ret = TranslateHWCList(code);
147 learnmode = NOLEARNMODE;
150 if (ret == NA_UNKNOWN)
157 void Input::setHWCtoCommand(ULLONG hcw, UCHAR command)
159 translist[hcw] = command;
162 void Input::unsetHWC(ULLONG hcw)
164 translist.erase(hcw);
167 void Input::LoadKeysConfig(VDR *vdr,const char *cfg)
170 if (sscanf(cfg,"%ld",&number) != 1) return;
171 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys num keys %d",number);
173 for (ULONG i = 0; i < number; i++) {
174 sprintf(keybuf, "RemoteKey%lu", i);
175 const char *keytrans = vdr->configLoad("General", keybuf);
179 if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
180 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
188 void Input::SaveKeysConfig()
193 RemoteTranslationList::const_iterator it;
194 for (it = translist.begin(); it != translist.end(); it++)
196 sprintf(buffer,"%08lXI%08lXK%02X",
197 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
198 sprintf(keybuf,"RemoteKey%d",number);
199 VDR::getInstance()->configSave("General",keybuf,buffer);
202 sprintf(buffer,"%d",number);
203 VDR::getInstance()->configSave("General","RemoteKeyNum",buffer);
207 void Input::InitHWCListwithDefaults()
209 translist[VOLUMEUP] = VOLUMEUP;
210 translist[VOLUMEDOWN] = VOLUMEDOWN;
211 translist[CHANNELUP] = CHANNELUP;
212 translist[CHANNELDOWN] = CHANNELDOWN;
215 translist[ZERO] = ZERO;
216 translist[ONE] = ONE;
217 translist[TWO] = TWO;
218 translist[THREE] = THREE;
219 translist[FOUR] = FOUR;
220 translist[FIVE] = FIVE;
221 translist[SIX] = SIX;
222 translist[SEVEN] = SEVEN;
223 translist[EIGHT] = EIGHT;
224 translist[NINE] = NINE;
225 translist[POWER] = POWER;
227 translist[RED] = RED;
228 translist[GREEN] = GREEN;
229 translist[YELLOW] = YELLOW;
230 translist[BLUE] = BLUE;
232 translist[MUTE] = MUTE;
233 translist[RADIO] = RADIO;
234 translist[REVERSE] = REVERSE;
235 translist[FORWARD] = FORWARD;
236 translist[RECORD] = RECORD;
237 translist[STOP] = STOP;
238 translist[PAUSE] = PAUSE;
239 translist[PLAY] = PLAY;
240 translist[SKIPBACK] = SKIPBACK;
241 translist[SKIPFORWARD] = SKIPFORWARD;
244 translist[FULL] = FULL;
248 translist[VIDEOS] = VIDEOS;
249 translist[MUSIC] = MUSIC;
250 translist[PICTURES] = PICTURES;
251 translist[GUIDE] = GUIDE;
252 translist[PREVCHANNEL] = PREVCHANNEL;
253 translist[STAR] = STAR;
254 translist[HASH] = HASH;
257 const char* Input::CommandDesc(UCHAR number)
262 return tr("Volume Up");
265 return tr("Volume Down");
267 return tr("Channel up");
269 return tr("Channel down");
311 return tr("Reverse");
315 return tr("Forward");
323 return tr("Skip back");
325 return tr("Skip forward");
329 return tr("Fullscreen");
337 return tr("Pictures");
349 return tr("Previous Channel");
355 return tr("Play/Pause");
362 char* Input::HCWDesc(ULLONG hcw)
365 temp=(char*)CommandDesc((UCHAR)hcw);
368 dest=new char[strlen(temp)+1];
374 sprintf(dest,"C:%lX",(ULONG)hcw);
379 char* Input::CommandTranslateStr(UCHAR command)
382 int length=5;//:+\t+0
383 int keys=0; //max 10;
384 char *commanddesc=(char*)CommandDesc(command);
385 if (commanddesc != NULL)
387 length+=strlen(commanddesc);
389 char *preassigneddesc=(char*)HardcodedTranslateStr(command);
390 if (preassigneddesc != NULL)
392 length+=strlen(preassigneddesc);
396 RemoteTranslationList::const_iterator it;
397 for (it = translist.begin(); it != translist.end(); it++)
399 if (it->second == command)
401 keydesc[keys] = HCWDesc(it->first);
402 length += strlen(keydesc[keys])+2;
404 if (keys == 10) break;
408 desc=new char [length];
410 if (commanddesc != NULL)
412 current+=sprintf(current,"%s:\t ",commanddesc);
416 current+=sprintf(current,":\t ");
418 if (preassigneddesc != NULL)
420 current+=sprintf(current,"%s\t",preassigneddesc);
424 current+=sprintf(current,"\t");
426 for (int i = 0;i < keys; i++)
428 current += sprintf(current,"%s, ",keydesc[i]);
429 delete [] keydesc[i];
434 bool Input::addOptionPagesToWTB(WTabBar *wtb)
436 WRemoteConfig* wrc = new WRemoteConfig();
437 wtb->addTab(tr("Remote Control"), wrc);
441 bool Input::loadOptionsfromServer(VDR* vdr)
445 config = vdr->configLoad("General", "RemoteKeyNum");
449 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys load");
450 LoadKeysConfig(vdr,config);
455 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys not found");
456 InitHWCListwithDefaults();
461 bool Input::saveOptionstoServer()
469 Log::getInstance()->log("Input", Log::INFO, "start called");
471 threadStartProtect.lock();
472 listenThread = std::thread( [this ]
474 threadStartProtect.lock();
475 threadStartProtect.unlock();
476 // FIXME block signals
480 threadStartProtect.unlock();
486 listenLoopStop = true;
487 informStopEventLoop();