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