From aa856e24048e603e559a8241837db36280541db6 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 5 Dec 2018 13:58:12 +0100 Subject: [PATCH] shift presets --- server.py | 2 +- static/index.html | 8 ++- static/js/cccc.js | 102 +++++++++++++++++++++++++++++++++----- static/shift_presets.html | 33 ++++++++++++ 4 files changed, 131 insertions(+), 14 deletions(-) create mode 100644 static/shift_presets.html diff --git a/server.py b/server.py index 78d9109..a7e169d 100755 --- a/server.py +++ b/server.py @@ -110,7 +110,7 @@ class API(object): def camera(self, **data): result = {} for key, value in data.items(): - getattr(ctl.camera, key)(**value) + result[key] = getattr(ctl.camera, key)(**value) return result def run(self, **data): diff --git a/static/index.html b/static/index.html index f323516..3bda12c 100644 --- a/static/index.html +++ b/static/index.html @@ -1,7 +1,7 @@ - + CAMP can capture canals @@ -104,6 +104,7 @@

Import:

  • import sequence
  • import presets
  • +
  • @@ -122,5 +123,10 @@ + diff --git a/static/js/cccc.js b/static/js/cccc.js index 5189586..c874d3d 100644 --- a/static/js/cccc.js +++ b/static/js/cccc.js @@ -53,16 +53,20 @@ if (value == null || value == undefined || !value.length || !isInt(value)) { var presets = []; +function presetSelect() { + var options = '' + presets.forEach(function(preset) { + options += ''; + }) + return $('') +} + function PresetEditor(args) { var $preset; var scope = this; this.init = function () { - var options = '' - presets.forEach(function(preset) { - options += ''; - }) - $preset = $('') + $preset = presetSelect() .appendTo(args.container); scope.focus(); }; @@ -353,14 +357,28 @@ function updateStatus() { $('button.delete').attr({disabled: !gotSelection}) } -$(function () { - api('getPresets', {}, function(response) { - presets = response.result.presets - loadData(JSON.parse(localStorage.sequence || '[]')) - updateStatus() - setInterval(updateStatus, 1000) + +var preset_offset = {}, current_position = {}; + +function updateShiftStatus() { + api('camera', { + 'status': {} + }, function(response) { + if (response.result) { + if (response.result.status) { + current_position = response.result.status; + var preset = presets[parseInt($('select[name=preset-editor]').val(), 10)]; + preset_offset['azimuth'] = preset['position']['azimuth'] - current_position['azimuth']; + preset_offset['elevation'] = preset['position']['elevation'] - current_position['elevation']; + preset_offset['absoluteZoom'] = preset['position']['absoluteZoom'] - current_position['absoluteZoom']; + updateDelta() + } + } }) -}) +} +function updateDelta() { + $('#delta').html(JSON.stringify(preset_offset, null, ' ')) +} function deleteRows() { var result = confirm("Are you sure you want to delete " + grid.getSelectedRows().length + " row(s)?"); @@ -480,6 +498,10 @@ $('button.export_presets').on({click: function() { href: url, download: 'presets.json' }); }}) +$('button.shift_presets').on({click: function() { + document.location.href = '/static/shift_presets.html'; +}}); + $('button.all_presets').on({click: function() { api('getPresets', {}, function(response) { presets = response.result.presets @@ -518,3 +540,59 @@ $('input.import_presets').on({change: function() { } reader.readAsText(this.files[0]); }}) + + +function shiftPresets(offset, callback) { + api('getPresets', {}, function(response) { + presets = response.result.presets + presets.forEach(function(preset) { + if (offset.azimuth) { + preset['position']['azimuth'] += offset.azimuth + } + if (offset.elevation) { + preset['position']['elevation'] += offset.elevation + } + if (offset.absoluteZoom) { + preset['position']['absoluteZoom'] += offset.absoluteZoom + } + }) + api('setPresets', { + 'presets': presets + }, function(response) { + presets = response.result.presets + callback && callback() + }) + }) + +} + +function init() { + api('getPresets', {}, function(response) { + presets = response.result.presets + loadData(JSON.parse(localStorage.sequence || '[]')) + updateStatus() + setInterval(updateStatus, 1000) + }) +} + +function init_shift() { + api('getPresets', {}, function(response) { + presets = response.result.presets + presetSelect().on({ + change: updateShiftStatus + }).appendTo($('body')) + $('
    ').attr({id: 'delta'}).appendTo($('body'))
    +        $('