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 <supla/io.h>
23
24#include "../action_handler.h"
25#include "../element.h"
26#include "../local_action.h"
27#include "output_interface.h"
28
29#define STATE_ON_INIT_OFF 0
30#define STATE_ON_INIT_ON 1
31
32namespace Supla {
33
34namespace Io {
35class Base;
36}
37
38namespace Control {
39class InternalPinOutput : public Element,
40 public ActionHandler,
41 public LocalAction,
42 public OutputInterface {
43 public:
44 explicit InternalPinOutput(Supla::Io::IoPin outPin);
45 explicit InternalPinOutput(Supla::Io::IoPin outPin, bool highIsOn);
46 explicit InternalPinOutput(Supla::Io::Base *io,
47 int pin,
48 bool highIsOn = true);
49 explicit InternalPinOutput(int pin, bool highIsOn = true);
50
51 virtual InternalPinOutput &setDefaultStateOn();
52 virtual InternalPinOutput &setDefaultStateOff();
53 virtual InternalPinOutput &setDurationMs(_supla_int_t duration);
54
55 virtual uint8_t pinOnValue();
56 virtual uint8_t pinOffValue();
57 virtual void turnOn(_supla_int_t duration = 0);
58 virtual void turnOff(_supla_int_t duration = 0);
59 virtual bool isOn();
60 virtual void toggle(_supla_int_t duration = 0);
61
62 void handleAction(int event, int action) override;
63
64 void onInit() override;
65 void iterateAlways() override;
66
67 int getOutputValue() const override;
68 void setOutputValue(int value) override;
69 bool isOnOffOnly() const override;
70
71 protected:
72 Supla::Io::IoPin outPin;
73 int8_t lastOutputValue = 0;
74 int8_t stateOnInit = STATE_ON_INIT_OFF;
75 uint32_t durationMs = 0;
76 uint32_t storedTurnOnDurationMs = 0;
77 uint32_t durationTimestamp = 0;
78};
79
80}; // namespace Control
81}; // namespace Supla
82
83#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:119
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition internal_pin_output.cpp:135
Definition output_interface.h:26
Definition io.h:36
Definition local_action.h:52
Definition io_pin.h:28