Apply formatting for files
This commit is contained in:
parent
048d4e8289
commit
28adbd583a
10 changed files with 685 additions and 583 deletions
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#define INADDRSZ 4
|
||||
#define INADDRSZ 4
|
||||
|
||||
int inet_pton4(const char *src, unsigned char *dst);
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "3ds/types.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "3ds/types.h"
|
||||
|
||||
struct settings {
|
||||
char IPString[16];
|
||||
int port;
|
||||
char IPString[16];
|
||||
int port;
|
||||
};
|
||||
|
||||
extern struct settings settings;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
#include <3ds.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "3ds/services/hid.h"
|
||||
#include "inet_pton.h"
|
||||
#include "sys/_types.h"
|
||||
|
@ -16,87 +17,87 @@
|
|||
#define DEFAULT_PORT 8889
|
||||
|
||||
enum NET_COMMANDS {
|
||||
CONNECT,
|
||||
KEYS,
|
||||
SCREENSHOT,
|
||||
CONNECT,
|
||||
KEYS,
|
||||
SCREENSHOT,
|
||||
};
|
||||
|
||||
// It is deliberately set up to have an anonymous struct as well as a named struct for convenience, not a mistake!
|
||||
struct packet {
|
||||
union {
|
||||
struct packetHeader {
|
||||
unsigned char command;
|
||||
unsigned char keyboardActive;
|
||||
};
|
||||
struct packetHeader packetHeader;
|
||||
};
|
||||
|
||||
union {
|
||||
// CONNECT
|
||||
union {
|
||||
struct connectPacket {
|
||||
};
|
||||
struct connectPacket connectPacket;
|
||||
};
|
||||
|
||||
// KEYS
|
||||
union {
|
||||
struct keysPacket {
|
||||
//Keys
|
||||
unsigned int keys;
|
||||
|
||||
//Cirle Pad
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
} circlePad;
|
||||
|
||||
//Touchpad
|
||||
struct {
|
||||
unsigned short x;
|
||||
unsigned short y;
|
||||
} touch;
|
||||
|
||||
//cStick
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
} cStick;
|
||||
|
||||
//Volume
|
||||
unsigned int volume; //way longer than needed, but it works.
|
||||
union {
|
||||
struct packetHeader {
|
||||
unsigned char command;
|
||||
unsigned char keyboardActive;
|
||||
};
|
||||
struct packetHeader packetHeader;
|
||||
};
|
||||
|
||||
//Gyroscope
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
short z;
|
||||
} gyro;
|
||||
union {
|
||||
// CONNECT
|
||||
union {
|
||||
struct connectPacket {
|
||||
};
|
||||
struct connectPacket connectPacket;
|
||||
};
|
||||
|
||||
unsigned char padding;
|
||||
// KEYS
|
||||
union {
|
||||
struct keysPacket {
|
||||
// Keys
|
||||
unsigned int keys;
|
||||
|
||||
//Accelerometer
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
short z;
|
||||
} accel;
|
||||
// Cirle Pad
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
} circlePad;
|
||||
|
||||
// unsigned int threeD32;
|
||||
};
|
||||
struct keysPacket keysPacket;
|
||||
};
|
||||
|
||||
// SCREENSHOT
|
||||
// union {
|
||||
// struct screenshotPacket {
|
||||
// unsigned short offset;
|
||||
// unsigned char data[SCREENSHOT_CHUNK];
|
||||
// };
|
||||
// struct screenshotPacket screenshotPacket;
|
||||
// };
|
||||
// This is not even used so...
|
||||
};
|
||||
// Touchpad
|
||||
struct {
|
||||
unsigned short x;
|
||||
unsigned short y;
|
||||
} touch;
|
||||
|
||||
// cStick
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
} cStick;
|
||||
|
||||
// Volume
|
||||
unsigned int volume; // way longer than needed, but it works.
|
||||
|
||||
// Gyroscope
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
short z;
|
||||
} gyro;
|
||||
|
||||
unsigned char padding;
|
||||
|
||||
// Accelerometer
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
short z;
|
||||
} accel;
|
||||
|
||||
// unsigned int threeD32;
|
||||
};
|
||||
struct keysPacket keysPacket;
|
||||
};
|
||||
|
||||
// SCREENSHOT
|
||||
// union {
|
||||
// struct screenshotPacket {
|
||||
// unsigned short offset;
|
||||
// unsigned char data[SCREENSHOT_CHUNK];
|
||||
// };
|
||||
// struct screenshotPacket screenshotPacket;
|
||||
// };
|
||||
// This is not even used so...
|
||||
};
|
||||
};
|
||||
|
||||
extern int sock;
|
||||
|
|
399
source/drawing.c
399
source/drawing.c
|
@ -1,177 +1,270 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include "drawing.h"
|
||||
|
||||
static const char fonts[] = { //Fonte 8x8 1BPP
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 //tile:0
|
||||
, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0, 0x18, 0x0 //tile:1
|
||||
, 0x6c, 0x6c, 0x6c, 0x0, 0x0, 0x0, 0x0, 0x0 //tile:2
|
||||
, 0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x0 //tile:3
|
||||
, 0x18, 0x7e, 0xc0, 0x7c, 0x6, 0xfc, 0x18, 0x0 //tile:4
|
||||
, 0x0, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xc6, 0x0 //tile:5
|
||||
, 0x38, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0x76, 0x0 //tile:6
|
||||
, 0x30, 0x30, 0x60, 0x0, 0x0, 0x0, 0x0, 0x0 //tile:7
|
||||
, 0xc, 0x18, 0x30, 0x30, 0x30, 0x18, 0xc, 0x0 //tile:8
|
||||
, 0x30, 0x18, 0xc, 0xc, 0xc, 0x18, 0x30, 0x0 //tile:9
|
||||
, 0x0, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x0, 0x0 //tile:10
|
||||
, 0x0, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x0, 0x0 //tile:11
|
||||
, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0x18, 0x30 //tile:12
|
||||
, 0x0, 0x0, 0x0, 0x7e, 0x0, 0x0, 0x0, 0x0 //tile:13
|
||||
, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0x18, 0x0 //tile:14
|
||||
, 0x6, 0xc, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x0 //tile:15
|
||||
, 0x7c, 0xce, 0xde, 0xf6, 0xe6, 0xc6, 0x7c, 0x0 //tile:16
|
||||
, 0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x0 //tile:17
|
||||
, 0x7c, 0xc6, 0x6, 0x7c, 0xc0, 0xc0, 0xfe, 0x0 //tile:18
|
||||
, 0xfc, 0x6, 0x6, 0x3c, 0x6, 0x6, 0xfc, 0x0 //tile:19
|
||||
, 0xc, 0xcc, 0xcc, 0xcc, 0xfe, 0xc, 0xc, 0x0 //tile:20
|
||||
, 0xfe, 0xc0, 0xfc, 0x6, 0x6, 0xc6, 0x7c, 0x0 //tile:21
|
||||
, 0x7c, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0x7c, 0x0 //tile:22
|
||||
, 0xfe, 0x6, 0x6, 0xc, 0x18, 0x30, 0x30, 0x0 //tile:23
|
||||
, 0x7c, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0x7c, 0x0 //tile:24
|
||||
, 0x7c, 0xc6, 0xc6, 0x7e, 0x6, 0x6, 0x7c, 0x0 //tile:25
|
||||
, 0x0, 0x18, 0x18, 0x0, 0x0, 0x18, 0x18, 0x0 //tile:26
|
||||
, 0x0, 0x18, 0x18, 0x0, 0x0, 0x18, 0x18, 0x30 //tile:27
|
||||
, 0xc, 0x18, 0x30, 0x60, 0x30, 0x18, 0xc, 0x0 //tile:28
|
||||
, 0x0, 0x0, 0x7e, 0x0, 0x7e, 0x0, 0x0, 0x0 //tile:29
|
||||
, 0x30, 0x18, 0xc, 0x6, 0xc, 0x18, 0x30, 0x0 //tile:30
|
||||
, 0x3c, 0x66, 0xc, 0x18, 0x18, 0x0, 0x18, 0x0 //tile:31
|
||||
, 0x7c, 0xc6, 0xde, 0xde, 0xde, 0xc0, 0x7e, 0x0 //tile:32
|
||||
, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x0 //tile:33
|
||||
, 0xfc, 0xc6, 0xc6, 0xfc, 0xc6, 0xc6, 0xfc, 0x0 //tile:34
|
||||
, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x0 //tile:35
|
||||
, 0xf8, 0xcc, 0xc6, 0xc6, 0xc6, 0xcc, 0xf8, 0x0 //tile:36
|
||||
, 0xfe, 0xc0, 0xc0, 0xf8, 0xc0, 0xc0, 0xfe, 0x0 //tile:37
|
||||
, 0xfe, 0xc0, 0xc0, 0xf8, 0xc0, 0xc0, 0xc0, 0x0 //tile:38
|
||||
, 0x7c, 0xc6, 0xc0, 0xc0, 0xce, 0xc6, 0x7c, 0x0 //tile:39
|
||||
, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x0 //tile:40
|
||||
, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x0 //tile:41
|
||||
, 0x6, 0x6, 0x6, 0x6, 0x6, 0xc6, 0x7c, 0x0 //tile:42
|
||||
, 0xc6, 0xcc, 0xd8, 0xf0, 0xd8, 0xcc, 0xc6, 0x0 //tile:43
|
||||
, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0x0 //tile:44
|
||||
, 0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0x0 //tile:45
|
||||
, 0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x0 //tile:46
|
||||
, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x0 //tile:47
|
||||
, 0xfc, 0xc6, 0xc6, 0xfc, 0xc0, 0xc0, 0xc0, 0x0 //tile:48
|
||||
, 0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x6 //tile:49
|
||||
, 0xfc, 0xc6, 0xc6, 0xfc, 0xd8, 0xcc, 0xc6, 0x0 //tile:50
|
||||
, 0x7c, 0xc6, 0xc0, 0x7c, 0x6, 0xc6, 0x7c, 0x0 //tile:51
|
||||
, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0 //tile:52
|
||||
, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0x0 //tile:53
|
||||
, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x38, 0x0 //tile:54
|
||||
, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x0 //tile:55
|
||||
, 0xc6, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0xc6, 0x0 //tile:56
|
||||
, 0xc6, 0xc6, 0xc6, 0x7c, 0x18, 0x30, 0xe0, 0x0 //tile:57
|
||||
, 0xfe, 0x6, 0xc, 0x18, 0x30, 0x60, 0xfe, 0x0 //tile:58
|
||||
, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x0 //tile:59
|
||||
, 0xc0, 0x60, 0x30, 0x18, 0xc, 0x6, 0x2, 0x0 //tile:60
|
||||
, 0x3c, 0xc, 0xc, 0xc, 0xc, 0xc, 0x3c, 0x0 //tile:61
|
||||
, 0x10, 0x38, 0x6c, 0xc6, 0x0, 0x0, 0x0, 0x0 //tile:62
|
||||
, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff //tile:63
|
||||
, 0x18, 0x18, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0 //tile:64
|
||||
, 0x0, 0x0, 0x7c, 0x6, 0x7e, 0xc6, 0x7e, 0x0 //tile:65
|
||||
, 0xc0, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xfc, 0x0 //tile:66
|
||||
, 0x0, 0x0, 0x7c, 0xc6, 0xc0, 0xc6, 0x7c, 0x0 //tile:67
|
||||
, 0x6, 0x6, 0x6, 0x7e, 0xc6, 0xc6, 0x7e, 0x0 //tile:68
|
||||
, 0x0, 0x0, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x0 //tile:69
|
||||
, 0x1c, 0x36, 0x30, 0x78, 0x30, 0x30, 0x78, 0x0 //tile:70
|
||||
, 0x0, 0x0, 0x7e, 0xc6, 0xc6, 0x7e, 0x6, 0xfc //tile:71
|
||||
, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x0 //tile:72
|
||||
, 0x18, 0x0, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x0 //tile:73
|
||||
, 0x6, 0x0, 0x6, 0x6, 0x6, 0x6, 0xc6, 0x7c //tile:74
|
||||
, 0xc0, 0xc0, 0xcc, 0xd8, 0xf8, 0xcc, 0xc6, 0x0 //tile:75
|
||||
, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x0 //tile:76
|
||||
, 0x0, 0x0, 0xcc, 0xfe, 0xfe, 0xd6, 0xd6, 0x0 //tile:77
|
||||
, 0x0, 0x0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x0 //tile:78
|
||||
, 0x0, 0x0, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x0 //tile:79
|
||||
, 0x0, 0x0, 0xfc, 0xc6, 0xc6, 0xfc, 0xc0, 0xc0 //tile:80
|
||||
, 0x0, 0x0, 0x7e, 0xc6, 0xc6, 0x7e, 0x6, 0x6 //tile:81
|
||||
, 0x0, 0x0, 0xfc, 0xc6, 0xc0, 0xc0, 0xc0, 0x0 //tile:82
|
||||
, 0x0, 0x0, 0x7e, 0xc0, 0x7c, 0x6, 0xfc, 0x0 //tile:83
|
||||
, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0xe, 0x0 //tile:84
|
||||
, 0x0, 0x0, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x0 //tile:85
|
||||
, 0x0, 0x0, 0xc6, 0xc6, 0xc6, 0x7c, 0x38, 0x0 //tile:86
|
||||
, 0x0, 0x0, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x0 //tile:87
|
||||
, 0x0, 0x0, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x0 //tile:88
|
||||
, 0x0, 0x0, 0xc6, 0xc6, 0xc6, 0x7e, 0x6, 0xfc //tile:89
|
||||
, 0x0, 0x0, 0xfe, 0xc, 0x38, 0x60, 0xfe, 0x0 //tile:90
|
||||
, 0xe, 0x18, 0x18, 0x70, 0x18, 0x18, 0xe, 0x0 //tile:91
|
||||
, 0x18, 0x18, 0x18, 0x0, 0x18, 0x18, 0x18, 0x0 //tile:92
|
||||
, 0x70, 0x18, 0x18, 0xe, 0x18, 0x18, 0x70, 0x0 //tile:93
|
||||
, 0x76, 0xdc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 //tile:94
|
||||
, 0x0, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0x0 //tile:95
|
||||
#include <3ds.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char fonts[] = {
|
||||
// Fonte 8x8 1BPP
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 // tile:0
|
||||
,
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x0, 0x18, 0x0 // tile:1
|
||||
,
|
||||
0x6c, 0x6c, 0x6c, 0x0, 0x0, 0x0, 0x0, 0x0 // tile:2
|
||||
,
|
||||
0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x0 // tile:3
|
||||
,
|
||||
0x18, 0x7e, 0xc0, 0x7c, 0x6, 0xfc, 0x18, 0x0 // tile:4
|
||||
,
|
||||
0x0, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xc6, 0x0 // tile:5
|
||||
,
|
||||
0x38, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0x76, 0x0 // tile:6
|
||||
,
|
||||
0x30, 0x30, 0x60, 0x0, 0x0, 0x0, 0x0, 0x0 // tile:7
|
||||
,
|
||||
0xc, 0x18, 0x30, 0x30, 0x30, 0x18, 0xc, 0x0 // tile:8
|
||||
,
|
||||
0x30, 0x18, 0xc, 0xc, 0xc, 0x18, 0x30, 0x0 // tile:9
|
||||
,
|
||||
0x0, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x0, 0x0 // tile:10
|
||||
,
|
||||
0x0, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x0, 0x0 // tile:11
|
||||
,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0x18, 0x30 // tile:12
|
||||
,
|
||||
0x0, 0x0, 0x0, 0x7e, 0x0, 0x0, 0x0, 0x0 // tile:13
|
||||
,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0x18, 0x0 // tile:14
|
||||
,
|
||||
0x6, 0xc, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x0 // tile:15
|
||||
,
|
||||
0x7c, 0xce, 0xde, 0xf6, 0xe6, 0xc6, 0x7c, 0x0 // tile:16
|
||||
,
|
||||
0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x0 // tile:17
|
||||
,
|
||||
0x7c, 0xc6, 0x6, 0x7c, 0xc0, 0xc0, 0xfe, 0x0 // tile:18
|
||||
,
|
||||
0xfc, 0x6, 0x6, 0x3c, 0x6, 0x6, 0xfc, 0x0 // tile:19
|
||||
,
|
||||
0xc, 0xcc, 0xcc, 0xcc, 0xfe, 0xc, 0xc, 0x0 // tile:20
|
||||
,
|
||||
0xfe, 0xc0, 0xfc, 0x6, 0x6, 0xc6, 0x7c, 0x0 // tile:21
|
||||
,
|
||||
0x7c, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0x7c, 0x0 // tile:22
|
||||
,
|
||||
0xfe, 0x6, 0x6, 0xc, 0x18, 0x30, 0x30, 0x0 // tile:23
|
||||
,
|
||||
0x7c, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0x7c, 0x0 // tile:24
|
||||
,
|
||||
0x7c, 0xc6, 0xc6, 0x7e, 0x6, 0x6, 0x7c, 0x0 // tile:25
|
||||
,
|
||||
0x0, 0x18, 0x18, 0x0, 0x0, 0x18, 0x18, 0x0 // tile:26
|
||||
,
|
||||
0x0, 0x18, 0x18, 0x0, 0x0, 0x18, 0x18, 0x30 // tile:27
|
||||
,
|
||||
0xc, 0x18, 0x30, 0x60, 0x30, 0x18, 0xc, 0x0 // tile:28
|
||||
,
|
||||
0x0, 0x0, 0x7e, 0x0, 0x7e, 0x0, 0x0, 0x0 // tile:29
|
||||
,
|
||||
0x30, 0x18, 0xc, 0x6, 0xc, 0x18, 0x30, 0x0 // tile:30
|
||||
,
|
||||
0x3c, 0x66, 0xc, 0x18, 0x18, 0x0, 0x18, 0x0 // tile:31
|
||||
,
|
||||
0x7c, 0xc6, 0xde, 0xde, 0xde, 0xc0, 0x7e, 0x0 // tile:32
|
||||
,
|
||||
0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x0 // tile:33
|
||||
,
|
||||
0xfc, 0xc6, 0xc6, 0xfc, 0xc6, 0xc6, 0xfc, 0x0 // tile:34
|
||||
,
|
||||
0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x0 // tile:35
|
||||
,
|
||||
0xf8, 0xcc, 0xc6, 0xc6, 0xc6, 0xcc, 0xf8, 0x0 // tile:36
|
||||
,
|
||||
0xfe, 0xc0, 0xc0, 0xf8, 0xc0, 0xc0, 0xfe, 0x0 // tile:37
|
||||
,
|
||||
0xfe, 0xc0, 0xc0, 0xf8, 0xc0, 0xc0, 0xc0, 0x0 // tile:38
|
||||
,
|
||||
0x7c, 0xc6, 0xc0, 0xc0, 0xce, 0xc6, 0x7c, 0x0 // tile:39
|
||||
,
|
||||
0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x0 // tile:40
|
||||
,
|
||||
0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x0 // tile:41
|
||||
,
|
||||
0x6, 0x6, 0x6, 0x6, 0x6, 0xc6, 0x7c, 0x0 // tile:42
|
||||
,
|
||||
0xc6, 0xcc, 0xd8, 0xf0, 0xd8, 0xcc, 0xc6, 0x0 // tile:43
|
||||
,
|
||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0x0 // tile:44
|
||||
,
|
||||
0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0x0 // tile:45
|
||||
,
|
||||
0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x0 // tile:46
|
||||
,
|
||||
0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x0 // tile:47
|
||||
,
|
||||
0xfc, 0xc6, 0xc6, 0xfc, 0xc0, 0xc0, 0xc0, 0x0 // tile:48
|
||||
,
|
||||
0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x6 // tile:49
|
||||
,
|
||||
0xfc, 0xc6, 0xc6, 0xfc, 0xd8, 0xcc, 0xc6, 0x0 // tile:50
|
||||
,
|
||||
0x7c, 0xc6, 0xc0, 0x7c, 0x6, 0xc6, 0x7c, 0x0 // tile:51
|
||||
,
|
||||
0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0 // tile:52
|
||||
,
|
||||
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0x0 // tile:53
|
||||
,
|
||||
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x38, 0x0 // tile:54
|
||||
,
|
||||
0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x0 // tile:55
|
||||
,
|
||||
0xc6, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0xc6, 0x0 // tile:56
|
||||
,
|
||||
0xc6, 0xc6, 0xc6, 0x7c, 0x18, 0x30, 0xe0, 0x0 // tile:57
|
||||
,
|
||||
0xfe, 0x6, 0xc, 0x18, 0x30, 0x60, 0xfe, 0x0 // tile:58
|
||||
,
|
||||
0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x0 // tile:59
|
||||
,
|
||||
0xc0, 0x60, 0x30, 0x18, 0xc, 0x6, 0x2, 0x0 // tile:60
|
||||
,
|
||||
0x3c, 0xc, 0xc, 0xc, 0xc, 0xc, 0x3c, 0x0 // tile:61
|
||||
,
|
||||
0x10, 0x38, 0x6c, 0xc6, 0x0, 0x0, 0x0, 0x0 // tile:62
|
||||
,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff // tile:63
|
||||
,
|
||||
0x18, 0x18, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0 // tile:64
|
||||
,
|
||||
0x0, 0x0, 0x7c, 0x6, 0x7e, 0xc6, 0x7e, 0x0 // tile:65
|
||||
,
|
||||
0xc0, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xfc, 0x0 // tile:66
|
||||
,
|
||||
0x0, 0x0, 0x7c, 0xc6, 0xc0, 0xc6, 0x7c, 0x0 // tile:67
|
||||
,
|
||||
0x6, 0x6, 0x6, 0x7e, 0xc6, 0xc6, 0x7e, 0x0 // tile:68
|
||||
,
|
||||
0x0, 0x0, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x0 // tile:69
|
||||
,
|
||||
0x1c, 0x36, 0x30, 0x78, 0x30, 0x30, 0x78, 0x0 // tile:70
|
||||
,
|
||||
0x0, 0x0, 0x7e, 0xc6, 0xc6, 0x7e, 0x6, 0xfc // tile:71
|
||||
,
|
||||
0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x0 // tile:72
|
||||
,
|
||||
0x18, 0x0, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x0 // tile:73
|
||||
,
|
||||
0x6, 0x0, 0x6, 0x6, 0x6, 0x6, 0xc6, 0x7c // tile:74
|
||||
,
|
||||
0xc0, 0xc0, 0xcc, 0xd8, 0xf8, 0xcc, 0xc6, 0x0 // tile:75
|
||||
,
|
||||
0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x0 // tile:76
|
||||
,
|
||||
0x0, 0x0, 0xcc, 0xfe, 0xfe, 0xd6, 0xd6, 0x0 // tile:77
|
||||
,
|
||||
0x0, 0x0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x0 // tile:78
|
||||
,
|
||||
0x0, 0x0, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x0 // tile:79
|
||||
,
|
||||
0x0, 0x0, 0xfc, 0xc6, 0xc6, 0xfc, 0xc0, 0xc0 // tile:80
|
||||
,
|
||||
0x0, 0x0, 0x7e, 0xc6, 0xc6, 0x7e, 0x6, 0x6 // tile:81
|
||||
,
|
||||
0x0, 0x0, 0xfc, 0xc6, 0xc0, 0xc0, 0xc0, 0x0 // tile:82
|
||||
,
|
||||
0x0, 0x0, 0x7e, 0xc0, 0x7c, 0x6, 0xfc, 0x0 // tile:83
|
||||
,
|
||||
0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0xe, 0x0 // tile:84
|
||||
,
|
||||
0x0, 0x0, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x0 // tile:85
|
||||
,
|
||||
0x0, 0x0, 0xc6, 0xc6, 0xc6, 0x7c, 0x38, 0x0 // tile:86
|
||||
,
|
||||
0x0, 0x0, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x0 // tile:87
|
||||
,
|
||||
0x0, 0x0, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x0 // tile:88
|
||||
,
|
||||
0x0, 0x0, 0xc6, 0xc6, 0xc6, 0x7e, 0x6, 0xfc // tile:89
|
||||
,
|
||||
0x0, 0x0, 0xfe, 0xc, 0x38, 0x60, 0xfe, 0x0 // tile:90
|
||||
,
|
||||
0xe, 0x18, 0x18, 0x70, 0x18, 0x18, 0xe, 0x0 // tile:91
|
||||
,
|
||||
0x18, 0x18, 0x18, 0x0, 0x18, 0x18, 0x18, 0x0 // tile:92
|
||||
,
|
||||
0x70, 0x18, 0x18, 0xe, 0x18, 0x18, 0x70, 0x0 // tile:93
|
||||
,
|
||||
0x76, 0xdc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 // tile:94
|
||||
,
|
||||
0x0, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0x0 // tile:95
|
||||
};
|
||||
|
||||
inline void clearScreen(void) {
|
||||
u8 *frame = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
|
||||
memset(frame, 0, 320 * 240 * 3);
|
||||
u8 *frame = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
|
||||
memset(frame, 0, 320 * 240 * 3);
|
||||
}
|
||||
|
||||
void drawPixelRGBFramebuffer(u8 *fb, int x, int y, u8 r, u8 g, u8 b) {
|
||||
y = 240 - y;
|
||||
x = x;
|
||||
u32 v = (y + x * 240) * 3;
|
||||
u8 *topLeftFB = fb ? fb : gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
|
||||
topLeftFB[v] = (b >> 3) + ((g & 0x1C) << 3);
|
||||
topLeftFB[v+1] = ((g & 0xE0) >> 5) + (r & 0xF8);
|
||||
y = 240 - y;
|
||||
x = x;
|
||||
u32 v = (y + x * 240) * 3;
|
||||
u8 *topLeftFB = fb ? fb : gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
|
||||
topLeftFB[v] = (b >> 3) + ((g & 0x1C) << 3);
|
||||
topLeftFB[v + 1] = ((g & 0xE0) >> 5) + (r & 0xF8);
|
||||
}
|
||||
|
||||
inline void drawBoxFramebuffer(u8 *fb, int x, int y, int width, int height, u8 r, u8 g, u8 b) {
|
||||
int lx, ly;
|
||||
for(lx = x; lx < x + width; lx++) {
|
||||
for(ly = y; ly < y + height; ly++) {
|
||||
drawPixelRGBFramebuffer(fb, lx, ly, r, g, b);
|
||||
}
|
||||
}
|
||||
int lx, ly;
|
||||
for (lx = x; lx < x + width; lx++) {
|
||||
for (ly = y; ly < y + height; ly++) {
|
||||
drawPixelRGBFramebuffer(fb, lx, ly, r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawStringFramebuffer(u8 *fb, int sx, int sy, char *text, ...) {
|
||||
char str[1024];
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vsnprintf(str, 1023, text, args);
|
||||
va_end(args);
|
||||
|
||||
int i;
|
||||
for(i = 0; i < strlen(str); i++) {
|
||||
int fntnum = (str[i] - 32) & 0xFF;
|
||||
int y;
|
||||
for(y = 0; y < 8; y++) {
|
||||
int currbyte = fonts[(fntnum * 8) + y];
|
||||
//Desenha sprite de 1BPP
|
||||
int x;
|
||||
int mult = 0x80;
|
||||
for(x = 0; x < 8; x++) {
|
||||
if((currbyte & mult) == mult) {
|
||||
drawPixelRGBFramebuffer(fb, sx + x, sy + y, 0xFF, 0xFF, 0xFF);
|
||||
drawPixelRGBFramebuffer(fb, sx + x, sy + y + 1, 0, 0, 0); //Sombra
|
||||
}
|
||||
mult /= 2;
|
||||
}
|
||||
}
|
||||
sx += 8;
|
||||
}
|
||||
char str[1024];
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vsnprintf(str, 1023, text, args);
|
||||
va_end(args);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < strlen(str); i++) {
|
||||
int fntnum = (str[i] - 32) & 0xFF;
|
||||
int y;
|
||||
for (y = 0; y < 8; y++) {
|
||||
int currbyte = fonts[(fntnum * 8) + y];
|
||||
// Desenha sprite de 1BPP
|
||||
int x;
|
||||
int mult = 0x80;
|
||||
for (x = 0; x < 8; x++) {
|
||||
if ((currbyte & mult) == mult) {
|
||||
drawPixelRGBFramebuffer(fb, sx + x, sy + y, 0xFF, 0xFF, 0xFF);
|
||||
drawPixelRGBFramebuffer(fb, sx + x, sy + y + 1, 0, 0, 0); // Sombra
|
||||
}
|
||||
mult /= 2;
|
||||
}
|
||||
}
|
||||
sx += 8;
|
||||
}
|
||||
}
|
||||
|
||||
static u32 brightnessMain;
|
||||
static u32 brightnessSub;
|
||||
|
||||
void disableBacklight() {
|
||||
u32 off = 0;
|
||||
|
||||
GSPGPU_ReadHWRegs(REG_LCDBACKLIGHTMAIN, &brightnessMain, 4);
|
||||
GSPGPU_ReadHWRegs(REG_LCDBACKLIGHTSUB, &brightnessSub, 4);
|
||||
|
||||
GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTMAIN, &off, 4);
|
||||
GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTSUB, &off, 4);
|
||||
u32 off = 0;
|
||||
|
||||
GSPGPU_ReadHWRegs(REG_LCDBACKLIGHTMAIN, &brightnessMain, 4);
|
||||
GSPGPU_ReadHWRegs(REG_LCDBACKLIGHTSUB, &brightnessSub, 4);
|
||||
|
||||
GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTMAIN, &off, 4);
|
||||
GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTSUB, &off, 4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void enableBacklight() {
|
||||
GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTMAIN, &brightnessMain, 4);
|
||||
GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTSUB, &brightnessSub, 4);
|
||||
GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTMAIN, &brightnessMain, 4);
|
||||
GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTSUB, &brightnessSub, 4);
|
||||
}
|
||||
|
|
|
@ -1,44 +1,42 @@
|
|||
#include "wireless.h"
|
||||
|
||||
#include "inet_pton.h"
|
||||
|
||||
#include "wireless.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;
|
||||
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;
|
||||
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 ((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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
else if(ch == '.' && saw_digit) {
|
||||
if(octets == 4)
|
||||
if (octets < 4)
|
||||
return (0);
|
||||
*++tp = 0;
|
||||
saw_digit = 0;
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
if(octets < 4)
|
||||
return (0);
|
||||
memcpy(dst, tmp, INADDRSZ);
|
||||
return (1);
|
||||
memcpy(dst, tmp, INADDRSZ);
|
||||
return (1);
|
||||
}
|
||||
|
|
114
source/input.c
114
source/input.c
|
@ -1,59 +1,69 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include "input.h"
|
||||
|
||||
#include <3ds.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "drawing.h"
|
||||
|
||||
#include "input.h"
|
||||
|
||||
int inputIP(void) {
|
||||
touchPosition touch;
|
||||
hidTouchRead(&touch);
|
||||
|
||||
//Draw Keypad
|
||||
drawString(160-20,50, "1");
|
||||
drawString(160, 50, "2");
|
||||
drawString(160+20, 50, "3");
|
||||
|
||||
drawString(160-20, 50+20, "4");
|
||||
drawString(160, 50+20, "5");
|
||||
drawString(160+20, 50+20, "6");
|
||||
|
||||
drawString(160-20, 50+40, "7");
|
||||
drawString(160, 50+40, "8");
|
||||
drawString(160+20, 50+40, "9");
|
||||
|
||||
drawString(160-10, 50+60, ".");
|
||||
drawString(160+10, 50+60, "0");
|
||||
|
||||
//Bottom Strip
|
||||
if(touch.py > 50+50 && touch.py < 50+70) {
|
||||
if(touch.px < 160 && touch.px > 160-20) return 11; // Dot
|
||||
else if(touch.px < 160+20 && touch.px > 160) return 0; // Zero
|
||||
}
|
||||
|
||||
//First Column
|
||||
else if(touch.px < 160-10 && touch.px > 160-30) {
|
||||
if(touch.py < 50+10 && touch.py > 50-10) return 1; // One
|
||||
else if(touch.py < 50+30 && touch.py > 50+10) return 4; // Four
|
||||
else if(touch.py < 50+50 && touch.py > 50+30) return 7; // Seven
|
||||
}
|
||||
|
||||
// Second Column
|
||||
else if(touch.px < 160+10 && touch.px > 160-10) {
|
||||
if(touch.py < 50+10 && touch.py > 50-10) return 2; // Two
|
||||
else if(touch.py < 50+30 && touch.py > 50+10) return 5; // Five
|
||||
else if(touch.py < 50+50 && touch.py > 50+30) return 8; // Eight
|
||||
}
|
||||
|
||||
// Third Column
|
||||
else if(touch.px < 160+30 && touch.px > 160+10) {
|
||||
if(touch.py < 50+10 && touch.py > 50-10) return 3; // Three
|
||||
else if(touch.py < 50+30 && touch.py > 50+10) return 6; // Six
|
||||
else if(touch.py < 50+50 && touch.py > 50+30) return 9; // Nine
|
||||
}
|
||||
|
||||
return 10;
|
||||
touchPosition touch;
|
||||
hidTouchRead(&touch);
|
||||
|
||||
// Draw Keypad
|
||||
drawString(160 - 20, 50, "1");
|
||||
drawString(160, 50, "2");
|
||||
drawString(160 + 20, 50, "3");
|
||||
|
||||
drawString(160 - 20, 50 + 20, "4");
|
||||
drawString(160, 50 + 20, "5");
|
||||
drawString(160 + 20, 50 + 20, "6");
|
||||
|
||||
drawString(160 - 20, 50 + 40, "7");
|
||||
drawString(160, 50 + 40, "8");
|
||||
drawString(160 + 20, 50 + 40, "9");
|
||||
|
||||
drawString(160 - 10, 50 + 60, ".");
|
||||
drawString(160 + 10, 50 + 60, "0");
|
||||
|
||||
// Bottom Strip
|
||||
if (touch.py > 50 + 50 && touch.py < 50 + 70) {
|
||||
if (touch.px < 160 && touch.px > 160 - 20)
|
||||
return 11; // Dot
|
||||
else if (touch.px < 160 + 20 && touch.px > 160)
|
||||
return 0; // Zero
|
||||
}
|
||||
|
||||
// First Column
|
||||
else if (touch.px < 160 - 10 && touch.px > 160 - 30) {
|
||||
if (touch.py < 50 + 10 && touch.py > 50 - 10)
|
||||
return 1; // One
|
||||
else if (touch.py < 50 + 30 && touch.py > 50 + 10)
|
||||
return 4; // Four
|
||||
else if (touch.py < 50 + 50 && touch.py > 50 + 30)
|
||||
return 7; // Seven
|
||||
}
|
||||
|
||||
// Second Column
|
||||
else if (touch.px < 160 + 10 && touch.px > 160 - 10) {
|
||||
if (touch.py < 50 + 10 && touch.py > 50 - 10)
|
||||
return 2; // Two
|
||||
else if (touch.py < 50 + 30 && touch.py > 50 + 10)
|
||||
return 5; // Five
|
||||
else if (touch.py < 50 + 50 && touch.py > 50 + 30)
|
||||
return 8; // Eight
|
||||
}
|
||||
|
||||
// Third Column
|
||||
else if (touch.px < 160 + 30 && touch.px > 160 + 10) {
|
||||
if (touch.py < 50 + 10 && touch.py > 50 - 10)
|
||||
return 3; // Three
|
||||
else if (touch.py < 50 + 30 && touch.py > 50 + 10)
|
||||
return 6; // Six
|
||||
else if (touch.py < 50 + 50 && touch.py > 50 + 30)
|
||||
return 9; // Nine
|
||||
}
|
||||
|
||||
return 10;
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
#include "keyboard.h"
|
||||
|
||||
#include <3ds.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "drawing.h"
|
||||
|
||||
#include "keyboard.h"
|
||||
|
||||
const char keyboardChars[60] = "!1234567890\x08QWERTYUIOP\13\13ASDFGHJKL-\13\13ZXCVBNM,.?\13\13\0\0\0 \0\0\0\0";
|
||||
|
||||
unsigned char keyboardActive = false;
|
||||
|
@ -14,65 +14,65 @@ unsigned char keyboardToggle = true;
|
|||
unsigned char keyboardGfx[320 * 240 * 3];
|
||||
|
||||
void preRenderKeyboard(void) {
|
||||
const char chars[60] = "!1234567890\x08QWERTYUIOP\13\13ASDFGHJKL-\13\13ZXCVBNM,.?\13\13\0\0\0 \0\0\0\0";
|
||||
|
||||
int x, y;
|
||||
for(x = 0; x < 12; x++) {
|
||||
for(y = 0; y < 4; y++) {
|
||||
// Not enter
|
||||
if(chars[x + y * 12] != '\13') {
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f), (int)(78.0f + (float)y * 320.0f / 12.0f), 25, 25, 31, 31, 31);
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f) + 1, (int)(78.0f + (float)y * 320.0f / 12.0f) + 1, 24, 24, 31, 0, 0);
|
||||
|
||||
// Backspace
|
||||
if(chars[x + y * 12] == '\x08') {
|
||||
drawStringFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f) + 10, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "-");
|
||||
drawStringFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f) + 8, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "<");
|
||||
}
|
||||
else drawStringFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f) + 9, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "%c", chars[x + y * 12]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Space
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)3 * 320.0f / 12.0f), (int)(78.0f + (float)4 * 320.0f / 12.0f), (int)(5.0f * 320.0f / 12.0f), 25, 31, 31, 31);
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)3 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)4 * 320.0f / 12.0f) + 1, (int)(5.0f * 320.0f / 12.0f) - 1, 24, 31, 0, 0);
|
||||
|
||||
// Enter
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)10 * 320.0f / 12.0f), (int)(78.0f + (float)1 * 320.0f / 12.0f), (int)(2.0f * 320.0f / 12.0f), (int)(3.0f * 320.0f / 12.0f), 31, 31, 31);
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)10 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)1 * 320.0f / 12.0f) + 1, (int)(2.0f * 320.0f / 12.0f) - 1, (int)(3.0f * 320.0f / 12.0f) - 1, 31, 0, 0);
|
||||
const char chars[60] = "!1234567890\x08QWERTYUIOP\13\13ASDFGHJKL-\13\13ZXCVBNM,.?\13\13\0\0\0 \0\0\0\0";
|
||||
|
||||
int x, y;
|
||||
for (x = 0; x < 12; x++) {
|
||||
for (y = 0; y < 4; y++) {
|
||||
// Not enter
|
||||
if (chars[x + y * 12] != '\13') {
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f), (int)(78.0f + (float)y * 320.0f / 12.0f), 25, 25, 31, 31, 31);
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f) + 1, (int)(78.0f + (float)y * 320.0f / 12.0f) + 1, 24, 24, 31, 0, 0);
|
||||
|
||||
// Backspace
|
||||
if (chars[x + y * 12] == '\x08') {
|
||||
drawStringFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f) + 10, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "-");
|
||||
drawStringFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f) + 8, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "<");
|
||||
} else
|
||||
drawStringFramebuffer(keyboardGfx, (int)((float)x * 320.0f / 12.0f) + 9, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "%c", chars[x + y * 12]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Space
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)3 * 320.0f / 12.0f), (int)(78.0f + (float)4 * 320.0f / 12.0f), (int)(5.0f * 320.0f / 12.0f), 25, 31, 31, 31);
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)3 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)4 * 320.0f / 12.0f) + 1, (int)(5.0f * 320.0f / 12.0f) - 1, 24, 31, 0, 0);
|
||||
|
||||
// Enter
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)10 * 320.0f / 12.0f), (int)(78.0f + (float)1 * 320.0f / 12.0f), (int)(2.0f * 320.0f / 12.0f), (int)(3.0f * 320.0f / 12.0f), 31, 31, 31);
|
||||
drawBoxFramebuffer(keyboardGfx, (int)((float)10 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)1 * 320.0f / 12.0f) + 1, (int)(2.0f * 320.0f / 12.0f) - 1, (int)(3.0f * 320.0f / 12.0f) - 1, 31, 0, 0);
|
||||
}
|
||||
|
||||
inline void drawKeyboard(void) {
|
||||
u8 *topLeftFB = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
|
||||
memcpy(topLeftFB, keyboardGfx, sizeof(keyboardGfx));
|
||||
|
||||
/*const char chars[60] = "!1234567890\x08QWERTYUIOP\13\13ASDFGHJKL-\13\13ZXCVBNM,.?\13\13\0\0\0 \0\0\0\0";
|
||||
|
||||
int x, y;
|
||||
for(x = 0; x < 12; x++) {
|
||||
for(y = 0; y < 4; y++) {
|
||||
// Not enter
|
||||
if(chars[x + y * 12] != '\13') {
|
||||
drawBox((int)((float)x * 320.0f / 12.0f), (int)(78.0f + (float)y * 320.0f / 12.0f), 25, 25, 31, 31, 31);
|
||||
drawBox((int)((float)x * 320.0f / 12.0f) + 1, (int)(78.0f + (float)y * 320.0f / 12.0f) + 1, 24, 24, 31, 0, 0);
|
||||
|
||||
// Backspace
|
||||
if(chars[x + y * 12] == '\x08') {
|
||||
drawString((int)((float)x * 320.0f / 12.0f) + 10, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "-");
|
||||
drawString((int)((float)x * 320.0f / 12.0f) + 8, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "<");
|
||||
}
|
||||
else drawString((int)((float)x * 320.0f / 12.0f) + 9, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "%c", chars[x + y * 12]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Space
|
||||
drawBox((int)((float)3 * 320.0f / 12.0f), (int)(78.0f + (float)4 * 320.0f / 12.0f), (int)(5.0f * 320.0f / 12.0f), 25, 31, 31, 31);
|
||||
drawBox((int)((float)3 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)4 * 320.0f / 12.0f) + 1, (int)(5.0f * 320.0f / 12.0f) - 1, 24, 31, 0, 0);
|
||||
|
||||
// Enter
|
||||
drawBox((int)((float)10 * 320.0f / 12.0f), (int)(78.0f + (float)1 * 320.0f / 12.0f), (int)(2.0f * 320.0f / 12.0f), (int)(3.0f * 320.0f / 12.0f), 31, 31, 31);
|
||||
drawBox((int)((float)10 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)1 * 320.0f / 12.0f) + 1, (int)(2.0f * 320.0f / 12.0f) - 1, (int)(3.0f * 320.0f / 12.0f) - 1, 31, 0, 0);
|
||||
*/
|
||||
u8 *topLeftFB = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
|
||||
memcpy(topLeftFB, keyboardGfx, sizeof(keyboardGfx));
|
||||
|
||||
/*const char chars[60] = "!1234567890\x08QWERTYUIOP\13\13ASDFGHJKL-\13\13ZXCVBNM,.?\13\13\0\0\0 \0\0\0\0";
|
||||
|
||||
int x, y;
|
||||
for(x = 0; x < 12; x++) {
|
||||
for(y = 0; y < 4; y++) {
|
||||
// Not enter
|
||||
if(chars[x + y * 12] != '\13') {
|
||||
drawBox((int)((float)x * 320.0f / 12.0f), (int)(78.0f + (float)y * 320.0f / 12.0f), 25, 25, 31, 31, 31);
|
||||
drawBox((int)((float)x * 320.0f / 12.0f) + 1, (int)(78.0f + (float)y * 320.0f / 12.0f) + 1, 24, 24, 31, 0, 0);
|
||||
|
||||
// Backspace
|
||||
if(chars[x + y * 12] == '\x08') {
|
||||
drawString((int)((float)x * 320.0f / 12.0f) + 10, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "-");
|
||||
drawString((int)((float)x * 320.0f / 12.0f) + 8, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "<");
|
||||
}
|
||||
else drawString((int)((float)x * 320.0f / 12.0f) + 9, (int)(78.0f + (float)y * 320.0f / 12.0f) + 9, "%c", chars[x + y * 12]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Space
|
||||
drawBox((int)((float)3 * 320.0f / 12.0f), (int)(78.0f + (float)4 * 320.0f / 12.0f), (int)(5.0f * 320.0f / 12.0f), 25, 31, 31, 31);
|
||||
drawBox((int)((float)3 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)4 * 320.0f / 12.0f) + 1, (int)(5.0f * 320.0f / 12.0f) - 1, 24, 31, 0, 0);
|
||||
|
||||
// Enter
|
||||
drawBox((int)((float)10 * 320.0f / 12.0f), (int)(78.0f + (float)1 * 320.0f / 12.0f), (int)(2.0f * 320.0f / 12.0f), (int)(3.0f * 320.0f / 12.0f), 31, 31, 31);
|
||||
drawBox((int)((float)10 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)1 * 320.0f / 12.0f) + 1, (int)(2.0f * 320.0f / 12.0f) - 1, (int)(3.0f * 320.0f / 12.0f) - 1, 31, 0, 0);
|
||||
*/
|
||||
}
|
||||
|
|
213
source/main.c
213
source/main.c
|
@ -1,13 +1,12 @@
|
|||
#include <3ds.h>
|
||||
#include <malloc.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <3ds.h>
|
||||
#include "3ds/services/gsplcd.h"
|
||||
#include "3ds/services/hid.h"
|
||||
#include "3ds/services/soc.h"
|
||||
|
||||
#include "drawing.h"
|
||||
#include "input.h"
|
||||
// #include "keyboard.h"
|
||||
|
@ -17,129 +16,129 @@
|
|||
static jmp_buf exitJmp;
|
||||
|
||||
void hang(char *message) {
|
||||
while (aptMainLoop()) {
|
||||
hidScanInput();
|
||||
while (aptMainLoop()) {
|
||||
hidScanInput();
|
||||
|
||||
clearScreen();
|
||||
drawString(10, 10, "%s", message);
|
||||
drawString(10, 20, "Start and Select to exit");
|
||||
clearScreen();
|
||||
drawString(10, 10, "%s", message);
|
||||
drawString(10, 20, "Start and Select to exit");
|
||||
|
||||
u32 kHeld = hidKeysHeld();
|
||||
if ((kHeld & KEY_START) && (kHeld & KEY_SELECT))
|
||||
longjmp(exitJmp, 1);
|
||||
u32 kHeld = hidKeysHeld();
|
||||
if ((kHeld & KEY_START) && (kHeld & KEY_SELECT))
|
||||
longjmp(exitJmp, 1);
|
||||
|
||||
gfxFlushBuffers();
|
||||
gspWaitForVBlank();
|
||||
gfxSwapBuffers();
|
||||
}
|
||||
gfxFlushBuffers();
|
||||
gspWaitForVBlank();
|
||||
gfxSwapBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
acInit();
|
||||
gfxInitDefault();
|
||||
acInit();
|
||||
gfxInitDefault();
|
||||
|
||||
gfxSetDoubleBuffering(GFX_TOP, true);
|
||||
gfxSetDoubleBuffering(GFX_BOTTOM, true);
|
||||
gfxSetDoubleBuffering(GFX_TOP, true);
|
||||
gfxSetDoubleBuffering(GFX_BOTTOM, true);
|
||||
|
||||
if (setjmp(exitJmp))
|
||||
goto exit;
|
||||
if (setjmp(exitJmp))
|
||||
goto exit;
|
||||
|
||||
// preRenderKeyboard();
|
||||
// preRenderKeyboard();
|
||||
|
||||
// clearScreen();
|
||||
drawString(10, 10, "Initing FS...");
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
// clearScreen();
|
||||
drawString(10, 10, "Initing FS...");
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
|
||||
fsInit();
|
||||
fsInit();
|
||||
|
||||
// clearScreen();
|
||||
drawString(10, 10, "Initing SOC...");
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
// clearScreen();
|
||||
drawString(10, 10, "Initing SOC...");
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
|
||||
socInit((u32 *)memalign(0x1000, 0x100000), 0x100000);
|
||||
socInit((u32 *)memalign(0x1000, 0x100000), 0x100000);
|
||||
|
||||
u32 wifiStatus = 0;
|
||||
ACU_GetWifiStatus(&wifiStatus);
|
||||
if (!wifiStatus) {
|
||||
hang("No WiFi! Is your wireless slider on?");
|
||||
}
|
||||
|
||||
clearScreen();
|
||||
drawString(10, 10, "Reading settings...");
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
|
||||
if (!readSettings()) {
|
||||
hang("Could not read 3DSController.ini!");
|
||||
}
|
||||
|
||||
clearScreen();
|
||||
drawString(10, 10, "Connecting to %s on port %d...", settings.IPString,
|
||||
settings.port);
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
|
||||
openSocket(settings.port);
|
||||
sendConnectionRequest();
|
||||
|
||||
// clearScreen();
|
||||
drawString(10, 10, "Sending data to %s on port %d...", settings.IPString,
|
||||
settings.port);
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
|
||||
GSPLCD_PowerOffAllBacklights();
|
||||
|
||||
while (aptMainLoop()) {
|
||||
hidScanInput();
|
||||
irrstScanInput();
|
||||
|
||||
u32 kHeld = hidKeysHeld();
|
||||
circlePosition circlePad;
|
||||
circlePosition cStick;
|
||||
angularRate gyro;
|
||||
accelVector accel;
|
||||
u8 vol8;
|
||||
u8 *volPointer = &vol8; // As a test for pointing at things.
|
||||
// u8 threeD;
|
||||
// u8 *threeDPointer = &threeD;
|
||||
hidCstickRead(&cStick);
|
||||
hidCircleRead(&circlePad);
|
||||
HIDUSER_EnableGyroscope();
|
||||
hidGyroRead(&gyro);
|
||||
HIDUSER_EnableAccelerometer();
|
||||
hidAccelRead(&accel);
|
||||
HIDUSER_GetSoundVolume(volPointer);
|
||||
// MCUHWC_GetSoundSliderLevel(threeDPointer);
|
||||
u32 volume = (u32)vol8; // Upscale to 32 for transmission
|
||||
// u32 threeD32 = (u32)threeD;
|
||||
touchPosition touch;
|
||||
touchRead(&touch);
|
||||
|
||||
clearScreen();
|
||||
|
||||
sendKeys(kHeld, circlePad, touch, cStick, volume, gyro, accel);
|
||||
// drawString(10, 10, "Volume: %x", volume);
|
||||
// receiveBuffer(sizeof(struct packet));
|
||||
|
||||
if ((kHeld & KEY_START) && (kHeld & KEY_SELECT)) {
|
||||
sendKeys(0, circlePad, touch, cStick, volume, gyro, accel);
|
||||
longjmp(exitJmp, 1);
|
||||
u32 wifiStatus = 0;
|
||||
ACU_GetWifiStatus(&wifiStatus);
|
||||
if (!wifiStatus) {
|
||||
hang("No WiFi! Is your wireless slider on?");
|
||||
}
|
||||
|
||||
clearScreen();
|
||||
drawString(10, 10, "Reading settings...");
|
||||
gfxFlushBuffers();
|
||||
gspWaitForVBlank();
|
||||
gfxSwapBuffers();
|
||||
}
|
||||
|
||||
if (!readSettings()) {
|
||||
hang("Could not read 3DSController.ini!");
|
||||
}
|
||||
|
||||
clearScreen();
|
||||
drawString(10, 10, "Connecting to %s on port %d...", settings.IPString,
|
||||
settings.port);
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
|
||||
openSocket(settings.port);
|
||||
sendConnectionRequest();
|
||||
|
||||
// clearScreen();
|
||||
drawString(10, 10, "Sending data to %s on port %d...", settings.IPString,
|
||||
settings.port);
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
|
||||
GSPLCD_PowerOffAllBacklights();
|
||||
|
||||
while (aptMainLoop()) {
|
||||
hidScanInput();
|
||||
irrstScanInput();
|
||||
|
||||
u32 kHeld = hidKeysHeld();
|
||||
circlePosition circlePad;
|
||||
circlePosition cStick;
|
||||
angularRate gyro;
|
||||
accelVector accel;
|
||||
u8 vol8;
|
||||
u8 *volPointer = &vol8; // As a test for pointing at things.
|
||||
// u8 threeD;
|
||||
// u8 *threeDPointer = &threeD;
|
||||
hidCstickRead(&cStick);
|
||||
hidCircleRead(&circlePad);
|
||||
HIDUSER_EnableGyroscope();
|
||||
hidGyroRead(&gyro);
|
||||
HIDUSER_EnableAccelerometer();
|
||||
hidAccelRead(&accel);
|
||||
HIDUSER_GetSoundVolume(volPointer);
|
||||
// MCUHWC_GetSoundSliderLevel(threeDPointer);
|
||||
u32 volume = (u32)vol8; // Upscale to 32 for transmission
|
||||
// u32 threeD32 = (u32)threeD;
|
||||
touchPosition touch;
|
||||
touchRead(&touch);
|
||||
|
||||
clearScreen();
|
||||
|
||||
sendKeys(kHeld, circlePad, touch, cStick, volume, gyro, accel);
|
||||
// drawString(10, 10, "Volume: %x", volume);
|
||||
// receiveBuffer(sizeof(struct packet));
|
||||
|
||||
if ((kHeld & KEY_START) && (kHeld & KEY_SELECT)) {
|
||||
sendKeys(0, circlePad, touch, cStick, volume, gyro, accel);
|
||||
longjmp(exitJmp, 1);
|
||||
}
|
||||
|
||||
gfxFlushBuffers();
|
||||
gspWaitForVBlank();
|
||||
gfxSwapBuffers();
|
||||
}
|
||||
|
||||
exit:
|
||||
GSPLCD_PowerOnAllBacklights();
|
||||
socExit();
|
||||
svcCloseHandle(fileHandle);
|
||||
fsExit();
|
||||
gfxExit();
|
||||
acExit();
|
||||
return 0;
|
||||
GSPLCD_PowerOnAllBacklights();
|
||||
socExit();
|
||||
svcCloseHandle(fileHandle);
|
||||
fsExit();
|
||||
gfxExit();
|
||||
acExit();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,84 +1,82 @@
|
|||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include "settings.h"
|
||||
|
||||
#include <3ds.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "3ds/services/fs.h"
|
||||
#include "wireless.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
struct settings settings;
|
||||
|
||||
struct settings defaultSettings = {
|
||||
.IPString = "",
|
||||
.port= DEFAULT_PORT,
|
||||
.IPString = "",
|
||||
.port = DEFAULT_PORT,
|
||||
};
|
||||
|
||||
Handle fileHandle;
|
||||
|
||||
static bool getSetting(char *name, char *src, char *dest) {
|
||||
char *start = strstr(src, name);
|
||||
|
||||
if(start) {
|
||||
start += strlen(name);
|
||||
|
||||
char *end = start + strlen(start);
|
||||
if(strstr(start, "\n") - 1 < end) end = strstr(start, "\n") - 1;
|
||||
size_t size = (size_t)end - (size_t)start;
|
||||
|
||||
strncpy(dest, start, size);
|
||||
dest[size] = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
char *start = strstr(src, name);
|
||||
|
||||
if (start) {
|
||||
start += strlen(name);
|
||||
|
||||
char *end = start + strlen(start);
|
||||
if (strstr(start, "\n") - 1 < end) end = strstr(start, "\n") - 1;
|
||||
size_t size = (size_t)end - (size_t)start;
|
||||
|
||||
strncpy(dest, start, size);
|
||||
dest[size] = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool readSettings(void) {
|
||||
char *buffer = NULL;
|
||||
u64 size;
|
||||
u32 bytesRead;
|
||||
|
||||
FS_ArchiveID sdmcArchiveID = (ARCHIVE_SDMC);
|
||||
// FS_Archive sdmcArchive = (FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}};
|
||||
FS_Path fileArchive = fsMakePath(PATH_EMPTY, NULL);
|
||||
FS_Path filePath = fsMakePath(PATH_ASCII, "/3DSController.ini");
|
||||
|
||||
Result ret = FSUSER_OpenFileDirectly(&fileHandle, sdmcArchiveID, fileArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_HIDDEN);
|
||||
if(ret) return false;
|
||||
|
||||
ret = FSFILE_GetSize(fileHandle, &size);
|
||||
if(ret) return false;
|
||||
|
||||
buffer = malloc(size);
|
||||
if(!buffer) return false;
|
||||
|
||||
ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size);
|
||||
if(ret || size != bytesRead) return false;
|
||||
|
||||
ret = FSFILE_Close(fileHandle);
|
||||
if(ret) return false;
|
||||
|
||||
memcpy(&settings, &defaultSettings, sizeof(struct settings));
|
||||
|
||||
char setting[64] = { '\0' };
|
||||
|
||||
if(getSetting("IP: ", buffer, settings.IPString)) {
|
||||
//inet_pton(AF_INET, settings.IPString, &(saout.sin_addr));
|
||||
inet_pton4(settings.IPString, (unsigned char *)&(saout.sin_addr));
|
||||
}
|
||||
else {
|
||||
free(buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(getSetting("Port: ", buffer, setting)) {
|
||||
sscanf(setting, "%d", &settings.port);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
return true;
|
||||
char *buffer = NULL;
|
||||
u64 size;
|
||||
u32 bytesRead;
|
||||
|
||||
FS_ArchiveID sdmcArchiveID = (ARCHIVE_SDMC);
|
||||
// FS_Archive sdmcArchive = (FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}};
|
||||
FS_Path fileArchive = fsMakePath(PATH_EMPTY, NULL);
|
||||
FS_Path filePath = fsMakePath(PATH_ASCII, "/3DSController.ini");
|
||||
|
||||
Result ret = FSUSER_OpenFileDirectly(&fileHandle, sdmcArchiveID, fileArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_HIDDEN);
|
||||
if (ret) return false;
|
||||
|
||||
ret = FSFILE_GetSize(fileHandle, &size);
|
||||
if (ret) return false;
|
||||
|
||||
buffer = malloc(size);
|
||||
if (!buffer) return false;
|
||||
|
||||
ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size);
|
||||
if (ret || size != bytesRead) return false;
|
||||
|
||||
ret = FSFILE_Close(fileHandle);
|
||||
if (ret) return false;
|
||||
|
||||
memcpy(&settings, &defaultSettings, sizeof(struct settings));
|
||||
|
||||
char setting[64] = {'\0'};
|
||||
|
||||
if (getSetting("IP: ", buffer, settings.IPString)) {
|
||||
// inet_pton(AF_INET, settings.IPString, &(saout.sin_addr));
|
||||
inet_pton4(settings.IPString, (unsigned char *)&(saout.sin_addr));
|
||||
} else {
|
||||
free(buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getSetting("Port: ", buffer, setting)) {
|
||||
sscanf(setting, "%d", &settings.port);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#include "wireless.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "keyboard.h"
|
||||
#include "sys/_types.h"
|
||||
#include "wireless.h"
|
||||
|
||||
int sock;
|
||||
struct sockaddr_in sain, saout;
|
||||
|
@ -11,50 +13,50 @@ 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);
|
||||
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;
|
||||
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));
|
||||
bind(sock, (struct sockaddr *)&sain, sizeof(sain));
|
||||
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void sendBuf(int length) {
|
||||
sendto(sock, (char *)&outBuf, length, 0, (struct sockaddr *)&saout,
|
||||
sizeof(saout));
|
||||
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);
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue