supla-device
Loading...
Searching...
No Matches
bistable_relay.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4/* BistableRelay
5 * This class can be used to controll bistable relay.
6 * Supla device will send short impulses (<0.5 s) on GPIO to toggle bistable
7 * relay state.
8 * Device does not have knowledge about the status of bistable relay, so it
9 * has to be read on a different GPIO (statusPin)
10 * This class can work without statusPin information, but Supla will lose
11 * information about status of bistable relay.
12 */
13
14#ifndef SRC_SUPLA_CONTROL_BISTABLE_RELAY_H_
15#define SRC_SUPLA_CONTROL_BISTABLE_RELAY_H_
16
17#include <supla-common/proto.h>
18#include <stdint.h>
19
20#include "../io.h"
21#include "relay.h"
22
23namespace Supla {
24namespace Io {
25struct IoPin;
26}
27
28namespace Control {
29class BistableRelay : public Relay {
30 public:
45 BistableRelay(int pin,
46 int statusPin = -1,
47 bool statusPullUp = true,
48 bool statusHighIsOn = true,
49 bool highIsOn = true,
50 _supla_int_t functions =
51 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
52
54 Supla::Io::IoPin statusPin = {},
55 _supla_int_t functions =
56 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
57
71 int pin,
72 int statusPin = -1,
73 bool statusPullUp = true,
74 bool statusHighIsOn = true,
75 bool highIsOn = true,
76 _supla_int_t functions =
77 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
78
93 Supla::Io::Base *ioState,
94 int pin,
95 int statusPin = -1,
96 bool statusPullUp = true,
97 bool statusHighIsOn = true,
98 bool highIsOn = true,
99 _supla_int_t functions =
100 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
101
102 void onInit() override;
103 void iterateAlways() override;
104 int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override;
105 void turnOn(_supla_int_t duration = 0) override;
106 void turnOff(_supla_int_t duration = 0) override;
107 void toggle(_supla_int_t duration = 0) override;
108
109 bool isOn() override;
110 bool isStatusUnknown();
111
112 protected:
113 void internalToggle();
114
115 uint32_t disarmTimeMs = 0;
116 uint32_t lastReadTime = 0;
117
118 Supla::Io::IoPin statusInputPin;
119 bool busy = false;
120 bool lastCommandTurnOn = false;
121};
122
123}; // namespace Control
124}; // namespace Supla
125
126#endif // SRC_SUPLA_CONTROL_BISTABLE_RELAY_H_
Definition bistable_relay.h:29
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition bistable_relay.cpp:119
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition bistable_relay.cpp:99
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:144
Definition relay.h:38
Definition io.h:23
Definition io_pin.h:14
Definition proto.h:1228