/[ps2dev-projects]/trunk/Projects/vibration-test/src/vibration-test.c
ViewVC logotype

Contents of /trunk/Projects/vibration-test/src/vibration-test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Fri Nov 2 00:03:01 2018 UTC (21 months, 1 week ago) by william
File MIME type: text/plain
File size: 2827 byte(s)
update src/vibration-test.c :: 
** to reflect current changes
** fix issues with text being written to the screen multiple times
** fix issue with small vibration engine not being enabled


1 /* Source Code (C) 2008 - NeoH4x0r
2 EMAIL: WilliamDeRieux@Gmail.com */
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <tamtypes.h>
7 #include <sifcmd.h>
8 #include <kernel.h>
9 #include <sifrpc.h>
10 #include <libpad.h>
11 #include <string.h>
12 #include <sys/stat.h>
13 #include <debug.h>
14 #include <timer.h>
15 #include <math.h>
16 #include <libpad.h>
17
18 /* Begin Global Custom Headers Section */
19 #include <CustomMacros.h>
20 //#include <StringFunctions.h>
21 //#include <DebugFunctions.h>
22 #include <DataTypeConversionFunctions.h>
23 #include <ee_timer.h>
24 #include <ControllerButtonHandler.h>
25 #include <ScreenFunctions.h>
26 #include <ModuleRoutines.h>
27 #include <TextAlignmentFunctions.h>
28 /* End Global Custom Headers Section */
29
30 /* Begin Local Custom Headers Section */
31
32 /* End Local Custom Headers Section */
33
34 static char actAlign[6];
35 static char padBuf[256] __attribute__((aligned(64)));
36 static int bVibrationStarted;
37 int main()
38 {
39 bVibrationStarted=0;
40 SifInitRpc(0); // Graphics Related Use, see Graph.h for a list of Modes
41 CreateScreen(); // Screen Initialization (needed for for graphics and text to be written to screen)
42
43 scr_printf("Loading Modules\n");
44 /* Load Various Modules, including Controller Modules */
45 Load_Modules();
46 scr_printf(" Modules Loaded...\n");
47
48 padInit(0);
49
50 padBuf[0] = 0;
51 padBuf[1] = 0;
52
53 scr_printf("Opening Pad 1\n");
54 int open_ret = padPortOpen(0, 0, padBuf);
55 if(!open_ret) { scr_printf(" Faled to open Pad 1\n"); }
56 else { scr_printf(" Opened Pad 1\n"); }
57
58 scr_printf("Initializing Pad 1\n");
59 if(!initializePad(0, 0)) { scr_printf(" Failed to initialize Pad 1\n"); SleepThread(); }
60 else { scr_printf(" Initialized Pad 1\n"); }
61
62
63 struct padButtonStatus buttons;
64
65 scr_printf("Press R1 to start vibration\n");
66 scr_printf("Hold L1, L2, R2, and then tap R1 to stop vibration\n");
67
68 while(1) {
69 int pr_state = padGetState(0, 0);
70 while((pr_state != PAD_STATE_STABLE) && (pr_state != PAD_STATE_FINDCTP1)) {
71 if(pr_state==PAD_STATE_DISCONN) {
72 printf("Pad(%d, %d) is disconnected\n", 0, 0);
73 }
74 pr_state=padGetState(0, 0);
75 }
76 int pr_ret = padRead(0, 0, &buttons); // port, slot, buttons
77 if (pr_ret != 0) {
78 if(buttons.l1_p && buttons.l2_p && buttons.r2_p && buttons.r1_p) {
79 if(bVibrationStarted == 1) {
80 bVibrationStarted=0;
81 scr_printf("Stopping vibration\n");
82 actAlign[0] = 0;
83 actAlign[1] = 0;
84 padSetActDirect(0, 0, actAlign);
85 }
86 }
87 else {
88 if((bVibrationStarted == 0) && buttons.r1_p) {
89 bVibrationStarted=1;
90 scr_printf("Starting vibration\n");
91 actAlign[0] = 1;
92 actAlign[1] = 255;
93 padSetActDirect(0, 0, actAlign);
94 }
95 }
96 }
97 pr_ret = 0;
98 }
99
100 return 0;
101
102 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.22