diff --git a/README.md b/README.md index c03ad21..dc75f40 100755 --- a/README.md +++ b/README.md @@ -2,11 +2,26 @@ Use web ondevicemotion event data provided to cemuhook. +added acceleration 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 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..f7bd4d4 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: motion.accelerationIncludingGravity.z, + z: 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)); }; @@ -121,4 +128,4 @@ }) -