def bumper(instructions): print "Bumper" instruction_counter = 0 while instruction_counter < len(instructions.main_list): instruction_id = instructions.main_list[instruction_counter] print instruction_id if instruction_id == api.GOTO_START: instruction_counter = 0 continue elif instruction_id == api.DONE: break print "about to do instructions" interrupt = api.do_instruction(instruction_id) print "interrupt" if interrupt == api.GO_BUTTON_INTERRUPT: # Restart Program instruction_counter = 0 continue elif interrupt == api.SWITCH_STATE_INTERRUPT: # Switch state break elif interrupt == api.LEFT_BUMPER_INTERRUPT and instructions.left_bumper is not None: bumper(instructions.left_bumper) elif interrupt == api.RIGHT_BUMPER_INTERRUPT and instructions.right_bumper is not None: bumper(instructions.right_bumper) else: instruction_counter += 1
def play(): GPIO.output(api.PROGRAM_BUZZER_ID, True) time.sleep(0.3) GPIO.output(api.PROGRAM_BUZZER_ID, False) GPIO.output(api.RED_LED_ID, False) GPIO.output(api.GREEN_LED_ID, True) f = open("instructions.json", "r") json_dict = json.loads(f.read()) f.close() instructions = api.json_dict_to_instruction_list(json_dict) instruction_counter = 0 while instruction_counter < len(instructions.main_list): instruction_id = instructions.main_list[instruction_counter] print instruction_id, instruction_counter if instruction_id == api.GOTO_START: if GPIO.input(api.PROGRAM_SWITCH_ID): break instruction_counter = 0 continue elif instruction_id == api.DONE: break interrupt = api.do_instruction(instruction_id) if interrupt == api.GO_BUTTON_INTERRUPT: # Restart Program instruction_counter = 0 continue elif interrupt == api.SWITCH_STATE_INTERRUPT: # Switch state break elif interrupt == api.LEFT_BUMPER_INTERRUPT and instructions.left_bumper is not None: bumper(instructions.left_bumper) elif interrupt == api.RIGHT_BUMPER_INTERRUPT and instructions.right_bumper is not None: bumper(instructions.right_bumper) else: instruction_counter += 1 while True: if (GPIO.input(api.GO_BUTTON_ID)) or (GPIO.input(api.PROGRAM_SWITCH_ID)): break