report only changed values on serial
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 16 Oct 2016 09:10:01 +0000 (11:10 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 16 Oct 2016 09:10:01 +0000 (11:10 +0200)
main.c

diff --git a/main.c b/main.c
index 181cde5..fc797a6 100644 (file)
--- 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('.');}