#include <yocto_relay.h>
Public Member Functions | |
virtual int | _invokeValueCallback (string value) |
s64 | countdown (void) |
int | delayedPulse (int ms_delay, int ms_duration) |
YDelayedPulse | delayedPulseTimer (void) |
s64 | get_countdown (void) |
YDelayedPulse | get_delayedPulseTimer (void) |
s64 | get_maxTimeOnStateA (void) |
s64 | get_maxTimeOnStateB (void) |
Y_OUTPUT_enum | get_output (void) |
s64 | get_pulseTimer (void) |
Y_STATE_enum | get_state (void) |
Y_STATEATPOWERON_enum | get_stateAtPowerOn (void) |
s64 | maxTimeOnStateA (void) |
s64 | maxTimeOnStateB (void) |
YRelay * | next (void) |
YRelay * | nextRelay (void) |
Y_OUTPUT_enum | output (void) |
int | pulse (int ms_duration) |
s64 | pulseTimer (void) |
virtual int | registerValueCallback (YRelayValueCallback callback) |
int | set_delayedPulseTimer (YDelayedPulse newval) |
int | set_maxTimeOnStateA (s64 newval) |
int | set_maxTimeOnStateB (s64 newval) |
int | set_output (Y_OUTPUT_enum newval) |
int | set_pulseTimer (s64 newval) |
int | set_state (Y_STATE_enum newval) |
int | set_stateAtPowerOn (Y_STATEATPOWERON_enum newval) |
int | setDelayedPulseTimer (YDelayedPulse newval) |
int | setMaxTimeOnStateA (s64 newval) |
int | setMaxTimeOnStateB (s64 newval) |
int | setOutput (Y_OUTPUT_enum newval) |
int | setPulseTimer (s64 newval) |
int | setState (Y_STATE_enum newval) |
int | setStateAtPowerOn (Y_STATEATPOWERON_enum newval) |
Y_STATE_enum | state (void) |
Y_STATEATPOWERON_enum | stateAtPowerOn (void) |
~YRelay () | |
Public Member Functions inherited from YFunction | |
void | _clearDataStreamCache () |
string | _decode_json_string (const string &json) |
string | _download (const string &url) |
YDataStream * | _findDataStream (YDataSet &dataset, const string &def) |
string | _get_json_path (const string &json, const string &path) |
vector< string > | _json_get_array (const string &json) |
string | _json_get_key (const string &json, const string &data) |
string | _json_get_string (const string &json) |
int | _parseEx (yJsonStateMachine &j) |
virtual int | _parserHelper (void) |
string | _parseString (yJsonStateMachine &j) |
string | _request (const string &request) |
string | _requestEx (int tcpchan, const string &request, yapiRequestProgressCallback callback, void *context) |
void | _throw (YRETCODE errType, string errMsg) |
YRETCODE | _upload (const string &path, const string &content) |
YRETCODE | _uploadWithProgress (const string &path, const string &content, yapiRequestProgressCallback callback, void *context) |
string | advertisedValue (void) |
void | clearCache () |
string | describe (void) |
string | errMessage (void) |
string | errorMessage (void) |
YRETCODE | errorType (void) |
YRETCODE | errType (void) |
YFUN_DESCR | functionDescriptor (void) |
string | get_advertisedValue (void) |
string | get_errorMessage (void) |
YRETCODE | get_errorType (void) |
virtual string | get_friendlyName (void) |
YFUN_DESCR | get_functionDescriptor (void) |
string | get_functionId (void) |
string | get_hardwareId (void) |
string | get_hubSerial () |
string | get_logicalName (void) |
YModule * | get_module (void) |
void * | get_userData (void) |
bool | isOnline (void) |
YRETCODE | load (int msValidity) |
virtual string | loadAttribute (string attrName) |
string | logicalName (void) |
YModule * | module (void) |
virtual int | muteValueCallbacks (void) |
YFunction * | next (void) |
YFunction * | nextFunction (void) |
virtual int | registerValueCallback (YFunctionValueCallback callback) |
int | set_advertisedValue (const string &newval) |
int | set_logicalName (const string &newval) |
void | set_userData (void *data) |
int | setAdvertisedValue (const string &newval) |
int | setLogicalName (const string &newval) |
void | setUserData (void *data) |
virtual int | unmuteValueCallbacks (void) |
void * | userData (void) |
virtual | ~YFunction () |
Static Public Member Functions | |
static YRelay * | Find (string func) |
static YRelay * | FindRelay (string func) |
static YRelay * | First (void) |
static YRelay * | FirstRelay (void) |
Static Public Member Functions inherited from YFunction | |
static void | _ClearCache (void) |
static YFunction * | Find (string func) |
static YFunction * | FindFunction (string func) |
static YFunction * | First (void) |
static YFunction * | FirstFunction (void) |
Protected Member Functions | |
virtual int | _parseAttr (YJSONObject *json_val) |
YRelay (const string &func) | |
Protected Member Functions inherited from YFunction | |
YRETCODE | _buildSetRequest (const string &changeattr, const string *changeval, string &request, string &errmsg) |
string | _escapeAttr (const string &changeval) |
YRETCODE | _getDescriptor (YFUN_DESCR &fundescr, string &errMsg) |
YRETCODE | _getDevice (YDevice *&dev, string &errMsg) |
YRETCODE | _load_unsafe (int msValidity) |
YRETCODE | _nextFunction (string &hwId) |
int | _parse (YJSONObject *j) |
YRETCODE | _setAttr (string attrname, string newvalue) |
YFunction (const string &func) | |
Protected Attributes | |
s64 | _countdown |
YDelayedPulse | _delayedPulseTimer |
s64 | _maxTimeOnStateA |
s64 | _maxTimeOnStateB |
Y_OUTPUT_enum | _output |
s64 | _pulseTimer |
Y_STATE_enum | _state |
Y_STATEATPOWERON_enum | _stateAtPowerOn |
YRelayValueCallback | _valueCallbackRelay |
Protected Attributes inherited from YFunction | |
string | _advertisedValue |
u64 | _cacheExpiration |
string | _className |
std::map< string, YDataStream * > | _dataStreams |
string | _func |
YFUN_DESCR | _fundescr |
string | _funId |
string | _hwId |
string | _lastErrorMsg |
YRETCODE | _lastErrorType |
string | _logicalName |
string | _serial |
yCRITICAL_SECTION | _this_cs |
void * | _userData |
YFunctionValueCallback | _valueCallbackFunction |
Friends | |
YRelay * | yFindRelay (const string &func) |
YRelay * | yFirstRelay (void) |
Additional Inherited Members | |
Static Protected Member Functions inherited from YFunction | |
static void | _AddToCache (const string &classname, const string &func, YFunction *obj) |
static YFunction * | _FindFromCache (const string &classname, const string &func) |
static void | _UpdateTimedReportCallbackList (YFunction *func, bool add) |
static void | _UpdateValueCallbackList (YFunction *func, bool add) |
Static Protected Attributes inherited from YFunction | |
static std::map< string, YFunction * > | _cache |
YRelay Class: Relay function interface
The Yoctopuce application programming interface allows you to switch the relay state. This change is not persistent: the relay will automatically return to its idle position whenever power is lost or if the module is restarted. The library can also generate automatically short pulses of determined duration. On devices with two output for each relay (double throw), the two outputs are named A and B, with output A corresponding to the idle position (at power off) and the output B corresponding to the active state. If you prefer the alternate default state, simply switch your cables on the board.
Definition at line 115 of file yocto_relay.h.
|
protected |
Definition at line 51 of file yocto_relay.cpp.
YRelay::~YRelay | ( | ) |
Definition at line 67 of file yocto_relay.cpp.
|
virtual |
Reimplemented from YFunction.
Definition at line 627 of file yocto_relay.cpp.
|
protectedvirtual |
Reimplemented from YFunction.
Definition at line 76 of file yocto_relay.cpp.
|
inline |
Definition at line 364 of file yocto_relay.h.
int YRelay::delayedPulse | ( | int | ms_delay, |
int | ms_duration | ||
) |
Schedules a pulse.
ms_delay | : waiting time before the pulse, in millisecondes |
ms_duration | : pulse duration, in millisecondes |
On failure, throws an exception or returns a negative error code.
Definition at line 511 of file yocto_relay.cpp.
|
inline |
Definition at line 334 of file yocto_relay.h.
|
inlinestatic |
Definition at line 413 of file yocto_relay.h.
|
static |
Retrieves a relay for a given identifier. The identifier can be specified using several formats:
This function does not require that the relay is online at the time it is invoked. The returned object is nevertheless valid. Use the method YRelay.isOnline() to test if the relay is indeed online at a given time. In case of ambiguity when looking for a relay by logical name, no error is notified: the first instance found is returned. The search is performed first by hardware name, then by logical name.
If a call to this object's is_online() method returns FALSE although you are certain that the matching device is plugged, make sure that you did call registerHub() at application initialization time.
func | : a string that uniquely characterizes the relay |
Definition at line 576 of file yocto_relay.cpp.
|
inlinestatic |
Definition at line 437 of file yocto_relay.h.
|
static |
Starts the enumeration of relays currently accessible. Use the method YRelay.nextRelay() to iterate on next relays.
Definition at line 647 of file yocto_relay.cpp.
s64 YRelay::get_countdown | ( | void | ) |
Returns the number of milliseconds remaining before a pulse (delayedPulse() call) When there is no scheduled pulse, returns zero.
On failure, throws an exception or returns Y_COUNTDOWN_INVALID.
Definition at line 527 of file yocto_relay.cpp.
YDelayedPulse YRelay::get_delayedPulseTimer | ( | void | ) |
Definition at line 463 of file yocto_relay.cpp.
s64 YRelay::get_maxTimeOnStateA | ( | void | ) |
Retourne the maximum time (ms) allowed for $THEFUNCTIONS$ to stay in state A before automatically switching back in to B state. Zero means no maximum time.
On failure, throws an exception or returns Y_MAXTIMEONSTATEA_INVALID.
Definition at line 238 of file yocto_relay.cpp.
s64 YRelay::get_maxTimeOnStateB | ( | void | ) |
Retourne the maximum time (ms) allowed for $THEFUNCTIONS$ to stay in state B before automatically switching back in to A state. Zero means no maximum time.
On failure, throws an exception or returns Y_MAXTIMEONSTATEB_INVALID.
Definition at line 294 of file yocto_relay.cpp.
Y_OUTPUT_enum YRelay::get_output | ( | void | ) |
Returns the output state of the relays, when used as a simple switch (single throw).
On failure, throws an exception or returns Y_OUTPUT_INVALID.
Definition at line 350 of file yocto_relay.cpp.
s64 YRelay::get_pulseTimer | ( | void | ) |
Returns the number of milliseconds remaining before the relays is returned to idle position (state A), during a measured pulse generation. When there is no ongoing pulse, returns zero.
On failure, throws an exception or returns Y_PULSETIMER_INVALID.
Definition at line 408 of file yocto_relay.cpp.
Y_STATE_enum YRelay::get_state | ( | void | ) |
Returns the state of the relays (A for the idle position, B for the active position).
On failure, throws an exception or returns Y_STATE_INVALID.
Definition at line 123 of file yocto_relay.cpp.
Y_STATEATPOWERON_enum YRelay::get_stateAtPowerOn | ( | void | ) |
Returns the state of the relays at device startup (A for the idle position, B for the active position, UNCHANGED for no change).
On failure, throws an exception or returns Y_STATEATPOWERON_INVALID.
Definition at line 181 of file yocto_relay.cpp.
|
inline |
Definition at line 230 of file yocto_relay.h.
|
inline |
Definition at line 257 of file yocto_relay.h.
|
inline |
Definition at line 424 of file yocto_relay.h.
YRelay * YRelay::nextRelay | ( | void | ) |
Continues the enumeration of relays started using yFirstRelay().
Definition at line 637 of file yocto_relay.cpp.
|
inline |
Definition at line 284 of file yocto_relay.h.
int YRelay::pulse | ( | int | ms_duration | ) |
Sets the relay to output B (active) for a specified duration, then brings it automatically back to output A (idle state).
ms_duration | : pulse duration, in millisecondes |
On failure, throws an exception or returns a negative error code.
Definition at line 456 of file yocto_relay.cpp.
|
inline |
Definition at line 313 of file yocto_relay.h.
|
virtual |
Registers the callback function that is invoked on every change of advertised value. The callback is invoked only during the execution of ySleep or yHandleEvents. This provides control over the time when the callback is triggered. For good responsiveness, remember to call one of these two functions periodically. To unregister a callback, pass a NULL pointer as argument.
callback | : the callback function to call, or a NULL pointer. The callback function should take two arguments: the function object of which the value has changed, and the character string describing the new advertised value. |
Definition at line 608 of file yocto_relay.cpp.
int YRelay::set_delayedPulseTimer | ( | YDelayedPulse | newval | ) |
Definition at line 485 of file yocto_relay.cpp.
int YRelay::set_maxTimeOnStateA | ( | s64 | newval | ) |
Sets the maximum time (ms) allowed for $THEFUNCTIONS$ to stay in state A before automatically switching back in to B state. Use zero for no maximum time.
newval | : an integer |
On failure, throws an exception or returns a negative error code.
Definition at line 270 of file yocto_relay.cpp.
int YRelay::set_maxTimeOnStateB | ( | s64 | newval | ) |
Sets the maximum time (ms) allowed for $THEFUNCTIONS$ to stay in state B before automatically switching back in to A state. Use zero for no maximum time.
newval | : an integer |
On failure, throws an exception or returns a negative error code.
Definition at line 326 of file yocto_relay.cpp.
int YRelay::set_output | ( | Y_OUTPUT_enum | newval | ) |
Changes the output state of the relays, when used as a simple switch (single throw).
newval | : either Y_OUTPUT_OFF or Y_OUTPUT_ON, according to the output state of the relays, when used as a simple switch (single throw) |
On failure, throws an exception or returns a negative error code.
Definition at line 382 of file yocto_relay.cpp.
int YRelay::set_pulseTimer | ( | s64 | newval | ) |
Definition at line 430 of file yocto_relay.cpp.
int YRelay::set_state | ( | Y_STATE_enum | newval | ) |
Changes the state of the relays (A for the idle position, B for the active position).
newval | : either Y_STATE_A or Y_STATE_B, according to the state of the relays (A for the idle position, B for the active position) |
On failure, throws an exception or returns a negative error code.
Definition at line 155 of file yocto_relay.cpp.
int YRelay::set_stateAtPowerOn | ( | Y_STATEATPOWERON_enum | newval | ) |
Preset the state of the relays at device startup (A for the idle position, B for the active position, UNCHANGED for no modification). Remember to call the matching module saveToFlash() method, otherwise this call will have no effect.
newval | : a value among Y_STATEATPOWERON_UNCHANGED, Y_STATEATPOWERON_A and Y_STATEATPOWERON_B |
On failure, throws an exception or returns a negative error code.
Definition at line 214 of file yocto_relay.cpp.
|
inline |
Definition at line 338 of file yocto_relay.h.
|
inline |
Definition at line 244 of file yocto_relay.h.
|
inline |
Definition at line 271 of file yocto_relay.h.
|
inline |
Definition at line 298 of file yocto_relay.h.
|
inline |
Definition at line 317 of file yocto_relay.h.
|
inline |
Definition at line 187 of file yocto_relay.h.
|
inline |
Definition at line 217 of file yocto_relay.h.
|
inline |
Definition at line 173 of file yocto_relay.h.
|
inline |
Definition at line 202 of file yocto_relay.h.
|
friend |
Retrieves a relay for a given identifier. The identifier can be specified using several formats:
This function does not require that the relay is online at the time it is invoked. The returned object is nevertheless valid. Use the method YRelay.isOnline() to test if the relay is indeed online at a given time. In case of ambiguity when looking for a relay by logical name, no error is notified: the first instance found is returned. The search is performed first by hardware name, then by logical name.
If a call to this object's is_online() method returns FALSE although you are certain that the matching device is plugged, make sure that you did call registerHub() at application initialization time.
func | : a string that uniquely characterizes the relay |
Definition at line 474 of file yocto_relay.h.
|
friend |
Starts the enumeration of relays currently accessible. Use the method YRelay.nextRelay() to iterate on next relays.
Definition at line 485 of file yocto_relay.h.
|
protected |
Definition at line 130 of file yocto_relay.h.
|
protected |
Definition at line 129 of file yocto_relay.h.
|
protected |
Definition at line 125 of file yocto_relay.h.
|
protected |
Definition at line 126 of file yocto_relay.h.
|
protected |
Definition at line 127 of file yocto_relay.h.
|
protected |
Definition at line 128 of file yocto_relay.h.
|
protected |
Definition at line 123 of file yocto_relay.h.
|
protected |
Definition at line 124 of file yocto_relay.h.
|
protected |
Definition at line 131 of file yocto_relay.h.
|
static |
Definition at line 161 of file yocto_relay.h.
|
static |
Definition at line 160 of file yocto_relay.h.
|
static |
Definition at line 154 of file yocto_relay.h.
|
static |
Definition at line 155 of file yocto_relay.h.
|
static |
Definition at line 158 of file yocto_relay.h.
|
static |
Definition at line 156 of file yocto_relay.h.
|
static |
Definition at line 157 of file yocto_relay.h.
|
static |
Definition at line 159 of file yocto_relay.h.
|
static |
Definition at line 147 of file yocto_relay.h.
|
static |
Definition at line 148 of file yocto_relay.h.
|
static |
Definition at line 149 of file yocto_relay.h.
|
static |
Definition at line 151 of file yocto_relay.h.
|
static |
Definition at line 152 of file yocto_relay.h.
|
static |
Definition at line 153 of file yocto_relay.h.
|
static |
Definition at line 150 of file yocto_relay.h.