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.channel = channel
self.auth = HTTPDigestAuth(self.username, self.password) 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): def url(self, method):
return 'http://{}/ISAPI/PTZCtrl/channels/{}/{}'.format(self.ip, self.channel, method) return 'http://{}/ISAPI/PTZCtrl/channels/{}/{}'.format(self.ip, self.channel, method)
@ -155,53 +168,57 @@ class Camera:
time.sleep(1) time.sleep(1)
print('presets loaded') 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 self.sequence_start = 0
if goto_first: if goto_first:
#self.goto_preset(steps[0], pan=100, tilt=100, zoom=100) #self.goto_preset(steps[0], pan=100, tilt=100, zoom=100)
first = steps[0] 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:] steps = steps[1:]
self.sequence_start = t0 = time.time() while True:
for step in steps: if goto_first:
self.next_target = step if isinstance(first, dict):
segment_t0 = time.time() if 'seqid' in first and first['seqid'] not in self.segment_times:
if self.abort: self.segment_times[first['seqid']] = 0
return first = first['preset']
if isinstance(step, dict): self.fast_preset(first, True)
if 'fast' in step or ('speed' in step and step['speed'] > 100): #self.goto_preset(first, pan=speed, tilt=speed)
self.fast_preset(step.get('fast', step.get('preset')), True) 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: else:
if 'preset' in step: self.goto_preset(step, pan=speed, tilt=speed)
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)
segment_time = time.time() - segment_t0 segment_time = time.time() - segment_t0
if isinstance(step, dict) and 'seqid' in step: if isinstance(step, dict) and 'seqid' in step:
self.segment_times[step['seqid']] = segment_time self.segment_times[step['seqid']] = segment_time
self.sequence_time = time.time() - t0 self.sequence_time = time.time() - t0
self.next_target = None self.next_target = None
if not loop:
break
def fast_preset(self, id, wait=False): def fast_preset(self, id, wait=False):
self.put('presets/%s/goto' % id, None) self.put('presets/%s/goto' % id, None)
@ -382,3 +399,4 @@ class Camera:
preset['position'] = preset.pop('AbsoluteHigh') preset['position'] = preset.pop('AbsoluteHigh')
preset['name'] = preset.pop('presetName') preset['name'] = preset.pop('presetName')
return presets return presets

View File

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

View File

@ -83,6 +83,7 @@
<h2>CAMP cam canal:</h2> <h2>CAMP cam canal:</h2>
<ul> <ul>
<li><button class="run">run</button></li> <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="goto">go to selected</button></li>
<li><button class="run_from">run from selected</button></li> <li><button class="run_from">run from selected</button></li>
<li><button class="continue_from">continue to 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_sequence" type="file">import sequence</input></li>
<li><input class="import_presets" type="file">import presets</input></li> <li><input class="import_presets" type="file">import presets</input></li>
<li><button class="shift_presets">shift presets</button></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>
</div> </div>

View File

@ -456,6 +456,19 @@ $('button.run').on({click: function() {
//console.log(response) //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() { $('button.run_from').on({click: function() {
var selected = grid.getSelectedRows()[0]; var selected = grid.getSelectedRows()[0];
api('run', { api('run', {

View File

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