From 0883f50f25bc6d4db1195e12e3649d063004cedb Mon Sep 17 00:00:00 2001 From: j Date: Mon, 13 Sep 2021 11:23:43 +0200 Subject: [PATCH] wipe, loop, include ptz --- camera.py | 98 ++++++++++++++++++++++++++++------------------- server.py | 5 +++ static/index.html | 3 ++ static/js/cccc.js | 13 +++++++ static/ptz.html | 9 +++++ 5 files changed, 88 insertions(+), 40 deletions(-) diff --git a/camera.py b/camera.py index b36a84f..c898bb6 100644 --- a/camera.py +++ b/camera.py @@ -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 + diff --git a/server.py b/server.py index e1275b4..73a1e55 100755 --- a/server.py +++ b/server.py @@ -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() diff --git a/static/index.html b/static/index.html index d0e5755..c24e23e 100644 --- a/static/index.html +++ b/static/index.html @@ -83,6 +83,7 @@

CAMP cam canal: