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