Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add acceleration data #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 13 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 15 additions & 8 deletions static.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
<option value="v">vertical</option>
</select>
</div>
<p>WebSocket State:<label id="lblConnected">Disconnecte</label></p>
<p>WebSocket State:<label id="lblConnected">Disconnected</label></p>
<p id="acx">x:0</p>
<p id="acy">y:0</p>
<p id="acz">z:0</p>
<p id="x">x:0</p>
<p id="y">y:0</p>
<p id="z">z:0</p>
Expand Down Expand Up @@ -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));
};
Expand All @@ -121,4 +128,4 @@
})
</script>

</html>
</html>