avr-equeue

changeset 1:9cb1db5d0e7c

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 13 Jul 2014 12:18:14 +0300
parents b1d590a201df
children 9b7983ee2a89
files Makefile equeue.c serial.c
diffstat 3 files changed, 36 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Wed Jul 09 08:58:46 2014 +0300
     1.2 +++ b/Makefile	Sun Jul 13 12:18:14 2014 +0300
     1.3 @@ -27,7 +27,7 @@
     1.4  
     1.5  .PHONY: fuses
     1.6  fuses:
     1.7 -	avrdude -c usbtiny -p $(mcu_dude) -U lfuse:w:0xc7:m
     1.8 +	avrdude -c usbtiny -p $(mcu_dude) -U lfuse:w:0xf7:m
     1.9  
    1.10  .PHONY: program
    1.11  program: $(hex)
     2.1 --- a/equeue.c	Wed Jul 09 08:58:46 2014 +0300
     2.2 +++ b/equeue.c	Sun Jul 13 12:18:14 2014 +0300
     2.3 @@ -4,6 +4,7 @@
     2.4   * B0		select display (0: units, 1: tens)
     2.5   * B[2,3]	buttons with internal pullups
     2.6   * D[6,7]	mode leds
     2.7 + * D4		emergency inverted B0 ...
     2.8   */
     2.9  
    2.10  #ifdef XTAL
    2.11 @@ -36,6 +37,9 @@
    2.12  int cur_customer;
    2.13  int last_ticket;
    2.14  
    2.15 +int com_issue_pending, com_cust_pending;
    2.16 +int report_inputs;
    2.17 +
    2.18  #define MAX_INPUT_SIZE	256
    2.19  char input[MAX_INPUT_SIZE];
    2.20  int inp_cidx;
    2.21 @@ -64,6 +68,15 @@
    2.22  	for(;;) {
    2.23  		int digit = i & 1;
    2.24  
    2.25 +		if(com_issue_pending) {
    2.26 +			printf("ticket: %d\n", last_ticket);
    2.27 +			com_issue_pending = 0;
    2.28 +		}
    2.29 +		if(com_cust_pending) {
    2.30 +			printf("customer: %d\n", cur_customer);
    2.31 +			com_cust_pending = 0;
    2.32 +		}
    2.33 +
    2.34  		/* first grab any input from the serial port */
    2.35  		while(have_input()) {
    2.36  			int c = getchar();
    2.37 @@ -80,10 +93,9 @@
    2.38  		}
    2.39  
    2.40  		disp_off();
    2.41 -		_delay_ms(1);
    2.42  		PORTB = (PORTB & 0xfe) | digit;
    2.43 +		PORTD = (PORTD & 0xef) | (((~digit) & 1) << 4);
    2.44  		/*PORTD = (PORTD & 0xdf) | ((~digit) << 5);*/
    2.45 -		_delay_ms(1);
    2.46  
    2.47  		if(show_ticket_cnt > 0) {
    2.48  			--show_ticket_cnt;
    2.49 @@ -95,7 +107,7 @@
    2.50  		}
    2.51  
    2.52  		++i;
    2.53 -		_delay_ms(1);
    2.54 +		_delay_ms(2);
    2.55  	}
    2.56  }
    2.57  
    2.58 @@ -103,7 +115,10 @@
    2.59  {
    2.60  	last_ticket++;
    2.61  	show_ticket_cnt = SHOW_TICKET_DELAY;
    2.62 -	printf("ticket: %d\n", last_ticket);
    2.63 +	if(report_inputs) {
    2.64 +		com_issue_pending = 1;
    2.65 +	}
    2.66 +	_delay_ms(1);
    2.67  }
    2.68  
    2.69  void next_customer(void)
    2.70 @@ -111,8 +126,11 @@
    2.71  	if(cur_customer < last_ticket) {
    2.72  		cur_customer++;
    2.73  		show_ticket_cnt = 0;
    2.74 -		printf("customer: %d\n", cur_customer);
    2.75 +		if(report_inputs) {
    2.76 +			com_cust_pending = 1;
    2.77 +		}
    2.78  	}
    2.79 +	_delay_ms(1);
    2.80  }
    2.81  
    2.82  ISR(PCINT0_vect)
    2.83 @@ -185,6 +203,11 @@
    2.84  		printf("OK,turning echo %s\n", cmd_echo ? "on" : "off");
    2.85  		break;
    2.86  
    2.87 +	case 'i':
    2.88 +		report_inputs = !report_inputs;
    2.89 +		printf("OK,turning input reports %s\n", report_inputs ? "on" : "off");
    2.90 +		break;
    2.91 +
    2.92  	case 'v':
    2.93  		printf("OK,%s\n", VERSTR);
    2.94  		break;
    2.95 @@ -216,7 +239,7 @@
    2.96  
    2.97  	case 'h':
    2.98  		printf("OK,commands: (e)cho, (v)ersion, (t)icket, (c)ustomer, "
    2.99 -				"(n)ext, (q)ueue, (r)eset, (h)elp.\n");
   2.100 +				"(n)ext, (q)ueue, (r)eset, (i)nput-reports, (h)elp.\n");
   2.101  		break;
   2.102  
   2.103  	default:
     3.1 --- a/serial.c	Wed Jul 09 08:58:46 2014 +0300
     3.2 +++ b/serial.c	Sun Jul 13 12:18:14 2014 +0300
     3.3 @@ -1,5 +1,11 @@
     3.4 +#ifdef XTAL
     3.5  #define F_CLK	XTAL
     3.6  #define F_CPU	XTAL
     3.7 +#else
     3.8 +#warning "compiled for 1mhz internal rc osc. serial comms won't work"
     3.9 +#define F_CLK	1000000
    3.10 +#define F_CPU	1000000
    3.11 +#endif
    3.12  
    3.13  #include <stdio.h>
    3.14  #include <avr/io.h>