From d774a6723a8830ae12ff3892ba5894b25cfabe63 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 13 Oct 2013 11:54:57 +0300 Subject: [PATCH] added getters for v4l2 controls --- doc/todo.txt | 3 +++ src/config.py | 12 ++++++------ src/handlers.py | 14 ++++++++++++++ src/v4l2ctl.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/doc/todo.txt b/doc/todo.txt index 8b72347..50b7e7a 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,3 +1,6 @@ +-> default sat/contrast/hue... for existing conf file is somehow 0 +-> request closed while setting the preview params +-> applying progress sometimes does not appear on frame -> style scroll bars -> hint text next to section titles diff --git a/src/config.py b/src/config.py index fab798c..e558630 100644 --- a/src/config.py +++ b/src/config.py @@ -522,16 +522,16 @@ def _set_default_motion(data): def _set_default_motion_camera(data): - data.setdefault('@name', '') + data.setdefault('@name', 'My Camera') data.setdefault('@enabled', False) data.setdefault('@proto', 'v4l2') - data.setdefault('videodevice', '') + data.setdefault('videodevice', '/dev/video0') data.setdefault('lightswitch', 0) data.setdefault('auto_brightness', True) - data.setdefault('brightness', 127) - data.setdefault('contrast', 127) - data.setdefault('saturation', 127) - data.setdefault('hue', 127) + data.setdefault('brightness', 0) + data.setdefault('contrast', 0) + data.setdefault('saturation', 0) + data.setdefault('hue', 0) data.setdefault('width', 352) data.setdefault('height', 288) data.setdefault('framerate', 5) diff --git a/src/handlers.py b/src/handlers.py index 6980c86..765607d 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -690,6 +690,20 @@ class ConfigHandler(BaseHandler): 'sunday_from': '09:00', 'sunday_to': '17:00' } + # null values for brightness & co. mean current values + if ui['proto'] == 'v4l2': + if ui['brightness'] == 0: + ui['brightness'] = v4l2ctl.get_brightness(ui['device']) + + if ui['contrast'] == 0: + ui['contrast'] = v4l2ctl.get_contrast(ui['device']) + + if ui['saturation'] == 0: + ui['saturation'] = v4l2ctl.get_saturation(ui['device']) + + if ui['hue'] == 0: + ui['hue'] = v4l2ctl.get_hue(ui['device']) + text_left = data.get('text_left') text_right = data.get('text_right') if text_left or text_right: diff --git a/src/v4l2ctl.py b/src/v4l2ctl.py index 52f4258..fa294da 100644 --- a/src/v4l2ctl.py +++ b/src/v4l2ctl.py @@ -50,22 +50,66 @@ def list_resolutions(device): return list(sorted(resolutions, key=lambda r: (r[0], r[1]))) +def get_brightness(device): + return _get_ctrl(device, 'brightness') + + def set_brightness(device, value): _set_ctrl(device, 'brightness', value) +def get_contrast(device): + return _get_ctrl(device, 'contrast') + + def set_contrast(device, value): _set_ctrl(device, 'contrast', value) +def get_saturation(device): + return _get_ctrl(device, 'saturation') + + def set_saturation(device, value): _set_ctrl(device, 'saturation', value) +def get_hue(device): + return _get_ctrl(device, 'hue') + + def set_hue(device, value): _set_ctrl(device, 'hue', value) +def _get_ctrl(device, control): + controls = _list_ctrls(device) + properties = controls.get(control) + if properties is None: + logging.warn('control %(control)s not found for device %(device)s' % { + 'control': control, 'device': device}) + + return None + + value = int(properties['value']) + + # adjust the value range + if 'min' in properties and 'max' in properties: + min_value = int(properties['min']) + max_value = int(properties['max']) + + value = int((value - min_value) * 100.0 / (max_value - min_value)) + + else: + logging.warn('min and max values not found for control %(control)s of device %(device)s' % { + 'control': control, 'device': device}) + + logging.debug('control %(control)s of device %(device)s is %(value)s%%' % { + 'control': control, 'device': device, 'value': value}) + + return value + + def _set_ctrl(device, control, value): controls = _list_ctrls(device) properties = controls.get(control) -- 2.39.5