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
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 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))