its scrolling, yay.
This commit is contained in:
parent
2858b1e71a
commit
a9d82b9b85
|
@ -1,16 +1,22 @@
|
|||
import serial
|
||||
from thread import start_new_thread, allocate_lock
|
||||
import time
|
||||
import threading
|
||||
|
||||
class Display:
|
||||
class Display(threading.Thread):
|
||||
def __init__(self,portname="/dev/ttyUSB0"):
|
||||
threading.Thread.__init__(self)
|
||||
self.serialport=None
|
||||
self.runme=True
|
||||
self.portlock = allocate_lock()
|
||||
self.portname=portname
|
||||
self.open_port()
|
||||
self.brightness=5
|
||||
self.scroll_line1 = None
|
||||
self.scroll_line2 = None
|
||||
self.offset_line1 = 0
|
||||
self.offset_line2 = 0
|
||||
self.screensaver = Screensaver(self)
|
||||
self.screensaver.start()
|
||||
self.open_port()
|
||||
|
||||
def __del__(self):
|
||||
if (not self.screensaver == None):
|
||||
|
@ -38,6 +44,79 @@ class Display:
|
|||
pass
|
||||
|
||||
|
||||
#Helper-Function, scrolls text in a specific line.
|
||||
def display_scroll_text(self,line,text):
|
||||
if (line==1): #clear the line on invocation:
|
||||
self.cmd("\x1f\x24\x01%c\x18" % chr(line) )
|
||||
self.scroll_line1 = text
|
||||
self.offset_line1=0
|
||||
if (line==2): #clear the line on invocation:
|
||||
self.cmd("\x1f\x24\x01%c\x18" % chr(line) )
|
||||
self.scroll_line2 = text
|
||||
self.offset_line2=0
|
||||
|
||||
|
||||
def display_handle_scroll(self,line,text,offset):
|
||||
if (text):
|
||||
l = len(text)
|
||||
if (l<21):
|
||||
if (offset == 0):
|
||||
self.cmd("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
|
||||
offset=1
|
||||
else:
|
||||
self.cmd("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
|
||||
missing_chars=20+offset-l
|
||||
if (missing_chars>0):
|
||||
self.cmd(text[:missing_chars])
|
||||
offset=((offset+1)%l)
|
||||
else:
|
||||
offset=0 #reset offset
|
||||
return offset
|
||||
|
||||
|
||||
def run(self):
|
||||
print "Starting Display thread"
|
||||
self.screensaver.start()
|
||||
while(self.runme):
|
||||
print("display thread loop\n")
|
||||
self.mutex_get()
|
||||
print("display got mutex and handles scroll\n")
|
||||
self.offset_line1 = self.display_handle_scroll(1,self.scroll_line1,self.offset_line1)
|
||||
self.offset_line2 = self.display_handle_scroll(2,self.scroll_line2,self.offset_line2)
|
||||
self.mutex_release()
|
||||
time.sleep(.5)
|
||||
print "Exiting Display thread"
|
||||
|
||||
def terminate(self):
|
||||
self.runme = False
|
||||
|
||||
|
||||
|
||||
#Front-End Funtion to display a Screen
|
||||
# with heading
|
||||
def display_screen(self,title,message):
|
||||
self.mutex_get()
|
||||
|
||||
self.offset_line1=0
|
||||
self.offset_line2=0
|
||||
self.screensaver.idle_reset();
|
||||
self.cmd_brightness(5)
|
||||
|
||||
if (len(title)<21):
|
||||
self.scroll_line1=None
|
||||
self.cmd("\x1f\x24\x01%c\x18%s" % (chr(1),'\xdb'*20) )
|
||||
if (len(title)<20):
|
||||
pos=1+(20-len(title))/2
|
||||
else:
|
||||
pos=1
|
||||
self.cmd("\x1f\x24%c%c%s" % (chr(pos),chr(1),title) )
|
||||
else:
|
||||
self.display_scroll_text(1,title)
|
||||
|
||||
self.display_scroll_text(2,message)
|
||||
self.mutex_release()
|
||||
|
||||
|
||||
|
||||
|
||||
def cmd_reset(self):
|
||||
|
@ -148,6 +227,7 @@ import time
|
|||
|
||||
class Screensaver (threading.Thread):
|
||||
def __init__(self,display):
|
||||
threading.Thread.__init__(self)
|
||||
self.display=display
|
||||
self.runme=True
|
||||
self.idlecounter=0
|
||||
|
@ -187,7 +267,6 @@ class Screensaver (threading.Thread):
|
|||
return
|
||||
|
||||
if (self.idlecounter==self.timeout_message):
|
||||
print("WHAAAAGHAA")
|
||||
self.display.mutex_get()
|
||||
self.display.cmd_time_set()
|
||||
self.display.mutex_release()
|
||||
|
|
|
@ -95,40 +95,6 @@ def display_cmd_dim(x):
|
|||
return
|
||||
|
||||
|
||||
def display_thread(x):
|
||||
global scroll_line1,scroll_line2
|
||||
global offset_line1,offset_line2
|
||||
global screensaver
|
||||
global idlemessage
|
||||
global lock
|
||||
|
||||
offset_line1=0
|
||||
offset_line2=0
|
||||
while(True):
|
||||
lock.acquire()
|
||||
|
||||
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_TIMEOUT):
|
||||
now = time.localtime()
|
||||
send_display("\x0c\x1F\x54%c%c\x1f\x03" % (chr(now.tm_hour),chr(now.tm_min)));
|
||||
if (scroll_line2):
|
||||
scroll_line1=scroll_line2
|
||||
else:
|
||||
scroll_line1=idlemessage
|
||||
scroll_line2=None
|
||||
offset_line1=0
|
||||
offset_line2=0
|
||||
|
||||
lock.release()
|
||||
time.sleep(.5)
|
||||
|
||||
|
||||
def send_display(s):
|
||||
global myDisplay
|
||||
# myDisplay.write(s,False)
|
||||
|
@ -549,14 +515,13 @@ def main():
|
|||
global myDisplay
|
||||
|
||||
myDisplay = Display("/dev/ttyUSB0")
|
||||
myDisplay.start()
|
||||
myDisplay.cmd_reset()
|
||||
myDisplay.write("Hello world!\n")
|
||||
time.sleep(10)
|
||||
myDisplay.display_screen("Nachricht","Hallo Welt! Dies ist eine sehr lange NAchricht!")
|
||||
time.sleep(100)
|
||||
myDisplay.cmd_cursor_show(False)
|
||||
start_new_thread(display_thread,(1,))
|
||||
|
||||
#display_scroll_text(1,"Line1: Text, dumm scrollend!")
|
||||
#display_scroll_text(4,"Line2: Und hier Text, auch dumm scrollend!")
|
||||
display_screen("HINWEIS","Herzlich willkommen bei der Freitagsrunde! *** ")
|
||||
while True:
|
||||
clear()
|
||||
|
|
Loading…
Reference in New Issue