Hardware Reference
In-Depth Information
Listing 12-1 continued
authenticator = BasicAuthenticator()
doorController = TestDoorController()
if(authenticator.check(authInput.getInput())):
doorController.send_open_pulse()
if __name__ == '__main__':
main()
Run the program in Listing 12-1, and you'll see it print the following messages that describe
what is happening in that part of the program. Note that at the moment the test data is hard
coded into the program so it is not interactive, but it shows how the blocks work together.
checking for input
checking input for 'Andrew', password: 1234 against ;
secret password '1234'
authentication is: True
unlock, wait and relock
Change the value returned by the getInput() function to something other than 1234 and
rerun the program. Check that you don't see the message about unlocking the door.
By now, much of the code should be familiar as functions, if statements, variables, print
statements and delays are covered in earlier chapters. Not covered so far are the keywords
class and self , which are concerned with object-orientated programming, or OOP for
short. In this example OOP is used as a means to break the task into manageable objects that
represent the blocks in your system diagram. Later in the chapter you'll swap out one object
for another, which makes it very easy to modify your programs, and reuse objects in other
projects. You'll learn more about OOP later in the section “Testing the Program and Fitting
the Lock”.
Your simulated system may not appear very exciting at the moment, but building up a sys-
tem with irm foundations can save hours of debugging later. he next steps are to start
expanding the blocks that actually take input and control the door.
Search WWH ::




Custom Search