orgua / OneWireHub

OneWire slave device emulator
GNU General Public License v3.0
343 stars 86 forks source link

Define timings for known master devices #86

Open eigenein opened 4 years ago

eigenein commented 4 years ago

Hi @orgua,

I can see that quite often people have to tweak the timings for their specific master devices and so had I. If I want to distribute a source code of my project, I'd need to provide a patch and instructions for building the project. This is not really handy and couldn't be easily put under a source control.

What if we used #ifdefs in order to store the timings in one central place? For instance, in OneWireHub_config.h:

#if defined(LIVOLO_C701TM_11)
// Contributed by someone who debugged this particular master.
constexpr timeOW_t ONEWIRE_TIME_RESET_MAX[2]         = {   50000_us, 80_us };
#elif defined(…)
// Another device(s)
…
#else
// Here we have the standard defaults.
constexpr timeOW_t ONEWIRE_TIME_RESET_MAX[2]         = {   960_us, 80_us }; // from ds2413
#endif

It's much easier to set -D while building, some platforms such as PlatformIO allow to put them into a project configuration file (platformio.inibuild_flags), so that an end user won't have to patch anything. Also, they will get reasonable values from someone who already spent time figuring them out.

I'm not experienced in C++, so the implementation may be not so pretty, especially overriding individual timings for different masters, but what do you think overall?