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:
315 RollerShutterInterface(bool tiltFunctionsEnabled,
316 Supla::Channel &externalChannel,
317 ElementMode mode);
318 void loadRollerShutterConfigOnly();
319 void purgeRollerShutterConfigOnly();
320
322 Supla::Control::Button *button = nullptr;
323 bool asInternal = true;
324 bool upButton = true;
325 ButtonListElement *next = nullptr;
326 };
327
337 bool upButton, bool asInternal);
338
339
340 bool lastDirectionWasOpen() const;
341 bool lastDirectionWasClose() const;
342
343 // returns true, when opening/closing time is setable from config
344 bool isTimeSettingAvailable() const;
345 bool getCalibrate() const;
346 void setCalibrate(bool value);
347
348 void printConfig() const;
349 uint32_t getTimeMarginValue(uint32_t fullTime) const;
350
351 uint8_t flags = 0;
352
353 uint8_t comfortDownValue = 20;
354 uint8_t comfortUpValue = 80;
355 uint8_t comfortUpTiltValue = 0;
356 uint8_t comfortDownTiltValue = 100;
357
358 Directions currentDirection = Directions::STOP_DIR; // stop, up, down
359 Directions lastDirection = Directions::STOP_DIR;
360
361 int16_t currentPosition =
362 UNKNOWN_POSITION; // 0 - open; 10000 - closed, in 0.01 units
363 int16_t currentTilt =
364 UNKNOWN_POSITION; // 0 - opening position
365 // 10000 - closing position, in 0.01 units
366 int8_t targetPosition = STOP_POSITION; // 0-100
367 int8_t targetTilt = UNKNOWN_POSITION; // 0-100
368 int16_t lastPositionBeforeMovement = UNKNOWN_POSITION; // 0-100
369 int16_t lastTiltBeforeMovement = UNKNOWN_POSITION; // 0-100
370 bool newTargetPositionAvailable = false;
371
372 RollerShutterConfig rsConfig;
373 TiltConfig tiltConfig;
374
375 ButtonListElement *buttonList = nullptr;
376
377 uint32_t closingTimeMs = 0;
378 uint32_t openingTimeMs = 0;
379 // Calibration time may be used also as indication of ongoing calibration,
380 // but without information about calibration lenght. In general:
381 // calibrationTime > 0 means that there is ongoing calibration
382 uint32_t calibrationTime = 0;
383 uint32_t lastUpdateTime = 0;
384
385 static int16_t rsStorageSaveDelay;
386};
387
388} // namespace Control
389} // namespace Supla
390
391
392#endif // SRC_SUPLA_CONTROL_ROLLER_SHUTTER_INTERFACE_H_
RollerShutterInterface(bool tiltFunctionsEnabled=false)
Constructor.
Definition roller_shutter_interface.cpp:78
Definition SuplaDevice.h:177
Definition channel.h:33
Definition button.h:34
bool isTiltFunctionsSupported() const
Check if tilt functions are supported.
Definition roller_shutter_interface.cpp:1400
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition roller_shutter_interface.cpp:679
int getTargetTilt() const
Get target tilt position.
Definition roller_shutter_interface.cpp:760
int getCurrentPosition() const
Get current roller shutter position.
Definition roller_shutter_interface.cpp:742
void setRsConfigTimeMarginEnabled(bool enable)
Enable/disable time margin configuration option.
Definition roller_shutter_interface.cpp:1197
void setRsConfigButtonsUpsideDownValue(uint8_t value)
Set buttons upside down value.
Definition roller_shutter_interface.cpp:1259
void setupButtonActions(Supla::Control::Button *button, bool upButton, bool asInternal)
Configure additional buttons for roller shutter.
Definition roller_shutter_interface.cpp:1330
int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override
Handles "new value" request from server.
Definition roller_shutter_interface.cpp:177
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition roller_shutter_interface.cpp:1273
int getCurrentDirection() const
Get current roller shutter movement direction.
Definition roller_shutter_interface.cpp:767
void setRsConfigTimeMarginValue(int8_t value)
Set time margin value.
Definition roller_shutter_interface.cpp:1266
bool isTiltFunctionEnabled() const
Check if tilt function is currently enabled.
Definition roller_shutter_interface.cpp:1405
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition roller_shutter_interface.cpp:157
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:1432
bool isTopReached() const
Check if top position (and tilt if applicable) is reached.
Definition roller_shutter_interface.cpp:1423
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition roller_shutter_interface.cpp:724
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:481
void setRsConfigMotorUpsideDownValue(uint8_t value)
Set motor upside down value.
Definition roller_shutter_interface.cpp:1252
void fillSuplaChannelNewValue(TSD_SuplaChannelNewValue *value) override
Fills TSD_SuplaChannelNewValue based on current state.
Definition roller_shutter_interface.cpp:1225
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition roller_shutter_interface.cpp:623
void onLoadConfig(SuplaDeviceClass *sdc) override
First method called on element in SuplaDevice.begin().
Definition roller_shutter_interface.cpp:997
int getCurrentTilt() const
Get current tilt position.
Definition roller_shutter_interface.cpp:749
void setRsConfigButtonsUpsideDownEnabled(bool enable)
Enable/disable buttons upside down configuration option.
Definition roller_shutter_interface.cpp:1187
void setRsConfigMotorUpsideDownEnabled(bool enable)
Enable/disable motor upside down configuration option.
Definition roller_shutter_interface.cpp:1177
int getTargetPosition() const
Get target roller shutter position.
Definition roller_shutter_interface.cpp:756
void addTiltFunctions()
Add tilt functions (facade blinds, vertical blinds) Changing of tilt functions will breake state stor...
Definition roller_shutter_interface.cpp:1394
virtual ~RollerShutterInterface()
Destructor.
Definition roller_shutter_interface.cpp:112
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition roller_shutter_interface.cpp:826
bool isTiltConfigured() const
Check if tilting is configured (time and control modes are set and isTiltFunctionEnabled is true).
Definition roller_shutter_interface.cpp:1418
Definition roller_shutter_interface.h:321
Definition roller_shutter_interface.h:42
Definition roller_shutter_interface.h:53
Definition proto.h:3412
Definition proto.h:2593
Definition proto.h:1227