screensaver now implemented in python (too) including idle message per state.

master
Florian Streibelt 13 years ago
parent f5f55eff84
commit 18f1de1b26

@ -38,6 +38,17 @@ display_fifo = None
scroll_line1 = None scroll_line1 = None
scroll_line2 = None scroll_line2 = None
idlemessage = None
offset_line1 = 0
offset_line2 = 0
brightness = 5
screensaver = 0
SCREENSAVER_DIM = 30
SCREENSAVER_TIMEOUT = 90
SCREENSAVER_OFF = 300
lock = allocate_lock() lock = allocate_lock()
@ -59,25 +70,72 @@ def display_scroll_text(line,text):
def display_handle_scroll(line,text,offset): def display_handle_scroll(line,text,offset):
if (text): if (text):
send_display("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
l = len(text) l = len(text)
missing_chars=20+offset-l if (l<21):
if (missing_chars>0): if (offset == 0):
send_display(text[:missing_chars]) send_display("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
offset=((offset+1)%l) offset=1
else:
send_display("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
missing_chars=20+offset-l
if (missing_chars>0):
send_display(text[:missing_chars])
offset=((offset+1)%l)
else: else:
offset=0 #reset offset offset=0 #reset offset
return offset return offset
def display_cmd_dim(x):
global brightness
if (brightness!=x):
if (x==0): #turn off:
send_display("\x1F\x45%c" % chr(255) )
brightness = x
return
else:
if (brightness==0): #turn on, then set wanted brightness:
send_display("\x1F\x45%c" % chr(0) )
brightness = x
send_display("\x1F\x58%c" % chr(x-1) )
def display_thread(x): def display_thread(x):
global scroll_line1,scroll_line2 global scroll_line1,scroll_line2
global offset_line1,offset_line2 global offset_line1,offset_line2
global screensaver
global idlemessage
offset_line1=0 offset_line1=0
offset_line2=0 offset_line2=0
while(True): while(True):
lock.acquire() lock.acquire()
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):
screensaver=screensaver+1
if ((screensaver >= SCREENSAVER_DIM) and (screensaver <= (SCREENSAVER_DIM+7))): #activate first stage of screensaver:
x = (8-( screensaver - SCREENSAVER_DIM))/2
display_cmd_dim(1+x)
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
if (screensaver == SCREENSAVER_OFF):
display_cmd_dim(0)
lock.release() lock.release()
time.sleep(.5) time.sleep(.5)
@ -110,8 +168,13 @@ def send_display(s):
def display_screen(title,message): def display_screen(title,message):
global scroll_line1,scroll_line2 global scroll_line1,scroll_line2
global offset_line1,offset_line2 global offset_line1,offset_line2
global screensaver
offset_line1=0 offset_line1=0
offset_line2=0 offset_line2=0
screensaver=0
display_cmd_dim(5)
if (len(title)<21): if (len(title)<21):
scroll_line1=None scroll_line1=None
send_display("\x1f\x24\x01%c\x18%s" % (chr(1),'\xdb'*20) ) send_display("\x1f\x24\x01%c\x18%s" % (chr(1),'\xdb'*20) )
@ -123,22 +186,22 @@ def display_screen(title,message):
else: else:
display_scroll_text(1,title) display_scroll_text(1,title)
if (len(message)<21): display_scroll_text(2,message)
scroll_line2=None
send_display("\x1f\x24%c%c\x18%s" % (chr(1),chr(2),message) )
else:
display_scroll_text(2,message)
#Front-End function to send data to the display. #Front-End function to send data to the display.
def print_display(s): def print_display(s):
global scroll_line1,scroll_line2 global scroll_line1,scroll_line2
global offset_line1,offset_line2 global offset_line1,offset_line2
global screensaver
lock.acquire() lock.acquire()
screensaver=0
offset_line1=0 offset_line1=0
offset_line2=0 offset_line2=0
scroll_line1=None scroll_line1=None
scroll_line2=None scroll_line2=None
display_cmd_dim(5)
send_display(s) send_display(s)
lock.release() lock.release()
@ -208,6 +271,7 @@ class Status:
self.transfers = None self.transfers = None
def dump(self): def dump(self):
def sign(amount, plus='+'): def sign(amount, plus='+'):
return '-' if amount < 0 else plus return '-' if amount < 0 else plus
@ -443,12 +507,14 @@ def print_prompt():
def handle(line, status): def handle(line, status):
global idlemessage
if line == 'exit': if line == 'exit':
clear() clear()
print_display("\x1b\x40exit...") print_display("\x0c")
sys.exit(0) sys.exit(0)
if status.logged_in(): if status.logged_in():
idlemessage=" Comitten nicht vergessen! ***"
if line in CODES: if line in CODES:
call = CODES[line] call = CODES[line]
method = call[0] method = call[0]
@ -467,6 +533,7 @@ def handle(line, status):
else: else:
status.buy(item) status.buy(item)
else: else:
idlemessage="Mir ist langweilig!"
try: try:
status.login(line) status.login(line)
except urllib2.HTTPError as e: except urllib2.HTTPError as e:
@ -488,7 +555,7 @@ def main():
colorama.init() colorama.init()
status = Status() status = Status()
global scroll_line1,scroll_line2 global scroll_line1,scroll_line2
print_display("\x1b\x40Kassensystem \n startet...") print_display("\x1b\x40\x1f\x43\x00")
start_new_thread(display_thread,(1,)) start_new_thread(display_thread,(1,))
#display_scroll_text(1,"Line1: Text, dumm scrollend!") #display_scroll_text(1,"Line1: Text, dumm scrollend!")

@ -301,7 +301,7 @@ main (int argc, char **argv)
//TODO: arg parser! //TODO: arg parser!
fifo = strdup ("/tmp/display"); fifo = strdup ("/tmp/display");
pausemsg = strdup("Bitte scanne Deine ID-Karte um Dich anzumelden *** "); pausemsg = NULL ; //strdup("Bitte scanne Deine ID-Karte um Dich anzumelden *** ");
if (argc != 2) if (argc != 2)
{ {

Loading…
Cancel
Save