Compare commits

...

2 Commits

Author SHA1 Message Date
j
329cb1083d warn about missing azimuth 2020-12-06 13:46:49 +01:00
j
df190dda02 store sequence on server 2020-12-06 13:42:13 +01:00
3 changed files with 58 additions and 15 deletions

View File

@ -289,9 +289,12 @@ class Camera:
#print(current, delta, move) #print(current, delta, move)
current, delta = get_delta() current, delta = get_delta()
changed = False changed = False
if pan and (not delta['azimuth'] or (delta['azimuth'] >= 0) != direction['azimuth']): if 'azimuth' in delta and 'azimuth' in direction:
pan = 0 if pan and (not delta['azimuth'] or (delta['azimuth'] >= 0) != direction['azimuth']):
changed = True pan = 0
changed = True
else:
print('why no azimuth? delta: %s direction: %s' % (delta, direction))
''' '''
if pan > 0: if pan > 0:
pan = min(pan, delta['azimuth']) pan = min(pan, delta['azimuth'])

View File

@ -33,7 +33,8 @@ with open('camera.json') as fd:
state = { state = {
'time': {}, 'time': {},
'status': 'Idle' 'status': 'Idle',
'sequence': [],
} }
def run_async(func): def run_async(func):
@ -90,7 +91,6 @@ class ControlQueue:
self.q.put(None) self.q.put(None)
self._worker.join() self._worker.join()
class API(object): class API(object):
def __call__(self, method, kwargs): def __call__(self, method, kwargs):
@ -98,7 +98,8 @@ class API(object):
def getPresets(self, **data): def getPresets(self, **data):
result = {} result = {}
result['presets'] = ctl.camera.get_presets(True) #result['presets'] = ctl.camera.get_presets(True)
result['presets'] = []
return result return result
def setPreset(self, **data): def setPreset(self, **data):
@ -163,6 +164,17 @@ class API(object):
result['position'] = ctl.camera.last_position result['position'] = ctl.camera.last_position
return result return result
def updateSequence(self, **data):
print('updateSequence')
state['sequence'] = data['sequence']
with open('sequence.json', 'w') as fd:
json.dump(state['sequence'], fd, indent=4, ensure_ascii=False)
def getSequence(self, **data):
result = {}
result['sequence'] = state['sequence']
return result
#@run_async #@run_async
def api_task(request, callback): def api_task(request, callback):
api = API() api = API()
@ -216,9 +228,20 @@ class MainHandler(tornado.web.RequestHandler):
self.set_header('Expires', '0') self.set_header('Expires', '0')
self.write(content) self.write(content)
def load_sequence():
if os.path.exists('sequence.json'):
try:
with open('sequence.json') as fd:
data = json.load(fd)
except:
data = []
state['sequence'] = data
def main(): def main():
global ctl global ctl
ctl = ControlQueue() ctl = ControlQueue()
load_sequence()
handlers = [ handlers = [
(r'/api/', RPCHandler), (r'/api/', RPCHandler),
(r'/static/(.*)', StaticFileHandler, {'path': STATIC_PATH}), (r'/static/(.*)', StaticFileHandler, {'path': STATIC_PATH}),
@ -230,7 +253,7 @@ def main():
'gzip': True, 'gzip': True,
} }
app = Application(handlers, **options) app = Application(handlers, **options)
print('listening on http://%s:%s/' % (ADDRESS, PORT)) print('listening on http://%s:%s/' % (ADDRESS, PORT))
app.listen(PORT, ADDRESS) app.listen(PORT, ADDRESS)
main = IOLoop.instance() main = IOLoop.instance()

View File

@ -51,6 +51,7 @@ if (value == null || value == undefined || !value.length || !isInt(value)) {
} }
} }
var currentSequence;
var presets = []; var presets = [];
var system_presets = [ var system_presets = [
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
@ -320,10 +321,13 @@ function totalDuration() {
function updateStatus() { function updateStatus() {
api('status', {}, function(response) { api('status', {}, function(response) {
if (response.result) { if (response.result) {
var gotSelection = grid.getSelectedRows().length > 0
var disabled = !gotSelection || response.result.status == 'Active'
$('#status').html(response.result.status) $('#status').html(response.result.status)
$('button.run').attr({disabled: response.result.status == 'Active'}) $('button.run').attr({disabled: response.result.status == 'Active'})
$('button.run_from').attr({disabled: response.result.status == 'Active'}) $('button.run_from').attr({disabled: disabled})
$('button.continue_from').attr({disabled: response.result.status == 'Active'}) $('button.continue_from').attr({disabled: disabled})
$('button.stop').attr({disabled: response.result.status != 'Active'}) $('button.stop').attr({disabled: response.result.status != 'Active'})
if (response.result.duration && response.result.status == 'Active') { if (response.result.duration && response.result.status == 'Active') {
$('#duration').html(formatDuration(response.result.duration)) $('#duration').html(formatDuration(response.result.duration))
@ -373,7 +377,17 @@ function updateStatus() {
seq.seqid = uuidv4() seq.seqid = uuidv4()
} }
}) })
localStorage.sequence = JSON.stringify(data) var sequence = JSON.stringify(data.map(step => {
step = Object.assign({}, step)
delete step.duration
delete step.status
return step
}))
if (sequence != currentSequence) {
console.log('updateSequence')
currentSequence = sequence
api('updateSequence', {sequence: data}, function() {})
}
var gotSelection = grid.getSelectedRows().length > 0 var gotSelection = grid.getSelectedRows().length > 0
$('button.goto').attr({disabled: !gotSelection}) $('button.goto').attr({disabled: !gotSelection})
@ -608,8 +622,9 @@ $('button.all_presets').on({click: function() {
$('input.import_sequence').on({change: function() { $('input.import_sequence').on({change: function() {
var reader = new FileReader() var reader = new FileReader()
reader.onload = function(event) { reader.onload = function(event) {
localStorage.sequence = reader.result var sequence = JSON.parse(reader.result)
loadData(JSON.parse(reader.result)) api('updateSequence', {sequence: sequence}, function() {})
loadData(sequence)
} }
reader.readAsText(this.files[0]); reader.readAsText(this.files[0]);
}}) }})
@ -654,9 +669,11 @@ function shiftPresets(offset, callback) {
function init() { function init() {
api('getPresets', {}, function(response) { api('getPresets', {}, function(response) {
presets = response.result.presets presets = response.result.presets
loadData(JSON.parse(localStorage.sequence || '[]')) api('getSequence', {}, function(response) {
updateStatus() loadData(response.result.sequence)
setInterval(updateStatus, 1000) updateStatus()
setInterval(updateStatus, 1000)
})
}) })
} }