HomePage RecentChanges Teensy Console and Serial

Teensy 3.1 console print with multiple outputs, fprintf style support for formatting and presentation of numbers in a single line and support for program memory strings.

#!C

// Examples

#define VERSION 100
void loop () {
  consolePrint("You can use a string");
  consolePrint(F("Or save memory and keep it in program space"));
  consolePrint(F("Print an integer=%d\n"), VERSION);
  consolePrint(F("The ISO8601 DateTime = %04d-%02d-%02dT%02d%:%02d:%02d\n"), 
    year(), month(), day(),
    hour(), minute(), second()
  );
}

// TODO - Support Floats (currently fprintf does not.

// ----------------------------------------------------------------------
// CONSOLE OUTPUT
void consolePrint(char* out, ...) {
	char printBuffer[BUFFER_SIZE];
	va_list argptr;
	va_start(argptr, out);
	vsnprintf(printBuffer, BUFFER_SIZE, out, argptr);
	va_end(argptr);
	if (! consolePassthrough) {
		Serial.print(printBuffer);    // Example output to two serial ports
		Serial3.print(printBuffer);
	}
}

// Convert FLASH String to String
void consolePrint(const __FlashStringHelper *out, ... ){
	char printBuffer[BUFFER_SIZE];
	va_list argptr;
	va_start(argptr, out);
	vsnprintf(printBuffer, BUFFER_SIZE, (const char *)out, argptr);
	va_end(argptr);
	consolePrint(printBuffer);
}

// Convert STRING to Char
void consolePrint(String& out, ...) {
	char strBuffer[BUFFER_SIZE];
	char printBuffer[BUFFER_SIZE];
	out.toCharArray(strBuffer, BUFFER_SIZE);

	va_list argptr;
	va_start(argptr, out);
	vsnprintf(printBuffer, BUFFER_SIZE, strBuffer, argptr);
	va_end(argptr);

	consolePrint(printBuffer, argptr);
}

Software error:

Can't locate object method "endform" via package "CGI" at /data/scott.dd.com.au/wiki/modules/search.pl line 15.

For help, please send mail to the webmaster (webmaster@dd.com.au), giving this error message and the time and date of the error.