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,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2016-06-19 00:08:01 +00:00
|
|
|
};
|
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,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2019-03-21 23:34:56 +00:00
|
|
|
};
|
|
|
|
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,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2016-06-19 00:08:01 +00:00
|
|
|
};
|
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-04-20 14:15:28 +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
|
|
|
}
|
2023-02-28 20:55:02 +00:00
|
|
|
timing.update(c, ms);
|
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;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:49:07 +00:00
|
|
|
cam.second = {};
|
2019-04-15 17:07:47 +00:00
|
|
|
cam.second.enabled = false;
|
2019-04-04 22:49:07 +00:00
|
|
|
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');
|
2019-04-19 01:58:11 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-04-19 01:58:11 +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,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2019-04-19 01:58:11 +00:00
|
|
|
};
|
|
|
|
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,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2019-04-19 01:58:11 +00:00
|
|
|
};
|
|
|
|
ipcRenderer.sendSync(cam.second.id, obj);
|
|
|
|
};
|
|
|
|
cam.second.move = function (callback) {
|
|
|
|
'use strict';
|
|
|
|
var obj;
|
|
|
|
if (cam.second.lock) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
obj = {
|
|
|
|
frame : true,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2019-04-19 01:58:11 +00:00
|
|
|
};
|
|
|
|
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) {
|
2019-04-20 14:15:28 +00:00
|
|
|
if (cam.second.dir) {
|
2019-04-19 01:58:11 +00:00
|
|
|
cam.second.pos += 1;
|
|
|
|
} else {
|
|
|
|
cam.second.pos -= 1;
|
|
|
|
}
|
|
|
|
}
|
2023-02-28 20:55:02 +00:00
|
|
|
timing.update(c, ms);
|
2019-04-20 14:15:28 +00:00
|
|
|
gui.counterUpdate('cam2', cam.second.pos)
|
2019-04-19 01:58:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
2019-04-20 14:15:28 +00:00
|
|
|
cam.second.listen = function () {
|
2019-04-19 01:58:11 +00:00
|
|
|
'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;
|