forked from letscontrolit/ESPEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_P109_RESOL_DeltaSol_Pro.ino
260 lines (212 loc) · 7.32 KB
/
_P109_RESOL_DeltaSol_Pro.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
#ifdef PLUGIN_BUILD_DEV
//#######################################################################################################
//################################## Plugin 109 RESOL DeltaSol Pro ######################################
//#######################################################################################################
#include <SoftwareSerial.h>
#define PLUGIN_109
#define PLUGIN_ID_109 109
#define PLUGIN_NAME_109 "RESOL DeltaSol Pro [DEVELOPMENT]"
#define PLUGIN_VALUENAME1_109 "register"
// uart rx-buffer size
#define RXBUF_SIZE 32
// RESOL register options
#define REG_TEMP_SENSOR_1 0
#define REG_TEMP_SENSOR_2 1
#define REG_TEMP_SENSOR_3 2
#define REG_RELAIS_1 3
#define REG_RELAIS_2 4
// total number of selectable registers
#define RESOL_REGISTER_OPTIONS 5
uint8_t Plugin_109_UART_Pin;
boolean Plugin_109_init = false;
boolean valuesValid = false;
uint8_t RXbuf[RXBUF_SIZE];
uint8_t RXbuf_IDX;
int16_t T1, T2 ,T3;
uint8_t R1, R2;
SoftwareSerial *Plugin_109_UART;
// RESOL CRC check
uint8_t VBus_CalcCrc(uint8_t *buf, uint8_t len)
{
uint8_t crc;
crc = 0x7F;
for (uint8_t i = 0; i < len; i++)
crc = (crc - buf [i]) & 0x7F;
return crc;
}
boolean Plugin_109(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_109;
Device[deviceCount].Type = DEVICE_TYPE_DUAL;
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].TimerOptional = true;
Device[deviceCount].GlobalSyncOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_109);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_109));
break;
}
case PLUGIN_WEBFORM_LOAD:
{
int16_t choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
String options[RESOL_REGISTER_OPTIONS];
uint optionValues[RESOL_REGISTER_OPTIONS];
optionValues[0] = REG_TEMP_SENSOR_1;
options[0] = F("Temperature sensor 1");
optionValues[1] = REG_TEMP_SENSOR_2;
options[1] = F("Temperature sensor 2");
optionValues[2] = REG_TEMP_SENSOR_3;
options[2] = F("Temperature sensor 3");
optionValues[3] = REG_RELAIS_1;
options[3] = F("Relais 1");
optionValues[4] = REG_RELAIS_2;
options[4] = F("Relais 2");
string += F("<TR><TD>Register:<TD><select name='plugin_109_register'>");
for (byte x = 0; x < RESOL_REGISTER_OPTIONS; x++)
{
string += F("<option value='");
string += optionValues[x];
string += "'";
if (choice == optionValues[x])
string += F(" selected");
string += ">";
string += options[x];
string += F("</option>");
}
string += F("</select>");
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
String plugin1 = WebServer.arg("plugin_109_register");
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin1.toInt();
Plugin_109_init = false; // Force device setup next time
success = true;
break;
}
case PLUGIN_INIT:
{
addLog(LOG_LEVEL_INFO, (char*)"INIT : RESOL DeltaSol Pro");
Plugin_109_UART = new SoftwareSerial(Settings.TaskDevicePin1[event->TaskIndex], Settings.TaskDevicePin2[event->TaskIndex], false, (2 * RXBUF_SIZE)); // set RX und Tx Pin number, no invert, buffer
Plugin_109_init = true;
success = true;
break;
}
case PLUGIN_TEN_PER_SECOND:
{
if (Plugin_109_init == true)
{
// buffer filled with more than twize the frame size bytes? -> at least one complete frame should then be available
if (Plugin_109_UART->available() > (2 * 30))
{
// search for first appearance of SOF (0xAA)
while ((Plugin_109_UART->available()) && (Plugin_109_UART->read() != 0xAA));
RXbuf_IDX = 0;
RXbuf[RXbuf_IDX] = 0;
while ((Plugin_109_UART->available()) && (RXbuf[RXbuf_IDX] != 0xAA) && (RXbuf_IDX < (RXBUF_SIZE - 1)))
RXbuf[++RXbuf_IDX] = Plugin_109_UART->read();
if (RXbuf[RXbuf_IDX] == 0xAA)
{
// ********* DeltaSol Pro registers *********
// check CRC of first and second group
if ( (VBus_CalcCrc(&RXbuf[10], 5) == RXbuf[15]) && (VBus_CalcCrc(&RXbuf[16], 5) == RXbuf[21]) )
{
// Temperature sensor 1
T1 = RXbuf[10] + ((RXbuf[14] & (1 << 0)) << 7);
T1 += (RXbuf[11] + ((RXbuf[14] & (1 << 1)) << 6)) << 8;
// Temperature sensor 2
T2 = RXbuf[12] + ((RXbuf[14] & (1 << 2)) << 5);
T2 += (RXbuf[13] + ((RXbuf[14] & (1 << 3)) << 4)) << 8;
// Temperature sensor 3
T3 = RXbuf[16] + ((RXbuf[20] & (1 << 0)) << 7);
T3 += (RXbuf[17] + ((RXbuf[20] & (1 << 1)) << 6)) << 8;
// Relais/speed
R1 = RXbuf[18] + ((RXbuf[20] & (1 << 2)) << 5);
R2 = RXbuf[19] + ((RXbuf[20] & (1 << 3)) << 4);
valuesValid = true;
} else
valuesValid = false;
}
Plugin_109_UART->flush();
}
}
success = true;
break;
}
case PLUGIN_READ:
{
float regValue;
String log = F("RESOL : ");
if (valuesValid == true)
{
switch (Settings.TaskDevicePluginConfig[event->TaskIndex][0])
{
case REG_TEMP_SENSOR_1:
{
log += F("T1");
regValue = (float)T1 / 10;
break;
}
case REG_TEMP_SENSOR_2:
{
log += F("T2");
regValue = (float)T2 / 10;
break;
}
case REG_TEMP_SENSOR_3:
{
log += F("T3");
regValue = (float)T3 / 10;
break;
}
case REG_RELAIS_1:
{
log += F("R1");
regValue = R1;
break;
}
case REG_RELAIS_2:
{
log += F("R2");
regValue = R2;
break;
}
default:
{
log += F("unknown");
regValue = 0;
break;
}
}
log += F("=");
log += regValue;
addLog(LOG_LEVEL_INFO, log);
UserVar[event->BaseVarIndex] = regValue;
success = true;
break;
}
}
}
return success;
}
#endif