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