almost usable. threads are not all temrinating yet
This commit is contained in:
parent
65255fb53a
commit
dd49d650fb
|
@ -8,6 +8,7 @@ class Display(threading.Thread):
|
|||
threading.Thread.__init__(self)
|
||||
self.serialport=None
|
||||
self.runme=True
|
||||
self.idlemessage=None
|
||||
self.portlock = allocate_lock()
|
||||
self.portname=portname
|
||||
self.brightness=5
|
||||
|
@ -32,13 +33,13 @@ class Display(threading.Thread):
|
|||
self.mutex_get()
|
||||
try:
|
||||
self.serialport = serial.Serial(self.portname,9600,timeout=2,rtscts=True, dsrdtr=True)
|
||||
print ("Initializing display on port:\n %s\n" % self.serialport )
|
||||
#print ("Initializing display on port:\n %s\n" % self.serialport )
|
||||
self.cmd_reset()
|
||||
self.mutex_release()
|
||||
except Exception as e:
|
||||
print ("Exception opening serial port '%s' for display\n" % self.portname)
|
||||
print ("Ignoring and trying to open it again later\n")
|
||||
print (e)
|
||||
#print ("Exception opening serial port '%s' for display\n" % self.portname)
|
||||
#print ("Ignoring and trying to open it again later\n")
|
||||
#print (e)
|
||||
self.serialport = None
|
||||
self.mutex_release()
|
||||
pass
|
||||
|
@ -75,17 +76,17 @@ class Display(threading.Thread):
|
|||
|
||||
|
||||
def run(self):
|
||||
print "Starting Display thread"
|
||||
#print "Starting Display thread"
|
||||
self.screensaver.start()
|
||||
while(self.runme):
|
||||
print("display thread loop\n")
|
||||
#print("display thread loop\n")
|
||||
self.mutex_get()
|
||||
print("display got mutex and handles scroll\n")
|
||||
#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"
|
||||
#print "Exiting Display thread"
|
||||
|
||||
def terminate(self):
|
||||
self.runme = False
|
||||
|
@ -137,7 +138,7 @@ class Display(threading.Thread):
|
|||
def cmd_brightness(self,level):
|
||||
if (self.brightness==level):
|
||||
return
|
||||
print("setting brightness to %i \n" %level)
|
||||
#print("setting brightness to %i \n" %level)
|
||||
if (level==0): #turn off:
|
||||
self.cmd_display_on(False)
|
||||
self.brightness = 0
|
||||
|
@ -155,13 +156,13 @@ class Display(threading.Thread):
|
|||
if (on):
|
||||
if (not self.brightness==0):
|
||||
return
|
||||
print("setting display to on: %s \n" % str(on))
|
||||
#print("setting display to on: %s \n" % str(on))
|
||||
self.cmd_blink(0)
|
||||
self.brightness=5
|
||||
else:
|
||||
if (self.brightness==0):
|
||||
return
|
||||
print("setting display to on: %s \n" % str(on))
|
||||
#print("setting display to on: %s \n" % str(on))
|
||||
self.cmd_blink(255)
|
||||
self.brightness=0
|
||||
|
||||
|
@ -209,6 +210,11 @@ class Display(threading.Thread):
|
|||
else:
|
||||
self.open_port()
|
||||
|
||||
def setIdlemessage(self,text):
|
||||
self.idlemessage=text
|
||||
|
||||
def getIdlemessage(self):
|
||||
return self.idlemessage
|
||||
|
||||
def mutex_get(self):
|
||||
self.portlock.acquire()
|
||||
|
@ -256,6 +262,7 @@ class Screensaver (threading.Thread):
|
|||
self.display.cmd_brightness(5)
|
||||
self.mutex.release()
|
||||
|
||||
|
||||
def _main_loop(self):
|
||||
if (self.idlecounter < self.timeout_off):
|
||||
self.idlecounter+=1
|
||||
|
@ -269,6 +276,7 @@ class Screensaver (threading.Thread):
|
|||
if (self.idlecounter==self.timeout_message):
|
||||
self.display.mutex_get()
|
||||
self.display.cmd_time_set()
|
||||
self.display.scroll_line1 = self.display.getIdlemessage()
|
||||
self.display.mutex_release()
|
||||
return
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ display_fifo = None
|
|||
scroll_line1 = None
|
||||
scroll_line2 = None
|
||||
|
||||
idlemessage = None
|
||||
|
||||
offset_line1 = 0
|
||||
offset_line2 = 0
|
||||
|
@ -56,19 +55,6 @@ SCREENSAVER_OFF = 2* 10*60
|
|||
|
||||
lock = allocate_lock()
|
||||
|
||||
def send_display(s):
|
||||
global myDisplay
|
||||
# myDisplay.write(s,False)
|
||||
|
||||
#Front-End Funtion to display a Screen
|
||||
# with heading
|
||||
def display_screen(title,message):
|
||||
myDisplay.display_screen(title,message)
|
||||
|
||||
|
||||
#Front-End function to send data to the display.
|
||||
def print_display(s):
|
||||
myDisplay.write(s,False)
|
||||
|
||||
def clear():
|
||||
os.system('clear')
|
||||
|
@ -165,7 +151,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]
|
||||
|
||||
|
@ -197,11 +183,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='+')
|
||||
|
@ -210,13 +196,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()
|
||||
|
@ -224,7 +210,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):
|
||||
|
@ -253,7 +239,7 @@ class Status:
|
|||
try:
|
||||
command.run(self.login_name)
|
||||
except urllib2.HTTPError as e:
|
||||
print_display('\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
||||
myDisplay.write('\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
||||
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||
break
|
||||
else:
|
||||
|
@ -336,11 +322,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()
|
||||
|
@ -382,14 +368,13 @@ def print_prompt():
|
|||
|
||||
|
||||
def handle(line, status):
|
||||
global idlemessage
|
||||
if line == 'exit':
|
||||
clear()
|
||||
print_display("\x0c")
|
||||
myDisplay.write("\x0c")
|
||||
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]
|
||||
|
@ -400,27 +385,27 @@ 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:
|
||||
if e.code == 404: # URL not found == user unknown
|
||||
display_screen("FEHLER","Nutzer ist unbekannt: '%s' *** " % line)
|
||||
myDisplay.display_screen("FEHLER","Nutzer ist unbekannt: '%s' *** " % line)
|
||||
|
||||
error_page('FEHLER: Benutzer "%s" nicht bekannt' % line,
|
||||
hint_message='Ist in der WebApp unter "Einstellungen" ' \
|
||||
'für Ihren Account Plugin "BarcodePlugin" ' \
|
||||
'als erlaubt markiert?')
|
||||
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))
|
||||
|
@ -447,14 +432,15 @@ def main():
|
|||
time.sleep(2)
|
||||
myDisplay.cmd_cursor_show(False)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
@ -463,6 +449,6 @@ if __name__ == '__main__':
|
|||
main()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
print_display("\x1b\x40Goodbye!")
|
||||
myDisplay.write("\x1b\x40Goodbye!")
|
||||
myDisplay.terminate()
|
||||
|
||||
|
|
Loading…
Reference in New Issue