ADISense1000 Version 2.1 code base

Fork of AdiSense1000_V21 by Sean Wilson

Branch:
v2.0
Revision:
29:57edca10d78c
Parent:
27:567abf893938
--- a/src/mbed/adi_sense_log.cpp	Mon Mar 26 20:28:05 2018 +0100
+++ b/src/mbed/adi_sense_log.cpp	Tue May 22 13:45:24 2018 +0100
@@ -44,16 +44,9 @@
 #include <mbed.h>
 #include "inc/adi_sense_log.h"
 
-#define ADI_SENSE_LOG_UART_BAUDRATE (115200)
+static Serial *gpUartDevice;
 
-#ifdef TARGET_STM32F411xE
-#define ADI_SENSE_LOG_UART_TX_PIN   (PA_11)
-#define ADI_SENSE_LOG_UART_RX_PIN   (PA_12)
-#else
-#error "unsupported target platform"
-#endif
-
-static Serial *gpUartDevice;
+static ADI_SENSE_LOG_LEVEL gLogLevel = ADI_SENSE_LOG_LEVEL_DEBUG;
 
 #ifdef __cplusplus
 extern "C" {
@@ -62,11 +55,15 @@
 /*
  * Open the Log interface and allocate resources
  */
-ADI_SENSE_RESULT adi_sense_LogOpen(void)
+ADI_SENSE_RESULT adi_sense_LogOpen(
+    ADI_SENSE_PLATFORM_LOG_CONFIG *pConfig)
 {
-    gpUartDevice = new Serial(ADI_SENSE_LOG_UART_TX_PIN,
-                              ADI_SENSE_LOG_UART_RX_PIN,
-                              ADI_SENSE_LOG_UART_BAUDRATE);
+    if (pConfig->disableLogs)
+        return ADI_SENSE_SUCCESS;
+
+    gpUartDevice = new Serial((PinName)pConfig->txPin,
+                              (PinName)pConfig->rxPin,
+                               pConfig->baudRate);
     if (!gpUartDevice)
     {
         ADI_SENSE_LOG_ERROR("Failed to allocate memory for Log UART context");
@@ -89,6 +86,14 @@
 }
 
 /*
+ * Set the log level for uart communication
+ */
+void adi_sense_LogLevel(ADI_SENSE_LOG_LEVEL maxLevel)
+{
+    gLogLevel = maxLevel;
+}
+
+/*
  * Print a log message to the platform log interface
  */
 void adi_sense_Log(ADI_SENSE_LOG_LEVEL level, const char* format, ...)
@@ -99,6 +104,9 @@
     if (!gpUartDevice)
         return;
 
+    if (level > gLogLevel)
+        return;
+
     va_start(va_args, format);
     vsnprintf(buffer, sizeof(buffer), format, va_args);
     va_end(va_args);