This file runs the VendoTron FSM. More...
Functions | |
def | 405_Lab0x01.kb_cb (key) |
Callback function inside keyboard module. More... | |
def | 405_Lab0x01.getChange (price, balance) |
This file computes the change for a certain purchase. More... | |
def | 405_Lab0x01.convertToCents (_moneyDict) |
Converts denominations and quantities to cents. More... | |
def | 405_Lab0x01.vendoTronTask (debugFlag, payment) |
Generator used to hold the FSM for the vending machine. More... | |
Variables | |
int | 405_Lab0x01.S0_INIT = 0 |
The init state. | |
int | 405_Lab0x01.S1_WAIT_FOR_ACTION = 1 |
Waits for user to press a button. | |
int | 405_Lab0x01.S2_DISPLAY_BALANCE = 2 |
Display the current balance. | |
int | 405_Lab0x01.S3_DO_TRANSACTION = 3 |
Computations after a drink is selected. | |
int | 405_Lab0x01.S4_QUERY_FOR_DRINK = 4 |
Ask user for another drink. | |
int | 405_Lab0x01.S5_RETURN_CHANGE = 5 |
return change. | |
int | 405_Lab0x01.S6_THANK_USER = 6 |
Thank user for buying a drink. | |
int | 405_Lab0x01.S7_TIME_OUT = 7 |
System times out and reminds user to finish. | |
dictionary | 405_Lab0x01.denomination |
Dictionary of denominations. More... | |
dictionary | 405_Lab0x01.balance = {1:0, 5:0, 10:0, 25:0, 100:0, 500:0, 1000:0, 2000:0} |
A dictionary of the starting balance, which should be 0. | |
dictionary | 405_Lab0x01.sodas = {'c':('Cuke',100), 'p':('Popsi',120), 's':('Spryte',85), 'd':('Dr. Pupper',110)} |
Dictionary for soda options. More... | |
dictionary | 405_Lab0x01.change = {1:0, 5:0, 10:0, 25:0, 100:0, 500:0, 1000:0, 2000:0} |
A dictionary of the starting change, which should be 0. | |
list | 405_Lab0x01.Keys = ["0","1","2","3","4","5","6","7","e","c","p","s","d","q","y","n"] |
A list of the possible keyboard commands that could be pressed. | |
405_Lab0x01.last_key = None | |
A variable to hold the last keystroke. | |
def | 405_Lab0x01.vendo = vendoTronTask(False, balance) |
This file runs the VendoTron FSM.
The user will input the quantity of each denomination that they are using to purchase the item, along with the price of the item, and the required drink, and several operations will be utilitized to simulate the workings of an actual vending machine. See source code here: https://bitbucket.org/MatthewFrostCP/me405/src/master/Lab0x01/Lab0x01.py
def 405_Lab0x01.convertToCents | ( | _moneyDict | ) |
Converts denominations and quantities to cents.
When a dictionary of denominations and values are inputted, the corresponding value in cents is outputted.
def 405_Lab0x01.getChange | ( | price, | |
balance | |||
) |
This file computes the change for a certain purchase.
The user will input the quantity of each denomination that they are using to purchase the item, along with the price of the item, and the corresponding change will be calculated in terms of the quantity of each denomination that will be returned.
price | The price of the selected soda. |
balance | A dictionary of the current balance. |
def 405_Lab0x01.kb_cb | ( | key | ) |
Callback function inside keyboard module.
When keyboard is pressed, it automatically gets sent to the callback function to assign a variable the letter pressed.
key | The key that was pressed to trigger the callback function. |
def 405_Lab0x01.vendoTronTask | ( | debugFlag, | |
payment | |||
) |
Generator used to hold the FSM for the vending machine.
This implements the finite state machine used to simulate the vending machine. This will handle all the keyboard inputs, timing issues, and is in charge of calling other functions to calculate change and balance.
debugFlag | When enabled to True, more print commands are displayed. |
payment | A dictionary with the current balance or payment. |
dictionary 405_Lab0x01.denomination |
Dictionary of denominations.
A dictionary of denominations that has the keyboard button as the key, and then a tuple for the name and amount of each denomination
dictionary 405_Lab0x01.sodas = {'c':('Cuke',100), 'p':('Popsi',120), 's':('Spryte',85), 'd':('Dr. Pupper',110)} |
Dictionary for soda options.
A dictionary of soda options that has the keyboard button as the key, and then a tuple for the name and price of each soda