DrMemCS / drmem

Full source tree for the DrMem control system
MIT License
3 stars 4 forks source link

Generalize internal `cycle` and `timer` drivers #91

Closed rneswold closed 11 months ago

rneswold commented 11 months ago

The cycle and timer drivers each create 2 devices, one to enable/disable the output and one to reflect the output of their internal state machine. The enable devices are boolean and a false to true transition starts their processing.

The output devices are boolean so, when enabled, the cycle driver generates a true/false/true/false chain until disabled. The timer driver outputs true for a configured length of time.

This issue proposes making the driver more general. The enable devices remain boolean, but the output device can be any supported type. The configuration for these drivers would specify a value sent to the output when it's disabled and a value when enabled. For the cycle driver, this would be an array of values.

So, to keep the same behavior as it is now, configuring the cycle driver for a 1 Hz square wave would use this:

[[driver]]
name = "cycle"
prefix = "demo"
cfg = {millis = 500, disabled = false, enabled = [true, false]}

It means configuring is a little more complicated (not much, though). And, yet, when we add the color type, you'll be able to run a sequence of colors to a LED bulb, for instance:

[[driver]]
name = "cycle"
prefix = "demo"
cfg = {millis = 500, disabled = "#black", enabled = ["#red", "#orange", "#yellow", "#green", "#blue", "#violet"]}

[[logic]]
name = "color-cycle"
inputs = { colors = "demo:output" }
outputs = { bulb = "bulb:color" }
exprs = ["{colors} -> {bulb}"]