yea, now screensaver almost works... or sth like that. lets convert the helper funcs

This commit is contained in:
Florian Streibelt 2011-10-18 23:10:35 +02:00
parent f575423506
commit 2858b1e71a
2 changed files with 35 additions and 18 deletions

View File

@ -8,7 +8,7 @@ class Display:
self.portlock = allocate_lock()
self.portname=portname
self.open_port()
self.brightness=0
self.brightness=5
self.screensaver = Screensaver(self)
self.screensaver.start()
@ -56,9 +56,12 @@ class Display:
def cmd_brightness(self,level):
if (self.brightness==level):
return
print("setting brightness to %i \n" %level)
if (level==0): #turn off:
self.cmd_display_on(False)
self.brightness = level
self.brightness = 0
return
else:
if (self.brightness==0): #turn on, then set wanted brightness:
@ -71,18 +74,26 @@ class Display:
# where the last value defines the blink rate,
# with 0=always on, 255=always off
if (on):
if (not self.brightness==0):
return
print("setting display to on: %s \n" % str(on))
self.cmd_blink(0)
self.brightness=5
else:
if (self.brightness==0):
return
print("setting display to on: %s \n" % str(on))
self.cmd_blink(255)
self.brightness=0
def cmd_curmode_overwrite(self):
cmd_curmode(1)
self.cmd_curmode(1)
def cmd_curmode_vscroll(self):
cmd_curmode(2)
self.cmd_curmode(2)
def cmd_curmode_hscroll(self):
cmd_curmode(3)
self.cmd_curmode(3)
def cmd_curmode(self,val=2):
self.cmd("\x1f%c" % chr(val))
@ -140,9 +151,9 @@ class Screensaver (threading.Thread):
self.display=display
self.runme=True
self.idlecounter=0
self.timeout_dim=30
self.timeout_message=60
self.timeout_off=120
self.timeout_dim=10
self.timeout_message=20
self.timeout_off=32
self.mutex = allocate_lock()
threading.Thread.__init__(self)
@ -162,26 +173,30 @@ class Screensaver (threading.Thread):
def idle_reset(self):
self.mutex.acquire()
self.idlecounter=0
self.display.cmd_brightness(5)
self.mutex.release()
def _main_loop(self):
if (self.idlecounter < self.timeout_off):
self.idlecounter+=1
if (self.idlecounter>=self.timeout_dim and self.idlecounter <= (self.timeout_dim+7)):
x = (8-( self.idlecounter - self.timeout_dim))/2
self.display.mutax_get()
self.display.mutex_get()
self.display.cmd_brightness(1+x)
self.display.mutax_release()
self.display.mutex_release()
return
if (self.idlecounter==self.timeout_message):
print("WHAAAAGHAA")
self.display.mutex_get()
self.display.cmd_time_set()
self.display.mutex_release()
return
if (self.idlecounter==self.timeout_off):
self.display.mutax_get()
display.cmd_display_on(False)
self.display.mutax_release()
self.display.mutex_get()
self.display.cmd_display_on(False)
self.display.mutex_release()
return
def __del__(self):

View File

@ -110,8 +110,8 @@ def display_thread(x):
offset_line1 = display_handle_scroll(1,scroll_line1,offset_line1)
offset_line2 = display_handle_scroll(2,scroll_line2,offset_line2)
if (screensaver <= SCREENSAVER_OFF):
screensaver=screensaver+1
# if (screensaver <= SCREENSAVER_OFF):
# screensaver=screensaver+1
if (screensaver == SCREENSAVER_TIMEOUT):
@ -131,7 +131,7 @@ def display_thread(x):
def send_display(s):
global myDisplay
myDisplay.write(s)
# myDisplay.write(s,False)
#Front-End Funtion to display a Screen
# with heading
@ -174,7 +174,7 @@ def print_display(s):
scroll_line1=None
scroll_line2=None
display_cmd_dim(5)
myDisplay.write(s)
# myDisplay.write(s,False)
lock.release()
def clear():
@ -550,6 +550,8 @@ def main():
myDisplay = Display("/dev/ttyUSB0")
myDisplay.cmd_reset()
myDisplay.write("Hello world!\n")
time.sleep(10)
myDisplay.cmd_cursor_show(False)
start_new_thread(display_thread,(1,))