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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 Remote* Remote::instance = NULL;
30 remoteType = OLDREMOTE;
31 learnmode = NOLEARNMODE;
39 Remote* Remote::getInstance()
44 void Remote::setRemoteType(UCHAR newType)
46 if ((newType != OLDREMOTE) && (newType != NEWREMOTE)) return;
50 void Remote::EnterLearningMode(UCHAR command)
52 learnmode = command; //Armed
55 void Remote::ResetToDefault()
58 InitHWCListwithDefaults();
62 UCHAR Remote::TranslateHWCFixed(ULLONG code)
93 const char*Remote::HardcodedTranslateStr(UCHAR command)
116 UCHAR Remote::TranslateHWCList(ULLONG code)
118 if (learnmode != NOLEARNMODE)
120 setHWCtoCommand(code, learnmode);
121 learnmode = NOLEARNMODE;
124 RemoteTranslationList::iterator it = translist.find(code);
125 if (it == translist.end())
135 UCHAR Remote::TranslateHWC(ULLONG code)
137 UCHAR ret = TranslateHWCFixed(code);
138 if (ret == NA_UNKNOWN)
140 ret = TranslateHWCList(code);
144 learnmode = NOLEARNMODE;
147 if (ret == NA_UNKNOWN)
154 void Remote::setHWCtoCommand(ULLONG hcw, UCHAR command)
156 translist[hcw] = command;
159 void Remote::unsetHWC(ULLONG hcw)
161 translist.erase(hcw);
164 void Remote::LoadKeysConfig(char *cfg)
167 start = strchr(cfg,'H')+1;
168 while ((start-1) != NULL)
172 if (sscanf(start,"%XI%XK%X",&ul1,&ul2,&uc) == 3)
174 translist[((ULLONG) ul1) | ((ULLONG)ul2) << 32]=(UCHAR)uc;
176 start = strchr(start, 'H')+1;
180 char *Remote::SaveKeysConfig()
182 int length=21*translist.size() +1;
183 char *output=new char[length];
184 char *current=output;
186 RemoteTranslationList::const_iterator it;
187 for (it = translist.begin(); it != translist.end(); it++)
189 current+=sprintf(current,"H%08XI%08XK%02X",
190 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
196 void Remote::InitHWCListwithDefaults()
198 translist[VOLUMEUP] = VOLUMEUP;
199 translist[VOLUMEDOWN] = VOLUMEDOWN;
200 translist[CHANNELUP] = CHANNELUP;
201 translist[CHANNELDOWN] = CHANNELDOWN;
204 translist[ZERO] = ZERO;
205 translist[ONE] = ONE;
206 translist[TWO] = TWO;
207 translist[THREE] = THREE;
208 translist[FOUR] = FOUR;
209 translist[FIVE] = FIVE;
210 translist[SIX] = SIX;
211 translist[SEVEN] = SEVEN;
212 translist[EIGHT] = EIGHT;
213 translist[NINE] = NINE;
214 translist[POWER] = POWER;
216 translist[RED] = RED;
217 translist[GREEN] = GREEN;
218 translist[YELLOW] = YELLOW;
219 translist[BLUE] = BLUE;
221 translist[MUTE] = MUTE;
222 translist[RADIO] = RADIO;
223 translist[REVERSE] = REVERSE;
224 translist[FORWARD] = FORWARD;
225 translist[RECORD] = RECORD;
226 translist[STOP] = STOP;
227 translist[PAUSE] = PAUSE;
228 translist[SKIPBACK] = SKIPBACK;
229 translist[SKIPFORWARD] = SKIPFORWARD;
232 translist[FULL] = FULL;
236 translist[VIDEOS] = VIDEOS;
237 translist[MUSIC] = MUSIC;
238 translist[PICTURES] = PICTURES;
239 translist[GUIDE] = GUIDE;
240 translist[PREVCHANNEL] = PREVCHANNEL;
241 translist[STAR] = STAR;
242 translist[HASH] = HASH;
245 const char *Remote::CommandDesc(UCHAR number)
250 return tr("Volume Up");
253 return tr("Volume Down");
255 return tr("Channel up");
257 return tr("Channel down");
299 return tr("Reverse");
303 return tr("Forward");
311 return tr("Skip back");
313 return tr("Skip forward");
317 return tr("Fullscreen");
325 return tr("Pictures");
337 return tr("Previous Channel");
348 char* Remote::HCWDesc(ULLONG hcw)
351 temp=(char*)CommandDesc((UCHAR)hcw);
354 dest=new char[strlen(temp)+1];
360 sprintf(dest,"C:%X",(ULONG)hcw);
365 char *Remote::CommandTranslateStr(UCHAR command)
368 int length=5;//:+\t+0
369 int keys=0; //max 10;
370 char *commanddesc=(char*)CommandDesc(command);
371 if (commanddesc != NULL)
373 length+=strlen(commanddesc);
375 char *preassigneddesc=(char*)HardcodedTranslateStr(command);
376 if (preassigneddesc != NULL)
378 length+=strlen(preassigneddesc);
382 RemoteTranslationList::const_iterator it;
383 for (it = translist.begin(); it != translist.end(); it++)
385 if (it->second == command)
387 keydesc[keys] = HCWDesc(it->first);
388 length += strlen(keydesc[keys])+2;
390 if (keys == 10) break;
394 desc=new char [length];
396 if (commanddesc != NULL)
398 current+=sprintf(current,"%s:\t ",commanddesc);
402 current+=sprintf(current,":\t ");
404 if (preassigneddesc != NULL)
406 current+=sprintf(current,"%s\t",preassigneddesc);
410 current+=sprintf(current,"\t");
412 for (int i = 0;i < keys; i++)
414 current += sprintf(current,"%s, ",keydesc[i]);
415 delete [] keydesc[i];