hour loop

This commit is contained in:
j 2021-11-23 10:44:28 +01:00
parent 765fc78c7b
commit 38d0ef4714
3 changed files with 35 additions and 9 deletions

View File

@ -147,7 +147,7 @@ class Camera:
if '<statusCode>1</statusCode>' not in r:
print(r)
elif duration:
time.sleep(duration)
self.sleep(duration)
self.continuous(self.STOP)
def set_preset(self, id, name):
@ -168,12 +168,24 @@ class Camera:
time.sleep(1)
print('presets loaded')
def sequence(self, steps=[], speed=12, goto_first=True, loop=False):
def sleep(self, seconds):
n = float(seconds)
if self.abort:
return
while n > 0:
step = min(n, 0.5)
time.sleep(step)
n -= step
if self.abort:
return
def sequence(self, steps=[], speed=12, goto_first=True, loop=False, hour_loop=False):
self.sequence_start = 0
if goto_first:
#self.goto_preset(steps[0], pan=100, tilt=100, zoom=100)
first = steps[0]
steps = steps[1:]
hour = time.gmtime().tm_hour
while True:
if goto_first:
if isinstance(first, dict):
@ -182,11 +194,13 @@ class Camera:
first = first['preset']
self.fast_preset(first, True)
#self.goto_preset(first, pan=speed, tilt=speed)
if self.abort:
return
time.sleep(3)
self.sleep(3)
self.sequence_start = t0 = time.time()
for step in steps:
next_hour = time.gmtime().tm_hour
if hour_loop and next_hour != hour:
hour = next_hour
break
self.next_target = step
segment_t0 = time.time()
if self.abort:
@ -206,9 +220,7 @@ class Camera:
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']))
self.sleep(step['sleep'])
else:
self.goto_preset(step, pan=speed, tilt=speed)
@ -217,7 +229,7 @@ class Camera:
self.segment_times[step['seqid']] = segment_time
self.sequence_time = time.time() - t0
self.next_target = None
if not loop:
if not loop and not hour_loop:
break
def fast_preset(self, id, wait=False):

View File

@ -84,6 +84,7 @@
<ul>
<li><button class="run">run</button></li>
<li><button class="loop">loop</button></li>
<li><button class="hour_loop">hour 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>

View File

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