genebean / PiWeatherRock

Displays local weather on a Raspberry Pi
https://piweatherrock.technicalissues.us
MIT License
50 stars 23 forks source link

Add ability to adjust screen timing #41

Closed metaMMA closed 4 years ago

metaMMA commented 4 years ago

This pull request adds three variables to the config.py.sample, and amends weather.py to accept these variables. It was written to be backward compatible with what current users are accustomed to seeing.

config.py.sample additions:

# Number of seconds to pause on the Daily and Hourly weather screens.
DH_PAUSE = 60 # 1 minute

# Number of seconds to pause on the Info screen.
INFO_SCREEN_PAUSE = 300 # 5 minutes

# Number of seconds between showing the info screen.
INFO_SCREEN_DELAY = 900 # 15 minutes

weather.py amendments (line 867+):

    # Automatically switch back to weather display after a couple minutes.
    if MODE not in ('d', 'h'):
        PERIODIC_INFO_ACTIVATION = 0
        NON_WEATHER_TIMEOUT += 1
        # Default in config.py.sample: pause for 5 minutes on info screen
        if NON_WEATHER_TIMEOUT > (config.INFO_SCREEN_PAUSE * 10):
            MODE = 'd'
            syslog.syslog("Switched to weather mode")
    else:
        NON_WEATHER_TIMEOUT = 0
        PERIODIC_INFO_ACTIVATION += 1
        # Default in config.py.sample: flip between 2 weather screens
        # for 15 minutes before showing info screen.
        if PERIODIC_INFO_ACTIVATION > (config.INFO_SCREEN_DELAY * 10):
            MODE = 'i'
            syslog.syslog("Switched to info mode")
        elif (PERIODIC_INFO_ACTIVATION % (config.DH_PAUSE * 10)) == 0 and
              MODE == 'd'):
            MODE = 'h'
        elif (PERIODIC_INFO_ACTIVATION % (config.DH_PAUSE * 10)) == 0 and
              MODE == 'h'):
            MODE = 'd'
metaMMA commented 4 years ago

Relevant: https://github.com/genebean/PiWeatherRock/issues/28

genebean commented 4 years ago

Thank you very much for this! The code looks good. I want to test it locally today but will merge it after that so long as it behaves as expected.

metaMMA commented 4 years ago

Thank you very much for this! The code looks good. I want to test it locally today but will merge it after that so long as it behaves as expected.

No problem. After reading Issue https://github.com/genebean/PiWeatherRock/issues/28 I think I'm going to amend this further, so that the end user can choose different screen times for daily and hourly, as well. I'll push the changes later today.

metaMMA commented 4 years ago

update to config.py.sample additions:

# Number of seconds to pause on the Daily weather screen.
DAILY_PAUSE = 60 # 1 minute

# Number of seconds to pause on the Hourly weather screen. 
HOURLY_PAUSE = 60 # 1 minute

# Number of seconds to pause on the Info screen.
INFO_SCREEN_PAUSE = 300 # 5 minutes

# Number of seconds between showing the info screen.
INFO_SCREEN_DELAY = 900 # 15 minutes

update to weather.py (line 869+)

    # Automatically switch back to weather display after a couple minutes.
    if MODE not in ('d', 'h'):
        PERIODIC_INFO_ACTIVATION = 0
        NON_WEATHER_TIMEOUT += 1
        D_COUNT = 0
        H_COUNT = 0
        # Default in config.py.sample: pause for 5 minutes on info screen.
        if NON_WEATHER_TIMEOUT > (config.INFO_SCREEN_PAUSE * 10):
            MODE = 'd'
            D_COUNT = 1
            syslog.syslog("Switching to weather mode")
    else:
        NON_WEATHER_TIMEOUT = 0
        PERIODIC_INFO_ACTIVATION += 1
        # Default in config.py.sample: flip between 2 weather screens
        # for 15 minutes before showing info screen.
        if PERIODIC_INFO_ACTIVATION > (config.INFO_SCREEN_DELAY * 10):
            MODE = 'i'
            syslog.syslog("Switching to info mode")
        elif (PERIODIC_INFO_ACTIVATION % (((config.DAILY_PAUSE * D_COUNT) +
              (config.HOURLY_PAUSE * H_COUNT)) * 10)) == 0:
            if MODE == 'd':
                syslog.syslog("Switching to HOURLY")
                MODE = 'h'
                H_COUNT += 1
            else:
                syslog.syslog("Switching to DAILY")
                MODE = 'd'
                D_COUNT += 1

additions to global variable ( lines 61-62)

D_COUNT = 1
H_COUNT = 0
genebean commented 4 years ago

This is working good for me, thanks!

Feb 27 20:55:43 tart python3[3863]: pygame 1.9.6
Feb 27 20:55:43 tart python3[3863]: Hello from the pygame community. https://www.pygame.org/contribute.html
Feb 27 20:55:43 tart python3[3863]: X Display = :0
Feb 27 20:55:43 tart python3[3863]: Framebuffer Size: 1824 x 984
Feb 27 20:55:44 tart systemd[1]: PiWeatherRock.service: Succeeded.
Feb 27 20:55:44 tart systemd[1]: Stopped PiWeatherRock Service.
Feb 27 20:55:44 tart systemd[1]: Started PiWeatherRock Service.
Feb 27 20:55:44 tart sudo[3894]: pam_unix(sudo:session): session closed for user root
Feb 27 20:55:48 tart /weather.py[3901]: X Display = :0
Feb 27 20:55:48 tart /weather.py[3901]: Framebuffer Size: 1824 x 984
Feb 27 20:57:27 tart /weather.py[3901]: Switching to HOURLY
Feb 27 20:59:00 tart /weather.py[3901]: Switching to DAILY
Feb 27 21:00:33 tart /weather.py[3901]: Switching to HOURLY
Feb 27 21:00:34 tart /weather.py[3901]: Switching to info mode
Feb 27 21:02:57 tart /weather.py[3901]: Switching to weather mode