Fork and fix for mwork

Dependencies:   mbed-dev-f303 FastPWM3 millis

Revision:
55:fee62d8fd8fb
Child:
58:fb799e99a5f7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/macro.h	Fri Jun 26 01:26:53 2020 +0000
@@ -0,0 +1,39 @@
+#ifndef macro_h
+#define macro_h
+#include "mode.h"
+extern Serial *pc ;
+extern int io_mode;
+#define Serial_printf(A) cond_printf(A)
+// Checks to see if in Serial mode before printing
+void cond_printf(const char *format, ...)
+{    
+    if (io_mode != IO_MODE_SERIAL) {
+        return;
+    }
+    /*if (io_mode == IO_MODE_STEP_DIR) {
+        pc->printf( "thoat");
+        return;
+    }
+    */
+    char loc_buf[64];
+    char * temp = loc_buf;
+    va_list arg;
+    va_list copy;
+    va_start(arg, format);
+    va_copy(copy, arg);
+    size_t len = vsnprintf(NULL, 0, format, arg);
+    va_end(copy);
+    if(len >= sizeof(loc_buf)){
+        temp = new char[len+1];
+        if(temp == NULL) {
+            return;
+        }
+    }
+    len = vsnprintf(temp, len+1, format, arg);
+    pc->printf( temp);
+    va_end(arg);
+    if(len > 64){
+        delete[] temp;
+    }    
+}
+#endif
\ No newline at end of file