mcopy/app/lib/ui/cam.js

224 lines
4.3 KiB
JavaScript
Raw Normal View History

2019-03-21 18:59:46 +00:00
const cam = {};
2016-06-19 00:08:01 +00:00
cam.queue = {};
cam.lock = false;
cam.id = 'camera';
cam.pos = 0;
cam.dir = true;
2016-06-19 00:08:01 +00:00
cam.init = function () {
'use strict';
cam.listen();
};
cam.set = function (dir, callback) {
'use strict';
var obj;
if (cam.lock) {
return false;
}
obj = {
dir : dir,
id : uuid()
2016-06-19 00:08:01 +00:00
};
ipcRenderer.sendSync(cam.id, obj);
2016-06-19 00:08:01 +00:00
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
cam.queue[obj.id] = obj;
cam.lock = true;
};
cam.setValue = function (val) {
'use strict';
var obj = {
val: val,
id : uuid()
};
ipcRenderer.sendSync(cam.id, obj);
};
2016-06-19 00:08:01 +00:00
cam.move = function (callback) {
'use strict';
var obj;
if (cam.lock) {
return false;
}
obj = {
frame : true,
id : uuid()
2016-06-19 00:08:01 +00:00
};
ipcRenderer.sendSync(cam.id, obj);
2016-06-19 00:08:01 +00:00
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
cam.queue[obj.id] = obj;
cam.lock = true;
};
cam.end = function (c, id, ms) {
'use strict';
if (c === cfg.arduino.cmd.camera_forward) {
cam.dir = true;
} else if (c === cfg.arduino.cmd.camera_backward) {
cam.dir = false;
} else if (c === cfg.arduino.cmd.camera) {
if (cam.dir) {
cam.pos += 1;
2016-06-19 00:08:01 +00:00
} else {
cam.pos -= 1;
2016-06-19 00:08:01 +00:00
}
} else if (c === cfg.arduino.cmd.cameras) {
if (cam.dir) {
cam.pos += 1;
} else {
cam.pos -= 1;
}
if (cam.second.dir) {
cam.second.pos += 1;
} else {
cam.second.pos -= 1;
}
gui.counterUpdate('cam2', cam.second.pos);
2016-06-19 00:08:01 +00:00
}
timing.update(c, ms);
gui.counterUpdate('cam', cam.pos);
2016-06-19 00:08:01 +00:00
if (typeof cam.queue[id] !== 'undefined') {
if (typeof cam.queue[id].callback !== 'undefined') {
cam.queue[id].callback(ms);
}
delete cam.queue[id];
cam.lock = false;
}
};
2023-07-05 19:17:45 +00:00
cam.exposure = async function (exposure) {
2023-07-05 19:17:45 +00:00
var obj = {
id : uuid(),
exposure
};
var change = false;
try {
change = await gui.confirm(`Are you sure you want to set camera exposure to ${exposure}ms?`);
} catch (err) {
log.error(err);
}
if (change) {
log.info(`Setting exposure: ${exposure}`);
ipcRenderer.sendSync(cam.id, obj);
} else {
timing.updateUI('#cam_time', timing.data['cam']);
}
2023-07-05 19:17:45 +00:00
}
2016-06-19 00:08:01 +00:00
cam.listen = function () {
'use strict';
ipcRenderer.on(cam.id, function (event, arg) {
2016-06-19 00:08:01 +00:00
cam.end(arg.cmd, arg.id, arg.ms);
return event.returnValue = true;
});
};
cam.second = {};
2019-04-15 17:07:47 +00:00
cam.second.enabled = false;
cam.second.queue = {};
cam.second.lock = false;
cam.second.id = 'camera_second';
cam.second.pos = 0;
cam.second.dir = true;
2019-04-15 17:07:47 +00:00
cam.second.enable = function () {
cam.second.enabled = true;
2019-04-16 14:01:42 +00:00
//ui actions
$('.cam2').addClass('on');
$('#counters').addClass('cameras');
cam.second.init();
2019-04-15 17:07:47 +00:00
}
cam.second.disable = function () {
cam.second.enabled = false;
2019-04-16 14:01:42 +00:00
//ui actions
$('.cam2').removeClass('on');
$('#counters').removeClass('cameras');
2019-04-15 17:07:47 +00:00
}
cam.second.init = function () {
'use strict';
cam.second.listen();
};
cam.second.set = function (dir, callback) {
'use strict';
var obj;
if (cam.second.lock) {
return false;
}
obj = {
dir : dir,
id : uuid()
};
ipcRenderer.sendSync(cam.second.id, obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
cam.second.queue[obj.id] = obj;
cam.second.lock = true;
};
cam.second.setValue = function (val) {
'use strict';
var obj = {
val: val,
id : uuid()
};
ipcRenderer.sendSync(cam.second.id, obj);
};
cam.second.move = function (callback) {
'use strict';
var obj;
if (cam.second.lock) {
return false;
}
obj = {
frame : true,
id : uuid()
};
ipcRenderer.sendSync(cam.second.id, obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
cam.second.queue[obj.id] = obj;
cam.second.lock = true;
};
cam.second.end = function (c, id, ms) {
'use strict';
if (c === cfg.arduino.cmd.camera_second_forward) {
cam.second.dir = true;
} else if (c === cfg.arduino.cmd.camera_second_backward) {
cam.second.dir = false;
} else if (c === cfg.arduino.cmd.camera_second) {
if (cam.second.dir) {
cam.second.pos += 1;
} else {
cam.second.pos -= 1;
}
}
timing.update(c, ms);
gui.counterUpdate('cam2', cam.second.pos)
if (typeof cam.second.queue[id] !== 'undefined') {
if (typeof cam.queue[id].callback !== 'undefined') {
cam.second.queue[id].callback(ms);
}
delete cam.second.queue[id];
cam.second.lock = false;
}
};
cam.second.listen = function () {
'use strict';
ipcRenderer.on(cam.second.id, function (event, arg) {
cam.second.end(arg.cmd, arg.id, arg.ms);
return event.returnValue = true;
});
};
2016-06-19 00:08:01 +00:00
module.exports = cam;