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.
Revision 0:40d65405e747, committed 2014-11-18
- Comitter:
- matsujirushi
- Date:
- Tue Nov 18 14:43:37 2014 +0000
- Child:
- 1:833745ae8a7e
- Commit message:
- Create MjLineSerial class.
Changed in this revision
| MjLineSerial.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MjLineSerial.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MjLineSerial.cpp Tue Nov 18 14:43:37 2014 +0000
@@ -0,0 +1,43 @@
+#include "MjLineSerial.h"
+#include <cstdarg>
+
+#define STRING_STACK_LIMIT 120
+
+namespace matsujirushi {
+
+MjLineSerial::MjLineSerial(RawSerial *serial)
+{
+ baseSerial = serial;
+}
+
+int MjLineSerial::getc()
+{
+ return baseSerial->getc();
+}
+
+int MjLineSerial::putc(int c)
+{
+ return baseSerial->putc(c);
+}
+
+int MjLineSerial::printf(const char *format, ...)
+{
+ std::va_list arg;
+ va_start(arg, format);
+ int len = vsnprintf(NULL, 0, format, arg);
+ if (len < STRING_STACK_LIMIT) {
+ char temp[STRING_STACK_LIMIT];
+ vsprintf(temp, format, arg);
+ puts(temp);
+ } else {
+ char *temp = new char[len + 1];
+ vsprintf(temp, format, arg);
+ puts(temp);
+ delete[] temp;
+ }
+ va_end(arg);
+ return len;
+}
+
+} // namespace matsujirushi
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MjLineSerial.h Tue Nov 18 14:43:37 2014 +0000
@@ -0,0 +1,23 @@
+#ifndef MJ_LINE_SERIAL_H
+#define MJ_LINE_SERIAL_H
+
+#include "mbed.h"
+
+namespace matsujirushi {
+
+class MjLineSerial
+{
+public:
+ MjLineSerial(RawSerial *serial);
+ int getc();
+ int putc(int c);
+ int printf(const char *format, ...);
+
+private:
+ RawSerial *baseSerial;
+
+};
+
+} // namespace matsujirushi
+
+#endif