mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-16 07:23:07 +01:00
use nonblocking write for serial
This commit is contained in:
@@ -1,25 +1,38 @@
|
||||
#include "GwLog.h"
|
||||
|
||||
GwLog::GwLog(bool logSerial, int level){
|
||||
this->logSerial=logSerial;
|
||||
class DefaultLogWriter: public GwLogWriter{
|
||||
public:
|
||||
virtual ~DefaultLogWriter(){};
|
||||
virtual void write(const char *data){
|
||||
Serial.print(data);
|
||||
}
|
||||
};
|
||||
|
||||
GwLog::GwLog(int level, GwLogWriter *writer){
|
||||
logLevel=level;
|
||||
if (writer == NULL) writer=new DefaultLogWriter();
|
||||
this->writer=writer;
|
||||
}
|
||||
void GwLog::logString(const char *fmt,...){
|
||||
if (! writer) return;
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
vsnprintf(buffer,99,fmt,args);
|
||||
if (logSerial){
|
||||
Serial.print("LOG: ");
|
||||
Serial.println(buffer);
|
||||
}
|
||||
writer->write(prefix.c_str());
|
||||
writer->write(buffer);
|
||||
writer->write("\n");
|
||||
}
|
||||
void GwLog::logDebug(int level,const char *fmt,...){
|
||||
if (level > logLevel) return;
|
||||
if (! writer) return;
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
vsnprintf(buffer,99,fmt,args);
|
||||
if (logSerial){
|
||||
Serial.print("LOG: ");
|
||||
Serial.println(buffer);
|
||||
}
|
||||
writer->write(prefix.c_str());
|
||||
writer->write(buffer);
|
||||
writer->write("\n");
|
||||
}
|
||||
void GwLog::setWriter(GwLogWriter *writer){
|
||||
if (this->writer) delete this->writer;
|
||||
this->writer=writer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user