AI2 Component  (Version nb184)
LegoMindstormsNxtBase.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2009-2011 Google, All Rights reserved
3 // Copyright 2011-2012 MIT, All rights reserved
4 // Released under the Apache License, Version 2.0
5 // http://www.apache.org/licenses/LICENSE-2.0
6 
7 package com.google.appinventor.components.runtime;
8 
15 
16 import android.util.Log;
17 
18 import java.io.UnsupportedEncodingException;
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.Map;
22 
28 @SimpleObject
30  implements BluetoothConnectionListener, Component, Deleteable {
31  private static final int TOY_ROBOT = 0x0804; // from android.bluetooth.BluetoothClass.Device.
32 
33  private static final Map<Integer, String> ERROR_MESSAGES;
34  static {
35  ERROR_MESSAGES = new HashMap<Integer, String>();
36  ERROR_MESSAGES.put(0x20, "Pending communication transaction in progress");
37  ERROR_MESSAGES.put(0x40, "Specified mailbox queue is empty");
38  ERROR_MESSAGES.put(0x81, "No more handles");
39  ERROR_MESSAGES.put(0x82, "No space");
40  ERROR_MESSAGES.put(0x83, "No more files");
41  ERROR_MESSAGES.put(0x84, "End of file expected");
42  ERROR_MESSAGES.put(0x85, "End of file");
43  ERROR_MESSAGES.put(0x86, "Not a linear file");
44  ERROR_MESSAGES.put(0x87, "File not found");
45  ERROR_MESSAGES.put(0x88, "Handle already closed");
46  ERROR_MESSAGES.put(0x89, "No linear space");
47  ERROR_MESSAGES.put(0x8A, "Undefined error");
48  ERROR_MESSAGES.put(0x8B, "File is busy");
49  ERROR_MESSAGES.put(0x8C, "No write buffers");
50  ERROR_MESSAGES.put(0x8D, "Append not possible");
51  ERROR_MESSAGES.put(0x8E, "File is full");
52  ERROR_MESSAGES.put(0x8F, "File exists");
53  ERROR_MESSAGES.put(0x90, "Module not found");
54  ERROR_MESSAGES.put(0x91, "Out of boundary");
55  ERROR_MESSAGES.put(0x92, "Illegal file name");
56  ERROR_MESSAGES.put(0x93, "Illegal handle");
57  ERROR_MESSAGES.put(0xBD, "Request failed (i.e. specified file not found)");
58  ERROR_MESSAGES.put(0xBE, "Unknown command opcode");
59  ERROR_MESSAGES.put(0xBF, "Insane packet");
60  ERROR_MESSAGES.put(0xC0, "Data contains out-of-range values");
61  ERROR_MESSAGES.put(0xDD, "Communication bus error");
62  ERROR_MESSAGES.put(0xDE, "No free memory in communication buffer");
63  ERROR_MESSAGES.put(0xDF, "Specified channel/connection is not valid");
64  ERROR_MESSAGES.put(0xE0, "Specified channel/connection not configured or busy");
65  ERROR_MESSAGES.put(0xEC, "No active program");
66  ERROR_MESSAGES.put(0xED, "Illegal size specified");
67  ERROR_MESSAGES.put(0xEE, "Illegal mailbox queue ID specified");
68  ERROR_MESSAGES.put(0xEF, "Attempted to access invalid field of a structure");
69  ERROR_MESSAGES.put(0xF0, "Bad input or output specified");
70  ERROR_MESSAGES.put(0xFB, "Insufficient memory available");
71  ERROR_MESSAGES.put(0xFF, "Bad arguments");
72  }
73 
74  protected final String logTag;
75 
76  // TODO(lizlooney) - allow communication via USB if possible.
78 
79 
83  protected LegoMindstormsNxtBase(ComponentContainer container, String logTag) {
84  super(container.$form());
85  this.logTag = logTag;
86  }
87 
91  protected LegoMindstormsNxtBase() {
92  super(null);
93  logTag = null;
94  }
95 
99  public final void Initialize() {
100  }
101 
106  description = "The BluetoothClient component that should be used for communication.",
107  category = PropertyCategory.BEHAVIOR, userVisible = false)
109  return bluetooth;
110  }
111 
117  defaultValue = "")
118  @SimpleProperty(userVisible = false)
119  public void BluetoothClient(BluetoothClient bluetoothClient) {
120  if (bluetooth != null) {
121  bluetooth.removeBluetoothConnectionListener(this);
122  bluetooth.detachComponent(this);
123  bluetooth = null;
124  }
125 
126  if (bluetoothClient != null) {
127  bluetooth = bluetoothClient;
128  bluetooth.attachComponent(this, Collections.singleton(TOY_ROBOT));
129  bluetooth.addBluetoothConnectionListener(this);
130  if (bluetooth.IsConnected()) {
131  // We missed the real afterConnect event.
133  }
134  }
135  }
136 
137  protected final void setOutputState(String functionName, int port, int power, int mode,
138  int regulationMode, int turnRatio, int runState, long tachoLimit) {
139  power = sanitizePower(power);
140  byte[] command = new byte[12];
141  command[0] = (byte) 0x80; // Direct command telegram, no response
142  command[1] = (byte) 0x04; // SETOUTPUTSTATE command
143  copyUBYTEValueToBytes(port, command, 2);
144  copySBYTEValueToBytes(power, command, 3);
145  copyUBYTEValueToBytes(mode, command, 4);
146  copyUBYTEValueToBytes(regulationMode, command, 5);
147  copySBYTEValueToBytes(turnRatio, command, 6);
148  copyUBYTEValueToBytes(runState, command, 7);
149  // NOTE(lizlooney) - the LEGO MINDSTORMS NXT Direct Commands documentation (AKA Appendix 2)
150  // says to use bytes 8-12 for the ULONG tacho limit. That's 5 bytes!
151  // I've tested sending a 5th byte and it is ignored. Paul Gyugyi confirmed that the code for
152  // the NXT firmware only uses 4 bytes. I'm pretty sure the documentation was supposed to say
153  // bytes 8-11.
154  copyULONGValueToBytes(tachoLimit, command, 8);
155  sendCommand(functionName, command);
156  }
157 
158  protected final void setInputMode(String functionName, int port, int sensorType, int sensorMode) {
159  byte[] command = new byte[5];
160  command[0] = (byte) 0x80; // Direct command telegram, no response
161  command[1] = (byte) 0x05; // SETINPUTMODE command
162  copyUBYTEValueToBytes(port, command, 2);
163  copyUBYTEValueToBytes(sensorType, command, 3);
164  copyUBYTEValueToBytes(sensorMode, command, 4);
165  sendCommand(functionName, command);
166  }
167 
168  protected final byte[] getInputValues(String functionName, int port) {
169  byte[] command = new byte[3];
170  command[0] = (byte) 0x00; // Direct command telegram, response required
171  command[1] = (byte) 0x07; // GETINPUTVALUES command
172  copyUBYTEValueToBytes(port, command, 2);
173  byte[] returnPackage = sendCommandAndReceiveReturnPackage(functionName, command);
174  if (evaluateStatus(functionName, returnPackage, command[1])) {
175  if (returnPackage.length == 16) {
176  return returnPackage;
177  } else {
178  Log.w(logTag, functionName + ": unexpected return package length " +
179  returnPackage.length + " (expected 16)");
180  }
181  }
182  return null;
183  }
184 
185  protected final void resetInputScaledValue(String functionName, int port) {
186  byte[] command = new byte[3];
187  command[0] = (byte) 0x80; // Direct command telegram, no response
188  command[1] = (byte) 0x08; // RESETINPUTSCALEDVALUE command
189  copyUBYTEValueToBytes(port, command, 2);
190  sendCommand(functionName, command);
191  }
192 
193  protected final int lsGetStatus(String functionName, int port) {
194  byte[] command = new byte[3];
195  command[0] = (byte) 0x00; // Direct command telegram, response required
196  command[1] = (byte) 0x0E; // LSGETSTATUS command
197  copyUBYTEValueToBytes(port, command, 2);
198  byte[] returnPackage = sendCommandAndReceiveReturnPackage(functionName, command);
199  if (evaluateStatus(functionName, returnPackage, command[1])) {
200  if (returnPackage.length == 4) {
201  return getUBYTEValueFromBytes(returnPackage, 3);
202  } else {
203  Log.w(logTag, functionName + ": unexpected return package length " +
204  returnPackage.length + " (expected 4)");
205  }
206  }
207  return 0;
208  }
209 
210  protected final void lsWrite(String functionName, int port, byte[] data, int rxDataLength) {
211  if (data.length > 16) {
212  throw new IllegalArgumentException("length must be <= 16");
213  }
214  byte[] command = new byte[5 + data.length];
215  command[0] = (byte) 0x00; // Direct command telegram, response required
216  command[1] = (byte) 0x0F; // LSWRITE command
217  copyUBYTEValueToBytes(port, command, 2);
218  copyUBYTEValueToBytes(data.length, command, 3);
219  copyUBYTEValueToBytes(rxDataLength, command, 4);
220  System.arraycopy(data, 0, command, 5, data.length);
221  byte[] returnPackage = sendCommandAndReceiveReturnPackage(functionName, command);
222  evaluateStatus(functionName, returnPackage, command[1]);
223  }
224 
225  protected final byte[] lsRead(String functionName, int port) {
226  byte[] command = new byte[3];
227  command[0] = (byte) 0x00; // Direct command telegram, response required
228  command[1] = (byte) 0x10; // LSREAD command
229  copyUBYTEValueToBytes(port, command, 2);
230  byte[] returnPackage = sendCommandAndReceiveReturnPackage(functionName, command);
231  if (evaluateStatus(functionName, returnPackage, command[1])) {
232  if (returnPackage.length == 20) {
233  return returnPackage;
234  } else {
235  Log.w(logTag, functionName + ": unexpected return package length " +
236  returnPackage.length + " (expected 20)");
237  }
238  }
239  return null;
240  }
241 
242 
243  /*
244  * Checks whether the bluetooth property has been set or whether this
245  * component is connected to a robot and, if necessary, dispatches the
246  * appropriate error.
247  *
248  * Returns true if everything is ok, false if there was an error.
249  */
250  protected final boolean checkBluetooth(String functionName) {
251  if (bluetooth == null) {
252  form.dispatchErrorOccurredEvent(this, functionName,
254  return false;
255  }
256  if (!bluetooth.IsConnected()) {
257  form.dispatchErrorOccurredEvent(this, functionName,
259  return false;
260  }
261  return true;
262  }
263 
264  protected final byte[] sendCommandAndReceiveReturnPackage(String functionName, byte[] command) {
265  sendCommand(functionName, command);
266  return receiveReturnPackage(functionName);
267  }
268 
269  protected final void sendCommand(String functionName, byte[] command) {
270  byte[] header = new byte[2];
271  copyUWORDValueToBytes(command.length, header, 0);
272  bluetooth.write(functionName, header);
273  bluetooth.write(functionName, command);
274  }
275 
276  private byte[] receiveReturnPackage(String functionName) {
277  byte[] header = bluetooth.read(functionName, 2);
278  if (header.length == 2) {
279  int length = getUWORDValueFromBytes(header, 0);
280  byte[] returnPackage = bluetooth.read(functionName, length);
281  if (returnPackage.length >= 3) {
282  return returnPackage;
283  }
284  }
285 
286  form.dispatchErrorOccurredEvent(this, functionName,
287  ErrorMessages.ERROR_NXT_INVALID_RETURN_PACKAGE);
288  return new byte[0];
289  }
290 
291  protected final boolean evaluateStatus(String functionName, byte[] returnPackage, byte command) {
292  int status = getStatus(functionName, returnPackage, command);
293  if (status == 0) {
294  return true;
295  } else {
296  handleError(functionName, status);
297  return false;
298  }
299  }
300 
301  protected final int getStatus(String functionName, byte[] returnPackage, byte command) {
302  if (returnPackage.length >= 3) {
303  if (returnPackage[0] != (byte) 0x02) {
304  Log.w(logTag, functionName + ": unexpected return package byte 0: 0x" +
305  Integer.toHexString(returnPackage[0] & 0xFF) + " (expected 0x02)");
306  }
307  if (returnPackage[1] != command) {
308  Log.w(logTag, functionName + ": unexpected return package byte 1: 0x" +
309  Integer.toHexString(returnPackage[1] & 0xFF) + " (expected 0x" +
310  Integer.toHexString(command & 0xFF) + ")");
311  }
312  return getUBYTEValueFromBytes(returnPackage, 2);
313  } else {
314  Log.w(logTag, functionName + ": unexpected return package length " +
315  returnPackage.length + " (expected >= 3)");
316  }
317  return -1;
318  }
319 
320  private void handleError(String functionName, int status) {
321  if (status < 0) {
322  // Real status bytes received from the NXT are unsigned.
323  // -1 is returned from getStatus when the returnPackage is not even big enough to contain a
324  // status byte. In that case, we've already called form.dispatchErrorOccurredEvent from
325  // receiveReturnPackage.
326  } else {
327  String errorMessage = ERROR_MESSAGES.get(status);
328  if (errorMessage != null) {
329  form.dispatchErrorOccurredEvent(this, functionName,
330  ErrorMessages.ERROR_NXT_ERROR_CODE_RECEIVED, errorMessage);
331  } else {
332  form.dispatchErrorOccurredEvent(this, functionName,
333  ErrorMessages.ERROR_NXT_ERROR_CODE_RECEIVED,
334  "Error code 0x" + Integer.toHexString(status & 0xFF));
335  }
336  }
337  }
338 
339  protected final void copyBooleanValueToBytes(boolean value, byte[] bytes, int offset) {
340  bytes[offset] = value ? (byte) 1 : (byte) 0;
341  }
342 
343  protected final void copySBYTEValueToBytes(int value, byte[] bytes, int offset) {
344  bytes[offset] = (byte) value;
345  }
346 
347  protected final void copyUBYTEValueToBytes(int value, byte[] bytes, int offset) {
348  bytes[offset] = (byte) value;
349  }
350 
351  protected final void copySWORDValueToBytes(int value, byte[] bytes, int offset) {
352  bytes[offset] = (byte) (value & 0xff);
353  value = value >> 8;
354  bytes[offset + 1] = (byte) (value & 0xff);
355  }
356 
357  protected final void copyUWORDValueToBytes(int value, byte[] bytes, int offset) {
358  bytes[offset] = (byte) (value & 0xff);
359  value = value >> 8;
360  bytes[offset + 1] = (byte) (value & 0xff);
361  }
362 
363  protected final void copySLONGValueToBytes(int value, byte[] bytes, int offset) {
364  bytes[offset] = (byte) (value & 0xff);
365  value = value >> 8;
366  bytes[offset + 1] = (byte) (value & 0xff);
367  value = value >> 8;
368  bytes[offset + 2] = (byte) (value & 0xff);
369  value = value >> 8;
370  bytes[offset + 3] = (byte) (value & 0xff);
371  }
372 
373  protected final void copyULONGValueToBytes(long value, byte[] bytes, int offset) {
374  bytes[offset] = (byte) (value & 0xff);
375  value = value >> 8;
376  bytes[offset + 1] = (byte) (value & 0xff);
377  value = value >> 8;
378  bytes[offset + 2] = (byte) (value & 0xff);
379  value = value >> 8;
380  bytes[offset + 3] = (byte) (value & 0xff);
381  }
382 
383  protected final void copyStringValueToBytes(String value, byte[] bytes, int offset,
384  int maxCount) {
385  if (value.length() > maxCount) {
386  value = value.substring(0, maxCount);
387  }
388  byte[] valueBytes;
389  try {
390  valueBytes = value.getBytes("ISO-8859-1");
391  } catch (UnsupportedEncodingException e) {
392  Log.w(logTag, "UnsupportedEncodingException: " + e.getMessage());
393  valueBytes = value.getBytes();
394  }
395  int lengthToCopy = Math.min(maxCount, valueBytes.length);
396  System.arraycopy(valueBytes, 0, bytes, offset, lengthToCopy);
397  }
398 
399  protected final boolean getBooleanValueFromBytes(byte[] bytes, int offset) {
400  return bytes[offset] != 0;
401  }
402 
403  protected final int getSBYTEValueFromBytes(byte[] bytes, int offset) {
404  return bytes[offset];
405  }
406 
407  protected final int getUBYTEValueFromBytes(byte[] bytes, int offset) {
408  return bytes[offset] & 0xFF;
409  }
410 
411  protected final int getSWORDValueFromBytes(byte[] bytes, int offset) {
412  return (bytes[offset] & 0xFF) |
413  (bytes[offset + 1] << 8);
414  }
415 
416  protected final int getUWORDValueFromBytes(byte[] bytes, int offset) {
417  return (bytes[offset] & 0xFF) |
418  ((bytes[offset + 1] & 0xFF) << 8);
419  }
420 
421  protected final int getSLONGValueFromBytes(byte[] bytes, int offset) {
422  return (bytes[offset] & 0xFF) |
423  ((bytes[offset + 1] & 0xFF) << 8) |
424  ((bytes[offset + 2] & 0xFF) << 16) |
425  (bytes[offset + 3] << 24);
426  }
427 
428  protected final long getULONGValueFromBytes(byte[] bytes, int offset) {
429  return (bytes[offset] & 0xFFL) |
430  ((bytes[offset + 1] & 0xFFL) << 8) |
431  ((bytes[offset + 2] & 0xFFL) << 16) |
432  ((bytes[offset + 3] & 0xFFL) << 24);
433  }
434 
435  protected final String getStringValueFromBytes(byte[] bytes, int offset) {
436  // Determine length by looking for the null termination byte.
437  int length = 0;
438  for (int i = offset; i < bytes.length; i++) {
439  if (bytes[i] == 0) {
440  length = i - offset;
441  break;
442  }
443  }
444  return getStringValueFromBytes(bytes, offset, length);
445  }
446 
447  protected final String getStringValueFromBytes(byte[] bytes, int offset, int count) {
448  try {
449  return new String(bytes, offset, count, "ISO-8859-1");
450  } catch (UnsupportedEncodingException e) {
451  Log.w(logTag, "UnsupportedEncodingException: " + e.getMessage());
452  return new String(bytes, offset, count);
453  }
454  }
455 
456  protected final int convertMotorPortLetterToNumber(String motorPortLetter) {
457  if (motorPortLetter.length() == 1) {
458  return convertMotorPortLetterToNumber(motorPortLetter.charAt(0));
459  }
460  throw new IllegalArgumentException("Illegal motor port letter " + motorPortLetter);
461  }
462 
463  protected final int convertMotorPortLetterToNumber(char motorPortLetter) {
464  if (motorPortLetter == 'A' || motorPortLetter == 'a') {
465  return 0;
466  } else if (motorPortLetter == 'B' || motorPortLetter == 'b') {
467  return 1;
468  } else if (motorPortLetter == 'C' || motorPortLetter == 'c') {
469  return 2;
470  }
471  throw new IllegalArgumentException("Illegal motor port letter " + motorPortLetter);
472  }
473 
474  protected final int convertSensorPortLetterToNumber(String sensorPortLetter) {
475  if (sensorPortLetter.length() == 1) {
476  return convertSensorPortLetterToNumber(sensorPortLetter.charAt(0));
477  }
478  throw new IllegalArgumentException("Illegal sensor port letter " + sensorPortLetter);
479  }
480 
481  protected final int convertSensorPortLetterToNumber(char sensorPortLetter) {
482  if (sensorPortLetter == '1') {
483  return 0;
484  } else if (sensorPortLetter == '2') {
485  return 1;
486  } else if (sensorPortLetter == '3') {
487  return 2;
488  } else if (sensorPortLetter == '4') {
489  return 3;
490  }
491  throw new IllegalArgumentException("Illegal sensor port letter " + sensorPortLetter);
492  }
493 
494  protected final int sanitizePower(int power) {
495  if (power < -100) {
496  Log.w(logTag, "power " + power + " is invalid, using -100.");
497  power = -100;
498  }
499  if (power > 100) {
500  Log.w(logTag, "power " + power + " is invalid, using 100.");
501  power = 100;
502  }
503  return power;
504  }
505 
506  protected final int sanitizeTurnRatio(int turnRatio) {
507  if (turnRatio < -100) {
508  Log.w(logTag, "turnRatio " + turnRatio + " is invalid, using -100.");
509  turnRatio = -100;
510  }
511  if (turnRatio > 100) {
512  Log.w(logTag, "turnRatio " + turnRatio + " is invalid, using 100.");
513  turnRatio = 100;
514  }
515  return turnRatio;
516  }
517 
518  // BluetoothConnectionListener implementation
519 
520  @Override
521  public void afterConnect(BluetoothConnectionBase bluetoothConnection) {
522  // Subclasses may wish to do something.
523  }
524 
525  @Override
526  public void beforeDisconnect(BluetoothConnectionBase bluetoothConnection) {
527  // Subclasses may wish to do something.
528  }
529 
530  // Deleteable implementation
531 
532  @Override
533  public void onDelete() {
534  if (bluetooth != null) {
535  bluetooth.removeBluetoothConnectionListener(this);
536  bluetooth.detachComponent(this);
537  bluetooth = null;
538  }
539  }
540 }
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getStatus
final int getStatus(String functionName, byte[] returnPackage, byte command)
Definition: LegoMindstormsNxtBase.java:301
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.Initialize
final void Initialize()
Definition: LegoMindstormsNxtBase.java:99
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getSWORDValueFromBytes
final int getSWORDValueFromBytes(byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:411
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.lsGetStatus
final int lsGetStatus(String functionName, int port)
Definition: LegoMindstormsNxtBase.java:193
com.google.appinventor.components.runtime.BluetoothConnectionBase.write
void write(String functionName, byte b)
Definition: BluetoothConnectionBase.java:513
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.copySWORDValueToBytes
final void copySWORDValueToBytes(int value, byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:351
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.onDelete
void onDelete()
Definition: LegoMindstormsNxtBase.java:533
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.evaluateStatus
final boolean evaluateStatus(String functionName, byte[] returnPackage, byte command)
Definition: LegoMindstormsNxtBase.java:291
com.google.appinventor.components.runtime.util.ErrorMessages
Definition: ErrorMessages.java:17
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getStringValueFromBytes
final String getStringValueFromBytes(byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:435
com.google.appinventor.components.runtime.util
-*- mode: java; c-basic-offset: 2; -*-
Definition: AccountChooser.java:7
com.google.appinventor.components.annotations.DesignerProperty
Definition: DesignerProperty.java:25
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.bluetooth
BluetoothClient bluetooth
Definition: LegoMindstormsNxtBase.java:77
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getSBYTEValueFromBytes
final int getSBYTEValueFromBytes(byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:403
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.copySBYTEValueToBytes
final void copySBYTEValueToBytes(int value, byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:343
com.google.appinventor.components
com.google.appinventor.components.runtime.BluetoothConnectionBase.IsConnected
final boolean IsConnected()
Definition: BluetoothConnectionBase.java:204
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.lsRead
final byte[] lsRead(String functionName, int port)
Definition: LegoMindstormsNxtBase.java:225
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.beforeDisconnect
void beforeDisconnect(BluetoothConnectionBase bluetoothConnection)
Definition: LegoMindstormsNxtBase.java:526
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.resetInputScaledValue
final void resetInputScaledValue(String functionName, int port)
Definition: LegoMindstormsNxtBase.java:185
com.google.appinventor.components.annotations.PropertyCategory.BEHAVIOR
BEHAVIOR
Definition: PropertyCategory.java:15
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.copyUBYTEValueToBytes
final void copyUBYTEValueToBytes(int value, byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:347
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.lsWrite
final void lsWrite(String functionName, int port, byte[] data, int rxDataLength)
Definition: LegoMindstormsNxtBase.java:210
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getUBYTEValueFromBytes
final int getUBYTEValueFromBytes(byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:407
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.logTag
final String logTag
Definition: LegoMindstormsNxtBase.java:74
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.copyULONGValueToBytes
final void copyULONGValueToBytes(long value, byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:373
com.google.appinventor.components.common.PropertyTypeConstants.PROPERTY_TYPE_BLUETOOTHCLIENT
static final String PROPERTY_TYPE_BLUETOOTHCLIENT
Definition: PropertyTypeConstants.java:28
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.sendCommand
final void sendCommand(String functionName, byte[] command)
Definition: LegoMindstormsNxtBase.java:269
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getSLONGValueFromBytes
final int getSLONGValueFromBytes(byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:421
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getInputValues
final byte[] getInputValues(String functionName, int port)
Definition: LegoMindstormsNxtBase.java:168
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.setOutputState
final void setOutputState(String functionName, int port, int power, int mode, int regulationMode, int turnRatio, int runState, long tachoLimit)
Definition: LegoMindstormsNxtBase.java:137
com.google.appinventor.components.runtime.AndroidNonvisibleComponent
Definition: AndroidNonvisibleComponent.java:17
com.google.appinventor.components.runtime.BluetoothClient
Definition: BluetoothClient.java:49
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.LegoMindstormsNxtBase
LegoMindstormsNxtBase()
Definition: LegoMindstormsNxtBase.java:91
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.copyBooleanValueToBytes
final void copyBooleanValueToBytes(boolean value, byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:339
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.convertMotorPortLetterToNumber
final int convertMotorPortLetterToNumber(String motorPortLetter)
Definition: LegoMindstormsNxtBase.java:456
com.google.appinventor.components.annotations.SimpleProperty
Definition: SimpleProperty.java:23
com.google.appinventor.components.runtime.BluetoothConnectionBase
Definition: BluetoothConnectionBase.java:41
com.google.appinventor.components.annotations.PropertyCategory
Definition: PropertyCategory.java:13
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.convertSensorPortLetterToNumber
final int convertSensorPortLetterToNumber(String sensorPortLetter)
Definition: LegoMindstormsNxtBase.java:474
com.google.appinventor.components.runtime.ComponentContainer
Definition: ComponentContainer.java:16
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.convertSensorPortLetterToNumber
final int convertSensorPortLetterToNumber(char sensorPortLetter)
Definition: LegoMindstormsNxtBase.java:481
com.google.appinventor.components.runtime.Component
Definition: Component.java:17
com.google.appinventor.components.runtime.Map< Integer, String >
com.google.appinventor.components.runtime.Deleteable
Definition: Deleteable.java:15
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.convertMotorPortLetterToNumber
final int convertMotorPortLetterToNumber(char motorPortLetter)
Definition: LegoMindstormsNxtBase.java:463
com.google.appinventor.components.runtime.LegoMindstormsNxtBase
Definition: LegoMindstormsNxtBase.java:29
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.sendCommandAndReceiveReturnPackage
final byte[] sendCommandAndReceiveReturnPackage(String functionName, byte[] command)
Definition: LegoMindstormsNxtBase.java:264
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.checkBluetooth
final boolean checkBluetooth(String functionName)
Definition: LegoMindstormsNxtBase.java:250
com.google.appinventor.components.runtime.Form.dispatchErrorOccurredEvent
void dispatchErrorOccurredEvent(final Component component, final String functionName, final int errorNumber, final Object... messageArgs)
Definition: Form.java:1011
com.google.appinventor.components.annotations.SimpleObject
Definition: SimpleObject.java:23
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getBooleanValueFromBytes
final boolean getBooleanValueFromBytes(byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:399
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getUWORDValueFromBytes
final int getUWORDValueFromBytes(byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:416
com.google
com
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_NXT_NOT_CONNECTED_TO_ROBOT
static final int ERROR_NXT_NOT_CONNECTED_TO_ROBOT
Definition: ErrorMessages.java:51
com.google.appinventor.components.runtime.BluetoothConnectionBase.read
final byte[] read(String functionName, int numberOfBytes)
Definition: BluetoothConnectionBase.java:778
com.google.appinventor.components.runtime.ComponentContainer.$form
Form $form()
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.sanitizeTurnRatio
final int sanitizeTurnRatio(int turnRatio)
Definition: LegoMindstormsNxtBase.java:506
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.setInputMode
final void setInputMode(String functionName, int port, int sensorType, int sensorMode)
Definition: LegoMindstormsNxtBase.java:158
com.google.appinventor.components.runtime.AndroidNonvisibleComponent.form
final Form form
Definition: AndroidNonvisibleComponent.java:19
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getStringValueFromBytes
final String getStringValueFromBytes(byte[] bytes, int offset, int count)
Definition: LegoMindstormsNxtBase.java:447
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.copyStringValueToBytes
final void copyStringValueToBytes(String value, byte[] bytes, int offset, int maxCount)
Definition: LegoMindstormsNxtBase.java:383
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.copyUWORDValueToBytes
final void copyUWORDValueToBytes(int value, byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:357
com.google.appinventor.components.common.PropertyTypeConstants
Definition: PropertyTypeConstants.java:14
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.copySLONGValueToBytes
final void copySLONGValueToBytes(int value, byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:363
com.google.appinventor.components.annotations
com.google.appinventor
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_NXT_BLUETOOTH_NOT_SET
static final int ERROR_NXT_BLUETOOTH_NOT_SET
Definition: ErrorMessages.java:50
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.afterConnect
void afterConnect(BluetoothConnectionBase bluetoothConnection)
Definition: LegoMindstormsNxtBase.java:521
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.LegoMindstormsNxtBase
LegoMindstormsNxtBase(ComponentContainer container, String logTag)
Definition: LegoMindstormsNxtBase.java:83
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.getULONGValueFromBytes
final long getULONGValueFromBytes(byte[] bytes, int offset)
Definition: LegoMindstormsNxtBase.java:428
com.google.appinventor.components.runtime.LegoMindstormsNxtBase.sanitizePower
final int sanitizePower(int power)
Definition: LegoMindstormsNxtBase.java:494