supla-device
Loading...
Searching...
No Matches
internal_pin_output.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
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_CONTROL_INTERNAL_PIN_OUTPUT_H_
20#define SRC_SUPLA_CONTROL_INTERNAL_PIN_OUTPUT_H_
21
22#include "../action_handler.h"
23#include "../element.h"
24#include "../local_action.h"
25#include "output_interface.h"
26
27#define STATE_ON_INIT_OFF 0
28#define STATE_ON_INIT_ON 1
29
30namespace Supla {
31
32namespace Io {
33class Base;
34}
35
36namespace Control {
37class InternalPinOutput : public Element,
38 public ActionHandler,
39 public LocalAction,
40 public OutputInterface {
41 public:
42 explicit InternalPinOutput(Supla::Io::Base *io,
43 int pin,
44 bool highIsOn = true);
45 explicit InternalPinOutput(int pin, bool highIsOn = true);
46
47 virtual InternalPinOutput &setDefaultStateOn();
48 virtual InternalPinOutput &setDefaultStateOff();
49 virtual InternalPinOutput &setDurationMs(_supla_int_t duration);
50
51 virtual uint8_t pinOnValue();
52 virtual uint8_t pinOffValue();
53 virtual void turnOn(_supla_int_t duration = 0);
54 virtual void turnOff(_supla_int_t duration = 0);
55 virtual bool isOn();
56 virtual void toggle(_supla_int_t duration = 0);
57
58 void handleAction(int event, int action) override;
59
60 void onInit() override;
61 void iterateAlways() override;
62
63 int getOutputValue() const override;
64 void setOutputValue(int value) override;
65 bool isOnOffOnly() const override;
66
67 protected:
68 int8_t pin = -1;
69 bool highIsOn = true;
70 int8_t lastOutputValue = 0;
71 int8_t stateOnInit = STATE_ON_INIT_OFF;
72 uint32_t durationMs = 0;
73 uint32_t storedTurnOnDurationMs = 0;
74 uint32_t durationTimestamp = 0;
75 Supla::Io::Base *io = nullptr;
76};
77
78}; // namespace Control
79}; // namespace Supla
80
81#endif // SRC_SUPLA_CONTROL_INTERNAL_PIN_OUTPUT_H_
Definition action_handler.h:21
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition internal_pin_output.cpp:108
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition internal_pin_output.cpp:124
Definition output_interface.h:26
Definition io.h:35
Definition local_action.h:52