LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
Input Class Reference

A single LightHub input (digital/analog pin, sensor, encoder, ...). More...

#include <inputs.h>

Public Member Functions

 Input (aJsonObject *obj, aJsonObject *configObj=NULL)
 Create an input from its JSON object.
 Input (char *name)
 Create an input by name from the global inputs object.
boolean isValid ()
void onContactChanged (int newValue)
void onAnalogChanged (itemCmd newValue)
int Poll (short cause)
void setup ()
void stop ()

Static Public Member Functions

static void onCounterChanged (int i)
static void onCounterChanged0 ()
static void onCounterChanged1 ()
static void onCounterChanged2 ()
static void onCounterChanged3 ()
static void onCounterChanged4 ()
static void onCounterChanged5 ()

Public Attributes

aJsonObject * inputObj
 Pointer to the input's JSON object in the global inputs tree.
uint8_t inType
 Input type (IN_* flags).
uint8_t pin
 First pin number.
uint8_t pin2
 Second pin number (rotary encoder, ...).
inStore * store
 Runtime state, packed in the JSON object's valueint.

Protected Member Functions

void Parse (aJsonObject *configObj=NULL)
void contactPoll (short cause)
void analogPoll (short cause)
void dht22Poll ()
void counterPoll ()
void attachInterruptPinIrq (int realPin, int irq)
unsigned long nextPollTime () const
void setNextPollTime (unsigned long pollTime)
void uptimePoll ()
bool publishDataToDomoticz (int, aJsonObject *, const char *format,...)
char * getIdxField ()
bool changeState (uint8_t newState, short cause, aJsonObject *currentInputObject, bool contactState, bool calledOnTimer=false)
void setupRotaryEncoder ()
aJsonObject * getCurrentInput ()
bool setCurrentInput (aJsonObject *obj)
bool setCurrentInput (int n)
bool setCurrentInput (char *name)
bool checkInstructions (aJsonObject *obj)

Detailed Description

A single LightHub input (digital/analog pin, sensor, encoder, ...).

Input reads one physical input, debounces it, runs the IS_* state machine and executes the actions (commands) configured in the "act" field of the input's JSON object. Supported types are defined by the IN_* flags: buttons, switches, analog inputs, rotary encoders, DHT22/CCS811/HDC1080 sensors, hardware counters and uptime.

Constructor & Destructor Documentation

◆ Input() [1/2]

Input::Input ( aJsonObject * obj,
aJsonObject * configObj = NULL )

Create an input from its JSON object.

Parameters
obj- the input object (or a nested "act" sub-object)
configObj- object holding the "T"/"#" fields (defaults to obj)

◆ Input() [2/2]

Input::Input ( char * name)

Create an input by name from the global inputs object.

Member Function Documentation

◆ analogPoll()

void Input::analogPoll ( short cause)
protected

Sample the analog value with noise filtering; fire actions on change.

◆ attachInterruptPinIrq()

void Input::attachInterruptPinIrq ( int realPin,
int irq )
protected

Attach a rising-edge ISR to a counter pin.

◆ changeState()

bool Input::changeState ( uint8_t newState,
short cause,
aJsonObject * currentInputObject,
bool contactState,
bool calledOnTimer = false )
protected

Apply a new IS_* state: debouncing, delayed-state handling and execution of the actions configured for the state.

◆ checkInstructions()

bool Input::checkInstructions ( aJsonObject * obj)
protected

Process the "activate" instruction: switch to another input.

Returns
true if handled.

◆ contactPoll()

void Input::contactPoll ( short cause)
protected

Debounce the contact and advance the IS_* state machine; fire actions on state change.

◆ counterPoll()

void Input::counterPoll ( )
protected

Publish the hardware counter value to the emit topic.

◆ dht22Poll()

void Input::dht22Poll ( )
protected

Read the DHT22 temperature/humidity, execute the temp/hum actions and emit.

◆ getCurrentInput()

aJsonObject * Input::getCurrentInput ( )
protected
Returns
the currently active sub-input object of an "act" group (or the input itself).

◆ getIdxField()

char * Input::getIdxField ( )
protected
Returns
the Domoticz "idx" field of the input, or NULL.

◆ isValid()

boolean Input::isValid ( )
Returns
true if the input was parsed (store != NULL).

◆ nextPollTime()

unsigned long Input::nextPollTime ( ) const
protected
Returns
the timestamp of the next allowed poll for this pin.

◆ onAnalogChanged()

void Input::onAnalogChanged ( itemCmd newValue)

ISR entry for an analog/encoder change carrying the new value.

◆ onContactChanged()

void Input::onContactChanged ( int newValue)

ISR entry: raw digital edge; the state change is applied on the next Poll().

◆ onCounterChanged()

void Input::onCounterChanged ( int i)
inlinestatic

ISR handler: increment a hardware counter value.

◆ onCounterChanged0()

void Input::onCounterChanged0 ( )
static

ISR handlers for counter interrupt numbers 0..5.

◆ onCounterChanged1()

void Input::onCounterChanged1 ( )
static

◆ onCounterChanged2()

void Input::onCounterChanged2 ( )
static

◆ onCounterChanged3()

void Input::onCounterChanged3 ( )
static

◆ onCounterChanged4()

void Input::onCounterChanged4 ( )
static

◆ onCounterChanged5()

void Input::onCounterChanged5 ( )
static

◆ Parse()

void Input::Parse ( aJsonObject * configObj = NULL)
protected

Parse the "T" (type) and "#" (pin / [pin, pin2]) fields of the input object.

◆ Poll()

int Input::Poll ( short cause)

Poll the input by cause: CHECK_INPUT/CHECK_INTERRUPT for contacts, CHECK_SENSOR for sensors, CHECK_ULTRASONIC for ultrasonic.

◆ publishDataToDomoticz()

bool Input::publishDataToDomoticz ( int pollTimeIncrement,
aJsonObject * emit,
const char * format,
... )
protected

Publish a sensor value in the Domoticz JSON format to the emit topic.

◆ setCurrentInput() [1/3]

bool Input::setCurrentInput ( aJsonObject * obj)
protected

Select the active sub-input of an "act" group by object.

Returns
true on success.

◆ setCurrentInput() [2/3]

bool Input::setCurrentInput ( char * name)
protected

Select the active sub-input of an "act" group by name.

Returns
true on success.

◆ setCurrentInput() [3/3]

bool Input::setCurrentInput ( int n)
protected

Select the active sub-input of an "act" group by 1-based index.

Returns
true on success.

◆ setNextPollTime()

void Input::setNextPollTime ( unsigned long pollTime)
protected

Set the timestamp of the next allowed poll for this pin.

◆ setup()

void Input::setup ( )

Initialize pin modes / sensor drivers.

◆ setupRotaryEncoder()

void Input::setupRotaryEncoder ( )
protected

Create the RotaryEncoder instance for an IN_RE input.

◆ stop()

void Input::stop ( )

Release resources (e.g. delete the rotary encoder instance).

◆ uptimePoll()

void Input::uptimePoll ( )
protected

Publish the system uptime (millis) to the emit topic.

Member Data Documentation

◆ inputObj

aJsonObject* Input::inputObj

Pointer to the input's JSON object in the global inputs tree.

◆ inType

uint8_t Input::inType

Input type (IN_* flags).

◆ pin

uint8_t Input::pin

First pin number.

◆ pin2

uint8_t Input::pin2

Second pin number (rotary encoder, ...).

◆ store

inStore* Input::store

Runtime state, packed in the JSON object's valueint.


The documentation for this class was generated from the following files: