From 99d62dc65d30dd5ff32d5fa407aeed325b0f5f7e Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 18 May 2012 04:15:26 +0200 Subject: digital/io-hub/src/guybrush: try again if door do not close --- digital/io-hub/src/guybrush/top.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'digital/io-hub/src/guybrush') diff --git a/digital/io-hub/src/guybrush/top.c b/digital/io-hub/src/guybrush/top.c index 8351e2ba..10834ac4 100644 --- a/digital/io-hub/src/guybrush/top.c +++ b/digital/io-hub/src/guybrush/top.c @@ -121,6 +121,10 @@ struct top_t int16_t totem_distance; /** Close door when out of unloading zone. */ uint8_t close_door; + /** Check door is closed once this reach 0. */ + uint8_t close_door_check; + /** Close the door once this reach 0. */ + uint8_t close_door_wait; }; /** Global context. */ @@ -140,6 +144,7 @@ top_update (void) IO_CLR (OUTPUT_DOOR_OPEN); IO_SET (OUTPUT_DOOR_CLOSE); top.close_door = 0; + top.close_door_check = 250; } } /* If door is closed, cut air to save power. */ @@ -147,6 +152,27 @@ top_update (void) { IO_CLR (OUTPUT_DOOR_CLOSE); } + /* Else, test if it should be closed. */ + else if (top.close_door_check) + { + top.close_door_check--; + if (!top.close_door_check) + { + IO_SET (OUTPUT_DOOR_OPEN); + IO_CLR (OUTPUT_DOOR_CLOSE); + top.close_door_wait = 250; + } + } + /* Close door after a delay. */ + if (top.close_door_wait) + { + top.close_door_wait--; + if (!top.close_door_wait) + { + IO_CLR (OUTPUT_DOOR_OPEN); + IO_SET (OUTPUT_DOOR_CLOSE); + } + } } /** Go collect a totem. */ -- cgit v1.2.3