supla-device
Loading...
Searching...
No Matches
roller_shutter_interface.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_ROLLER_SHUTTER_INTERFACE_H_
20#define SRC_SUPLA_CONTROL_ROLLER_SHUTTER_INTERFACE_H_
21
22#include "../action_handler.h"
23#include "../channel_element.h"
24
25#define UNKNOWN_POSITION -1
26#define STOP_POSITION -2
27#define MOVE_UP_POSITION -3
28#define MOVE_DOWN_POSITION -4
29#define RS_DEFAULT_OPERATION_TIMEOUT_MS 60000
30
31namespace Supla {
32
33namespace Control {
34
35class Button;
36
37enum class Directions : uint8_t { STOP_DIR = 0, DOWN_DIR = 1, UP_DIR = 2 };
38
39#pragma pack(push, 1)
41 uint8_t motorUpsideDown = 1; // 0 - not set/not used, 1 - false, 2 - true
42 uint8_t buttonsUpsideDown = 1; // 0 - not set/not used, 1 - false, 2 - true
43 int8_t timeMargin = -1; // -1 default (device specific), 0 - not set/not used
44 // 1 - no margin,
45 // > 1 - 51% of opening/closing time added on extreme
46 // positions - value should be decremented by 1.
47 uint8_t visualizationType = 0; // 0 - default, other values depends on
48 // Cloud and App support
49};
50#pragma pack(pop)
51
52class RollerShutterInterface : public ChannelElement, public ActionHandler {
53 public:
54 RollerShutterInterface();
55 virtual ~RollerShutterInterface();
56
57 RollerShutterInterface(const RollerShutterInterface &) = delete;
58 RollerShutterInterface &operator=(const RollerShutterInterface &) = delete;
59
60 int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override;
61 void handleAction(int event, int action) override;
63 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
64 bool local = false) override;
65 void fillChannelConfig(void *channelConfig,
66 int *size,
67 uint8_t configType) override;
68
69 // Method is used by external integrations to prepare TSD_SuplaChannelNewValue
70 // value for specific channel type (i.e. to prefill durationMS field when
71 // required)
73
74 virtual void close(); // Sets target position to 100%
75 virtual void open(); // Sets target position to 0%
76 virtual void stop(); // Stop motor
77 virtual void moveUp(); // start opening roller shutter regardless of its
78 // position (keep motor going up)
79 virtual void moveDown(); // starts closing roller shutter regardless of its
80 // position (keep motor going down)
81
82 virtual void setTargetPosition(int newPosition);
83 void setCurrentPosition(int newPosition);
84 void setNotCalibrated();
85 // Sets calibration ongoing flag, by setting calibration timeout.
86 // calibrationTime = 1 is used to indicate ongoing calibration for
87 // devices without explicit calibration time setting
88 void setCalibrationOngoing(int calibrationTime = 1);
89 void setCalibrationFinished();
90
91 int getCurrentPosition() const;
92 int getTargetPosition() const;
93 // Get current roller shutter movement direction. Returns int value of
94 // enum Supla::Control::Directions
95 int getCurrentDirection() const;
96
97 void configComfortUpValue(uint8_t position);
98 void configComfortDownValue(uint8_t position);
99
100 void onInit() override;
101 void onLoadConfig(SuplaDeviceClass *sdc) override;
102 void saveConfig();
103 void onLoadState() override;
104 void onSaveState() override;
105 void purgeConfig() override;
106 void iterateAlways() override;
107
108 uint32_t getClosingTimeMs() const;
109 uint32_t getOpeningTimeMs() const;
110
111 void attach(Supla::Control::Button *up, Supla::Control::Button *down);
112 void attach(Supla::Control::Button *button, bool upButton, bool asInternal);
113
114 virtual void triggerCalibration();
115 void setCalibrationNeeded();
116 bool isCalibrationRequested() const;
117 bool isCalibrated() const;
118
119 void setRsConfigMotorUpsideDownEnabled(bool enable);
120 void setRsConfigButtonsUpsideDownEnabled(bool enable);
121 void setRsConfigTimeMarginEnabled(bool enable);
122
123 void setRsConfigMotorUpsideDownValue(uint8_t value);
124 void setRsConfigButtonsUpsideDownValue(uint8_t value);
125 void setRsConfigTimeMarginValue(int8_t value);
126
127 uint8_t getMotorUpsideDown() const;
128 uint8_t getButtonsUpsideDown() const;
129 int8_t getTimeMargin() const;
130
131 static void setRsStorageSaveDelay(int delayMs);
132
133 virtual bool inMove();
134 virtual bool isCalibrationInProgress() const;
135 bool isCalibrationFailed() const;
136 bool isCalibrationLost() const;
137 bool isMotorProblem() const;
138
139 bool isFunctionSupported(int32_t channelFunction) const;
140 bool isAutoCalibrationSupported() const;
141
142 void setOpenCloseTime(uint32_t newClosingTimeMs, uint32_t newOpeningTimeMs);
143
144 void setCalibrationFailed(bool value);
145 void setCalibrationLost(bool value);
146 void setMotorProblem(bool value);
147
148 protected:
150 Supla::Control::Button *button = nullptr;
151 bool asInternal = true;
152 bool upButton = true;
153 ButtonListElement *next = nullptr;
154 };
155
165 bool upButton, bool asInternal);
166
167
168 bool lastDirectionWasOpen() const;
169 bool lastDirectionWasClose() const;
170
171 // returns true, when opening/closing time is setable from config
172 bool isTimeSettingAvailable() const;
173 bool getCalibrate() const;
174 void setCalibrate(bool value);
175
176 void printConfig() const;
177 uint32_t getTimeMarginValue(uint32_t fullTime) const;
178
179 uint8_t flags = 0;
180
181 uint8_t comfortDownValue = 20;
182 uint8_t comfortUpValue = 80;
183
184 Directions currentDirection = Directions::STOP_DIR; // stop, up, down
185 Directions lastDirection = Directions::STOP_DIR;
186
187 int8_t currentPosition = UNKNOWN_POSITION; // 0 - closed; 100 - opened
188 int8_t targetPosition = STOP_POSITION; // 0-100
189 int8_t lastPositionBeforeMovement = UNKNOWN_POSITION; // 0-100
190 bool newTargetPositionAvailable = false;
191
192 RollerShutterConfig rsConfig;
193
194 ButtonListElement *buttonList = nullptr;
195
196 uint32_t closingTimeMs = 0;
197 uint32_t openingTimeMs = 0;
198 // Calibration time may be used also as indication of ongoing calibration,
199 // but without information about calibration lenght. In general:
200 // calibrationTime > 0 means that there is ongoing calibration
201 uint32_t calibrationTime = 0;
202 uint32_t lastUpdateTime = 0;
203
204 static int16_t rsStorageSaveDelay;
205};
206
207} // namespace Control
208} // namespace Supla
209
210
211#endif // SRC_SUPLA_CONTROL_ROLLER_SHUTTER_INTERFACE_H_
Definition SuplaDevice.h:96
Definition button.h:30
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition roller_shutter_interface.cpp:463
void setupButtonActions(Supla::Control::Button *button, bool upButton, bool asInternal)
Configure additional buttons for roller shutter.
Definition roller_shutter_interface.cpp:901
int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override
Handles "new value" request from server.
Definition roller_shutter_interface.cpp:127
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition roller_shutter_interface.cpp:851
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition roller_shutter_interface.cpp:107
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition roller_shutter_interface.cpp:482
void fillSuplaChannelNewValue(TSD_SuplaChannelNewValue *value) override
Fills TSD_SuplaChannelNewValue based on current state.
Definition roller_shutter_interface.cpp:803
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition roller_shutter_interface.cpp:427
void onLoadConfig(SuplaDeviceClass *sdc) override
First method called on element in SuplaDevice.begin().
Definition roller_shutter_interface.cpp:648
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition roller_shutter_interface.cpp:550
Definition roller_shutter_interface.h:149
Definition roller_shutter_interface.h:40
Definition proto.h:3025
Definition proto.h:2260
Definition proto.h:1177