Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AdiSense1000 by
Diff: src/mbed/adi_sense_log.cpp
- 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);
