-
-
Save shevkoplyas/ec218af6a5881ae2f275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int aprintf(char *str, ...) { | |
int i, j, count = 0; | |
va_list argv; | |
va_start(argv, str); | |
for(i = 0, j = 0; str[i] != '\0'; i++) { | |
if (str[i] == '%') { | |
count++; | |
Serial.write(reinterpret_cast<const uint8_t*>(str+j), i-j); | |
switch (str[++i]) { | |
case 'd': Serial.print(va_arg(argv, int)); | |
break; | |
case 'l': Serial.print(va_arg(argv, long)); | |
break; | |
case 'f': Serial.print(va_arg(argv, double)); | |
break; | |
case 'c': Serial.print((char) va_arg(argv, int)); | |
break; | |
case 's': Serial.print(va_arg(argv, char *)); | |
break; | |
case '%': Serial.print("%"); | |
break; | |
default:; | |
}; | |
j = i+1; | |
} | |
}; | |
va_end(argv); | |
if(i > j) { | |
Serial.write(reinterpret_cast<const uint8_t*>(str+j), i-j); | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment