OSDN Git Service

lejos_NXJ_win32_0_5_0beta.zip
[nxt-jsp/lejos_nxj.git] / nxtOSEK / lejos_nxj / src / java / classes / lejos / nxt / RCXMotorMultiplexer.java
diff --git a/nxtOSEK/lejos_nxj/src/java/classes/lejos/nxt/RCXMotorMultiplexer.java b/nxtOSEK/lejos_nxj/src/java/classes/lejos/nxt/RCXMotorMultiplexer.java
new file mode 100644 (file)
index 0000000..c3be147
--- /dev/null
@@ -0,0 +1,42 @@
+package lejos.nxt;\r
+\r
+/**\r
+ * Supports the mindsensors RCX Motor Multiplexer\r
+ * \r
+ * @author Lawrie Griffiths\r
+ *\r
+ */\r
+public class RCXMotorMultiplexer extends I2CSensor {\r
+       private byte[] buf = new byte[1];\r
+       \r
+       public RCXMotor A = new RCXMotor(new RCXPlexedMotorPort(this,0));\r
+       public RCXMotor B = new RCXMotor(new RCXPlexedMotorPort(this,1));\r
+       public RCXMotor C = new RCXMotor(new RCXPlexedMotorPort(this,2));\r
+       public RCXMotor D = new RCXMotor(new RCXPlexedMotorPort(this,3));\r
+       \r
+       \r
+       public RCXMotorMultiplexer(I2CPort port) {\r
+               super(port);\r
+               setAddress(0x5A);\r
+       }\r
+       \r
+       public void setSpeed(int speed, int id) {\r
+               buf[0] = (byte) speed;\r
+               sendData(0x43 + (id*2), buf, 1);\r
+       }\r
+       \r
+       public int getSpeed(int id) {\r
+               getData(0x43 + (id*2), buf, 1);\r
+           return buf[0] & 0xFF;\r
+       }\r
+       \r
+       public void setDirection(int direction, int id) {\r
+               buf[0] = (byte) direction;\r
+               sendData(0x42 + (id*2), buf, 1);\r
+       }\r
+       \r
+       public int getDirection(int id) {\r
+               getData(0x42 + (id*2), buf, 1);\r
+           return buf[0] & 0xFF;\r
+       }\r
+}\r