2019-03-21 18:59:46 +00:00
|
|
|
const cam = {};
|
2016-06-19 00:08:01 +00:00
|
|
|
|
|
|
|
cam.queue = {};
|
|
|
|
cam.lock = false;
|
2019-03-21 23:34:56 +00:00
|
|
|
cam.id = 'camera';
|
2019-03-31 00:29:01 +00:00
|
|
|
cam.pos = 0;
|
|
|
|
cam.dir = true;
|
2019-03-22 01:02:28 +00:00
|
|
|
|
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.v4()
|
|
|
|
};
|
2019-03-21 23:34:56 +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;
|
|
|
|
};
|
2019-03-21 23:34:56 +00:00
|
|
|
|
|
|
|
cam.setValue = function (val) {
|
|
|
|
'use strict';
|
|
|
|
var obj = {
|
|
|
|
val: val,
|
|
|
|
id : uuid.v4()
|
|
|
|
};
|
|
|
|
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.v4()
|
|
|
|
};
|
2019-03-21 23:34:56 +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';
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.arduino.cmd.camera_forward) {
|
2019-03-31 00:29:01 +00:00
|
|
|
cam.dir = true;
|
2019-03-22 08:33:53 +00:00
|
|
|
} else if (c === cfg.arduino.cmd.camera_backward) {
|
2019-03-31 00:29:01 +00:00
|
|
|
cam.dir = false;
|
2019-03-22 08:33:53 +00:00
|
|
|
} else if (c === cfg.arduino.cmd.camera) {
|
2019-03-31 00:29:01 +00:00
|
|
|
if (cam.dir) {
|
|
|
|
cam.pos += 1;
|
2016-06-19 00:08:01 +00:00
|
|
|
} else {
|
2019-03-31 00:29:01 +00:00
|
|
|
cam.pos -= 1;
|
2016-06-19 00:08:01 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-31 00:29:01 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
cam.listen = function () {
|
|
|
|
'use strict';
|
2019-03-21 23:34:56 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = cam;
|