Often times a system needs manual user input. In MudPi this is done through controls. Examples of controls are a button, switch and potentiometer. These range of controls can solve the majority of a systems user input needs.

Control Fundamentals

All control classes extend from a base Control component class. The main responsibility of a control is to read and parse the current state determining if it should emit an event with changed state. Controls are almost like a sensor with higher frequency updates with some added on functionality.

Control State

Controls take readings during each worker update loop. For each loop all the controls loop through and read their current state. If the state has changed since the last reading the data is packaged in a JSON object keyed based on the control key. This data then gets published over the event system.

Control Types

The three control types button, switch and potentiometer each trigger state changes in a different manner. They all will emit an event when their state is changed but the button control will continue to fire while pressed while a switch only fires once. To prevent floating numbers from triggering multiple events, the potentiometer control has a buffer you can configure before it will fire.

Available Interfaces

Below is a list of currently supported interfaces for controls.

exampleChanges state randomly for testingLearn More
gpioControl connected to linux board GPIOLearn More
nanpyA control on a device running NanpyLearn More

If you would like at add support for another control interface read the developer docs and submit a PR!

Control Event

While you can listen to the StateUpdated event for all the controls they also broadcast an event on the control topic as well. This event is broadcast for you to hook into controls and add additional functionality.

Event: ControlUpdated

"event": "ControlUpdated",
"component_id": "example_control_1",
"type": "button",
"name": "Example Control 1",
"updated_at": "2021-03-14 09:34:33",
"state": 1,
"invert_state": 0