6 package com.google.appinventor.components.runtime;
15 import java.util.Collections;
27 private static final int TOY_ROBOT = 0x0804;
33 super(container.
$form());
42 @
SimpleProperty(description =
"The BluetoothClient component that should be used for communication.",
57 bluetooth.removeBluetoothConnectionListener(
this);
62 if (bluetoothClient !=
null) {
64 bluetooth.attachComponent(
this, Collections.singleton(TOY_ROBOT));
65 bluetooth.addBluetoothConnectionListener(
this);
87 protected final byte[]
sendCommand(String functionName,
byte[] command,
boolean doReceiveReply) {
100 if (doReceiveReply) {
103 if (header.length == 4) {
105 int replySize = (int) ((Short) decodedHeader[0]) - 2;
106 int replyCount = (int) ((Short) decodedHeader[1]);
109 if (reply.length == replySize)
127 if (letter.length() != 1)
128 throw new IllegalArgumentException(
"String \"" + letter +
"\" is not a valid sensor port letter");
130 int portNumber = letter.charAt(0) -
'1';
132 if (portNumber < 0 || portNumber > 3)
133 throw new IllegalArgumentException(
"String \"" + letter +
"\" is not a valid sensor port letter");
139 if (portNumber < 0 || portNumber > 3)
140 throw new IllegalArgumentException(portNumber +
" is not a valid port number");
142 return "" + (
'1' + portNumber);
146 if (letters.length() > 4)
147 throw new IllegalArgumentException(
"Malformed motor port letters \"" + letters +
"\"");
154 for (
int i = 0; i < letters.length(); i++)
156 switch (letters.charAt(i))
160 throw new IllegalArgumentException(
"Malformed motor port letters \"" + letters +
"\"");
166 throw new IllegalArgumentException(
"Malformed motor port letters \"" + letters +
"\"");
172 throw new IllegalArgumentException(
"Malformed motor port letters \"" + letters +
"\"");
178 throw new IllegalArgumentException(
"Malformed motor port letters \"" + letters +
"\"");
183 throw new IllegalArgumentException(
"Malformed motor port letters \"" + letters +
"\"");
187 return portABit | portBBit | portCBit | portDBit;
191 if (bitField < 0 || bitField > 15)
192 throw new IllegalArgumentException(
"Invalid bit field number " + bitField);
194 String portLetters =
"";
196 if ((bitField & 1) != 0)
199 if ((bitField & 2) != 0)
202 if ((bitField & 4) != 0)
205 if ((bitField & 8) != 0)
225 bluetooth.removeBluetoothConnectionListener(
this);