player 1 controls fixed, but others are not working atm

This commit is contained in:
DevL0rd 2022-03-04 23:51:27 +07:00
parent acf91af8e0
commit b5f93d9c7d
4 changed files with 87 additions and 99 deletions

View file

@ -19,7 +19,8 @@
"thread.h": "c", "thread.h": "c",
"renderer.h": "c", "renderer.h": "c",
"switch.h": "c", "switch.h": "c",
"xmemory0": "c" "xmemory0": "c",
"socket.h": "c"
}, },
"Lua.diagnostics.disable": [ "Lua.diagnostics.disable": [
"lowercase-global", "lowercase-global",

View file

@ -89,15 +89,7 @@ app.on('ready', function () {
// Quit when all windows are closed. // Quit when all windows are closed.
app.on('window-all-closed', function () { app.on('window-all-closed', function () {
if (ffmpegAudioProcess) { killStream();
ffmpegAudioProcess.kill();
}
if (ffmpegProcess) {
ffmpegProcess.kill();
}
if (autoChangeResolution) {
changeScreenRes(originalW, originalH);
}
if (process.platform !== 'darwin') app.quit() if (process.platform !== 'darwin') app.quit()
}) })
@ -126,6 +118,7 @@ function log(str) {
// Emitted when the window is closed. // Emitted when the window is closed.
ipcMain.on('close', function () { ipcMain.on('close', function () {
killStream();
mainWindow.destroy(); mainWindow.destroy();
}); });
ipcMain.on('min', function () { ipcMain.on('min', function () {
@ -185,6 +178,20 @@ ipcMain.on("restartComputer", (event, fullMessage) => {
//Streaming //Streaming
//***************************************************************/ //***************************************************************/
function killStream() {
if (autoChangeResolution) {
changeScreenRes(originalW, originalH);
}
if (hidStreamClient) {
hidStreamClient.end();
}
if (ffmpegProcess) {
ffmpegProcess.kill();
}
if (ffmpegAudioProcess) {
ffmpegAudioProcess.kill();
}
}
function startStreamer(arg) { function startStreamer(arg) {
screenWidth = mainScreen.bounds.width * screen.getPrimaryDisplay().scaleFactor; screenWidth = mainScreen.bounds.width * screen.getPrimaryDisplay().scaleFactor;
screenHeight = mainScreen.bounds.height * screen.getPrimaryDisplay().scaleFactor; screenHeight = mainScreen.bounds.height * screen.getPrimaryDisplay().scaleFactor;
@ -235,7 +242,6 @@ function startStreamer(arg) {
); );
ffmpegProcess.stdout.on("data", data => { ffmpegProcess.stdout.on("data", data => {
log(`${data}`); log(`${data}`);
restartingStream = false;
}); });
ffmpegProcess.stderr.on('data', (data) => { ffmpegProcess.stderr.on('data', (data) => {
log(`${data}`); log(`${data}`);
@ -245,9 +251,6 @@ function startStreamer(arg) {
if (autoChangeResolution && !restartingStream) { if (autoChangeResolution && !restartingStream) {
changeScreenRes(originalW, originalH); changeScreenRes(originalW, originalH);
} }
if (restartingStream) {
startStreamer(arg);
}
clientSender.send("close"); clientSender.send("close");
}); });
} }
@ -273,27 +276,22 @@ function startStreamer(arg) {
ipcMain.on('connect', (event, arg) => { ipcMain.on('connect', (event, arg) => {
clientSender = event.sender; clientSender = event.sender;
killStream()
startStreamer(arg); startStreamer(arg);
}) })
ipcMain.on('restart', (event, arg) => { ipcMain.on('restart', (event, arg) => {
restartingStream = true; restartingStream = true;
if (ffmpegAudioProcess) { killStream()
ffmpegAudioProcess.kill(); setTimeout(function () {
} restartingStream = false;
if (ffmpegProcess) { startStreamer(arg);
ffmpegProcess.kill(); }, 1000)
}
}); });
ipcMain.on('kill', (event, arg) => { ipcMain.on('kill', (event, arg) => {
if (ffmpegAudioProcess) { killStream()
ffmpegAudioProcess.kill();
}
if (ffmpegProcess) {
ffmpegProcess.kill();
}
}); });
@ -389,9 +387,6 @@ function convertAnalog(axis) {
} }
return na; return na;
} }
function convertAnalogXY(x, y) {
return { x: convertAnalog(x), y: convertAnalog(y) };
}
function handleControllerInput(hid, controllerId, playerNumber) { function handleControllerInput(hid, controllerId, playerNumber) {
var heldKeys = hid.get("HeldKeys" + playerNumber); var heldKeys = hid.get("HeldKeys" + playerNumber);
var LJoyX = convertAnalog(hid.get("LJoyX" + playerNumber)); var LJoyX = convertAnalog(hid.get("LJoyX" + playerNumber));
@ -678,74 +673,64 @@ function connectHID() {
hidStreamClient.setNoDelay(true); hidStreamClient.setNoDelay(true);
log('Connected to Switch!'); log('Connected to Switch!');
}); });
} hidStreamClient.on('error', function (ex) {
hidStreamClient.on('error', function (ex) { if (ex) {
log("Could not connect to Switch. Connection timed out..."); log("Could not connect to Switch. Connection timed out...");
if (ex) { // setTimeout(connectHID, 1000);
log("Could not connect to Switch. Connection timed out...");
setTimeout(connectHID, 1000);
}
});
hidStreamClient.on('data', function (chunk) {
log(chunk)
hidDataBuffer += chunk.toString("hex");
var completeData = "";
if (hidDataBuffer.includes("ffffffffffffffff") && hidDataBuffer.includes("ffffffffffffff7")) {
completeData = hidDataBuffer.split("ffffffffffffffff")[1].split("ffffffffffffff7")[0];
hidDataBuffer = "";
if (completeData.length != 416) {
log("Incorrect data length: " + completeData.length + " - " + completeData);
return
} }
} else { });
return; hidStreamClient.on('data', function (chunk) {
} hidDataBuffer += chunk.toString("hex");
var data = Buffer.from(completeData, 'hex'); var completeData = "";
var hid = parseInputStruct(data); if (hidDataBuffer.includes("ffffffffffffffff") && hidDataBuffer.includes("ffffffffffffff7")) {
completeData = hidDataBuffer.split("ffffffffffffffff")[1].split("ffffffffffffff7")[0];
hidDataBuffer = "";
if (completeData.length != 256) {
log("Incorrect data length: " + completeData.length + " - " + completeData);
return
}
} else {
return;
}
var data = Buffer.from(completeData, 'hex');
var hid = parseInputStruct(data);
var controllerCount = hid.get("controllerCount"); var controllerCount = hid.get("controllerCount");
if (controllerCount > controllerIds.length) { if (controllerCount > controllerIds.length) {
plugControllerIn(); plugControllerIn();
} }
fpsPrintTimer++; // fpsPrintTimer++;
if (fpsPrintTimer == 10) { // if (fpsPrintTimer == 10) {
log("switchFps=" + hid.get("frameRate")) // log("switchFps=" + hid.get("frameRate"))
fpsPrintTimer = 0; // fpsPrintTimer = 0;
} // }
var playerNumber; var playerNumber;
for (i in controllerIds) {
playerNumber = parseInt(i) + 1;
handleControllerInput(hid, controllerIds[i], playerNumber);
}
handleMouseInputToggling(hid, 1);
if (mouseControl == "ANALOG" && mouseInput) {
handleAnalogMouse(hid, 1);
} else if (mouseControl == "GYRO" && mouseInput) {
handleGyroMouse(hid, 1);
}
handleTouchInput(hid);
handleGyroAndAccel(hid);
});
hidStreamClient.on('close', function () {
log('hidStreamClient Disconnected.');
try {
for (i in controllerIds) { for (i in controllerIds) {
vgen.unplug(controllerIds[i]); playerNumber = parseInt(i) + 1;
handleControllerInput(hid, controllerIds[i], playerNumber);
} }
controllerIds = []; handleMouseInputToggling(hid, 1);
} catch (error) { if (mouseControl == "ANALOG" && mouseInput) {
handleAnalogMouse(hid, 1);
} } else if (mouseControl == "GYRO" && mouseInput) {
if (usingVideo) { handleGyroMouse(hid, 1);
ffmpegProcess.kill(); }
} handleTouchInput(hid);
if (usingAudio) { handleGyroAndAccel(hid);
ffmpegAudioProcess.kill(); });
}
setTimeout(connectHID, 1000);
});
hidStreamClient.on('close', function () {
log('hidStreamClient Disconnected.');
try {
for (i in controllerIds) {
vgen.unplug(controllerIds[i]);
}
controllerIds = [];
} catch (error) {
}
killStream();
});
}

View file

@ -44,11 +44,13 @@ void gamePadSend(JoyConSocket *connection)
// printf("hiddbgSetAutoPilotVirtualPadState(): 0x%x\n", rc); // printf("hiddbgSetAutoPilotVirtualPadState(): 0x%x\n", rc);
// } // }
pkg.heldKeys1 = (uint32_t)states[0].state.buttons; HidAnalogStickState analog_stick_l = padGetStickPos(&pad, 0);
pkg.lJoyX1 = (int32_t)states[0].state.analog_stick_l.x; HidAnalogStickState analog_stick_r = padGetStickPos(&pad, 1);
pkg.lJoyY1 = (int32_t)states[0].state.analog_stick_l.y; pkg.heldKeys1 = (uint32_t)kHeld;
pkg.rJoyX1 = (int32_t)states[0].state.analog_stick_r.x; pkg.lJoyX1 = (int32_t)analog_stick_l.x;
pkg.rJoyY1 = (int32_t)states[0].state.analog_stick_r.y; pkg.lJoyY1 = (int32_t)analog_stick_l.y;
pkg.rJoyX1 = (int32_t)analog_stick_r.x;
pkg.rJoyY1 = (int32_t)analog_stick_r.y;
pkg.heldKeys2 = (uint32_t)states[1].state.buttons; pkg.heldKeys2 = (uint32_t)states[1].state.buttons;
pkg.lJoyX2 = (int32_t)states[1].state.analog_stick_l.x; pkg.lJoyX2 = (int32_t)states[1].state.analog_stick_l.x;

View file

@ -17,12 +17,12 @@ void network_init(const SocketInitConfig *conf)
nxlinkStdio(); nxlinkStdio();
printf("avformat_network_init\n"); printf("avformat_network_init\n");
avformat_network_init(); // avformat_network_init();
} }
void network_unInit() void network_unInit()
{ {
avformat_network_deinit(); // avformat_network_deinit();
socketExit(); socketExit();
} }