4 // Testing module for the Mindsensor PSPNx wrapper class
\r
6 // 09.28.2008 Jon C. Martin
\r
11 // To properly interface with LEJOS-OSEK, we need to use C linkage between our
\r
12 // code and LEJOS-OSEK
\r
15 #define PSPNx_DEFAULT_PORT 0x02
\r
18 #include "ecrobot_interface.h"
\r
23 PSPNx psStick(NXT_PORT_S1, PSPNx_DEFAULT_PORT);
\r
28 //Mindsensor's support confirms that for certain gamepads, setting a mode
\r
29 //must be called several times until it becomes active
\r
30 psStick.setAnalog();
\r
33 U8 const * const rawData = psStick.getRawData();
\r
35 //grab the first two bytes of the raw data (the button data)
\r
36 U16 rawDigitalPad = *(reinterpret_cast<U16 const * const>(rawData));
\r
38 rawDigitalPad ^= 0xffff;
\r
40 //display the bit set indicating whether or not a digital button is pressed
\r
41 for(int i = 0; i < 16; ++i)
\r
43 display_goto_xy(i,0);
\r
44 //quick and dirty way to display each bit's status
\r
45 display_int((rawDigitalPad & (1 << i))? 1 : 0, 0);
\r
48 //display the analog stick data
\r
49 display_goto_xy(0,1);
\r
50 display_int(rawData[2], 0);
\r
51 display_goto_xy(4,1);
\r
52 display_int(rawData[3], 0);
\r
53 display_goto_xy(0,2);
\r
54 display_int(rawData[4], 0);
\r
55 display_goto_xy(4,2);
\r
56 display_int(rawData[5], 0);
\r
58 //example of how to read and use the three distinct digital button states
\r
59 if(psStick.pressed(PSPNx_SQUARE))
\r
62 display_goto_xy(0,4);
\r
63 display_string("Pressed");
\r
66 if(psStick.held(PSPNx_SQUARE))
\r
68 display_goto_xy(0,5);
\r
69 display_string("Held");
\r
72 if(psStick.released(PSPNx_SQUARE))
\r
74 display_goto_xy(0,6);
\r
75 display_string("Released");
\r
78 //press select to clear the display
\r
79 if(psStick.pressed(PSPNx_SELECT))
\r