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 void customPinMode(int channelNumber, uint8_t pin, uint8_t mode);
42 virtual int customDigitalRead(int channelNumber, uint8_t pin);
43 virtual unsigned int customPulseIn(int channelNumber,
44 uint8_t pin,
45 uint8_t value,
46 uint64_t timeoutMicro);
47 virtual void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val);
48 virtual void customAnalogWrite(int channelNumber, uint8_t pin, int val);
49 virtual int customAnalogRead(int channelNumber, uint8_t pin);
50 virtual void customAttachInterrupt(uint8_t pin, void (*func)(void), int mode);
51 virtual void customDetachInterrupt(uint8_t pin);
52 virtual uint8_t customPinToInterrupt(uint8_t pin);
53
54 private:
55 bool useAsSingleton = true;
56};
57
58void pinMode(uint8_t pin, uint8_t mode, Supla::Io::Base *io = Base::ioInstance);
59int digitalRead(uint8_t pin, Supla::Io::Base *io = Base::ioInstance);
60void digitalWrite(uint8_t pin,
61 uint8_t val,
62 Supla::Io::Base *io = Base::ioInstance);
63void analogWrite(uint8_t pin,
64 int value,
65 Supla::Io::Base *io = Base::ioInstance);
66int analogRead(uint8_t pin, Supla::Io::Base *io = Base::ioInstance);
67unsigned int pulseIn(uint8_t pin,
68 uint8_t value,
69 uint64_t timeoutMicro,
70 Supla::Io::Base *io = Base::ioInstance);
71
72void pinMode(int channelNumber,
73 uint8_t pin,
74 uint8_t mode,
75 Supla::Io::Base *io = Base::ioInstance);
76int digitalRead(int channelNumber,
77 uint8_t pin,
78 Supla::Io::Base *io = Base::ioInstance);
79void digitalWrite(int channelNumber,
80 uint8_t pin,
81 uint8_t val,
82 Supla::Io::Base *io = Base::ioInstance);
83void analogWrite(int channelNumber,
84 uint8_t pin,
85 int value,
86 Supla::Io::Base *io = Base::ioInstance);
87int analogRead(int channelNumber,
88 uint8_t pin,
89 Supla::Io::Base *io = Base::ioInstance);
90unsigned int pulseIn(int channelNumber,
91 uint8_t pin,
92 uint8_t value,
93 uint64_t timeoutMicro,
94 Supla::Io::Base *io = Base::ioInstance);
95
96void attachInterrupt(uint8_t pin,
97 void (*func)(void),
98 int mode,
99 Io::Base *io = Base::ioInstance);
100void detachInterrupt(uint8_t pin, Io::Base *io = Base::ioInstance);
101uint8_t pinToInterrupt(uint8_t pin, Io::Base *io = Base::ioInstance);
102} // namespace Io
103}; // namespace Supla
104
105#endif // SRC_SUPLA_IO_H_
Definition io.h:35