projects
/
Arduino-Nano-VA-meter
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
generate serial output for trend
[Arduino-Nano-VA-meter]
/
main.c
diff --git
a/main.c
b/main.c
index
181cde5
..
b79f191
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)
#define USART_BAUDRATE 9600
#define UBRR_VALUE (((F_CPU/(USART_BAUDRATE*16UL)))-1)
+// this will output only changes on serial
+#define SERIAL_CHANGES 0
+
void serial_init(){
// initialize USART (must call this before using it)
UBRR0=UBRR_VALUE; // set baud rate
void serial_init(){
// initialize USART (must call this before using it)
UBRR0=UBRR_VALUE; // set baud rate
@@
-27,7
+30,7
@@
void serial_string(const char* s){
void serial_break(){
serial_send(10); // new line
void serial_break(){
serial_send(10); // new line
-
serial_send(13); // carriage return
+
//
serial_send(13); // carriage return
}
void serial_comma(){
serial_send(','); // comma
}
void serial_comma(){
serial_send(','); // comma
@@
-83,8
+86,11
@@
volatile uint8_t regC;
volatile uint8_t regD;
// these values will hold the current/voltage value
volatile uint8_t regD;
// these values will hold the current/voltage value
-volatile char current[4];
-volatile char voltage[4];
+volatile char current[4] = "XXXX";
+volatile char voltage[4] = "XXXX";
+
+volatile int display_sum = 0;
+volatile int last_display_sum = 0;
void read_capture(){
void read_capture(){
@@
-185,12
+191,24
@@
void capture_full(){
if (capture_letter('1'+i)) {break;}
}
}
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('.');}
}
for(i=0;i<4;i++) {
serial_send(voltage[i]);
if (i==1){serial_send('.');}
}
- serial_send('
,
');
+ serial_send('
');
for(i=0;i<4;i++) {
serial_send(current[i]);
if (i==2){serial_send('.');}
for(i=0;i<4;i++) {
serial_send(current[i]);
if (i==2){serial_send('.');}