def record(): GPIO.output(api.RED_LED_ID, True) GPIO.output(api.GREEN_LED_ID, False) instructions = InstructionList.InstructionList() last_nfc = None # While we are set to record state and the user hasn't finalized the program while GPIO.input(api.PROGRAM_SWITCH_ID) == 1 and not GPIO.input(api.GO_BUTTON_ID): print "Recording" nfc = hardware_api.get_nfc() if last_nfc is not None and last_nfc == nfc: continue elif nfc is not None: print "Appending Instruction" print nfc instruction_id = int(nfc, 16) instructions.append_instruction(instruction_id) # buzz the buzzer GPIO.output(api.PROGRAM_BUZZER_ID, True) time.sleep(0.1) GPIO.output(api.PROGRAM_BUZZER_ID, False) if GPIO.input(api.GO_BUTTON_ID) == 1: print "Programmed" GPIO.output(api.PROGRAM_BUZZER_ID, True) time.sleep(0.3) GPIO.output(api.PROGRAM_BUZZER_ID, False) # Overwrite instruction file f = open("instructions.json", "w") f.write(api.instruction_list_to_json(instructions)) f.close() break last_nfc = nfc
__author__ = 'ben' import api import InstructionList import json instructions = InstructionList.InstructionList() instructions.append_instruction(api.MOVE_FORWARD) instructions.append_instruction(api.LEFT_BUMPER_START) instructions.append_instruction(api.MOVE_BACKWARDS) instructions.append_instruction(api.PIVOT_RIGHT) instructions.append_instruction(api.LEFT_BUMPER_END) instructions.append_instruction(api.BEEP) instructions.append_instruction(api.RIGHT_BUMPER_START) instructions.append_instruction(api.DONE) instructions.append_instruction(api.RIGHT_BUMPER_END) instructions.append_instruction(api.GOTO_START) f = open('test_json.json', 'w') json_string = api.instruction_list_to_json(instructions) f.write(json_string) f.close() api.json_dict_to_instruction_list(json.loads(json_string))