From 7bc4745e2ad16f2ac2480ee23b7aa1a233ad17f9 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 Nov 2016 22:50:53 +0100 Subject: [PATCH] make it possible to align autotime to an minute --- config/settings/espeak.settings.conf | 5 +++- config/settings/settings.conf | 7 +++-- config/settings/settings.conf.chrys | 5 +++- config/settings/settings.conf.storm | 5 +++- .../commands/onScreenUpdate/76000-time.py | 28 +++++++++++++++---- src/fenrir/core/settings.py | 3 +- 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 3e8183ba..76ea1f1a 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -125,4 +125,7 @@ list= enabled=False presentTime=True presentDate=True -delaySec=3600 +delaySec=0 +# present time after to given minutes example every 15 minutes: 00,15,30,45 +# if delaySec is >0 onMinutes is ignored +onMinutes=00,30 diff --git a/config/settings/settings.conf b/config/settings/settings.conf index c3b007f5..eb8146df 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -130,5 +130,8 @@ enabled=False presentTime=True # present date (on change) presentDate=True -# present time after x seconds -delaySec=3600 +# present time after a given period of seconds +delaySec=0 +# present time after to given minutes example every 15 minutes: 00,15,30,45 +# if delaySec is >0 onMinutes is ignored +onMinutes=00,30 diff --git a/config/settings/settings.conf.chrys b/config/settings/settings.conf.chrys index 82861dfb..e348d363 100644 --- a/config/settings/settings.conf.chrys +++ b/config/settings/settings.conf.chrys @@ -131,4 +131,7 @@ presentTime=True # present date (on change) presentDate=True # present time after x seconds -delaySec=3600 +delaySec=0 +# present time after to given minutes example every 15 minutes: 00,15,30,45 +# if delaySec is >0 onMinutes is ignored +onMinutes=00,30 diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index 5b47566f..2714b2c2 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -81,4 +81,7 @@ presentTime=True # present date (on change) presentDate=True # present time after x seconds -delaySec=3600 +delaySec=0 +# present time after to given minutes example every 15 minutes: 00,15,30,45 +# if delaySec is >0 onMinutes is ignored +onMinutes=00,30 diff --git a/src/fenrir/commands/onScreenUpdate/76000-time.py b/src/fenrir/commands/onScreenUpdate/76000-time.py index f63461e8..20b2062d 100644 --- a/src/fenrir/commands/onScreenUpdate/76000-time.py +++ b/src/fenrir/commands/onScreenUpdate/76000-time.py @@ -14,7 +14,7 @@ class command(): pass def initialize(self, environment): self.env = environment - self.lastTime = time.time() + self.lastTime = datetime.datetime.now() self.lastDateString = '' self.lastTimeString = '' def shutdown(self): @@ -25,13 +25,31 @@ class command(): def run(self): if not self.env['runtime']['settingsManager'].getSettingAsBool('time', 'enabled'): return - if int(time.time() - self.lastTime) < self.env['runtime']['settingsManager'].getSettingAsInt('time', 'delaySec'): + onMinutes = self.env['runtime']['settingsManager'].getSetting('time', 'onMinutes') + delaySec = self.env['runtime']['settingsManager'].getSettingAsInt('time', 'delaySec') + # no need + if onMinutes == '' and delaySec <= 0: return + onMinutes = onMinutes.split(',') + now = datetime.datetime.now() + # ignore onMinutes if there is a delaySec + if delaySec > 0: + if int((now-self.lastTime).total_seconds()) < delaySec: + return + else: + # shoul announce? + if not str(now.minute) in onMinutes: + return + # already announced? + if now.hour == self.lastTime.hour: + if now.minute == self.lastTime.minute: + return + timeFormat = self.env['runtime']['settingsManager'].getSetting('general', 'timeFormat') - timeString = datetime.datetime.strftime(datetime.datetime.now(), timeFormat) + timeString = datetime.datetime.strftime(now, timeFormat) dateFormat = self.env['runtime']['settingsManager'].getSetting('general', 'dateFormat') - dateString = datetime.datetime.strftime(datetime.datetime.now(), dateFormat) + dateString = datetime.datetime.strftime(now, dateFormat) if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentTime'): # present the time self.env['runtime']['outputManager'].presentText('Autotime: ' + timeString , soundIcon='', interrupt=False) @@ -40,7 +58,7 @@ class command(): if self.lastDateString != dateString: self.env['runtime']['outputManager'].presentText(dateString , soundIcon='', interrupt=False) self.lastDateString = dateString - self.lastTime = time.time() + self.lastTime = datetime.datetime.now() self.lastTimeString = timeString def setCallback(self, callback): pass diff --git a/src/fenrir/core/settings.py b/src/fenrir/core/settings.py index fab91ada..c21aca01 100644 --- a/src/fenrir/core/settings.py +++ b/src/fenrir/core/settings.py @@ -68,7 +68,8 @@ settings = { 'enabled': False, 'presentTime': True, 'presentDate': True, - 'delaySec': 3600, + 'delaySec': 0, + 'onMinutes': '00,30', }, 'keyboard':{ 'driver': 'evdev',