From 498b585b67e5ee6056f2ce9b7a2968b32773d02a Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 26 Nov 2024 13:27:31 -0500 Subject: [PATCH] Add support for controlling the printer with an NES retro-style USB controller. As long as it has 10 buttons. --- app/data/cfg.json | 2 +- app/js/app.js | 2 + app/lib/ui/cam.js | 21 ++++ app/lib/ui/cmd.js | 104 ++++++++++---------- app/lib/ui/gamecontroller.js | 159 +++++++++++++++++++++++++++++++ app/lib/ui/gamecontroller.js.map | 1 + app/lib/ui/proj.js | 22 +++++ app/lib/ui/seq.js | 6 +- app/lib/ui/seq.js.map | 2 +- app/package-lock.json | 4 +- app/package.json | 2 +- app/src/index.js | 2 + app/src/lib/ui/gamecontroller.ts | 155 ++++++++++++++++++++++++++++++ app/src/lib/ui/seq.ts | 7 +- data/cfg.json | 2 +- notes/controller_test.js | 2 + package-lock.json | 4 +- package.json | 2 +- processing/mcopy/cfg.json | 2 +- scad/cpc_connectors.scad | 2 +- scad/mcopy_gate.scad | 10 +- 21 files changed, 444 insertions(+), 69 deletions(-) create mode 100644 app/lib/ui/gamecontroller.js create mode 100644 app/lib/ui/gamecontroller.js.map create mode 100644 app/src/lib/ui/gamecontroller.ts create mode 100644 notes/controller_test.js diff --git a/app/data/cfg.json b/app/data/cfg.json index 64ec3f4..e2d700f 100644 --- a/app/data/cfg.json +++ b/app/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.150", + "version": "1.8.151", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/app/js/app.js b/app/js/app.js index f5798d7..962fad1 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -2501,6 +2501,7 @@ const timing = require('./lib/ui/timing.js'); const Mscript = require('./lib/mscript'); const { delay } = require('./lib/delay'); const alertObj = require('./lib/ui/alert.js'); +const gamecontroller = require('./lib/ui/gamecontroller.js'); const { Log } = require('./lib/log'); let log; @@ -2533,4 +2534,5 @@ async function init () { capper.init(); alertObj.init(); timing.init(); + gamecontroller.init(seq, cmd, cam, proj); }; \ No newline at end of file diff --git a/app/lib/ui/cam.js b/app/lib/ui/cam.js index 73152d8..06f072c 100644 --- a/app/lib/ui/cam.js +++ b/app/lib/ui/cam.js @@ -29,6 +29,15 @@ cam.set = function (dir, callback) { cam.lock = true; }; +cam.setAsync = async function (dir) { + return new Promise((resolve, reject) => { + return cam.set(dir, function (ms) { + setTimeout(reject, 10000); + return resolve(ms); + }); + }); +} + cam.setValue = function (val) { 'use strict'; var obj = { @@ -55,6 +64,16 @@ cam.move = function (callback) { cam.queue[obj.id] = obj; cam.lock = true; }; + +cam.moveAsync = async function () { + return new Promise((resolve, reject) => { + return cam.move(function (ms) { + setTimeout(reject, 10000); + return resolve(ms); + }); + }); +} + cam.end = function (c, id, ms) { 'use strict'; if (c === cfg.arduino.cmd.camera_forward) { @@ -85,6 +104,8 @@ cam.end = function (c, id, ms) { if (typeof cam.queue[id] !== 'undefined') { if (typeof cam.queue[id].callback !== 'undefined') { cam.queue[id].callback(ms); + } else { + log.info('NO CAM CALLBACK') } delete cam.queue[id]; cam.lock = false; diff --git a/app/lib/ui/cmd.js b/app/lib/ui/cmd.js index 3e53eee..f7c18a3 100644 --- a/app/lib/ui/cmd.js +++ b/app/lib/ui/cmd.js @@ -15,14 +15,14 @@ cmd.projector_forward = function (callback) { $('#cmd_proj_forward').addClass('active'); if (!proj.dir) { proj.set(true, function (ms) { - setTimeout(function () { + //setTimeout(function () { proj.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { - setTimeout(function () { + //setTimeout(function () { proj.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); } }; /** @@ -40,14 +40,14 @@ cmd.projector_backward = function (callback) { $('#cmd_proj_backward').addClass('active'); if (proj.dir) { proj.set(false, function (ms) { - setTimeout(function () { + //setTimeout(function () { proj.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { - setTimeout(function () { + //setTimeout(function () { proj.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); } }; @@ -61,14 +61,14 @@ cmd.projector_second_forward = function (callback) { $('#cmd_proj2_forward').addClass('active'); if (!proj.second.dir) { proj.second.set(true, function (ms) { - setTimeout(function () { + //setTimeout(function () { proj.second.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { - setTimeout(function () { + //setTimeout(function () { proj.second.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); } }; cmd.projector_second_backward = function (callback) { @@ -81,14 +81,14 @@ cmd.projector_second_backward = function (callback) { $('#cmd_proj2_backward').addClass('active'); if (proj.second.dir) { proj.second.set(false, function (ms) { - setTimeout(function () { + //setTimeout(function () { proj.second.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { - setTimeout(function () { + //setTimeout(function () { proj.second.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); } }; @@ -112,32 +112,32 @@ cmd.camera_forward = function (rgb, callback) { var off = [0, 0, 0]; var res = function (ms) { gui.updateState(); - setTimeout(function () { + //setTimeout(function () { light.display(off); light.set(off, function () { $('#cmd_cam_forward').removeClass('active'); if (callback) { callback(ms); } }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }; $('#cmd_cam_forward').addClass('active'); if (!cam.dir) { cam.set(true, function () { - setTimeout( function () { + //setTimeout( function () { light.display(rgb); light.set(rgb, function () { - setTimeout( function () { + //setTimeout( function () { cam.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { light.display(rgb); light.set(rgb, function () { - setTimeout(function () { + //setTimeout(function () { cam.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } }; @@ -234,20 +234,20 @@ cmd.camera_backward = function (rgb, callback) { $('#cmd_cam_backward').addClass('active'); if (cam.dir) { cam.set(false, function () { - setTimeout(function () { + //setTimeout(function () { light.display(rgb); light.set(rgb, function () { cam.move(res); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { - setTimeout(function () { + //setTimeout(function () { light.display(rgb); light.set(rgb, function () { cam.move(res); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); } }; /** @@ -284,12 +284,12 @@ cmd.black_backward = function (callback) { }); } else { cam.set(false, function () { - setTimeout(function () { + //setTimeout(function () { light.display(off); light.set(off, function () { cam.move(res); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } } else { @@ -309,12 +309,12 @@ cmd.black_backward = function (callback) { }, cfg.arduino.serialDelay); }); } else { - setTimeout(function () { + //setTimeout(function () { light.display(off); light.set(off, function () { cam.move(res); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); } } }; @@ -339,32 +339,32 @@ cmd.camera_second_forward = function (callback) { var off = [0, 0, 0]; var res = function (ms) { gui.updateState(); - setTimeout(function () { + //setTimeout(function () { light.display(off); light.set(off, function () { $('#cmd_cam2_forward').removeClass('active'); if (callback) { callback(ms); } }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }; $('#cmd_cam2_forward').addClass('active'); if (!cam.second.dir) { cam.second.set(true, function () { - setTimeout( function () { + //setTimeout( function () { light.display(rgb); light.set(rgb, function () { setTimeout( function () { cam.second.move(res); }, cfg.arduino.serialDelay); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { light.display(rgb); light.set(rgb, function () { - setTimeout(function () { + //setTimeout(function () { cam.second.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } }; @@ -382,20 +382,20 @@ cmd.camera_second_backward = function (callback) { $('#cmd_cam_backward').addClass('active'); if (cam.second.dir) { cam.second.set(false, function () { - setTimeout(function () { + //setTimeout(function () { light.display(rgb); light.set(rgb, function () { cam.second.move(res); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { - setTimeout(function () { + //setTimeout(function () { light.display(rgb); light.set(rgb, function () { cam.second.move(res); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); } }; @@ -410,21 +410,21 @@ cmd.black_second_forward = function (callback) { $('#cmd_black2_forward').addClass('active'); if (!cam.second.dir) { cam.second.set(true, function () { - setTimeout( function () { + //setTimeout( function () { light.display(off); light.set(off, function () { - setTimeout( function () { + //setTimeout( function () { cam.second.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { light.display(off); light.set(off, function () { - setTimeout(function () { + //setTimeout(function () { cam.second.move(res); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } }; @@ -440,20 +440,20 @@ cmd.black2_backward = function (callback) { $('#cmd_black2_backward').addClass('active'); if (cam.second.dir) { cam.second.set(false, function () { - setTimeout(function () { + //setTimeout(function () { light.display(off); light.set(off, function () { cam.second.move(res); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); }); } else { - setTimeout(function () { + //setTimeout(function () { light.display(off); light.set(off, function () { cam.second.move(res); }); - }, cfg.arduino.serialDelay); + //}, cfg.arduino.serialDelay); } }; diff --git a/app/lib/ui/gamecontroller.js b/app/lib/ui/gamecontroller.js new file mode 100644 index 0000000..dc939d9 --- /dev/null +++ b/app/lib/ui/gamecontroller.js @@ -0,0 +1,159 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +let gamecontroller; +class GameController { + constructor() { + this.cameraMoving = false; + this.projectorMoving = false; + } + init(seq, cmd, cam, proj) { + this.seq = seq; + this.cmd = cmd; + this.cam = cam; + this.proj = proj; + window.addEventListener('gamepadconnected', (e) => { + const gamepads = navigator.getGamepads(); + if (gamepads.length > 0) { + console.dir(gamepads[0]); + this.pressed = gamepads[0].buttons.map((button) => { return button.pressed; }); + if (gamepads[0].id.indexOf("USB Gamepad") !== -1 && gamepads[0].buttons.length === 10) { + gui.notify('GAMEPAD CONNECTED', 'NES Controller'); + } + else { + gui.notify('GAMEPAD CONNECTED', 'Unknown'); + } + } + this.handleController(); + }); + window.addEventListener('gamepaddisconnected', (e) => { + gui.notify('GAMEPAD DISCONNECTED', ''); + }); + } + handleController() { + const gamepads = navigator.getGamepads(); + if (gamepads.length === 0) { + return; + } + const gamepad = gamepads[0]; + if (gamepad.id.indexOf("USB Gamepad") !== -1 && gamepad.buttons.length === 10) { + this.handleNESController(gamepad); + } + requestAnimationFrame(this.handleController.bind(this)); + } + handleNESController(gamepad) { + const leftStickX = gamepad.axes[0]; + const leftStickY = gamepad.axes[1]; + //log.info(leftStickX + ',' + leftStickY) + //select == 8 + //start == 9 + //A == 2 + //B == 1 + for (let i = 0; i < gamepad.buttons.length; i++) { + if (gamepad.buttons[i].pressed && !this.pressed[i]) { + log.info(`Button[${i}] pressed`); + if (i === 2) { + if (!this.cameraMoving) + this.camera(); + } + else if (i === 1) { + if (!this.projectorMoving) + this.projector(); + } + else if (i == 9) { + this.sequence(); + } + } + } + this.pressed = gamepad.buttons.map((button) => { return button.pressed; }); + this.cameraDirection(leftStickX); + this.projectorDirection(leftStickY); + } + camera(silent = false) { + return __awaiter(this, void 0, void 0, function* () { + const dir = this.cam.dir ? 'camera_forward' : 'camera_backward'; + if (!silent) + log.info(`Gamepad A ${dir}`); + this.cameraMoving = true; + yield this.cam.moveAsync(); + this.cameraMoving = false; + }); + } + projector(silent = false) { + return __awaiter(this, void 0, void 0, function* () { + const dir = this.cam.dir ? 'projector_forward' : 'projector_backward'; + if (!silent) + log.info(`Gamepad B ${dir}`); + this.projectorMoving = true; + yield this.proj.moveAsync(); + this.projectorMoving = false; + }); + } + cameraDirection(dir) { + return __awaiter(this, void 0, void 0, function* () { + if (dir !== 0 && this.cameraMoving) { + log.info('Camera D-PAD blocked'); + return; + } + if (dir === 1) { + log.info('Gamepad D-pad camera_forward'); + if (!this.cam.dir) { + this.cameraMoving = true; + yield this.proj.setAsync(true); + } + yield this.camera(true); + } + else if (dir === -1) { + log.info('Gamepad D-pad camera_backward'); + if (this.cam.dir) { + this.cameraMoving = true; + yield this.cam.setAsync(true); + } + yield this.camera(true); + } + }); + } + projectorDirection(dir) { + return __awaiter(this, void 0, void 0, function* () { + if (dir !== 0 && this.projectorMoving) { + log.info('Projector D-PAD blocked'); + return; + } + if (dir === -1) { + log.info('Gamepad D-pad projector_forward'); + if (!this.proj.dir) { + this.projectorMoving = true; + yield this.proj.setAsync(true); + } + yield this.projector(true); + } + else if (dir === 1) { + log.info('Gamepad D-pad projector_backward'); + if (this.proj.dir) { + this.projectorMoving = true; + yield this.proj.setAsync(false); + } + yield this.projector(true); + } + }); + } + sequence() { + return __awaiter(this, void 0, void 0, function* () { + if (!this.seq.isRunning()) { + this.seq.start(); + } + else { + this.seq.cancel(); + } + }); + } +} +gamecontroller = new GameController(); +module.exports = gamecontroller; +//# sourceMappingURL=gamecontroller.js.map \ No newline at end of file diff --git a/app/lib/ui/gamecontroller.js.map b/app/lib/ui/gamecontroller.js.map new file mode 100644 index 0000000..028892d --- /dev/null +++ b/app/lib/ui/gamecontroller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"gamecontroller.js","sourceRoot":"","sources":["../../src/lib/ui/gamecontroller.ts"],"names":[],"mappings":";;;;;;;;;AAAA,IAAI,cAA+B,CAAC;AAEpC,MAAM,cAAc;IAUlB;QAHQ,iBAAY,GAAa,KAAK,CAAC;QAC/B,oBAAe,GAAa,KAAK,CAAC;IAI1C,CAAC;IAEM,IAAI,CAAE,GAAc,EAAE,G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BAC7C,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;oBACjB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;oBAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;iBACjC;gBACD,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;aAC5B;QACH,CAAC;KAAA;IAEK,QAAQ;;YACZ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE;gBACzB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;aAClB;iBAAM;gBACL,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;aACnB;QACH,CAAC;KAAA;CACF;AAGD,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;AACtC,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC"} \ No newline at end of file diff --git a/app/lib/ui/proj.js b/app/lib/ui/proj.js index 80d5729..346a41c 100644 --- a/app/lib/ui/proj.js +++ b/app/lib/ui/proj.js @@ -28,6 +28,16 @@ proj.set = function (dir, callback) { proj.queue[obj.id] = obj; proj.lock = true; }; + +proj.setAsync = async function (dir) { + return new Promise((resolve, reject) => { + return proj.set(dir, function (ms) { + setTimeout(reject, 10000); + return resolve(ms); + }); + }); +} + proj.move = function (callback) { 'use strict'; var obj; @@ -46,6 +56,16 @@ proj.move = function (callback) { proj.queue[obj.id] = obj; proj.lock = true; }; + +proj.moveAsync = async function () { + return new Promise((resolve, reject) => { + return proj.move(function (ms) { + setTimeout(reject, 10000); + return resolve(ms); + }); + }); +} + proj.end = function (c, id, ms) { 'use strict'; if (c === cfg.arduino.cmd.projector_forward) { @@ -75,6 +95,8 @@ proj.end = function (c, id, ms) { if (typeof proj.queue[id] !== 'undefined') { if (typeof proj.queue[id].callback !== 'undefined') { proj.queue[id].callback(ms); + } else { + log.info('NO PROJ CALLBACK') } delete proj.queue[id]; proj.lock = false; diff --git a/app/lib/ui/seq.js b/app/lib/ui/seq.js index 9dbfefb..7a35855 100644 --- a/app/lib/ui/seq.js +++ b/app/lib/ui/seq.js @@ -21,6 +21,7 @@ class Sequence { let timeStr; //console.log(JSON.stringify(arg)) if (arg.start) { + this.running = true; if (typeof arg.loop !== 'undefined' && typeof arg.step !== 'undefined') { this.activeStep(arg.step); log.info(`Step ${arg.step + 1}/${this.arr.length}, Loop ${arg.loop + 1}/${this.loops}`, 'SERIAL', true); @@ -33,6 +34,7 @@ class Sequence { } } else if (arg.stop) { + this.running = false; if (typeof arg.loop !== 'undefined' && typeof arg.step !== 'undefined') { //console.log(JSON.stringify(arg)) this.progress(arg.step + 1, arg.loop); @@ -218,9 +220,11 @@ class Sequence { } cancel() { gui.spinner(true, `Cancelling sequence...`); - this.running = false; this.stop(); } + isRunning() { + return this.running; + } } seq = new Sequence(); module.exports = seq; diff --git a/app/lib/ui/seq.js.map b/app/lib/ui/seq.js.map index 6ee8c6a..32be97c 100644 --- a/app/lib/ui/seq.js.map +++ b/app/lib/ui/seq.js.map @@ -1 +1 @@ -{"version":3,"file":"seq.js","sourceRoot":"","sources":["../../src/lib/ui/seq.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AA0BZ,IAAI,GAAG,GAAS,EAAE,CAAC;AAGnB,MAAM,QAAQ;IASb;QARQ,OAAE,GAAY,UAAU,CAAC;QAC1B,SAAI,GAAW,EAAE,CAAC;QAClB,cAAS,GAAY,CAAC,CAAC;QACvB,QAAG,GAAW,EAAE,CAAC;QACjB,UAAK,GAAY,CAAC,CAAC;QACnB,SAAI,GAAY,EAAE,CAAC;QAClB,SAAI,GAAY,CAAC,CAAC;QAClB,YAAO,GAAa,KAAK,CAAC;IAGlC,CAAC;IACM,IAAI;QACV,IAAI,CAAC,MAAM,EAAE,CAAC;IACf,CAAC;IACO,MAAM;QACb,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CA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CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;SAC7C;aAAM;YACN,CAAC,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;SACxD;QAED,eAAe;QACf,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QACvC,UAAU,GAAG,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;QAEzC,CAAC,CAAC,0BAA0B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;QACxE,CAAC,CAAC,2BAA2B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;QAE3E,OAAO;QACP,CAAC,CAAC,4BAA4B,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QACzE,OAAO,EAAE,CAAC;IACX,CAAC;IAEM,KAAK;QACX,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrB,CAAC;IAEM,MAAM;QACZ,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC;IAEM,SAAS;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD;AAED,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAC;AAErB,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC"} \ No newline at end of file diff --git a/app/package-lock.json b/app/package-lock.json index 87b90ab..056b4e6 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,12 +1,12 @@ { "name": "mcopy-app", - "version": "1.8.150", + "version": "1.8.151", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mcopy-app", - "version": "1.8.109", + "version": "1.8.150", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/app/package.json b/app/package.json index 7548f96..106093e 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.150", + "version": "1.8.151", "description": "GUI for the mcopy small gauge film optical printer platform", "main": "main.js", "scripts": { diff --git a/app/src/index.js b/app/src/index.js index 852424d..0c3517b 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -27,6 +27,7 @@ const timing = require('./lib/ui/timing.js'); const Mscript = require('./lib/mscript'); const { delay } = require('./lib/delay'); const alertObj = require('./lib/ui/alert.js'); +const gamecontroller = require('./lib/ui/gamecontroller.js'); const { Log } = require('./lib/log'); let log; @@ -59,4 +60,5 @@ async function init () { capper.init(); alertObj.init(); timing.init(); + gamecontroller.init(seq, cmd, cam, proj); }; \ No newline at end of file diff --git a/app/src/lib/ui/gamecontroller.ts b/app/src/lib/ui/gamecontroller.ts new file mode 100644 index 0000000..7f340f6 --- /dev/null +++ b/app/src/lib/ui/gamecontroller.ts @@ -0,0 +1,155 @@ +let gamecontroller : GameController; + +class GameController { + private seq : Sequence; + private cmd : any; + private cam : any; + private proj : any; + private pressed : boolean[]; + + private cameraMoving : boolean = false; + private projectorMoving : boolean = false; + + constructor () { + + } + + public init (seq : Sequence, cmd : any, cam : any, proj : any) { + this.seq = seq; + this.cmd = cmd; + this.cam = cam; + this.proj = proj; + + window.addEventListener('gamepadconnected', (e) => { + const gamepads = navigator.getGamepads(); + if (gamepads.length > 0) { + console.dir(gamepads[0]); + this.pressed = gamepads[0].buttons.map((button: GamepadButton) => { return button.pressed; }); + if (gamepads[0].id.indexOf("USB Gamepad") !== -1 && gamepads[0].buttons.length === 10) { + gui.notify('GAMEPAD CONNECTED', 'NES Controller'); + } else { + gui.notify('GAMEPAD CONNECTED', 'Unknown'); + } + } + this.handleController(); + }); + + window.addEventListener('gamepaddisconnected', (e) => { + gui.notify('GAMEPAD DISCONNECTED', ''); + }); + } + + handleController () { + const gamepads = navigator.getGamepads(); + + if (gamepads.length === 0) { + return; + } + + const gamepad : Gamepad = gamepads[0]; + if (gamepad.id.indexOf("USB Gamepad") !== -1 && gamepad.buttons.length === 10) { + this.handleNESController(gamepad); + } + + requestAnimationFrame(this.handleController.bind(this)); + } + + handleNESController (gamepad : Gamepad) { + const leftStickX : number = gamepad.axes[0]; + const leftStickY : number = gamepad.axes[1]; + //log.info(leftStickX + ',' + leftStickY) + //select == 8 + //start == 9 + //A == 2 + //B == 1 + for (let i = 0; i < gamepad.buttons.length; i++) { + if (gamepad.buttons[i].pressed && !this.pressed[i]) { + log.info(`Button[${i}] pressed`); + if (i === 2) { + if (!this.cameraMoving) this.camera(); + } else if (i === 1) { + if (!this.projectorMoving) this.projector(); + } else if (i == 9) { + this.sequence(); + } + } + } + + this.pressed = gamepad.buttons.map((button: GamepadButton) => { return button.pressed; }); + + this.cameraDirection(leftStickX); + this.projectorDirection(leftStickY); + } + + async camera (silent : boolean = false) { + const dir : string = this.cam.dir ? 'camera_forward' : 'camera_backward'; + if (!silent) log.info(`Gamepad A ${dir}`); + this.cameraMoving = true; + await this.cam.moveAsync(); + this.cameraMoving = false; + } + + async projector (silent : boolean = false) { + const dir : string = this.cam.dir ? 'projector_forward' : 'projector_backward'; + if (!silent) log.info(`Gamepad B ${dir}`); + this.projectorMoving = true; + await this.proj.moveAsync(); + this.projectorMoving = false; + } + + async cameraDirection (dir: number) { + if (dir !== 0 && this.cameraMoving) { + log.info('Camera D-PAD blocked') + return; + } + if (dir === 1) { + log.info('Gamepad D-pad camera_forward'); + if (!this.cam.dir) { + this.cameraMoving = true; + await this.proj.setAsync(true); + } + await this.camera(true); + } else if (dir === -1) { + log.info('Gamepad D-pad camera_backward'); + if (this.cam.dir) { + this.cameraMoving = true; + await this.cam.setAsync(true); + } + await this.camera(true); + } + } + + async projectorDirection (dir : number) { + if (dir !== 0 && this.projectorMoving) { + log.info('Projector D-PAD blocked') + return; + } + if (dir === -1) { + log.info('Gamepad D-pad projector_forward'); + if (!this.proj.dir) { + this.projectorMoving = true; + await this.proj.setAsync(true); + } + await this.projector(true); + } else if (dir === 1) { + log.info('Gamepad D-pad projector_backward'); + if (this.proj.dir) { + this.projectorMoving = true; + await this.proj.setAsync(false); + } + await this.projector(true); + } + } + + async sequence () { + if (!this.seq.isRunning()) { + this.seq.start(); + } else { + this.seq.cancel(); + } + } +} + + +gamecontroller = new GameController(); +module.exports = gamecontroller; \ No newline at end of file diff --git a/app/src/lib/ui/seq.ts b/app/src/lib/ui/seq.ts index 97f31e0..edced94 100644 --- a/app/src/lib/ui/seq.ts +++ b/app/src/lib/ui/seq.ts @@ -49,6 +49,7 @@ class Sequence { let timeStr; //console.log(JSON.stringify(arg)) if (arg.start) { + this.running = true; if (typeof arg.loop !== 'undefined' && typeof arg.step !== 'undefined') { this.activeStep(arg.step); log.info(`Step ${arg.step + 1}/${this.arr.length}, Loop ${arg.loop + 1}/${this.loops}`, 'SERIAL', true); @@ -58,6 +59,7 @@ class Sequence { this.progress(0, 0); } } else if (arg.stop) { + this.running = false; if (typeof arg.loop !== 'undefined' && typeof arg.step !== 'undefined') { //console.log(JSON.stringify(arg)) this.progress(arg.step + 1, arg.loop); @@ -257,9 +259,12 @@ class Sequence { public cancel () { gui.spinner(true, `Cancelling sequence...`); - this.running = false; this.stop(); } + + public isRunning () : boolean { + return this.running; + } } seq = new Sequence(); diff --git a/data/cfg.json b/data/cfg.json index 64ec3f4..e2d700f 100644 --- a/data/cfg.json +++ b/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.150", + "version": "1.8.151", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/notes/controller_test.js b/notes/controller_test.js new file mode 100644 index 0000000..7e21777 --- /dev/null +++ b/notes/controller_test.js @@ -0,0 +1,2 @@ +var HID = require('node-hid'); +console.log(HID.devices()); diff --git a/package-lock.json b/package-lock.json index f97bcec..23941fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mcopy", - "version": "1.8.150", + "version": "1.8.151", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mcopy", - "version": "1.8.150", + "version": "1.8.151", "license": "MIT", "dependencies": { "alert": "file:app/lib/alert", diff --git a/package.json b/package.json index 0ccd052..805dc67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mcopy", - "version": "1.8.150", + "version": "1.8.151", "description": "Small gauge film optical printer platform", "main": "build.js", "directories": { diff --git a/processing/mcopy/cfg.json b/processing/mcopy/cfg.json index 64ec3f4..e2d700f 100644 --- a/processing/mcopy/cfg.json +++ b/processing/mcopy/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.150", + "version": "1.8.151", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/scad/cpc_connectors.scad b/scad/cpc_connectors.scad index 6087620..800df3e 100644 --- a/scad/cpc_connectors.scad +++ b/scad/cpc_connectors.scad @@ -231,7 +231,7 @@ module debug () { } } -PART = "9pin_plug"; +PART = "9pin_socket"; if (PART == "9pin_plug") { rotate([180, 0, 0]) cpc_9pin_plug(); diff --git a/scad/mcopy_gate.scad b/scad/mcopy_gate.scad index b305ed8..76a6230 100644 --- a/scad/mcopy_gate.scad +++ b/scad/mcopy_gate.scad @@ -565,6 +565,7 @@ module slide_rail (pos = [0, 0, 0], side = "A") { BoltSlotY = 1.5; BoltSlotOffsetY = side == "A" ? BoltSlotY : -BoltSlotY; BoltsOffsetY = side == "A" ? -1 / 2 : 1 / 2; + NutVoidY = side == "A" ? -4.5 : 4.5; translate(pos) { difference() { cube([7, 9, BodyZ - 16], center = true); @@ -574,6 +575,7 @@ module slide_rail (pos = [0, 0, 0], side = "A") { slide_rail_bolt_slot([0, BoltsOffsetY, SlideRailBoltSpacingZ / 2], [0, 90, 0], BoltSlotY, BoltSlotOffsetY); slide_rail_bolt_slot([0, BoltsOffsetY, -SlideRailBoltSpacingZ / 2], [0, 90, 0], BoltSlotY, BoltSlotOffsetY); } + translate([0, NutVoidY, ((BodyZ - 16) / 2) - (3 / 2) + 0.01]) cube([7 + 1, 7 , 3], center = true); } } } @@ -724,12 +726,12 @@ module front_block (pos = [0, 0, 0], rot = [0, 0, 0]) { //for pegs translate([12.25, 0, -1.75]) { - translate([3.5, 0, 0]) rounded_cube([33.4, 31.4, 4], d = 3, center = true, $fn = 30); - translate([-3, 12, -2]) { + translate([3.5, 0, 0]) rounded_cube([33.6, 31.6, 4], d = 3, center = true, $fn = 30); + translate([-5, 12, -2]) { cylinder(r = R(2.75), h = 20, center = true, $fn = 40); translate([0, 0, 7]) m2_5_nut(4); } - translate([-3, -12, -2]) { + translate([-5, -12, -2]) { cylinder(r = R(2.75), h = 20, center = true, $fn = 40); translate([0, 0, 7]) m2_5_nut(4); } @@ -860,7 +862,7 @@ module debug () { } } -PART="front_block_16mm"; +PART="front_block_16mmx"; if (PART == "front_plate") { //1