From c65d52083c201ecfbb93756d73d901c4a2b20b53 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 16 Oct 2016 11:10:01 +0200 Subject: [PATCH] report only changed values on serial --- main.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 181cde5..fc797a6 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,9 @@ #define USART_BAUDRATE 9600 #define UBRR_VALUE (((F_CPU/(USART_BAUDRATE*16UL)))-1) +// this will output only changes on serial +#define SERIAL_CHANGES 1 + void serial_init(){ // initialize USART (must call this before using it) UBRR0=UBRR_VALUE; // set baud rate @@ -86,6 +89,9 @@ volatile uint8_t regD; volatile char current[4]; volatile char voltage[4]; +volatile int display_sum = 0; +volatile int last_display_sum = 0; + void read_capture(){ // load the volatile capture variables with tue current pin state @@ -185,7 +191,19 @@ void capture_full(){ if (capture_letter('1'+i)) {break;} } } - + +#if SERIAL_CHANGES + // don't send same values over serial + for(i=0;i<4;i++) { + display_sum = voltage[i] + current[i]; + } + if ( display_sum == last_display_sum ) { + return; + } else { + last_display_sum = display_sum; + } +#endif + for(i=0;i<4;i++) { serial_send(voltage[i]); if (i==1){serial_send('.');} -- 2.20.1