-
Notifications
You must be signed in to change notification settings - Fork 30
/
_P043_ClkOutput.ino
137 lines (124 loc) · 4.3 KB
/
_P043_ClkOutput.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
//#######################################################################################################
//#################################### Plugin 043: Clock Output #########################################
//#######################################################################################################
#define PLUGIN_043
#define PLUGIN_ID_043 43
#define PLUGIN_NAME_043 "Clock - Output"
#define PLUGIN_VALUENAME1_043 "Output"
#define PLUGIN_043_MAX_SETTINGS 8
boolean Plugin_043(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_043;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_043);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_043));
break;
}
case PLUGIN_WEBFORM_LOAD:
{
for (byte x = 0; x < PLUGIN_043_MAX_SETTINGS; x++)
{
string += F("<TR><TD>Day,Time ");
string += x+1;
string += F(":<TD><input type='text' name='plugin_043_clock");
string += x;
string += F("' value='");
string += timeLong2String(ExtraTaskSettings.TaskDevicePluginConfigLong[x]);
string += F("'>");
byte choice = ExtraTaskSettings.TaskDevicePluginConfig[x];
String options[3];
options[0] = F("");
options[1] = F("Off");
options[2] = F("On");
int optionValues[3];
optionValues[0] = 0;
optionValues[1] = 1;
optionValues[2] = 2;
string += F("<select name='plugin_043_state");
string += x;
string += F("'>");
for (byte x = 0; x < 3; 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:
{
for (byte x = 0; x < PLUGIN_043_MAX_SETTINGS; x++)
{
String argc = F("plugin_043_clock");
argc += x;
String plugin1 = WebServer.arg(argc);
ExtraTaskSettings.TaskDevicePluginConfigLong[x] = string2TimeLong(plugin1);
argc = F("plugin_043_state");
argc += x;
String plugin2 = WebServer.arg(argc);
ExtraTaskSettings.TaskDevicePluginConfig[x] = plugin2.toInt();
}
success = true;
break;
}
case PLUGIN_INIT:
{
success = true;
break;
}
case PLUGIN_CLOCK_IN:
{
LoadTaskSettings(event->TaskIndex);
for (byte x = 0; x < PLUGIN_043_MAX_SETTINGS; x++)
{
unsigned long clockEvent = (unsigned long)minute() % 10 | (unsigned long)(minute() / 10) << 4 | (unsigned long)(hour() % 10) << 8 | (unsigned long)(hour() / 10) << 12 | (unsigned long)weekday() << 16;
unsigned long clockSet = ExtraTaskSettings.TaskDevicePluginConfigLong[x];
if (matchClockEvent(clockEvent,clockSet))
{
byte state = ExtraTaskSettings.TaskDevicePluginConfig[x];
if (state != 0)
{
state--;
pinMode(Settings.TaskDevicePin1[event->TaskIndex], OUTPUT);
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], state);
UserVar[event->BaseVarIndex] = state;
String log = F("TCLK : State ");
log += state;
addLog(LOG_LEVEL_INFO, log);
sendData(event);
}
}
}
break;
}
}
return success;
}