How to handle different configurations in toit / j...
# help
k
I have different controller configurations and want to handle them with same source code. Is there a possibility to enable/disable code parts alla #ifdef in C?
f
If you use
if x
and
x
is a constant then the compiler will optimize it away.
Not the same as an ifdef, but serves the same purpose is some circumstances
k
Thank you for your lightning fast answer.
Unfortunately I get errors with conditional imports.
f
You can just leave the import.
The tree shaker will get rid of it if not used
k
aha, no overhead generated ?
f
Completely removed
k
But how can I switch between different hw configuration files?
f
what's your exact scenario?
k
I have different controllers ESP32 - prototype and ESP32-D1mini. The second one has different gpio, no display, no button, ...
f
Not completely clear what the best approach is. I see some scenarios: - have a different entry file that sets up the constants and then calls a more generic entry-point in a different file. Depending on how this is done, it could still use tree-shaking. - stay generic in code and use assets to figure out which configuration is currently running. In that case the code would be the same for all configurations and therefore no tree-shaking could happen. You could also use the
main
arguments (instead of assets).
k
What are assets ?
Assets is data that can be stored together with a container.
3 Views