def switch_mode(devices, mode): """ Call the mode's configuration routine defined in the tc module based on the mode. devices: the devices we modify mode: the mode the device is in return: whether the operation was a success """ ret = False if "tablet" in mode: if mode.startswith("i"): ret = tc.set_tablet(devices, "inverted") elif mode.startswith("l"): ret = tc.set_tablet(devices, "left") elif mode.startswith("r"): ret = tc.set_tablet(devices, "right") else: if mode == "tent": ret = tc.set_tent(devices) elif mode == "scratchpad": ret = tc.set_scratchpad(devices) elif mode == "normal": ret = tc.set_normal(devices) return ret
def main(conf="/etc/autotablet/inputDevices.json"): devices = tc.load_device_configuration(conf) # print("Found accelerometers: " + str(accelerometers)) accels = acmon.get_acceleromters("/sys/bus/iio/devices/") previous = "unknown" try: while(acmon.accels_readable(accels)): for accel in accels: mode = determine_mode(accel) if mode != previous or not ok: ok = switch_mode(devices, mode) sleep(1.0) previous = mode except OSError: print("Cannot recover from error" + str(sys.exc_info()[0])) tc.set_normal(devices) acmon.close_all_accelerometers(accels) sys.exit(1) tc.set_normal(devices) acmon.close_all_accelerometers(accels)
def main(conf="/etc/autotablet/inputDevices.json"): devices = tc.load_device_configuration(conf) # print("Found accelerometers: " + str(accelerometers)) accels = acmon.get_acceleromters("/sys/bus/iio/devices/") previous = "unknown" try: while (acmon.accels_readable(accels)): for accel in accels: mode = determine_mode(accel) if mode != previous or not ok: ok = switch_mode(devices, mode) sleep(1.0) previous = mode except OSError: print("Cannot recover from error" + str(sys.exc_info()[0])) tc.set_normal(devices) acmon.close_all_accelerometers(accels) sys.exit(1) except KeyboardInterrupt: print("Terminated by user") tc.set_normal(devices) acmon.close_all_accelerometers(accels) sys.exit(0) tc.set_normal(devices) acmon.close_all_accelerometers(accels)