3dscontroller-ng/3DSsource/source/inet_pton.c
Fijxu 2b3744a344 Add gyro & accel support. Update python script.
- 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)
2023-07-30 17:22:04 -04:00

44 lines
899 B
C

#include "wireless.h"
#include "inet_pton.h"
int inet_pton4(const char *src, unsigned char *dst) {
static const char digits[] = "0123456789";
int saw_digit, octets, ch;
unsigned char tmp[INADDRSZ], *tp;
saw_digit = 0;
octets = 0;
tp = tmp;
*tp = 0;
while((ch = *src++) != '\0') {
const char *pch;
if((pch = strchr(digits, ch)) != NULL) {
unsigned int val = *tp * 10 + (unsigned int)(pch - digits);
if(saw_digit && *tp == 0)
return (0);
if(val > 255)
return (0);
*tp = (unsigned char)val;
if(! saw_digit) {
if(++octets > 4)
return (0);
saw_digit = 1;
}
}
else if(ch == '.' && saw_digit) {
if(octets == 4)
return (0);
*++tp = 0;
saw_digit = 0;
}
else
return (0);
}
if(octets < 4)
return (0);
memcpy(dst, tmp, INADDRSZ);
return (1);
}