Fork and fix for mwork

Dependencies:   mbed-dev-f303 FastPWM3 millis

Committer:
annhandt09
Date:
Fri Jun 26 01:26:53 2020 +0000
Revision:
55:fee62d8fd8fb
Child:
58:fb799e99a5f7
change serial printf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
annhandt09 55:fee62d8fd8fb 1 #ifndef macro_h
annhandt09 55:fee62d8fd8fb 2 #define macro_h
annhandt09 55:fee62d8fd8fb 3 #include "mode.h"
annhandt09 55:fee62d8fd8fb 4 extern Serial *pc ;
annhandt09 55:fee62d8fd8fb 5 extern int io_mode;
annhandt09 55:fee62d8fd8fb 6 #define Serial_printf(A) cond_printf(A)
annhandt09 55:fee62d8fd8fb 7 // Checks to see if in Serial mode before printing
annhandt09 55:fee62d8fd8fb 8 void cond_printf(const char *format, ...)
annhandt09 55:fee62d8fd8fb 9 {
annhandt09 55:fee62d8fd8fb 10 if (io_mode != IO_MODE_SERIAL) {
annhandt09 55:fee62d8fd8fb 11 return;
annhandt09 55:fee62d8fd8fb 12 }
annhandt09 55:fee62d8fd8fb 13 /*if (io_mode == IO_MODE_STEP_DIR) {
annhandt09 55:fee62d8fd8fb 14 pc->printf( "thoat");
annhandt09 55:fee62d8fd8fb 15 return;
annhandt09 55:fee62d8fd8fb 16 }
annhandt09 55:fee62d8fd8fb 17 */
annhandt09 55:fee62d8fd8fb 18 char loc_buf[64];
annhandt09 55:fee62d8fd8fb 19 char * temp = loc_buf;
annhandt09 55:fee62d8fd8fb 20 va_list arg;
annhandt09 55:fee62d8fd8fb 21 va_list copy;
annhandt09 55:fee62d8fd8fb 22 va_start(arg, format);
annhandt09 55:fee62d8fd8fb 23 va_copy(copy, arg);
annhandt09 55:fee62d8fd8fb 24 size_t len = vsnprintf(NULL, 0, format, arg);
annhandt09 55:fee62d8fd8fb 25 va_end(copy);
annhandt09 55:fee62d8fd8fb 26 if(len >= sizeof(loc_buf)){
annhandt09 55:fee62d8fd8fb 27 temp = new char[len+1];
annhandt09 55:fee62d8fd8fb 28 if(temp == NULL) {
annhandt09 55:fee62d8fd8fb 29 return;
annhandt09 55:fee62d8fd8fb 30 }
annhandt09 55:fee62d8fd8fb 31 }
annhandt09 55:fee62d8fd8fb 32 len = vsnprintf(temp, len+1, format, arg);
annhandt09 55:fee62d8fd8fb 33 pc->printf( temp);
annhandt09 55:fee62d8fd8fb 34 va_end(arg);
annhandt09 55:fee62d8fd8fb 35 if(len > 64){
annhandt09 55:fee62d8fd8fb 36 delete[] temp;
annhandt09 55:fee62d8fd8fb 37 }
annhandt09 55:fee62d8fd8fb 38 }
annhandt09 55:fee62d8fd8fb 39 #endif