diff options
Diffstat (limited to 'stm/printf.c')
-rw-r--r-- | stm/printf.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/stm/printf.c b/stm/printf.c index fa94269257..c0fa82e1b0 100644 --- a/stm/printf.c +++ b/stm/printf.c @@ -206,6 +206,21 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) { case 'P': // ? chrs += pfenv_print_int(pfenv, va_arg(args, int), 0, 16, 'A', flags, width); break; + case 'g': + { + // This is a very hacky approach to printing floats. Micropython + // uses %g when using print, and I just wanted to see somthing + // usable. I expect that this will be replaced with something + // more appropriate. + char dot = '.'; + double d = va_arg(args, double); + int left = (int)d; + int right = (int)((d - (double)(int)d) * 1000000.0); + chrs += pfenv_print_int(pfenv, left, 1, 10, 'a', flags, width); + chrs += pfenv_print_strn(pfenv, &dot, 1, flags, width); + chrs += pfenv_print_int(pfenv, right, 0, 10, 'a', PF_FLAG_ZERO_PAD, 6); + break; + } default: pfenv->print_strn(pfenv->data, fmt, 1); chrs += 1; @@ -220,14 +235,10 @@ void stdout_print_strn(void *data, const char *str, unsigned int len) { // send stdout to USART, USB CDC VCP, and LCD if nothing else bool any = false; - // TODO should have a setting for which USART port to send to -#if 0 // if 0'd out so that we're not calling functions with the wrong arguments - if (usart_is_enabled()) { - usart_tx_strn_cooked(str, len); + if (pyb_usart_global_debug != PYB_USART_NONE) { + usart_tx_strn_cooked(pyb_usart_global_debug, str, len); any = true; } -#endif - if (usb_vcp_is_enabled()) { usb_vcp_send_strn_cooked(str, len); any = true; |