OSDN Git Service

lejos_NXJ_win32_0_5_0beta.zip
[nxt-jsp/lejos_nxj.git] / nxtOSEK / lejos_nxj / src / java / classes / lejos / nxt / remote / RemoteBattery.java
1 package lejos.nxt.remote;\r
2 \r
3 import lejos.nxt.comm.*;\r
4 import java.io.*;\r
5 \r
6 /**\r
7  * Battery readings from a remote NXT.\r
8  */\r
9 public class RemoteBattery implements NXTProtocol {\r
10         \r
11         private NXTCommand nxtCommand;\r
12         \r
13         public RemoteBattery(NXTCommand nxtCommand) {\r
14                 this.nxtCommand = nxtCommand;\r
15         }\r
16                 \r
17         /**\r
18          * The NXT uses 6 batteries of 1500 mV each.\r
19          * @return Battery voltage in mV. ~9000 = full.\r
20          */\r
21         public int getVoltageMilliVolt() {\r
22                 /*\r
23              * calculation from LEGO firmware\r
24              */\r
25                 try {\r
26                         return nxtCommand.getBatteryLevel();\r
27                 } catch (IOException ioe) {\r
28                         return 0;\r
29                 }\r
30         }\r
31 \r
32         /**\r
33          * The NXT uses 6 batteries of 1.5 V each.\r
34          * @return Battery voltage in Volt. ~9V = full.\r
35          */\r
36         public float getVoltage() {\r
37            return (float)(getVoltageMilliVolt() * 0.001);\r
38         }\r
39 }\r
40 \r