sidoh / epaper_templates

Template-oriented driver for e-paper displays
MIT License
256 stars 27 forks source link

Printf formatters (String and Int types) #19

Closed nullstalgia closed 4 years ago

nullstalgia commented 4 years ago

Basically, strftime but printf!

So you can duplicate the value (%s %s %s | %d %d %d)

Write a number in Hex (%X)

Add a prefix/suffic (John: %s!!!)

sidoh commented 4 years ago

Love it! Gonna take a closer look this evening.

nullstalgia commented 4 years ago

I tried to do a float type instead of int, but no matter what number I gave it, it always gave me crap random values. Even using a plain atol() with c_str didn't work. (But it turns out that's how String's toFloat() works. And even that screwed up.)

If you can figure that part out, that would likely be preferred by both of us. :)

sidoh commented 4 years ago

I think printf with floats is disabled by default in the SDK. Adding these build flags is supposed to enable it:

  -Wl,-u,_printf_float,-u,_scanf_float

but it generates a linker error:

/Users/cmullins/.platformio/packages/framework-arduinoespressif32@2.10002.190628/tools/sdk/lib/libc_nano.a(lib_a-nano-vfprintf_float.o):(.literal+0x18): undefined reference to `_printf_common'
/Users/cmullins/.platformio/packages/framework-arduinoespressif32@2.10002.190628/tools/sdk/lib/libc_nano.a(lib_a-nano-vfprintf_float.o): In function `_printf_float':
/Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/nano-vfprintf_float.c:287: undefined reference to `_printf_common'

which I think probably means it isn't implemented in the ESP32 SDK. there's likely a workaround, but nothing springs to mind immediately.

Gonna push a patch to use snprintf instead of sprintf to avoid a potential overflow. Otherwise, think this is ready to go.

Thanks again -- great idea!

nullstalgia commented 4 years ago

Shame with the float thing. Luckily, we can send strings that are preformatted with whatever we need! :)


I didn't know that existed! Good idea.

Merge when ready!

sidoh commented 4 years ago

I'll tag a release with your changes shortly. :)