-
Notifications
You must be signed in to change notification settings - Fork 0
/
M0dularisPlus-Testsuite_beta5.ino
executable file
·184 lines (152 loc) · 5.26 KB
/
M0dularisPlus-Testsuite_beta5.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
/* *****************************************************************************
Includes
*/
#include <SerialFlash.h> // http://librarymanager/All#SerialFlash @ 0.5.0
//#include <SerialFlash.h> // http://librarymanager/All#xxx @ 1.2.3
#include "KonnektingDevice.h"
#include "Memory.h"
//#include <Arduino.h>
/* *****************************************************************************
Defines
*/
#define KNX_SERIAL Serial1
#define PROG_LED 19 // A1
#define PROG_BTN 15 // A5
#define MANUFACTURER_ID 0xDEAD
#define DEVICE_ID 0xFF
#define REVISION 0x00
KnxComObject KnxDevice::_comObjectsList[] = {
/* Index 0 - Test Receive Object */ KnxComObject(KNX_DPT_1_001, 0x2a),
/* Index 1 - Test Send Object */ KnxComObject(KNX_DPT_1_001, 0x34),
};
const byte KnxDevice::_numberOfComObjects =
sizeof(_comObjectsList) / sizeof(KnxComObject); // do not change this code
byte KonnektingDevice::_paramSizeList[] = {
/* Index 0 - startupDelay */ PARAM_UINT8,
/* Index 1 - blink1Delay */ PARAM_UINT8,
/* Index 2 - blink2Delay */ PARAM_UINT8,
};
const int KonnektingDevice::_numberOfParams =
sizeof(_paramSizeList); // do not change this code
// void writeComObj(byte comObjId, word ga) {
// byte gaHi = (ga >> 8) & 0xff;
// byte gaLo = (ga >> 0) & 0xff;
// byte settings = 0x80;
// writeMemory(EEPROM_COMOBJECTTABLE_START + (comObjId * 3) + 0, gaHi);
// writeMemory(EEPROM_COMOBJECTTABLE_START + (comObjId * 3) + 1, gaLo);
// writeMemory(EEPROM_COMOBJECTTABLE_START + (comObjId * 3) + 2, settings);
// }
/* *****************************************************************************
S E T U P
*/
void setup() {
SerialUSB.begin(115200);
pinMode(PROG_LED, OUTPUT);
digitalWrite(PROG_LED, HIGH);
long start = millis();
while (!SerialUSB) {
//while (!SerialUSB && (millis() - start < 2000)) {
// wait for serial connection at most 2sec
}
digitalWrite(PROG_LED, LOW);
/*
make debug serial port known to debug class
Means: KONNEKTING will use this serial port for console debugging
*/
Debug.setPrintStream(&SerialUSB);
Debug.println(F("Test-Suite: M0dularis+ v1.0 @ beta5 build date=%s time=%s"),
F(__DATE__), F(__TIME__));
/*
Set memory functions
*/
Debug.println(F("Setup Memory ..."));
setupMemory();
setupFlash();
Debug.println(F("--> DONE"));
/*
* Fake parametrization
*/
// Debug.println(F("Fake Memory Data..."));
// word individualAddress = P_ADDR(1,1,1);
// byte iaHi = (individualAddress >> 8) & 0xff;
// byte iaLo = (individualAddress >> 0) & 0xff;
// byte deviceFlags = 0xFE;
// writeMemory(EEPROM_DEVICE_FLAGS, deviceFlags);
// writeMemory(EEPROM_INDIVIDUALADDRESS_HI, iaHi);
// writeMemory(EEPROM_INDIVIDUALADDRESS_LO, iaLo);
// // writeComObj(0, G_ADDR(15,7,253));
// // writeComObj(1, G_ADDR(15,7,254));
// Debug.println(F("--> DONE"));
Debug.println(F("Setup Memory Fctptr ..."));
// ptr for memory access
Konnekting.setMemoryReadFunc(&readMemory);
Konnekting.setMemoryWriteFunc(&writeMemory);
Konnekting.setMemoryUpdateFunc(&updateMemory);
Konnekting.setMemoryCommitFunc(&commitMemory);
// ptr for writing/reading data to/from device
Konnekting.setDataOpenWriteFunc(&dataOpenWrite);
Konnekting.setDataOpenReadFunc(&dataOpenRead);
Konnekting.setDataWriteFunc(&dataWrite);
Konnekting.setDataReadFunc(&dataRead);
Konnekting.setDataRemoveFunc(&dataRemove);
Konnekting.setDataCloseFunc(&dataClose);
Debug.println(F("--> DONE"));
// M0dularis+ uses "Serial1" !!!
Konnekting.init(KNX_SERIAL, PROG_BTN, PROG_LED, MANUFACTURER_ID, DEVICE_ID,
REVISION);
Debug.println(F("--> setup() DONE"));
}
long last = 0;
bool state = false;
/* *****************************************************************************
L O O P
*/
void loop() {
Knx.task();
// it's not ready, unless it's programmed via Suite
if (Konnekting.isReadyForApplication()) {
// Blink Prog-LED SLOW for testing purpose
if (millis() - last > 1000) {
// send state every second to bus
Knx.write(1, (bool) state);
//Debug.println(F("Sending %i on 15/7/254 from 1.1.1"), state);
//Debug.println(F("blink_0 %i "), state);
if (state) {
digitalWrite(PROG_LED, HIGH);
state = false;
} else {
digitalWrite(PROG_LED, LOW);
state = true;
}
last = millis();
}
} else {
// Blink Prog-LED FAST for testing purpose
if (Konnekting.isProgState() && (millis() - last > 200)) {
// Debug.println(F("blink_1 %i "), state);
if (state) {
digitalWrite(PROG_LED, HIGH);
state = false;
} else {
digitalWrite(PROG_LED, LOW);
state = true;
}
last = millis();
} else {
// Blink Prog-LED SLOW for testing purpose
if (millis() - last > 1000) {
//Debug.println(F("blink_2 %i "), state);
if (state) {
digitalWrite(PROG_LED, HIGH);
state = false;
} else {
digitalWrite(PROG_LED, LOW);
state = true;
}
last = millis();
}
}
}
}
// Callback function to handle com objects updates
void knxEvents(byte index) { Debug.println(F("knxEvents: i=%i"), index); };