-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
440 lines (411 loc) · 15.6 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - Sony Remote Control for PS2 and TV
* Based on:
*
* main.c - Infrared Remote example
*
*
* Copyright (c) 2005 Marcus R. Brown <[email protected]>
* Copyright (c) 2005 James Forshaw <[email protected]>
* Copyright (c) 2005 John Kelley <[email protected]>
* Copyright (c) 2005 Matthew H <[email protected]>
* --------------------------------------------------
* Included changes for much larger uses by melman101 : [email protected]
* $$
*/
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspsircs.h>
#include <stdlib.h>
#include <string.h>
/* Define the module info section */
PSP_MODULE_INFO("SIRCS", 0, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
// sircs commands are easily found in lirc
// - interpret as described at
// http://sourceforge.net/mailarchive/message.php?msg_id=8833252
#define SIRCS_ADDR_DVD 0x1b5a
#define SIRCS_CMD_RESET 0x15
#define SIRCS_CMD_PLAY 0x32
#define SIRCS_CMD_PAUSE 0x39
void send_code(int type, int dev, int cmd)
{
struct sircs_data sd;
int ret;
int count = 06; // this seems like a good number
sd.type = type;
sd.cmd = cmd & 0x7f;
sd.dev = dev & 0x1fff;
ret = sceSircsSend(&sd, count);
if (ret < 0)
{
printf ("sceSircsSend returned %d\n", ret);
}
}
/* Exit callback */
int exit_callback(void)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
void CallbackThread(void *arg)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main(void)
{
SceCtrlData pad;
u32 buttonsold = 0;
int initial_state = 0;
int sirc_bits = 20; // # of bits in code, choose from 12, 15 or 20
int sirc_bits2 = 12;
int sent = 0;
int double_button = 0;
SetupCallbacks();
pspDebugScreenInit();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
printf ("Remote Control for: ");
pspDebugScreenSetTextColor(0xCD0000);
printf ("PS2\n");
pspDebugScreenSetTextColor(0xFFFFFF);
printf ("-------\n");
printf ("By: melman101\n");
printf ("Email: [email protected]\n");
printf ("Send any suggestions or tips if you got!\n");
printf ("-------\n");
pspDebugScreenSetTextColor(0x3300ff);
printf ("R Trigger & L Trigger Same Time switches remotes between PS2/Wega\n");
pspDebugScreenSetTextColor(0xFFFFFF);
printf ("-------\n");
pspDebugScreenSetTextColor(0x3300ff);
printf ("Much thanks and help from PSPSDK SIRCS example!\n");
pspDebugScreenSetTextColor(0xFFFFFF);
printf ("Square, X, Circle and Triangle all send same symbol\n");
printf ("Triggers send L1 and R1\n");
printf ("Up, Down, Left, Right on Directional Pad send same\n");
printf ("Left Trigger + Start = on - Left Trigger + Select = off\n");
pspDebugScreenSetXY(0, 2);
do {
sceCtrlReadBufferPositive(&pad, 1);
if (initial_state == 1)
{
if (sent == 0)
{
if (pad.Lx > 170 && pad.Lx < 255)
{
printf("Menu right\n");
send_code(sirc_bits2, 0x01, 0x33);
sent = 1;
}
if (pad.Ly > 170 && pad.Ly < 255)
{
printf("Menu down\n");
send_code(sirc_bits2, 0x01, 0x75);
sent = 1;
}
if (pad.Lx < 70 && pad.Lx > 0)
{
printf("Menu left\n");
send_code(sirc_bits2, 0x01, 0x34);
sent = 1;
}
if (pad.Ly < 70 && pad.Ly > 0)
{
printf("Menu up\n");
send_code(sirc_bits2, 0x01, 0x74);
sent = 1;
}
}
if ((pad.Ly > 100 && pad.Ly < 150) && (pad.Lx > 100 && pad.Lx < 150))
{
sent = 0;
}
}
if (initial_state == 2)
{
if (sent == 0)
{
if (pad.Lx > 170 && pad.Lx < 255)
{
printf("Scan Reverse\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x34);
sent = 1;
}
if (pad.Lx < 70 && pad.Lx > 0)
{
printf("Scan Forward\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x33);
sent = 1;
}
}
if ((pad.Ly > 100 && pad.Ly < 150) && (pad.Lx > 100 && pad.Lx < 150))
{
sent = 0;
}
}
if (pad.Buttons != buttonsold)
{
// PS2 Remote
if (initial_state == 0) {
if ((pad.Buttons & PSP_CTRL_SELECT) && (pad.Buttons & PSP_CTRL_LTRIGGER))
{
printf ("PS2 Power Off\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x2F);
double_button = 1;
}
if ((pad.Buttons & PSP_CTRL_START) && (pad.Buttons & PSP_CTRL_LTRIGGER))
{
printf ("PS2 Power On\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x2E);
double_button = 1;
}
if ((pad.Buttons & PSP_CTRL_LTRIGGER) && (pad.Buttons & PSP_CTRL_RTRIGGER))
{
initial_state = 1;
pspDebugScreenClear();
printf("Remote Control for: ");
pspDebugScreenSetTextColor(0x3300ff);
printf ("Sony WEGA\n");
pspDebugScreenSetTextColor(0xFFFFFF);
printf ("X = TV/Video - Circle = Sleep Timer\n");
printf ("Triangle = Pip on/off - Square = PIP Swap\n");
printf ("Left = Decrease Volume - Right = Increase Volume\n");
printf ("LTrigger + Triangle = Menu - Analog Stick to scroll threw\n");
printf ("Select = Enter on Menu - Up/Down = Channel Up/Down\n");
printf ("Start is Power\n");
double_button = 1;
}
if ((pad.Buttons & PSP_CTRL_SELECT) && (double_button == 0))
{
printf ("Select Button\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x50);
}
if ((pad.Buttons & PSP_CTRL_START) && (double_button == 0))
{
printf ("Start Button\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x53);
}
if ((pad.Buttons & PSP_CTRL_SQUARE) && (double_button == 0))
{
printf ("Sending Square\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x5F);
}
if ((pad.Buttons & PSP_CTRL_CIRCLE) && (double_button == 0))
{
printf ("Sending Circle\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x5D);
}
if ((pad.Buttons & PSP_CTRL_TRIANGLE) && (double_button == 0))
{
printf ("Sending Triangle\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x5C);
}
if ((pad.Buttons & PSP_CTRL_CROSS) && (double_button == 0))
{
printf ("Sending X\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x5E);
}
if ((pad.Buttons & PSP_CTRL_UP) && (double_button == 0))
{
printf ("Sending Up\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x54);
}
if ((pad.Buttons & PSP_CTRL_DOWN) && (double_button == 0))
{
printf ("Sending Down\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x56);
}
if ((pad.Buttons & PSP_CTRL_LEFT) && (double_button == 0))
{
printf ("Sending Left\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x57);
}
if ((pad.Buttons & PSP_CTRL_RIGHT) && (double_button == 0))
{
printf ("Sending Right\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x55);
}
if ((pad.Buttons & PSP_CTRL_RTRIGGER) && (double_button == 0))
{
printf ("R1\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x5B);
}
if ((pad.Buttons & PSP_CTRL_LTRIGGER) && (double_button == 0))
{
printf ("L1\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x5A);
}
}
// Sony WEGA Remote
else if (initial_state == 1)
{
if ((pad.Buttons & PSP_CTRL_LTRIGGER) && (pad.Buttons & PSP_CTRL_TRIANGLE))
{
printf ("Menu\n");
send_code(sirc_bits2, 0x01, 0x60);
double_button = 1;
}
if ((pad.Buttons & PSP_CTRL_START) && (double_button == 0))
{
printf ("Sending Power ON/OFF to TV!\n");
send_code(sirc_bits2, 0x01, 0x15);
}
if ((pad.Buttons & PSP_CTRL_LEFT) && (double_button == 0))
{
printf ("Decreasing TV Volume\n");
send_code(sirc_bits2, 0x01, 0x13);
}
if ((pad.Buttons & PSP_CTRL_RIGHT) && (double_button == 0))
{
printf ("Increasing TV Volume\n");
send_code(sirc_bits2, 0x01, 0x12);
}
if ((pad.Buttons & PSP_CTRL_CROSS) && (double_button == 0))
{
printf ("TV/VIDEO\n");
send_code(sirc_bits2, 0x01, 0x25);
}
if ((pad.Buttons & PSP_CTRL_TRIANGLE) && (double_button == 0))
{
printf ("PIP On\n");
send_code(sirc_bits2, 0x01, 0x5b);
}
if ((pad.Buttons & PSP_CTRL_SQUARE) && (double_button == 0))
{
printf ("PIP SWAP\n");
send_code(sirc_bits2, 0x01, 0x5f);
}
if ((pad.Buttons & PSP_CTRL_CIRCLE) && (double_button == 0))
{
printf ("Sleep Timer\n");
send_code(sirc_bits2, 0x01, 0x36);
}
if ((pad.Buttons & PSP_CTRL_SELECT) && (double_button == 0))
{
printf ("Enter\n");
send_code(sirc_bits2, 0x01, 0x65);
}
if ((pad.Buttons & PSP_CTRL_UP) && (double_button == 0))
{
printf ("Channel up\n");
send_code(sirc_bits2, 0x01, 0x10);
}
if ((pad.Buttons & PSP_CTRL_DOWN) && (double_button == 0))
{
printf ("Channel down\n");
send_code(sirc_bits2, 0x01, 0x11);
}
if ((pad.Buttons & PSP_CTRL_RTRIGGER) && (double_button == 0))
{
initial_state = initial_state + 1;
pspDebugScreenClear();
printf ("Remote Control for ");
pspDebugScreenSetTextColor(0x33DDAA);
printf ("PS2 DVD Player\n");
pspDebugScreenSetTextColor(0xFFFFFF);
printf ("Triangle = On-Screen Controller - Circle = Play\n");
printf ("X = Stop - Up/Down/Left/Right Control Display");
printf ("Square = Pause - Start = Enter\n");
printf ("LTrigger = DVD Menu\n");
printf ("Analog Stick Left = Scan Reverse\n");
printf ("Analog Stick Left = Scan Forward\n");
}
}
// Sony PS2 DVD Remote
else if (initial_state == 2)
{
if ((pad.Buttons & PSP_CTRL_START) && (double_button == 0))
{
printf ("Enter\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x0B);
}
if ((pad.Buttons & PSP_CTRL_CROSS) && (double_button == 0))
{
printf ("Stop\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x38);
}
if ((pad.Buttons & PSP_CTRL_TRIANGLE) && (double_button == 0))
{
printf ("On-Screen Controller\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x50);
}
if ((pad.Buttons & PSP_CTRL_SQUARE) && (double_button == 0))
{
printf ("Pause\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x39);
}
if ((pad.Buttons & PSP_CTRL_CIRCLE) && (double_button == 0))
{
printf ("Play\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x32);
}
if ((pad.Buttons & PSP_CTRL_LTRIGGER) && (double_button == 0))
{
printf ("DVD Menu\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x1B);
}
if ((pad.Buttons & PSP_CTRL_UP) && (double_button == 0))
{
printf ("Up\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x79);
}
if ((pad.Buttons & PSP_CTRL_DOWN) && (double_button == 0))
{
printf ("Down\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x7A);
}
if ((pad.Buttons & PSP_CTRL_LEFT) && (double_button == 0))
{
printf ("Left\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x7B);
}
if ((pad.Buttons & PSP_CTRL_RIGHT) && (double_button == 0))
{
printf ("Right\n");
send_code(sirc_bits, SIRCS_ADDR_DVD, 0x7C);
}
if ((pad.Buttons & PSP_CTRL_RTRIGGER) && (double_button == 0))
{
initial_state = 0;
pspDebugScreenClear();
printf ("Remote Control for ");
pspDebugScreenSetTextColor(0xCD0000);
printf ("PS2\n");
pspDebugScreenSetTextColor(0xFFFFFF);
printf ("Square, X, Circle and Triangle all send same symbol\n");
printf ("Up, Down, Left, Right on Directional Pad send same\n");
printf ("Start is on, Select is off\n");
}
}
double_button = 0;
buttonsold = pad.Buttons;
}
sceDisplayWaitVblankStart();
} while (1);
return 0;
}