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(char *cfg)
245 start = strchr(cfg,'H')+1;
246 while ((start-1) != NULL)
250 if (sscanf(start,"%lXI%lXK%lX",&ul1,&ul2,&uc) == 3)
252 translist[((ULLONG) ul1) | ((ULLONG)ul2) << 32]=(UCHAR)uc;
254 start = strchr(start, 'H')+1;
258 char *Remote::SaveKeysConfig()
260 int length=21*translist.size() +1;
261 char *output=new char[length];
262 char *current=output;
263 RemoteTranslationList::const_iterator it;
264 for (it = translist.begin(); it != translist.end(); it++)
266 current+=snprintf(current,21,"H%08lXI%08lXK%02X",
267 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
273 void Remote::InitHWCListwithDefaults()
275 translist[VOLUMEUP] = VOLUMEUP;
276 translist[VOLUMEDOWN] = VOLUMEDOWN;
277 translist[CHANNELUP] = CHANNELUP;
278 translist[CHANNELDOWN] = CHANNELDOWN;
281 translist[ZERO] = ZERO;
282 translist[ONE] = ONE;
283 translist[TWO] = TWO;
284 translist[THREE] = THREE;
285 translist[FOUR] = FOUR;
286 translist[FIVE] = FIVE;
287 translist[SIX] = SIX;
288 translist[SEVEN] = SEVEN;
289 translist[EIGHT] = EIGHT;
290 translist[NINE] = NINE;
291 translist[POWER] = POWER;
293 translist[RED] = RED;
294 translist[GREEN] = GREEN;
295 translist[YELLOW] = YELLOW;
296 translist[BLUE] = BLUE;
298 translist[MUTE] = MUTE;
299 translist[RADIO] = RADIO;
300 translist[REVERSE] = REVERSE;
301 translist[FORWARD] = FORWARD;
302 translist[RECORD] = RECORD;
303 translist[STOP] = STOP;
304 translist[PAUSE] = PAUSE;
305 translist[PLAY] = PLAY;
306 translist[SKIPBACK] = SKIPBACK;
307 translist[SKIPFORWARD] = SKIPFORWARD;
310 translist[FULL] = FULL;
314 translist[VIDEOS] = VIDEOS;
315 translist[MUSIC] = MUSIC;
316 translist[PICTURES] = PICTURES;
317 translist[GUIDE] = GUIDE;
318 translist[PREVCHANNEL] = PREVCHANNEL;
319 translist[STAR] = STAR;
320 translist[HASH] = HASH;
323 const char *Remote::CommandDesc(UCHAR number)
328 return tr("Volume Up");
331 return tr("Volume Down");
333 return tr("Channel up");
335 return tr("Channel down");
377 return tr("Reverse");
381 return tr("Forward");
389 return tr("Skip back");
391 return tr("Skip forward");
395 return tr("Fullscreen");
403 return tr("Pictures");
415 return tr("Previous Channel");
421 return tr("Play/Pause");
428 char* Remote::HCWDesc(ULLONG hcw)
431 temp=(char*)CommandDesc((UCHAR)hcw);
434 dest=new char[strlen(temp)+1];
440 sprintf(dest,"C:%lX",(ULONG)hcw);
445 char *Remote::CommandTranslateStr(UCHAR command)
448 int length=5;//:+\t+0
449 int keys=0; //max 10;
450 char *commanddesc=(char*)CommandDesc(command);
451 if (commanddesc != NULL)
453 length+=strlen(commanddesc);
455 char *preassigneddesc=(char*)HardcodedTranslateStr(command);
456 if (preassigneddesc != NULL)
458 length+=strlen(preassigneddesc);
462 RemoteTranslationList::const_iterator it;
463 for (it = translist.begin(); it != translist.end(); it++)
465 if (it->second == command)
467 keydesc[keys] = HCWDesc(it->first);
468 length += strlen(keydesc[keys])+2;
470 if (keys == 10) break;
474 desc=new char [length];
476 if (commanddesc != NULL)
478 current+=sprintf(current,"%s:\t ",commanddesc);
482 current+=sprintf(current,":\t ");
484 if (preassigneddesc != NULL)
486 current+=sprintf(current,"%s\t",preassigneddesc);
490 current+=sprintf(current,"\t");
492 for (int i = 0;i < keys; i++)
494 current += sprintf(current,"%s, ",keydesc[i]);
495 delete [] keydesc[i];
500 bool Remote::addOptionPagesToWTB(WTabBar *wtb)
502 WRemoteConfig* wrc = new WRemoteConfig();
503 wtb->addTab(tr("Remote Control"), wrc);
507 bool Remote::loadOptionsfromServer(VDR* vdr)
511 config = vdr->configLoad("General", "Remote keys");
515 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys load");
516 LoadKeysConfig(config);
521 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys not found");
522 InitHWCListwithDefaults();
527 bool Remote::saveOptionstoServer()
529 char *keyscon=SaveKeysConfig();
530 VDR::getInstance()->configSave("General","Remote keys",keyscon);