supla-device
Loading...
Searching...
No Matches
bistable_relay.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 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15*/
16
17/* BistableRelay
18 * This class can be used to controll bistable relay.
19 * Supla device will send short impulses (<0.5 s) on GPIO to toggle bistable
20 * relay state.
21 * Device does not have knowledge about the status of bistable relay, so it
22 * has to be read on a different GPIO (statusPin)
23 * This class can work without statusPin information, but Supla will lose
24 * information about status of bistable relay.
25 */
26
27#ifndef SRC_SUPLA_CONTROL_BISTABLE_RELAY_H_
28#define SRC_SUPLA_CONTROL_BISTABLE_RELAY_H_
29
30#include <supla-common/proto.h>
31#include <stdint.h>
32#include "relay.h"
33
34namespace Supla {
35namespace Io {
36class Base;
37}
38
39namespace Control {
40class BistableRelay : public Relay {
41 public:
56 BistableRelay(int pin,
57 int statusPin = -1,
58 bool statusPullUp = true,
59 bool statusHighIsOn = true,
60 bool highIsOn = true,
61 _supla_int_t functions =
62 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
63
77 int pin,
78 int statusPin = -1,
79 bool statusPullUp = true,
80 bool statusHighIsOn = true,
81 bool highIsOn = true,
82 _supla_int_t functions =
83 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
84
99 Supla::Io::Base *ioState,
100 int pin,
101 int statusPin = -1,
102 bool statusPullUp = true,
103 bool statusHighIsOn = true,
104 bool highIsOn = true,
105 _supla_int_t functions =
106 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
107
108 void onInit() override;
109 void iterateAlways() override;
110 int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override;
111 void turnOn(_supla_int_t duration = 0) override;
112 void turnOff(_supla_int_t duration = 0) override;
113 void toggle(_supla_int_t duration = 0) override;
114
115 bool isOn() override;
116 bool isStatusUnknown();
117
118 protected:
119 void internalToggle();
120
121 Supla::Io::Base *ioState = nullptr;
122
123 uint32_t disarmTimeMs = 0;
124 uint32_t lastReadTime = 0;
125
126 int16_t statusPin = -1;
127 bool statusPullUp = true;
128 bool statusHighIsOn = true;
129 bool busy = false;
130 bool lastCommandTurnOn = false;
131};
132
133}; // namespace Control
134}; // namespace Supla
135
136#endif // SRC_SUPLA_CONTROL_BISTABLE_RELAY_H_
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition bistable_relay.cpp:112
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition bistable_relay.cpp:85
BistableRelay(int pin, int statusPin=-1, bool statusPullUp=true, bool statusHighIsOn=true, bool highIsOn=true, _supla_int_t functions=(0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER))
BistableRelay constructor which works on ESP's GPIO (with defaul Supla::Io)
Definition bistable_relay.cpp:69
int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override
Handles "new value" request from server.
Definition bistable_relay.cpp:137
Definition io.h:35
Definition proto.h:1199