c4ev3/EV3-API

Order of InitEV3 and setallsensormode commands should be unimportant

Closed this issue · 1 comments

abke commented

InitEV3 and setallsensormode must be called in this fixed order.

Sometimes, newbies and students and others do mix both vice versa and got unexpected program results.

There is a strong wish, to init the EV3 from setallsensormode if this is not done before.

Thanks in advance
J. Abke

a3f commented

I changed SetSensorMode and SetAllSensorMode to call InitEV3 if necessary.
I wasn't a fan of that approach though, so I implemented what I have been meaning to do back in 2015...: Automatic initialization of the EV3.

With the changes introduced in a7a0b52, #include <ev3.h> should be enough to have InitEv3() and FreeEv3() be automatically called on startup/teardown, respectively.

Users might still call it manually, but if they had the header included somewhere, it would just be a no-op.

This is still not optimal, but it's what I assume the best one can do in a static library without affecting how the final executable is linked. If someone feels like it, they could change the crt0 in the EV3-Eclipse-Plugin as well, which would be the proper way.