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 "relay.h"
31
32namespace Supla {
33namespace Control {
34class BistableRelay : public Relay {
35 public:
36 BistableRelay(Supla::Io *io,
37 int pin,
38 int statusPin = -1,
39 bool statusPullUp = true,
40 bool statusHighIsOn = true,
41 bool highIsOn = true,
42 _supla_int_t functions =
43 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
44 BistableRelay(int pin,
45 int statusPin = -1,
46 bool statusPullUp = true,
47 bool statusHighIsOn = true,
48 bool highIsOn = true,
49 _supla_int_t functions =
50 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
51 void onInit() override;
52 void iterateAlways() override;
53 int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override;
54 void turnOn(_supla_int_t duration = 0) override;
55 void turnOff(_supla_int_t duration = 0) override;
56 void toggle(_supla_int_t duration = 0) override;
57
58 bool isOn() override;
59 bool isStatusUnknown();
60
61 protected:
62 void internalToggle();
63
64 uint32_t disarmTimeMs = 0;
65 uint32_t lastReadTime = 0;
66
67 int16_t statusPin = -1;
68 bool statusPullUp = true;
69 bool statusHighIsOn = true;
70 bool busy = false;
71};
72
73}; // namespace Control
74}; // namespace Supla
75
76#endif // SRC_SUPLA_CONTROL_BISTABLE_RELAY_H_
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition bistable_relay.cpp:79
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition bistable_relay.cpp:56
int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override
Handles "new value" request from server.
Definition bistable_relay.cpp:93
Definition io.h:33
Definition proto.h:1167