Log

Dependents:   oldheating gps motorhome heating

Revision:
13:fb7f40c2e446
Parent:
12:19c2d4943124
Child:
14:7fcd0d7d3b28
--- a/log.c	Thu Jan 11 17:39:18 2018 +0000
+++ b/log.c	Fri Feb 02 15:51:36 2018 +0000
@@ -13,9 +13,10 @@
 static char *pUart; //Initialised in init
 
 static bool enable = true;
-
-bool LogUart = true;
-
+static void (*tmFunction)(struct tm* ptm);
+static bool useUart = false; //This is set during initialisation
+       bool LogUart = true;  //Always start off with the uart running
+       
 static char* incrementPushPullPointer(char* p, char* buffer, int bufferLength)
 {
     p++; //increment the pointer by one
@@ -78,17 +79,24 @@
 {
     enable = value;
 }
-void LogInit()
+void LogClear()
 {
-    Uart0Init();
     pPush = buffer;
     pPull = buffer;
     pUart = buffer;
 }
+void LogInit(void (*tmFunctionParam)(struct tm* ptm), int baud)
+{
+    useUart = baud;
+    if (useUart) Uart0Init(baud);
+    tmFunction = tmFunctionParam;
+    LogClear();
+}
 void LogMain()
 {
-    if (!LogUart)       return;    //Do nothing if uart is not enabled
-    if (pUart == pPush) return;    //Do nothing if all characters have been sent
+    if (!useUart)       return;
+    if (!LogUart)       return;     //Do nothing if uart is not enabled
+    if (pUart == pPush) return;     //Do nothing if all characters have been sent
     int result = Uart0PutC(*pUart); //Attempt to write the character
     if (result == 0) pUart = incrementPushPullPointer(pUart, buffer, BUFFER_LENGTH); //If the character was written to the uart then move to the next
 }
@@ -155,14 +163,13 @@
         LogPush(t + '0'); LogPush(u + '0');
     }
 }
-void (*LogTmFunction)(struct tm* ptm);
 
 static int logTimeOnly()
 {
-    if (!LogTmFunction) return 0;
+    if (!tmFunction) return 0;
     
     struct tm tm;
-    LogTmFunction(&tm);
+    tmFunction(&tm);
     
     pushuint4(tm.tm_year + 1900);
     LogPush('-');