|
|
|
@ -42,7 +42,6 @@ display_fifo = None
|
|
|
|
|
scroll_line1 = None
|
|
|
|
|
scroll_line2 = None
|
|
|
|
|
|
|
|
|
|
idlemessage = None
|
|
|
|
|
|
|
|
|
|
offset_line1 = 0
|
|
|
|
|
offset_line2 = 0
|
|
|
|
@ -56,158 +55,6 @@ SCREENSAVER_OFF = 2* 10*60
|
|
|
|
|
|
|
|
|
|
lock = allocate_lock()
|
|
|
|
|
|
|
|
|
|
#Helper-Function, scrolls text in a specific line.
|
|
|
|
|
def display_scroll_text(line,text):
|
|
|
|
|
global scroll_line1,scroll_line2
|
|
|
|
|
global offset_line1,offset_line2
|
|
|
|
|
lock.acquire()
|
|
|
|
|
if (line==1): #clear the line on invocation:
|
|
|
|
|
send_display("\x1f\x24\x01%c\x18" % chr(line) )
|
|
|
|
|
scroll_line1 = text
|
|
|
|
|
offset_line1=0
|
|
|
|
|
if (line==2): #clear the line on invocation:
|
|
|
|
|
send_display("\x1f\x24\x01%c\x18" % chr(line) )
|
|
|
|
|
scroll_line2 = text
|
|
|
|
|
offset_line2=0
|
|
|
|
|
lock.release()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def display_handle_scroll(line,text,offset):
|
|
|
|
|
if (text):
|
|
|
|
|
l = len(text)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_display(s):
|
|
|
|
|
global display_fifo
|
|
|
|
|
if not display_fifo:
|
|
|
|
|
try:
|
|
|
|
|
fd = os.open( "/tmp/display", os.O_WRONLY)
|
|
|
|
|
display_fifo = os.fdopen(fd,"w")
|
|
|
|
|
except OSError:
|
|
|
|
|
display_fifo = None
|
|
|
|
|
pass
|
|
|
|
|
return
|
|
|
|
|
except IOError:
|
|
|
|
|
display_fifo = None
|
|
|
|
|
pass
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
display_fifo.write(s)
|
|
|
|
|
display_fifo.flush()
|
|
|
|
|
except IOError:
|
|
|
|
|
display_fifo = None
|
|
|
|
|
pass
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Front-End Funtion to display a Screen
|
|
|
|
|
# with heading
|
|
|
|
|
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) )
|
|
|
|
|
if (len(title)<20):
|
|
|
|
|
pos=1+(20-len(title))/2
|
|
|
|
|
else:
|
|
|
|
|
pos=1
|
|
|
|
|
send_display("\x1f\x24%c%c%s" % (chr(pos),chr(1),title) )
|
|
|
|
|
else:
|
|
|
|
|
display_scroll_text(1,title)
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
def clear():
|
|
|
|
|
os.system('clear')
|
|
|
|
@ -328,7 +175,7 @@ class Status:
|
|
|
|
|
if self.logged_in():
|
|
|
|
|
print('Eingeloggt als: %s%s%s' % (COLOR_SOME, self.login_name, COLOR_RESET))
|
|
|
|
|
print()
|
|
|
|
|
print_display('\x0cHallo %-14s' % (self.login_name[:13]+"!") )
|
|
|
|
|
myDisplay.write('\x0cHallo %-14s' % (self.login_name[:13]+"!") )
|
|
|
|
|
if self.transfers:
|
|
|
|
|
initial_command, initial_balance = self.transfers[0]
|
|
|
|
|
|
|
|
|
@ -360,11 +207,11 @@ class Status:
|
|
|
|
|
mylabel="Pfand "+command.commodity_label()[:9]
|
|
|
|
|
if (mycmd==3):
|
|
|
|
|
mylabel=("%-13s" % (command.commodity_label()[:13]))+"+P"
|
|
|
|
|
print_display('\x0b%-15s %4.2f' % (asciify(mylabel)[:15],abs(command.difference())));
|
|
|
|
|
print_display('\x0b\nSUMME: {%02i} %8.2f' % ((i-1),initial_balance - self.balance));
|
|
|
|
|
myDisplay.write('\x0b%-15s %4.2f' % (asciify(mylabel)[:15],abs(command.difference())));
|
|
|
|
|
myDisplay.write('\x0b\nSUMME: {%02i} %8.2f' % ((i-1),initial_balance - self.balance));
|
|
|
|
|
else:
|
|
|
|
|
print_display('\x0b%-15s %4.2f' % (command.label()[:15],abs(command.difference())));
|
|
|
|
|
print_display('\x0b\nSUMME: {%02i} %8.2f' % ((i-1),initial_balance - self.balance));
|
|
|
|
|
myDisplay.write('\x0b%-15s %4.2f' % (command.label()[:15],abs(command.difference())));
|
|
|
|
|
myDisplay.write('\x0b\nSUMME: {%02i} %8.2f' % ((i-1),initial_balance - self.balance));
|
|
|
|
|
|
|
|
|
|
if len(self.transfers) > 1:
|
|
|
|
|
show_total(self.balance - initial_balance, plus='+')
|
|
|
|
@ -373,13 +220,13 @@ class Status:
|
|
|
|
|
|
|
|
|
|
if self.balance < 0:
|
|
|
|
|
warn_balance()
|
|
|
|
|
print_display('\x0b\nKonto: %5.2f!' % (self.balance) )
|
|
|
|
|
myDisplay.write('\x0b\nKonto: %5.2f!' % (self.balance) )
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
print(COLOR_MUCH + 'Committen nicht vergessen.' + COLOR_RESET)
|
|
|
|
|
else:
|
|
|
|
|
print('Kontostand beträgt: %s%.2f Euro%s' % (COLOR_MUCH, self.balance, COLOR_RESET))
|
|
|
|
|
display_screen("KONTOSTAND","%s: %.2f Euro" % (self.login_name,self.balance))
|
|
|
|
|
myDisplay.display_screen("KONTOSTAND","%s: %.2f Euro" % (self.login_name,self.balance))
|
|
|
|
|
if self.balance < 0:
|
|
|
|
|
print()
|
|
|
|
|
warn_balance()
|
|
|
|
@ -387,7 +234,7 @@ class Status:
|
|
|
|
|
print(COLOR_MUCH + 'Bitte einloggen.' + COLOR_RESET)
|
|
|
|
|
print()
|
|
|
|
|
print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.')
|
|
|
|
|
display_screen("LOGIN","Bitte scanne Deinen login-Token! *** ")
|
|
|
|
|
myDisplay.display_screen("LOGIN","Bitte scanne Deinen login-Token! *** ")
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
def logged_in(self):
|
|
|
|
@ -416,7 +263,7 @@ class Status:
|
|
|
|
|
try:
|
|
|
|
|
command.run(self.login_name)
|
|
|
|
|
except urllib2.HTTPError as e:
|
|
|
|
|
print_display('\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
|
|
|
|
myDisplay.display_screen("Server error",'Server Error: %s' % str(e))
|
|
|
|
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
@ -499,11 +346,11 @@ class Status:
|
|
|
|
|
error_page(_PRODUCT_FIRST)
|
|
|
|
|
return
|
|
|
|
|
if prev.includes_deposit():
|
|
|
|
|
print_display('\x0cFEHLER: schon Pfand %20s' % prev.item_name()[:20])
|
|
|
|
|
myDisplay.write('\x0cFEHLER: schon Pfand %20s' % prev.item_name()[:20])
|
|
|
|
|
error_page('FEHLER: Pfand für Produkt "%s" bereits aktiviert' % prev.item_name())
|
|
|
|
|
return
|
|
|
|
|
if prev.deposit_value() <= 0:
|
|
|
|
|
print_display('\x0cFEHLER: Pfandfrei! %20s' % prev.item_name()[:20])
|
|
|
|
|
myDisplay.write('\x0cFEHLER: Pfandfrei! %20s' % prev.item_name()[:20])
|
|
|
|
|
error_page('FEHLER: Produkt "%s" hat kein Pfand' % prev.item_name())
|
|
|
|
|
return
|
|
|
|
|
before = prev.difference()
|
|
|
|
@ -545,14 +392,14 @@ def print_prompt():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle(line, status):
|
|
|
|
|
global idlemessage
|
|
|
|
|
if line == 'exit':
|
|
|
|
|
clear()
|
|
|
|
|
print_display("\x0c")
|
|
|
|
|
myDisplay.write("\x0c")
|
|
|
|
|
myDisplay.terminate()
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
if status.logged_in():
|
|
|
|
|
idlemessage=" Comitten nicht vergessen! ***"
|
|
|
|
|
myDisplay.setIdlemessage(" Comitten nicht vergessen! ***")
|
|
|
|
|
if line in CODES:
|
|
|
|
|
call = CODES[line]
|
|
|
|
|
method = call[0]
|
|
|
|
@ -563,15 +410,15 @@ def handle(line, status):
|
|
|
|
|
item = status.find(line)
|
|
|
|
|
except urllib2.HTTPError as e:
|
|
|
|
|
if e.code == 404: # URL not found == item not found with REST
|
|
|
|
|
print_display('\x0cERROR: %13sCode ist unbekannt' % ( line[:13]))
|
|
|
|
|
myDisplay.display_screen("FEHLER","Code ist unbekannt: '%s'" % ( line[:23]))
|
|
|
|
|
error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line)
|
|
|
|
|
else:
|
|
|
|
|
print_display('\x0cERROR: Server Error%20s' % str(e)[:20])
|
|
|
|
|
myDisplay.display_screen("Server error",'%20s' % str(e)[:20])
|
|
|
|
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
|
|
|
|
else:
|
|
|
|
|
status.buy(item)
|
|
|
|
|
else:
|
|
|
|
|
idlemessage="Mir ist langweilig!"
|
|
|
|
|
myDisplay.setIdlemessage("Mir ist langweilig!")
|
|
|
|
|
try:
|
|
|
|
|
status.login(line)
|
|
|
|
|
except urllib2.HTTPError as e:
|
|
|
|
@ -584,7 +431,7 @@ def handle(line, status):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if item is None:
|
|
|
|
|
display_screen("FEHLER","Nutzer ist unbekannt: '%s' *** " % line)
|
|
|
|
|
myDisplay.display_screen("FEHLER","Nutzer ist unbekannt: '%s' *** " % line)
|
|
|
|
|
|
|
|
|
|
error_page('FEHLER: Produkt oder Nutzer "%s" nicht bekannt' % line,
|
|
|
|
|
hint_message='Ist in der WebApp unter "Einstellungen" ' \
|
|
|
|
@ -592,8 +439,9 @@ def handle(line, status):
|
|
|
|
|
'als erlaubt markiert?')
|
|
|
|
|
else:
|
|
|
|
|
item_info_page(item)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
print_display('\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
|
|
|
|
myDisplay.display_screen("FEHLER",'Server Error %20s' % str(e)[:20])
|
|
|
|
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
|
|
|
|
except urllib2.URLError as e:
|
|
|
|
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
|
|
|
@ -615,21 +463,19 @@ def main():
|
|
|
|
|
global myDisplay
|
|
|
|
|
|
|
|
|
|
myDisplay = Display("/dev/ttyUSB0")
|
|
|
|
|
myDisplay.start()
|
|
|
|
|
myDisplay.cmd_reset()
|
|
|
|
|
myDisplay.cmd_cursor_show(False)
|
|
|
|
|
|
|
|
|
|
print_display("\x1b\x40\x1f\x43\x00")
|
|
|
|
|
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! *** ")
|
|
|
|
|
myDisplay.display_screen("HINWEIS","Herzlich willkommen bei der Freitagsrunde! *** ")
|
|
|
|
|
time.sleep(5)
|
|
|
|
|
while True:
|
|
|
|
|
clear()
|
|
|
|
|
status.dump()
|
|
|
|
|
print_prompt()
|
|
|
|
|
line = read_line(sys.stdin, timeout=3*60.0, timeout_func=status.logout)
|
|
|
|
|
if line:
|
|
|
|
|
print_display('\x0cBarcode:\n%20s' % line[:20])
|
|
|
|
|
myDisplay.write('\x0cBarcode:\n%20s' % line[:20])
|
|
|
|
|
handle(line, status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -637,5 +483,7 @@ if __name__ == '__main__':
|
|
|
|
|
try:
|
|
|
|
|
main()
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
myDisplay.terminate()
|
|
|
|
|
myDisplay.write("\x1b\x40Goodbye!")
|
|
|
|
|
pass
|
|
|
|
|
print_display("\x1b\x40Goodbye!")
|
|
|
|
|
|
|
|
|
|