update preset

This commit is contained in:
j 2020-12-05 12:55:59 +01:00
parent f1c953c615
commit b408a89c1d
2 changed files with 50 additions and 5 deletions

View File

@ -101,6 +101,11 @@ class API(object):
result['presets'] = ctl.camera.get_presets(True)
return result
def setPreset(self, **data):
result = {}
ctl.camera.set_preset(data['id'], data['name'])
return result
def setPresets(self, **data):
result = {}
ctl.camera.set_presets(data['presets'])

View File

@ -52,12 +52,29 @@ if (value == null || value == undefined || !value.length || !isInt(value)) {
}
var presets = [];
var system_presets = [
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105
];
function presetSelect() {
function presetSelect(all) {
var options = ''
presets.forEach(function(preset) {
options += '<option value="'+preset.id+'">' + preset.id + ': ' + preset.name + '</option>';
})
if (all) {
for (var id=1;id<=300;id++) {
if (system_presets.indexOf(id) == -1) {
var preset = getPreset(id)
if (preset) {
options += '<option value="'+preset.id+'">' + preset.id + ': ' + preset.name + '</option>';
} else {
options += '<option value="'+id+'">' + id + ': Preset ' + id + '</option>';
}
}
}
} else {
presets.forEach(function(preset) {
options += '<option value="'+preset.id+'">' + preset.id + ': ' + preset.name + '</option>';
})
}
return $('<select name="preset-editor">' + options + '</select>')
}
@ -679,5 +696,28 @@ function init_ptz() {
})
})
}
api('getPresets', {}, function(response) {
presets = response.result.presets
var id = 1
presetSelect(true).on({
change: event => {
id = parseInt(event.target.value)
var preset = getPreset(id)
name.val(preset ? preset.name : '')
}
}).appendTo($('body'))
var name = $('<input>').appendTo($('body'))
name.val(getPreset(id).name)
$('<button>').html('Set')
.appendTo($('body')).on({
click: function() {
var data = {}
if (name.val().length) {
data['name'] = name.val()
}
data['id'] = id
api('setPreset', data)
}
})
})
}