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,"%lXI%lXK%lX",&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;
185 RemoteTranslationList::const_iterator it;
186 for (it = translist.begin(); it != translist.end(); it++)
188 current+=sprintf(current,"H%08lXI%08lXK%02X",
189 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
195 void Remote::InitHWCListwithDefaults()
197 translist[VOLUMEUP] = VOLUMEUP;
198 translist[VOLUMEDOWN] = VOLUMEDOWN;
199 translist[CHANNELUP] = CHANNELUP;
200 translist[CHANNELDOWN] = CHANNELDOWN;
203 translist[ZERO] = ZERO;
204 translist[ONE] = ONE;
205 translist[TWO] = TWO;
206 translist[THREE] = THREE;
207 translist[FOUR] = FOUR;
208 translist[FIVE] = FIVE;
209 translist[SIX] = SIX;
210 translist[SEVEN] = SEVEN;
211 translist[EIGHT] = EIGHT;
212 translist[NINE] = NINE;
213 translist[POWER] = POWER;
215 translist[RED] = RED;
216 translist[GREEN] = GREEN;
217 translist[YELLOW] = YELLOW;
218 translist[BLUE] = BLUE;
220 translist[MUTE] = MUTE;
221 translist[RADIO] = RADIO;
222 translist[REVERSE] = REVERSE;
223 translist[FORWARD] = FORWARD;
224 translist[RECORD] = RECORD;
225 translist[STOP] = STOP;
226 translist[PAUSE] = PAUSE;
227 translist[SKIPBACK] = SKIPBACK;
228 translist[SKIPFORWARD] = SKIPFORWARD;
231 translist[FULL] = FULL;
235 translist[VIDEOS] = VIDEOS;
236 translist[MUSIC] = MUSIC;
237 translist[PICTURES] = PICTURES;
238 translist[GUIDE] = GUIDE;
239 translist[PREVCHANNEL] = PREVCHANNEL;
240 translist[STAR] = STAR;
241 translist[HASH] = HASH;
244 const char *Remote::CommandDesc(UCHAR number)
249 return tr("Volume Up");
252 return tr("Volume Down");
254 return tr("Channel up");
256 return tr("Channel down");
298 return tr("Reverse");
302 return tr("Forward");
310 return tr("Skip back");
312 return tr("Skip forward");
316 return tr("Fullscreen");
324 return tr("Pictures");
336 return tr("Previous Channel");
347 char* Remote::HCWDesc(ULLONG hcw)
350 temp=(char*)CommandDesc((UCHAR)hcw);
353 dest=new char[strlen(temp)+1];
359 sprintf(dest,"C:%lX",(ULONG)hcw);
364 char *Remote::CommandTranslateStr(UCHAR command)
367 int length=5;//:+\t+0
368 int keys=0; //max 10;
369 char *commanddesc=(char*)CommandDesc(command);
370 if (commanddesc != NULL)
372 length+=strlen(commanddesc);
374 char *preassigneddesc=(char*)HardcodedTranslateStr(command);
375 if (preassigneddesc != NULL)
377 length+=strlen(preassigneddesc);
381 RemoteTranslationList::const_iterator it;
382 for (it = translist.begin(); it != translist.end(); it++)
384 if (it->second == command)
386 keydesc[keys] = HCWDesc(it->first);
387 length += strlen(keydesc[keys])+2;
389 if (keys == 10) break;
393 desc=new char [length];
395 if (commanddesc != NULL)
397 current+=sprintf(current,"%s:\t ",commanddesc);
401 current+=sprintf(current,":\t ");
403 if (preassigneddesc != NULL)
405 current+=sprintf(current,"%s\t",preassigneddesc);
409 current+=sprintf(current,"\t");
411 for (int i = 0;i < keys; i++)
413 current += sprintf(current,"%s, ",keydesc[i]);
414 delete [] keydesc[i];