code/drinks_lib.py
def start_mixing(recipe):
	""" compiles the recipe and starts the mixing process.
	recipe: EITHER as string with recipe name OR as int with index in recipes list
	"""
	global is_mixing, recipe_step, commands, recipes

	if is_mixing:										# break, when there's already a recipe mixing
		return
	
	print("[DR SM]", "1/4 no other recipe mixing")

	if type(recipe) != int and type(recipe) != str:		# break when input type not correct
		return

	print("[DR SM]", "2/4 correct input type")

	if type(recipe) == int:								# get recipe name when index given
		recipe = recipes[recipe]
	
	print("[DR SM]", "3/4 got recipe name from index (if needed)")
	
	if not _test_availability(recipe):					# break when recipe not available
		return
	
	print("[DR SM]", "4/4 recipe is available")
	print("[DR SM]", "all checks passed, compiling recipe")
	
	file1 = open(dir_recipes + recipe, 'r')				# open file
	steps = file1.readlines()							# save steps as a list
	file1.close()

	steps.pop(0)			# remove info line

	for idx, i in enumerate(steps):
		if steps[idx].endswith('\n'):					# remove trailing newline characters
			steps[idx] = steps[idx][:-1]

	commands.clear() 									# delete previous commands
	""" compile recipe """
	for step in steps:									# compile step by step
		list = step.split(',')							# [<drink>, <volume>]
		time = int(int(list[1]) * gl.TIME_PER_ML)		# calculate needed time	(in ms)
		plug = plugs.index(list[0])						# get the plug
		print("[DR SM]", "Plug:", plug,"corresponding drink:" , list[0])

		commands.append("o" + str(plug))				# open valve
		commands.append("t" + str(time))				# set timer
		commands.append("w")							# wait for timer to pass
		commands.append("c" + str(plug))				# close valve
	
	commands.append("o0")								# cleaning procedure. this will pump some water through to clean the pipes
	commands.append("t" + str(gl.CLEANING_TIME))
	commands.append("w")
	commands.append("c0")

	commands.append("e")					# end sign
	print("[DR SM] compiling done")
	print("[DR SM] commands:")
	for c in commands:
		print(c)
 
	# start the mixing process
	is_mixing = True
	recipe_step = 0
 compiles the recipe and starts the mixing process.
	recipe: EITHER as string with recipe name OR as int with index in recipes list
	
compiles the recipe and starts the mixing process.
recipe: EITHER as string with recipe name OR as int with index in recipes list
compiles the recipe and starts the mixing process . recipe : EITHER as string with recipe name OR as int with index in recipes list
def start_mixing(recipe):
	global is_mixing, recipe_step, commands, recipes
	if is_mixing:										
		return
	print("[DR SM]", "1/4 no other recipe mixing")
	if type(recipe) != int and type(recipe) != str:		
		return
	print("[DR SM]", "2/4 correct input type")
	if type(recipe) == int:								
		recipe = recipes[recipe]
	print("[DR SM]", "3/4 got recipe name from index (if needed)")
	if not _test_availability(recipe):					
		return
	print("[DR SM]", "4/4 recipe is available")
	print("[DR SM]", "all checks passed, compiling recipe")
	file1 = open(dir_recipes + recipe, 'r')				
	steps = file1.readlines()							
	file1.close()
	steps.pop(0)			
	for idx, i in enumerate(steps):
		if steps[idx].endswith('\n'):					
			steps[idx] = steps[idx][:-1]
	commands.clear() 									
	for step in steps:									
		list = step.split(',')							
		time = int(int(list[1]) * gl.TIME_PER_ML)		
		plug = plugs.index(list[0])						
		print("[DR SM]", "Plug:", plug,"corresponding drink:" , list[0])
		commands.append("o" + str(plug))				
		commands.append("t" + str(time))				
		commands.append("w")							
		commands.append("c" + str(plug))				
	commands.append("o0")								
	commands.append("t" + str(gl.CLEANING_TIME))
	commands.append("w")
	commands.append("c0")
	commands.append("e")					
	print("[DR SM] compiling done")
	print("[DR SM] commands:")
	for c in commands:
		print(c)
	is_mixing = True
	recipe_step = 0
def start_mixing ( recipe ) : global is_mixing , recipe_step , commands , recipes if is_mixing : return print ( "[DR SM]" , "1/4 no other recipe mixing" ) if type ( recipe ) != int and type ( recipe ) != str : return print ( "[DR SM]" , "2/4 correct input type" ) if type ( recipe ) == int : recipe = recipes [ recipe ] print ( "[DR SM]" , "3/4 got recipe name from index (if needed)" ) if not _test_availability ( recipe ) : return print ( "[DR SM]" , "4/4 recipe is available" ) print ( "[DR SM]" , "all checks passed, compiling recipe" ) file1 = open ( dir_recipes + recipe , 'r' ) steps = file1 . readlines ( ) file1 . close ( ) steps . pop ( 0 ) for idx , i in enumerate ( steps ) : if steps [ idx ] . endswith ( '\n' ) : steps [ idx ] = steps [ idx ] [ : - 1 ] commands . clear ( ) """ compile recipe """ for step in steps : list = step . split ( ',' ) time = int ( int ( list [ 1 ] ) * gl . TIME_PER_ML ) plug = plugs . index ( list [ 0 ] ) print ( "[DR SM]" , "Plug:" , plug , "corresponding drink:" , list [ 0 ] ) commands . append ( "o" + str ( plug ) ) commands . append ( "t" + str ( time ) ) commands . append ( "w" ) commands . append ( "c" + str ( plug ) ) commands . append ( "o0" ) commands . append ( "t" + str ( gl . CLEANING_TIME ) ) commands . append ( "w" ) commands . append ( "c0" ) commands . append ( "e" ) print ( "[DR SM] compiling done" ) print ( "[DR SM] commands:" ) for c in commands : print ( c ) is_mixing = True recipe_step = 0
compiles the recipe and starts the mixing process.
compiles the recipe and starts the mixing process .
""" compiles the recipe and starts the mixing process.
	recipe: EITHER as string with recipe name OR as int with index in recipes list
	""" # break, when there's already a recipe mixing # break when input type not correct # get recipe name when index given # break when recipe not available # open file # save steps as a list # remove info line # remove trailing newline characters # delete previous commands """ compile recipe """ # compile step by step # [<drink>, <volume>] # calculate needed time	(in ms) # get the plug # open valve # set timer # wait for timer to pass # close valve # cleaning procedure. this will pump some water through to clean the pipes # end sign # start the mixing process
recipe