From 97ddcb3bb4314e6b3d11987ed2be6a0d972dd293 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 14 Sep 2008 15:50:11 +0000 Subject: [PATCH] Sleep timer --- CREDITS | 3 + command.cc | 9 ++ main.cc | 14 ++- objects.mk | 2 +- vsleeptimer.cc | 314 +++++++++++++++++++++++++++++++++++++++++++++++++ vsleeptimer.h | 86 ++++++++++++++ wsymbol.cc | 63 ++++++++-- wsymbol.h | 2 +- 8 files changed, 481 insertions(+), 12 deletions(-) create mode 100644 vsleeptimer.cc create mode 100644 vsleeptimer.h diff --git a/CREDITS b/CREDITS index 23f9e35..12d5aed 100644 --- a/CREDITS +++ b/CREDITS @@ -50,6 +50,9 @@ Alexander Pipelka Code cleaning patches Various bug fixes +Googles + Sleep timer + Thanks to the following people for their work with the MVP: Jon Gettler, BtB and the other MVPMC developers diff --git a/command.cc b/command.cc index 241f538..ccf1fb4 100644 --- a/command.cc +++ b/command.cc @@ -49,6 +49,7 @@ #include "boxx.h" #include "boxstack.h" #include "log.h" +#include "vsleeptimer.h" Command* Command::instance = NULL; @@ -466,6 +467,13 @@ void Command::handleCommand(int button) doFromTheTop(false); return; } + case Remote::GO: + { + VSleeptimer* sleep = new VSleeptimer(); + boxstack->add(sleep); + sleep->handleCommand(button); // this will draw+show + return; + } } } @@ -502,6 +510,7 @@ void Command::doStandby() VDR::getInstance()->disconnect(); Led::getInstance()->off(); isStandby = 1; + Sleeptimer::getInstance()->shutdown(); #ifdef WIN32 stop(); //different behavoiur on windows, we exit #endif diff --git a/main.cc b/main.cc index 5361f7f..ac5a593 100644 --- a/main.cc +++ b/main.cc @@ -41,7 +41,7 @@ #include "audiomvp.h" #include "videomvp.h" #include "wol.h" - +#include "vsleeptimer.h" #ifndef WIN32 void sighandler(int signalReceived); #endif @@ -66,6 +66,7 @@ VDR* vdr; Video* video; Audio* audio; Wol* wol; +Sleeptimer* sleeptimer; // Linux MVP main function and sighandler #ifndef WIN32 @@ -117,8 +118,9 @@ int main(int argc, char** argv) boxstack = new BoxStack(); command = new Command(); wol = new Wol(); - - if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !boxstack || !command || !wol) + sleeptimer = new Sleeptimer(); + + if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !boxstack || !command || !wol || !sleeptimer) { printf("Could not create objects. Memory problems?\n"); shutdown(1); @@ -463,6 +465,12 @@ void shutdown(int code) logger->log("Core", Log::NOTICE, "WOL module shut down"); } + if (sleeptimer) + { + delete sleeptimer; + logger->log("Core", Log::NOTICE, "Sleeptimer module shut down"); + } + if (logger) { logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n"); diff --git a/objects.mk b/objects.mk index 77681f4..5fb9fcb 100644 --- a/objects.mk +++ b/objects.mk @@ -17,6 +17,6 @@ OBJECTS1 = command.o log.o tcp.o dsock.o thread.o timers.o i18n.o mutex.o \ vmedialist.o media.o vpicture.o vpicturebanner.o \ vaudioplayer.o audioplayer.o demuxeraudio.o abstractoption.o \ eventdispatcher.o vdrrequestpacket.o vdrresponsepacket.o \ - vvideolivetv.o \ + vvideolivetv.o vsleeptimer.o \ playerlivetv.o playerliveradio.o \ wprogressbar.o diff --git a/vsleeptimer.cc b/vsleeptimer.cc new file mode 100644 index 0000000..79ea1f9 --- /dev/null +++ b/vsleeptimer.cc @@ -0,0 +1,314 @@ +/* + Copyright 2008 Googles + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "vsleeptimer.h" + +#include "remote.h" +#include "wsymbol.h" +#include "colour.h" +#include "video.h" +#include "timers.h" +#include "boxstack.h" +#include "command.h" + +Sleeptimer* Sleeptimer::instance = NULL; + +Sleeptimer::Sleeptimer() +{ + if (instance) return; + sec = -1; + active = false; + instance = this; + +} + +Sleeptimer::~Sleeptimer() +{ + instance = NULL; +} + + +const char* Sleeptimer::SetTime() +{ + if (sec <890) + { + sec=900; + if (active==false) + { + active = true; + threadStart(); + } + + return "0:15"; + } + else if (sec <1790) + { + sec = 1800; + if (active==false) + { + active = true; + threadStart(); + } + + return "0:30"; + } + else if (sec < 2690) + { + sec = 2700; + if (active==false) + { + active = true; + threadStart(); + } + + return "0:45"; + } + else if (sec < 3590) + { + sec = 3600; + if (active==false) + { + active = true; + threadStart(); + } + + return "1:00"; + } + else if (sec < 4490) + { + sec = 4500; + if (active==false) + { + active = true; + threadStart(); + } + + return "1:15"; + } + else if (sec < 5390) + { + sec = 5400; + if (active==false) + { + active = true; + threadStart(); + } + + return "1:30"; + } + else if (sec < 6290) + { + sec = 6300; + if (active==false) + { + active = true; + threadStart(); + } + + return "1:45"; + } + else if (sec < 7190) + { + sec = 7200; + if (active==false) + { + active = true; + threadStart(); + } + + return "2:00"; + + } + else + { + sec = -1; + if (active==true) + shutdown(); + return "AUS"; + } + +} + +Sleeptimer* Sleeptimer::getInstance() +{ + return instance; +} + +void Sleeptimer::threadMethod() +{ + + while (sec>-1 && active==true) + { + sec--; + if (sec<31 && sec>-1) + { + VCountdown* count = new VCountdown(); + char* temp; + asprintf(&temp, "0:%02d", sec); + count->draw(temp); + free (temp); + Message* m1 = new Message(); + m1->message = Message::ADD_VIEW; + m1->to = BoxStack::getInstance(); + m1->parameter = (ULONG)count; + Command::getInstance()->postMessageNoLock(m1); + } + MILLISLEEP(1000); + + + if (sec==-1) + { + Message* m2 = new Message(); // Delete self + m2->message = Message::UDP_BUTTON; + m2->to = Command::getInstance(); + m2->from = this; + m2->parameter = 61; + Command::getInstance()->postMessageFromOuterSpace(m2); + shutdown(); + } + + } + + +} + +void Sleeptimer::shutdown() +{ + if (active==true) + { + sec=-1; + threadCancel(); + active = false; + } + +} + + +VSleeptimer::VSleeptimer() +{ + setSize(100, 28); + createBuffer(); + if (Video::getInstance()->getFormat() == Video::PAL) + { + setPosition(100, 499); + } + else + { + setPosition(90, 400); + } +} + +VSleeptimer::~VSleeptimer() +{ + // Make sure the timer is deleted + Timers::getInstance()->cancelTimer(this, 1); +} + +void VSleeptimer::draw() +{ + fillColour(Colour::VIEWBACKGROUND); + WSymbol w; + TEMPADD(&w); + w.nextSymbol = WSymbol::CLOCK; + w.setPosition(3, 0); + w.draw(); + + Boxx::draw(); + drawText(displaySleeptimer,50,2,Colour::LIGHTTEXT); + Timers::getInstance()->setTimerD(this, 1, 2); +} + +void VSleeptimer::timercall(int clientReference) +{ + // delete me! + Message* m = new Message(); // Delete self + m->message = Message::CLOSE_ME; + m->to = BoxStack::getInstance(); + m->from = this; + Command::getInstance()->postMessageFromOuterSpace(m); +} + +int VSleeptimer::handleCommand(int command) +{ + switch(command) + { + case Remote::GO: + { + displaySleeptimer = Sleeptimer::getInstance()->SetTime(); + draw(); + BoxStack::getInstance()->update(this); + // handled + return 2; + } + } + + // allow command to drop through to other views + return 0; +} + + + + +VCountdown::VCountdown() +{ + + setSize(100, 28); + createBuffer(); + if (Video::getInstance()->getFormat() == Video::PAL) + { + setPosition(100, 499); + } + else + { + setPosition(90, 400); + } +} + +VCountdown::~VCountdown() +{ + // Make sure the timer is deleted + Timers::getInstance()->cancelTimer(this, 1); +} + +void VCountdown::draw(const char* sec) +{ + + fillColour(Colour::VIEWBACKGROUND); + WSymbol w; + TEMPADD(&w); + w.nextSymbol = WSymbol::CLOCK; + w.nextColour = Colour::RED; + w.setPosition(3, 0); + w.draw(); + + Boxx::draw(); + drawText(sec,50,2,Colour::RED); + Timers::getInstance()->setTimerD(this, 1, 1); +} + +void VCountdown::timercall(int clientReference) +{ + // delete me! + Message* m = new Message(); // Delete self + m->message = Message::CLOSE_ME; + m->to = BoxStack::getInstance(); + m->from = this; + Command::getInstance()->postMessageFromOuterSpace(m); +} diff --git a/vsleeptimer.h b/vsleeptimer.h new file mode 100644 index 0000000..b6c04ec --- /dev/null +++ b/vsleeptimer.h @@ -0,0 +1,86 @@ +/* + Copyright 2008 Googles + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef VSLEEPTIMER_H +#define VSLEEPTIMER_H + +#include + +#include "boxx.h" +#include "timerreceiver.h" + +#ifndef WIN32 +#include "threadp.h" +#else +#include "threadwin.h" +#endif + +class Sleeptimer : public Thread_TYPE +{ + public: + Sleeptimer(); + virtual ~Sleeptimer(); + static Sleeptimer* getInstance(); + const char* SetTime(); + void shutdown(); + virtual void threadMethod(); + virtual void threadPostStopCleanup() {}; + + private: + int sec; + bool active; + static Sleeptimer* instance; + + + +}; + + + + +class VSleeptimer : public Boxx, public TimerReceiver +{ + public: + VSleeptimer(); + ~VSleeptimer(); + void draw(); + int handleCommand(int command); + void timercall(int clientReference); + + private: + const char* displaySleeptimer; + +}; + +class VCountdown : public Boxx, public TimerReceiver +{ + + public: + VCountdown(); + ~VCountdown(); + void draw(const char* sec); + void timercall(int clientReference); + +} +; + + +#endif + diff --git a/wsymbol.cc b/wsymbol.cc index 4f693e0..a4d8262 100644 --- a/wsymbol.cc +++ b/wsymbol.cc @@ -22,8 +22,8 @@ #include "colour.h" -UCHAR WSymbol::widths[] = { 2, 2, 4, 4, 1, 1, 3, 3, 3, 3, 3, 4, 4, 2, 2, 3, 5, 5, 4, 4, 2, 2, 5, 5, 4, 4}; -UCHAR WSymbol::heights[] = { 8, 8, 12, 12, 24, 4, 18, 18, 18, 18, 18, 30, 30, 16, 16, 18, 18, 18, 16, 16, 8, 8, 16, 16, 16, 16}; +UCHAR WSymbol::widths[] = { 2, 2, 4, 4, 1, 1, 3, 3, 3, 3, 3, 4, 4, 2, 2, 3, 5, 5, 4, 4, 2, 2, 5, 5, 4, 4, 5}; +UCHAR WSymbol::heights[] = { 8, 8, 12, 12, 24, 4, 18, 18, 18, 18, 18, 30, 30, 16, 16, 18, 18, 18, 16, 16, 8, 8, 16, 16, 16, 16, 26}; UCHAR WSymbol::symbols[] = { @@ -999,12 +999,61 @@ UCHAR WSymbol::symbols[] = { 0xFF, 0x03, 0xFC, 0xFF, 0xFF, 0x03, 0xFC, 0xFF, +/* +00000000 00011111 11111111 11111000 00000000 +00000000 00111111 11111111 11111100 00000000 +00000000 01111111 11111111 11111110 00000000 +00000000 11111111 11111111 11111111 00000000 +00000001 11111111 11111111 11111111 10000000 +00000011 11111100 00000000 00111111 11000000 +00000111 11111000 00000000 00011111 11100000 +00001111 11110000 00111100 00001111 11110000 +00011111 11100000 00111100 00000111 11111000 +00111111 11000000 00111100 00000011 11111100 +01111111 10000000 00111100 00000001 11111110 +11111111 00000000 00111111 11111100 11111111 +11111111 00000000 00111111 11111100 11111111 +11111111 00000000 00111111 11111100 11111111 +11111111 00000000 00111111 11111100 11111111 +01111111 10000000 00000000 00000001 11111110 +00111111 11000000 00000000 00000011 11111100 +00011111 11100000 00000000 00000111 11111000 +00001111 11110000 00000000 00001111 11110000 +00000111 11111000 00000000 00011111 11100000 +00000011 11111100 00000000 00111111 11000000 +00000001 11111111 11111111 11111111 10000000 +00000000 11111111 11111111 11111110 00000000 +00000000 01111111 11111111 11111100 00000000 +00000000 00111111 11111111 11111000 00000000 +00000000 00011111 11111111 11110000 00000000 +*/ - - - - - +0x00, 0x1F, 0xFF, 0xF8, 0x00, +0x00, 0x3F, 0xFF, 0xFC, 0x00, +0x00, 0x7F, 0xFF, 0xFE, 0x00, +0x00, 0xFF, 0xFF, 0xFF, 0x00, +0x01, 0xFF, 0xFF, 0xFF, 0x80, +0x03, 0xFC, 0x00, 0x3F, 0xC0, +0x07, 0xF8, 0x00, 0x1F, 0xE0, +0x0F, 0xF0, 0x3C, 0x0F, 0xF0, +0x1F, 0xE0, 0x3C, 0x07, 0xF8, +0x3F, 0xC0, 0x3C, 0x03, 0xFC, +0x7F, 0x80, 0x3C, 0x01, 0xFE, +0xFF, 0x00, 0x3F, 0xFC, 0xFF, +0xFF, 0x00, 0x3F, 0xFC, 0xFF, +0xFF, 0x00, 0x3F, 0xFC, 0xFF, +0xFF, 0x00, 0x3F, 0xFC, 0xFF, +0x7F, 0x80, 0x00, 0x01, 0xFE, +0x3F, 0xC0, 0x00, 0x03, 0xFC, +0x1F, 0xE0, 0x00, 0x07, 0xF8, +0x0F, 0xF0, 0x00, 0x0F, 0xF0, +0x07, 0xF8, 0x00, 0x1F, 0xE0, +0x03, 0xFC, 0x00, 0x3F, 0xC0, +0x01, 0xFF, 0xFF, 0xFF, 0x80, +0x00, 0xFF, 0xFF, 0xFE, 0x00, +0x00, 0x7F, 0xFF, 0xFC, 0x00, +0x00, 0x3F, 0xFF, 0xF8, 0x00, +0x00, 0x1F, 0xFF, 0xF0, 0x00, }; diff --git a/wsymbol.h b/wsymbol.h index 2a6c940..4cb59c9 100644 --- a/wsymbol.h +++ b/wsymbol.h @@ -61,7 +61,7 @@ class WSymbol : public Boxx const static UCHAR VIDEOASPECT169 = 23; const static UCHAR SINGLEAUDIO = 24; const static UCHAR MULTIAUDIO = 25; - + const static UCHAR CLOCK = 26; private: static UCHAR symbols[]; static UCHAR widths[]; -- 2.39.2