from . import boardtype

import pytest


def read_firmware_version():
    with open('/sys/kernel/debug/edt_ft5x06/fw_version') as f:
        return int(f.read())


@pytest.mark.skipif(not boardtype.is_librem5(), reason="Not a phone")
@pytest.mark.skipif(abs(read_firmware_version()) > 100,
                    reason="Firmware version only readable while screen on.")
def test_firmware_version():
    assert(read_firmware_version() == 3)


def test_touch_controller():
    if boardtype.is_librem5():
        match = 'N: Name="generic ft5x06'
    else:
        match = 'N: Name="Goodix Capacitive TouchScreen'
    assert(match in open("/proc/bus/input/devices").read())
