diff --git a/asus_fliplock.py b/asus_fliplock.py index 248133c..b676cd2 100755 --- a/asus_fliplock.py +++ b/asus_fliplock.py @@ -3,6 +3,7 @@ import importlib import logging import os +from time import sleep import re import sys from typing import Optional @@ -41,7 +42,7 @@ def search_devices(): with open('/proc/bus/input/devices', 'r') as f: lines = f.readlines() for line in lines: - + # Look for the device switches if re.search("switches", line): switches_detected = 1 @@ -71,12 +72,13 @@ def search_devices(): if switches_detected == 2 and wmi_hotkeys_detected == 2: break - if switches_detected != 2: + if switches_detected != 2 or wmi_hotkeys_detected != 2: tries -= 1 if tries == 0: if switches_detected != 2 and wmi_hotkeys_detected != 2: log.error("Can't find neither switches or wmi hotkeys device") sys.exit(1) + sleep(0.1) else: break @@ -104,14 +106,14 @@ def execute_cmds_in_array(cmds): execute_cmd(cmd) -def flip(intel_hid_switches_tablet_mode): +def flip(intel_hid_switches_tablet_mode): if intel_hid_switches_tablet_mode: execute_cmds_in_array(fliplock_layouts.tablet_mode_actions) else: execute_cmds_in_array(fliplock_layouts.laptop_mode_actions) -# If mode has been changed, do something +# If mode has been changed, do something if switches is None and wmi_hotkeys is not None: for e in d_t_wmi_hotkeys.events(): @@ -126,6 +128,7 @@ def flip(intel_hid_switches_tablet_mode): flip(intel_hid_switches_tablet_mode) intel_hid_switches_tablet_mode = not intel_hid_switches_tablet_mode + # TODO: first flip is ommited because device for swithes is added immediately when is flip_key (usually EV_KEY.KEY_PROG2) triggered search_devices()