From: Calin Crisan Date: Sun, 13 Oct 2013 14:28:05 +0000 (+0300) Subject: added support for missing controls X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=5d5e5e24603e420074ba6bd1f3dc214b27138c52;p=motioneye-debian added support for missing controls --- diff --git a/doc/todo.txt b/doc/todo.txt index fc9ed42..ba8767a 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,6 +1,6 @@ --> picam2 : nu avem hue si da eroare -> picam2: zeroconf refreshEnabled == 1 --> change password: refresh asks for auth +-> change password: refresh asks for auth +-> js framerate should be the minimum between the two framerates -> style scroll bars -> hint text next to section titles diff --git a/src/handlers.py b/src/handlers.py index 765607d..6adc154 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -144,12 +144,10 @@ class ConfigHandler(BaseHandler): if remote_ui_config is None: return self.finish_json({'error': 'Failed to get remote camera configuration.'}) - tmp_config = self._camera_ui_to_dict(remote_ui_config) - tmp_config.update(camera_config) - ui_config = self._camera_dict_to_ui(tmp_config) - ui_config['available_resolutions'] = remote_ui_config['available_resolutions'] + for key, value in camera_config.items(): + remote_ui_config[key.replace('@', '')] = value - self.finish_json(ui_config) + self.finish_json(remote_ui_config) remote.get_config( camera_config.get('@host'), @@ -483,10 +481,6 @@ class ConfigHandler(BaseHandler): 'videodevice': ui.get('device', ''), 'lightswitch': int(ui.get('light_switch_detect', False)) * 5, 'auto_brightness': ui.get('auto_brightness', False), - 'brightness': max(1, int(round(int(ui.get('brightness', 0)) * 2.55))), - 'contrast': max(1, int(round(int(ui.get('contrast', 0)) * 2.55))), - 'saturation': max(1, int(round(int(ui.get('saturation', 0)) * 2.55))), - 'hue': max(1, int(round(int(ui.get('hue', 0)) * 2.55))), 'width': int(ui['resolution'].split('x')[0]), 'height': int(ui['resolution'].split('x')[1]), 'framerate': int(ui.get('framerate', 1)), @@ -545,6 +539,18 @@ class ConfigHandler(BaseHandler): '@working_schedule': '' } + if 'brightness' in ui: + data['brightness'] = max(1, int(round(int(ui.get('brightness', 0)) * 2.55))) + + if 'contrast' in ui: + data['contrast'] = max(1, int(round(int(ui.get('contrast', 0)) * 2.55))) + + if 'saturation' in ui: + data['saturation'] = max(1, int(round(int(ui.get('saturation', 0)) * 2.55))) + + if 'hue' in ui: + data['hue'] = max(1, int(round(int(ui.get('hue', 0)) * 2.55))) + if ui.get('text_overlay', False): left_text = ui.get('left_text', 'camera-name') if left_text == 'camera-name': @@ -622,10 +628,6 @@ class ConfigHandler(BaseHandler): 'device': device_uri, 'light_switch_detect': data.get('lightswitch') > 0, 'auto_brightness': data.get('auto_brightness'), - 'brightness': int(round(int(data.get('brightness')) / 2.55)), - 'contrast': int(round(int(data.get('contrast')) / 2.55)), - 'saturation': int(round(int(data.get('saturation')) / 2.55)), - 'hue': int(round(int(data.get('hue')) / 2.55)), 'resolution': str(data.get('width')) + 'x' + str(data.get('height')), 'framerate': int(data.get('framerate')), 'rotation': int(data.get('rotate')), @@ -690,20 +692,36 @@ 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']) + brightness = v4l2ctl.get_brightness(ui['device']) + if brightness is not None: + ui['brightness'] = brightness - if ui['saturation'] == 0: - ui['saturation'] = v4l2ctl.get_saturation(ui['device']) + contrast = v4l2ctl.get_contrast(ui['device']) + if contrast is not None: + ui['contrast'] = contrast - if ui['hue'] == 0: - ui['hue'] = v4l2ctl.get_hue(ui['device']) + saturation = v4l2ctl.get_saturation(ui['device']) + if saturation is not None: + ui['saturation'] = saturation + hue = v4l2ctl.get_hue(ui['device']) + if hue is not None: + ui['hue'] = hue + + else: + if 'brightness' in data: + ui['brightness'] = data['brightness'] + + if 'contrast' in data: + ui['contrast'] = data['contrast'] + + if 'saturation' in data: + ui['saturation'] = data['saturation'] + + if 'hue' in data: + ui['hue'] = data['hue'] + text_left = data.get('text_left') text_right = data.get('text_right') if text_left or text_right: diff --git a/src/remote.py b/src/remote.py index b885432..0a3d9cc 100644 --- a/src/remote.py +++ b/src/remote.py @@ -120,9 +120,9 @@ def set_preview(host, port, username, password, camera_id, controls, callback): 'host': host, 'port': port}) - controls = json.dumps(controls) + data = json.dumps(controls) - request = _make_request(host, port, username, password, '/config/%(id)s/set_preview/' % {'id': camera_id}) + request = _make_request(host, port, username, password, '/config/%(id)s/set_preview/' % {'id': camera_id}, method='POST', data=data) def on_response(response): if response.error: diff --git a/static/js/main.js b/static/js/main.js index b14f3dc..bf6403d 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -305,6 +305,13 @@ function updateConfigUi() { objs.each(unmarkHide); + /* sliders */ + $('input.range').each(function () { + if (this.value === '' || this.value == null) { + $(this).parents('tr:eq(0)').each(markHide); + } + }); + /* general enable switch */ var motionEyeEnabled = $('#motionEyeSwitch').get(0).checked; if (!motionEyeEnabled) { @@ -455,7 +462,7 @@ function dict2MainUi(dict) { } function cameraUi2Dict() { - return { + var dict = { /* video device */ 'enabled': $('#videoDeviceSwitch')[0].checked, 'name': $('#deviceNameEntry').val(), @@ -463,10 +470,6 @@ function cameraUi2Dict() { 'device': $('#deviceEntry').val().split('://')[1], 'light_switch_detect': $('#lightSwitchDetectSwitch')[0].checked, 'auto_brightness': $('#autoBrightnessSwitch')[0].checked, - 'brightness': $('#brightnessSlider').val(), - 'contrast': $('#contrastSlider').val(), - 'saturation': $('#saturationSlider').val(), - 'hue': $('#hueSlider').val(), 'resolution': $('#resolutionSelect').val(), 'rotation': $('#rotationSelect').val(), 'framerate': $('#framerateSlider').val(), @@ -537,6 +540,24 @@ function cameraUi2Dict() { 'sunday_from': $('#sundayFrom').val(), 'sunday_to': $('#sundayTo').val(), }; + + if ($('#brightnessSlider').val() !== '') { + dict.brightness = $('#brightnessSlider').val(); + } + + if ($('#contrastSlider').val() !== '') { + dict.contrast = $('#contrastSlider').val(); + } + + if ($('#saturationSlider').val() !== '') { + dict.saturation = $('#saturationSlider').val(); + } + + if ($('#hueSlider').val() !== '') { + dict.hue = $('#hueSlider').val(); + } + + return dict; } function dict2CameraUi(dict) { @@ -546,11 +567,12 @@ function dict2CameraUi(dict) { $('#deviceEntry').val(dict['proto'] + '://' + dict['device']); $('#lightSwitchDetectSwitch')[0].checked = dict['light_switch_detect']; $('#autoBrightnessSwitch')[0].checked = dict['auto_brightness']; + $('#brightnessSlider').val(dict['brightness']); $('#contrastSlider').val(dict['contrast']); $('#saturationSlider').val(dict['saturation']); $('#hueSlider').val(dict['hue']); - + $('#resolutionSelect').html(''); dict['available_resolutions'].forEach(function (resolution) { $('#resolutionSelect').append(''); @@ -857,12 +879,23 @@ function pushPreview() { var saturation = $('#saturationSlider').val(); var hue = $('#hueSlider').val(); - var data = { - 'brightness': brightness, - 'contrast': contrast, - 'saturation': saturation, - 'hue': hue - }; + var data = {}; + + if (brightness !== '') { + data.brightness = brightness; + } + + if (contrast !== '') { + data.contrast = contrast; + } + + if (saturation !== '') { + data.saturation = saturation; + } + + if (hue !== '') { + data.hue = hue; + } refreshDisabled++;