1 /* sample.cpp for TOPPERS/ATK(OSEK) */
\r
7 using namespace ecrobot;
\r
12 #include "kernel_id.h"
\r
13 #include "ecrobot_interface.h"
\r
15 PSPNx psStick(PORT_1);
\r
17 // nxtOSEK hook to be invoked from an ISR in category 2
\r
18 void user_1ms_isr_type2(void)
\r
20 SleeperMonitor(); // needed for I2C device and Clock classes
\r
30 U8 rawData[PSPNx::DATA_BUFFER_BYTE_SIZE];
\r
32 //Mindsensor's support confirms that for certain gamepads, setting a mode
\r
33 //must be called several times until it becomes active
\r
34 psStick.setAnalog();
\r
37 psStick.get(rawData); // get raw I2C data
\r
38 //grab the first two bytes of the raw data (the button data)
\r
39 U16 rawDigitalPad = *(reinterpret_cast<U16 const * const>(rawData));
\r
41 rawDigitalPad ^= 0xffff;
\r
44 //display the bit set indicating whether or not a digital button is pressed
\r
45 for(int i = 0; i < 16; ++i)
\r
47 //quick and dirty way to display each bit's status
\r
48 lcd.putf("d", ((rawDigitalPad & (1 << i))? 1 : 0),0);
\r
51 //display the analog stick data
\r
53 lcd.putf("sddn", " LeftX/Y:", rawData[2],0, rawData[3],5);
\r
54 lcd.putf("sddn", "RightX/Y:", rawData[4],0, rawData[5],5);
\r
56 //example of how to read and use the three distinct digital button states
\r
57 lcd.putf("s", "SQUARE:");
\r
58 if(psStick.pressed(PSPNx::SQUARE))
\r
60 lcd.putf("s", "Pressed ");
\r
63 if(psStick.held(PSPNx::SQUARE))
\r
65 lcd.putf("s", "Held ");
\r
68 if(psStick.released(PSPNx::SQUARE))
\r
70 lcd.putf("s", "Released");
\r