def main(): print("Enter 0 to exit") while True: try: user_input = input("Enter a 9X command: ") if user_input == '0': return encoded = GwtSUtils.encode9x(user_input) print(GwtSUtils.int_array_to_hex_str(encoded)) # Displays 9x computed command print(GwtSUtils.ir_fancy_format(GwtSUtils.encode_ir(encoded))) # Displays IR on/off timings except ValueError: print("Bad input")
def check_command(command): """ Checks 9X and 55 commands to make sure they're correct. :param command []String 9X or 55 command :return Boolean True if it's a correct command and False if not. """ if len(command) < 5: return False if command[0][0] == "9": calculated_command = GwtSUtils.int_array_to_hex_str(GwtSUtils.encode9x(" ".join(command[1:-1]))) elif command[0][0] == "5": calculated_command = GwtSUtils.int_array_to_hex_str(GwtSUtils.encode55(" ".join(command[2:-1]))) else: return False if calculated_command == " ".join(command): return True return False
print(GwtSUtils.ir_fancy_format(GwtSUtils.encode_ir(encoded))) # Displays IR on/off timings except ValueError: print("Bad input") # Show Sequencer if len(sys.argv) > 1: input_commands = list() command_dict = dict() # Open, format, and put file contents into input_commands with open(sys.argv[1], 'r') as input_file: for line in input_file: input_commands.append(line.replace(':', '').split()) # Process input_commands and add to dictionary to resolve timing conflicts. for line in input_commands: times = (GwtSUtils.generate_delays(line)) for key, content in times.items(): if key in command_dict.keys(): command_dict[key].extend(content) # Commands with same timing played right after each other # command_dict[key] = content # Newer commands overwrite older commands. else: command_dict[key] = content # Write to file try: output = open(sys.argv[2], 'w') except IndexError: # Use default filename if no output filename supplied output = open("output.txt", 'w') for key, content in sorted(command_dict.items()): output.write(key + ": " + " ".join(content) + "\n") output.close() sys.exit()
def encode9x(command): """ Encodes a 9X command with correct 9X length code and CRC. :param command String 9X command without :return String Encoded 9X command """ return GwtSUtils.int_array_to_hex_str(GwtSUtils.encode9x(command))