OSDN Git Service

lejos_NXJ_win32_0_5_0beta.zip
[nxt-jsp/lejos_nxj.git] / nxtOSEK / lejos_nxj / src / java / classes / lejos / nxt / IRSeeker.java
1 package lejos.nxt;\r
2 \r
3 /**\r
4  * HiTechnic IRSeeker sensor - untested.\r
5  * www.hitechnic.com\r
6  */\r
7 public class IRSeeker extends I2CSensor {\r
8         byte[] buf = new byte[1];\r
9         \r
10         public IRSeeker(I2CPort port)\r
11         {\r
12                 super(port);\r
13         }\r
14         \r
15         /**\r
16          * Returns the direction of the target (1-9)\r
17          * or zero if no target. \r
18          * \r
19          * @return direction\r
20          */\r
21         public int getDirection() {\r
22                 int ret = getData(0x42, buf, 1);\r
23                 if(ret != 0) return -1;\r
24                 return (0xFF & buf[0]);\r
25         }\r
26         \r
27         /**\r
28          * Returns value of sensor 1 - 5.\r
29          * \r
30          * @return sensor value (0 to 255).\r
31          */\r
32         public int getSensorValue(int id) {\r
33                 if (id <= 0 || id > 5) return -1;\r
34                 int ret = getData(0x42 + id, buf, 1);\r
35                 if(ret != 0) return -1;\r
36                 return (0xFF & buf[0]);\r
37         }\r
38 }\r