From 124ab39f829f080dff53b723b79b239aeb34c003 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 26 Sep 2019 23:39:32 +0200 Subject: [PATCH] Expanded verbose options --- button.py | 5 +++-- clocky.py | 61 +++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/button.py b/button.py index 10d1570..09853ac 100644 --- a/button.py +++ b/button.py @@ -16,8 +16,9 @@ class Button: presstime=0 ignore=0 - def __init__(self, gpio): - print("initialize button on gpio %d" %gpio) + def __init__(self, gpio,verbose=False): + if verbose: + print("initialize button on gpio %d" %gpio) self.gpio = gpio GPIO.setup(self.gpio, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.add_event_detect(self.gpio, GPIO.BOTH, callback=self.my_callback) diff --git a/clocky.py b/clocky.py index 953752b..e17b700 100755 --- a/clocky.py +++ b/clocky.py @@ -6,6 +6,7 @@ import time import sys import tm1637 import max7219 +os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide" import pygame from time import sleep,strftime import RPi.GPIO as GPIO @@ -13,6 +14,7 @@ import button import signal import clockytracklist +VERBOSE=False settings= {} looptype=0 quit=0 @@ -49,7 +51,10 @@ reload=False def receive_signal(signum, stack): global stopprogram global reload - print('Received signal: %d' %signum) + if VERBOSE: + print('Received signal: %d' %signum) + else: + print("") if signum == signal.SIGHUP: reload=True if signum == signal.SIGINT: @@ -81,35 +86,40 @@ brightness=0 snooze=0 count=0 -print('My PID is %d' %os.getpid()) +if VERBOSE: + print('My PID is %d' %os.getpid()) signal.signal(signal.SIGHUP, receive_signal) signal.signal(signal.SIGINT, receive_signal) -but1=button.Button(21) -but2=button.Button(20) -but3=button.Button(26) +but1=button.Button(21,verbose=VERBOSE) +but2=button.Button(20,verbose=VERBOSE) +but3=button.Button(26,verbose=VERBOSE) #------------------------------------------------------------------ #------------------------------------------------------------------ while not stopprogram: - print("Load config...") + if VERBOSE: + print("Load config...") reload=False -# display=tm1637.TM1637(CLK=14, DIO=4, brightness=1) - display=max7219.MAX7219(brightness=1) + display=tm1637.TM1637(CLK=14, DIO=4, brightness=1) +# display=max7219.MAX7219(brightness=1) display.Clear() display.SetBrightnessRaw(o_defaultbrightness) - print("reading mp3s from directory:") - tracks=clockytracklist.ClockyTracklist("mp3",recursive=True,verbose=True) + if VERBOSE: + print("Reading mp3s from directory:") + tracks=clockytracklist.ClockyTracklist("mp3",recursive=True,verbose=VERBOSE) allmp3s=tracks.tracklist c=0 - for m in allmp3s: - print(" %2d : %s"%(c+1,m)) - c+=1 + if VERBOSE: + print("\nTracks:") + for m in allmp3s: + print("%2d : %s"%(c+1,m)) + c+=1 stamp() print("Started") @@ -129,7 +139,8 @@ while not stopprogram: handle.close() else: - print("Configfile: \""+o_configfilename+"\":") + if VERBOSE: + print("Configfile: \""+o_configfilename+"\":") with open(o_configfilename, 'rb') as handle: settings = pickle.load(handle) @@ -137,21 +148,27 @@ while not stopprogram: a_mins=int(settings['alarmtime']%60) a_hour=int((settings['alarmtime']-a_mins)/60) - print("Alarmtime : %02d:%02d"%(a_hour,a_mins)) - print("Alarmdisable: %d"%(settings['alarmdisabled'])) - print("Starttrack : %d"%(settings['starttrack'])) + if VERBOSE: + print("Alarmtime : %02d:%02d"%(a_hour,a_mins)) + print("Alarmdisable: %d"%(settings['alarmdisabled'])) + print("Starttrack : %d"%(settings['starttrack'])) for i in range(0,10): if i==settings['starttrack']: - print("=>",end='') + if VERBOSE: + print("=>",end='') else: - print(" ",end='') - print(" [T%01dM%02d] "%(i,settings["track%d"%i]),end='') + if VERBOSE: + print(" ",end='') + if VERBOSE: + print(" [T%01dM%02d] "%(i,settings["track%d"%i]),end='') if settings["track%d"%i] and (settings["track%d"%i]-1 < len(allmp3s)): + if VERBOSE: print("\""+allmp3s[settings["track%d"%i]-1]+"\"") else: + if VERBOSE: print("") - settings["track%d"%i]=0 + settings["track%d"%i]=0 writesettings() @@ -472,7 +489,7 @@ while not stopprogram: # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if looptype==5: # Alarm! + if looptype==5: # Alarm loop! #o_timetomaxvol = 60 # seconds it takes to go from 0% to 100% volume if colon: