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",
"renderer.h": "c",
"switch.h": "c",
"xmemory0": "c"
"xmemory0": "c",
"socket.h": "c"
},
"Lua.diagnostics.disable": [
"lowercase-global",

View file

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

View file

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

View file

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