diff main.c @ 40:9b5b202129c3

main.c: - get rid of some debugging - separate uart_enabled flag ts.py: - remember next wake time, not the interval log.py: - comments for sqlite templog.py - use cgi
author Matt Johnston <matt@ucc.asn.au>
date Sat, 23 Jun 2012 22:10:23 +0800
parents a670a67ba489
children 1701457e6007
line wrap: on
line diff
--- a/main.c	Sat Jun 16 09:08:47 2012 +0800
+++ b/main.c	Sat Jun 23 22:10:23 2012 +0800
@@ -1,9 +1,3 @@
-/* Name: main.c
- * Author: <insert your name here>
- * Copyright: <insert your copyright message here>
- * License: <insert your license reference here>
- */
-
 #include <stdio.h>
 #include <string.h>
 #include <stddef.h>
@@ -85,6 +79,7 @@
 // boolean flags
 static uint8_t need_measurement;
 static uint8_t need_comms;
+static uint8_t uart_enabled;
 
 // counts down from WAKE_SECS to 0, goes to deep sleep when hits 0
 static uint8_t comms_timeout;
@@ -184,23 +179,27 @@
     UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0);
     //8N1
     UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
+	uart_enabled = 1;
 }
 
 static void 
 uart_off()
 {
-#if 0
     // Turn of interrupts and disable tx/rx
     UCSR0B = 0;
+	uart_enabled = 0;
 
     // Power reduction register
     //PRR |= _BV(PRUSART0);
-#endif
 }
 
 int 
 uart_putchar(char c, FILE *stream)
 {
+	if (!uart_enabled)
+	{
+		return EOF;
+	}
     // XXX could perhaps sleep in the loop for power.
     if (c == '\n')
     {
@@ -222,7 +221,7 @@
             crc_out = _crc_ccitt_update(crc_out, '\n');
         }
     }
-    return 0;
+    return (unsigned char)c;
 }
 
 static void
@@ -753,13 +752,6 @@
     need_comms = 1;
     need_measurement = 1;
 
-#if 0
-    for (;;)
-    {
-        do_comms();
-    }
-#endif
-
     for(;;)
     {
         if (need_measurement)
@@ -778,7 +770,6 @@
 
 		deep_sleep();
         blink();
-        printf(".");
     }
 
     return 0;   /* never reached */