LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
inputs.h File Reference

LightHub input system (digital/analog pins, sensors, encoders). More...

#include <aJSON.h>
#include "modules/in_ccs811_hdc1080.h"
#include "itemCmd.h"

Go to the source code of this file.

Classes

union  inStore
 Per-input runtime state, packed into the JSON object's valueint. More...
class  Input
 A single LightHub input (digital/analog pin, sensor, encoder, ...). More...
class  readCache
 Cache of raw pin reads to avoid multiple GPIO/I2C accesses within one poll cycle. More...

Macros

#define IN_ACTIVE_HIGH   2
#define IN_ANALOG   64
#define IN_RE   32
#define IN_I2C   128
#define IN_PUSH_ON   0
#define IN_PUSH_TOGGLE   1
#define IN_DHT22   4
#define IN_CCS811   5
#define IN_HDC1080   6
#define IN_ULTRASONIC   7
#define IN_COUNTER   8
#define IN_UPTIME   16
#define IS_IDLE   0
#define IS_PRESSED   1
#define IS_RELEASED   2
#define IS_LONG   3
#define IS_REPEAT   4
#define IS_WAITPRESS   5
#define IS_PRESSED2   6
#define IS_RELEASED2   7
#define IS_LONG2   8u
#define IS_REPEAT2   9u
#define IS_PRESSED3   10u
#define IS_LONG3   11u
#define IS_REPEAT3   12u
#define IS_WAITRELEASE   13u
#define IS_REQSTATE   0xFF
#define IS_NOP   0xF
#define SAME_STATE_ATTEMPTS   2
 Debounce: number of identical reads / analog samples before a state change.
#define ANALOG_STATE_ATTEMPTS   6
#define ANALOG_NOIZE   1
 Analog noise threshold (ADC steps).
#define CHECK_SENSOR   1
#define CHECK_INPUT   2
#define CHECK_INTERRUPT   3
#define CHECK_ULTRASONIC   4
#define T_LONG   1000
#define T_IDLE   600
#define T_RPT   300
#define T_RPT_PULSE   150
#define T_REPEAT   30000

Variables

aJsonObject * inputs
readCache inCache

Detailed Description

LightHub input system (digital/analog pins, sensors, encoders).

Every physical input (button, switch, analog pin, rotary encoder, DHT22/CCS811/HDC1080 sensor, counter, uptime) is an Input entry of the global inputs JSON object. An input debounces its signal, runs an IS_* state machine and executes the actions configured in the "act" field (commands to items / emit topics). The runtime state of each input is packed into the inStore union stored in the JSON object itself.

Macro Definition Documentation

◆ ANALOG_NOIZE

#define ANALOG_NOIZE   1

Analog noise threshold (ADC steps).

◆ ANALOG_STATE_ATTEMPTS

#define ANALOG_STATE_ATTEMPTS   6

◆ CHECK_INPUT

#define CHECK_INPUT   2

◆ CHECK_INTERRUPT

#define CHECK_INTERRUPT   3

◆ CHECK_SENSOR

#define CHECK_SENSOR   1

Poll causes (see Input::Poll()):

  • CHECK_SENSOR - slow cycle (sensors: DHT22, CCS811, counters, ...)
  • CHECK_INPUT - fast cycle (contacts, analog)
  • CHECK_INTERRUPT - realtime (ISR-driven)
  • CHECK_ULTRASONIC - ultrasonic ping

◆ CHECK_ULTRASONIC

#define CHECK_ULTRASONIC   4

◆ IN_ACTIVE_HIGH

#define IN_ACTIVE_HIGH   2

Input type flags (bitmask, combined with "|"):

  • IN_PUSH_ON (0) - button: ON while pressed, OFF on release (overridden by scmd/rcmd) - default
  • IN_PUSH_TOGGLE (1) - every physical push toggles the logical switch on/off (toggle on leading edge)
  • IN_ACTIVE_HIGH (2) - high level = PUSHED/CLOSED/ON, otherwise low; use INPUT mode instead of INPUT_PULLUP
  • IN_RE (32) - rotary encoder input
  • IN_ANALOG (64) - analog input
  • IN_I2C (128) - pin on an MCP23017 I2C expander

Sensor types (no GPIO edge, polled in the CHECK_SENSOR cycle):

  • IN_DHT22 (4), IN_CCS811 (5), IN_HDC1080 (6), IN_ULTRASONIC (7), IN_COUNTER (8), IN_UPTIME (16).

Examples: 0 - plain button (default), 1 - toggle button, 2 - active-high switch, 64 - analog input, 66 - active-high analog input, 32 (IN_RE) combined with 0/1 - rotary encoder, 128 - I2C expander button.

◆ IN_ANALOG

#define IN_ANALOG   64

◆ IN_CCS811

#define IN_CCS811   5

◆ IN_COUNTER

#define IN_COUNTER   8

◆ IN_DHT22

#define IN_DHT22   4

◆ IN_HDC1080

#define IN_HDC1080   6

◆ IN_I2C

#define IN_I2C   128

◆ IN_PUSH_ON

#define IN_PUSH_ON   0

◆ IN_PUSH_TOGGLE

#define IN_PUSH_TOGGLE   1

◆ IN_RE

#define IN_RE   32

◆ IN_ULTRASONIC

#define IN_ULTRASONIC   7

◆ IN_UPTIME

#define IN_UPTIME   16

◆ IS_IDLE

#define IS_IDLE   0

Input state machine states (IS_*):

  • IS_IDLE - initial state, contact not touched yet
  • IS_PRESSED / IS_RELEASED - moment of press / release (commands fire here)
  • IS_LONG - long press detected (after T_LONG ms)
  • IS_REPEAT - auto-repeat while held (T_RPT period)
  • IS_WAITPRESS / IS_WAITRELEASE - waiting for the edge (delayed state)
  • IS_PRESSED2/3, IS_LONG2/3, IS_REPEAT2/3 - 2nd/3rd contact states (multi-pin inputs)
  • IS_REQSTATE - request: apply the stored reqState on the next poll
  • IS_NOP - no state change

◆ IS_LONG

#define IS_LONG   3

◆ IS_LONG2

#define IS_LONG2   8u

◆ IS_LONG3

#define IS_LONG3   11u

◆ IS_NOP

#define IS_NOP   0xF

◆ IS_PRESSED

#define IS_PRESSED   1

◆ IS_PRESSED2

#define IS_PRESSED2   6

◆ IS_PRESSED3

#define IS_PRESSED3   10u

◆ IS_RELEASED

#define IS_RELEASED   2

◆ IS_RELEASED2

#define IS_RELEASED2   7

◆ IS_REPEAT

#define IS_REPEAT   4

◆ IS_REPEAT2

#define IS_REPEAT2   9u

◆ IS_REPEAT3

#define IS_REPEAT3   12u

◆ IS_REQSTATE

#define IS_REQSTATE   0xFF

◆ IS_WAITPRESS

#define IS_WAITPRESS   5

◆ IS_WAITRELEASE

#define IS_WAITRELEASE   13u

◆ SAME_STATE_ATTEMPTS

#define SAME_STATE_ATTEMPTS   2

Debounce: number of identical reads / analog samples before a state change.

◆ T_IDLE

#define T_IDLE   600

◆ T_LONG

#define T_LONG   1000

Timing parameters (ms): long press, idle, auto-repeat period, repeat pulse, max repeat.

◆ T_REPEAT

#define T_REPEAT   30000

◆ T_RPT

#define T_RPT   300

◆ T_RPT_PULSE

#define T_RPT_PULSE   150

Variable Documentation

◆ inCache

readCache inCache
extern

◆ inputs

aJsonObject* inputs
extern