Lydia - Printhead
Loading...
Searching...
No Matches
Relay Class Reference

#include <Relay.h>

Inheritance diagram for Relay:
[legend]

Public Member Functions

short debug ()
 Virtual function to debug the component.
 
short info (short val0, short val1)
 Virtual function to display information about the component.
 
short loop ()
 Virtual function to run the component in a loop.
 
short onRegisterMethods (Bridge *bridge)
 
 Relay (Component *owner, short _pin, short _id, short _addr, short _val=0)
 
short set (int val)
 
short setup ()
 Virtual function to set up the component.
 
- Public Member Functions inherited from Component
void clearFlag (byte flag)
 Clears a specific flag for the component.
 
 Component ()
 Default constructor for the Component class.
 
 Component (String _name)
 Constructor for the Component class with a specified name.
 
 Component (String _name, short _id)
 Constructor for the Component class with a specified name and ID.
 
 Component (String _name, short _id, int _flags)
 Constructor for the Component class with a specified name, ID, and flags.
 
 Component (String _name, short _id, int _flags, Component *_owner)
 Constructor for the Component class with a specified name, ID, flags, and owner.
 
virtual short debug (short val0, short val1)
 Virtual function to debug the component.
 
virtual short destroy ()
 Virtual function to destroy the component.
 
void disable ()
 Disables the component.
 
void enable ()
 Enables the component.
 
bool enabled ()
 Checks if the component is enabled.
 
bool hasFlag (byte flag)
 Checks if the component has a specific flag.
 
virtual short info ()
 Virtual function to display information about the component.
 
virtual short onError (short id, short error)
 
virtual short onMessage (int id, E_CALLS verb, E_MessageFlags flags, const void *user, Component *src)
 Handles incoming messages.
 
virtual short onRawResponse (short size, uint8_t rxBuffer[])
 
virtual short onResponse (short error)
 
void setFlag (byte flag)
 Sets a specific flag for the component.
 
 ~Component ()
 Destructor for the Component class.
 
- Public Member Functions inherited from ModbusGateway
short getAddress ()
 
MB_FC getFunctionCode ()
 
short getNumberAddresses ()
 
virtual String getRegisterDescription (short flags=0)
 
const chargetRegisterMode ()
 
 ModbusGateway ()
 
 ModbusGateway (short _addr)
 
 ModbusGateway (short _addr, short _fc)
 
void setAddress (short _addr)
 
void setFunctionCode (MB_FC fc)
 
void setGateway (Mudbus *mudbus)
 
void setNumberAddresses (short _nbAddr)
 
void setRegisterMode (MB_REGISTER_MODE mode)
 
- Public Member Functions inherited from ModbusValue< bool >
 ModbusValue (int _addr)
 
 ModbusValue (int _addr, int _fc)
 
bool netVal ()
 
void onChange (const bool &value)
 
void onSet (const bool &value)
 

Public Attributes

short pin
 
bool value
 
- Public Attributes inherited from Component
int flags
 The run flags for the component.
 
const short id
 The ID of the component.
 
millis_t last
 The last tick time in milliseconds.
 
String name
 The name of the component.
 
int nFlags
 The network capabilities of the component.
 
millis_t now
 The current time in milliseconds.
 
Componentowner
 The owner of the component.
 
- Public Attributes inherited from ModbusGateway
short addr
 
MB_FC fn
 
uchar lastMQSlot
 
Mudbusmudbus
 
short nbAddr
 
short registerMode
 

Additional Inherited Members

- Static Public Attributes inherited from Component
static const int COMPONENT_DEFAULT = 1 << OBJECT_RUN_FLAGS::E_OF_LOOP | 1 << OBJECT_RUN_FLAGS::E_OF_SETUP
 The default run flags for a component.
 
static const int COMPONENT_NO_ID = 0
 The default ID for a component.
 

Detailed Description

Definition at line 17 of file Relay.h.

Constructor & Destructor Documentation

◆ Relay()

Relay::Relay ( Component * owner,
short _pin,
short _id,
short _addr,
short _val = 0 )
inline

Definition at line 21 of file Relay.h.

28 pin(_pin),
29 value(_val)
30 //registerMode(MB_REGISTER_MODE::E_MB_REGISTER_MODE_READ_WRITE)
31 {
32 //setFlag(OBJECT_RUN_FLAGS::E_OF_DEBUG);
33 SBI(nFlags, OBJECT_NET_CAPS::E_NCAPS_MODBUS);
34 setRegisterMode(MB_REGISTER_MODE::E_MB_REGISTER_MODE_READ_WRITE);
35 }
static const int COMPONENT_DEFAULT
The default run flags for a component.
Definition Component.h:26
Component()
Default constructor for the Component class.
Definition Component.h:36
int nFlags
The network capabilities of the component.
Definition Component.h:206
Component * owner
The owner of the component.
Definition Component.h:211
void setRegisterMode(MB_REGISTER_MODE mode)
Definition ModbusValue.h:85
bool value
Definition Relay.h:107
short pin
Definition Relay.h:106
Definition xtimer.h:21
#define SBI(n, b)
Definition macros.h:153

Member Function Documentation

◆ debug()

short Relay::debug ( )
inlinevirtual

Virtual function to debug the component.

Parameters
streamThe stream to output the debug information to.
Returns
The error code indicating the success or failure of the operation.

Reimplemented from Component.

Definition at line 42 of file Relay.h.

43 {
44 return info(0,0);
45 }
virtual short info()
Virtual function to display information about the component.
Definition Component.h:114

◆ info()

short Relay::info ( short val0,
short val1 )
inlinevirtual

Virtual function to display information about the component.

Parameters
streamThe stream to output the information to.
Returns
The error code indicating the success or failure of the operation.

Reimplemented from Component.

Definition at line 37 of file Relay.h.

38 {
39 Log.verboseln("Relay::info - Pin=%d | Key=%d | Addr=%d | Val=%d | NetVal=%d ", pin, id, addr, value, netVal());
40 return E_OK;
41 }
#define E_OK

◆ loop()

short Relay::loop ( )
inlinevirtual

Virtual function to run the component in a loop.

Returns
The error code indicating the success or failure of the operation.

Reimplemented from Component.

Definition at line 96 of file Relay.h.

97 {
98 bool val = netVal();
99 if (val != value)
100 {
101 set(val);
102 }
103 return E_OK;
104 }
short set(int val)
Definition Relay.h:61

◆ onRegisterMethods()

short Relay::onRegisterMethods ( Bridge * bridge)
inlinevirtual

Registers methods for the component with the specified bridge. This method should be overridden by derived classes to provide custom method registration logic.

Parameters
bridgeThe bridge to register methods with.
Returns
The status code indicating the success or failure of the method registration.

Reimplemented from Component.

Definition at line 87 of file Relay.h.

88 {
89 bridge->registerMemberFunction(id, this, C_STR("set"), (ComponentFnPtr)&Relay::set);
90 bridge->registerMemberFunction(id, this, C_STR("info"), (ComponentFnPtr)&Relay::info);
91 bridge->registerMemberFunction(id, this, C_STR("setFlag"), (ComponentFnPtr)&Relay::setFlag);
92 //bridge->registerMemberFunction(id, this, C_STR("clearFlag"), (ComponentFnPtr)&Relay::clearFlag);
93 return E_OK;
94 }
short(Component::* ComponentFnPtr)(short, short)
Function pointer type for component member functions.
Definition Component.h:268
SComponentInfo * registerMemberFunction(ushort id, Component *clazz, char *method, ComponentFnPtr ptr)
Definition Bridge.cpp:56
void setFlag(byte flag)
Sets a specific flag for the component.
Definition Component.h:149
#define C_STR(s)
Definition macros.h:433

◆ set()

short Relay::set ( int val)
inline

Definition at line 61 of file Relay.h.

62 {
63 value = val;
64#ifdef PLATFORM_PORTENTA_H7_M7
65 if (_value == 1)
66 {
68 Log.verbose(F("Relay:set pin=%d value=%d" CR), pin, _value);
69 }
70 else
71 {
73 Log.verbose(F("Relay:set pin=%d value=%d" CR), pin, _value);
74 }
75#endif
76
77#ifdef PLATFORM_CONTROLLINO_MEGA
78 digitalWrite(pin, val ? HIGH : LOW);
79#endif
80 if (netVal() != value)
81 {
82 onSet(val);
83 }
84 return val;
85 }
void onSet(const bool &value)

◆ setup()

short Relay::setup ( )
inlinevirtual

Virtual function to set up the component.

Returns
The error code indicating the success or failure of the operation.

Reimplemented from Component.

Definition at line 47 of file Relay.h.

48 {
49#ifdef PLATFORM_PORTENTA_H7_M7
50 /*
51 digital_outputs.setLatch();
52 // Uncomment this line to set over current behavior of all
53 // channels to auto retry mode instead of latch mode:
54 // digital_outputs.setRetry();
55 digital_outputs.set(pin, LOW);
56 */
57#endif
58 return E_OK;
59 }

Member Data Documentation

◆ pin

short Relay::pin

Definition at line 106 of file Relay.h.

◆ value

bool Relay::value

Definition at line 107 of file Relay.h.


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