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

Relay (ON/OFF output) driver (CH_RELAY = 6 / CH_RELAYX = 16). More...

#include <out_relay.h>

Inheritance diagram for out_relay:

Public Member Functions

void link (Item *_item)
 Attach to an item and read its pin/period configuration.
void getConfig ()
 Read pin and pulse period from the item arguments (negative pin = inverted).
void relay (bool state)
 Physically switch the relay and publish the new action state.
int Setup () override
 Initialize the pin (OUTPUT, inactive) and remember the state if the item is active.
int Poll (short cause) override
 For CH_RELAYX: toggle the relay on/off according to the configured period and /set value.
int Stop () override
 Release the pin and mark the driver uninitialized.
int getChanType () override
 Channel type of the driver.
int Ctrl (itemCmd cmd, char *subItem=NULL, bool toExecute=true, bool authorized=false) override
 Handle /set (duration/turn-on) and /cmd (ON/OFF/TOGGLE/XON/XOFF/HALT/REST) commands.
Public Member Functions inherited from abstractOut
 abstractOut ()
virtual int isActive ()
virtual bool isAllowed (itemCmd cmd)
virtual itemCmd getDefaultOnVal ()
virtual int Status () override
virtual void setStatus (uint8_t status) override
Item * getItem ()
Public Member Functions inherited from abstractCh
 abstractCh ()
virtual ~abstractCh ()

Protected Attributes

short pin
bool inverted
uint32_t period
Protected Attributes inherited from abstractOut
Item * item
 Item currently linked to this driver.

Additional Inherited Members

Protected Member Functions inherited from abstractOut
int pubAction (bool state)
Protected Member Functions inherited from abstractCh
int publishTopic (const char *topic, long value, const char *subtopic=NULL)
int publishTopic (const char *topic, float value, const char *subtopic=NULL)
int publishTopic (const char *topic, const char *value, const char *subtopic=NULL, const char *suffix=NULL)

Detailed Description

Relay (ON/OFF output) driver (CH_RELAY = 6 / CH_RELAYX = 16).

Switches a digital output pin. In the simple CH_RELAY form the relay is latched; in the CH_RELAYX form it is a pulse output: after each turn-on the relay stays active for val/255 of the configured period and is switched off by the polling loop.

JSON config (item argument array):

  • CH_RELAY: [6, pin, val, cmd]
  • CH_RELAYX: [16, [pin, period_sec], val, cmd], period in seconds (default 5).

A negative pin number selects an inverted output (active-low).

Commands (/cmd): ON / OFF / TOGGLE / XON / XOFF / HALT / REST, plus a /set percent value which defines the ON duration for CH_RELAYX.

Member Function Documentation

◆ Ctrl()

int out_relay::Ctrl ( itemCmd cmd,
char * subItem = NULL,
bool toExecute = true,
bool authorized = false )
overridevirtual

Handle /set (duration/turn-on) and /cmd (ON/OFF/TOGGLE/XON/XOFF/HALT/REST) commands.

Implements abstractOut.

◆ getChanType()

int out_relay::getChanType ( )
overridevirtual

Channel type of the driver.

Reimplemented from abstractOut.

◆ getConfig()

void out_relay::getConfig ( )

Read pin and pulse period from the item arguments (negative pin = inverted).

◆ link()

void out_relay::link ( Item * _item)
inlinevirtual

Attach to an item and read its pin/period configuration.

Reimplemented from abstractOut.

◆ Poll()

int out_relay::Poll ( short cause)
overridevirtual

For CH_RELAYX: toggle the relay on/off according to the configured period and /set value.

Reimplemented from abstractCh.

◆ relay()

void out_relay::relay ( bool state)

Physically switch the relay and publish the new action state.

◆ Setup()

int out_relay::Setup ( )
overridevirtual

Initialize the pin (OUTPUT, inactive) and remember the state if the item is active.

????

Reimplemented from abstractOut.

◆ Stop()

int out_relay::Stop ( )
overridevirtual

Release the pin and mark the driver uninitialized.

Reimplemented from abstractCh.

Member Data Documentation

◆ inverted

bool out_relay::inverted
protected

◆ period

uint32_t out_relay::period
protected

◆ pin

short out_relay::pin
protected

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