controller.c
1.54 KB
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
#include <ultra64.h>
#include <ramrom.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* app specific includes */
#include "rsplight.h"
OSMesgQueue controllerMsgQ;
OSMesg controllerMsgBuf;
int initControllers(void);
OSContStatus statusdata[MAXCONTROLLERS];
OSContPad controllerdata[MAXCONTROLLERS];
/*
*
* Return the lowest number controller connected to system
*/
int initControllers()
{
OSMesgQueue serialMsgQ;
OSMesg serialMsg;
int i;
u8 pattern;
osCreateMesgQueue(&serialMsgQ, &serialMsg, 1);
osSetEventMesg(OS_EVENT_SI, &serialMsgQ, (OSMesg)1);
osContInit(&serialMsgQ, &pattern, &statusdata[0]);
osCreateMesgQueue(&controllerMsgQ, &controllerMsgBuf, 1);
osSetEventMesg(OS_EVENT_SI, &controllerMsgQ, (OSMesg)0);
for (i = 0; i < MAXCONTROLLERS; i++) {
if ((pattern & (1<<i)) &&
!(statusdata[i].errno & CONT_NO_RESPONSE_ERROR))
return i;
}
return -1;
}
void ReadController()
{
static u16 button, lastbutton;
osContStartReadData(&controllerMsgQ);
(void)osRecvMesg(&controllerMsgQ, NULL, OS_MESG_BLOCK);
osContGetReadData(controllerdata);
button = controllerdata[0].button;
if ((button & CONT_A) && !(lastbutton & CONT_A))
{
ImageNumber--;
rmonPrintf("Doing image %d \n", ImageNumber);
}
else if ((button & CONT_E) && !(lastbutton & CONT_E))
{
ImageNumber++;
rmonPrintf("Doing image %d \n", ImageNumber);
}
lastbutton = button;
}