forked from adlerweb/asysbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asb_io_din.h
153 lines (126 loc) · 4.33 KB
/
asb_io_din.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
aSysBus io module - digital inputs
@copyright 2015-2017 Florian Knodt, www.adlerweb.info
Based on iSysBus - 2010 Patrick Amrhein, www.isysbus.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ASB_IO_DIN__H
#define ASB_IO_DIN__H
#include <Arduino.h>
#include <inttypes.h>
#include <asb.h>
#define ASB_IO_DIN_DIRECT 0 //pushed = on, released = off - e.g. switch, temporary action, etc
#define ASB_IO_DIN_BTOGGLE 1 //toggle every time button is pushed - e.g. push-button as light swtich, etc
#define ASB_IO_DIN_STOGGLE 2 //toggle every time button is pushed or released - e.g. multiple switches for switching lights
/**
* Direct input struct
* Contains pin numbers and configuration for outputs
*/
typedef struct {
/**
* Affected pin
*/
byte pin = 0xFF;
/**
* Target address
* Unicast: 0x0001 - 0x07FF
* Milticast/Broadcast: 0x0001 - 0xFFFF
* 0x0 -> everything
*/
unsigned int target = 0;
/**
* Is pin inverted?
*/
boolean invert = false;
/**
* Use Pull-Up?
*/
boolean pullup = false;
/**
* Input mode
*/
byte mode = ASB_IO_DIN_DIRECT;
/**
* Last received state
*/
byte last = LOW;
} asbIoDIn;
/**
* Digital input module
* @see ASB_IO
*/
class ASB_IO_DIN : public ASB_IO {
private:
/**
* Number of configured inputs
*/
byte _items;
/**
* Array of configured inputs
*/
asbIoDIn *_config;
public:
/**
* Initialize
* @param read configuration objects using id X, 1-15
* @return bool true if successful
*/
ASB_IO_DIN(byte cfgId);
/**
* Read configuration block starting at provided address
* @param read configuration object from address X
* @return bool true if successful
*/
bool cfgRead(unsigned int address);
/**
* Write current configuration
* @param asbIoDIn configuration struct reference
* @return bool true if successful
*/
bool cfgWrite(asbIoDIn &cfg);
/**
* Reset current configuration and free memory
* @return bool true if successful
*/
bool cfgReset(void);
/**
* Reserve memory for configuration
* @param objects number of configuration objects
* @return bool true if successful
*/
bool cfgReserve(byte objects);
/**
* Process incoming packet
* @param pkg Packet struct
* @return bool true if successful
*/
bool process(asbPacket &pkg);
/**
* Main loop call, e.G. for polling stuff
* @return bool true if successful
*/
bool loop(void);
/**
* Attach an input to a set of metadata
*
* If the supplied pins state changes an IO-message will be send
*
* @param target target address between 0x0001 and 0xFFFF
* @param pin Pin number to monitor
* @param mode ASB_IN_DIRECT = Direct output, _TOGGLE = Toggle output when HIGH
* @param invert input
* @param pullup use internal pull-up resistor
* @return true if successfully added
*/
bool attach(unsigned int target, byte pin, byte mode, bool invert, bool pullup);
};
#endif /* ASB_IO_DIN__H */