supla-device
Loading...
Searching...
No Matches
io.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#ifndef SRC_SUPLA_IO_H_
18#define SRC_SUPLA_IO_H_
19
20#include <stdint.h>
21
22#include "definitions.h"
23
24namespace Supla {
25// This class can be used to override digitalRead and digitalWrite methods.
26// If you want to add custom behavior i.e. during read/write from some
27// digital pin, you can inherit from Supla::Io::Base class, implement your
28// own customDigitalRead and customDigitalWrite methods and create instance
29// of this class. It will automatically register and SuplaDevice will use it.
30//
31// Example use: implement some additional logic, when relay state is
32// changed.
33namespace Io {
34
35class Base {
36 public:
37 static Base *ioInstance;
38
39 explicit Base(bool useAsSingleton = true);
40 virtual ~Base();
41 virtual bool isReady() const;
42
43 virtual void customPinMode(int channelNumber, uint8_t pin, uint8_t mode);
44 virtual int customDigitalRead(int channelNumber, uint8_t pin);
45 virtual unsigned int customPulseIn(int channelNumber,
46 uint8_t pin,
47 uint8_t value,
48 uint64_t timeoutMicro);
49 virtual void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val);
50 virtual void customAnalogWrite(int channelNumber, uint8_t pin, int val);
51 virtual int customAnalogRead(int channelNumber, uint8_t pin);
52 virtual void customAttachInterrupt(uint8_t pin, void (*func)(void), int mode);
53 virtual void customDetachInterrupt(uint8_t pin);
54 virtual uint8_t customPinToInterrupt(uint8_t pin);
55
56 private:
57 bool useAsSingleton = true;
58};
59
60void pinMode(uint8_t pin, uint8_t mode, Supla::Io::Base *io = Base::ioInstance);
61int digitalRead(uint8_t pin, Supla::Io::Base *io = Base::ioInstance);
62void digitalWrite(uint8_t pin,
63 uint8_t val,
64 Supla::Io::Base *io = Base::ioInstance);
65void analogWrite(uint8_t pin,
66 int value,
67 Supla::Io::Base *io = Base::ioInstance);
68int analogRead(uint8_t pin, Supla::Io::Base *io = Base::ioInstance);
69unsigned int pulseIn(uint8_t pin,
70 uint8_t value,
71 uint64_t timeoutMicro,
72 Supla::Io::Base *io = Base::ioInstance);
73
74void pinMode(int channelNumber,
75 uint8_t pin,
76 uint8_t mode,
77 Supla::Io::Base *io = Base::ioInstance);
78int digitalRead(int channelNumber,
79 uint8_t pin,
80 Supla::Io::Base *io = Base::ioInstance);
81void digitalWrite(int channelNumber,
82 uint8_t pin,
83 uint8_t val,
84 Supla::Io::Base *io = Base::ioInstance);
85void analogWrite(int channelNumber,
86 uint8_t pin,
87 int value,
88 Supla::Io::Base *io = Base::ioInstance);
89int analogRead(int channelNumber,
90 uint8_t pin,
91 Supla::Io::Base *io = Base::ioInstance);
92unsigned int pulseIn(int channelNumber,
93 uint8_t pin,
94 uint8_t value,
95 uint64_t timeoutMicro,
96 Supla::Io::Base *io = Base::ioInstance);
97
98void attachInterrupt(uint8_t pin,
99 void (*func)(void),
100 int mode,
101 Io::Base *io = Base::ioInstance);
102void detachInterrupt(uint8_t pin, Io::Base *io = Base::ioInstance);
103uint8_t pinToInterrupt(uint8_t pin, Io::Base *io = Base::ioInstance);
104} // namespace Io
105}; // namespace Supla
106
107#endif // SRC_SUPLA_IO_H_
Definition io.h:35