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-20 22:37:00 +00:00
|
|
|
proj.lock2 = false;
|
2019-03-21 23:34:56 +00:00
|
|
|
proj.id = 'projector';
|
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 01:02:28 +00:00
|
|
|
if (c === mcopy.cfg.arduino.cmd.projector_forward) {
|
2016-06-19 00:06:57 +00:00
|
|
|
mcopy.state.projector.direction = true;
|
2019-03-22 01:02:28 +00:00
|
|
|
} else if (c === mcopy.cfg.arduino.cmd.projector_backward) {
|
2016-06-19 00:06:57 +00:00
|
|
|
mcopy.state.projector.direction = false;
|
|
|
|
} else if (c === mcopy.cfg.arduino.cmd.projector) {
|
|
|
|
if (mcopy.state.projector.direction) {
|
|
|
|
mcopy.state.projector.pos += 1;
|
|
|
|
} else {
|
|
|
|
mcopy.state.projector.pos -= 1;
|
|
|
|
}
|
|
|
|
}
|
2019-03-20 22:37:00 +00:00
|
|
|
//
|
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
|
|
|
};
|
|
|
|
|
|
|
|
proj.setValue2 = function (val) {
|
|
|
|
'use strict';
|
|
|
|
var obj = {
|
|
|
|
val: val,
|
|
|
|
second : true,
|
|
|
|
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-02-24 03:19:03 +00:00
|
|
|
|
2016-06-19 00:06:57 +00:00
|
|
|
module.exports = proj;
|