Browse Source

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

master
Florian Streibelt 11 years ago
parent
commit
18f1de1b26
  1. 91
      client-barcode/freitagskasse.py
  2. 2
      display-daemon/ser.c

91
client-barcode/freitagskasse.py

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

2
display-daemon/ser.c

@ -301,7 +301,7 @@ main (int argc, char **argv) @@ -301,7 +301,7 @@ main (int argc, char **argv)
//TODO: arg parser!
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)
{

Loading…
Cancel
Save