Controls

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

Control Fundamentals

Controls work similar for both the pi and arduino. The main difference is there are more controls supported on the arduino due to its analog capabilities. This is why the pi does not support the potentiometer control type. All controls require three options to load: type, pin, and name. The type of control determines which control class gets instantiated by the control worker.

All control classes extend from a base control class are intended to be as simple as possible. The main responsibility of a control is to read and parse the current state determining if it should emit an event with changed state.

Control Readings

Controls take readings during each worker 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 redis. Below is the control event that MudPi broadcasts.

Control Event

channel: controls

Data will be an object of all your control reading keyed based on the control name/key that fired the event.

{
    "event": "ControlUpdate",
    "data": {...}
}

Control Types

The three control types button, switch and potentiometer each fire off events 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. To prevent floating numbers from triggering multiple events, the potentiometer control has a change buffer of 3 before it will fire.