|
|
|
@ -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()
|
|
|
|
|