From af69d2f16fd4aeb461a5e2c3ea6aac3438808b63 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 12 Oct 2011 02:27:06 +0200 Subject: [PATCH 01/51] Timeouts now suitable for real use, old values for testing only --- display-daemon/ser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/display-daemon/ser.c b/display-daemon/ser.c index f9d6725..8d3d6a8 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -77,9 +77,9 @@ char display_time[] = {0x1f,0x55}; #define TIME_BASE 200000 #define TB_TO_SECS(x) (x*1000000/TIME_BASE) -#define TIME_CLOCK TB_TO_SECS(5) -#define TIME_DIM TB_TO_SECS(30) -#define TIME_OFF TB_TO_SECS(120) +#define TIME_CLOCK TB_TO_SECS(25) +#define TIME_DIM TB_TO_SECS(90) +#define TIME_OFF TB_TO_SECS(320) #define DEVICE "/dev/ttyUSB0" From 7bcc8f0c180d5a5b1e329e7d41abc2e17ad5b0ed Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 12 Oct 2011 02:28:35 +0200 Subject: [PATCH 02/51] Added first Code fragments for external display. --- client-barcode/freitagskasse.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 1f4a5c5..1e6fdff 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -30,6 +30,27 @@ COLOR_MUCH = Fore.YELLOW + Style.BRIGHT COLOR_RESET = Style.RESET_ALL +display_fifo = None + + +def print_display(s): + global display_fifo + """ + Comment out this return for now if you dont + want to use the display. + + return + + """ + if not display_fifo: + try: + display_fifo = open('/tmp/display', 'w') + except IOError: + display_fifo = None + return + display_fifo.write(s) + display_fifo.flush() + def clear(): os.system('clear') @@ -71,6 +92,7 @@ def delay(what, seconds): def warn_balance(): print('Kontostand im Minus, bitte Geld aufladen.') + print_display('\e\x0cKontostand im Minus, bitte Geld aufladen.') def error_page(message): @@ -122,6 +144,7 @@ class Status: if self.logged_in(): print('Eingeloggt als: %s%s%s' % (COLOR_SOME, self.login_name, COLOR_RESET)) print() + print_display('\e\x0cBenutzer: %10s' %self.login_name[:10]) if self.transfers: initial_command, initial_balance = self.transfers[0] @@ -142,6 +165,7 @@ class Status: print(COLOR_SOME + 'Committen nicht vergessen.' + COLOR_RESET) else: print('Kontostand beträgt: %s%.2f Euro%s' % (COLOR_MUCH, self.balance, COLOR_RESET)) + print_display('Kontostand: %8.2f' % self.balance) if self.balance < 0: print() warn_balance() @@ -149,6 +173,7 @@ class Status: print(COLOR_MUCH + 'Bitte einloggen.' + COLOR_RESET) print() print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.') + print_display("\e\x0cAnmeldung: Bitte ID-Karte scannen...") print() def logged_in(self): @@ -173,6 +198,7 @@ class Status: try: command.run(self.login_name) except urllib2.HTTPError as e: + print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20]) error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e)) break else: @@ -344,8 +370,10 @@ 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('\e\x0cFEHLER:\nAktion/ware unbekannt') error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line) else: + print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20]) error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e)) else: status.buy(item) @@ -354,8 +382,10 @@ def handle(line, status): status.login(line) except urllib2.HTTPError as e: if e.code == 404: # URL not found == user unknown + print_display('\e\x0cFEHLER: Nutzer ist unbekannt: "%7s"' % line[:7]) error_page('FEHLER: Benutzer "%s" nicht bekannt' % line) else: + print_display('\e\x0cFEHLER: 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)) @@ -365,6 +395,8 @@ def main(): colorama.init() status = Status() + print_display("\x1b\x40Kassensystem \n startet...") + while True: clear() status.dump() @@ -382,3 +414,4 @@ if __name__ == '__main__': main() except KeyboardInterrupt: pass + print_display("\x1b\x40Goodbye!") From 5c15a18110edca305aac96e0193a6374a5b67a8b Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 12 Oct 2011 02:46:36 +0200 Subject: [PATCH 03/51] do not create fifo if not there --- client-barcode/freitagskasse.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 1e6fdff..dec31a4 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -35,16 +35,11 @@ display_fifo = None def print_display(s): global display_fifo - """ - Comment out this return for now if you dont - want to use the display. - - return - - """ if not display_fifo: try: - display_fifo = open('/tmp/display', 'w') + #display_fifo = open('/tmp/display', 'w') + fd = os.open( "/tmp/display", os.O_WRONLY) + display_fifo = os.fdopen(fd,"w") except IOError: display_fifo = None return From 7dc1d5c7ca717ab74ad26cd8ea2e3085f10af586 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 12 Oct 2011 13:16:45 +0200 Subject: [PATCH 04/51] various comments added. --- display-daemon/ser.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/display-daemon/ser.c b/display-daemon/ser.c index 8d3d6a8..d640eeb 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -42,30 +42,50 @@ initport (int fd) return 1; } - +//reset the display to defaults char display_init[] = { 0x1b, 0x40 }; -char display_showtime[] = { 0x1F, 0x54 }; + +//show or hide the cursor char display_cursor_off[] = { 0x1f, 0x43, 0x0 }; char display_cursor_on[] = { 0x1f, 0x43, 0x1 }; +// blink-command: +// where the last value defines the blink rate, +// with 0=always on, 255=always off char display_on[] = { 0x1f, 0x45, 0x0 }; char display_off[] = { 0x1f, 0x45, 0xff }; +//Modes for new chars: char display_overwrite[] = { 0x1f, 0x01 }; char display_vscroll[] = { 0x1f, 0x02 }; char display_hscroll[] = { 0x1f, 0x03 }; +//clear and cursor home char display_clear_screen[] = { 0x0c }; +// activate timer display in lower right corner. +// actual time has to be set via display_set_timer. char display_time[] = {0x1f,0x55}; +// configures hour and minutes of the internal clock and +// displays the time in the lower right corner. +// turns off when something gets written into the line. +// two bytes have to follow with hour and minute +char display_set_timer[] = { 0x1F, 0x54 }; + +// various commands for the display: +// send a command sequence from the heap(!) {sizeof used} +// only to be used within the macros presented below! #define DWC(c) display_write(c,sizeof(c)) + +//send a null terminated string: #define SEND_TEXT(t) display_write(t,strlen(t)) +//various commands #define SEND_DISPLAY_INIT DWC(display_init) #define SEND_CURSOR_OFF DWC(display_cursor_off) #define SEND_CURSOR_ON DWC(display_cursor_on) -#define SEND_DEFINE_TIMER DWC(display_showtime) +#define SEND_DEFINE_TIMER DWC(display_set_timer) #define SEND_SHOW_TIMER DWC(display_time) #define SEND_MODE_OVERWRITE DWC(display_overwrite) #define SEND_MODE_VSCROLL DWC(display_vscroll) @@ -74,6 +94,7 @@ char display_time[] = {0x1f,0x55}; #define SEND_DISPLAY_ON DWC(display_on) #define SEND_CLEAR DWC(display_clear_screen); +// internal defines. #define TIME_BASE 200000 #define TB_TO_SECS(x) (x*1000000/TIME_BASE) @@ -83,8 +104,9 @@ char display_time[] = {0x1f,0x55}; #define DEVICE "/dev/ttyUSB0" -#define PAUSEMSG "Hallo, bitte melde Dich am Barcodereader an, um das Kassensystem zu benutzen *** Angebot: Die Mate heute nur 0.75 *** " - +#define PAUSEMSG "Hallo, bitte melde Dich am Barcodereader an, um das Kassensystem zu benutzen *** " + +// chars per line in our display: #define LINELEN 20 void From b36df0167d968e4dcfa4e9ee3d6f181ab1d9f048 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 12 Oct 2011 13:18:28 +0200 Subject: [PATCH 05/51] Now licensed under GPL... --- display-daemon/ser.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/display-daemon/ser.c b/display-daemon/ser.c index d640eeb..1e60400 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2011 Florian Streibelt + * Licensed under GPL v3 or later + * + */ + #include /* Standard input/output definitions */ #include /* String function definitions */ #include /* UNIX standard function definitions */ From ffe61d7e7cfc32d766c91bd876150767e4d12918 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 12 Oct 2011 19:53:05 +0200 Subject: [PATCH 06/51] stuff... --- client-barcode/freitagskasse.py | 2 +- display-daemon/ser.c | 70 +++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index dec31a4..15f033f 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -87,7 +87,7 @@ def delay(what, seconds): def warn_balance(): print('Kontostand im Minus, bitte Geld aufladen.') - print_display('\e\x0cKontostand im Minus, bitte Geld aufladen.') + print_display('\e\x0cKontostand im Minus,bitte Geld aufladen.') def error_page(message): diff --git a/display-daemon/ser.c b/display-daemon/ser.c index 1e60400..9757d1a 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -71,7 +71,8 @@ char display_clear_screen[] = { 0x0c }; // activate timer display in lower right corner. // actual time has to be set via display_set_timer. -char display_time[] = {0x1f,0x55}; +char display_time[] = { 0x1f, 0x55 }; + // configures hour and minutes of the internal clock and // displays the time in the lower right corner. // turns off when something gets written into the line. @@ -129,7 +130,7 @@ void display_putstring (char *s) { screensaver = 0; - SEND_TEXT(s); + SEND_TEXT (s); } @@ -175,7 +176,7 @@ display_dim (short i) SEND_CURSOR_OFF; // turn display on again SEND_DISPLAY_ON; - SEND_MODE_OVERWRITE; + SEND_MODE_OVERWRITE; char c[4] = { 0x1f, 0x58, 0x04, 0x00 }; l = 6; //c[5]=i; @@ -243,7 +244,10 @@ sighandler (int sig) SEND_DISPLAY_OFF; close (fd); - if (fifo) {unlink(fifo);} + if (fifo) + { + unlink (fifo); + } exit (0); //signal(sig, sighandler); } @@ -252,18 +256,20 @@ sighandler (int sig) int main (int argc, char **argv) { - char *devnode ; + char *devnode; //TODO: arg parser! - fifo=strdup("/tmp/display"); + fifo = strdup ("/tmp/display"); if (argc != 2) { - devnode=strdup(DEVICE); - printf ("no device specified, using default %s\n",devnode); - }else{ - devnode=strdup(argv[1]); - } + devnode = strdup (DEVICE); + printf ("no device specified, using default %s\n", devnode); + } + else + { + devnode = strdup (argv[1]); + } fd = open (devnode, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { @@ -304,13 +310,20 @@ main (int argc, char **argv) while (1) { - usleep(TIME_BASE); - //printf ("screensaver = %05d brightness: %d\n", screensaver, brightness); - if (screensaver < 10000) + usleep (TIME_BASE); + + if (0 == (screensaver) % TB_TO_SECS (1)) { - screensaver++; + //one-second event comes HERE: + printf + ("debug: screensaver: %d time until clock: %d time until dim: %d time until off: %d\n", + screensaver, TIME_CLOCK - screensaver, TIME_DIM - screensaver, + TIME_OFF - screensaver); } + //printf ("screensaver = %05d brightness: %d\n", screensaver, brightness); + screensaver = (screensaver + 1) % TIME_CLOCK + TIME_OFF + TIME_DIM; + if (screensaver == TIME_CLOCK) { showtime (); @@ -322,17 +335,22 @@ main (int argc, char **argv) //show a scroll text while the screensaver is active... - if ((screensaver > (TIME_CLOCK+10)) && (screensaver < TIME_OFF)){ - char *message = calloc(LINELEN+1,sizeof(char)); - strncpy(message,PAUSEMSG+((screensaver-TIME_CLOCK-1)%strlen(PAUSEMSG)),LINELEN); - int l = strlen(message); - if (l (TIME_CLOCK + 10)) && (screensaver < TIME_OFF)) + { + char *message = calloc (LINELEN + 1, sizeof (char)); + strncpy (message, + PAUSEMSG + + ((screensaver - TIME_CLOCK - 1) % strlen (PAUSEMSG)), + LINELEN); + int l = strlen (message); + if (l < LINELEN) + { + message = strncat (message, PAUSEMSG, LINELEN - l); + } + SEND_TEXT ("\x0b"); + SEND_TEXT (message); + free (message); + } //after some more seconds of inactivity dim display and finally turn off if ((screensaver > TIME_DIM) && (brightness > 1)) From f9550712d8bae9c76eddde81e10e4f5f6d1782fa Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 12 Oct 2011 20:45:28 +0200 Subject: [PATCH 07/51] not all screens yet on the display. scroll text would be nice... --- client-barcode/freitagskasse.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 7d61d4b..b0554fe 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -92,7 +92,6 @@ def delay(what, seconds): def warn_balance(): print('Kontostand im Minus, bitte Geld aufladen.') - print_display('\e\x0cKontostand im Minus,bitte Geld aufladen.') def error_page(error_message, hint_message=None): @@ -141,7 +140,7 @@ class Status: if self.logged_in(): print('Eingeloggt als: %s%s%s' % (COLOR_SOME, self.login_name, COLOR_RESET)) print() - print_display('\e\x0cBenutzer: %10s' %self.login_name[:10]) + print_display('\x0cHallo %-14s' % (self.login_name[:13]+"!") ) if self.transfers: initial_command, initial_balance = self.transfers[0] @@ -160,6 +159,11 @@ class Status: show_item(i, command.difference(), command.label(), COLOR_DEPOSIT) i += 1 show_bar() + + if isinstance(command, BuyCommand): + print_display('\x0b%-15s %4.2f' % (command.commodity_label()[:15],abs(command.difference()))); + print_display('\x0b\nSUMME: %2i %10.2f' % (i-1,initial_balance - self.balance)); + if len(self.transfers) > 1: show_total(self.balance - initial_balance, plus='+') show_bar() @@ -167,6 +171,7 @@ class Status: if self.balance < 0: warn_balance() + print_display('\x0b\nKonto: %5.2f!' % (self.balance) ) print() print(COLOR_SOME + 'Committen nicht vergessen.' + COLOR_RESET) @@ -346,10 +351,10 @@ 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('\e\x0cFEHLER:\nAktion/ware unbekannt') + print_display('\x0cERROR:\nCode ist unbekannt!') error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line) else: - print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20]) + print_display('\x0cERROR: Server Error%20s' % str(e)[:20]) error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e)) else: status.buy(item) From e36d00c393c50ea59eba590c9cbd24c2224be5b7 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Thu, 13 Oct 2011 19:19:17 +0200 Subject: [PATCH 08/51] Bugs removed that prevented the screen from turning on again.: --- display-daemon/Makefile | 2 ++ display-daemon/ser.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/display-daemon/Makefile b/display-daemon/Makefile index d242e59..ceff071 100644 --- a/display-daemon/Makefile +++ b/display-daemon/Makefile @@ -2,3 +2,5 @@ CFLAGS=-g -Wall ser: ser.c gcc -ggdb -Wall ser.c -o ser -lpthread #mipsel-linux-uclibc-gcc -o ser.mips ser.c -lpthread +run: ser + ./ser diff --git a/display-daemon/ser.c b/display-daemon/ser.c index 9757d1a..7d3d911 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -217,6 +217,7 @@ rthread (void *args) { screensaver = 0; + display_dim (4); if (pc == '\n') { @@ -227,7 +228,6 @@ rthread (void *args) display_write (&c, 1); } pc = c; - display_dim (4); } close (pipe); } @@ -322,7 +322,10 @@ main (int argc, char **argv) } //printf ("screensaver = %05d brightness: %d\n", screensaver, brightness); - screensaver = (screensaver + 1) % TIME_CLOCK + TIME_OFF + TIME_DIM; + if (screensaver < (TIME_CLOCK + TIME_OFF + TIME_DIM + 10)){ + screensaver++; + } + //screensaver = (screensaver + 1) % (TIME_CLOCK + TIME_OFF + TIME_DIM + 10); if (screensaver == TIME_CLOCK) { From ad5eff49bea8e38dd78476d58dfbbd034487b7b0 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Thu, 13 Oct 2011 22:22:04 +0200 Subject: [PATCH 09/51] Scrolling text now in function and with a 'slide in' from right --- display-daemon/ser.c | 56 ++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/display-daemon/ser.c b/display-daemon/ser.c index 7d3d911..f609d21 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -22,7 +22,10 @@ int fd; int screensaver; int brightness = 4; +int offset = 0; char *fifo; +char *pausemsg = NULL; + pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; pthread_t thread1; @@ -105,17 +108,17 @@ char display_set_timer[] = { 0x1F, 0x54 }; #define TIME_BASE 200000 #define TB_TO_SECS(x) (x*1000000/TIME_BASE) -#define TIME_CLOCK TB_TO_SECS(25) +#define TIME_CLOCK TB_TO_SECS(5) #define TIME_DIM TB_TO_SECS(90) #define TIME_OFF TB_TO_SECS(320) #define DEVICE "/dev/ttyUSB0" -#define PAUSEMSG "Hallo, bitte melde Dich am Barcodereader an, um das Kassensystem zu benutzen *** " // chars per line in our display: #define LINELEN 20 + void display_write (const void *buf, size_t count) { @@ -252,6 +255,36 @@ sighandler (int sig) //signal(sig, sighandler); } +void scrolltext(){ + + if (pausemsg){ + char *message = calloc (LINELEN + 1, sizeof (char)); + + int spaces=0; + + if (offset (TIME_CLOCK + 10)) && (screensaver < TIME_OFF)) { - char *message = calloc (LINELEN + 1, sizeof (char)); - strncpy (message, - PAUSEMSG + - ((screensaver - TIME_CLOCK - 1) % strlen (PAUSEMSG)), - LINELEN); - int l = strlen (message); - if (l < LINELEN) - { - message = strncat (message, PAUSEMSG, LINELEN - l); - } - SEND_TEXT ("\x0b"); - SEND_TEXT (message); - free (message); + scrolltext(); } //after some more seconds of inactivity dim display and finally turn off From 2a1ad9f1224733f1d26910405fc320f7e88229da Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Thu, 13 Oct 2011 22:23:36 +0200 Subject: [PATCH 10/51] fixed some escape codes and added some output screens --- client-barcode/freitagskasse.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index b0554fe..701da0f 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -162,7 +162,10 @@ class Status: if isinstance(command, BuyCommand): print_display('\x0b%-15s %4.2f' % (command.commodity_label()[:15],abs(command.difference()))); - print_display('\x0b\nSUMME: %2i %10.2f' % (i-1,initial_balance - self.balance)); + print_display('\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)); if len(self.transfers) > 1: show_total(self.balance - initial_balance, plus='+') @@ -293,9 +296,11 @@ class Status: error_page(_PRODUCT_FIRST) return if prev.includes_deposit(): + print_display('\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]) error_page('FEHLER: Produkt "%s" hat kein Pfand' % prev.item_name()) return before = prev.difference() @@ -351,7 +356,7 @@ 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:\nCode ist unbekannt!') + print_display('\x0cERROR: %13sCode ist unbekannt' % ( line[:13])) error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line) else: print_display('\x0cERROR: Server Error%20s' % str(e)[:20]) @@ -363,13 +368,13 @@ def handle(line, status): status.login(line) except urllib2.HTTPError as e: if e.code == 404: # URL not found == user unknown - print_display('\e\x0cFEHLER: Nutzer ist unbekannt: "%7s"' % line[:7]) + print_display('\x0cFEHLER: Nutzer ist unbekannt: "%7s"' % line[:7]) 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('\e\x0cFEHLER: Server Error%20s' % str(e)[:20]) + print_display('\x0cFEHLER: 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)) @@ -389,6 +394,7 @@ def main(): if not l: break line = l.rstrip() + print_display('\x0cBarcode:\n%20s' % line[:20]) if line: handle(line, status) From f880ec04ea2caa4b0707af2b767f099318aae673 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Thu, 13 Oct 2011 23:21:09 +0200 Subject: [PATCH 11/51] now with goodbye message --- client-barcode/freitagskasse.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 701da0f..1062f2e 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -223,6 +223,7 @@ class Status: # Show final balance for some time clear() self.dump() + print_display('\x0bDanke,%-14s' % (self.login_name[:13]+"!") ) delay('Logout', 3) # Logout From f0fa719d9f4da20f816aae43ce9b2afea815162c Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Thu, 13 Oct 2011 23:58:47 +0200 Subject: [PATCH 12/51] now displays deposit corectly --- client-barcode/freitagskasse.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 1062f2e..d7774eb 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -161,7 +161,18 @@ class Status: show_bar() if isinstance(command, BuyCommand): - print_display('\x0b%-15s %4.2f' % (command.commodity_label()[:15],abs(command.difference()))); + muff = 0; + if (command.includes_commodity()): + muff+=1; + if (command.includes_deposit()): + muff+=2; + if (muff==1): + mylabel=command.item_name() + if (muff==2): + mylabel="Pfand "+command.commodity_label()[:9] + if (muff==3): + mylabel=("%-13s" % (command.commodity_label()[:13]))+"+P" + print_display('\x0b%-15s %4.2f' % (mylabel[:15],abs(command.difference()))); print_display('\x0b\nSUMME: {%02i} %8.2f' % ((i-1),initial_balance - self.balance)); else: print_display('\x0b%-15s %4.2f' % (command.label()[:15],abs(command.difference()))); From b83d15a461ef7cf0dc465735487d43aa92b1402c Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Fri, 14 Oct 2011 01:48:28 +0200 Subject: [PATCH 13/51] finally{} --- client-barcode/freitagskasse.py | 2 +- display-daemon/ser.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index d7774eb..79f4d3c 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -234,7 +234,7 @@ class Status: # Show final balance for some time clear() self.dump() - print_display('\x0bDanke,%-14s' % (self.login_name[:13]+"!") ) + print_display('\x0bDanke, %-12s' % (self.login_name[:12]+"!") ) delay('Logout', 3) # Logout diff --git a/display-daemon/ser.c b/display-daemon/ser.c index f609d21..d5704a3 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -20,6 +20,7 @@ int fd; +int display_dirty=0; int screensaver; int brightness = 4; int offset = 0; @@ -108,9 +109,9 @@ char display_set_timer[] = { 0x1F, 0x54 }; #define TIME_BASE 200000 #define TB_TO_SECS(x) (x*1000000/TIME_BASE) -#define TIME_CLOCK TB_TO_SECS(5) +#define TIME_CLOCK TB_TO_SECS(65) #define TIME_DIM TB_TO_SECS(90) -#define TIME_OFF TB_TO_SECS(320) +#define TIME_OFF TB_TO_SECS(520) #define DEVICE "/dev/ttyUSB0" @@ -220,6 +221,11 @@ rthread (void *args) { screensaver = 0; + if (display_dirty) { + printf("DEBUG: resetting display\n"); + SEND_DISPLAY_INIT; + display_dirty=0; + } display_dim (4); if (pc == '\n') @@ -363,10 +369,12 @@ main (int argc, char **argv) if (screensaver == TIME_CLOCK) { + display_dirty=1; showtime (); } if (screensaver == TIME_OFF) { + display_dirty=1; display_dim (0); } @@ -374,6 +382,7 @@ main (int argc, char **argv) //show a scroll text while the screensaver is active... if ((screensaver > (TIME_CLOCK + 10)) && (screensaver < TIME_OFF)) { + display_dirty=1; scrolltext(); } From d6e277fac4e49eba181a92018ee8612a26c481b6 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Fri, 14 Oct 2011 20:46:25 +0200 Subject: [PATCH 14/51] cursor off/full display init after resume --- display-daemon/ser.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/display-daemon/ser.c b/display-daemon/ser.c index d5704a3..287f4e4 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -160,6 +160,14 @@ showtime (void) display_write (msg, strlen (msg)); } +void +send_display_init(){ + SEND_DISPLAY_INIT; + SEND_CURSOR_OFF; + SEND_DISPLAY_ON; + SEND_MODE_OVERWRITE; +} + void display_dim (short i) { @@ -177,10 +185,7 @@ display_dim (short i) char *d; if (brightness == 0) { - SEND_CURSOR_OFF; - // turn display on again - SEND_DISPLAY_ON; - SEND_MODE_OVERWRITE; + send_display_init(); char c[4] = { 0x1f, 0x58, 0x04, 0x00 }; l = 6; //c[5]=i; @@ -223,7 +228,7 @@ rthread (void *args) screensaver = 0; if (display_dirty) { printf("DEBUG: resetting display\n"); - SEND_DISPLAY_INIT; + send_display_init(); display_dirty=0; } display_dim (4); @@ -246,10 +251,7 @@ void sighandler (int sig) { pthread_kill (thread1, 0); - - SEND_DISPLAY_INIT; - SEND_MODE_OVERWRITE; - SEND_CURSOR_OFF; + send_display_init(); SEND_DISPLAY_OFF; close (fd); @@ -324,9 +326,7 @@ main (int argc, char **argv) initport (fd); //init display, set, vertical scroll, cursor off - SEND_DISPLAY_INIT; - SEND_MODE_OVERWRITE; - SEND_CURSOR_OFF; + send_display_init(); pthread_create (&thread1, NULL, rthread, NULL); signal (SIGINT, sighandler); From 5124cf1d23036f9e3aadb9810c06dea270c7c7c7 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 02:10:19 +0200 Subject: [PATCH 15/51] wrong escape sequence --- client-barcode/freitagskasse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 79f4d3c..2b0fe8f 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -199,7 +199,7 @@ class Status: print(COLOR_MUCH + 'Bitte einloggen.' + COLOR_RESET) print() print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.') - print_display("\e\x0cAnmeldung: Bitte ID-Karte scannen...") + print_display("\x0cAnmeldung: Bitte ID-Karte scannen\x0b") print() def logged_in(self): @@ -224,7 +224,7 @@ class Status: try: command.run(self.login_name) except urllib2.HTTPError as e: - print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20]) + print_display('\x0cFEHLER: Server Error%20s' % str(e)[:20]) error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e)) break else: From 15493ee6aa14a9b8b7199819d010e297909e7081 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 02:21:32 +0200 Subject: [PATCH 16/51] now now exit if display daemin dies --- client-barcode/freitagskasse.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 2b0fe8f..bb38451 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -37,7 +37,6 @@ def print_display(s): global display_fifo if not display_fifo: try: - #display_fifo = open('/tmp/display', 'w') fd = os.open( "/tmp/display", os.O_WRONLY) display_fifo = os.fdopen(fd,"w") except OSError: @@ -48,8 +47,13 @@ def print_display(s): display_fifo = None pass return - display_fifo.write(s) - display_fifo.flush() + try: + display_fifo.write(s) + display_fifo.flush() + except IOError: + display_fifo = None + pass + return def clear(): From 665ba7cc5eb6c0a7b59cfdc0ce2c38e1155236dd Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 03:49:13 +0200 Subject: [PATCH 17/51] Display now has scrolling text implemented in a python thread and error-screens, etc --- client-barcode/freitagskasse.py | 71 ++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index bb38451..31089e3 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -18,6 +18,9 @@ import os import time import urllib2 +from thread import start_new_thread, allocate_lock +import time + COLOR_HINT = Fore.YELLOW + Style.BRIGHT COLOR_ERROR = Fore.RED @@ -32,8 +35,62 @@ COLOR_RESET = Style.RESET_ALL display_fifo = None +scroll_line1 = None +scroll_line2 = None -def print_display(s): + +lock = allocate_lock() + +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) + else: + offset=0 #reset offset + return offset + +def display_scroll_text(line,text): + global scroll_line1,scroll_line2 + lock.acquire() + if (line==1): #clear the line on invocation: + send_display("\x1f\x24\x01%c\x18" % chr(line) ) + scroll_line1 = text + if (line==2): #clear the line on invocation: + send_display("\x1f\x24\x01%c\x18" % chr(line) ) + scroll_line2 = text + lock.release() + +def display_screen(title,message): + if (len(title)<21): + 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) + + + +def display_thread(x): + global scroll_line1,scroll_line2 + 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) + lock.release() + time.sleep(.5) + + +def send_display(s): global display_fifo if not display_fifo: try: @@ -55,6 +112,12 @@ def print_display(s): pass return +def print_display(s): + lock.acquire() +# scroll_line1=None +# scroll_line2=None +# send_display(s) + lock.release() def clear(): os.system('clear') @@ -399,9 +462,13 @@ def handle(line, status): def main(): colorama.init() status = Status() - + global scroll_line1,scroll_line2 print_display("\x1b\x40Kassensystem \n startet...") + 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! *** ") while True: clear() status.dump() From 5684b460019bc59b47f8c30ceb7cccf368592a57 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 04:15:50 +0200 Subject: [PATCH 18/51] Moar functions for the display --- client-barcode/freitagskasse.py | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 31089e3..3c97246 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -55,6 +55,9 @@ def display_handle_scroll(line,text,offset): def display_scroll_text(line,text): global scroll_line1,scroll_line2 + global offset_line1,offset_line2 + offset_line1=0 + offset_line2=0 lock.acquire() if (line==1): #clear the line on invocation: send_display("\x1f\x24\x01%c\x18" % chr(line) ) @@ -65,7 +68,12 @@ def display_scroll_text(line,text): lock.release() def display_screen(title,message): + global scroll_line1,scroll_line2 + global offset_line1,offset_line2 + offset_line1=0 + offset_line2=0 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 @@ -74,12 +82,18 @@ def display_screen(title,message): send_display("\x1f\x24%c%c%s" % (chr(pos),chr(1),title) ) else: display_scroll_text(1,title) - display_scroll_text(2,message) + + 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) def display_thread(x): global scroll_line1,scroll_line2 + global offset_line1,offset_line2 offset_line1=0 offset_line2=0 while(True): @@ -113,10 +127,14 @@ def send_display(s): return def print_display(s): + global scroll_line1,scroll_line2 + global offset_line1,offset_line2 lock.acquire() -# scroll_line1=None -# scroll_line2=None -# send_display(s) + offset_line1=0 + offset_line2=0 + scroll_line1=None + scroll_line2=None + send_display(s) lock.release() def clear(): @@ -258,7 +276,7 @@ class Status: print(COLOR_SOME + 'Committen nicht vergessen.' + COLOR_RESET) else: print('Kontostand beträgt: %s%.2f Euro%s' % (COLOR_MUCH, self.balance, COLOR_RESET)) - print_display('Kontostand: %8.2f' % self.balance) + display_screen("KONTOSTAND","%s: %.2f Euro" % (self.login_name,self.balance)) if self.balance < 0: print() warn_balance() @@ -266,7 +284,7 @@ class Status: print(COLOR_MUCH + 'Bitte einloggen.' + COLOR_RESET) print() print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.') - print_display("\x0cAnmeldung: Bitte ID-Karte scannen\x0b") + display_screen("LOGIN","Bitte scanne Deinen login-Token! *** ") print() def logged_in(self): @@ -422,6 +440,7 @@ def print_prompt(): def handle(line, status): if line == 'exit': clear() + print_display("\x1b\x40exit...") sys.exit(0) if status.logged_in(): @@ -447,7 +466,8 @@ def handle(line, status): status.login(line) except urllib2.HTTPError as e: if e.code == 404: # URL not found == user unknown - print_display('\x0cFEHLER: Nutzer ist unbekannt: "%7s"' % line[:7]) + 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" ' \ From f5f55eff847e7724ccd91ae1c8adce812444d76e Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 04:19:49 +0200 Subject: [PATCH 19/51] reordering of functions --- client-barcode/freitagskasse.py | 77 ++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 3c97246..a8ec903 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -41,55 +41,33 @@ scroll_line2 = None lock = allocate_lock() -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) - else: - offset=0 #reset offset - return offset - +#Helper-Function, scrolls text in a specific line. def display_scroll_text(line,text): global scroll_line1,scroll_line2 global offset_line1,offset_line2 - offset_line1=0 - offset_line2=0 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_screen(title,message): - global scroll_line1,scroll_line2 - global offset_line1,offset_line2 - offset_line1=0 - offset_line2=0 - 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) - - 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) +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) + else: + offset=0 #reset offset + return offset def display_thread(x): global scroll_line1,scroll_line2 @@ -126,6 +104,33 @@ def send_display(s): 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 + offset_line1=0 + offset_line2=0 + 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) + + 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) + + +#Front-End function to send data to the display. def print_display(s): global scroll_line1,scroll_line2 global offset_line1,offset_line2 From 18f1de1b26371edbae4b3250836df413c0817aba Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 05:38:14 +0200 Subject: [PATCH 20/51] screensaver now implemented in python (too) including idle message per state. --- client-barcode/freitagskasse.py | 91 ++++++++++++++++++++++++++++----- display-daemon/ser.c | 2 +- 2 files changed, 80 insertions(+), 13 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index a8ec903..f1f1daa 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -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): 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): 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): 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: self.transfers = None def dump(self): + def sign(amount, plus='+'): return '-' if amount < 0 else plus @@ -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): else: status.buy(item) else: + idlemessage="Mir ist langweilig!" try: status.login(line) except urllib2.HTTPError as e: @@ -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!") diff --git a/display-daemon/ser.c b/display-daemon/ser.c index 287f4e4..d01ab45 100644 --- a/display-daemon/ser.c +++ b/display-daemon/ser.c @@ -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) { From bc234a691c7b3e0df61b3e2c5ca8043df72afc44 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 05:41:05 +0200 Subject: [PATCH 21/51] renamed to a more sane name --- client-barcode/freitagskasse.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index f1f1daa..821a9ef 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -315,16 +315,16 @@ class Status: show_bar() if isinstance(command, BuyCommand): - muff = 0; + mycmd = 0; if (command.includes_commodity()): - muff+=1; + mycmd+=1; if (command.includes_deposit()): - muff+=2; - if (muff==1): + mycmd+=2; + if (mycmd==1): mylabel=command.item_name() - if (muff==2): + if (mycmd==2): mylabel="Pfand "+command.commodity_label()[:9] - if (muff==3): + if (mycmd==3): mylabel=("%-13s" % (command.commodity_label()[:13]))+"+P" print_display('\x0b%-15s %4.2f' % (mylabel[:15],abs(command.difference()))); print_display('\x0b\nSUMME: {%02i} %8.2f' % ((i-1),initial_balance - self.balance)); From 1818360fc5e85f840d0d5992fba35d8e4009de77 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 05:58:48 +0200 Subject: [PATCH 22/51] some screens net to get fixed. --- client-barcode/freitagskasse.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 821a9ef..3de95ad 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -388,7 +388,6 @@ class Status: # Show final balance for some time clear() self.dump() - print_display('\x0bDanke, %-12s' % (self.login_name[:12]+"!") ) delay('Logout', 3) # Logout From afa510e0905ce7689c8aed9a4eda7f9ca35256c1 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 15 Oct 2011 06:11:15 +0200 Subject: [PATCH 23/51] better timeouts and the real url --- client-barcode/freitagskasse.py | 6 +++--- client-barcode/freitagslib/network.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 3de95ad..7b505c6 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -46,9 +46,9 @@ offset_line2 = 0 brightness = 5 screensaver = 0 -SCREENSAVER_DIM = 30 -SCREENSAVER_TIMEOUT = 90 -SCREENSAVER_OFF = 300 +SCREENSAVER_DIM = 2* 20 +SCREENSAVER_TIMEOUT = 2* 120 +SCREENSAVER_OFF = 2* 10*60 lock = allocate_lock() diff --git a/client-barcode/freitagslib/network.py b/client-barcode/freitagslib/network.py index 5b75030..778d092 100644 --- a/client-barcode/freitagslib/network.py +++ b/client-barcode/freitagslib/network.py @@ -24,6 +24,7 @@ DEPOSIT_BANK = 2 _BASE_URL = 'http://devcat.someserver.de:13805/api2/' +_BASE_URL = 'https://k4ever.freitagsrunde.org:443/api2/' _auth = base64.encodestring('%s:%s' % (os.environ['BARCODE_PLUGIN_USER'], os.environ['BARCODE_PLUGIN_PASS'])).rstrip() _headers = {'Authorization':'Basic %s' % _auth} From dd27a1e5ab40e5e9fbcdb2e4f38f5e12b68dfa41 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 17 Oct 2011 19:59:16 +0200 Subject: [PATCH 24/51] client-barcode: Handle long labels better --- client-barcode/freitagskasse.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index ae4886e..a9b8964 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -108,9 +108,15 @@ class Status: % ('', '', color(balance), sign(balance, plus), abs(balance), COLOR_RESET)) + def shorten(text, length): + if len(text) <= length: + return text + else: + return text[:length - 3] + '...' + def show_item(position, diff, label, color): print('%2d) %-40s %s%c %6.2f Euro%s' \ - % (position, label, color, sign(diff), + % (position, shorten(label, 40), color, sign(diff), abs(diff), COLOR_RESET)) def show_bar(): From bb468f25bf1fe16c26a113270143c6b2787fc5f5 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 17 Oct 2011 21:23:17 +0200 Subject: [PATCH 25/51] =?UTF-8?q?Hopefully=20fix=20crash=20on=20sending=20?= =?UTF-8?q?"Sch=C3=B6fferhofer"=20to=20LCD=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client-barcode/freitagskasse.py | 3 ++- client-barcode/freitagslib/encoding.py | 35 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 client-barcode/freitagslib/encoding.py diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 3d25160..4c3b604 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -7,6 +7,7 @@ from __future__ import print_function import freitagslib.network as net from freitagslib.commands import BuyCommand, DepositCommand +from freitagslib.encoding import asciify import colorama from colorama import Fore, Style @@ -332,7 +333,7 @@ class Status: mylabel="Pfand "+command.commodity_label()[:9] if (mycmd==3): mylabel=("%-13s" % (command.commodity_label()[:13]))+"+P" - print_display('\x0b%-15s %4.2f' % (mylabel[:15],abs(command.difference()))); + 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)); else: print_display('\x0b%-15s %4.2f' % (command.label()[:15],abs(command.difference()))); diff --git a/client-barcode/freitagslib/encoding.py b/client-barcode/freitagslib/encoding.py new file mode 100644 index 0000000..0c254ab --- /dev/null +++ b/client-barcode/freitagslib/encoding.py @@ -0,0 +1,35 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2011 Sebastian Pipping +# Licensed under GPL v3 or later + +from __future__ import print_function + +def asciify(utf8): + _mapping = ( + ('ö', 'oe'), + ('Ö', 'Oe'), + ('ä', 'ae'), + ('Ä', 'Ae'), + ('ü', 'ue'), + ('Ü', 'Ue'), + ('ß', 'ss'), + ) + _mapping = dict(((ord(unicode(key, 'utf-8')), value) for key, value in _mapping)) + + def subst(unichar): + def fix(unichar): + if ord(unichar) > 127: + return unicode('?') + return unichar + + return _mapping.get(ord(unichar), fix(unichar)) + + unichars = utf8.decode('utf-8') + unitext = ''.join(subst(e) for e in unichars) + return unitext.encode('ascii') + + +if __name__ == '__main__': + print(asciify('Schöfferhofer')) From bb880e494b7f64349fcf3e956cd80d215d1b4e06 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 17 Oct 2011 21:46:31 +0200 Subject: [PATCH 26/51] Allow asciify to deal with instances of unicode --- client-barcode/freitagslib/encoding.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client-barcode/freitagslib/encoding.py b/client-barcode/freitagslib/encoding.py index 0c254ab..00ee211 100644 --- a/client-barcode/freitagslib/encoding.py +++ b/client-barcode/freitagslib/encoding.py @@ -6,7 +6,14 @@ from __future__ import print_function -def asciify(utf8): +def ensure_unicode(candidate, encoding='utf-8'): + if isinstance(candidate, basestring) \ + and not isinstance(candidate, unicode): + return unicode(candidate, encoding) + return candidate + + +def asciify(text): _mapping = ( ('ö', 'oe'), ('Ö', 'Oe'), @@ -26,7 +33,7 @@ def asciify(utf8): return _mapping.get(ord(unichar), fix(unichar)) - unichars = utf8.decode('utf-8') + unichars = ensure_unicode(text, 'utf-8') unitext = ''.join(subst(e) for e in unichars) return unitext.encode('ascii') From 0a86d9391cedc2789346d393801ae56809e75da2 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 17 Oct 2011 22:44:31 +0200 Subject: [PATCH 27/51] client-barcode: Extra method Status.logout() --- client-barcode/freitagskasse.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 4c3b604..40c38bf 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -377,6 +377,10 @@ class Status: self.balance = balance self.transfers = list() + def logout(self): + # Must not fail if not logged in + self._reset() + def commit(self): assert(self.logged_in()) @@ -397,8 +401,8 @@ class Status: self.dump() delay('Logout', 3) - # Logout - self._reset() + self.logout() + def find(self, barcode): try: From c532fdb55166a4bae8abd37b55cb50d53bfcaf31 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 17 Oct 2011 23:16:57 +0200 Subject: [PATCH 28/51] client-barcode: No longer print empty barcode on LCD display --- client-barcode/freitagskasse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 40c38bf..3f67de2 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -579,8 +579,8 @@ def main(): if not l: break line = l.rstrip() - print_display('\x0cBarcode:\n%20s' % line[:20]) if line: + print_display('\x0cBarcode:\n%20s' % line[:20]) handle(line, status) From d3b0a8fa4c4fc095531e58a3e74f8a9ddf9889e1 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 17 Oct 2011 23:19:21 +0200 Subject: [PATCH 29/51] client-barcode: Turn stdin reading to nonblocking, add autologout after 3 Minutes --- client-barcode/freitagskasse.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 3f67de2..eff1bb5 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -18,6 +18,7 @@ from decimal import Decimal import os import time import urllib2 +import select from thread import start_new_thread, allocate_lock import time @@ -514,6 +515,7 @@ class Status: def print_prompt(): sys.stdout.write(">>> ") + sys.stdout.flush() def handle(line, status): @@ -561,6 +563,15 @@ def handle(line, status): error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e)) +def read_line(f, timeout, timeout_func): + ready_to_read, _, _ = select.select([f], [], [], timeout) + if ready_to_read: + return f.readline().rstrip() + else: + timeout_func() + return '' + + def main(): colorama.init() status = Status() @@ -575,10 +586,7 @@ def main(): clear() status.dump() print_prompt() - l = sys.stdin.readline() - if not l: - break - line = l.rstrip() + line = read_line(sys.stdin, timeout=3*60.0, timeout_func=status.logout) if line: print_display('\x0cBarcode:\n%20s' % line[:20]) handle(line, status) From 5c9d45b7255b88502ebca813e3e546b06da68570 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Tue, 18 Oct 2011 18:59:14 +0200 Subject: [PATCH 30/51] first steps for pulling display functionality out of the client --- client-barcode/display.py | 25 +++++++++++++++++++++++++ client-barcode/freitagskasse.py | 7 +++++++ 2 files changed, 32 insertions(+) create mode 100644 client-barcode/display.py diff --git a/client-barcode/display.py b/client-barcode/display.py new file mode 100644 index 0000000..6e2702e --- /dev/null +++ b/client-barcode/display.py @@ -0,0 +1,25 @@ +import serial + +class Display: + def __init__(self,portname="/dev/ttyUSB0"): + #code here + self.serialport=None + self.open_port(portname) + + def __del__(self): + if (not self.serialport == None): + self.serialport.close() + self.serialport=None + + def open_port(self,portname): + self.serialport = serial.Serial(portname,9600,timeout=2,rtscts=True, dsrdtr=True) + self.reset_display() + self.send("Hello world") + + + def reset_display(self): + print ("Initializing display on port %s\n" % self.serialport ) + #code here + + def send(self,text): + self.serialport.write(text) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index eff1bb5..681cba0 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -20,9 +20,11 @@ import time import urllib2 import select +from display import Display from thread import start_new_thread, allocate_lock import time +myDisplay=None COLOR_HINT = Fore.YELLOW + Style.BRIGHT COLOR_ERROR = Fore.RED @@ -576,6 +578,11 @@ def main(): colorama.init() status = Status() global scroll_line1,scroll_line2 + global myDisplay + + myDisplay = Display("/dev/ttyUSB0") + myDisplay.reset_display() + print_display("\x1b\x40\x1f\x43\x00") start_new_thread(display_thread,(1,)) From 0aad574f600f37f08faae603952a4f9644aa92a8 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Tue, 18 Oct 2011 19:23:14 +0200 Subject: [PATCH 31/51] commands converted from C-program to python, now replacing all calls accordingly --- client-barcode/display.py | 63 +++++++++++++++++++++++++++++---- client-barcode/freitagskasse.py | 2 +- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index 6e2702e..59ad56d 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -1,8 +1,9 @@ import serial + + class Display: def __init__(self,portname="/dev/ttyUSB0"): - #code here self.serialport=None self.open_port(portname) @@ -13,13 +14,61 @@ class Display: def open_port(self,portname): self.serialport = serial.Serial(portname,9600,timeout=2,rtscts=True, dsrdtr=True) - self.reset_display() - self.send("Hello world") + print ("Initializing display:\n %s\n" % self.serialport ) + self.cmd_reset() + self.write("Hello world") + + def cmd_reset(self): + #reset the display + self.write("\x1b\x40") + + def cmd_cursor_show(self,on=True): + #show or hide the cursor + if (on): + self.write("\x1f\x43\x01") + else: + self.write("\x1f\x43\x00") + + def cmd_blink(self,rate=127): + self.write("\x1f\x45%c" % rate) + + def cmd_display_on(self,on=True): + # blink-command: + # where the last value defines the blink rate, + # with 0=always on, 255=always off + if (on): + self.cmd_blink(0) + else: + self.cmd_blink(255) + + def cmd_curmode_overwrite(self): + cmd_curmode(1) + + def cmd_curmode_vscroll(self): + cmd_curmode(2) + + def cmd_curmode_hscroll(self): + cmd_curmode(3) + + def cmd_curmode(self,val=2): + self.write("\x1f%c" % val) + + def cmd_clear(self): + self.write("\x0c") + + + def cmd_time(self): + # activate timer display in lower right corner. + # actual time has to be set via display_set_timer. + self.write("\x1f\x55") + def cmd_time_set(self,h,m): + # configures hour and minutes of the internal clock and + # displays the time in the lower right corner. + # turns off when something gets written into the line. + # two bytes have to follow with hour and minute + self.write("\x1F\x54%c%c" % (h,m) ) - def reset_display(self): - print ("Initializing display on port %s\n" % self.serialport ) - #code here - def send(self,text): + def write(self,text): self.serialport.write(text) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 681cba0..d8ce0ba 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -581,7 +581,7 @@ def main(): global myDisplay myDisplay = Display("/dev/ttyUSB0") - myDisplay.reset_display() + myDisplay.cmd_reset() print_display("\x1b\x40\x1f\x43\x00") start_new_thread(display_thread,(1,)) From d468585069364199098786755912aba8874d5626 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 18 Oct 2011 21:05:36 +0200 Subject: [PATCH 32/51] client-barcode: Allow showing product info without log-in (bug #202) Log-in is tried first so if someone's code matches a product he can still log in --- client-barcode/freitagskasse.py | 46 ++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index d8ce0ba..8ffedd9 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -263,6 +263,30 @@ def error_page(error_message, hint_message=None): delay('Weiter', delay_seconds) +def item_info_page(item): + indent = 4 * ' ' + + clear() + print('Diese Ware heißt') + print() + print(indent + COLOR_SOME + item.name + COLOR_RESET) + print() + print('und kostet') + print() + if item.deposit > 0: + print(indent + '%s%4.2f Euro%s (plus %4.2f Euro Pfand) .' \ + % (COLOR_MUCH, item.price, COLOR_RESET, item.deposit)) + else: + print(indent + '%s%4.2f Euro%s .' \ + % (COLOR_MUCH, item.price, COLOR_RESET)) + print() + print() + print(COLOR_MUCH + 'Zum Kaufen bitte einloggen.' + COLOR_RESET) + print() + + delay('Weiter', 3) + + class Status: def __init__(self): self._reset() @@ -552,12 +576,22 @@ def handle(line, status): 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) - - 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?') + # Try same code as a product + item = None + try: + item = status.find(line) + except urllib2.HTTPError as e: + pass + + if item is None: + 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" ' \ + 'für Ihren Account Plugin "BarcodePlugin" ' \ + 'als erlaubt markiert?') + else: + item_info_page(item) else: print_display('\x0cFEHLER: Server Error%20s' % str(e)[:20]) error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e)) From f575423506792af11408741eab04ca78cabcdbee Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Tue, 18 Oct 2011 22:30:25 +0200 Subject: [PATCH 33/51] started to push the screensaver over --- client-barcode/display.py | 153 ++++++++++++++++++++++++++++---- client-barcode/freitagskasse.py | 53 +++-------- 2 files changed, 145 insertions(+), 61 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index 59ad56d..b1459e3 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -1,36 +1,70 @@ import serial - - +from thread import start_new_thread, allocate_lock +import time class Display: def __init__(self,portname="/dev/ttyUSB0"): self.serialport=None - self.open_port(portname) + self.portlock = allocate_lock() + self.portname=portname + self.open_port() + self.brightness=0 + self.screensaver = Screensaver(self) + self.screensaver.start() def __del__(self): + if (not self.screensaver == None): + self.screensaver.terminate() + self.screensaver = None + if (not self.serialport == None): self.serialport.close() self.serialport=None - def open_port(self,portname): - self.serialport = serial.Serial(portname,9600,timeout=2,rtscts=True, dsrdtr=True) - print ("Initializing display:\n %s\n" % self.serialport ) - self.cmd_reset() - self.write("Hello world") + def open_port(self): + + 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 ) + 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) + self.serialport = None + self.mutex_release() + pass + + + def cmd_reset(self): #reset the display - self.write("\x1b\x40") + self.cmd("\x1b\x40") def cmd_cursor_show(self,on=True): #show or hide the cursor if (on): - self.write("\x1f\x43\x01") + self.cmd("\x1f\x43\x01") else: - self.write("\x1f\x43\x00") + self.cmd("\x1f\x43\x00") def cmd_blink(self,rate=127): - self.write("\x1f\x45%c" % rate) + self.cmd("\x1f\x45%c" % chr(rate)) + + + def cmd_brightness(self,level): + if (level==0): #turn off: + self.cmd_display_on(False) + self.brightness = level + return + else: + if (self.brightness==0): #turn on, then set wanted brightness: + self.cmd_display_on(True) + self.brightness = level + self.cmd("\x1F\x58%c" % chr(level-1) ) def cmd_display_on(self,on=True): # blink-command: @@ -51,24 +85,105 @@ class Display: cmd_curmode(3) def cmd_curmode(self,val=2): - self.write("\x1f%c" % val) + self.cmd("\x1f%c" % chr(val)) def cmd_clear(self): - self.write("\x0c") + self.cmd("\x0c") def cmd_time(self): # activate timer display in lower right corner. # actual time has to be set via display_set_timer. - self.write("\x1f\x55") + self.cmd("\x1f\x55") - def cmd_time_set(self,h,m): + def cmd_time_set(self,h=None,m=None): + if (h==None or m==None): + now = time.localtime() + h=now.tm_hour + m=now.tm_min # configures hour and minutes of the internal clock and # displays the time in the lower right corner. # turns off when something gets written into the line. # two bytes have to follow with hour and minute - self.write("\x1F\x54%c%c" % (h,m) ) + self.cmd("\x1F\x54%c%c" % (chr(h),chr(m)) ) + self.cmd_curmode_hscroll() # makes the time more robust... + + def cmd(self,text): #for commands: do not reset screensaver timeout + self.write(text,False) + def write(self,text,idle_reset=True): #for data: reset screensaver timeout + if (not self.serialport == None): + if (idle_reset): + self.screensaver.idle_reset(); + self.serialport.write(text) + else: + self.open_port() + + + def mutex_get(self): + self.portlock.acquire() + + def mutex_release(self): + self.portlock.release() + + def terminate(self): + if (not self.screensaver == None): + self.screensaver.terminate() + self.screensaver = None + + +import threading +import time + +class Screensaver (threading.Thread): + def __init__(self,display): + self.display=display + self.runme=True + self.idlecounter=0 + self.timeout_dim=30 + self.timeout_message=60 + self.timeout_off=120 + self.mutex = allocate_lock() + threading.Thread.__init__(self) + + def run(self): + print "Starting Screensaver thread" + while(self.runme): + self.mutex.acquire() + self._main_loop() + self.mutex.release() + time.sleep(.5) + print "Exiting Screensaver thread" + + def terminate(self): + self.runme = False + + + def idle_reset(self): + self.mutex.acquire() + self.idlecounter=0 + self.mutex.release() + + def _main_loop(self): + if (self.idlecounter < self.timeout_off): + self.idlecounter+=1 + + if (self.idlecounter>=self.timeout_dim and self.idlecounter <= (self.timeout_dim+7)): + x = (8-( self.idlecounter - self.timeout_dim))/2 + self.display.mutax_get() + self.display.cmd_brightness(1+x) + self.display.mutax_release() + return + + if (self.idlecounter==self.timeout_message): + return + + if (self.idlecounter==self.timeout_off): + self.display.mutax_get() + display.cmd_display_on(False) + self.display.mutax_release() + return + + def __del__(self): + print("bye") - def write(self,text): - self.serialport.write(text) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index d8ce0ba..c8214ff 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -60,6 +60,7 @@ lock = allocate_lock() def display_scroll_text(line,text): global scroll_line1,scroll_line2 global offset_line1,offset_line2 + global lock lock.acquire() if (line==1): #clear the line on invocation: send_display("\x1f\x24\x01%c\x18" % chr(line) ) @@ -91,18 +92,7 @@ def display_handle_scroll(line,text,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) ) + return def display_thread(x): @@ -110,6 +100,7 @@ def display_thread(x): global offset_line1,offset_line2 global screensaver global idlemessage + global lock offset_line1=0 offset_line2=0 @@ -122,9 +113,6 @@ def display_thread(x): 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() @@ -136,36 +124,14 @@ def display_thread(x): 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 - + global myDisplay + myDisplay.write(s) #Front-End Funtion to display a Screen # with heading @@ -198,6 +164,8 @@ def print_display(s): global scroll_line1,scroll_line2 global offset_line1,offset_line2 global screensaver + global myDisplay + global lock lock.acquire() screensaver=0 @@ -206,7 +174,7 @@ def print_display(s): scroll_line1=None scroll_line2=None display_cmd_dim(5) - send_display(s) + myDisplay.write(s) lock.release() def clear(): @@ -582,8 +550,7 @@ def main(): myDisplay = Display("/dev/ttyUSB0") myDisplay.cmd_reset() - - print_display("\x1b\x40\x1f\x43\x00") + myDisplay.cmd_cursor_show(False) start_new_thread(display_thread,(1,)) #display_scroll_text(1,"Line1: Text, dumm scrollend!") @@ -605,3 +572,5 @@ if __name__ == '__main__': except KeyboardInterrupt: pass print_display("\x1b\x40Goodbye!") + myDisplay.terminate() + From 2858b1e71ab462d78d13c82e861d4e478cd4ecb5 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Tue, 18 Oct 2011 23:10:35 +0200 Subject: [PATCH 34/51] yea, now screensaver almost works... or sth like that. lets convert the helper funcs --- client-barcode/display.py | 43 ++++++++++++++++++++++----------- client-barcode/freitagskasse.py | 10 +++++--- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index b1459e3..ee6b1d6 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -8,7 +8,7 @@ class Display: self.portlock = allocate_lock() self.portname=portname self.open_port() - self.brightness=0 + self.brightness=5 self.screensaver = Screensaver(self) self.screensaver.start() @@ -56,9 +56,12 @@ class Display: def cmd_brightness(self,level): + if (self.brightness==level): + return + print("setting brightness to %i \n" %level) if (level==0): #turn off: self.cmd_display_on(False) - self.brightness = level + self.brightness = 0 return else: if (self.brightness==0): #turn on, then set wanted brightness: @@ -71,18 +74,26 @@ class Display: # where the last value defines the blink rate, # with 0=always on, 255=always off if (on): + if (not self.brightness==0): + return + 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)) self.cmd_blink(255) + self.brightness=0 def cmd_curmode_overwrite(self): - cmd_curmode(1) + self.cmd_curmode(1) def cmd_curmode_vscroll(self): - cmd_curmode(2) + self.cmd_curmode(2) def cmd_curmode_hscroll(self): - cmd_curmode(3) + self.cmd_curmode(3) def cmd_curmode(self,val=2): self.cmd("\x1f%c" % chr(val)) @@ -140,9 +151,9 @@ class Screensaver (threading.Thread): self.display=display self.runme=True self.idlecounter=0 - self.timeout_dim=30 - self.timeout_message=60 - self.timeout_off=120 + self.timeout_dim=10 + self.timeout_message=20 + self.timeout_off=32 self.mutex = allocate_lock() threading.Thread.__init__(self) @@ -162,26 +173,30 @@ class Screensaver (threading.Thread): def idle_reset(self): self.mutex.acquire() self.idlecounter=0 + self.display.cmd_brightness(5) self.mutex.release() def _main_loop(self): if (self.idlecounter < self.timeout_off): self.idlecounter+=1 - if (self.idlecounter>=self.timeout_dim and self.idlecounter <= (self.timeout_dim+7)): x = (8-( self.idlecounter - self.timeout_dim))/2 - self.display.mutax_get() + self.display.mutex_get() self.display.cmd_brightness(1+x) - self.display.mutax_release() + self.display.mutex_release() return if (self.idlecounter==self.timeout_message): + print("WHAAAAGHAA") + self.display.mutex_get() + self.display.cmd_time_set() + self.display.mutex_release() return if (self.idlecounter==self.timeout_off): - self.display.mutax_get() - display.cmd_display_on(False) - self.display.mutax_release() + self.display.mutex_get() + self.display.cmd_display_on(False) + self.display.mutex_release() return def __del__(self): diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index c8214ff..c9ce940 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -110,8 +110,8 @@ def display_thread(x): 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_OFF): +# screensaver=screensaver+1 if (screensaver == SCREENSAVER_TIMEOUT): @@ -131,7 +131,7 @@ def display_thread(x): def send_display(s): global myDisplay - myDisplay.write(s) +# myDisplay.write(s,False) #Front-End Funtion to display a Screen # with heading @@ -174,7 +174,7 @@ def print_display(s): scroll_line1=None scroll_line2=None display_cmd_dim(5) - myDisplay.write(s) +# myDisplay.write(s,False) lock.release() def clear(): @@ -550,6 +550,8 @@ def main(): myDisplay = Display("/dev/ttyUSB0") myDisplay.cmd_reset() + myDisplay.write("Hello world!\n") + time.sleep(10) myDisplay.cmd_cursor_show(False) start_new_thread(display_thread,(1,)) From a9d82b9b85c2fe91847e049ae897453069173ffc Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Tue, 18 Oct 2011 23:56:37 +0200 Subject: [PATCH 35/51] its scrolling, yay. --- client-barcode/display.py | 87 +++++++++++++++++++++++++++++++-- client-barcode/freitagskasse.py | 41 ++-------------- 2 files changed, 86 insertions(+), 42 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index ee6b1d6..1fabbcd 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -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() diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index c9ce940..1133c16 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -95,40 +95,6 @@ def display_cmd_dim(x): return -def display_thread(x): - global scroll_line1,scroll_line2 - global offset_line1,offset_line2 - global screensaver - global idlemessage - global lock - - 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_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 - - lock.release() - time.sleep(.5) - - def send_display(s): global myDisplay # myDisplay.write(s,False) @@ -549,14 +515,13 @@ def main(): global myDisplay myDisplay = Display("/dev/ttyUSB0") + myDisplay.start() myDisplay.cmd_reset() - myDisplay.write("Hello world!\n") - time.sleep(10) + myDisplay.display_screen("Nachricht","Hallo Welt! Dies ist eine sehr lange NAchricht!") + time.sleep(100) myDisplay.cmd_cursor_show(False) 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! *** ") while True: clear() From 65255fb53ad8fe502156e73d0be475f47f7b26fb Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Tue, 18 Oct 2011 23:59:18 +0200 Subject: [PATCH 36/51] the first time information is somehow displayed again --- client-barcode/freitagskasse.py | 81 ++------------------------------- 1 file changed, 3 insertions(+), 78 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 1133c16..27abbb6 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -56,45 +56,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 - global lock - 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): - return - - def send_display(s): global myDisplay # myDisplay.write(s,False) @@ -102,46 +63,12 @@ def send_display(s): #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) + myDisplay.display_screen(title,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 - global myDisplay - global lock - - lock.acquire() - screensaver=0 - offset_line1=0 - offset_line2=0 - scroll_line1=None - scroll_line2=None - display_cmd_dim(5) -# myDisplay.write(s,False) - lock.release() + myDisplay.write(s,False) def clear(): os.system('clear') @@ -517,10 +444,8 @@ def main(): myDisplay = Display("/dev/ttyUSB0") myDisplay.start() myDisplay.cmd_reset() - myDisplay.display_screen("Nachricht","Hallo Welt! Dies ist eine sehr lange NAchricht!") - time.sleep(100) + time.sleep(2) myDisplay.cmd_cursor_show(False) - start_new_thread(display_thread,(1,)) display_screen("HINWEIS","Herzlich willkommen bei der Freitagsrunde! *** ") while True: From dd49d650fbc6ad9c8b510412d6f7f2fe28afb7c3 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 19 Oct 2011 00:12:49 +0200 Subject: [PATCH 37/51] almost usable. threads are not all temrinating yet --- client-barcode/display.py | 30 ++++++++++------- client-barcode/freitagskasse.py | 58 +++++++++++++-------------------- 2 files changed, 41 insertions(+), 47 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index 1fabbcd..d9ac0a7 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -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 diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 27abbb6..80dc12d 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -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() From 4af75944909b85c834c17910af409c53df0788b5 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 19 Oct 2011 00:22:14 +0200 Subject: [PATCH 38/51] gnah.. i don't know yet if I hate or like that language --- client-barcode/display.py | 8 +++----- client-barcode/freitagskasse.py | 7 ++++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index d9ac0a7..b220bf6 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -21,7 +21,6 @@ class Display(threading.Thread): def __del__(self): if (not self.screensaver == None): - self.screensaver.terminate() self.screensaver = None if (not self.serialport == None): @@ -79,17 +78,15 @@ class Display(threading.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") 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 @@ -223,6 +220,7 @@ class Display(threading.Thread): self.portlock.release() def terminate(self): + self.runme=False if (not self.screensaver == None): self.screensaver.terminate() self.screensaver = None diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 80dc12d..b71bd47 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -239,7 +239,7 @@ class Status: try: command.run(self.login_name) except urllib2.HTTPError as e: - myDisplay.write('\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: @@ -371,6 +371,7 @@ def handle(line, status): if line == 'exit': clear() myDisplay.write("\x0c") + myDisplay.terminate() sys.exit(0) if status.logged_in(): @@ -448,7 +449,7 @@ if __name__ == '__main__': try: main() except KeyboardInterrupt: - pass - myDisplay.write("\x1b\x40Goodbye!") myDisplay.terminate() + myDisplay.write("\x1b\x40Goodbye!") + pass From 67ebf64ffe4c7618a7901717d91bea455d494b3c Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 19 Oct 2011 00:27:02 +0200 Subject: [PATCH 39/51] finally usuable(?) again! --- client-barcode/display.py | 14 ++++++++------ client-barcode/freitagskasse.py | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index b220bf6..42422d7 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -78,7 +78,7 @@ class Display(threading.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") self.offset_line1 = self.display_handle_scroll(1,self.scroll_line1,self.offset_line1) @@ -203,6 +203,8 @@ class Display(threading.Thread): if (not self.serialport == None): if (idle_reset): self.screensaver.idle_reset(); + self.scroll_line1=None + self.scroll_line2=None self.serialport.write(text) else: self.open_port() @@ -235,20 +237,20 @@ class Screensaver (threading.Thread): self.display=display self.runme=True self.idlecounter=0 - self.timeout_dim=10 - self.timeout_message=20 - self.timeout_off=32 + self.timeout_dim=30 + self.timeout_message=60 + self.timeout_off=300 self.mutex = allocate_lock() threading.Thread.__init__(self) def run(self): - print "Starting Screensaver thread" + #print "Starting Screensaver thread" while(self.runme): self.mutex.acquire() self._main_loop() self.mutex.release() time.sleep(.5) - print "Exiting Screensaver thread" + #print "Exiting Screensaver thread" def terminate(self): self.runme = False diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index b71bd47..09c7815 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -430,7 +430,6 @@ def main(): myDisplay = Display("/dev/ttyUSB0") myDisplay.start() myDisplay.cmd_reset() - time.sleep(2) myDisplay.cmd_cursor_show(False) myDisplay.display_screen("HINWEIS","Herzlich willkommen bei der Freitagsrunde! *** ") From fb80a1a70d6d186fd1e186c5dd6720d935eeac56 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 19 Oct 2011 01:45:57 +0200 Subject: [PATCH 40/51] now starts without display too --- client-barcode/display.py | 5 +---- client-barcode/freitagskasse.py | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index 42422d7..509cd6a 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -28,11 +28,10 @@ class Display(threading.Thread): self.serialport=None def open_port(self): - - 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 ) + self.mutex_get() self.cmd_reset() self.mutex_release() except Exception as e: @@ -40,8 +39,6 @@ class Display(threading.Thread): #print ("Ignoring and trying to open it again later\n") #print (e) self.serialport = None - self.mutex_release() - pass #Helper-Function, scrolls text in a specific line. diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 1c6159b..e3d2387 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -121,9 +121,11 @@ def item_info_page(item): print('und kostet') print() if item.deposit > 0: + myDisplay.display_screen("PREISINFO","%s: %4.2f Euro (%4.2f Euro Pfand)" % (item.name,item.price,item.deposit)) print(indent + '%s%4.2f Euro%s (plus %4.2f Euro Pfand) .' \ % (COLOR_MUCH, item.price, COLOR_RESET, item.deposit)) else: + myDisplay.display_screen("PREISINFO","%s: %4.2f Euro" % (item.name,item.price)) print(indent + '%s%4.2f Euro%s .' \ % (COLOR_MUCH, item.price, COLOR_RESET)) print() From f5d40285a1162098d3f85262e1506aaef7d2c463 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 19 Oct 2011 01:56:37 +0200 Subject: [PATCH 41/51] fixed typos and increased display time for price info --- client-barcode/freitagskasse.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index e3d2387..d3e377d 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -133,7 +133,7 @@ def item_info_page(item): print(COLOR_MUCH + 'Zum Kaufen bitte einloggen.' + COLOR_RESET) print() - delay('Weiter', 3) + delay('Weiter', 5) class Status: @@ -236,7 +236,7 @@ class Status: print(COLOR_MUCH + 'Bitte einloggen.' + COLOR_RESET) print() print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.') - myDisplay.display_screen("LOGIN","Bitte scanne Deinen login-Token! *** ") + myDisplay.display_screen("LOGIN","Bitte scanne Deinen Login-Token! *** ") print() def logged_in(self): @@ -477,7 +477,7 @@ def main(): print_prompt() line = read_line(sys.stdin, timeout=3*60.0, timeout_func=status.logout) if line: - myDisplay.write('\x0cBarcode:\n%20s' % line[:20]) + myDisplay.write('\x0cRFID/Barcode:\n%20s' % line[:20]) handle(line, status) From 7c8a072f4f5d1b6ecced85c616c1138f70cff19a Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 18 Oct 2011 00:22:30 +0200 Subject: [PATCH 42/51] RFID: Add current Keypresser Code --- rfid/rfid_keypresser.py | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 rfid/rfid_keypresser.py diff --git a/rfid/rfid_keypresser.py b/rfid/rfid_keypresser.py new file mode 100755 index 0000000..48e0744 --- /dev/null +++ b/rfid/rfid_keypresser.py @@ -0,0 +1,55 @@ +#! /usr/bin/env python + +# by Andrew Karpow +# Public Domain + +from smartcard.CardMonitoring import CardMonitor, CardObserver +from smartcard.util import toHexString +from threading import Condition +import subprocess + +# a simple card observer that prints inserted/removed cards +class printobserver(CardObserver): + + def update(self, observable, (addedcards, removedcards)): + for card in addedcards: + + SELECT_GUID= [0xFF, 0xCA, 0x00, 0x00, 0x00] + print "+Inserted: ", toHexString(card.atr) + + try: + card.connection = card.createConnection() + card.connection.connect() + + # Request UID - Unique Identifier + response, sw1, sw2 = card.connection.transmit(SELECT_GUID) + + except Exception as e: + print str(e) + continue + + # convert UID to hex-string and remove whitespaces + send= toHexString(response).replace(' ', '') + + try: + # Send UID to active window + subprocess.Popen(['xdotool', 'type', send]) + except OSError as e: + print str(e) + + for card in removedcards: + print "-Removed: ", toHexString(card.atr) + + +if __name__ == '__main__': + cardmonitor= CardMonitor() + cardobserver= printobserver() + cardmonitor.addObserver(cardobserver) + + try: + c= Condition() + c.acquire() + c.wait() + except KeyboardInterrupt as e: + cardmonitor.deleteObserver(cardobserver) + From b526525cfa4da56fd970b04f344fe764e4c06e9b Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 18 Oct 2011 01:25:14 +0200 Subject: [PATCH 43/51] RFID: Add finishing keypress for xdotool --- rfid/rfid_keypresser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rfid/rfid_keypresser.py b/rfid/rfid_keypresser.py index 48e0744..28f9d9b 100755 --- a/rfid/rfid_keypresser.py +++ b/rfid/rfid_keypresser.py @@ -33,7 +33,7 @@ class printobserver(CardObserver): try: # Send UID to active window - subprocess.Popen(['xdotool', 'type', send]) + subprocess.Popen(['xdotool', 'type', send+'\n']) except OSError as e: print str(e) From 2e83f6fbb31bafe010353f5201636f80e9f2e920 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 19 Oct 2011 04:48:23 +0200 Subject: [PATCH 44/51] RFID: License under "GPL v3 or later" (with acknoledgement from Andy) --- rfid/rfid_keypresser.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rfid/rfid_keypresser.py b/rfid/rfid_keypresser.py index 28f9d9b..819691c 100755 --- a/rfid/rfid_keypresser.py +++ b/rfid/rfid_keypresser.py @@ -1,7 +1,8 @@ #! /usr/bin/env python - -# by Andrew Karpow -# Public Domain +# -*- coding: utf-8 -*- +# +# Copyright (C) 2011 Andrew Karpow +# Licensed under GPL v3 or later from smartcard.CardMonitoring import CardMonitor, CardObserver from smartcard.util import toHexString From 9880b1ebc1892e0559c816aa21d06dd9e5087624 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 19 Oct 2011 05:55:36 +0200 Subject: [PATCH 45/51] client-barcode: Turn off console echo (experiment for now, idea by Andy Gunschl) --- client-barcode/freitagskasse.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index d3e377d..01e2de7 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -19,6 +19,8 @@ import os import time import urllib2 import select +import termios +import atexit from display import Display from thread import start_new_thread, allocate_lock @@ -458,8 +460,25 @@ def read_line(f, timeout, timeout_func): return '' +def enable_echo(fd, enabled): + (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(fd) + if enabled: + lflag |= termios.ECHO + else: + lflag &= ~termios.ECHO + new_attr = [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] + termios.tcsetattr(fd, termios.TCSANOW, new_attr) + + def main(): + debugging = bool(os.environ.get('BARCODE_PLUGIN_DEBUG', False)) + colorama.init() + + if not debugging: + atexit.register(enable_echo, sys.stdin.fileno(), True) + enable_echo(sys.stdin.fileno(), False) + status = Status() global scroll_line1,scroll_line2 global myDisplay @@ -474,7 +493,8 @@ def main(): while True: clear() status.dump() - print_prompt() + if debugging: + print_prompt() line = read_line(sys.stdin, timeout=3*60.0, timeout_func=status.logout) if line: myDisplay.write('\x0cRFID/Barcode:\n%20s' % line[:20]) From a0f1acffc1a5eee376c9a43d2d4484f22de6287e Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 19 Oct 2011 05:56:20 +0200 Subject: [PATCH 46/51] client-barcode: Reduce presentation time of item info page --- client-barcode/freitagskasse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 01e2de7..55606d8 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -135,7 +135,7 @@ def item_info_page(item): print(COLOR_MUCH + 'Zum Kaufen bitte einloggen.' + COLOR_RESET) print() - delay('Weiter', 5) + delay('Weiter', 3) class Status: From 10962d479fc51e929ad6ea7179cf5ee924ed830b Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Wed, 19 Oct 2011 12:45:28 +0200 Subject: [PATCH 47/51] sleep entfernt, etc --- client-barcode/freitagskasse.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 55606d8..266cb58 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -396,14 +396,14 @@ def print_prompt(): def handle(line, status): + myDisplay.setIdlemessage("Mir ist langweilig!") if line == 'exit': clear() - myDisplay.write("\x0c") + myDisplay.cmd_clear() myDisplay.terminate() sys.exit(0) if status.logged_in(): - myDisplay.setIdlemessage(" Comitten nicht vergessen! ***") if line in CODES: call = CODES[line] method = call[0] @@ -422,9 +422,9 @@ def handle(line, status): else: status.buy(item) else: - myDisplay.setIdlemessage("Mir ist langweilig!") try: status.login(line) + myDisplay.setIdlemessage(" Comitten nicht vergessen! ***") except urllib2.HTTPError as e: if e.code == 404: # URL not found == user unknown # Try same code as a product @@ -488,8 +488,7 @@ def main(): myDisplay.cmd_reset() myDisplay.cmd_cursor_show(False) - myDisplay.display_screen("HINWEIS","Herzlich willkommen bei der Freitagsrunde! *** ") - time.sleep(5) + myDisplay.display_screen("Bitte Geduld","Initialisierung... ") while True: clear() status.dump() @@ -506,6 +505,7 @@ if __name__ == '__main__': main() except KeyboardInterrupt: myDisplay.terminate() - myDisplay.write("\x1b\x40Goodbye!") + myDisplay.cmd_reset() + myDisplay.cmd_cursor_show(False) pass From 5ba9cf97d61893db7fe61264266b10938af5b38d Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 19 Oct 2011 19:17:28 +0200 Subject: [PATCH 48/51] Revert "client-barcode: Turn off console echo (experiment for now, idea by Andy Gunschl)" This reverts commit 9880b1ebc1892e0559c816aa21d06dd9e5087624. --- client-barcode/freitagskasse.py | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 266cb58..6c18b0d 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -19,8 +19,6 @@ import os import time import urllib2 import select -import termios -import atexit from display import Display from thread import start_new_thread, allocate_lock @@ -460,25 +458,8 @@ def read_line(f, timeout, timeout_func): return '' -def enable_echo(fd, enabled): - (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(fd) - if enabled: - lflag |= termios.ECHO - else: - lflag &= ~termios.ECHO - new_attr = [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] - termios.tcsetattr(fd, termios.TCSANOW, new_attr) - - def main(): - debugging = bool(os.environ.get('BARCODE_PLUGIN_DEBUG', False)) - colorama.init() - - if not debugging: - atexit.register(enable_echo, sys.stdin.fileno(), True) - enable_echo(sys.stdin.fileno(), False) - status = Status() global scroll_line1,scroll_line2 global myDisplay @@ -492,8 +473,7 @@ def main(): while True: clear() status.dump() - if debugging: - print_prompt() + print_prompt() line = read_line(sys.stdin, timeout=3*60.0, timeout_func=status.logout) if line: myDisplay.write('\x0cRFID/Barcode:\n%20s' % line[:20]) From eff542bc993e0d373369fdee07ceae95711e561e Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 19 Oct 2011 19:30:26 +0200 Subject: [PATCH 49/51] client-barcode: Increase presentation time of item info page (bug #202) --- client-barcode/freitagskasse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 6c18b0d..09650b6 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -133,7 +133,7 @@ def item_info_page(item): print(COLOR_MUCH + 'Zum Kaufen bitte einloggen.' + COLOR_RESET) print() - delay('Weiter', 3) + delay('Weiter', 6) class Status: From 7046890acfc69cf0deabd3ce2533aa6f7e62e48e Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 19 Oct 2011 19:43:33 +0200 Subject: [PATCH 50/51] client-barcode: Show sum of commodity and deposit on item info page, too (bug #202) --- client-barcode/freitagskasse.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 09650b6..939c14f 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -122,8 +122,9 @@ def item_info_page(item): print() if item.deposit > 0: myDisplay.display_screen("PREISINFO","%s: %4.2f Euro (%4.2f Euro Pfand)" % (item.name,item.price,item.deposit)) - print(indent + '%s%4.2f Euro%s (plus %4.2f Euro Pfand) .' \ - % (COLOR_MUCH, item.price, COLOR_RESET, item.deposit)) + print(indent + '%s%4.2f Euro%s + %4.2f Euro Pfand = %s%4.2f Euro%s .' \ + % (COLOR_SOME, item.price, COLOR_RESET, item.deposit, + COLOR_MUCH, item.price + item.deposit, COLOR_RESET)) else: myDisplay.display_screen("PREISINFO","%s: %4.2f Euro" % (item.name,item.price)) print(indent + '%s%4.2f Euro%s .' \ From 53368e49ac90b65cffe9951e2d434e29e4c4bf72 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 19 Oct 2011 20:32:17 +0200 Subject: [PATCH 51/51] client-barcode: Commit 6 deposits of 1.00 Euro as one deposit of 6.00 Euro (bug #203) --- client-barcode/freitagskasse.py | 15 +++++++++++++++ client-barcode/freitagslib/commands.py | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 939c14f..9958f60 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -261,6 +261,21 @@ class Status: def commit(self): assert(self.logged_in()) + # Compress DepositCommands + dummy, initial_balance = self.transfers[0] + balance_before = initial_balance + compressed_deposit = DepositCommand(Decimal('0')) + others = list() + for (command, dummy) in list(self.transfers): + if isinstance(command, DepositCommand): + compressed_deposit.add(command) + else: + others.append((command, balance_before)) + balance_before += command.difference() + if compressed_deposit.difference() != 0: + others.append((compressed_deposit, balance_before)) + self.transfers = others + # Process command queue for (command, balance_backup) in list(self.transfers): try: diff --git a/client-barcode/freitagslib/commands.py b/client-barcode/freitagslib/commands.py index 1782118..69a27ab 100644 --- a/client-barcode/freitagslib/commands.py +++ b/client-barcode/freitagslib/commands.py @@ -15,6 +15,10 @@ class DepositCommand(object): def difference(self): return self._difference + def add(self, deposit_command): + assert(isinstance(deposit_command, DepositCommand)) + self._difference += deposit_command._difference + def run(self, user_name): net.deposit(self._difference, net.DEPOSIT_CASH, user_name)