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
32class Io;
33
34namespace Control {
35class InternalPinOutput : public Element,
36 public ActionHandler,
37 public LocalAction,
38 public OutputInterface {
39 public:
40 explicit InternalPinOutput(Supla::Io *io, int pin, bool highIsOn = true);
41 explicit InternalPinOutput(int pin, bool highIsOn = true);
42
43 virtual InternalPinOutput &setDefaultStateOn();
44 virtual InternalPinOutput &setDefaultStateOff();
45 virtual InternalPinOutput &setDurationMs(_supla_int_t duration);
46
47 virtual uint8_t pinOnValue();
48 virtual uint8_t pinOffValue();
49 virtual void turnOn(_supla_int_t duration = 0);
50 virtual void turnOff(_supla_int_t duration = 0);
51 virtual bool isOn();
52 virtual void toggle(_supla_int_t duration = 0);
53
54 void handleAction(int event, int action) override;
55
56 void onInit() override;
57 void iterateAlways() override;
58
59 int getOutputValue() const override;
60 void setOutputValue(int value) override;
61 bool isOnOffOnly() const override;
62
63 protected:
64 int pin = -1;
65 bool highIsOn = true;
66 int8_t stateOnInit = STATE_ON_INIT_OFF;
67 unsigned _supla_int_t durationMs = 0;
68 unsigned _supla_int_t storedTurnOnDurationMs = 0;
69 uint32_t durationTimestamp = 0;
70 int lastOutputValue = 0;
71 Supla::Io *io = nullptr;
72};
73
74}; // namespace Control
75}; // namespace Supla
76
77#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:33
Definition local_action.h:53