Browse Source

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

Florian Streibelt 9 years ago
parent
commit
18f1de1b26
2 changed files with 80 additions and 13 deletions
  1. 79
    12
      client-barcode/freitagskasse.py
  2. 1
    1
      display-daemon/ser.c

+ 79
- 12
client-barcode/freitagskasse.py View File

@@ -38,6 +38,17 @@ display_fifo = None
38 38
 scroll_line1 = None
39 39
 scroll_line2 = None
40 40
 
41
+idlemessage = None
42
+
43
+offset_line1 = 0
44
+offset_line2 = 0
45
+
46
+brightness  = 5
47
+screensaver = 0
48
+
49
+SCREENSAVER_DIM     = 30
50
+SCREENSAVER_TIMEOUT = 90
51
+SCREENSAVER_OFF     = 300
41 52
 
42 53
 lock = allocate_lock()
43 54
 
@@ -59,25 +70,72 @@ def display_scroll_text(line,text):
59 70
 
60 71
 def display_handle_scroll(line,text,offset):
61 72
 	if (text):
62
-		send_display("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
63 73
 		l = len(text)
64
-		missing_chars=20+offset-l
65
-		if (missing_chars>0):
66
-			send_display(text[:missing_chars])
67
-		offset=((offset+1)%l)
74
+		if (l<21):
75
+			if (offset == 0):
76
+				send_display("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
77
+				offset=1
78
+		else:
79
+			send_display("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
80
+			missing_chars=20+offset-l
81
+			if (missing_chars>0):
82
+				send_display(text[:missing_chars])
83
+			offset=((offset+1)%l)
68 84
 	else:
69 85
 		offset=0	#reset offset
70 86
 	return offset
71 87
 
88
+
89
+def display_cmd_dim(x):
90
+	global brightness
91
+	if (brightness!=x):
92
+		if (x==0): #turn off:
93
+			send_display("\x1F\x45%c" % chr(255) )
94
+			brightness = x
95
+			return
96
+			
97
+		else:
98
+			if (brightness==0): #turn on, then set wanted brightness:
99
+				send_display("\x1F\x45%c" % chr(0) )
100
+			brightness = x
101
+			send_display("\x1F\x58%c" % chr(x-1) )
102
+
103
+
72 104
 def display_thread(x):
73 105
 	global scroll_line1,scroll_line2
74 106
 	global offset_line1,offset_line2
107
+	global screensaver
108
+	global idlemessage
109
+
75 110
 	offset_line1=0
76 111
 	offset_line2=0
77 112
 	while(True):
78 113
 		lock.acquire()
114
+
79 115
 		offset_line1 = display_handle_scroll(1,scroll_line1,offset_line1)
80 116
 		offset_line2 = display_handle_scroll(2,scroll_line2,offset_line2)
117
+
118
+		if (screensaver <= SCREENSAVER_OFF):
119
+			screensaver=screensaver+1
120
+
121
+		if ((screensaver >= SCREENSAVER_DIM) and (screensaver <= (SCREENSAVER_DIM+7))): #activate first stage of screensaver:
122
+			x = (8-( screensaver - SCREENSAVER_DIM))/2
123
+			display_cmd_dim(1+x)
124
+
125
+		if (screensaver == SCREENSAVER_TIMEOUT):
126
+			now = time.localtime()
127
+			send_display("\x0c\x1F\x54%c%c\x1f\x03" % (chr(now.tm_hour),chr(now.tm_min)));
128
+			if (scroll_line2):
129
+				scroll_line1=scroll_line2
130
+			else:
131
+				scroll_line1=idlemessage
132
+			scroll_line2=None
133
+			offset_line1=0
134
+			offset_line2=0				
135
+		
136
+		if (screensaver == SCREENSAVER_OFF):
137
+			display_cmd_dim(0)
138
+			
81 139
 		lock.release()
82 140
 		time.sleep(.5)
83 141
 
@@ -110,8 +168,13 @@ def send_display(s):
110 168
 def display_screen(title,message):
111 169
 	global scroll_line1,scroll_line2
112 170
 	global offset_line1,offset_line2
171
+	global screensaver
172
+
113 173
 	offset_line1=0
114 174
 	offset_line2=0
175
+	screensaver=0
176
+	display_cmd_dim(5)
177
+
115 178
 	if (len(title)<21):
116 179
 		scroll_line1=None
117 180
 		send_display("\x1f\x24\x01%c\x18%s" % (chr(1),'\xdb'*20) )
@@ -123,22 +186,22 @@ def display_screen(title,message):
123 186
 	else:
124 187
 		display_scroll_text(1,title)
125 188
 
126
-	if (len(message)<21):
127
-		scroll_line2=None
128
-		send_display("\x1f\x24%c%c\x18%s" % (chr(1),chr(2),message) )
129
-	else:
130
-		display_scroll_text(2,message)
189
+	display_scroll_text(2,message)
131 190
 
132 191
 
133 192
 #Front-End function to send data to the display.
134 193
 def print_display(s):
135 194
 	global scroll_line1,scroll_line2
136 195
 	global offset_line1,offset_line2
196
+	global screensaver
197
+
137 198
 	lock.acquire()
199
+	screensaver=0
138 200
 	offset_line1=0
139 201
 	offset_line2=0
140 202
 	scroll_line1=None
141 203
 	scroll_line2=None
204
+	display_cmd_dim(5)
142 205
 	send_display(s)
143 206
 	lock.release()
144 207
 
@@ -208,6 +271,7 @@ class Status:
208 271
 		self.transfers = None
209 272
 
210 273
 	def dump(self):
274
+
211 275
 		def sign(amount, plus='+'):
212 276
 			return '-' if amount < 0 else plus
213 277
 
@@ -443,12 +507,14 @@ def print_prompt():
443 507
 
444 508
 
445 509
 def handle(line, status):
510
+	global idlemessage
446 511
 	if line == 'exit':
447 512
 		clear()
448
-		print_display("\x1b\x40exit...")
513
+		print_display("\x0c")
449 514
 		sys.exit(0)
450 515
 
451 516
 	if status.logged_in():
517
+		idlemessage=" Comitten nicht vergessen! ***"
452 518
 		if line in CODES:
453 519
 			call = CODES[line]
454 520
 			method = call[0]
@@ -467,6 +533,7 @@ def handle(line, status):
467 533
 			else:
468 534
 				status.buy(item)
469 535
 	else:
536
+		idlemessage="Mir ist langweilig!"
470 537
 		try:
471 538
 			status.login(line)
472 539
 		except urllib2.HTTPError as e:
@@ -488,7 +555,7 @@ def main():
488 555
 	colorama.init()
489 556
 	status = Status()
490 557
 	global scroll_line1,scroll_line2
491
-	print_display("\x1b\x40Kassensystem \n startet...")
558
+	print_display("\x1b\x40\x1f\x43\x00")
492 559
 	start_new_thread(display_thread,(1,))
493 560
 
494 561
 	#display_scroll_text(1,"Line1: Text, dumm scrollend!")

+ 1
- 1
display-daemon/ser.c View File

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

Loading…
Cancel
Save