-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
300 lines (268 loc) · 8.5 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
#include "std.h"
// Kernel mode access required for hardware hacks
PSP_MODULE_INFO("Philips Remote", 0x1000, 1, 1); // KMEM access for ir hacks
PSP_MAIN_THREAD_ATTR(0); // Kernel thread
#include "stdexit.c_" // standard exit code
static u32 PollButtons(u32* buttonsShiftPtr)
{
static u32 s_buttonsLastPoll = 0;
SceCtrlData pad;
sceCtrlReadBufferPositive(&pad, 1);
u32 buttonsNew = pad.Buttons & ~s_buttonsLastPoll;
s_buttonsLastPoll = pad.Buttons;
if (buttonsShiftPtr != NULL)
*buttonsShiftPtr = s_buttonsLastPoll & ~buttonsNew;
// first time shift button is pressed it comes through normally
return buttonsNew;
}
// test modes
static void DoTVMode();
static void DoTestMode();
static void DoDVDMode();
int main(void)
{
SetupCallbacks();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
while (1)
{
// main mode
pspDebugScreenInit();
printf("Philips IR\n\n");
printf("Press TRIANGLE to exit\n");
printf("Press CIRCLE for TV\n");
printf("Press SQUARE for DVD\n");
printf("Press CROSS for TEST MODE\n");
u32 buttons;
while ((buttons = PollButtons(NULL)) == 0)
sceDisplayWaitVblankStart(); // slow things down a little
if (buttons & PSP_CTRL_TRIANGLE)
break;
if (buttons & PSP_CTRL_CIRCLE)
DoTVMode();
else if (buttons & PSP_CTRL_SQUARE)
DoDVDMode();
else if (buttons & PSP_CTRL_CROSS)
DoTestMode();
// when modes exit - redraw the instructions
}
printf("\nGoodbye\n");
sceKernelExitGame();
return 0;
}
//////////////////////////////////////////////////////////////////////
// TV Mode
#include "rc6.h"
static void DoTVMode()
{
u8 tvDevId = 0;
pspDebugScreenInit();
printf("TV Mode\n");
printf("Press SELECT for BACK\n");
printf("Press START to turn TV on/off\n");
printf("Press LEFT/RIGHT for volume up/down\n");
printf("Press UP/DOWN for channel up/down\n");
printf("Press CROSS for MUTE\n");
printf("Press TRIANGLE for Text\n");
printf("Hold RTrigger and press LEFT/RIGHT/UP/DOWN for menu navigate\n");
printf("Hold RTrigger and press CROSS or CIRCLE for OK\n");
printf("Hold L and press SQUARE/TRIANGLE/CIRCLE/CROSS for RED/GREEN/YELLOW/BLUE\n");
while (1)
{
u32 buttonsShift;
u32 buttons = PollButtons(&buttonsShift);
if (buttons & PSP_CTRL_SELECT)
break;
if (buttonsShift & PSP_CTRL_RTRIGGER)
{
// R Trigger for menu navigate
if (buttons & PSP_CTRL_UP)
send_rc6_philips(tvDevId,IR_BUTTON_UP);
else if (buttons & PSP_CTRL_DOWN)
send_rc6_philips(tvDevId,IR_BUTTON_DOWN);
else if (buttons & PSP_CTRL_LEFT)
send_rc6_philips(tvDevId,IR_BUTTON_LEFT);
else if (buttons & PSP_CTRL_RIGHT)
send_rc6_philips(tvDevId,IR_BUTTON_RIGHT);
else if (buttons & PSP_CTRL_CROSS)
send_rc6_philips(tvDevId,IR_BUTTON_OK);
else if (buttons & PSP_CTRL_CIRCLE)
send_rc6_philips(tvDevId,IR_BUTTON_OK);
else if (buttons & PSP_CTRL_SQUARE)
send_rc6_philips(tvDevId,IR_BUTTON_ENTER);
}
else if (buttonsShift & PSP_CTRL_LTRIGGER)
{
// L Trigger for modes
if (buttons & PSP_CTRL_CROSS)
send_rc6_philips(tvDevId,IR_BUTTON_BLUE);
else if (buttons & PSP_CTRL_CIRCLE)
send_rc6_philips(tvDevId,IR_BUTTON_YELLOW);
else if (buttons & PSP_CTRL_SQUARE)
send_rc6_philips(tvDevId,IR_BUTTON_RED);
else if (buttons & PSP_CTRL_TRIANGLE)
send_rc6_philips(tvDevId,IR_BUTTON_GREEN);
}
else
{
// no shift
if (buttons & PSP_CTRL_UP)
send_rc6_philips(tvDevId,IR_BUTTON_CH_UP);
else if (buttons & PSP_CTRL_DOWN)
send_rc6_philips(tvDevId,IR_BUTTON_CH_DOWN);
else if (buttons & PSP_CTRL_LEFT)
send_rc6_philips(tvDevId,IR_BUTTON_VOL_DOWN);
else if (buttons & PSP_CTRL_RIGHT)
send_rc6_philips(tvDevId,IR_BUTTON_VOL_UP);
else if (buttons & PSP_CTRL_CROSS)
send_rc6_philips(tvDevId,IR_BUTTON_MUTE);
else if (buttons & PSP_CTRL_TRIANGLE)
send_rc6_philips(tvDevId,IR_BUTTON_TEXT);
else if (buttons & PSP_CTRL_START)
send_rc6_philips(tvDevId,IR_BUTTON_POWER);
}
}
printf("Exiting TV Mode\n");
}
//////////////////////////////////////////////////////////////////////
// DVD Mode
static void DoDVDMode()
{
u8 dvdId = 4;
pspDebugScreenInit();
printf("DVD Mode\n");
printf("Press SELECT for BACK\n");
printf("Press START to turn DVD on/off\n");
printf("Press TRIANGLE for PLAY\n");
printf("Press SQUARE for STOP\n");
printf("Press CIRCLE for PAUSE\n");
printf("Press LEFT/RIGHT/UP/DOWN for menu navigate\n");
printf("Press CROSS for OK\n");
printf("Hold RTrigger and press LEFT/RIGHT for FORWARD/REWIND\n");
printf("Hold LTrigger and press CROSS for Subtitles\n");
printf("Hold LTrigger and press CIRCLE for Disk Menu\n");
printf("Hold LTrigger and press SQUARE for System Menu\n");
while (1)
{
u32 buttonsShift;
u32 buttons = PollButtons(&buttonsShift);
if (buttons & PSP_CTRL_SELECT)
break;
if (buttonsShift & PSP_CTRL_RTRIGGER)
{
// R Trigger
if (buttons & PSP_CTRL_LEFT)
send_rc6_philips(dvdId,IR_BUTTON_REW);
else if (buttons & PSP_CTRL_RIGHT)
send_rc6_philips(dvdId,IR_BUTTON_FWD);
else if (buttons & PSP_CTRL_CROSS)
send_rc6_philips(dvdId,IR_BUTTON_OK);
else if (buttons & PSP_CTRL_CIRCLE)
send_rc6_philips(dvdId,IR_BUTTON_OK);
else if (buttons & PSP_CTRL_SQUARE)
send_rc6_philips(dvdId,IR_BUTTON_ENTER);
}
else if (buttonsShift & PSP_CTRL_LTRIGGER)
{
// L Trigger
if (buttons & PSP_CTRL_CROSS)
send_rc6_philips(dvdId,IR_BUTTON_SUBTITLE);
else if (buttons & PSP_CTRL_CIRCLE)
send_rc6_philips(dvdId,IR_BUTTON_DVDMENU);
else if (buttons & PSP_CTRL_SQUARE)
send_rc6_philips(dvdId,IR_BUTTON_SYSMENU);
}
else
{
// no shift
if (buttons & PSP_CTRL_UP)
send_rc6_philips(dvdId,IR_BUTTON_UP);
else if (buttons & PSP_CTRL_DOWN)
send_rc6_philips(dvdId,IR_BUTTON_DOWN);
else if (buttons & PSP_CTRL_LEFT)
send_rc6_philips(dvdId,IR_BUTTON_LEFT);
else if (buttons & PSP_CTRL_RIGHT)
send_rc6_philips(dvdId,IR_BUTTON_RIGHT);
else if (buttons & PSP_CTRL_START)
send_rc6_philips(dvdId,IR_BUTTON_POWER);
else if (buttons & PSP_CTRL_TRIANGLE)
send_rc6_philips(dvdId,IR_BUTTON_PLAY);
else if (buttons & PSP_CTRL_CIRCLE)
send_rc6_philips(dvdId,IR_BUTTON_PAUSE);
else if (buttons & PSP_CTRL_SQUARE)
send_rc6_philips(dvdId,IR_BUTTON_STOP);
else if (buttons & PSP_CTRL_CROSS)
send_rc6_philips(dvdId,IR_BUTTON_OK);
}
}
printf("Exiting DVD Mode\n");
}
//////////////////////////////////////////////////////////////////////
// Test Mode
static void PrintTestModeInfo()
{
pspDebugScreenInit();
printf("Philips Test Mode\n");
printf("Press CROSS for Send\n");
printf("Press TRIANGLE to exit\n");
printf("Press UP for DeviceID+\n");
printf("Press DOWN for DeviceID-\n");
printf("Press LEFT for Code+ \n");
printf("Press RIGHT for Code-\n");
}
static void DoTestMode()
{
int count = 0;
u8 devId, code, oldId, oldCode;
devId = 0;
code = 0;
oldId = 1;
oldCode = 1;
PrintTestModeInfo();
while (1)
{
u32 buttonsShift;
u32 buttons = PollButtons(&buttonsShift);
if (buttons & PSP_CTRL_TRIANGLE)
break;
if (buttons & PSP_CTRL_UP){
if(devId < 255)
devId++;
else
devId = 0;
}
else if (buttons & PSP_CTRL_DOWN){
if(devId > 0)
devId--;
else
devId = 255;
}
else if (buttons & PSP_CTRL_LEFT){
if(code > 0)
code--;
else
code = 255;
}
else if (buttons & PSP_CTRL_RIGHT){
if(code < 255)
code++;
else
code = 0;
}
else if (buttons & PSP_CTRL_CROSS)
send_rc6_philips(devId, code);
if(devId != oldId || code != oldCode){
if(count < 25)
count++;
else{
PrintTestModeInfo();
count = 0;
}
printf("Dev: %x, Code: %x\n", devId, code);
oldId = devId;
oldCode = code;
}
}
printf("Exiting Test Mode\n");
}
//////////////////////////////////////////////////////////////////////