code/io_lib.py
def update_input():
	""" update all  / reads the input and stores it to be returned by read_input() """
	global UP, DOWN, LEFT, RIGHT, NEXT, BACK, pygame_events
	global up_state, down_state, left_state, right_state, next_state, back_state
	global up_state_prev, down_state_prev, left_state_prev, right_state_prev, next_state_prev, back_state_prev


	if gl.os_is_linux:
		global UP_BT, DOWN_BT, LEFT_BT, RIGHT_BT, NEXT_BT, BACK_BT		

	# refresh previous states
	up_state_prev, down_state_prev, left_state_prev, right_state_prev, next_state_prev, back_state_prev = up_state, down_state, left_state, right_state, next_state, back_state

	# read current state
	if gl.os_is_linux:				# for the raspberry pi / buttons on gpio
		up_state	= not UP_BT.is_pressed			# read every input
		down_state	= not DOWN_BT.is_pressed
		left_state	= not LEFT_BT.is_pressed
		right_state	= not RIGHT_BT.is_pressed
		next_state	= not NEXT_BT.is_pressed
		back_state	= not BACK_BT.is_pressed

	# for keyboard
	for event in pygame_events:
		if event.type == pygame.KEYDOWN:		# if pressed down
			if(event.key == pygame.K_UP):		up_state 	= True
			if(event.key == pygame.K_DOWN):		down_state 	= True
			if(event.key == pygame.K_LEFT):		left_state 	= True
			if(event.key == pygame.K_RIGHT):	right_state = True
			if(event.key == pygame.K_RETURN):	next_state 	= True
			if(event.key == pygame.K_DELETE):	back_state 	= True
		if event.type == pygame.KEYUP:			# if released
			if(event.key == pygame.K_UP):		up_state 	= False
			if(event.key == pygame.K_DOWN):		down_state 	= False
			if(event.key == pygame.K_LEFT):		left_state 	= False
			if(event.key == pygame.K_RIGHT):	right_state = False
			if(event.key == pygame.K_RETURN):	next_state 	= False
			if(event.key == pygame.K_DELETE):	back_state 	= False

	
		# check for credits (activate by either pressing all button down at once or pressing tab)
		# it only test for one key first to save time
		if (not up_state and gl.os_is_linux == True) or (event.type == pygame.KEYDOWN and event.key == pygame.K_TAB):
			if not down_state and not left_state and not right_state and not next_state and not back_state or (event.type == pygame.KEYDOWN and event.key == pygame.K_TAB):
				print("[IO UI] go to credits")
				gl.cr_prev_pos = gl.prog_pos
				gl.prog_pos = 'cr'
 update all  / reads the input and stores it to be returned by read_input() 
update all  / reads the input and stores it to be returned by read_input()
update all / reads the input and stores it to be returned by read_input ()
def update_input():
	global UP, DOWN, LEFT, RIGHT, NEXT, BACK, pygame_events
	global up_state, down_state, left_state, right_state, next_state, back_state
	global up_state_prev, down_state_prev, left_state_prev, right_state_prev, next_state_prev, back_state_prev
	if gl.os_is_linux:
		global UP_BT, DOWN_BT, LEFT_BT, RIGHT_BT, NEXT_BT, BACK_BT		
	up_state_prev, down_state_prev, left_state_prev, right_state_prev, next_state_prev, back_state_prev = up_state, down_state, left_state, right_state, next_state, back_state
	if gl.os_is_linux:				
		up_state	= not UP_BT.is_pressed			
		down_state	= not DOWN_BT.is_pressed
		left_state	= not LEFT_BT.is_pressed
		right_state	= not RIGHT_BT.is_pressed
		next_state	= not NEXT_BT.is_pressed
		back_state	= not BACK_BT.is_pressed
	for event in pygame_events:
		if event.type == pygame.KEYDOWN:		
			if(event.key == pygame.K_UP):		up_state 	= True
			if(event.key == pygame.K_DOWN):		down_state 	= True
			if(event.key == pygame.K_LEFT):		left_state 	= True
			if(event.key == pygame.K_RIGHT):	right_state = True
			if(event.key == pygame.K_RETURN):	next_state 	= True
			if(event.key == pygame.K_DELETE):	back_state 	= True
		if event.type == pygame.KEYUP:			
			if(event.key == pygame.K_UP):		up_state 	= False
			if(event.key == pygame.K_DOWN):		down_state 	= False
			if(event.key == pygame.K_LEFT):		left_state 	= False
			if(event.key == pygame.K_RIGHT):	right_state = False
			if(event.key == pygame.K_RETURN):	next_state 	= False
			if(event.key == pygame.K_DELETE):	back_state 	= False
		if (not up_state and gl.os_is_linux == True) or (event.type == pygame.KEYDOWN and event.key == pygame.K_TAB):
			if not down_state and not left_state and not right_state and not next_state and not back_state or (event.type == pygame.KEYDOWN and event.key == pygame.K_TAB):
				print("[IO UI] go to credits")
				gl.cr_prev_pos = gl.prog_pos
				gl.prog_pos = 'cr'
def update_input ( ) : global UP , DOWN , LEFT , RIGHT , NEXT , BACK , pygame_events global up_state , down_state , left_state , right_state , next_state , back_state global up_state_prev , down_state_prev , left_state_prev , right_state_prev , next_state_prev , back_state_prev if gl . os_is_linux : global UP_BT , DOWN_BT , LEFT_BT , RIGHT_BT , NEXT_BT , BACK_BT up_state_prev , down_state_prev , left_state_prev , right_state_prev , next_state_prev , back_state_prev = up_state , down_state , left_state , right_state , next_state , back_state if gl . os_is_linux : up_state = not UP_BT . is_pressed down_state = not DOWN_BT . is_pressed left_state = not LEFT_BT . is_pressed right_state = not RIGHT_BT . is_pressed next_state = not NEXT_BT . is_pressed back_state = not BACK_BT . is_pressed for event in pygame_events : if event . type == pygame . KEYDOWN : if ( event . key == pygame . K_UP ) : up_state = True if ( event . key == pygame . K_DOWN ) : down_state = True if ( event . key == pygame . K_LEFT ) : left_state = True if ( event . key == pygame . K_RIGHT ) : right_state = True if ( event . key == pygame . K_RETURN ) : next_state = True if ( event . key == pygame . K_DELETE ) : back_state = True if event . type == pygame . KEYUP : if ( event . key == pygame . K_UP ) : up_state = False if ( event . key == pygame . K_DOWN ) : down_state = False if ( event . key == pygame . K_LEFT ) : left_state = False if ( event . key == pygame . K_RIGHT ) : right_state = False if ( event . key == pygame . K_RETURN ) : next_state = False if ( event . key == pygame . K_DELETE ) : back_state = False if ( not up_state and gl . os_is_linux == True ) or ( event . type == pygame . KEYDOWN and event . key == pygame . K_TAB ) : if not down_state and not left_state and not right_state and not next_state and not back_state or ( event . type == pygame . KEYDOWN and event . key == pygame . K_TAB ) : print ( "[IO UI] go to credits" ) gl . cr_prev_pos = gl . prog_pos gl . prog_pos = 'cr'
update all  / reads the input and stores it to be returned by read_input()
update all / reads the input and stores it to be returned by read_input ()
""" update all  / reads the input and stores it to be returned by read_input() """ # refresh previous states # read current state # for the raspberry pi / buttons on gpio # read every input # for keyboard # if pressed down # if released # check for credits (activate by either pressing all button down at once or pressing tab) # it only test for one key first to save time