BrewPi / firmware

Brewing temperature control firmware for the BrewPi Spark (Particle Photon inside)
http://www.brewpi.com
GNU Affero General Public License v3.0
97 stars 55 forks source link

Valve controller and OneWire actuator share underlying DS24xx driver #73

Closed elcojacobs closed 7 years ago

elcojacobs commented 7 years ago

With a DS2413 actuator or DS2408 valve controller, the two actuators share a single driving IC. When writing to this IC, a latch value is written as a single byte, so it affects both actuators. We solved this by reading the state of the latch (from the hardware), changing the bits for the particular valve and writing the new value back.

With this approach, the software did not have a copy of the latch state. Each valve driver was unaware of the state of the other valve, the only interacted directly with the hardware. When writing a valve, the existing action for the other valve on the same board could become lost.

This PR changes the approach to instantiating a DS24xx driver in software, which keeps a copy of the latch state. No need to read it back from the hardware. This driver object is shared by both valves/actuators.

When a valve/actuator is installed, the device list is searched for an existing device that uses the same IC (by address). If one is found, the shared_ptr is copied and both devices will use the same object. When none is found, a new object is instantiated.

I chose to use shared_ptr for the DS24xx ptr, so we don't have to worry about refcounting and destruction ourselves.