Add lock to I2CDevComuino, PCA9548ACom and SHT85
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 aprivate
class member otherwise (nesting mechanism) -
concrete application for
SHT85
. It requiresdynamic_cast
since class member is simplyI2CCom
(and notI2CDevComuino
orPCA9548ACom
), which does not know about theTextSerial
(*) -
protection added to
ScopeLock
against null pointers, which may happen fromSHT85
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