supla-device
|
Base class for all elements of SuplaDevice. More...
#include <element.h>
Public Member Functions | |
Element * | next () |
Returns next Element from the list. | |
virtual void | onLoadConfig (SuplaDeviceClass *sdc) |
First method called on element in SuplaDevice.begin(). | |
virtual void | purgeConfig () |
Removes all configration data related to the element from Storage::Config. | |
virtual void | onLoadState () |
Second method called on element in SuplaDevice.begin(). | |
virtual void | onInit () |
Third method called on element in SuplaDevice.begin() | |
virtual void | onSaveState () |
Method called periodically during SuplaDevice iteration. | |
virtual void | onRegistered (Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr) |
Method called each time when device successfully registers to Supla server. | |
virtual void | iterateAlways () |
Method called on each SuplaDevice iteration. | |
virtual bool | iterateConnected () |
Method called on each SuplaDevice iteration when device is connected and registered to Supla server or other protocol. | |
virtual bool | iterateConnected (void *ptr) |
deprecated | |
virtual void | onTimer () |
Method called on timer interupt. | |
virtual void | onFastTimer () |
Method called on fast timer interupt. | |
virtual void | onSoftReset () |
Method called when device soft restart is triggered. | |
virtual void | onDeviceConfigChange (uint64_t fieldBit) |
Method called when device config is changed. | |
virtual int32_t | handleNewValueFromServer (TSD_SuplaChannelNewValue *newValue) |
Handles "new value" request from server. | |
virtual void | fillSuplaChannelNewValue (TSD_SuplaChannelNewValue *value) |
Fills TSD_SuplaChannelNewValue based on current state. | |
virtual void | handleGetChannelState (TDSC_ChannelState *channelState) |
Handles "get channel state (i)" request from server. | |
virtual int | handleCalcfgFromServer (TSD_DeviceCalCfgRequest *request) |
Handles CALCFG requests from server. | |
virtual uint8_t | handleChannelConfig (TSD_ChannelConfig *newChannelConfig, bool local=false) |
Handles "set channel config" request from server. | |
virtual uint8_t | handleWeeklySchedule (TSD_ChannelConfig *newWeeklySchedule, bool altSchedule=false, bool local=false) |
Handles "set channel config" with "weekly schedule" type request from server. | |
virtual void | handleSetChannelConfigResult (TSDS_SetChannelConfigResult *result) |
Handles "set channel config" reply from server. | |
virtual void | handleChannelConfigFinished () |
Handles "channel config finished" message from server. | |
int | getChannelNumber () const |
Returns channel number. | |
int | getSecondaryChannelNumber () const |
Returns secondary channel number. | |
virtual bool | isOwnerOfSubDeviceId (int subDeviceId) const |
Returns true if element is owner of subDeviceId. | |
virtual const Channel * | getChannel () const |
Returns pointer to main channel. | |
virtual Channel * | getChannel () |
virtual const Channel * | getSecondaryChannel () const |
Returns pointer to secondary channel. | |
virtual Channel * | getSecondaryChannel () |
virtual void | generateKey (char *output, const char *key) const |
Generates key used for Config. | |
Element & | disableChannelState () |
Disables channel state (i) function. | |
bool | isChannelStateEnabled () const |
Returns true if channel state (i) function is enabled. | |
virtual bool | isAnyUpdatePending () |
Returns true if any update is pending. | |
void | setInitialCaption (const char *caption, bool secondaryChannel=false) |
Sets initial caption. | |
void | setDefaultFunction (int32_t defaultFunction) |
Sets default channel's function. | |
Static Public Member Functions | |
static Element * | begin () |
Returns first Element (based on creation order) | |
static Element * | last () |
Returns last Element (based on creation order) | |
static Element * | getElementByChannelNumber (int channelNumber) |
Returns Element by channel number. | |
static Element * | getOwnerOfSubDeviceId (int subDeviceId) |
Returns Element which owns given subDeviceId. | |
static bool | IsAnyUpdatePending () |
Checks if any element has pending update for remote server. | |
static void | NotifyElementsAboutConfigChange (uint64_t fieldBit) |
Notifies all elements about device config change. | |
static bool | IsInvalidPtrSet () |
When "invalid pointer" is set, previously obtained Element pointer may be invalid. | |
static void | ClearInvalidPtr () |
Clears "invalid pointer" flag. | |
Protected Attributes | |
Element * | nextPtr = nullptr |
Static Protected Attributes | |
static Element * | firstPtr = nullptr |
static bool | invalidatePtr = false |
Base class for all elements of SuplaDevice.
|
static |
Element & Supla::Element::disableChannelState | ( | ) |
Disables channel state (i) function.
|
virtual |
Fills TSD_SuplaChannelNewValue based on current state.
value | pointer to TSD_SuplaChannelNewValue which should be filled |
Reimplemented in Relay, RollerShutterInterface, Supla::Control::Relay, Supla::Control::RGBWBase, and Supla::Control::RollerShutterInterface.
|
virtual |
Generates key used for Config.
Adds "x_" prefix to the key where x is a channel number. Output is written to output buffer and limitted to SUPLA_CONFIG_MAX_KEY_SIZE.
output | output buffer (should be at least SUPLA_CONFIG_MAX_KEY_SIZE) |
key | key |
|
virtual |
Returns pointer to main channel.
Reimplemented in BinaryBase, ElectricityMeter, Supla::ChannelElement, Supla::Control::ActionTrigger, Supla::Sensor::BinaryBase, and Supla::Sensor::ElectricityMeter.
int Supla::Element::getChannelNumber | ( | ) | const |
Returns channel number.
|
static |
|
static |
|
virtual |
Returns pointer to secondary channel.
Reimplemented in Supla::Sensor::ThermHygroPressMeter.
int Supla::Element::getSecondaryChannelNumber | ( | ) | const |
Returns secondary channel number.
|
virtual |
Handles CALCFG requests from server.
request |
Reimplemented in Container, ElectricityMeter, GeneralPurposeMeter, OcrImpulseCounter, RollerShutterInterface, Supla::Control::LightRelay, Supla::Control::RollerShutterInterface, Supla::Sensor::Container, Supla::Sensor::ElectricityMeter, Supla::Sensor::GeneralPurposeMeter, Supla::Sensor::OcrImpulseCounter, Supla::Sensor::VirtualImpulseCounter, and VirtualImpulseCounter.
|
virtual |
Handles "set channel config" request from server.
newChannelConfig | pointer to new channel configuration |
local | true if request is local (issued by device itself), false when requests originates from server. |
Reimplemented in HvacBase, Supla::Control::ActionTrigger, Supla::Control::HvacBase, and Supla::ElementWithChannelActions.
|
virtual |
Handles "channel config finished" message from server.
This message informs device that server finished sending channel config for this element.
Reimplemented in BinaryBase, HvacBase, Supla::Control::HvacBase, Supla::ElementWithChannelActions, and Supla::Sensor::BinaryBase.
|
virtual |
Handles "get channel state (i)" request from server.
channelState | pointer to TDSC_ChannelState which should be filled. channelState is prefilled with network and device info. |
Reimplemented in Supla::Control::LightRelay.
|
virtual |
Handles "new value" request from server.
newValue | pointer to TSD_SuplaChannelNewValue |
Reimplemented in HvacBase, Relay, RollerShutterInterface, Supla::Control::BistableRelay, Supla::Control::HvacBase, Supla::Control::Relay, Supla::Control::RGBWBase, Supla::Control::RollerShutterInterface, Supla::Control::ValveBase, and ValveBase.
|
virtual |
Handles "set channel config" reply from server.
All types of channel config should be handled here (including weekly schedule, default config, etc).
result |
Reimplemented in HvacBase, Supla::Control::HvacBase, and Supla::ElementWithChannelActions.
|
virtual |
Handles "set channel config" with "weekly schedule" type request from server.
newWeeklySchedule | pointer to new weekly schedule |
altSchedule | true if request is for alternative schedule (for cooling) |
local | true if request is local (issued by device itself), false when requests originates from server. |
Reimplemented in HvacBase, and Supla::Control::HvacBase.
|
static |
Checks if any element has pending update for remote server.
This method is usually used by device which supports sleeping. It will call it to check if there is any more update to be send to the server before disconnecting and going to sleep.
|
virtual |
Returns true if any update is pending.
Reimplemented in Supla::ElementWithChannelActions.
bool Supla::Element::isChannelStateEnabled | ( | ) | const |
Returns true if channel state (i) function is enabled.
|
static |
|
virtual |
Returns true if element is owner of subDeviceId.
subDeviceId |
|
virtual |
Method called on each SuplaDevice iteration.
It should provide all actions that have to be executed periodically regardless of network state.
Reimplemented in BinaryBase, Container, ElectricityMeter, EnterCfgModeAfterPowerCycle, GeneralPurposeChannelBase, HvacBase, OcrImpulseCounter, Relay, RelayHvacAggregator, RollerShutterInterface, SecondsCounter, Supla::Control::BistableRelay, Supla::Control::HvacBase, Supla::Control::InternalPinOutput, Supla::Control::LightRelay, Supla::Control::PinStatusLed, Supla::Control::Relay, Supla::Control::RelayHvacAggregator, Supla::Control::RGBWBase, Supla::Control::RollerShutterInterface, Supla::Control::ValveBase, Supla::Device::EnterCfgModeAfterPowerCycle, Supla::Device::FactoryTest, Supla::Device::StatusLed, Supla::EspWebServer, Supla::PV::Afore, Supla::PV::Fronius, Supla::PV::SolarEdge, Supla::Sensor::BinaryBase, Supla::Sensor::Container, Supla::Sensor::Distance, Supla::Sensor::DS18B20, Supla::Sensor::ElectricityMeter, Supla::Sensor::GeneralPurposeChannelBase, Supla::Sensor::HX711, Supla::Sensor::NTC10k, Supla::Sensor::OcrImpulseCounter, Supla::Sensor::Pressure, Supla::Sensor::Rain, Supla::Sensor::sds011, Supla::Sensor::SecondsCounter, Supla::Sensor::TemperatureDropSensor, Supla::Sensor::ThermHygroMeter, Supla::Sensor::ThermHygroPressMeter, Supla::Sensor::Thermometer, Supla::Sensor::VirtualImpulseCounter, Supla::Sensor::Weight, Supla::Sensor::Wind, TemperatureDropSensor, Thermometer, ValveBase, VirtualImpulseCounter, and Weight.
|
virtual |
Method called on each SuplaDevice iteration when device is connected and registered to Supla server or other protocol.
Reimplemented in HvacBase, OcrImpulseCounter, Relay, Supla::Clock, Supla::Control::HvacBase, Supla::Control::Relay, Supla::ElementWithChannelActions, Supla::PV::Afore, Supla::PV::Fronius, Supla::PV::SolarEdge, Supla::Sensor::OcrImpulseCounter, and Supla::Sensor::ThermHygroPressMeter.
|
static |
Element * Supla::Element::next | ( | ) |
|
static |
Notifies all elements about device config change.
fieldBit | bit mask of changed field (see SUPLA_DEVICE_CONFIG_FIELD_ in proto.h) |
|
virtual |
Method called when device config is changed.
fieldBit | bit mask of changed field |
Reimplemented in Supla::Clock, and Supla::Device::StatusLed.
|
virtual |
Method called on fast timer interupt.
It should provide all actions that have to be executed periodically regardless of other SuplaDevice activities. It is usually called every 1 ms (or 0.5 ms for Arduino Mega).
Reimplemented in ImpulseCounter, Supla::Control::RGBWBase, and Supla::Sensor::ImpulseCounter.
|
virtual |
Third method called on element in SuplaDevice.begin()
Method called during SuplaDevice initialization. I.e. load initial state, initialize pins etc.
Reimplemented in BlinkingLed, Button, ElectricityMeter, GeneralPurposeChannelBase, GroupButtonControlRgbw, HvacBase, ImpulseCounter, OcrImpulseCounter, Relay, RollerShutterInterface, SimpleButton, Supla::Control::ActionTrigger, Supla::Control::BistableRelay, Supla::Control::BlinkingLed, Supla::Control::Button, Supla::Control::DimmerLeds, Supla::Control::GroupButtonControlRgbw, Supla::Control::HvacBase, Supla::Control::InternalPinOutput, Supla::Control::PinStatusLed, Supla::Control::Relay, Supla::Control::RGBLeds, Supla::Control::RGBWBase, Supla::Control::RGBWLeds, Supla::Control::RollerShutter, Supla::Control::RollerShutterInterface, Supla::Control::SimpleButton, Supla::Control::TrippleButtonRollerShutter, Supla::Control::ValveBase, Supla::Control::VirtualRelay, Supla::Device::FactoryTest, Supla::DS1307RTC, Supla::DS3231RTC, Supla::Sensor::AHT, Supla::Sensor::Bh1750, Supla::Sensor::Binary, Supla::Sensor::BME280, Supla::Sensor::ElectricityMeter, Supla::Sensor::EspFreeHeap, Supla::Sensor::GeneralPurposeChannelBase, Supla::Sensor::HC_SR04, Supla::Sensor::HX711, Supla::Sensor::ImpulseCounter, Supla::Sensor::Max44009, Supla::Sensor::NTC10k, Supla::Sensor::OcrImpulseCounter, Supla::Sensor::OnePhaseElectricityMeter, Supla::Sensor::PZEMv2, Supla::Sensor::PZEMv3, Supla::Sensor::SHT3x, Supla::Sensor::Si7021, Supla::Sensor::TemperatureDropSensor, Supla::Sensor::ThermHygroMeter, Supla::Sensor::Thermometer, Supla::Sensor::ThreePhasePZEMv3, Supla::Sensor::ThreePhasePZEMv3_ADDR, Supla::Sensor::VirtualBinary, Supla::Sensor::VirtualImpulseCounter, TemperatureDropSensor, Thermometer, ValveBase, and VirtualImpulseCounter.
|
virtual |
First method called on element in SuplaDevice.begin().
Called only if Config Storage class is configured. Element should read its configration in this method.
sdc |
Reimplemented in BinaryBase, Button, Container, ElectricityMeter, EnterCfgModeAfterPowerCycle, GeneralPurposeChannelBase, GeneralPurposeMeter, GroupButtonControlRgbw, HvacBase, OcrImpulseCounter, Relay, RollerShutterInterface, Supla::Clock, Supla::Control::ActionTrigger, Supla::Control::Button, Supla::Control::GroupButtonControlRgbw, Supla::Control::HvacBase, Supla::Control::Relay, Supla::Control::RGBWBase, Supla::Control::RollerShutterInterface, Supla::Control::ValveBase, Supla::Device::EnterCfgModeAfterPowerCycle, Supla::Device::StatusLed, Supla::Sensor::BinaryBase, Supla::Sensor::Container, Supla::Sensor::ElectricityMeter, Supla::Sensor::GeneralPurposeChannelBase, Supla::Sensor::GeneralPurposeMeter, Supla::Sensor::OcrImpulseCounter, Supla::Sensor::ThermHygroMeter, and ValveBase.
|
virtual |
Second method called on element in SuplaDevice.begin().
Method called during state Storage initialization (i.e. read from EEPROM, FRAM). Called only if Storage class is configured.
Reimplemented in GeneralPurposeMeter, HvacBase, OcrImpulseCounter, Relay, RollerShutterInterface, Supla::Control::ActionTrigger, Supla::Control::DimmerBase, Supla::Control::HvacBase, Supla::Control::LightRelay, Supla::Control::Relay, Supla::Control::RGBBase, Supla::Control::RGBWBase, Supla::Control::RollerShutterInterface, Supla::Control::ValveBase, Supla::Sensor::GeneralPurposeMeter, Supla::Sensor::HX711, Supla::Sensor::OcrImpulseCounter, Supla::Sensor::VirtualBinary, Supla::Sensor::VirtualImpulseCounter, ValveBase, and VirtualImpulseCounter.
|
virtual |
Method called each time when device successfully registers to Supla server.
suplaSrpc |
Reimplemented in BinaryBase, ElectricityMeter, HvacBase, Notification, Relay, Supla::Control::ActionTrigger, Supla::Control::HvacBase, Supla::Control::Relay, Supla::ElementWithChannelActions, Supla::Notification, Supla::Sensor::BinaryBase, and Supla::Sensor::ElectricityMeter.
|
virtual |
Method called periodically during SuplaDevice iteration.
It should provide state saving for this elemnet to Storage
Reimplemented in GeneralPurposeMeter, HvacBase, OcrImpulseCounter, Relay, RollerShutterInterface, Supla::Control::ActionTrigger, Supla::Control::DimmerBase, Supla::Control::HvacBase, Supla::Control::LightRelay, Supla::Control::Relay, Supla::Control::RGBBase, Supla::Control::RGBWBase, Supla::Control::RollerShutterInterface, Supla::Control::ValveBase, Supla::Sensor::GeneralPurposeMeter, Supla::Sensor::HX711, Supla::Sensor::OcrImpulseCounter, Supla::Sensor::VirtualBinary, Supla::Sensor::VirtualImpulseCounter, ValveBase, and VirtualImpulseCounter.
|
virtual |
Method called on timer interupt.
It should provide all actions that have to be executed periodically regardless of other SuplaDevice activities. It is usually called every 10 ms.
Reimplemented in BlinkingLed, Button, SimpleButton, Supla::Clock, Supla::Control::BistableRollerShutter, Supla::Control::BlinkingLed, Supla::Control::Button, Supla::Control::PinStatusLed, Supla::Control::RollerShutter, Supla::Control::SequenceButton, and Supla::Control::SimpleButton.
|
virtual |
Removes all configration data related to the element from Storage::Config.
Reimplemented in BinaryBase, ElectricityMeter, HvacBase, RollerShutterInterface, Supla::Control::HvacBase, Supla::Control::RollerShutterInterface, Supla::Control::ValveBase, Supla::ElementWithChannelActions, Supla::Sensor::BinaryBase, Supla::Sensor::ElectricityMeter, Supla::Sensor::ThermHygroMeter, and ValveBase.
void Supla::Element::setDefaultFunction | ( | int32_t | defaultFunction | ) |
Sets default channel's function.
defaultFunction | SUPLA_CHANNELFNC_* see proto.h |
void Supla::Element::setInitialCaption | ( | const char * | caption, |
bool | secondaryChannel = false ) |
Sets initial caption.
Initial caption is used as channel's caption when it is registered on server for the first time.
caption | caption |
secondaryChannel | true if caption is for secondary channel, false otherwise |