2019-03-21 19:43:03 +00:00
|
|
|
const proj = {};
|
2016-06-19 00:06:57 +00:00
|
|
|
|
|
|
|
proj.queue = {};
|
|
|
|
proj.lock = false;
|
2019-03-21 23:34:56 +00:00
|
|
|
proj.id = 'projector';
|
2019-03-31 00:29:01 +00:00
|
|
|
proj.dir = true;
|
|
|
|
proj.pos = 0;
|
2019-03-22 01:02:28 +00:00
|
|
|
|
2016-06-19 00:06:57 +00:00
|
|
|
proj.init = function () {
|
|
|
|
'use strict';
|
|
|
|
proj.listen();
|
|
|
|
};
|
|
|
|
proj.set = function (dir, callback) {
|
|
|
|
'use strict';
|
|
|
|
var obj;
|
|
|
|
if (proj.lock) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
obj = {
|
|
|
|
dir : dir,
|
|
|
|
id : uuid.v4()
|
|
|
|
};
|
2019-03-21 23:34:56 +00:00
|
|
|
ipcRenderer.sendSync(proj.id, obj);
|
2016-06-19 00:06:57 +00:00
|
|
|
|
|
|
|
if (typeof callback !== 'undefined') {
|
|
|
|
obj.callback = callback;
|
|
|
|
}
|
|
|
|
proj.queue[obj.id] = obj;
|
|
|
|
proj.lock = true;
|
|
|
|
};
|
|
|
|
proj.move = function (callback) {
|
|
|
|
'use strict';
|
|
|
|
var obj;
|
|
|
|
if (proj.lock) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
obj = {
|
|
|
|
frame : true,
|
|
|
|
id : uuid.v4()
|
|
|
|
};
|
2019-03-21 23:34:56 +00:00
|
|
|
ipcRenderer.sendSync(proj.id, obj);
|
2016-06-19 00:06:57 +00:00
|
|
|
|
|
|
|
if (typeof callback !== 'undefined') {
|
|
|
|
obj.callback = callback;
|
|
|
|
}
|
|
|
|
proj.queue[obj.id] = obj;
|
|
|
|
proj.lock = true;
|
|
|
|
};
|
|
|
|
proj.end = function (c, id, ms) {
|
|
|
|
'use strict';
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.arduino.cmd.projector_forward) {
|
2019-03-31 00:29:01 +00:00
|
|
|
proj.dir = true;
|
2019-03-22 08:33:53 +00:00
|
|
|
} else if (c === cfg.arduino.cmd.projector_backward) {
|
2019-03-31 00:29:01 +00:00
|
|
|
proj.dir = false;
|
2019-03-22 08:33:53 +00:00
|
|
|
} else if (c === cfg.arduino.cmd.projector) {
|
2019-03-31 00:29:01 +00:00
|
|
|
if (proj.dir) {
|
|
|
|
proj.pos += 1;
|
2016-06-19 00:06:57 +00:00
|
|
|
} else {
|
2019-03-31 00:29:01 +00:00
|
|
|
proj.pos -= 1;
|
2016-06-19 00:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-31 00:29:01 +00:00
|
|
|
gui.counterUpdate('proj', proj.pos)
|
2016-06-19 00:06:57 +00:00
|
|
|
if (typeof proj.queue[id] !== 'undefined') {
|
|
|
|
if (typeof proj.queue[id].callback !== 'undefined') {
|
|
|
|
proj.queue[id].callback(ms);
|
|
|
|
}
|
|
|
|
delete proj.queue[id];
|
|
|
|
proj.lock = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
proj.listen = function () {
|
|
|
|
'use strict';
|
2019-03-21 23:34:56 +00:00
|
|
|
ipcRenderer.on(proj.id, function (event, arg) {
|
2016-06-19 00:06:57 +00:00
|
|
|
proj.end(arg.cmd, arg.id, arg.ms);
|
|
|
|
return event.returnValue = true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-02-24 03:19:03 +00:00
|
|
|
proj.setValue = function (val) {
|
|
|
|
'use strict';
|
|
|
|
var obj = {
|
|
|
|
val: val,
|
|
|
|
id : uuid.v4()
|
|
|
|
};
|
2019-03-21 23:34:56 +00:00
|
|
|
ipcRenderer.sendSync(proj.id, obj);
|
2019-03-20 22:37:00 +00:00
|
|
|
};
|
|
|
|
|
2019-04-04 22:49:07 +00:00
|
|
|
proj.second = {};
|
2019-04-15 17:07:47 +00:00
|
|
|
proj.second.enabled = false;
|
2019-04-04 22:49:07 +00:00
|
|
|
proj.second.queue = {};
|
|
|
|
proj.second.lock = false;
|
|
|
|
proj.second.id = 'projector_second';
|
|
|
|
proj.second.dir = true;
|
|
|
|
proj.second.pos = 0;
|
2019-02-24 03:19:03 +00:00
|
|
|
|
2019-04-15 17:07:47 +00:00
|
|
|
|
|
|
|
proj.second.enable = function () {
|
|
|
|
proj.second.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
proj.second.disable = function () {
|
|
|
|
proj.second.disabled = true;
|
|
|
|
}
|
|
|
|
|
2016-06-19 00:06:57 +00:00
|
|
|
module.exports = proj;
|