OSDN Git Service

Remove liblejososek.a dependency as it is obsolete.
[nxt-jsp/etrobo-atk.git] / nxtOSEK / samples_c++ / cpp / PSPNx / sample.cpp
1 /* sample.cpp for TOPPERS/ATK(OSEK) */\r
2 \r
3 // ECRobot++ API\r
4 #include "PSPNx.h"\r
5 #include "Lcd.h"\r
6 #include "Clock.h"\r
7 using namespace ecrobot;\r
8 \r
9 extern "C"\r
10 {\r
11 #include "kernel.h"\r
12 #include "kernel_id.h"\r
13 #include "ecrobot_interface.h"\r
14 \r
15 PSPNx psStick(PORT_1);\r
16 \r
17 // nxtOSEK hook to be invoked from an ISR in category 2\r
18 void user_1ms_isr_type2(void)\r
19 {\r
20         SleeperMonitor(); // needed for I2C device and Clock classes\r
21 }\r
22 \r
23 TASK(TaskMain)\r
24 {\r
25         Clock clock;\r
26         Lcd lcd;\r
27 \r
28         while(1)\r
29         {\r
30                 U8 rawData[PSPNx::DATA_BUFFER_BYTE_SIZE];\r
31 \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
35                 psStick.update();\r
36 \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
40             //flip the bits\r
41             rawDigitalPad ^= 0xffff;\r
42 \r
43                 lcd.clear();\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
46             {\r
47                 //quick and dirty way to display each bit's status\r
48                 lcd.putf("d", ((rawDigitalPad & (1 << i))? 1 : 0),0);\r
49             }\r
50 \r
51             //display the analog stick data\r
52             lcd.cursor(0,1);\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
55 \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
59             {\r
60                 lcd.putf("s", "Pressed ");\r
61             }\r
62 \r
63             if(psStick.held(PSPNx::SQUARE))\r
64             {\r
65                 lcd.putf("s", "Held    ");\r
66             }\r
67 \r
68             if(psStick.released(PSPNx::SQUARE))\r
69             {\r
70                 lcd.putf("s", "Released");\r
71             }\r
72 \r
73             lcd.disp();\r
74             clock.wait(20);\r
75         }\r
76 }\r
77 }\r