Andrew Boyson / log

Dependents:   oldheating gps motorhome heating

Files at this revision

API Documentation at this revision

Comitter:
andrewboyson
Date:
Fri Feb 02 15:51:36 2018 +0000
Parent:
12:19c2d4943124
Child:
14:7fcd0d7d3b28
Commit message:
Baud specified in initialisation routine

Changed in this revision

log.c Show annotated file Show diff for this revision Revisions of this file
log.h Show annotated file Show diff for this revision Revisions of this file
--- 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('-');
--- a/log.h	Thu Jan 11 17:39:18 2018 +0000
+++ b/log.h	Fri Feb 02 15:51:36 2018 +0000
@@ -2,10 +2,11 @@
 #include <time.h>
 #include <stdbool.h>
 
-extern void (*LogTmFunction)(struct tm* ptm);
-extern void LogInit(void);
+extern bool LogUart;
+extern void LogInit(void (*tmFunction)(struct tm* ptm), int baud); //Set baud to 0 if no serial
 extern void LogMain(void);
-extern bool LogUart;
+
+extern void LogClear(void);
 
 extern void LogPush(char c);
 extern int  Log(char* snd);