This file contains a Finite State Machine representaion of a Vendotron vending machine. More...
Namespaces | |
| Lab0x01 | |
| This package contains vendo.py. | |
Functions | |
| def | vendo.kb_cb (key) |
| Callback function which is called when a key has been pressed. More... | |
| def | vendo.VendotronTask () |
| Runs one iteration of the task. More... | |
Variables | |
| string | vendo.last_key = '' |
| The input key pressed by the user. | |
| def | vendo.vendo = VendotronTask() |
| Initialize code to run FSM (not the init state). More... | |
This file contains a Finite State Machine representaion of a Vendotron vending machine.
| def vendo.kb_cb | ( | key | ) |
Callback function which is called when a key has been pressed.
| key | String representation of the key pressed by the user. |
| def vendo.VendotronTask | ( | ) |
Runs one iteration of the task.
This program embodies the function of the vending machine designed in HW 0x00. Performs a particular state's operations in each iteration. On startup, display a message in the REPL (state 0). Moves into state 1 and stays there where the user can instruct the following actions -
1) Insert a coin by pressing one of the number keys (0-7) for their respective currencies. On doing so, the balance will be displayed in the REPL and the machine will go back to state 1. The number keys are '0' for a penny, '1' for a nickel, '2' for a dime, '3' for a quarter, '4' for $1, '5' for $5, '6' for $10, and '7' for $20.
2) Select a drink by pressing one of the drink keys. If the balance is insufficient, then an "Insufficient Funds" message will be displayed on the REPL along with the current balance and the price of the selected item and the machine will go back to state 1. If the current balance is sufficient, then the selcted item will be vended and the current balance computed. If there is no remaining balance left, then the machine will go back to state 1. However, if there is any remaining balance, then the user will be prompted to select another beverage. The drink keys are 'c' for Cuke, 'p' for Popsi, 's' for Spryte, 'd' for Dr. Pupper.
3) Eject at any time by pressing the 'e' key. On doing so, the full balance will be returned and the machine will go back to state 1.
If the machine is in state 1 for a long time, then it will go into an 'Idle' state in which a message will be displayed in the REPL saying 'Try Cuke today!'.
| def vendo.vendo = VendotronTask() |
Initialize code to run FSM (not the init state).
This means building the iterator as generator object