2b3744a344
- Added Gyroscope and accelerometer support. Now the 3DS sends the data of the Gyroscope and accelerometer to the IP address - Now the python script uses `python-evdev` instead of `python-uinput`. It support more EVENTS and INPUT_PROPS, so the gyroscope and accelerometer is identified as an gyro and accel device. Just like the DualShock linux driver (hid-playstation.c) - Python script has now a debug variable, if it's enabled it will show some debug info, like the state of the keys and sensors X,Y,Z positions. - Added some explanations on the python script to make development more easier (Mostly for myself)
60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
#include <stddef.h>
|
|
#include <string.h>
|
|
#include "keyboard.h"
|
|
#include "sys/_types.h"
|
|
#include "wireless.h"
|
|
|
|
int sock;
|
|
struct sockaddr_in sain, saout;
|
|
struct packet outBuf, rcvBuf;
|
|
|
|
socklen_t sockaddr_in_sizePtr = (int)sizeof(struct sockaddr_in);
|
|
|
|
bool openSocket(int port) {
|
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
saout.sin_family = sain.sin_family = AF_INET;
|
|
saout.sin_port = sain.sin_port = htons(port);
|
|
sain.sin_addr.s_addr = INADDR_ANY;
|
|
|
|
bind(sock, (struct sockaddr *)&sain, sizeof(sain));
|
|
|
|
fcntl(sock, F_SETFL, O_NONBLOCK);
|
|
|
|
return true;
|
|
}
|
|
|
|
void sendBuf(int length) {
|
|
sendto(sock, (char *)&outBuf, length, 0, (struct sockaddr *)&saout,
|
|
sizeof(saout));
|
|
}
|
|
|
|
int receiveBuffer(int length) {
|
|
return recvfrom(sock, (char *)&rcvBuf, length, 0, (struct sockaddr *)&sain,
|
|
&sockaddr_in_sizePtr);
|
|
}
|
|
|
|
void sendConnectionRequest(void) {
|
|
outBuf.command = CONNECT;
|
|
outBuf.keyboardActive = keyboardActive;
|
|
sendBuf(offsetof(struct packet, connectPacket) +
|
|
sizeof(struct connectPacket));
|
|
}
|
|
|
|
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch,
|
|
circlePosition cStick, unsigned int volume,
|
|
angularRate gyro, accelVector accel) {
|
|
outBuf.command = KEYS;
|
|
outBuf.keyboardActive = keyboardActive;
|
|
memcpy(&outBuf.keys, &keys, 4);
|
|
memcpy(&outBuf.circlePad, &circlePad, 4);
|
|
memcpy(&outBuf.touch, &touch, 4);
|
|
memcpy(&outBuf.cStick, &cStick, 4);
|
|
memcpy(&outBuf.volume, &volume, 4);
|
|
memcpy(&outBuf.gyro, &gyro, 6);
|
|
// Padding to separate gyro from accel, making it less confusing when parsing the data
|
|
outBuf.padding = 0;
|
|
memcpy(&outBuf.accel, &accel, 6);
|
|
// memcpy(&outBuf.threeD32, &threeD32, 4);
|
|
sendBuf(offsetof(struct packet, keysPacket) + sizeof(struct keysPacket));
|
|
}
|