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,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2016-06-19 00:06:57 +00:00
|
|
|
};
|
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;
|
|
|
|
};
|
2024-11-26 18:27:31 +00:00
|
|
|
|
|
|
|
proj.setAsync = async function (dir) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return proj.set(dir, function (ms) {
|
|
|
|
setTimeout(reject, 10000);
|
|
|
|
return resolve(ms);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-19 00:06:57 +00:00
|
|
|
proj.move = function (callback) {
|
|
|
|
'use strict';
|
|
|
|
var obj;
|
|
|
|
if (proj.lock) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
obj = {
|
2024-05-23 22:49:18 +00:00
|
|
|
move : true,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2016-06-19 00:06:57 +00:00
|
|
|
};
|
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;
|
|
|
|
};
|
2024-11-26 18:27:31 +00:00
|
|
|
|
|
|
|
proj.moveAsync = async function () {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return proj.move(function (ms) {
|
|
|
|
setTimeout(reject, 10000);
|
|
|
|
return resolve(ms);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-19 00:06:57 +00:00
|
|
|
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-04-20 14:15:28 +00:00
|
|
|
} else if (c === cfg.arduino.cmd.projectors) {
|
|
|
|
if (proj.dir) {
|
|
|
|
proj.pos += 1;
|
|
|
|
} else {
|
|
|
|
proj.pos -= 1;
|
|
|
|
}
|
|
|
|
if (proj.second.dir) {
|
|
|
|
proj.second.pos += 1;
|
|
|
|
} else {
|
|
|
|
proj.second.pos -= 1;
|
|
|
|
}
|
2019-04-20 23:52:26 +00:00
|
|
|
gui.counterUpdate('proj2', proj.second.pos);
|
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);
|
2024-11-26 18:27:31 +00:00
|
|
|
} else {
|
|
|
|
log.info('NO PROJ CALLBACK')
|
2016-06-19 00:06:57 +00:00
|
|
|
}
|
|
|
|
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,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2019-02-24 03:19:03 +00:00
|
|
|
};
|
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;
|
2019-04-16 14:01:42 +00:00
|
|
|
//ui actions
|
|
|
|
$('.proj2').addClass('on');
|
|
|
|
$('#counters').addClass('projectors');
|
2019-04-19 01:58:11 +00:00
|
|
|
proj.second.init();
|
2019-04-15 17:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proj.second.disable = function () {
|
|
|
|
proj.second.disabled = true;
|
2019-04-16 14:01:42 +00:00
|
|
|
//ui actions
|
|
|
|
$('.proj2').removeClass('on');
|
|
|
|
$('#counters').removeClass('projectors');
|
2019-04-15 17:07:47 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 01:58:11 +00:00
|
|
|
proj.second.init = function () {
|
|
|
|
'use strict';
|
|
|
|
proj.second.listen();
|
|
|
|
};
|
|
|
|
proj.second.set = function (dir, callback) {
|
|
|
|
'use strict';
|
|
|
|
var obj;
|
|
|
|
if (proj.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(proj.second.id, obj);
|
|
|
|
|
|
|
|
if (typeof callback !== 'undefined') {
|
|
|
|
obj.callback = callback;
|
|
|
|
}
|
|
|
|
proj.second.queue[obj.id] = obj;
|
|
|
|
proj.second.lock = true;
|
|
|
|
};
|
|
|
|
proj.second.move = function (callback) {
|
|
|
|
'use strict';
|
|
|
|
var obj;
|
|
|
|
if (proj.second.lock) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
obj = {
|
2024-05-23 22:49:18 +00:00
|
|
|
move : true,
|
2019-04-20 14:15:28 +00:00
|
|
|
id : uuid()
|
2019-04-19 01:58:11 +00:00
|
|
|
};
|
|
|
|
ipcRenderer.sendSync(proj.second.id, obj);
|
|
|
|
|
|
|
|
if (typeof callback !== 'undefined') {
|
|
|
|
obj.callback = callback;
|
|
|
|
}
|
|
|
|
proj.second.queue[obj.id] = obj;
|
|
|
|
proj.second.lock = true;
|
|
|
|
};
|
|
|
|
proj.second.end = function (c, id, ms) {
|
|
|
|
'use strict';
|
|
|
|
if (c === cfg.arduino.cmd.projector_second_forward) {
|
|
|
|
proj.second.dir = true;
|
|
|
|
} else if (c === cfg.arduino.cmd.projector_second_backward) {
|
|
|
|
proj.second.dir = false;
|
|
|
|
} else if (c === cfg.arduino.cmd.projector_second) {
|
2019-04-20 14:15:28 +00:00
|
|
|
if (proj.second.dir) {
|
2019-04-19 01:58:11 +00:00
|
|
|
proj.second.pos += 1;
|
|
|
|
} else {
|
|
|
|
proj.second.pos -= 1;
|
|
|
|
}
|
|
|
|
}
|
2023-02-28 20:55:02 +00:00
|
|
|
timing.update(c, ms);
|
2019-04-19 01:58:11 +00:00
|
|
|
gui.counterUpdate('proj2', proj.second.pos);
|
|
|
|
if (typeof proj.second.queue[id] !== 'undefined') {
|
|
|
|
if (typeof proj.second.queue[id].callback !== 'undefined') {
|
|
|
|
proj.second.queue[id].callback(ms);
|
|
|
|
}
|
|
|
|
delete proj.second.queue[id];
|
|
|
|
proj.second.lock = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
proj.second.listen = function () {
|
|
|
|
'use strict';
|
|
|
|
ipcRenderer.on(proj.second.id, function (event, arg) {
|
|
|
|
proj.second.end(arg.cmd, arg.id, arg.ms);
|
|
|
|
return event.returnValue = true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
proj.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(proj.second.id, obj);
|
|
|
|
};
|
|
|
|
|
2016-06-19 00:06:57 +00:00
|
|
|
module.exports = proj;
|