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