-
Notifications
You must be signed in to change notification settings - Fork 317
/
_P203_Feeder.ino
168 lines (128 loc) · 4.5 KB
/
_P203_Feeder.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
//#######################################################################################################
//################################ Plugin 203: Pet feeder ###########################################
//#######################################################################################################
//############################### Plugin for ESP Easy by DatuX ###############################
//################################### http://www.datux.nl ##############################################
//#######################################################################################################
#ifdef PLUGIN_BUILD_TESTING
#define PLUGIN_203
#define PLUGIN_ID_203 203
#define PLUGIN_NAME_203 "Automated pet feeder [TESTING]"
#ifndef CONFIG
#define CONFIG(n) (Settings.TaskDevicePluginConfig[event->TaskIndex][n])
#endif
//to not scare the cat of sudden motor movements
//attack and sustain in mS
void ramped_pulse(byte pin, unsigned long attack, unsigned long sustain)
{
//attack
unsigned long start_time=millis();
while (millis()-start_time < attack)
{
analogWrite(pin, ((millis()-start_time) * PWMRANGE /attack ) );
yield();
}
//sustain
analogWrite(pin, PWMRANGE);
// digitalWrite(pin, HIGH);
delay(sustain);
//releaase
start_time=millis();
while (millis()-start_time < attack)
{
analogWrite(pin, PWMRANGE-(((millis()-start_time) * PWMRANGE / attack) ));
yield();
}
//make sure its really off
analogWrite(pin, 0);
// digitalWrite(pin, LOW);
}
boolean Plugin_203(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_203;
Device[deviceCount].Type = DEVICE_TYPE_TRIPLE;
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = false;
Device[deviceCount].GlobalSyncOption = false;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_203);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
break;
}
case PLUGIN_WEBFORM_LOAD:
{
addFormNumericBox(F("Rotate forward time"), F("forward"), CONFIG(0), 0, 60000);
addUnit(F("ms"));
addFormNumericBox(F("Rotate reverse time"), F("reverse"), CONFIG(1), 0, 60000);
addUnit(F("ms"));
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
CONFIG(0) = getFormItemInt(F("forward"));
CONFIG(1) = getFormItemInt(F("reverse"));
success = true;
break;
}
case PLUGIN_INIT:
{
pinMode(Settings.TaskDevicePin1[event->TaskIndex],OUTPUT);
pinMode(Settings.TaskDevicePin2[event->TaskIndex],OUTPUT);
pinMode(Settings.TaskDevicePin3[event->TaskIndex],OUTPUT);
// analogWriteFreq(30000);
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW); //disable
success = true;
break;
}
case PLUGIN_WRITE:
{
String command = parseString(string, 1);
if (command == F("feed"))
{
// for(int i=0; i<event->Par1; i++)
{
//forward
// digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH); //enable
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], LOW);
ramped_pulse(Settings.TaskDevicePin1[event->TaskIndex], event->Par1, CONFIG(0));
// delay(CONFIG(0));
//pause
// digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW); //disable
// delay(100);
//reverse
// digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH); //enable
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], HIGH);
ramped_pulse(Settings.TaskDevicePin1[event->TaskIndex], 1000, CONFIG(1));
// delay(CONFIG(1));
//pause
// digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW); //disable
// delay(100);
}
}
success=true;
break;
}
}
return success;
}
#endif