From 8750bcfadf46eba00fb5616488dcf53297e22be4 Mon Sep 17 00:00:00 2001 From: zxhzxhz Date: Mon, 27 Jan 2020 14:22:26 +0800 Subject: [PATCH 1/4] add acceleration data --- app.js | 22 +++++++++++++--------- static.html | 21 ++++++++++++++------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/app.js b/app.js index 61504be..e348b65 100755 --- a/app.js +++ b/app.js @@ -93,7 +93,7 @@ async function main() { } function SendPacket(client, data) { - let buffer = new Buffer(16); + let buffer = new Buffer.alloc(16); let index = BeginPacket(buffer, data.length); // buffer.fill(data,index); buffer = Buffer.concat([buffer, data]); @@ -171,7 +171,7 @@ async function main() { for (let i = 0; i < numOfPadRequests; i++) { let requestIndex = data[index + i]; if (requestIndex !== 0) continue; - let outBuffer = new Buffer(16); + let outBuffer = new Buffer.alloc(16); outBuffer.writeUInt32LE(MessageType.DSUS_PortInfo, 0, true); let outIndex = 4; outBuffer[outIndex++] = 0x00; // pad id @@ -200,7 +200,7 @@ async function main() { } macToRegister = macToRegister.join(":"); - // console.log(`Pad data request (${flags}, ${idToRRegister}, ${macToRegister})`); + // console.log(`Pad data request (${flags}, ${idToRRegister}, ${macToRegister})`); // There is only one controller, so if ( @@ -219,7 +219,7 @@ async function main() { if (client === null || Date.now() - lastRequestAt > clientTimeoutLimit) return; - let outBuffer = new Buffer(100); + let outBuffer = new Buffer.alloc(100); let outIndex = BeginPacket(outBuffer); outBuffer.writeUInt32LE(MessageType.DSUS_PadDataRsp, outIndex, true); outIndex += 4; @@ -403,11 +403,15 @@ async function main() { phoneIsConnected = true; ws.on("report", function(msg) { var data = JSON.parse(msg) - Report((data.ts * 1000).toString(16), { - x: 0, - y: 0, - z: 0 - }, data.gyro); + /*console.log((data.ts * 1000).toString(16)); + console.log(data.gyro); + console.log(data.acceleratorData)*/ + + Report( + (data.ts * 1000).toString(16), + data.acceleratorData, + data.gyro + ); }); // ws.on("error", () => { // phoneIsConnected = false; diff --git a/static.html b/static.html index c3b420c..956d0c8 100755 --- a/static.html +++ b/static.html @@ -36,7 +36,10 @@ -

WebSocket State:

+

WebSocket State:

+

x:0

+

y:0

+

z:0

x:0

y:0

z:0

@@ -96,19 +99,23 @@ x: -scale * motion.rotationRate.beta, y: -scale * motion.rotationRate.gamma, } - + var acceleratorData = { + x: motion.accelerationIncludingGravity.x, + y: -1 * motion.accelerationIncludingGravity.z, + z: -1 * motion.accelerationIncludingGravity.y, + } document.getElementById("x").textContent = 'x:' + gyroV.x document.getElementById("y").textContent = 'y:' + gyroV.y document.getElementById("z").textContent = 'z:' + gyroV.z + document.getElementById("acx").textContent = 'acceleration:x:' + acceleratorData.x + document.getElementById("acy").textContent = 'acceleration:y:' + acceleratorData.y + document.getElementById("acz").textContent = 'acceleration:z:' + acceleratorData.z document.getElementById("s").textContent = 'Current Sensitivity:' + scale var data = { ts: new Date().getTime(), gyro: screen == 'v' ? gyroV : gyroH, - acceleration: { - x: 0, - y: 0, - z: 0 - } + //acceleration: {x: 0,y: 0,z: 0} + acceleratorData } ws.emit('report',JSON.stringify(data)); }; From 585aaa2e01b680c495ac27eb7865c1ab8c32dd72 Mon Sep 17 00:00:00 2001 From: zxhzxhz <47572137+zxhzxhz@users.noreply.github.com> Date: Mon, 27 Jan 2020 14:32:05 +0800 Subject: [PATCH 2/4] Update static.html --- static.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/static.html b/static.html index 956d0c8..f7bd4d4 100755 --- a/static.html +++ b/static.html @@ -101,8 +101,8 @@ } var acceleratorData = { x: motion.accelerationIncludingGravity.x, - y: -1 * motion.accelerationIncludingGravity.z, - z: -1 * motion.accelerationIncludingGravity.y, + y: motion.accelerationIncludingGravity.z, + z: motion.accelerationIncludingGravity.y, } document.getElementById("x").textContent = 'x:' + gyroV.x document.getElementById("y").textContent = 'y:' + gyroV.y @@ -128,4 +128,4 @@ }) - \ No newline at end of file + From 4854e320d568fac49da2eebd88992279eb908fbd Mon Sep 17 00:00:00 2001 From: zxhzxhz <47572137+zxhzxhz@users.noreply.github.com> Date: Wed, 6 May 2020 03:37:41 +0800 Subject: [PATCH 3/4] Update README.md --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c03ad21..286ae3b 100755 --- a/README.md +++ b/README.md @@ -2,11 +2,26 @@ Use web ondevicemotion event data provided to cemuhook. +added accelation data by me. + +You can use original version by hjmmc. + + + ## Usage -Download releases [Gyro.exe](https://github.com/hjmmc/WebGyroForCemuhook/releases) +~~Download releases [Gyro.exe](https://github.com/hjmmc/WebGyroForCemuhook/releases)~~ + +~~Double click Gyro.exe~~ + +Download code and run with Node.js -Double click Gyro.exe +``` +git clone https://github.com/zxhzxhz/WebGyroForCemuhook.git +cd WebGyroForCemuhook +npm install +npm start +``` Run Cemu.exe and Checked Options->GamePad mation source->DSU1->By Slot From f92f36a5fbcfb6aef8847d2dee263a1dfbbd17f5 Mon Sep 17 00:00:00 2001 From: zxhzxhz <47572137+zxhzxhz@users.noreply.github.com> Date: Wed, 6 May 2020 03:41:25 +0800 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 286ae3b..dc75f40 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Use web ondevicemotion event data provided to cemuhook. -added accelation data by me. +added acceleration data by me. You can use original version by hjmmc.