diff --git a/ovos_i2c_detection/__init__.py b/ovos_i2c_detection/__init__.py index d4d057e..ebbeed6 100644 --- a/ovos_i2c_detection/__init__.py +++ b/ovos_i2c_detection/__init__.py @@ -1,7 +1,7 @@ import subprocess import serial from time import sleep -from pathlib import Path +from ovos_utils.log import LOG def is_texas_tas5806(): cmd = 'i2cdetect -y -a 1 0x2f 0x2f | egrep "(2f|UU)" | awk \'{print $2}\'' @@ -58,24 +58,24 @@ def is_adafruit_amp(): def is_mark_1(): if is_wm8960(): - SER_PORTS = ["serial0", "ttyS0", "ttyAMA0"] try: - for port in SER_PORTS: - s_port = Path(f"/dev/{port}") - if s_port.exists(): - s_port = str(s_port) - ser = serial.Serial(s_port, 9600, timeout=5) - ser.write(b'system.version') - while True: - is_mk1 = ser.readline().decode().rstrip() - if is_mk1 and "Command" in is_mk1: - ser.close() - # This is a Mark 1 - return True - break + ser = serial.Serial("/dev/ttyAMA0", 9600, timeout=5) + ser.write(b'system.version') + while ser.is_open: + is_mk1 = ser.readline().decode().rstrip() + if is_mk1 and "Command" in is_mk1: + # Check for a version + mk1_ver = ser.readline().decode().rstrip() + # New versions of the firmware will return a version that needs read to continue + if mk1_ver: + LOG.debug(f"Firmware version {mk1_ver}") ser.close() + # This is a Mark 1 + return True ser.close() - return False - except: + ser.close() + return False + except Exception as e: + LOG.error(e) return False