Hardware Reference
In-Depth Information
Listing 17-3 continued
if ((sensor==INNER_BEAM) and (eventType==BROKEN)):
debug (“on way out”)
state = “OUTWARD_BOUND”
#record when the inner beam was broken
outTime = eventTime
if ((sensor==OUTER_BEAM) and (eventType==BROKEN)):
debug (“on way in”)
state = “INWARD_BOUND”
## the bird has started leaving. Check to see if it
##bobs back or breaks the next sensor
elif (state == “OUTWARD_BOUND”):
# check that this event is within 5 seconds of the last
if (diffTime.seconds < 5):
# if bird puts head back in box return to IDLE
if ((sensor==INNER_BEAM) and (eventType==UNBROKEN)):
debug (“inside bob back”)
state = “IDLE”
# bird continues and breaks the OUTER_BEAM
elif ((sensor==OUTER_BEAM) and (eventType==BROKEN)):
debug (“outward”)
# bird is still going out, wait for the inner
# beam to clear
state = “WAITING_OUTWARD_I_CLEAR”
##the bird is still in the entrance hole, blocking
##both beams
elif (state == “WAITING_OUTWARD_I_CLEAR”):
if (diffTime.seconds < 5):
# bird is very nearly out, waiting for the
# outside beam to clear now
if ((sensor==INNER_BEAM) and (eventType==UNBROKEN)):
debug (“inside cleared, waiting for outside;
to clear”)
state = “WAITING_OUTWARD_O_CLEAR”
else:
debug (“timeout on waiting outward I Clear”)
state= “IDLE”
elif (state == “WAITING_OUTWARD_O_CLEAR”):
Search WWH ::




Custom Search