2 Copyright 2004-2005 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, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "wremoteconfig.h"
28 Remote* Remote::instance = NULL;
32 const ULONG Remote::NOLEARNMODE;
34 const UCHAR Remote::NA_LEARN;
35 const UCHAR Remote::NA_NONE;
36 const UCHAR Remote::NA_UNKNOWN;
37 const UCHAR Remote::NA_SIGNAL;
38 const UCHAR Remote::DF_UP;
39 const UCHAR Remote::DF_DOWN;
40 const UCHAR Remote::DF_LEFT;
41 const UCHAR Remote::DF_RIGHT;
43 // Problem common buttons
44 const UCHAR Remote::VOLUMEUP;
45 const UCHAR Remote::VOLUMEDOWN;
46 const UCHAR Remote::CHANNELUP;
47 const UCHAR Remote::CHANNELDOWN;
50 const UCHAR Remote::ZERO;
51 const UCHAR Remote::ONE;
52 const UCHAR Remote::TWO;
53 const UCHAR Remote::THREE;
54 const UCHAR Remote::FOUR;
55 const UCHAR Remote::FIVE;
56 const UCHAR Remote::SIX;
57 const UCHAR Remote::SEVEN;
58 const UCHAR Remote::EIGHT;
59 const UCHAR Remote::NINE;
60 const UCHAR Remote::POWER;
61 const UCHAR Remote::GO;
62 const UCHAR Remote::BACK;
63 const UCHAR Remote::MENU;
64 const UCHAR Remote::RED;
65 const UCHAR Remote::GREEN;
66 const UCHAR Remote::YELLOW;
67 const UCHAR Remote::BLUE;
68 const UCHAR Remote::MUTE;
69 const UCHAR Remote::RADIO;
70 const UCHAR Remote::REVERSE;
71 const UCHAR Remote::PLAY;
72 const UCHAR Remote::FORWARD;
73 const UCHAR Remote::RECORD;
74 const UCHAR Remote::STOP;
75 const UCHAR Remote::PAUSE;
76 const UCHAR Remote::SKIPBACK;
77 const UCHAR Remote::SKIPFORWARD;
78 const UCHAR Remote::OK;
81 const UCHAR Remote::FULL;
84 const UCHAR Remote::TV;
85 const UCHAR Remote::VIDEOS;
86 const UCHAR Remote::MUSIC;
87 const UCHAR Remote::PICTURES;
88 const UCHAR Remote::GUIDE;
89 const UCHAR Remote::UP;
90 const UCHAR Remote::DOWN;
91 const UCHAR Remote::LEFT;
92 const UCHAR Remote::RIGHT;
93 const UCHAR Remote::PREVCHANNEL;
94 const UCHAR Remote::STAR;
95 const UCHAR Remote::HASH;
98 const UCHAR Remote::PLAYPAUSE;
102 const UCHAR Remote::OLDREMOTE;
103 const UCHAR Remote::NEWREMOTE;
109 if (instance) return;
111 remoteType = OLDREMOTE;
112 learnmode = NOLEARNMODE;
120 Remote* Remote::getInstance()
125 void Remote::setRemoteType(UCHAR newType)
127 if ((newType != OLDREMOTE) && (newType != NEWREMOTE)) return;
128 remoteType = newType;
131 void Remote::EnterLearningMode(UCHAR command)
133 learnmode = command; //Armed
136 void Remote::ResetToDefault()
139 InitHWCListwithDefaults();
143 UCHAR Remote::TranslateHWCFixed(ULLONG code)
174 const char*Remote::HardcodedTranslateStr(UCHAR command)
197 UCHAR Remote::TranslateHWCList(ULLONG code)
199 if (learnmode != NOLEARNMODE)
201 setHWCtoCommand(code, learnmode);
202 learnmode = NOLEARNMODE;
205 RemoteTranslationList::iterator it = translist.find(code);
206 if (it == translist.end())
216 UCHAR Remote::TranslateHWC(ULLONG code)
218 UCHAR ret = TranslateHWCFixed(code);
219 if (ret == NA_UNKNOWN)
221 ret = TranslateHWCList(code);
225 learnmode = NOLEARNMODE;
228 if (ret == NA_UNKNOWN)
235 void Remote::setHWCtoCommand(ULLONG hcw, UCHAR command)
237 translist[hcw] = command;
240 void Remote::unsetHWC(ULLONG hcw)
242 translist.erase(hcw);
245 void Remote::LoadKeysConfig(VDR *vdr,const char *cfg)
248 if (sscanf(cfg,"%ld",&number) != 1) return;
249 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys num keys %d",number);
252 for (int i = 0; i < number; i++) {
253 sprintf(keybuf, "RemoteKey%d", i);
254 const char *keytrans = vdr->configLoad("General", keybuf);
258 if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
259 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
266 void Remote::SaveKeysConfig()
271 RemoteTranslationList::const_iterator it;
272 for (it = translist.begin(); it != translist.end(); it++)
274 sprintf(buffer,"%08lXI%08lXK%02X",
275 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
276 sprintf(keybuf,"RemoteKey%d",number);
277 VDR::getInstance()->configSave("General",keybuf,buffer);
280 sprintf(buffer,"%d",number);
281 VDR::getInstance()->configSave("General","RemoteKeyNum",buffer);
285 void Remote::InitHWCListwithDefaults()
287 translist[VOLUMEUP] = VOLUMEUP;
288 translist[VOLUMEDOWN] = VOLUMEDOWN;
289 translist[CHANNELUP] = CHANNELUP;
290 translist[CHANNELDOWN] = CHANNELDOWN;
293 translist[ZERO] = ZERO;
294 translist[ONE] = ONE;
295 translist[TWO] = TWO;
296 translist[THREE] = THREE;
297 translist[FOUR] = FOUR;
298 translist[FIVE] = FIVE;
299 translist[SIX] = SIX;
300 translist[SEVEN] = SEVEN;
301 translist[EIGHT] = EIGHT;
302 translist[NINE] = NINE;
303 translist[POWER] = POWER;
305 translist[RED] = RED;
306 translist[GREEN] = GREEN;
307 translist[YELLOW] = YELLOW;
308 translist[BLUE] = BLUE;
310 translist[MUTE] = MUTE;
311 translist[RADIO] = RADIO;
312 translist[REVERSE] = REVERSE;
313 translist[FORWARD] = FORWARD;
314 translist[RECORD] = RECORD;
315 translist[STOP] = STOP;
316 translist[PAUSE] = PAUSE;
317 translist[PLAY] = PLAY;
318 translist[SKIPBACK] = SKIPBACK;
319 translist[SKIPFORWARD] = SKIPFORWARD;
322 translist[FULL] = FULL;
326 translist[VIDEOS] = VIDEOS;
327 translist[MUSIC] = MUSIC;
328 translist[PICTURES] = PICTURES;
329 translist[GUIDE] = GUIDE;
330 translist[PREVCHANNEL] = PREVCHANNEL;
331 translist[STAR] = STAR;
332 translist[HASH] = HASH;
335 const char *Remote::CommandDesc(UCHAR number)
340 return tr("Volume Up");
343 return tr("Volume Down");
345 return tr("Channel up");
347 return tr("Channel down");
389 return tr("Reverse");
393 return tr("Forward");
401 return tr("Skip back");
403 return tr("Skip forward");
407 return tr("Fullscreen");
415 return tr("Pictures");
427 return tr("Previous Channel");
433 return tr("Play/Pause");
440 char* Remote::HCWDesc(ULLONG hcw)
443 temp=(char*)CommandDesc((UCHAR)hcw);
446 dest=new char[strlen(temp)+1];
452 sprintf(dest,"C:%lX",(ULONG)hcw);
457 char *Remote::CommandTranslateStr(UCHAR command)
460 int length=5;//:+\t+0
461 int keys=0; //max 10;
462 char *commanddesc=(char*)CommandDesc(command);
463 if (commanddesc != NULL)
465 length+=strlen(commanddesc);
467 char *preassigneddesc=(char*)HardcodedTranslateStr(command);
468 if (preassigneddesc != NULL)
470 length+=strlen(preassigneddesc);
474 RemoteTranslationList::const_iterator it;
475 for (it = translist.begin(); it != translist.end(); it++)
477 if (it->second == command)
479 keydesc[keys] = HCWDesc(it->first);
480 length += strlen(keydesc[keys])+2;
482 if (keys == 10) break;
486 desc=new char [length];
488 if (commanddesc != NULL)
490 current+=sprintf(current,"%s:\t ",commanddesc);
494 current+=sprintf(current,":\t ");
496 if (preassigneddesc != NULL)
498 current+=sprintf(current,"%s\t",preassigneddesc);
502 current+=sprintf(current,"\t");
504 for (int i = 0;i < keys; i++)
506 current += sprintf(current,"%s, ",keydesc[i]);
507 delete [] keydesc[i];
512 bool Remote::addOptionPagesToWTB(WTabBar *wtb)
514 WRemoteConfig* wrc = new WRemoteConfig();
515 wtb->addTab(tr("Remote Control"), wrc);
519 bool Remote::loadOptionsfromServer(VDR* vdr)
523 config = vdr->configLoad("General", "RemoteKeyNum");
527 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys load");
528 LoadKeysConfig(vdr,config);
533 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys not found");
534 InitHWCListwithDefaults();
539 bool Remote::saveOptionstoServer()