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

View File

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