2 Copyright 2008 Thomas Steger
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, see <https://www.gnu.org/licenses/>.
20 #include "vsleeptimer.h"
28 #include "messagequeue.h"
30 Sleeptimer* Sleeptimer::instance = NULL;
32 Sleeptimer::Sleeptimer()
38 Sleeptimer::~Sleeptimer()
43 const char* Sleeptimer::SetTime()
143 Sleeptimer* Sleeptimer::getInstance()
148 void Sleeptimer::threadMethod()
150 while (sec>-1 && active==true)
153 if (sec<31 && sec>-1)
155 VCountdown* count = new VCountdown();
157 sprintf(temp, "0:%02d", sec);
158 count->drawClock(temp);
160 Message* m1 = new Message();
161 m1->message = Message::ADD_VIEW;
162 m1->to = BoxStack::getInstance();
163 m1->data = reinterpret_cast<void*>(count);
164 MessageQueue::getInstance()->postMessage(m1);
170 Message* m2 = new Message();
171 m2->message = Message::INPUT_EVENT;
172 m2->to = Command::getInstance();
174 m2->parameter = Input::POWER;
175 MessageQueue::getInstance()->postMessage(m2);
181 void Sleeptimer::shutdown()
192 VSleeptimer::VSleeptimer()
196 if (Video::getInstance()->getFormat() == Video::PAL)
198 setPosition(100, 499);
202 setPosition(90, 400);
206 VSleeptimer::~VSleeptimer()
208 // Make sure the timer is deleted
209 Timers::getInstance()->cancelTimer(this, 1);
212 void VSleeptimer::draw()
214 fillColour(DrawStyle::VIEWBACKGROUND);
217 w.nextSymbol = WSymbol::CLOCK;
222 drawText(displaySleeptimer,50,2,DrawStyle::LIGHTTEXT);
223 Timers::getInstance()->setTimerD(this, 1, 2);
226 void VSleeptimer::timercall(int /* clientReference */)
229 Message* m = new Message(); // Delete self
230 m->message = Message::CLOSE_ME;
231 m->to = BoxStack::getInstance();
233 MessageQueue::getInstance()->postMessage(m);
236 int VSleeptimer::handleCommand(int command)
242 displaySleeptimer = Sleeptimer::getInstance()->SetTime();
244 BoxStack::getInstance()->update(this);
250 // allow command to drop through to other views
257 VCountdown::VCountdown()
262 if (Video::getInstance()->getFormat() == Video::PAL)
264 setPosition(100, 499);
268 setPosition(90, 400);
272 VCountdown::~VCountdown()
274 // Make sure the timer is deleted
275 Timers::getInstance()->cancelTimer(this, 1);
278 void VCountdown::drawClock(const char* sec)
280 fillColour(DrawStyle::VIEWBACKGROUND);
283 w.nextSymbol = WSymbol::CLOCK;
284 w.nextColour = DrawStyle::RED;
289 drawText(sec, 50, 2, DrawStyle::RED);
290 Timers::getInstance()->setTimerD(this, 1, 1);
293 void VCountdown::timercall(int /* clientReference */)
296 Message* m = new Message(); // Delete self
297 m->message = Message::CLOSE_ME;
298 m->to = BoxStack::getInstance();
300 MessageQueue::getInstance()->postMessage(m);