Fork and fix for mwork

Dependencies:   mbed-dev-f303 FastPWM3 millis

macro.cpp

Committer:
annhandt09
Date:
2020-06-29
Revision:
59:568e7be5232f
Parent:
58:fb799e99a5f7

File content as of revision 59:568e7be5232f:

#include "macro.h"

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;
    }    
}