Skip to content

Add lock to I2CDevComuino, PCA9548ACom and SHT85

Matthias Saimpert requested to merge SaclayITk/labRemote:ms_I2CCom_lock into devel

The idea is to be able to read SHT85 connected to a arduino with DevComuino installed with several apps running in parralel.

The difficulty arises from the fact that the TextSerial is a private class member and not directly accessible from the sensor.

Here is my (quite minimal and probably imperfect, but working) solution :

  • I2CDevComuino / PCA9548ACom now heritate from ILockable interface (multiple heritance)

  • new lock/unlock functions allow to lock the TextSerial, which is a private class member otherwise (nesting mechanism)

  • concrete application for SHT85. It requires dynamic_cast since class member is simply I2CCom (and not I2CDevComuino or PCA9548ACom), which does not know about the TextSerial (*)

  • protection added to ScopeLock against null pointers, which may happen from SHT85 now (*)

(*) may not be the most elegant implementation but tested and seems quite robust to me, comments welcome, feel free to refactorize this how you prefer also

Merge request reports