mirror of
https://github.com/DevL0rd/SkyNX
synced 2024-11-22 02:53:04 +00:00
FINALLY figured out instable hid connection
This commit is contained in:
parent
799a82034b
commit
bfff6828bc
7 changed files with 126 additions and 115 deletions
11
.vscode/settings.json
vendored
11
.vscode/settings.json
vendored
|
@ -6,6 +6,15 @@
|
|||
"iosfwd": "c",
|
||||
"queue": "c",
|
||||
"sdl.h": "c",
|
||||
"context.h": "c"
|
||||
"context.h": "c",
|
||||
"array": "c",
|
||||
"deque": "c",
|
||||
"list": "c",
|
||||
"vector": "c",
|
||||
"xhash": "c",
|
||||
"xstring": "c",
|
||||
"xutility": "c",
|
||||
"string_view": "c",
|
||||
"type_traits": "c"
|
||||
}
|
||||
}
|
|
@ -346,9 +346,9 @@ function smoothGyroMouse(gyro) {
|
|||
} else {
|
||||
gyroHistory.shift();
|
||||
gyroHistory.push(gyro);
|
||||
gyro.x = (gyroHistory[0].x + gyroHistory[1].x + gyroHistory[2].x) / 3;
|
||||
gyro.y = (gyroHistory[0].y + gyroHistory[1].y + gyroHistory[2].y) / 3;
|
||||
gyro.z = (gyroHistory[0].z + gyroHistory[1].z + gyroHistory[2].z) / 3;
|
||||
gyro.x = ((gyroHistory[0].x * 1) + (gyroHistory[1].x * 3) + (gyroHistory[2].x * 5)) / 9;
|
||||
gyro.y = ((gyroHistory[0].y * 1) + (gyroHistory[1].y * 3) + (gyroHistory[2].y * 5)) / 9;
|
||||
gyro.z = ((gyroHistory[0].z * 1) + (gyroHistory[1].z * 3) + (gyroHistory[2].z * 5)) / 9;
|
||||
if (gyro.x < 0.01 && gyro.x > 0) {
|
||||
gyro.x = 0;
|
||||
} else if (gyro.x > -0.01 && gyro.x < 0) {
|
||||
|
@ -465,6 +465,7 @@ function handleTouchInput(hid) {
|
|||
}
|
||||
}
|
||||
function handleGyroAndAccel(hid) {
|
||||
|
||||
var gyro = { x: hid.get("gyroX"), y: hid.get("gyroY"), z: hid.get("gyroZ") }
|
||||
var accel = { x: hid.get("accelX"), y: hid.get("accelY"), z: hid.get("accelZ") }
|
||||
for (axis in gyro) {
|
||||
|
@ -475,6 +476,7 @@ function handleGyroAndAccel(hid) {
|
|||
}
|
||||
|
||||
hidStreamClient.on('data', function (data) {
|
||||
console.log("dataLength: " + data.length)
|
||||
switchHidBuffer = new Buffer.from(data);
|
||||
var hid = parseInputStruct(switchHidBuffer)
|
||||
var controllerCount = hid.get("controllerCount");
|
||||
|
|
|
@ -11,7 +11,7 @@ void gamePadSend(JoyConSocket *connection)
|
|||
JoyPkg pkg;
|
||||
/* Recieve switch input and generate the package */
|
||||
hidScanInput();
|
||||
unsigned int controllersConnected = 0;
|
||||
u32 controllersConnected = 0;
|
||||
HidControllerID player1Id;
|
||||
if (hidGetHandheldMode())
|
||||
{
|
||||
|
@ -31,86 +31,89 @@ void gamePadSend(JoyConSocket *connection)
|
|||
}
|
||||
pkg.frameRate = frameRate;
|
||||
pkg.controllerCount = controllersConnected;
|
||||
pkg.heldKeys1 = (u32)hidKeysHeld(player1Id);
|
||||
|
||||
pkg.heldKeys1 = !(u32)hidKeysHeld(player1Id) ? 0 : (u32)hidKeysHeld(player1Id);
|
||||
hidJoystickRead(&lJoy, player1Id, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&rJoy, player1Id, JOYSTICK_RIGHT);
|
||||
pkg.lJoyX1 = lJoy.dx;
|
||||
pkg.lJoyY1 = lJoy.dy;
|
||||
pkg.rJoyX1 = rJoy.dx;
|
||||
pkg.rJoyY1 = rJoy.dy;
|
||||
pkg.lJoyX1 = !lJoy.dx ? 0 : lJoy.dx;
|
||||
pkg.lJoyY1 = !lJoy.dy ? 0 : lJoy.dy;
|
||||
pkg.rJoyX1 = !rJoy.dx ? 0 : rJoy.dx;
|
||||
pkg.rJoyY1 = !rJoy.dy ? 0 : rJoy.dy;
|
||||
|
||||
pkg.heldKeys2 = (u32)hidKeysHeld(CONTROLLER_PLAYER_2);
|
||||
pkg.heldKeys2 = !(u32)hidKeysHeld(CONTROLLER_PLAYER_2) ? 0 : (u32)hidKeysHeld(CONTROLLER_PLAYER_2);
|
||||
hidJoystickRead(&lJoy, CONTROLLER_PLAYER_2, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&rJoy, CONTROLLER_PLAYER_2, JOYSTICK_RIGHT);
|
||||
pkg.lJoyX2 = lJoy.dx;
|
||||
pkg.lJoyY2 = lJoy.dy;
|
||||
pkg.rJoyX2 = rJoy.dx;
|
||||
pkg.rJoyY2 = rJoy.dy;
|
||||
pkg.lJoyX2 = !lJoy.dx ? 0 : lJoy.dx;
|
||||
pkg.lJoyY2 = !lJoy.dy ? 0 : lJoy.dy;
|
||||
pkg.rJoyX2 = !rJoy.dx ? 0 : rJoy.dx;
|
||||
pkg.rJoyY2 = !rJoy.dy ? 0 : rJoy.dy;
|
||||
|
||||
pkg.heldKeys3 = (u32)hidKeysHeld(CONTROLLER_PLAYER_3);
|
||||
pkg.heldKeys3 = !(u32)hidKeysHeld(CONTROLLER_PLAYER_3) ? 0 : (u32)hidKeysHeld(CONTROLLER_PLAYER_3);
|
||||
hidJoystickRead(&lJoy, CONTROLLER_PLAYER_3, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&rJoy, CONTROLLER_PLAYER_3, JOYSTICK_RIGHT);
|
||||
pkg.lJoyX3 = lJoy.dx;
|
||||
pkg.lJoyY3 = lJoy.dy;
|
||||
pkg.rJoyX3 = rJoy.dx;
|
||||
pkg.rJoyY3 = rJoy.dy;
|
||||
pkg.lJoyX3 = !lJoy.dx ? 0 : lJoy.dx;
|
||||
pkg.lJoyY3 = !lJoy.dy ? 0 : lJoy.dy;
|
||||
pkg.rJoyX3 = !rJoy.dx ? 0 : rJoy.dx;
|
||||
pkg.rJoyY3 = !rJoy.dy ? 0 : rJoy.dy;
|
||||
|
||||
pkg.heldKeys4 = (u32)hidKeysHeld(CONTROLLER_PLAYER_4);
|
||||
pkg.heldKeys4 = !(u32)hidKeysHeld(CONTROLLER_PLAYER_4) ? 0 : (u32)hidKeysHeld(CONTROLLER_PLAYER_4);
|
||||
hidJoystickRead(&lJoy, CONTROLLER_PLAYER_4, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&rJoy, CONTROLLER_PLAYER_4, JOYSTICK_RIGHT);
|
||||
pkg.lJoyX4 = lJoy.dx;
|
||||
pkg.lJoyY4 = lJoy.dy;
|
||||
pkg.rJoyX4 = rJoy.dx;
|
||||
pkg.rJoyY4 = rJoy.dy;
|
||||
pkg.lJoyX4 = !lJoy.dx ? 0 : lJoy.dx;
|
||||
pkg.lJoyY4 = !lJoy.dy ? 0 : lJoy.dy;
|
||||
pkg.rJoyX4 = !rJoy.dx ? 0 : rJoy.dx;
|
||||
pkg.rJoyY4 = !rJoy.dy ? 0 : rJoy.dy;
|
||||
|
||||
pkg.heldKeys5 = (u32)hidKeysHeld(CONTROLLER_PLAYER_5);
|
||||
pkg.heldKeys5 = !(u32)hidKeysHeld(CONTROLLER_PLAYER_5) ? 0 : (u32)hidKeysHeld(CONTROLLER_PLAYER_5);
|
||||
hidJoystickRead(&lJoy, CONTROLLER_PLAYER_5, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&rJoy, CONTROLLER_PLAYER_5, JOYSTICK_RIGHT);
|
||||
pkg.lJoyX5 = lJoy.dx;
|
||||
pkg.lJoyY5 = lJoy.dy;
|
||||
pkg.rJoyX5 = rJoy.dx;
|
||||
pkg.rJoyY5 = rJoy.dy;
|
||||
|
||||
pkg.heldKeys6 = (u32)hidKeysHeld(CONTROLLER_PLAYER_6);
|
||||
pkg.lJoyX5 = !lJoy.dx ? 0 : lJoy.dx;
|
||||
pkg.lJoyY5 = !lJoy.dy ? 0 : lJoy.dy;
|
||||
pkg.rJoyX5 = !rJoy.dx ? 0 : rJoy.dx;
|
||||
pkg.rJoyY5 = !rJoy.dy ? 0 : rJoy.dy;
|
||||
|
||||
pkg.heldKeys6 = !(u32)hidKeysHeld(CONTROLLER_PLAYER_6) ? 0 : (u32)hidKeysHeld(CONTROLLER_PLAYER_6);
|
||||
hidJoystickRead(&lJoy, CONTROLLER_PLAYER_6, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&rJoy, CONTROLLER_PLAYER_6, JOYSTICK_RIGHT);
|
||||
pkg.lJoyX6 = lJoy.dx;
|
||||
pkg.lJoyY6 = lJoy.dy;
|
||||
pkg.rJoyX6 = rJoy.dx;
|
||||
pkg.rJoyY6 = rJoy.dy;
|
||||
pkg.lJoyX6 = !lJoy.dx ? 0 : lJoy.dx;
|
||||
pkg.lJoyY6 = !lJoy.dy ? 0 : lJoy.dy;
|
||||
pkg.rJoyX6 = !rJoy.dx ? 0 : rJoy.dx;
|
||||
pkg.rJoyY6 = !rJoy.dy ? 0 : rJoy.dy;
|
||||
|
||||
pkg.heldKeys7 = (u32)hidKeysHeld(CONTROLLER_PLAYER_7);
|
||||
pkg.heldKeys7 = !(u32)hidKeysHeld(CONTROLLER_PLAYER_7) ? 0 : (u32)hidKeysHeld(CONTROLLER_PLAYER_7);
|
||||
hidJoystickRead(&lJoy, CONTROLLER_PLAYER_7, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&rJoy, CONTROLLER_PLAYER_7, JOYSTICK_RIGHT);
|
||||
pkg.lJoyX7 = lJoy.dx;
|
||||
pkg.lJoyY7 = lJoy.dy;
|
||||
pkg.rJoyX7 = rJoy.dx;
|
||||
pkg.rJoyY7 = rJoy.dy;
|
||||
pkg.lJoyX7 = !lJoy.dx ? 0 : lJoy.dx;
|
||||
pkg.lJoyY7 = !lJoy.dy ? 0 : lJoy.dy;
|
||||
pkg.rJoyX7 = !rJoy.dx ? 0 : rJoy.dx;
|
||||
pkg.rJoyY7 = !rJoy.dy ? 0 : rJoy.dy;
|
||||
|
||||
pkg.heldKeys8 = (u32)hidKeysHeld(CONTROLLER_PLAYER_8);
|
||||
pkg.heldKeys8 = !(u32)hidKeysHeld(CONTROLLER_PLAYER_8) ? 0 : (u32)hidKeysHeld(CONTROLLER_PLAYER_8);
|
||||
hidJoystickRead(&lJoy, CONTROLLER_PLAYER_8, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&rJoy, CONTROLLER_PLAYER_8, JOYSTICK_RIGHT);
|
||||
pkg.lJoyX8 = lJoy.dx;
|
||||
pkg.lJoyY8 = lJoy.dy;
|
||||
pkg.rJoyX8 = rJoy.dx;
|
||||
pkg.rJoyY8 = rJoy.dy;
|
||||
pkg.lJoyX8 = !lJoy.dx ? 0 : lJoy.dx;
|
||||
pkg.lJoyY8 = !lJoy.dy ? 0 : lJoy.dy;
|
||||
pkg.rJoyX8 = !rJoy.dx ? 0 : rJoy.dx;
|
||||
pkg.rJoyY8 = !rJoy.dy ? 0 : rJoy.dy;
|
||||
|
||||
touchPosition touch;
|
||||
hidTouchRead(&touch, 0);
|
||||
pkg.touchX1 = touch.px;
|
||||
pkg.touchY1 = touch.py;
|
||||
pkg.touchX1 = !touch.px ? 0 : touch.px;
|
||||
pkg.touchY1 = !touch.py ? 0 : touch.py;
|
||||
hidTouchRead(&touch, 1);
|
||||
pkg.touchX2 = touch.px;
|
||||
pkg.touchY2 = touch.py;
|
||||
pkg.touchX2 = !touch.px ? 0 : touch.px;
|
||||
pkg.touchY2 = !touch.py ? 0 : touch.py;
|
||||
|
||||
SixAxisSensorValues sixaxis;
|
||||
// You can read back up to 17 successive values at once
|
||||
hidSixAxisSensorValuesRead(&sixaxis, player1Id, 1);
|
||||
pkg.accelX = sixaxis.accelerometer.x;
|
||||
pkg.accelY = sixaxis.accelerometer.y;
|
||||
pkg.accelZ = sixaxis.accelerometer.z;
|
||||
pkg.gyroX = sixaxis.gyroscope.x;
|
||||
pkg.gyroY = sixaxis.gyroscope.y;
|
||||
pkg.gyroZ = sixaxis.gyroscope.z;
|
||||
pkg.accelX = !sixaxis.accelerometer.x ? 0 : sixaxis.accelerometer.x;
|
||||
pkg.accelY = !sixaxis.accelerometer.y ? 0 : sixaxis.accelerometer.y;
|
||||
pkg.accelZ = !sixaxis.accelerometer.z ? 0 : sixaxis.accelerometer.z;
|
||||
pkg.gyroX = !sixaxis.gyroscope.x ? 0 : sixaxis.gyroscope.x;
|
||||
pkg.gyroY = !sixaxis.gyroscope.y ? 0 : sixaxis.gyroscope.y;
|
||||
pkg.gyroZ = !sixaxis.gyroscope.z ? 0 : sixaxis.gyroscope.z;
|
||||
sendJoyConInput(connection, &pkg);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ static const SocketInitConfig socketInitConf = {
|
|||
.tcp_rx_buf_max_size = 0x400000,
|
||||
|
||||
.udp_tx_buf_size = 0x1400,
|
||||
.udp_rx_buf_size = 0x2500,
|
||||
.udp_rx_buf_size = 0x3500,
|
||||
|
||||
.sb_efficiency = 2,
|
||||
};
|
||||
|
@ -123,8 +123,7 @@ void init()
|
|||
/* Init all switch required systems */
|
||||
switchInit();
|
||||
pcvSetClockRate(PcvModule_CpuBus, 1785000000); //Overclock CPU
|
||||
pcvSetClockRate(PcvModule_GPU, 921000000); //Overclock GPU
|
||||
pcvSetClockRate(PcvModule_EMC, 1600000000); //OC memory to docked frequency
|
||||
|
||||
renderContext = createRenderer();
|
||||
videoContext = createVideoContext();
|
||||
videoContext->renderContext = renderContext;
|
||||
|
@ -139,8 +138,6 @@ void unInit()
|
|||
freeVideoContext(videoContext);
|
||||
unInitGyro();
|
||||
pcvSetClockRate(PcvModule_CpuBus, 1020000000); //Reset CPU clock to default
|
||||
pcvSetClockRate(PcvModule_GPU, 768000000); //Reset GPU clock to docked frequency
|
||||
// pcvSetClockRate(PcvModule_EMC, 1600000000); //Leave memory in docked frequency
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
|
|
@ -10,58 +10,58 @@
|
|||
/* Data to send to server */
|
||||
typedef struct
|
||||
{
|
||||
u32 heldKeys1;
|
||||
s32 lJoyX1;
|
||||
s32 lJoyY1;
|
||||
s32 rJoyX1;
|
||||
s32 rJoyY1;
|
||||
u32 heldKeys2;
|
||||
s32 lJoyX2;
|
||||
s32 lJoyY2;
|
||||
s32 rJoyX2;
|
||||
s32 rJoyY2;
|
||||
u32 heldKeys3;
|
||||
s32 lJoyX3;
|
||||
s32 lJoyY3;
|
||||
s32 rJoyX3;
|
||||
s32 rJoyY3;
|
||||
u32 heldKeys4;
|
||||
s32 lJoyX4;
|
||||
s32 lJoyY4;
|
||||
s32 rJoyX4;
|
||||
s32 rJoyY4;
|
||||
u32 heldKeys5;
|
||||
s32 lJoyX5;
|
||||
s32 lJoyY5;
|
||||
s32 rJoyX5;
|
||||
s32 rJoyY5;
|
||||
u32 heldKeys6;
|
||||
s32 lJoyX6;
|
||||
s32 lJoyY6;
|
||||
s32 rJoyX6;
|
||||
s32 rJoyY6;
|
||||
u32 heldKeys7;
|
||||
s32 lJoyX7;
|
||||
s32 lJoyY7;
|
||||
s32 rJoyX7;
|
||||
s32 rJoyY7;
|
||||
u32 heldKeys8;
|
||||
s32 lJoyX8;
|
||||
s32 lJoyY8;
|
||||
s32 rJoyX8;
|
||||
s32 rJoyY8;
|
||||
u32 touchX1;
|
||||
u32 touchY1;
|
||||
u32 touchX2;
|
||||
u32 touchY2;
|
||||
float accelX;
|
||||
float accelY;
|
||||
float accelZ;
|
||||
float gyroX;
|
||||
float gyroY;
|
||||
float gyroZ;
|
||||
unsigned int controllerCount;
|
||||
unsigned int frameRate;
|
||||
uint32_t heldKeys1;
|
||||
int32_t lJoyX1;
|
||||
int32_t lJoyY1;
|
||||
int32_t rJoyX1;
|
||||
int32_t rJoyY1;
|
||||
uint32_t heldKeys2;
|
||||
int32_t lJoyX2;
|
||||
int32_t lJoyY2;
|
||||
int32_t rJoyX2;
|
||||
int32_t rJoyY2;
|
||||
uint32_t heldKeys3;
|
||||
int32_t lJoyX3;
|
||||
int32_t lJoyY3;
|
||||
int32_t rJoyX3;
|
||||
int32_t rJoyY3;
|
||||
uint32_t heldKeys4;
|
||||
int32_t lJoyX4;
|
||||
int32_t lJoyY4;
|
||||
int32_t rJoyX4;
|
||||
int32_t rJoyY4;
|
||||
uint32_t heldKeys5;
|
||||
int32_t lJoyX5;
|
||||
int32_t lJoyY5;
|
||||
int32_t rJoyX5;
|
||||
int32_t rJoyY5;
|
||||
uint32_t heldKeys6;
|
||||
int32_t lJoyX6;
|
||||
int32_t lJoyY6;
|
||||
int32_t rJoyX6;
|
||||
int32_t rJoyY6;
|
||||
uint32_t heldKeys7;
|
||||
int32_t lJoyX7;
|
||||
int32_t lJoyY7;
|
||||
int32_t rJoyX7;
|
||||
int32_t rJoyY7;
|
||||
uint32_t heldKeys8;
|
||||
int32_t lJoyX8;
|
||||
int32_t lJoyY8;
|
||||
int32_t rJoyX8;
|
||||
int32_t rJoyY8;
|
||||
uint32_t touchX1;
|
||||
uint32_t touchY1;
|
||||
uint32_t touchX2;
|
||||
uint32_t touchY2;
|
||||
float_t accelX;
|
||||
float_t accelY;
|
||||
float_t accelZ;
|
||||
float_t gyroX;
|
||||
float_t gyroY;
|
||||
float_t gyroZ;
|
||||
uint32_t controllerCount;
|
||||
uint32_t frameRate;
|
||||
} JoyPkg;
|
||||
|
||||
/* Init nx network and av network */
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
float timeThen = 0;
|
||||
float timeNow = 1;
|
||||
float delta = 1;
|
||||
unsigned int frameRate = 0;
|
||||
u32 frameRate = 0;
|
||||
void initDelta()
|
||||
{
|
||||
timeThen = svcGetSystemTick();
|
||||
|
@ -489,7 +489,7 @@ void handleFrame(RenderContext *renderContext, VideoContext *videoContext)
|
|||
if (++videoContext->video_frame_count % 60 == 0)
|
||||
{
|
||||
new_time = svcGetSystemTick();
|
||||
frameRate = (unsigned int)(60.0 / ((new_time - old_time) / 19200000.0));
|
||||
frameRate = (u32)(60.0 / ((new_time - old_time) / 19200000.0));
|
||||
old_time = new_time;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <libswscale/swscale.h>
|
||||
|
||||
#include "context.h"
|
||||
unsigned int frameRate;
|
||||
u32 frameRate;
|
||||
/* Allocates a render context */
|
||||
RenderContext *createRenderer(void);
|
||||
|
||||
|
|
Loading…
Reference in a new issue