supla-device
Loading...
Searching...
No Matches
valve_base.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_CONTROL_VALVE_BASE_H_
20#define SRC_SUPLA_CONTROL_VALVE_BASE_H_
21
22#include <supla/channel_element.h>
23#include <supla-common/proto.h>
24#include <supla/action_handler.h>
25
26namespace Supla {
27namespace Control {
28
29#pragma pack(push, 1)
30struct ValveConfig {
31 ValveConfig();
32 uint8_t sensorData[20];
33 uint8_t reserved[32] = {};
34};
35#pragma pack(pop)
36
41class ValveBase : public ChannelElement, public ActionHandler {
42 public:
49 explicit ValveBase(bool openClose = true);
50
51 void onInit() override;
52 void iterateAlways() override;
53 void onLoadConfig(SuplaDeviceClass *) override;
54 void onLoadState() override;
55 void onSaveState() override;
56 uint8_t applyChannelConfig(TSD_ChannelConfig *result,
57 bool local = false) override;
58 void fillChannelConfig(void *channelConfig, int *size) override;
59 int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override;
60 void purgeConfig() override;
61
72 void handleAction(int event, int action) override;
73
77 void openValve();
78
82 void closeValve();
83
90 void setValve(uint8_t openLevel);
91
92
98 bool isFloodDetected() const;
99
103 void printConfig() const;
104
110 void saveConfig(bool local = true);
111
119 virtual void setValueOnDevice(uint8_t openLevel);
120
128 virtual uint8_t getValueOpenStateFromDevice();
129
139 bool addSensor(uint8_t channelNumber);
140
149 bool removeSensor(uint8_t channelNumber);
150
161 void setIgnoreManuallyOpenedTimeMs(uint32_t timeMs);
162
163 protected:
164 ValveConfig config = {};
165 uint32_t lastSensorsCheckTimestamp = 0;
166 uint32_t lastUpdateTimestamp = 0;
167 uint32_t lastCmdTimestamp = 0;
168 uint32_t ignoreManuallyOpenedTimeMs = 30000;
169 uint8_t lastOpenLevelState = 0;
170};
171
172}; // namespace Control
173}; // namespace Supla
174
175#endif // SRC_SUPLA_CONTROL_VALVE_BASE_H_
Definition SuplaDevice.h:93
Definition action_handler.h:21
void closeValve()
Close valve.
Definition valve_base.cpp:293
bool isFloodDetected() const
Check all sensors and return true if flood is detected.
Definition valve_base.cpp:85
bool removeSensor(uint8_t channelNumber)
Remove sensor from the channel's configuration.
Definition valve_base.cpp:391
void printConfig() const
Print current configuration in logs (for debug purpose)
Definition valve_base.cpp:160
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition valve_base.cpp:51
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition valve_base.cpp:135
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition valve_base.cpp:169
virtual uint8_t getValueOpenStateFromDevice()
Get value from device or any other interface.
Definition valve_base.cpp:413
bool addSensor(uint8_t channelNumber)
Add sensor to the channel's configuration.
Definition valve_base.cpp:348
void setIgnoreManuallyOpenedTimeMs(uint32_t timeMs)
Set ignore manually opened time in milliseconds.
Definition valve_base.cpp:426
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition valve_base.cpp:196
void setValve(uint8_t openLevel)
Set valve.
Definition valve_base.cpp:301
void handleAction(int event, int action) override
Implementation of ActionHandler::handleAction.
Definition valve_base.cpp:430
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition valve_base.cpp:150
void saveConfig(bool local=true)
Save current configuration to Config.
Definition valve_base.cpp:320
int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override
Handles "new value" request from server.
Definition valve_base.cpp:112
void openValve()
Open valve.
Definition valve_base.cpp:297
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition valve_base.cpp:47
ValveBase(bool openClose=true)
Constructor.
Definition valve_base.cpp:35
virtual void setValueOnDevice(uint8_t openLevel)
Set value on device or any other interface.
Definition valve_base.cpp:420
Definition valve_base.h:30
Definition proto.h:2912
Definition proto.h:1167