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
23 Command* Command::instance = NULL;
39 Command* Command::getInstance()
46 if (initted) return 0;
49 logger = Log::getInstance();
50 viewman = ViewMan::getInstance();
51 remote = Remote::getInstance();
53 if (!logger || !viewman || !remote)
62 int Command::shutdown()
64 if (!initted) return 0;
71 // VDR::getInstance()->cancelFindingServer();
82 Video* video = Video::getInstance();
84 UCHAR screenSize = video->getFormat();
86 // moved from startup because surface delete doesn't work
90 Led::getInstance()->on();
94 v->setDimensions(video->getScreenWidth(), video->getScreenHeight());
95 v->setBackgroundColour(Colour::VIDEOBLUE);
99 viewman->removeView(v);
102 VWallpaper* w = new VWallpaper();
103 if (screenSize == Video::PAL)
105 logger->log("Command", Log::DEBUG, "PAL wallpaper selected");
106 w->init("/wallpaperPAL.jpg");
110 logger->log("Command", Log::DEBUG, "NTSC wallpaper selected");
111 w->init("/wallpaperNTSC.jpg");
117 VConnect* vconnect = new VConnect();
118 viewman->add(vconnect);
125 button = remote->getButtonPress(2); // FIXME why is this set to 2 and not 0? so it can quit
126 if ((button == Remote::NA_NONE) || (button == Remote::NA_UNKNOWN)) continue;
128 if (button != Remote::NA_SIGNAL) handleCommand(button);
129 processMessageQueue();
133 void Command::postMessage(Message* m)
135 MessageQueue::postMessage(m);
136 kill(mainPid, SIGURG);
139 void Command::processMessage(Message* m)
141 logger->log("Command", Log::DEBUG, "processing message %i", m->message);
145 case Message::STANDBY:
150 case Message::STOP_PLAYBACK:
152 handleCommand(Remote::STOP); // an odd way of doing it, but so simple
155 case Message::VDR_CONNECTED:
157 doJustConnected((VConnect*)m->from);
163 void Command::handleCommand(int button)
165 if (isStandby && (button != Remote::POWER)) return;
167 if (viewman->handleCommand(button)) return;
169 // command was not handled
173 case Remote::DF_LEFT:
174 case Remote::DF_RIGHT:
175 case Remote::VOLUMEUP:
176 case Remote::VOLUMEDOWN:
178 VVolume* v = new VVolume();
179 v->handleCommand(button); // this will draw+show
181 viewman->timedDelete(v, 2, 1);
186 VMute* v = new VMute();
190 viewman->timedDelete(v, 2, 1);
201 Osd::getInstance()->screenShot("/out.jpg");
208 void Command::doStandby()
212 Video::getInstance()->signalOn();
213 Led::getInstance()->on();
217 VConnect* vconnect = new VConnect();
218 viewman->add(vconnect);
223 ViewMan* viewman = ViewMan::getInstance();
225 viewman->removeAll();
226 viewman->redrawAll();
228 VDR::getInstance()->configSave("General", "Last Power State", "Off");
229 VDR::getInstance()->disconnect();
230 Video::getInstance()->signalOff();
231 Led::getInstance()->off();
236 void Command::doReboot()
238 VDR::getInstance()->disconnect();
240 logger->log("Command", Log::NOTICE, "Reboot");
241 reboot(LINUX_REBOOT_CMD_RESTART);
244 void Command::doJustConnected(VConnect* vconnect)
246 Video* video = Video::getInstance();
247 ViewMan* viewman = ViewMan::getInstance();
248 viewman->removeView(vconnect, 0, 1);
250 VInfo* vi = new VInfo();
251 vi->setDimensions(400, 200);
252 if (video->getFormat() == Video::PAL)
253 vi->setScreenPos(170, 200);
255 vi->setScreenPos(160, 150);
257 vi->setMainText("\n Connected, loading config");
263 VDR* vdr = VDR::getInstance();
265 // Power off if first boot and config says so
270 char* powerAfterBoot = vdr->configLoad("General", "Power After Boot");
274 if (!strcasecmp(powerAfterBoot, "On"))
276 logger->log("Command", Log::INFO, "Config says Power After Boot = On");
278 else if (!strcasecmp(powerAfterBoot, "Off"))
280 logger->log("Command", Log::INFO, "Config says Power After Boot = Off");
284 else if (!strcasecmp(powerAfterBoot, "Last state"))
286 char* lastPowerState = vdr->configLoad("General", "Last Power State");
289 if (!strcasecmp(lastPowerState, "On"))
291 logger->log("Command", Log::INFO, "Config says Last Power State = On");
293 else if (!strcasecmp(lastPowerState, "Off"))
295 logger->log("Command", Log::INFO, "Config says Last Power State = Off");
301 logger->log("Command", Log::INFO, "Config General/Last Power State not understood");
306 logger->log("Command", Log::INFO, "Config General/Last Power State not found");
311 logger->log("Command", Log::INFO, "Config/Power After Boot not understood");
316 logger->log("Command", Log::INFO, "Config General/Power After Boot not found");
321 // Go S-Video if config says so
323 char* svideo = vdr->configLoad("TV", "S-Video");
327 if (!strcasecmp(svideo, "Yes"))
329 logger->log("Command", Log::INFO, "Switching to S-Video as S-Video=%s", svideo);
330 video->setConnection(Video::SVIDEO);
334 logger->log("Command", Log::INFO, "Leaving video output as S-Video=%s", svideo);
335 video->setConnection(Video::COMPOSITERGB);
340 logger->log("Command", Log::INFO, "Config TV/S-Video not found");
345 char* remoteType = vdr->configLoad("General", "Remote type");
349 if (!strcasecmp(remoteType, "New"))
351 logger->log("Command", Log::INFO, "Switching to New remote type");
352 remote->setRemoteType(Remote::NEWREMOTE);
356 logger->log("Command", Log::INFO, "Switching to Old remote type");
357 remote->setRemoteType(Remote::OLDREMOTE);
362 logger->log("Command", Log::INFO, "Config General/Remote type not found");
363 remote->setRemoteType(Remote::OLDREMOTE);
366 // Save power state = on
368 vdr->configSave("General", "Last Power State", "On");
370 // Get TV aspect ratio
372 char* aspect = vdr->configLoad("TV", "Aspect");
376 if (!strcasecmp(aspect, "16:9"))
378 logger->log("Command", Log::INFO, "Switching to TV aspect 16:9");
379 video->setAspectRatio(Video::ASPECT16X9);
383 logger->log("Command", Log::INFO, "Switching to TV aspect 4:3");
384 video->setAspectRatio(Video::ASPECT4X3);
389 logger->log("Command", Log::INFO, "Config TV/Aspect type not found, going 4:3");
390 video->setAspectRatio(Video::ASPECT4X3);
397 viewman->removeView(vi);
399 VWelcome* vw = new VWelcome();
401 viewman->redrawAll();
404 handleCommand(Remote::DOWN);
405 handleCommand(Remote::DOWN);
406 handleCommand(Remote::DOWN);
407 handleCommand(Remote::OK);