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 void handleAction(int event, int action) override;
109
110 bool isOn() override;
111 bool isStatusUnknown();
112
113 protected:
114 bool canUseWeeklySchedule() const override;
115 bool applyWeeklyScheduleState(bool on) override;
116 void internalToggle();
117
118 uint32_t disarmTimeMs = 0;
119 uint32_t lastReadTime = 0;
120
121 Supla::Io::IoPin statusInputPin;
122 bool busy = false;
123 bool lastCommandTurnOn = false;
124};
125
126}; // namespace Control
127}; // namespace Supla
128
129#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:122
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition bistable_relay.cpp:102
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:72
int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override
Handles "new value" request from server.
Definition bistable_relay.cpp:147
Definition relay.h:45
Definition io.h:23
Definition io_pin.h:14
Definition proto.h:1243