From 96df8b9a7eabb2870876eaefc38a06b38b0c32c9 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 12 Apr 2015 17:49:24 +0300 Subject: [PATCH] use persistent video device paths rather than generic /dev/video* ones --- src/v4l2ctl.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/v4l2ctl.py b/src/v4l2ctl.py index e760efb..8c17bd9 100644 --- a/src/v4l2ctl.py +++ b/src/v4l2ctl.py @@ -17,7 +17,7 @@ import fcntl import logging -import os +import os.path import re import stat import subprocess @@ -28,6 +28,8 @@ _resolutions_cache = {} _ctrls_cache = {} _ctrl_values_cache = {} +_DEV_V4L_BY_ID = '/dev/v4l/by-id/' + def find_v4l2_ctl(): try: @@ -87,6 +89,7 @@ def list_devices(): for line in output.split('\n'): if line.startswith('\t'): device = line.strip() + device = find_persistent_device(device) devices.append((device, name)) logging.debug('found device %(name)s: %(device)s' % { @@ -201,6 +204,21 @@ def device_present(device): except: return False + + +def find_persistent_device(device): + try: + devs_by_id = os.listdir(_DEV_V4L_BY_ID) + + except OSError: + return device + + for p in devs_by_id: + p = os.path.join(_DEV_V4L_BY_ID, p) + if os.path.realpath(p) == device: + return p + + return device def get_brightness(device): -- 2.39.5