From 08f41415dc37fcd85c39857ce69776f17d1e5439 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 21 Jun 2023 10:43:41 +0200 Subject: [PATCH] format option to write microseconds --- StringFormatter.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/StringFormatter.cpp b/StringFormatter.cpp index f7d9c50..c475ef0 100644 --- a/StringFormatter.cpp +++ b/StringFormatter.cpp @@ -117,6 +117,24 @@ void StringFormatter::send2(Print * stream,const FSH* format, va_list args) { case 'o': stream->print(va_arg(args, int), OCT); break; case 'x': stream->print((unsigned int)va_arg(args, unsigned int), HEX); break; case 'X': stream->print((unsigned long)va_arg(args, unsigned long), HEX); break; + case 'M': + { // this prints a unsigned long microseconds time in readable format + unsigned long time = va_arg(args, long); + if (time >= 2000) { + time = time / 1000; + if (time >= 2000) { + printPadded(stream, time/1000, formatWidth, formatLeft); + stream->print(F("sec")); + } else { + printPadded(stream,time, formatWidth, formatLeft); + stream->print(F("msec")); + } + } else { + printPadded(stream,time, formatWidth, formatLeft); + stream->print(F("usec")); + } + } + break; //case 'f': stream->print(va_arg(args, double), 2); break; //format width prefix case '-':