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 {
35class Io;
36
37namespace Control {
38class BistableRelay : public Relay {
39 public:
40 BistableRelay(Supla::Io *io,
41 int pin,
42 int statusPin = -1,
43 bool statusPullUp = true,
44 bool statusHighIsOn = true,
45 bool highIsOn = true,
46 _supla_int_t functions =
47 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
48 BistableRelay(int pin,
49 int statusPin = -1,
50 bool statusPullUp = true,
51 bool statusHighIsOn = true,
52 bool highIsOn = true,
53 _supla_int_t functions =
54 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
55 void onInit() override;
56 void iterateAlways() override;
57 int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override;
58 void turnOn(_supla_int_t duration = 0) override;
59 void turnOff(_supla_int_t duration = 0) override;
60 void toggle(_supla_int_t duration = 0) override;
61
62 bool isOn() override;
63 bool isStatusUnknown();
64
65 protected:
66 void internalToggle();
67
68 uint32_t disarmTimeMs = 0;
69 uint32_t lastReadTime = 0;
70
71 int16_t statusPin = -1;
72 bool statusPullUp = true;
73 bool statusHighIsOn = true;
74 bool busy = false;
75};
76
77}; // namespace Control
78}; // namespace Supla
79
80#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:33
Definition proto.h:1169