# HG changeset patch
# User John Tsiombikas <nuclear@member.fsf.org>
# Date 1405243094 -10800
# Node ID 9cb1db5d0e7c5365a4e6006fe282b47fd6151ea6
# Parent  b1d590a201dfaea128a3696a4db61a71046694f2
foo

diff -r b1d590a201df -r 9cb1db5d0e7c Makefile
--- a/Makefile	Wed Jul 09 08:58:46 2014 +0300
+++ b/Makefile	Sun Jul 13 12:18:14 2014 +0300
@@ -27,7 +27,7 @@
 
 .PHONY: fuses
 fuses:
-	avrdude -c usbtiny -p $(mcu_dude) -U lfuse:w:0xc7:m
+	avrdude -c usbtiny -p $(mcu_dude) -U lfuse:w:0xf7:m
 
 .PHONY: program
 program: $(hex)
diff -r b1d590a201df -r 9cb1db5d0e7c equeue.c
--- a/equeue.c	Wed Jul 09 08:58:46 2014 +0300
+++ b/equeue.c	Sun Jul 13 12:18:14 2014 +0300
@@ -4,6 +4,7 @@
  * B0		select display (0: units, 1: tens)
  * B[2,3]	buttons with internal pullups
  * D[6,7]	mode leds
+ * D4		emergency inverted B0 ...
  */
 
 #ifdef XTAL
@@ -36,6 +37,9 @@
 int cur_customer;
 int last_ticket;
 
+int com_issue_pending, com_cust_pending;
+int report_inputs;
+
 #define MAX_INPUT_SIZE	256
 char input[MAX_INPUT_SIZE];
 int inp_cidx;
@@ -64,6 +68,15 @@
 	for(;;) {
 		int digit = i & 1;
 
+		if(com_issue_pending) {
+			printf("ticket: %d\n", last_ticket);
+			com_issue_pending = 0;
+		}
+		if(com_cust_pending) {
+			printf("customer: %d\n", cur_customer);
+			com_cust_pending = 0;
+		}
+
 		/* first grab any input from the serial port */
 		while(have_input()) {
 			int c = getchar();
@@ -80,10 +93,9 @@
 		}
 
 		disp_off();
-		_delay_ms(1);
 		PORTB = (PORTB & 0xfe) | digit;
+		PORTD = (PORTD & 0xef) | (((~digit) & 1) << 4);
 		/*PORTD = (PORTD & 0xdf) | ((~digit) << 5);*/
-		_delay_ms(1);
 
 		if(show_ticket_cnt > 0) {
 			--show_ticket_cnt;
@@ -95,7 +107,7 @@
 		}
 
 		++i;
-		_delay_ms(1);
+		_delay_ms(2);
 	}
 }
 
@@ -103,7 +115,10 @@
 {
 	last_ticket++;
 	show_ticket_cnt = SHOW_TICKET_DELAY;
-	printf("ticket: %d\n", last_ticket);
+	if(report_inputs) {
+		com_issue_pending = 1;
+	}
+	_delay_ms(1);
 }
 
 void next_customer(void)
@@ -111,8 +126,11 @@
 	if(cur_customer < last_ticket) {
 		cur_customer++;
 		show_ticket_cnt = 0;
-		printf("customer: %d\n", cur_customer);
+		if(report_inputs) {
+			com_cust_pending = 1;
+		}
 	}
+	_delay_ms(1);
 }
 
 ISR(PCINT0_vect)
@@ -185,6 +203,11 @@
 		printf("OK,turning echo %s\n", cmd_echo ? "on" : "off");
 		break;
 
+	case 'i':
+		report_inputs = !report_inputs;
+		printf("OK,turning input reports %s\n", report_inputs ? "on" : "off");
+		break;
+
 	case 'v':
 		printf("OK,%s\n", VERSTR);
 		break;
@@ -216,7 +239,7 @@
 
 	case 'h':
 		printf("OK,commands: (e)cho, (v)ersion, (t)icket, (c)ustomer, "
-				"(n)ext, (q)ueue, (r)eset, (h)elp.\n");
+				"(n)ext, (q)ueue, (r)eset, (i)nput-reports, (h)elp.\n");
 		break;
 
 	default:
diff -r b1d590a201df -r 9cb1db5d0e7c serial.c
--- a/serial.c	Wed Jul 09 08:58:46 2014 +0300
+++ b/serial.c	Sun Jul 13 12:18:14 2014 +0300
@@ -1,5 +1,11 @@
+#ifdef XTAL
 #define F_CLK	XTAL
 #define F_CPU	XTAL
+#else
+#warning "compiled for 1mhz internal rc osc. serial comms won't work"
+#define F_CLK	1000000
+#define F_CPU	1000000
+#endif
 
 #include <stdio.h>
 #include <avr/io.h>