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
26 Remote* Remote::instance = NULL;
32 remoteType = OLDREMOTE;
33 learnmode = NOLEARNMODE;
41 Remote* Remote::getInstance()
46 void Remote::setRemoteType(UCHAR newType)
48 if ((newType != OLDREMOTE) && (newType != NEWREMOTE)) return;
52 void Remote::EnterLearningMode(UCHAR command)
54 learnmode = command; //Armed
57 void Remote::ResetToDefault()
60 InitHWCListwithDefaults();
64 UCHAR Remote::TranslateHWCFixed(ULLONG code)
95 const char*Remote::HardcodedTranslateStr(UCHAR command)
118 UCHAR Remote::TranslateHWCList(ULLONG code)
120 if (learnmode != NOLEARNMODE)
122 setHWCtoCommand(code, learnmode);
123 learnmode = NOLEARNMODE;
126 RemoteTranslationList::iterator it = translist.find(code);
127 if (it == translist.end())
137 UCHAR Remote::TranslateHWC(ULLONG code)
139 UCHAR ret = TranslateHWCFixed(code);
140 if (ret == NA_UNKNOWN)
142 ret = TranslateHWCList(code);
146 learnmode = NOLEARNMODE;
149 if (ret == NA_UNKNOWN)
156 void Remote::setHWCtoCommand(ULLONG hcw, UCHAR command)
158 translist[hcw] = command;
161 void Remote::unsetHWC(ULLONG hcw)
163 translist.erase(hcw);
166 void Remote::LoadKeysConfig(char *cfg)
169 start = strchr(cfg,'H')+1;
170 while ((start-1) != NULL)
174 if (sscanf(start,"%lXI%lXK%lX",&ul1,&ul2,&uc) == 3)
176 translist[((ULLONG) ul1) | ((ULLONG)ul2) << 32]=(UCHAR)uc;
178 start = strchr(start, 'H')+1;
182 char *Remote::SaveKeysConfig()
184 int length=21*translist.size() +1;
185 char *output=new char[length];
186 char *current=output;
187 RemoteTranslationList::const_iterator it;
188 for (it = translist.begin(); it != translist.end(); it++)
190 current+=sprintf(current,"H%08lXI%08lXK%02X",
191 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
197 void Remote::InitHWCListwithDefaults()
199 translist[VOLUMEUP] = VOLUMEUP;
200 translist[VOLUMEDOWN] = VOLUMEDOWN;
201 translist[CHANNELUP] = CHANNELUP;
202 translist[CHANNELDOWN] = CHANNELDOWN;
205 translist[ZERO] = ZERO;
206 translist[ONE] = ONE;
207 translist[TWO] = TWO;
208 translist[THREE] = THREE;
209 translist[FOUR] = FOUR;
210 translist[FIVE] = FIVE;
211 translist[SIX] = SIX;
212 translist[SEVEN] = SEVEN;
213 translist[EIGHT] = EIGHT;
214 translist[NINE] = NINE;
215 translist[POWER] = POWER;
217 translist[RED] = RED;
218 translist[GREEN] = GREEN;
219 translist[YELLOW] = YELLOW;
220 translist[BLUE] = BLUE;
222 translist[MUTE] = MUTE;
223 translist[RADIO] = RADIO;
224 translist[REVERSE] = REVERSE;
225 translist[FORWARD] = FORWARD;
226 translist[RECORD] = RECORD;
227 translist[STOP] = STOP;
228 translist[PAUSE] = PAUSE;
229 translist[PLAY] = PLAY;
230 translist[SKIPBACK] = SKIPBACK;
231 translist[SKIPFORWARD] = SKIPFORWARD;
234 translist[FULL] = FULL;
238 translist[VIDEOS] = VIDEOS;
239 translist[MUSIC] = MUSIC;
240 translist[PICTURES] = PICTURES;
241 translist[GUIDE] = GUIDE;
242 translist[PREVCHANNEL] = PREVCHANNEL;
243 translist[STAR] = STAR;
244 translist[HASH] = HASH;
247 const char *Remote::CommandDesc(UCHAR number)
252 return tr("Volume Up");
255 return tr("Volume Down");
257 return tr("Channel up");
259 return tr("Channel down");
301 return tr("Reverse");
305 return tr("Forward");
313 return tr("Skip back");
315 return tr("Skip forward");
319 return tr("Fullscreen");
327 return tr("Pictures");
339 return tr("Previous Channel");
350 char* Remote::HCWDesc(ULLONG hcw)
353 temp=(char*)CommandDesc((UCHAR)hcw);
356 dest=new char[strlen(temp)+1];
362 sprintf(dest,"C:%lX",(ULONG)hcw);
367 char *Remote::CommandTranslateStr(UCHAR command)
370 int length=5;//:+\t+0
371 int keys=0; //max 10;
372 char *commanddesc=(char*)CommandDesc(command);
373 if (commanddesc != NULL)
375 length+=strlen(commanddesc);
377 char *preassigneddesc=(char*)HardcodedTranslateStr(command);
378 if (preassigneddesc != NULL)
380 length+=strlen(preassigneddesc);
384 RemoteTranslationList::const_iterator it;
385 for (it = translist.begin(); it != translist.end(); it++)
387 if (it->second == command)
389 keydesc[keys] = HCWDesc(it->first);
390 length += strlen(keydesc[keys])+2;
392 if (keys == 10) break;
396 desc=new char [length];
398 if (commanddesc != NULL)
400 current+=sprintf(current,"%s:\t ",commanddesc);
404 current+=sprintf(current,":\t ");
406 if (preassigneddesc != NULL)
408 current+=sprintf(current,"%s\t",preassigneddesc);
412 current+=sprintf(current,"\t");
414 for (int i = 0;i < keys; i++)
416 current += sprintf(current,"%s, ",keydesc[i]);
417 delete [] keydesc[i];