forked from mit-cml/appinventor-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Nxt option list definitions * Do basic DirectCommands upgrade * Add overloads * Upgrade other Nxt components * Add upgraders * Fix formatting * Add new errors * Pr comments
- Loading branch information
Showing
21 changed files
with
744 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
appinventor/components/src/com/google/appinventor/components/common/NxtMailbox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// -*- mode: java; c-basic-offset: 2; -*- | ||
// Copyright 2020 MIT, All rights reserved | ||
// Released under the Apache License, Version 2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package com.google.appinventor.components.common; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Defines a NxtMailbox type used by the NxtDirectCommands component. | ||
*/ | ||
public enum NxtMailbox implements OptionList<Integer> { | ||
// Note from Paul Gyugyi during code review: we are only supporting mailboxes 1-10, but NXT can | ||
// use mailboxes above 10 as relays to other NXTs. We've never needed it, but if you ever see | ||
// a feature request or bug report, all that might be required is just raising our upper limit | ||
// on the range. | ||
Box1(1, 0), | ||
Box2(2, 1), | ||
Box3(3, 2), | ||
Box4(4, 3), | ||
Box5(5, 4), | ||
Box6(6, 5), | ||
Box7(7, 6), | ||
Box8(8, 7), | ||
Box9(9, 8), | ||
Box10(10, 9); | ||
|
||
private Integer value; | ||
private int intValue; | ||
|
||
NxtMailbox(Integer box, int intBox) { | ||
this.value = box; | ||
this.intValue = intBox; | ||
} | ||
|
||
public Integer toUnderlyingValue() { | ||
return value; | ||
} | ||
|
||
public Integer toInt() { | ||
return intValue; | ||
} | ||
|
||
private static final Map<Integer, NxtMailbox> lookup = new HashMap<>(); | ||
|
||
static { | ||
for (NxtMailbox box : NxtMailbox.values()) { | ||
lookup.put(box.toUnderlyingValue(), box); | ||
} | ||
} | ||
|
||
public static NxtMailbox fromUnderlyingValue(Integer box) { | ||
return lookup.get(box); | ||
} | ||
} | ||
|
48 changes: 48 additions & 0 deletions
48
appinventor/components/src/com/google/appinventor/components/common/NxtMotorMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// -*- mode: java; c-basic-offset: 2; -*- | ||
// Copyright 2020 MIT, All rights reserved | ||
// Released under the Apache License, Version 2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package com.google.appinventor.components.common; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Defines a NxtMotorMode type used by the NxtDirectCommands component. | ||
* | ||
* Info attained from: | ||
* http://kio4.com/b4a/programas/Appendix%202-LEGO%20MINDSTORMS%20NXT%20Direct%20commands.pdf | ||
* http://www.ni.com/pdf/manuals/372574c.pdf | ||
* In combination with the documentation here: | ||
* https://www.mindstorms.rwth-aachen.de/documents/downloads/doc/version-4.07/help/NXT_SetInputMode.html | ||
*/ | ||
public enum NxtMotorMode implements OptionList<Integer> { | ||
On(0x01), | ||
Brake(0x02), // Allows for electronic breaking, which improves accuracy of motor output. | ||
@Default | ||
Regulated(0x04), // Allows regulation based on the regulationMode property. | ||
Coast(0x00); // Motors will rotate freely. | ||
|
||
private int value; | ||
|
||
NxtMotorMode(int mode) { | ||
this.value = mode; | ||
} | ||
|
||
public Integer toUnderlyingValue() { | ||
return value; | ||
} | ||
|
||
private static final Map<Integer, NxtMotorMode> lookup = new HashMap<>(); | ||
|
||
static { | ||
for (NxtMotorMode mode : NxtMotorMode.values()) { | ||
lookup.put(mode.toUnderlyingValue(), mode); | ||
} | ||
} | ||
|
||
public static NxtMotorMode fromUnderlyingValue(Integer mode) { | ||
return lookup.get(mode); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
appinventor/components/src/com/google/appinventor/components/common/NxtMotorPort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// -*- mode: java; c-basic-offset: 2; -*- | ||
// Copyright 2020 MIT, All rights reserved | ||
// Released under the Apache License, Version 2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package com.google.appinventor.components.common; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Defines a NxtMotorPort type used by the NxtDirectCommands component. | ||
*/ | ||
public enum NxtMotorPort implements OptionList<String> { | ||
PortA("A", 0), | ||
PortB("B", 1), | ||
PortC("C", 2); | ||
|
||
private String value; | ||
private int intValue; | ||
|
||
NxtMotorPort(String port, int intPort) { | ||
this.value = port; | ||
this.intValue = intPort; | ||
} | ||
|
||
public String toUnderlyingValue() { | ||
return value; | ||
} | ||
|
||
public Integer toInt() { | ||
return intValue; | ||
} | ||
|
||
private static final Map<String, NxtMotorPort> lookup = new HashMap<>(); | ||
|
||
static { | ||
for(NxtMotorPort port : NxtMotorPort.values()) { | ||
String str = port.toUnderlyingValue(); | ||
lookup.put(str, port); | ||
lookup.put(str.toLowerCase(), port); | ||
} | ||
} | ||
|
||
public static NxtMotorPort fromUnderlyingValue(String port) { | ||
return lookup.get(port); | ||
} | ||
} | ||
|
49 changes: 49 additions & 0 deletions
49
appinventor/components/src/com/google/appinventor/components/common/NxtRegulationMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// -*- mode: java; c-basic-offset: 2; -*- | ||
// Copyright 2020 MIT, All rights reserved | ||
// Released under the Apache License, Version 2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package com.google.appinventor.components.common; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Defines a NxtRegulationMode type used by the NxtDirectCommands component. | ||
* | ||
* Info attained from: | ||
* http://kio4.com/b4a/programas/Appendix%202-LEGO%20MINDSTORMS%20NXT%20Direct%20commands.pdf | ||
* http://www.ni.com/pdf/manuals/372574c.pdf | ||
* In combination with the documentation here: | ||
* https://www.mindstorms.rwth-aachen.de/documents/downloads/doc/version-4.07/help/NXT_SetInputMode.html | ||
* | ||
* Note that this property is only important if the motor mode is set to regulated. | ||
*/ | ||
public enum NxtRegulationMode implements OptionList<Integer> { | ||
Disabled(0x00), // No regulation. | ||
@Default | ||
Speed(0x01), // Speed regulation. | ||
Syncronization(0x02); // Enables motor syncronization. | ||
|
||
private int value; | ||
|
||
NxtRegulationMode(int mode) { | ||
this.value = mode; | ||
} | ||
|
||
public Integer toUnderlyingValue() { | ||
return value; | ||
} | ||
|
||
private static final Map<Integer, NxtRegulationMode> lookup = new HashMap<>(); | ||
|
||
static { | ||
for (NxtRegulationMode mode : NxtRegulationMode.values()) { | ||
lookup.put(mode.toUnderlyingValue(), mode); | ||
} | ||
} | ||
|
||
public static NxtRegulationMode fromUnderlyingValue(Integer mode) { | ||
return lookup.get(mode); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
appinventor/components/src/com/google/appinventor/components/common/NxtRunState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// -*- mode: java; c-basic-offset: 2; -*- | ||
// Copyright 2020 MIT, All rights reserved | ||
// Released under the Apache License, Version 2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package com.google.appinventor.components.common; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Defines a NxtRunState type used by the NxtDirectCommands component. | ||
* | ||
* Info attained from: | ||
* http://kio4.com/b4a/programas/Appendix%202-LEGO%20MINDSTORMS%20NXT%20Direct%20commands.pdf | ||
* http://www.ni.com/pdf/manuals/372574c.pdf | ||
* In combination with the documentation here: | ||
* https://www.mindstorms.rwth-aachen.de/documents/downloads/doc/version-4.07/help/NXT_SetInputMode.html | ||
*/ | ||
public enum NxtRunState implements OptionList<Integer> { | ||
Disabled(0x00), | ||
@Default | ||
Running(0x20), | ||
RampUp(0x10), | ||
RampDown(0x40); | ||
|
||
private int value; | ||
|
||
NxtRunState(int state) { | ||
this.value = state; | ||
} | ||
|
||
public Integer toUnderlyingValue() { | ||
return value; | ||
} | ||
|
||
private static final Map<Integer, NxtRunState> lookup = new HashMap<>(); | ||
|
||
static { | ||
for (NxtRunState state : NxtRunState.values()) { | ||
lookup.put(state.toUnderlyingValue(), state); | ||
} | ||
} | ||
|
||
public static NxtRunState fromUnderlyingValue(Integer state) { | ||
return lookup.get(state); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
appinventor/components/src/com/google/appinventor/components/common/NxtSensorMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// -*- mode: java; c-basic-offset: 2; -*- | ||
// Copyright 2020 MIT, All rights reserved | ||
// Released under the Apache License, Version 2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package com.google.appinventor.components.common; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Defines a NxtSensorMode type used by the NxtDirectCommands component. | ||
* | ||
* Info attained from the "LEGO MINDSTORMS NXT Direct Command" document. | ||
* http://kio4.com/b4a/programas/Appendix%202-LEGO%20MINDSTORMS%20NXT%20Direct%20commands.pdf | ||
* http://www.ni.com/pdf/manuals/372574c.pdf | ||
* In combination with the documentation here: | ||
* https://www.mindstorms.rwth-aachen.de/documents/downloads/doc/version-4.07/help/NXT_SetInputMode.html | ||
*/ | ||
public enum NxtSensorMode implements OptionList<Integer> { | ||
Raw(0x00), | ||
Boolean(0x20), // 1 if > 45% else 0. | ||
TransitionCount(0x60), // Count transitions of boolean mode. | ||
PeriodCount(0x60), // Count periods of boolean mode. | ||
Percentage(0x80), // Range [0, 100]. | ||
RcxCelsius(0xA0), // Range [-200, 700]. Readings in .1 degrees Celsius. | ||
RcxFahrenheit(0xC0), // Range [-400, 1580]. Readings in .1 degrees Fahrenheit. | ||
RcxAngleSteps(0xE0); | ||
|
||
private int value; | ||
|
||
NxtSensorMode(int mode) { | ||
this.value = mode; | ||
} | ||
|
||
public Integer toUnderlyingValue() { | ||
return value; | ||
} | ||
|
||
private static final Map<Integer, NxtSensorMode> lookup = new HashMap<>(); | ||
|
||
static { | ||
for (NxtSensorMode mode : NxtSensorMode.values()) { | ||
lookup.put(mode.toUnderlyingValue(), mode); | ||
} | ||
} | ||
|
||
public static NxtSensorMode fromUnderlyingValue(Integer mode) { | ||
return lookup.get(mode); | ||
} | ||
} | ||
|
Oops, something went wrong.