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;
31 const ULONG Remote::NOLEARNMODE;
33 const UCHAR Remote::NA_LEARN;
34 const UCHAR Remote::NA_NONE;
35 const UCHAR Remote::NA_UNKNOWN;
36 const UCHAR Remote::NA_SIGNAL;
37 const UCHAR Remote::DF_UP;
38 const UCHAR Remote::DF_DOWN;
39 const UCHAR Remote::DF_LEFT;
40 const UCHAR Remote::DF_RIGHT;
42 // Problem common buttons
43 const UCHAR Remote::VOLUMEUP;
44 const UCHAR Remote::VOLUMEDOWN;
45 const UCHAR Remote::CHANNELUP;
46 const UCHAR Remote::CHANNELDOWN;
49 const UCHAR Remote::ZERO;
50 const UCHAR Remote::ONE;
51 const UCHAR Remote::TWO;
52 const UCHAR Remote::THREE;
53 const UCHAR Remote::FOUR;
54 const UCHAR Remote::FIVE;
55 const UCHAR Remote::SIX;
56 const UCHAR Remote::SEVEN;
57 const UCHAR Remote::EIGHT;
58 const UCHAR Remote::NINE;
59 const UCHAR Remote::POWER;
60 const UCHAR Remote::GO;
61 const UCHAR Remote::BACK;
62 const UCHAR Remote::MENU;
63 const UCHAR Remote::RED;
64 const UCHAR Remote::GREEN;
65 const UCHAR Remote::YELLOW;
66 const UCHAR Remote::BLUE;
67 const UCHAR Remote::MUTE;
68 const UCHAR Remote::RADIO;
69 const UCHAR Remote::REVERSE;
70 const UCHAR Remote::PLAY;
71 const UCHAR Remote::FORWARD;
72 const UCHAR Remote::RECORD;
73 const UCHAR Remote::STOP;
74 const UCHAR Remote::PAUSE;
75 const UCHAR Remote::SKIPBACK;
76 const UCHAR Remote::SKIPFORWARD;
77 const UCHAR Remote::OK;
80 const UCHAR Remote::FULL;
83 const UCHAR Remote::TV;
84 const UCHAR Remote::VIDEOS;
85 const UCHAR Remote::MUSIC;
86 const UCHAR Remote::PICTURES;
87 const UCHAR Remote::GUIDE;
88 const UCHAR Remote::UP;
89 const UCHAR Remote::DOWN;
90 const UCHAR Remote::LEFT;
91 const UCHAR Remote::RIGHT;
92 const UCHAR Remote::PREVCHANNEL;
93 const UCHAR Remote::STAR;
94 const UCHAR Remote::HASH;
97 const UCHAR Remote::PLAYPAUSE;
101 const UCHAR Remote::OLDREMOTE;
102 const UCHAR Remote::NEWREMOTE;
106 if (instance) return;
108 remoteType = OLDREMOTE;
109 learnmode = NOLEARNMODE;
117 Remote* Remote::getInstance()
122 void Remote::setRemoteType(UCHAR newType)
124 if ((newType != OLDREMOTE) && (newType != NEWREMOTE)) return;
125 remoteType = newType;
128 void Remote::EnterLearningMode(UCHAR command)
130 learnmode = command; //Armed
133 void Remote::ResetToDefault()
136 InitHWCListwithDefaults();
140 UCHAR Remote::TranslateHWCFixed(ULLONG code)
171 const char*Remote::HardcodedTranslateStr(UCHAR command)
194 UCHAR Remote::TranslateHWCList(ULLONG code)
196 if (learnmode != NOLEARNMODE)
198 setHWCtoCommand(code, learnmode);
199 learnmode = NOLEARNMODE;
202 RemoteTranslationList::iterator it = translist.find(code);
203 if (it == translist.end())
213 UCHAR Remote::TranslateHWC(ULLONG code)
215 UCHAR ret = TranslateHWCFixed(code);
216 if (ret == NA_UNKNOWN)
218 ret = TranslateHWCList(code);
222 learnmode = NOLEARNMODE;
225 if (ret == NA_UNKNOWN)
232 void Remote::setHWCtoCommand(ULLONG hcw, UCHAR command)
234 translist[hcw] = command;
237 void Remote::unsetHWC(ULLONG hcw)
239 translist.erase(hcw);
242 void Remote::LoadKeysConfig(VDR *vdr,const char *cfg)
245 if (sscanf(cfg,"%ld",&number) != 1) return;
246 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys num keys %d",number);
249 for (int i = 0; i < number; i++) {
250 sprintf(keybuf, "RemoteKey%d", i);
251 const char *keytrans = vdr->configLoad("General", keybuf);
255 if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
256 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
263 void Remote::SaveKeysConfig()
268 RemoteTranslationList::const_iterator it;
269 for (it = translist.begin(); it != translist.end(); it++)
271 sprintf(buffer,"%08lXI%08lXK%02X",
272 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
273 sprintf(keybuf,"RemoteKey%d",number);
274 VDR::getInstance()->configSave("General",keybuf,buffer);
277 sprintf(buffer,"%d",number);
278 VDR::getInstance()->configSave("General","RemoteKeyNum",buffer);
282 void Remote::InitHWCListwithDefaults()
284 translist[VOLUMEUP] = VOLUMEUP;
285 translist[VOLUMEDOWN] = VOLUMEDOWN;
286 translist[CHANNELUP] = CHANNELUP;
287 translist[CHANNELDOWN] = CHANNELDOWN;
290 translist[ZERO] = ZERO;
291 translist[ONE] = ONE;
292 translist[TWO] = TWO;
293 translist[THREE] = THREE;
294 translist[FOUR] = FOUR;
295 translist[FIVE] = FIVE;
296 translist[SIX] = SIX;
297 translist[SEVEN] = SEVEN;
298 translist[EIGHT] = EIGHT;
299 translist[NINE] = NINE;
300 translist[POWER] = POWER;
302 translist[RED] = RED;
303 translist[GREEN] = GREEN;
304 translist[YELLOW] = YELLOW;
305 translist[BLUE] = BLUE;
307 translist[MUTE] = MUTE;
308 translist[RADIO] = RADIO;
309 translist[REVERSE] = REVERSE;
310 translist[FORWARD] = FORWARD;
311 translist[RECORD] = RECORD;
312 translist[STOP] = STOP;
313 translist[PAUSE] = PAUSE;
314 translist[PLAY] = PLAY;
315 translist[SKIPBACK] = SKIPBACK;
316 translist[SKIPFORWARD] = SKIPFORWARD;
319 translist[FULL] = FULL;
323 translist[VIDEOS] = VIDEOS;
324 translist[MUSIC] = MUSIC;
325 translist[PICTURES] = PICTURES;
326 translist[GUIDE] = GUIDE;
327 translist[PREVCHANNEL] = PREVCHANNEL;
328 translist[STAR] = STAR;
329 translist[HASH] = HASH;
332 const char *Remote::CommandDesc(UCHAR number)
337 return tr("Volume Up");
340 return tr("Volume Down");
342 return tr("Channel up");
344 return tr("Channel down");
386 return tr("Reverse");
390 return tr("Forward");
398 return tr("Skip back");
400 return tr("Skip forward");
404 return tr("Fullscreen");
412 return tr("Pictures");
424 return tr("Previous Channel");
430 return tr("Play/Pause");
437 char* Remote::HCWDesc(ULLONG hcw)
440 temp=(char*)CommandDesc((UCHAR)hcw);
443 dest=new char[strlen(temp)+1];
449 sprintf(dest,"C:%lX",(ULONG)hcw);
454 char *Remote::CommandTranslateStr(UCHAR command)
457 int length=5;//:+\t+0
458 int keys=0; //max 10;
459 char *commanddesc=(char*)CommandDesc(command);
460 if (commanddesc != NULL)
462 length+=strlen(commanddesc);
464 char *preassigneddesc=(char*)HardcodedTranslateStr(command);
465 if (preassigneddesc != NULL)
467 length+=strlen(preassigneddesc);
471 RemoteTranslationList::const_iterator it;
472 for (it = translist.begin(); it != translist.end(); it++)
474 if (it->second == command)
476 keydesc[keys] = HCWDesc(it->first);
477 length += strlen(keydesc[keys])+2;
479 if (keys == 10) break;
483 desc=new char [length];
485 if (commanddesc != NULL)
487 current+=sprintf(current,"%s:\t ",commanddesc);
491 current+=sprintf(current,":\t ");
493 if (preassigneddesc != NULL)
495 current+=sprintf(current,"%s\t",preassigneddesc);
499 current+=sprintf(current,"\t");
501 for (int i = 0;i < keys; i++)
503 current += sprintf(current,"%s, ",keydesc[i]);
504 delete [] keydesc[i];
509 bool Remote::addOptionPagesToWTB(WTabBar *wtb)
511 WRemoteConfig* wrc = new WRemoteConfig();
512 wtb->addTab(tr("Remote Control"), wrc);
516 bool Remote::loadOptionsfromServer(VDR* vdr)
520 config = vdr->configLoad("General", "RemoteKeyNum");
524 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys load");
525 LoadKeysConfig(vdr,config);
530 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys not found");
531 InitHWCListwithDefaults();
536 bool Remote::saveOptionstoServer()