detect corrupt packets. hid

This commit is contained in:
devl0rd 2020-04-29 00:04:49 -06:00
parent 3f918ffb1a
commit 1dea781e36
5 changed files with 12 additions and 4 deletions

View file

@ -96,6 +96,7 @@ function startVideoProcess() {
});
}
hidStreamClient.on('connect', function () {
hidStreamClient.setNoDelay(true);
console.log('Connected to Switch!');
if (usingVideo) {
startVideoProcess();
@ -476,8 +477,15 @@ function handleGyroAndAccel(hid) {
}
var fpsPrintTimer = 0;
hidStreamClient.on('data', function (data) {
if (data.length < 208) {
console.log("Data incorrect length. Data length: " + data.length)
return;
} //packet is 208 in length. anyless then the data is bad
if (data.length > 208) {
data.length = 208; //ignore extra data
// console.log(data.length / 208)
}
switchHidBuffer = new Buffer.from(data);
var hid = parseInputStruct(switchHidBuffer)
var controllerCount = hid.get("controllerCount");
if (controllerCount > controllerIds.length) {

View file

@ -134,7 +134,6 @@ void audioHandlerLoop()
resample((unsigned short *)in_buf, sizeof(in_buf), (unsigned short *)buf_data[curBuf], FACT);
play_buf(buffer_size, DATA_SIZE);
played++;
// svcSleepThread(16666665); //Nano sleep to keep at 60fps
}
for (int curBuf = 0; curBuf < BUF_COUNT; curBuf++)

View file

@ -136,7 +136,7 @@ void inputHandlerLoop(void *dummy)
while (appletMainLoop())
{
handleInput(connection);
svcSleepThread(23333333);
svcSleepThread(23333333ULL);
}
freeJoyConSocket(connection);

View file

@ -153,7 +153,7 @@ int main(int argc, char **argv)
{
drawSplash(renderContext);
}
svcSleepThread(14285714); //Nano sleep to keep at 70fps to handle drop frames without stutter
svcSleepThread(14285714ULL); //Nano sleep to keep at 70fps to handle drop frames without stutter
}
/* Deinitialize all used systems */
unInit();

View file

@ -81,6 +81,7 @@ int connectJoyConSocket(JoyConSocket *connection, int port)
void sendJoyConInput(JoyConSocket *connection, const JoyPkg *pkg)
{
// printf("%lu\n", sizeof(JoyPkg));
if (send(connection->sock, pkg, sizeof(JoyPkg), 0) != sizeof(JoyPkg))
{
connection->sock = -1;