Skip to content

Commit dd60fd6

Browse files
committed
refactor
1 parent 44af5cf commit dd60fd6

File tree

13 files changed

+181
-296
lines changed

13 files changed

+181
-296
lines changed

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
build/*
2-
!EBOOT.PBP
3-
4-
# vscode
5-
.vscode/
1+
build
2+
.vscode

CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.15)
22
project(psp-controller)
33

4-
add_compile_options(-Wall -Wextra -Werror -Wconversion)
5-
set(CMAKE_C_STANDARD 11)
6-
set(CMAKE_C_STANDARD_REQUIRED On)
7-
set(CMAKE_C_EXTENSIONS Off)
84
add_executable(
95
${PROJECT_NAME}
10-
src/main.c
11-
src/callback.c
12-
src/connection.c
13-
src/psp_modules.c
6+
main.c
147
)
158

169
target_link_libraries(

main.c

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#include <pspkernel.h>
2+
#include <pspdebug.h>
3+
#include <pspctrl.h>
4+
#include <pspsdk.h>
5+
#include <pspnet_apctl.h>
6+
#include <psputility.h>
7+
#include <arpa/inet.h>
8+
9+
#include <string.h>
10+
11+
#define MODULE_NAME "PSP-CONTROLLER"
12+
#define IP_ADDRESS "192.168.4.1"
13+
#define PORT 80
14+
15+
PSP_MODULE_INFO(MODULE_NAME, PSP_MODULE_USER, 0, 1);
16+
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
17+
18+
PSP_HEAP_THRESHOLD_SIZE_KB(4096);
19+
PSP_HEAP_SIZE_KB(-4096);
20+
PSP_MAIN_THREAD_STACK_SIZE_KB(4096);
21+
22+
int exit_cb(int arg0, int arg1, void *common) {
23+
sceKernelExitGame();
24+
return 0;
25+
}
26+
27+
int thread_cb(SceSize args, void *argp) {
28+
int cbid = sceKernelCreateCallback("exit_cb", exit_cb, NULL);
29+
30+
sceKernelRegisterExitCallback(cbid);
31+
sceKernelSleepThreadCB();
32+
return 0;
33+
}
34+
35+
int setup_cb(void) {
36+
SceUID thid = sceKernelCreateThread("setup_cb", thread_cb, 0x10, 0x1000, PSP_THREAD_ATTR_USER, NULL);
37+
sceKernelStartThread(thid, 0, NULL);
38+
return thid;
39+
}
40+
41+
int connect_apctl(int config) {
42+
int state;
43+
int last_state = -1;
44+
int error;
45+
46+
/* Connect to first wifi profile */
47+
error = sceNetApctlConnect(config);
48+
if (error < 0) {
49+
pspDebugScreenPrintf(MODULE_NAME ": sceNetApctlConnect returns %08x\n", error);
50+
return 0;
51+
}
52+
53+
pspDebugScreenPrintf(MODULE_NAME ": Connecting...\n");
54+
while (1) {
55+
error = sceNetApctlGetState(&state);
56+
if (error < 0) {
57+
pspDebugScreenPrintf(MODULE_NAME ": sceNetApctlGetState returns $%08x\n", error);
58+
break;
59+
}
60+
61+
if (state > last_state) {
62+
pspDebugScreenPrintf("connection state %d of 4\n", state);
63+
last_state = state;
64+
}
65+
66+
if (state == PSP_NET_APCTL_STATE_GOT_IP) { break; }
67+
sceKernelDelayThread(50 * 1000); // 50ms
68+
}
69+
}
70+
71+
int main(void) {
72+
setup_cb();
73+
sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON);
74+
sceUtilityLoadNetModule(PSP_NET_MODULE_INET);
75+
pspDebugScreenInit();
76+
77+
int sock;
78+
int error;
79+
SceCtrlData pad;
80+
struct sockaddr_in name;
81+
const char ON[64] = "GET /on HTTP/1.1\r\nHost: " IP_ADDRESS "\r\nConnection: close\r\n\r\n";
82+
const char OFF[64] = "GET /off HTTP/1.1\r\nHost: " IP_ADDRESS "\r\nConnection: close\r\n\r\n";
83+
84+
memset(&name, 0, sizeof(name));
85+
sceCtrlSetSamplingCycle(0);
86+
sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
87+
88+
do {
89+
error = pspSdkInetInit();
90+
if (error) {
91+
pspDebugScreenPrintf(MODULE_NAME ": pspSdkInetInit returns %08x\n", error);
92+
break;
93+
}
94+
95+
connect_apctl(1);
96+
pspDebugScreenClear();
97+
pspDebugScreenPrintf("==================================\n");
98+
pspDebugScreenPrintf("psp-controller-client\n");
99+
pspDebugScreenPrintf("GitHub: https://github.com/diamant3/psp-controller\n");
100+
pspDebugScreenPrintf("==================================\n");
101+
while (1) {
102+
pspDebugScreenSetXY(0, 4);
103+
sceCtrlReadBufferPositive(&pad, 1);
104+
105+
if (pad.Buttons != 0) {
106+
sock = socket(PF_INET, SOCK_STREAM, 0);
107+
if (sock < 0) { return -1; }
108+
109+
name.sin_family = AF_INET;
110+
name.sin_port = htons(PORT);
111+
inet_pton(AF_INET, IP_ADDRESS, &(name.sin_addr));
112+
113+
connect(sock, (struct sockaddr *)&name, sizeof(name));
114+
115+
if (pad.Buttons & PSP_CTRL_CIRCLE) {
116+
pspDebugScreenPrintf("LED Status: On ");
117+
send(sock, &ON, strlen(ON), 0);
118+
}
119+
120+
if (pad.Buttons & PSP_CTRL_CROSS) {
121+
pspDebugScreenPrintf("LED Status: Off");
122+
send(sock, &OFF, strlen(OFF), 0);
123+
}
124+
}
125+
126+
sceKernelDelayThread(50 * 1000); // 50ms
127+
}
128+
} while (0);
129+
130+
pspSdkInetTerm();
131+
sceUtilityUnloadNetModule(PSP_NET_MODULE_COMMON);
132+
sceUtilityUnloadNetModule(PSP_NET_MODULE_INET);
133+
return 0;
134+
}

main.ino

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <ESP8266WiFi.h>
2+
#include <ESP8266WebServer.h>
3+
4+
// Set web server port number to 80
5+
ESP8266WebServer server(80);
6+
7+
// Set BUILTIN LED
8+
const int ledPin = BUILTIN_LED;
9+
10+
// Network credentials
11+
const char *ssid = "PSP-CONTROLLER SERVER";
12+
const char *password = "";
13+
14+
void setup() {
15+
// Initialize the LED pin as an output
16+
pinMode(ledPin, OUTPUT);
17+
digitalWrite(ledPin, HIGH);
18+
19+
// Start Serial
20+
Serial.begin(115200);
21+
delay(10);
22+
23+
// Configure as an access point
24+
Serial.println();
25+
Serial.println("Setting up WiFi AP...");
26+
WiFi.softAP(ssid, password);
27+
28+
IPAddress IP = WiFi.softAPIP();
29+
30+
// web server routes
31+
server.on("/on", []() { digitalWrite(ledPin, LOW); server.send(200, "text/html", ""); });
32+
server.on("/off", []() { digitalWrite(ledPin, HIGH); server.send(200, "text/html", ""); });
33+
34+
// Start the server
35+
server.begin();
36+
Serial.print("HTTP server started: ");
37+
Serial.println(IP);
38+
}
39+
40+
void loop() {
41+
// Handle client requests
42+
server.handleClient();
43+
}

psp-controller/psp-controller.ino

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/callback.c

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/callback.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/connection.c

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/connection.h

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)