#How to handle different configurations in toit / jaguar ?
Thread channel in help
kaxori07/11/2023 03:08 PM
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?
floitsch07/11/2023 03:09 PM
If you use if x and x is a constant then the compiler will optimize it away.
floitsch07/11/2023 03:10 PM
Not the same as an ifdef, but serves the same purpose is some circumstances
kaxori07/11/2023 03:11 PM
Thank you for your lightning fast answer.
1
kaxori07/11/2023 03:27 PM
Unfortunately I get errors with conditional imports.
floitsch07/11/2023 03:27 PM
You can just leave the import.
floitsch07/11/2023 03:27 PM
The tree shaker will get rid of it if not used
kaxori07/11/2023 03:28 PM
aha, no overhead generated ?
floitsch07/11/2023 03:28 PM
Completely removed
kaxori07/11/2023 03:32 PM
But how can I switch between different hw configuration files?
floitsch07/11/2023 03:32 PM
what's your exact scenario?
kaxori07/11/2023 03:34 PM
I have different controllers ESP32 - prototype and ESP32-D1mini. The second one has different gpio, no display, no button, ...
floitsch07/11/2023 03:40 PM
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).
Program your microcontrollers in a fast and robust high-level language. - GitHub - toitlang/toit: Program your microcontrollers in a fast and robust high-level language.
floitsch07/11/2023 03:45 PM
Assets is data that can be stored together with a container.