@@ -13,10 +13,10 @@ enum action {
13
13
ACT_OUTER ,
14
14
15
15
// "close" or "open" is sw position when rewind began
16
- ACT_REWIND_CLOSE_INIT , // rewind just started, sensor OPEN
17
- ACT_REWIND_CLOSE , // rewind under way (or just started but never was
18
- // OPEN), sensor MIDDLE
19
- ACT_REWIND_OPEN , // rewind under way, sensor MIDDLE
16
+ ACT_REWIND_CLOSE ,
17
+ ACT_REWIND_OPEN ,
18
+
19
+ ACT_COOLDOWN ,
20
20
};
21
21
22
22
enum pins {
@@ -100,11 +100,6 @@ static bool outer_done_p() {
100
100
(!state .sw_outer_closed && state .sens_open );
101
101
}
102
102
103
- // if currently closing outer door, determine if we must rewind
104
- static bool close_rewind_p () {
105
- return state .sw_outer_closed && state .sens_open ;
106
- }
107
-
108
103
static void ensure_flshgnd () {
109
104
TCCR0B = (1 <<CS02 );
110
105
TCCR0A = (1 <<COM0A0 );
@@ -161,8 +156,6 @@ static void action_outer() {
161
156
static void auto_action_motion () {
162
157
if (state .inner_done ) {
163
158
if (outer_done_p ()) {
164
- // TODO: this will the periodic timer to be set too far
165
- // ahead sometimes?
166
159
action_idle ();
167
160
} else {
168
161
action_outer ();
@@ -172,16 +165,9 @@ static void auto_action_motion() {
172
165
}
173
166
}
174
167
175
- static void action_rewind_close_init () {
176
- ensure_flshgnd ();
177
- state .action = ACT_REWIND_CLOSE_INIT ;
178
- pin_outer_up ();
179
- OCR1B = TCNT1 + 0x0800 ;
180
- }
181
-
182
168
static void action_rewind_close () {
183
169
ensure_flshgnd ();
184
- state .action = ACT_REWIND_CLOSE_INIT ;
170
+ state .action = ACT_REWIND_CLOSE ;
185
171
// should already be set, but for consistency...
186
172
pin_outer_up ();
187
173
OCR1B = TCNT1 + 0x0800 ;
@@ -194,6 +180,14 @@ static void action_rewind_open() {
194
180
OCR1B = TCNT1 + 0x0800 ;
195
181
}
196
182
183
+ static void action_cooldown () {
184
+ ensure_flshgnd ();
185
+ state .action = ACT_COOLDOWN ;
186
+ pin_idle ();
187
+ // about a minute
188
+ OCR1B = TCNT1 + 0x2000 ;
189
+ }
190
+
197
191
///////////////////////////////
198
192
// act and act-timer
199
193
@@ -210,14 +204,6 @@ static void act() {
210
204
case ACT_OUTER :
211
205
if (outer_done_p ()) {
212
206
auto_action_motion ();
213
- // TODO: make close_rewind_p not shitty
214
- } else if (false && close_rewind_p ()) {
215
- action_rewind_close_init ();
216
- }
217
- break ;
218
- case ACT_REWIND_CLOSE_INIT :
219
- if (!state .sens_open ) {
220
- action_rewind_close ();
221
207
}
222
208
break ;
223
209
case ACT_REWIND_CLOSE :
@@ -226,23 +212,26 @@ static void act() {
226
212
auto_action_motion ();
227
213
} else if (state .sens_open ) {
228
214
// got stuck on the way down during rewind, so it came
229
- // back up the other side. For now, just lower
230
- // immediately -- but if there's a serious blockage,
231
- // this could cause a continuous loop, maybe damaging
232
- // the motor? TODO: some delay
233
- action_outer ();
215
+ // back up the other (normal spooling) side. Assume a
216
+ // serious blockage.
217
+ action_cooldown ();
234
218
}
235
219
break ;
236
220
case ACT_REWIND_OPEN :
237
- if (state .sens_closed ) {
238
- // rewind finished
221
+ if (state .sens_closed || state .sens_open ) {
222
+ // rewind finished OR the door got caught while
223
+ // rewinding (never reached the bottom) and is now open
224
+ // but spooled the wrong direction, which will be
225
+ // corrected when the door is next opened.
226
+
227
+ // This could cause a loop of activating the motor in
228
+ // case of a serious blockage.
239
229
auto_action_motion ();
240
- } else if (state .sens_open ) {
241
- // we rewound all the way? means it got stuck lowering
242
- // while rewinding.
243
- action_rewind_close_init ();
244
230
}
245
231
break ;
232
+ case ACT_COOLDOWN :
233
+ // do nothing, we're waiting for the timer.
234
+ break ;
246
235
}
247
236
}
248
237
@@ -252,30 +241,30 @@ static void act_timer() {
252
241
case ACT_IDLE :
253
242
// Inner door periodic
254
243
state .inner_done = false;
255
- act ();
244
+ auto_action_motion ();
256
245
break ;
257
246
case ACT_INNER :
258
247
// Stop moving inner door
259
248
state .inner_done = true;
260
- act ();
249
+ auto_action_motion ();
261
250
break ;
262
251
case ACT_OUTER :
263
252
// Start rewind
264
253
if (state .sw_outer_closed ) {
265
- if (state .sens_open ) {
266
- action_rewind_close_init ();
267
- } else {
268
- action_rewind_close ();
269
- }
254
+ action_rewind_close ();
270
255
} else {
271
256
action_rewind_open ();
272
257
}
273
258
break ;
274
259
275
260
case ACT_REWIND_OPEN :
276
- case ACT_REWIND_CLOSE_INIT :
277
261
case ACT_REWIND_CLOSE :
278
- // rewind took too long. TODO
262
+ // rewind took too long
263
+ action_cooldown ();
264
+ break ;
265
+ case ACT_COOLDOWN :
266
+ // cooldown complete
267
+ auto_action_motion ();
279
268
break ;
280
269
}
281
270
}
0 commit comments