-
Notifications
You must be signed in to change notification settings - Fork 4
/
EnOceanGateway.ino
367 lines (328 loc) · 11.6 KB
/
EnOceanGateway.ino
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#include "Arduino.h"
#include <KonnektingDevice.h>
#include "kdevice_KNX_EnOcean_Gateway.h"
#include "EEPROM.h"
#include "Enocean.h"
#include <Wire.h>
// ################################################
// ### DEBUG CONFIGURATION
// ################################################
// DEBUG-MODE
//#define KDEBUG // comment this line to disable DEBUG mode
#ifdef KDEBUG
#include <DebugUtil.h>
// Get correct serial port for debugging
#define DEBUGSERIAL SerialUSB
#endif
// ################################################
// ### KONNEKTING Configuration
// ################################################
#define KNX_SERIAL Serial1 // Leonardo/Micro/Zero etc. use Serial1
// ################################################
// ### IO Configuration
// ################################################
#define PROG_LED_PIN A2
#define PROG_BUTTON_PIN A1
#define LED_YELLOW 25
// Enocean Device Libraries
#include "EnOceanDevice_RPS_simple.h"
#include "EnOceanDevice_RPS_sender.h"
#include "EnOceanDevice_NodOn_2Ch.h"
#include "EnOceanDevice_1BS_simple.h"
#include "EnOceanDevice_T_H_VOC.h"
// ################################################
// ### EnOcean Devices Instance creation
// ### order doesn't matter here
// ################################################
EnOceanDevice_RPS_simple taster1 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple taster2 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple taster3 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple taster4 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple taster5 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple taster6 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple taster7 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple taster8 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple taster9 = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_simple tasterA = EnOceanDevice_RPS_simple();
EnOceanDevice_RPS_sender rpsSender1 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSender2 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSender3 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSender4 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSender5 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSender6 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSender7 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSender8 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSender9 = EnOceanDevice_RPS_sender();
EnOceanDevice_RPS_sender rpsSenderA = EnOceanDevice_RPS_sender();
EnOceanDevice_NodOn_2Ch actor1 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actor2 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actor3 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actor4 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actor5 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actor6 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actor7 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actor8 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actor9 = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_NodOn_2Ch actorA = EnOceanDevice_NodOn_2Ch();
EnOceanDevice_1BS_simple sensorFenster1 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster2 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster3 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster4 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster5 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster6 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster7 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster8 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster9 = EnOceanDevice_1BS_simple();
EnOceanDevice_1BS_simple sensorFenster10 = EnOceanDevice_1BS_simple();
EnOceanDevice_T_H_VOC sensor_T_H_VOC_1 = EnOceanDevice_T_H_VOC();
EnOceanDevice_T_H_VOC sensor_T_H_VOC_2 = EnOceanDevice_T_H_VOC();
EnOceanDevice_T_H_VOC sensor_T_H_VOC_3 = EnOceanDevice_T_H_VOC();
EnOceanDevice_T_H_VOC sensor_T_H_VOC_4 = EnOceanDevice_T_H_VOC();
EnOceanDevice_T_H_VOC sensor_T_H_VOC_5 = EnOceanDevice_T_H_VOC();
void setup()
{
//****************** Init IO *******************************************************
pinMode(LED_YELLOW, OUTPUT);
digitalWrite(LED_YELLOW, HIGH);
Wire.begin();
//****************** Init Debug Interface ********************************************
#ifdef KDEBUG
// Start debug serial with 9600 bauds
DEBUGSERIAL.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(__SAMD21G18A__)
// wait for serial port to connect. Needed for Leonardo/Micro/ProMicro/Zero only
while (!DEBUGSERIAL)
{
}
#endif
// make debug serial port known to debug class
// Means: KONNEKTING will use the same serial port for console debugging
Debug.setPrintStream(&DEBUGSERIAL);
Debug.println(F("KONNEKTING EnOcean Gateway"));
#endif
//****************** Init Debug KONNEKTING ********************************************
Konnekting.setMemoryReadFunc(&readMemory);
Konnekting.setMemoryWriteFunc(&writeMemory);
Konnekting.setMemoryUpdateFunc(&updateMemory);
Konnekting.setMemoryCommitFunc(&commitMemory);
// Initialize KNX enabled Arduino Board
Konnekting.init(KNX_SERIAL, PROG_BUTTON_PIN, PROG_LED_PIN, MANUFACTURER_ID, DEVICE_ID, REVISION);
//****************** Read Parameter ***************************************************
#ifdef KDEBUG
Debug.println(F("** READ Parameter ******************"));
#endif
// for(int i=0; i<1000 ; i++)
// {
// writeEeprom(i, 255);
// delay(5);
// }
// ####################################################################################
// ###
// ### EnOcean Devices configuration from the definition in Konnekting
// ### ATTENTION: The order defines the position from which com-obj and params data is read
// ###
// ####################################################################################
#ifdef KDEBUG
Debug.println(F("** READ Taster 1 ******************"));
#endif
enOcean.configureDevice(taster1);
#ifdef KDEBUG
Debug.println(F("** READ Taster 2 ******************"));
#endif
enOcean.configureDevice(taster2);
#ifdef KDEBUG
Debug.println(F("** READ Taster 3 ******************"));
#endif
enOcean.configureDevice(taster3);
#ifdef KDEBUG
Debug.println(F("** READ Taster 4 ******************"));
#endif
enOcean.configureDevice(taster4);
#ifdef KDEBUG
Debug.println(F("** READ Taster 5 ******************"));
#endif
enOcean.configureDevice(taster5);
#ifdef KDEBUG
Debug.println(F("** READ Taster 6 ******************"));
#endif
enOcean.configureDevice(taster6);
#ifdef KDEBUG
Debug.println(F("** READ Taster 7 ******************"));
#endif
enOcean.configureDevice(taster7);
#ifdef KDEBUG
Debug.println(F("** READ Taster 8 ******************"));
#endif
enOcean.configureDevice(taster8);
#ifdef KDEBUG
Debug.println(F("** READ Taster 9 ******************"));
#endif
enOcean.configureDevice(taster9);
#ifdef KDEBUG
Debug.println(F("** READ Taster 10 *****************"));
#endif
enOcean.configureDevice(tasterA);
#ifdef KDEBUG
Debug.println(F("** READ Sender 1 ******************"));
#endif
enOcean.configureDevice(rpsSender1);
#ifdef KDEBUG
Debug.println(F("** READ Sender 2 ******************"));
#endif
enOcean.configureDevice(rpsSender2);
#ifdef KDEBUG
Debug.println(F("** READ Sender 3 ******************"));
#endif
enOcean.configureDevice(rpsSender3);
#ifdef KDEBUG
Debug.println(F("** READ Sender 4 ******************"));
#endif
enOcean.configureDevice(rpsSender4);
#ifdef KDEBUG
Debug.println(F("** READ Sender 5 ******************"));
#endif
enOcean.configureDevice(rpsSender5);
#ifdef KDEBUG
Debug.println(F("** READ Sender 6 ******************"));
#endif
enOcean.configureDevice(rpsSender6);
#ifdef KDEBUG
Debug.println(F("** READ Sender 7 ******************"));
#endif
enOcean.configureDevice(rpsSender7);
#ifdef KDEBUG
Debug.println(F("** READ Sender 8 ******************"));
#endif
enOcean.configureDevice(rpsSender8);
#ifdef KDEBUG
Debug.println(F("** READ Sender 9 ******************"));
#endif
enOcean.configureDevice(rpsSender9);
#ifdef KDEBUG
Debug.println(F("** READ Sender 10 *****************"));
#endif
enOcean.configureDevice(rpsSenderA);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 1 ******************"));
#endif
enOcean.configureDevice(actor1);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 2 ******************"));
#endif
enOcean.configureDevice(actor2);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 3 ******************"));
#endif
enOcean.configureDevice(actor3);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 4 ******************"));
#endif
enOcean.configureDevice(actor4);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 5 ******************"));
#endif
enOcean.configureDevice(actor5);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 6 ******************"));
#endif
enOcean.configureDevice(actor6);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 7 ******************"));
#endif
enOcean.configureDevice(actor7);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 8 ******************"));
#endif
enOcean.configureDevice(actor8);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 9 ******************"));
#endif
enOcean.configureDevice(actor9);
#ifdef KDEBUG
Debug.println(F("** READ Aktor 10 *****************"));
#endif
enOcean.configureDevice(actorA);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 1 *****************"));
#endif
enOcean.configureDevice(sensorFenster1);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 2 *****************"));
#endif
enOcean.configureDevice(sensorFenster2);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 3 *****************"));
#endif
enOcean.configureDevice(sensorFenster3);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 4 *****************"));
#endif
enOcean.configureDevice(sensorFenster4);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 5 *****************"));
#endif
enOcean.configureDevice(sensorFenster5);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 6 *****************"));
#endif
enOcean.configureDevice(sensorFenster7);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 7 *****************"));
#endif
enOcean.configureDevice(sensorFenster7);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 8 *****************"));
#endif
enOcean.configureDevice(sensorFenster8);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 9 *****************"));
#endif
enOcean.configureDevice(sensorFenster9);
#ifdef KDEBUG
Debug.println(F("** READ Sensor Fenster 10 *****************"));
#endif
enOcean.configureDevice(sensorFenster10);
#ifdef KDEBUG
Debug.println(F("** READ Sensor T H VOC 1 *****************"));
#endif
enOcean.configureDevice(sensor_T_H_VOC_1);
#ifdef KDEBUG
Debug.println(F("** READ Sensor T H VOC 2 *****************"));
#endif
enOcean.configureDevice(sensor_T_H_VOC_2);
#ifdef KDEBUG
Debug.println(F("** READ Sensor T H VOC 3 *****************"));
#endif
enOcean.configureDevice(sensor_T_H_VOC_3);
#ifdef KDEBUG
Debug.println(F("** READ Sensor T H VOC 4 *****************"));
#endif
enOcean.configureDevice(sensor_T_H_VOC_4);
#ifdef KDEBUG
Debug.println(F("** READ Sensor T H VOC 5 *****************"));
#endif
enOcean.configureDevice(sensor_T_H_VOC_5);
#ifdef KDEBUG
Debug.println(F("ID0: 0x%08x"), taster1.tasterId);
#endif
// Init EnOcean operation if not yet done by any device during setup
enOcean.init();
// for (int i=0; i<200 ;i++){
// writeEeprom(i, 255);
// delay (5);
// }
#ifdef KDEBUG
Debug.println(F("Ready for normal operation"));
#endif
digitalWrite(LED_YELLOW, LOW);
}
void loop()
{
Knx.task();
if (Konnekting.isReadyForApplication())
enOcean.task();
}
void knxEvents(byte index)
{
enOcean.handleKnxEvents(index);
}