wipe, loop, include ptz

This commit is contained in:
j 2021-09-13 11:23:43 +02:00
parent d711133b86
commit 0883f50f25
5 changed files with 88 additions and 40 deletions

View File

@ -99,6 +99,19 @@ class Camera:
self.channel = channel
self.auth = HTTPDigestAuth(self.username, self.password)
def put_aux(self, cmd):
data = PTZData(cmd, root='PTZAux')
r = self.put('auxcontrols/1', data)
return r
def wipe(self):
cmd = {
'id': '1',
'type': 'WIPER',
'status': 'on'
}
r = self.put_aux(cmd)
def url(self, method):
return 'http://{}/ISAPI/PTZCtrl/channels/{}/{}'.format(self.ip, self.channel, method)
@ -155,53 +168,57 @@ class Camera:
time.sleep(1)
print('presets loaded')
def sequence(self, steps=[], speed=12, goto_first=True):
def sequence(self, steps=[], speed=12, goto_first=True, loop=False):
self.sequence_start = 0
if goto_first:
#self.goto_preset(steps[0], pan=100, tilt=100, zoom=100)
first = steps[0]
if isinstance(first, dict):
if 'seqid' in first and first['seqid'] not in self.segment_times:
self.segment_times[first['seqid']] = 0
first = first['preset']
self.fast_preset(first, True)
#self.goto_preset(first, pan=speed, tilt=speed)
if self.abort:
return
time.sleep(3)
steps = steps[1:]
self.sequence_start = t0 = time.time()
for step in steps:
self.next_target = step
segment_t0 = time.time()
if self.abort:
return
if isinstance(step, dict):
if 'fast' in step or ('speed' in step and step['speed'] > 100):
self.fast_preset(step.get('fast', step.get('preset')), True)
while True:
if goto_first:
if isinstance(first, dict):
if 'seqid' in first and first['seqid'] not in self.segment_times:
self.segment_times[first['seqid']] = 0
first = first['preset']
self.fast_preset(first, True)
#self.goto_preset(first, pan=speed, tilt=speed)
if self.abort:
return
time.sleep(3)
self.sequence_start = t0 = time.time()
for step in steps:
self.next_target = step
segment_t0 = time.time()
if self.abort:
return
if isinstance(step, dict):
if 'fast' in step or ('speed' in step and step['speed'] > 100):
self.fast_preset(step.get('fast', step.get('preset')), True)
else:
if 'preset' in step:
kwargs = {
'pan': step['speed'],
'tilt': step['speed'],
}
if step.get('zoom'):
kwargs['zoom'] = step['zoom']
if 'zoom_last' in step:
kwargs['zoom_last'] = step['zoom_last']
self.goto_preset(step['preset'], **kwargs)
if 'sleep' in step:
if self.abort:
return
time.sleep(float(step['sleep']))
else:
if 'preset' in step:
kwargs = {
'pan': step['speed'],
'tilt': step['speed'],
}
if step.get('zoom'):
kwargs['zoom'] = step['zoom']
if 'zoom_last' in step:
kwargs['zoom_last'] = step['zoom_last']
self.goto_preset(step['preset'], **kwargs)
if 'sleep' in step:
if self.abort:
return
time.sleep(float(step['sleep']))
else:
self.goto_preset(step, pan=speed, tilt=speed)
self.goto_preset(step, pan=speed, tilt=speed)
segment_time = time.time() - segment_t0
if isinstance(step, dict) and 'seqid' in step:
self.segment_times[step['seqid']] = segment_time
self.sequence_time = time.time() - t0
self.next_target = None
segment_time = time.time() - segment_t0
if isinstance(step, dict) and 'seqid' in step:
self.segment_times[step['seqid']] = segment_time
self.sequence_time = time.time() - t0
self.next_target = None
if not loop:
break
def fast_preset(self, id, wait=False):
self.put('presets/%s/goto' % id, None)
@ -382,3 +399,4 @@ class Camera:
preset['position'] = preset.pop('AbsoluteHigh')
preset['name'] = preset.pop('presetName')
return presets

View File

@ -174,6 +174,11 @@ class API(object):
result['sequence'] = state['sequence']
return result
def wipe(self, **data):
result = {}
ctl.camera.wipe()
return result
#@run_async
def api_task(request, callback):
api = API()

View File

@ -83,6 +83,7 @@
<h2>CAMP cam canal:</h2>
<ul>
<li><button class="run">run</button></li>
<li><button class="loop">loop</button></li>
<li><button class="goto">go to selected</button></li>
<li><button class="run_from">run from selected</button></li>
<li><button class="continue_from">continue to selected</button></li>
@ -106,6 +107,8 @@
<li><input class="import_sequence" type="file">import sequence</input></li>
<li><input class="import_presets" type="file">import presets</input></li>
<li><button class="shift_presets">shift presets</button></li>
<h2>PTZ:</h2>
<iframe src="/static/ptz.html" width="100%" height="300px" frameborder=0></iframe>
</div>
</div>

View File

@ -456,6 +456,19 @@ $('button.run').on({click: function() {
//console.log(response)
})
}})
$('button.loop').on({click: function() {
data.forEach(function(seq) {
if (!seq.seqid) {
seq.seqid = uuidv4()
}
})
api('run', {
'steps': data,
'loop': true
}, function(response) {
//console.log(response)
})
}})
$('button.run_from').on({click: function() {
var selected = grid.getSelectedRows()[0];
api('run', {

View File

@ -50,11 +50,20 @@
Speed: <input name="speed" value="1" style="width:30px"></input>
Duration: <input name="duration" value="4" style="width:30px"></input>
<br>
<br>
<li><button class="wipe">wipe</button></li>
</div>
<script>
$(function () {
init_ptz()
document.querySelector('button.wipe').addEventListener('click', () => {
api('wipe', {
}, function(response) {
console.log(response)
})
})
})
</script>
</body>