Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Commit d4e33d6

Browse files
committed
Move all *_DRIVER_NAME fields to classes respectively
1 parent 7197ca1 commit d4e33d6

19 files changed

Lines changed: 115 additions & 62 deletions

.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<attribute name="maven.pomderived" value="true"/>
2323
</attributes>
2424
</classpathentry>
25-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
2626
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
2727
<attributes>
2828
<attribute name="maven.pomderived" value="true"/>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4-
org.eclipse.jdt.core.compiler.compliance=1.6
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
55
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
66
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
77
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8-
org.eclipse.jdt.core.compiler.source=1.6
8+
org.eclipse.jdt.core.compiler.source=1.8

src/main/java/org/ev3dev/hardware/LED.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class LED extends Device{
4141
/**
4242
* This Sysfs's class name (e.g. <code>/sys/class/lego-sensor</code>, and <code>lego-sensor</code> is the class name)
4343
*/
44-
public static final String LED_CLASS_NAME = "leds";
44+
public static final String CLASS_NAME = "leds";
4545

4646
/**
4747
* Creates a new LED instance.
@@ -50,7 +50,7 @@ public class LED extends Device{
5050
* @throws InvalidLEDException If the specified LEFT RIGHT field or color field isn't valid.
5151
*/
5252
public LED(int leftRightField, int colorField) throws InvalidLEDException{
53-
super(LED_CLASS_NAME);
53+
super(CLASS_NAME);
5454
if (leftRightField != 0 && leftRightField != 1){
5555
throw new InvalidLEDException("You are not specifying a EV3_LEFT_LED or EV3_RIGHT_LED field!");
5656
} else if (colorField != 0 && colorField != 1){
@@ -73,8 +73,8 @@ public LED(int leftRightField, int colorField) throws InvalidLEDException{
7373
* @throws InvalidLEDException If the specified <code>ledName</code> does not exist
7474
*/
7575
public LED(String ledName) throws InvalidLEDException{
76-
super(LED_CLASS_NAME);
77-
File file = new File(Sysfs.SYSTEM_CLASS_PATH + LED_CLASS_NAME + "/" + ledName);
76+
super(CLASS_NAME);
77+
File file = new File(Sysfs.SYSTEM_CLASS_PATH + CLASS_NAME + "/" + ledName);
7878
if (!file.exists()){
7979
throw new InvalidLEDException("The specified LED does not exist");
8080
}

src/main/java/org/ev3dev/hardware/motors/DCMotor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public class DCMotor extends Device{
2020
/**
2121
* This Sysfs's class name (e.g. <code>/sys/class/lego-sensor</code>, and <code>lego-sensor</code> is the class name)
2222
*/
23-
public static final String DC_MOTOR_CLASS_NAME = "dc-motor";
23+
public static final String CLASS_NAME = "dc-motor";
2424

2525
/**
2626
* This Sysfs's class name prefix (e.g. <code>/sys/class/lego-sensor/sensor0</code>, and <code>sensor</code> is the class name prefix without the [N] value.)
2727
*/
28-
public static final String MOTOR_CLASS_NAME_PREFIX = "motor";
28+
public static final String CLASS_NAME_PREFIX = "motor";
2929

3030
private String address;
3131

@@ -37,13 +37,13 @@ public class DCMotor extends Device{
3737
* @throws InvalidMotorException If the specified port wasn't exist a ServoMotor
3838
*/
3939
public DCMotor(LegoPort port) throws InvalidPortException, IOException, InvalidMotorException{
40-
super(port, DC_MOTOR_CLASS_NAME, MOTOR_CLASS_NAME_PREFIX);
40+
super(port, CLASS_NAME, CLASS_NAME_PREFIX);
4141
address = port.getAddress();
4242

4343
//Verify is the LegoPort connecting a motor / is a output
4444
if (!address.contains("out")){
4545
throw new InvalidPortException("The specified port (" + port.getAddress() + ") isn't a output.");
46-
} else if (!port.getStatus().equals(DC_MOTOR_CLASS_NAME)){
46+
} else if (!port.getStatus().equals(CLASS_NAME)){
4747
throw new InvalidMotorException("The specified port (" + port.getAddress() + ") isn't a motor (" + port.getStatus() + ")");
4848
}
4949
}

src/main/java/org/ev3dev/hardware/motors/LargeMotor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
import org.ev3dev.exception.InvalidMotorException;
66
import org.ev3dev.exception.InvalidPortException;
77
import org.ev3dev.hardware.ports.LegoPort;
8-
import org.ev3dev.io.Def;
98

109
public class LargeMotor extends Motor {
1110

11+
/**
12+
* This device's default driver name
13+
*/
14+
public static final String DRIVER_NAME = "lego-ev3-l-motor";
15+
1216
public LargeMotor(LegoPort port) throws InvalidPortException, IOException, InvalidMotorException {
1317
super(port);
1418
String drivername = this.getDriverName();
15-
if (!drivername.equals(Def.LARGE_MOTOR_DRIVER_NAME)){
16-
throw new InvalidMotorException("It is not a LargeMotor (" + Def.LARGE_MOTOR_DRIVER_NAME + "): " + drivername);
19+
if (!drivername.equals(DRIVER_NAME)){
20+
throw new InvalidMotorException("It is not a LargeMotor (" + DRIVER_NAME + "): " + drivername);
1721
}
1822
}
1923

src/main/java/org/ev3dev/hardware/motors/MediumMotor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
import org.ev3dev.exception.InvalidMotorException;
66
import org.ev3dev.exception.InvalidPortException;
77
import org.ev3dev.hardware.ports.LegoPort;
8-
import org.ev3dev.io.Def;
98

109
public class MediumMotor extends Motor {
10+
11+
/**
12+
* This device's default driver name
13+
*/
14+
public static final String DRIVER_NAME = "lego-ev3-m-motor";
1115

1216
public MediumMotor(LegoPort port) throws InvalidPortException, IOException, InvalidMotorException {
1317
super(port);
1418
String drivername = this.getDriverName();
15-
if (!drivername.equals(Def.MEDIUM_MOTOR_DRIVER_NAME)){
16-
throw new InvalidMotorException("It is not a MediumMotor (" + Def.MEDIUM_MOTOR_DRIVER_NAME + "): " + drivername);
19+
if (!drivername.equals(DRIVER_NAME)){
20+
throw new InvalidMotorException("It is not a MediumMotor (" + DRIVER_NAME + "): " + drivername);
1721
}
1822
}
1923

src/main/java/org/ev3dev/hardware/motors/Motor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public class Motor extends Device{
3535
/**
3636
* This Sysfs's class name (e.g. <code>/sys/class/lego-sensor</code>, and <code>lego-sensor</code> is the class name)
3737
*/
38-
public static final String MOTOR_CLASS_NAME = "tacho-motor";
38+
public static final String CLASS_NAME = "tacho-motor";
3939

4040
/**
4141
* This Sysfs's class name prefix (e.g. <code>/sys/class/lego-sensor/sensor0</code>, and <code>sensor</code> is the class name prefix without the [N] value.)
4242
*/
43-
public static final String MOTOR_CLASS_NAME_PREFIX = "motor";
43+
public static final String CLASS_NAME_PREFIX = "motor";
4444

4545
//-----------------------------------------------------------------------------
4646

@@ -55,13 +55,13 @@ public class Motor extends Device{
5555
* @throws IOException If the LegoPort specified goes wrong
5656
*/
5757
public Motor(LegoPort port) throws InvalidPortException, IOException{
58-
super(port, MOTOR_CLASS_NAME, MOTOR_CLASS_NAME_PREFIX);
58+
super(port, CLASS_NAME, CLASS_NAME_PREFIX);
5959
address = port.getAddress();
6060

6161
//Verify is the LegoPort connecting a motor / is a output
6262
if (!address.contains("out")){
6363
throw new InvalidPortException("The specified port (" + port.getAddress() + ") isn't a output.");
64-
} else if (!port.getStatus().equals(MOTOR_CLASS_NAME)){
64+
} else if (!port.getStatus().equals(CLASS_NAME)){
6565
throw new InvalidPortException("The specified port (" + port.getAddress() + ") isn't a motor (" + port.getStatus() + ")");
6666
}
6767
}

src/main/java/org/ev3dev/hardware/motors/ServoMotor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public class ServoMotor extends Device{
1919
/**
2020
* This Sysfs's class name (e.g. <code>/sys/class/lego-sensor</code>, and <code>lego-sensor</code> is the class name)
2121
*/
22-
public static final String SERVO_MOTOR_CLASS_NAME = "servo-motor";
22+
public static final String CLASS_NAME = "servo-motor";
2323

2424
/**
2525
* This Sysfs's class name prefix (e.g. <code>/sys/class/lego-sensor/sensor0</code>, and <code>sensor</code> is the class name prefix without the [N] value.)
2626
*/
27-
public static final String SERVO_MOTOR_CLASS_NAME_PREFIX = "motor";
27+
public static final String CLASS_NAME_PREFIX = "motor";
2828

2929
private String address;
3030

@@ -36,13 +36,13 @@ public class ServoMotor extends Device{
3636
* @throws InvalidMotorException The specified motor wasn't a motor
3737
*/
3838
public ServoMotor(LegoPort port) throws InvalidPortException, InvalidMotorException, IOException{
39-
super(port, SERVO_MOTOR_CLASS_NAME, SERVO_MOTOR_CLASS_NAME_PREFIX);
39+
super(port, CLASS_NAME, CLASS_NAME_PREFIX);
4040
address = port.getAddress();
4141

4242
//Verify is the LegoPort connecting a motor / is a output
4343
if (!address.contains("out")){
4444
throw new InvalidPortException("The specified port (" + port.getAddress() + ") isn't a output.");
45-
} else if (!port.getStatus().equals(SERVO_MOTOR_CLASS_NAME)){
45+
} else if (!port.getStatus().equals(CLASS_NAME)){
4646
throw new InvalidMotorException("The specified port (" + port.getAddress() + ") isn't a motor (" + port.getStatus() + ")");
4747
}
4848
}

src/main/java/org/ev3dev/hardware/ports/LegoPort.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.IOException;
44

55
import org.ev3dev.exception.InvalidPortException;
6-
import org.ev3dev.hardware.Device;
76
import org.ev3dev.io.Sysfs;
87

98
/***
@@ -33,7 +32,7 @@ public class LegoPort{
3332
/**
3433
* The sysfs class name of LegoPort
3534
*/
36-
public static final String SYSTEM_CLASS_NAME = "lego-port";
35+
public static final String CLASS_NAME = "lego-port";
3736

3837
/**
3938
* Sensor Port 1 on the EV3
@@ -95,7 +94,7 @@ public LegoPort(int port) throws InvalidPortException{
9594
* @throws IOException If I/O goes wrong
9695
*/
9796
public String getAddress() throws IOException{
98-
String address = Sysfs.getAttribute(SYSTEM_CLASS_NAME, "port" + port, "address");
97+
String address = Sysfs.getAttribute(CLASS_NAME, "port" + port, "address");
9998
return address;
10099
}
101100

@@ -105,7 +104,7 @@ public String getAddress() throws IOException{
105104
* @throws IOException if I/O goes wrong
106105
*/
107106
public String getDriverName() throws IOException{
108-
String drivername = Sysfs.getAttribute(SYSTEM_CLASS_NAME, "port" + port, "driver_name");
107+
String drivername = Sysfs.getAttribute(CLASS_NAME, "port" + port, "driver_name");
109108
return drivername;
110109
}
111110

@@ -115,7 +114,7 @@ public String getDriverName() throws IOException{
115114
* @throws IOException If I/O goes wrong
116115
*/
117116
public String[] getModes() throws IOException{
118-
String modesstr = Sysfs.getAttribute(SYSTEM_CLASS_NAME, "port" + port, "modes");
117+
String modesstr = Sysfs.getAttribute(CLASS_NAME, "port" + port, "modes");
119118
return Sysfs.separateSpace(modesstr);
120119
}
121120

@@ -128,7 +127,7 @@ public String[] getModes() throws IOException{
128127
* @throws IOException If I/O goes wrong
129128
*/
130129
public String getMode() throws IOException{
131-
String mode = Sysfs.getAttribute(SYSTEM_CLASS_NAME, "port" + port, "mode");
130+
String mode = Sysfs.getAttribute(CLASS_NAME, "port" + port, "mode");
132131
return mode;
133132
}
134133

@@ -141,7 +140,7 @@ public String getMode() throws IOException{
141140
* @throws IOException If I/O goes wrong
142141
*/
143142
public void setMode(String mode) throws IOException{
144-
Sysfs.setAttribute(SYSTEM_CLASS_NAME, "port" + port, "mode", mode);
143+
Sysfs.setAttribute(CLASS_NAME, "port" + port, "mode", mode);
145144
}
146145

147146
/**
@@ -152,7 +151,7 @@ public void setMode(String mode) throws IOException{
152151
* @throws IOException If I/O goes wrong
153152
*/
154153
public void setDevice(String driver) throws IOException{
155-
Sysfs.setAttribute(SYSTEM_CLASS_NAME, "port" + port, "set_device", driver);
154+
Sysfs.setAttribute(CLASS_NAME, "port" + port, "set_device", driver);
156155
}
157156

158157
/**
@@ -163,7 +162,7 @@ public void setDevice(String driver) throws IOException{
163162
* @throws IOException If I/O goes wrong
164163
*/
165164
public String getStatus() throws IOException{
166-
String status = Sysfs.getAttribute(SYSTEM_CLASS_NAME, "port" + port, "status");
165+
String status = Sysfs.getAttribute(CLASS_NAME, "port" + port, "status");
167166
return status;
168167
}
169168
}

src/main/java/org/ev3dev/hardware/sensors/ColorSensor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
public class ColorSensor extends Sensor {
1717

18+
/**
19+
* This device's default driver name
20+
*/
21+
public static final String DRIVER_NAME = "lego-ev3-color";
22+
1823
private boolean autoSwitchMode = true;
1924

2025
/**
@@ -26,7 +31,7 @@ public class ColorSensor extends Sensor {
2631
*/
2732
public ColorSensor(LegoPort port) throws IOException, InvalidPortException, InvalidSensorException {
2833
super(port);
29-
if (!Def.COLOR_SENSOR_DRIVER_NAME.equals(this.getDriverName())){
34+
if (!DRIVER_NAME.equals(this.getDriverName())){
3035
throw new InvalidSensorException("The specified device is not a color sensor.");
3136
}
3237
port.getAddress();

0 commit comments

Comments
 (0)