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 STOP_REQUEST -5
30#define RS_DEFAULT_OPERATION_TIMEOUT_MS 60000
31#define RS_MAX_OPERATION_TIME_MS 600000 // Max opening/closing/tilting time
32
33namespace Supla {
34
35namespace Control {
36
37class Button;
38
39enum class Directions : uint8_t { STOP_DIR = 0, DOWN_DIR = 1, UP_DIR = 2 };
40
41#pragma pack(push, 1)
43 uint8_t motorUpsideDown = 1; // 0 - not set/not used, 1 - false, 2 - true
44 uint8_t buttonsUpsideDown = 1; // 0 - not set/not used, 1 - false, 2 - true
45 int8_t timeMargin = -1; // -1 default (device specific), 0 - not set/not used
46 // 1 - no margin,
47 // > 1 - 51% of opening/closing time added on extreme
48 // positions - value should be decremented by 1.
49 uint8_t visualizationType = 0; // 0 - default, other values depends on
50 // Cloud and App support
51};
52
53struct TiltConfig {
54 uint32_t tiltingTime = 0;
55 uint16_t tilt0Angle = 0; // 0 - 180 - degree corresponding to tilt 0
56 uint16_t tilt100Angle = 0; // 0 - 180 - degree corresponding to tilt 100
57 uint8_t tiltControlType =
58 SUPLA_TILT_CONTROL_TYPE_UNKNOWN; // SUPLA_TILT_CONTROL_TYPE_
59
60 void clear();
61};
62#pragma pack(pop)
63
64class RollerShutterInterface : public ChannelElement, public ActionHandler {
65 public:
76 explicit RollerShutterInterface(bool tiltFunctionsEnabled = false);
77
82
84 RollerShutterInterface &operator=(const RollerShutterInterface &) = delete;
85
95 void addTiltFunctions();
96
102 bool isTiltFunctionsSupported() const;
103
109 bool isTiltFunctionEnabled() const;
110
117 bool isTiltConfigured() const;
118
124 bool isTopReached() const;
125
131 bool isBottomReached() const;
132
133 int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override;
134 void handleAction(int event, int action) override;
135 int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override;
136 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
137 bool local = false) override;
138 void fillChannelConfig(void *channelConfig,
139 int *size,
140 uint8_t configType) override;
141
142 // Method is used by external integrations to prepare TSD_SuplaChannelNewValue
143 // value for specific channel type (i.e. to prefill durationMS field when
144 // required)
146
147 virtual void close(); // Sets target position to 100%
148 virtual void open(); // Sets target position to 0%
149 virtual void stop(); // Stop motor
150 virtual void moveUp(); // start opening roller shutter regardless of its
151 // position (keep motor going up)
152 virtual void moveDown(); // starts closing roller shutter regardless of its
153 // position (keep motor going down)
154
155 virtual void setTargetPosition(int newPosition,
156 int newTilt = UNKNOWN_POSITION);
164 void setCurrentPosition(int newPosition, int newTilt = UNKNOWN_POSITION);
165 void setNotCalibrated();
166 // Sets calibration ongoing flag, by setting calibration timeout.
167 // calibrationTime = 1 is used to indicate ongoing calibration for
168 // devices without explicit calibration time setting
169 void setCalibrationOngoing(int calibrationTime = 1);
170 void setCalibrationFinished();
171
177 int getCurrentPosition() const;
178
185 int getCurrentTilt() const;
186
193 int getTargetPosition() const;
194
201 int getTargetTilt() const;
202
208 int getCurrentDirection() const;
209
210 void configComfortUpValue(uint8_t position);
211 void configComfortDownValue(uint8_t position);
212 void configComfortUpTiltValue(uint8_t position);
213 void configComfortDownTiltValue(uint8_t position);
214
215 void onInit() override;
216 void onLoadConfig(SuplaDeviceClass *sdc) override;
217 void saveConfig();
218 void onLoadState() override;
219 void onSaveState() override;
220 void purgeConfig() override;
221 void iterateAlways() override;
222
223 uint32_t getClosingTimeMs() const;
224 uint32_t getOpeningTimeMs() const;
225 uint32_t getTiltingTimeMs() const;
226 uint32_t getTiltControlType() const;
227
228 void attach(Supla::Control::Button *up, Supla::Control::Button *down);
229 void attach(Supla::Control::Button *button, bool upButton, bool asInternal);
230
231 virtual void triggerCalibration();
232 void setCalibrationNeeded();
233 bool isCalibrationRequested() const;
234 bool isCalibrated() const;
235
243 void setRsConfigMotorUpsideDownEnabled(bool enable);
244
252 void setRsConfigButtonsUpsideDownEnabled(bool enable);
253
261 void setRsConfigTimeMarginEnabled(bool enable);
262
269 void setRsConfigMotorUpsideDownValue(uint8_t value);
270
277 void setRsConfigButtonsUpsideDownValue(uint8_t value);
278
287 void setRsConfigTimeMarginValue(int8_t value);
288
289 uint8_t getMotorUpsideDown() const;
290 uint8_t getButtonsUpsideDown() const;
291 int8_t getTimeMargin() const;
292
293 static void setRsStorageSaveDelay(int delayMs);
294
295 virtual bool inMove();
296 virtual bool isCalibrationInProgress() const;
297 void startCalibration(uint32_t timeMs);
298 void stopCalibration();
299 bool isCalibrationFailed() const;
300 bool isCalibrationLost() const;
301 bool isMotorProblem() const;
302
303 bool isFunctionSupported(int32_t channelFunction) const;
304 bool isAutoCalibrationSupported() const;
305
306 void setOpenCloseTime(uint32_t newClosingTimeMs, uint32_t newOpeningTimeMs);
307 void setTiltingTime(uint32_t newTiltingTimeMs, bool local = true);
308 void setTiltControlType(uint8_t newTiltControlType, bool local = true);
309
310 void setCalibrationFailed(bool value);
311 void setCalibrationLost(bool value);
312 void setMotorProblem(bool value);
313
314 protected:
316 Supla::Control::Button *button = nullptr;
317 bool asInternal = true;
318 bool upButton = true;
319 ButtonListElement *next = nullptr;
320 };
321
331 bool upButton, bool asInternal);
332
333
334 bool lastDirectionWasOpen() const;
335 bool lastDirectionWasClose() const;
336
337 // returns true, when opening/closing time is setable from config
338 bool isTimeSettingAvailable() const;
339 bool getCalibrate() const;
340 void setCalibrate(bool value);
341
342 void printConfig() const;
343 uint32_t getTimeMarginValue(uint32_t fullTime) const;
344
345 uint8_t flags = 0;
346
347 uint8_t comfortDownValue = 20;
348 uint8_t comfortUpValue = 80;
349 uint8_t comfortUpTiltValue = 0;
350 uint8_t comfortDownTiltValue = 100;
351
352 Directions currentDirection = Directions::STOP_DIR; // stop, up, down
353 Directions lastDirection = Directions::STOP_DIR;
354
355 int16_t currentPosition =
356 UNKNOWN_POSITION; // 0 - open; 10000 - closed, in 0.01 units
357 int16_t currentTilt =
358 UNKNOWN_POSITION; // 0 - opening position
359 // 10000 - closing position, in 0.01 units
360 int8_t targetPosition = STOP_POSITION; // 0-100
361 int8_t targetTilt = UNKNOWN_POSITION; // 0-100
362 int16_t lastPositionBeforeMovement = UNKNOWN_POSITION; // 0-100
363 int16_t lastTiltBeforeMovement = UNKNOWN_POSITION; // 0-100
364 bool newTargetPositionAvailable = false;
365
366 RollerShutterConfig rsConfig;
367 TiltConfig tiltConfig;
368
369 ButtonListElement *buttonList = nullptr;
370
371 uint32_t closingTimeMs = 0;
372 uint32_t openingTimeMs = 0;
373 // Calibration time may be used also as indication of ongoing calibration,
374 // but without information about calibration lenght. In general:
375 // calibrationTime > 0 means that there is ongoing calibration
376 uint32_t calibrationTime = 0;
377 uint32_t lastUpdateTime = 0;
378
379 static int16_t rsStorageSaveDelay;
380};
381
382} // namespace Control
383} // namespace Supla
384
385
386#endif // SRC_SUPLA_CONTROL_ROLLER_SHUTTER_INTERFACE_H_
RollerShutterInterface(bool tiltFunctionsEnabled=false)
Constructor.
Definition roller_shutter_interface.cpp:78
Definition SuplaDevice.h:162
Definition button.h:34
bool isTiltFunctionsSupported() const
Check if tilt functions are supported.
Definition roller_shutter_interface.cpp:1371
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition roller_shutter_interface.cpp:660
int getTargetTilt() const
Get target tilt position.
Definition roller_shutter_interface.cpp:741
int getCurrentPosition() const
Get current roller shutter position.
Definition roller_shutter_interface.cpp:723
void setRsConfigTimeMarginEnabled(bool enable)
Enable/disable time margin configuration option.
Definition roller_shutter_interface.cpp:1172
void setRsConfigButtonsUpsideDownValue(uint8_t value)
Set buttons upside down value.
Definition roller_shutter_interface.cpp:1234
void setupButtonActions(Supla::Control::Button *button, bool upButton, bool asInternal)
Configure additional buttons for roller shutter.
Definition roller_shutter_interface.cpp:1301
int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override
Handles "new value" request from server.
Definition roller_shutter_interface.cpp:158
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition roller_shutter_interface.cpp:1248
int getCurrentDirection() const
Get current roller shutter movement direction.
Definition roller_shutter_interface.cpp:748
void setRsConfigTimeMarginValue(int8_t value)
Set time margin value.
Definition roller_shutter_interface.cpp:1241
bool isTiltFunctionEnabled() const
Check if tilt function is currently enabled.
Definition roller_shutter_interface.cpp:1376
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition roller_shutter_interface.cpp:138
RollerShutterInterface(bool tiltFunctionsEnabled=false)
Constructor.
Definition roller_shutter_interface.cpp:78
bool isBottomReached() const
Check if bottom position (and tilt if applicable) is reached.
Definition roller_shutter_interface.cpp:1403
bool isTopReached() const
Check if top position (and tilt if applicable) is reached.
Definition roller_shutter_interface.cpp:1394
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition roller_shutter_interface.cpp:705
void setCurrentPosition(int newPosition, int newTilt=UNKNOWN_POSITION)
Set current roller shutter/facade blind position (and tilt) (0 = open; 100 = closed).
Definition roller_shutter_interface.cpp:462
void setRsConfigMotorUpsideDownValue(uint8_t value)
Set motor upside down value.
Definition roller_shutter_interface.cpp:1227
void fillSuplaChannelNewValue(TSD_SuplaChannelNewValue *value) override
Fills TSD_SuplaChannelNewValue based on current state.
Definition roller_shutter_interface.cpp:1200
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition roller_shutter_interface.cpp:604
void onLoadConfig(SuplaDeviceClass *sdc) override
First method called on element in SuplaDevice.begin().
Definition roller_shutter_interface.cpp:978
int getCurrentTilt() const
Get current tilt position.
Definition roller_shutter_interface.cpp:730
void setRsConfigButtonsUpsideDownEnabled(bool enable)
Enable/disable buttons upside down configuration option.
Definition roller_shutter_interface.cpp:1162
void setRsConfigMotorUpsideDownEnabled(bool enable)
Enable/disable motor upside down configuration option.
Definition roller_shutter_interface.cpp:1152
int getTargetPosition() const
Get target roller shutter position.
Definition roller_shutter_interface.cpp:737
void addTiltFunctions()
Add tilt functions (facade blinds, vertical blinds) Changing of tilt functions will breake state stor...
Definition roller_shutter_interface.cpp:1365
virtual ~RollerShutterInterface()
Destructor.
Definition roller_shutter_interface.cpp:93
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition roller_shutter_interface.cpp:807
bool isTiltConfigured() const
Check if tilting is configured (time and control modes are set and isTiltFunctionEnabled is true).
Definition roller_shutter_interface.cpp:1389
Definition roller_shutter_interface.h:315
Definition roller_shutter_interface.h:42
Definition roller_shutter_interface.h:53
Definition proto.h:3116
Definition proto.h:2311
Definition proto.h:1224