From 4fb594582ea4587a83328b3e9964fde3c5bc36c1 Mon Sep 17 00:00:00 2001 From: anbr Date: Sat, 23 Oct 2010 18:45:18 +0200 Subject: Allow turn display off at night (Feature #175) --- watch.c | 128 +++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 78 insertions(+), 50 deletions(-) (limited to 'watch.c') diff --git a/watch.c b/watch.c index 712f28e..4a102a1 100644 --- a/watch.c +++ b/watch.c @@ -20,6 +20,7 @@ #include "ffont.h" #include +#include struct cMutexLooker { cMutex& mutex; @@ -65,7 +66,6 @@ cVFDWatch::cVFDWatch() replayTime = NULL; currentTime = NULL; - m_eWatchMode = eLiveTV; m_nScrollOffset = -1; @@ -210,6 +210,8 @@ void cVFDWatch::Action(void) unsigned int nCnt = 0; cTimeMs runTime; + struct tm tm_r; + bool bLastSuspend = false; for (;!m_bShutdown;++nCnt) { @@ -218,6 +220,7 @@ void cVFDWatch::Action(void) unsigned int nIcons = 0; bool bFlush = false; bool bReDraw = false; + bool bSuspend = false; if(m_bShutdown) break; else { @@ -225,64 +228,89 @@ void cVFDWatch::Action(void) runTime.Set(); time_t ts = time(NULL); - - // every second the clock need updates. - if (theSetup.m_nRenderMode == eRenderMode_DualLine) { - if((0 == (nCnt % 2))) { - bReDraw = CurrentTime(ts); - if(m_eWatchMode != eLiveTV) { - bReDraw |= ReplayTime(); - } + if(theSetup.m_nSuspendMode != eSuspendMode_Never + && theSetup.m_nSuspendTimeOff != theSetup.m_nSuspendTimeOn) { + struct tm *now = localtime_r(&ts, &tm_r); + int clock = now->tm_hour * 100 + now->tm_min; + if(theSetup.m_nSuspendTimeOff > theSetup.m_nSuspendTimeOn) { //like 8-20 + bSuspend = (clock >= theSetup.m_nSuspendTimeOn) + && (clock <= theSetup.m_nSuspendTimeOff); + } else { //like 0-8 and 20..24 + bSuspend = (clock >= theSetup.m_nSuspendTimeOn) + || (clock <= theSetup.m_nSuspendTimeOff); + } + if(theSetup.m_nSuspendMode == eSuspendMode_Timed + && !ShutdownHandler.IsUserInactive()) { + bSuspend = false; } } - - bFlush = RenderScreen(bReDraw); - if(m_eWatchMode != eLiveTV) { - switch(ReplayMode()) { - case eReplayNone: - case eReplayPaused: - nIcons |= eIconPAUSE; - break; - default: - case eReplayPlay: - nIcons |= eIconPLAY; - break; - case eReplayBackward1: - case eReplayBackward2: - case eReplayBackward3: - break; - case eReplayForward1: - case eReplayForward2: - case eReplayForward3: - break; - } + if(bSuspend != bLastSuspend) { + bReDraw = true; } - for(n=0;n