OSDN Git Service

Update samples to nxtOSEK_v212.zip (I did not check their licenses.)
[nxt-jsp/etrobo-atk.git] / nxtOSEK / samples_c++ / cpp / BluetoothGamePad / sample.cpp
1 /* sample.cpp for TOPPERS/ATK(OSEK) */\r
2 \r
3 // ECRobot++ API\r
4 #include "Clock.h"\r
5 #include "Lcd.h"\r
6 #include "Nxt.h"\r
7 #include "Vector.h"\r
8 #include "GamePad.h" // GamePad class for NXT GamePad\r
9 #include "Bluetooth.h"\r
10 #include "BTConnection.h"\r
11 using namespace ecrobot;\r
12 \r
13 Bluetooth bt;\r
14 \r
15 static const CHAR* PASSKEY = "1234";\r
16 \r
17 extern "C"\r
18 {\r
19 #include "kernel.h"\r
20 #include "kernel_id.h"\r
21 #include "ecrobot_interface.h"\r
22 \r
23 /* nxtOSEK hook to be invoked from an ISR in category 2 */\r
24 void user_1ms_isr_type2(void){}\r
25 \r
26 TASK(TaskMain)\r
27 {\r
28         Clock clock;\r
29         Lcd lcd;\r
30         Nxt nxt;\r
31         BTConnection btConnection(bt, lcd, nxt);\r
32 \r
33         if (btConnection.connect(PASSKEY) == 1)\r
34         {\r
35                 GamePad gp(bt);\r
36                 VectorT<S8> command;\r
37                 lcd.clear();\r
38                 lcd.putf("s", "GamePad");\r
39                 while(1)\r
40                 {\r
41                         command = gp.get(); // receive command from GamePad\r
42                         lcd.clearRow(1); // clear data buffer at row 1\r
43                         lcd.putf("dd", command.mX,0, command.mY,5);\r
44                         lcd.disp();\r
45 \r
46                         clock.wait(50);\r
47                 }\r
48         }\r
49         while(1);\r
50 }\r
51 }\r