Hardware Reference
In-Depth Information
state = “WAITING_OUTWARD_O_CLEAR”
elif (state == “WAITING_OUTWARD_O_CLEAR”):
if ((sensor==OUTER_BEAM) and (eventType==UNBROKEN)):
debug (str(eventTime)+" BIRD has left")
outwardTimes.append(date2num(eventTime))
state = "IDLE"
#set of states for bird coming in
elif (state == "INWARD_BOUND"):
if ((sensor==OUTER_BEAM) and (eventType==UNBROKEN)):
debug ("outside bob out")
state = "IDLE"
elif ((sensor==INNER_BEAM) and (eventType==BREAK)):
debug ("inward")
state = "WAITING_INWARD_O_CLEAR"
elif (state == "WAITING_INWARD_O_CLEAR"):
if ((sensor==OUTER_BEAM) and (eventType==UNBROKEN)):
debug ("outside cleared, waiting for inside to clear")
state = "WAITING_INWARD_I_CLEAR"
elif (state == "WAITING_INWARD_I_CLEAR"):
if ((sensor==INNER_BEAM) and (eventType==UNBROKEN)):
state == "IDLE"
debug (str(eventTime)+" BIRD has returned")
# if we end up in any other state, then we generate an error
else:
debug ("error")
raise ValueError, "unexpected input block state: "+state
he main part of the program in Listing 17-2 is performed by the for loop which reads
stdin , line by line:
for line in sys.stdin
Each loop iteration processes another line of the ile. First the line is split at each comma and
placed into separate variables. he datetime.datetime.strptime function is the oppo-
site of the strftime function, converting a string-formatted time into a date object that
Python can process.
he variables are tested by the if statements in the state machine to determine if a state
transition should be made. If it is detected that a bird has left, then the time it left is appended
into the outwardTimes array. You will use this array to draw a graph of activity.
Search WWH ::




Custom Search