Added default fallback values to serial parameters used in Serial constructor. Fixes #3381

This commit is contained in:
Federico Fissore 2015-06-22 10:35:28 +02:00
parent 380b147dae
commit a49f1b264a
2 changed files with 26 additions and 14 deletions

View File

@ -195,6 +195,18 @@ public class PreferencesData {
set(key, String.valueOf(value));
}
static public float getFloat(String attribute, float defaultValue) {
if (has(attribute)) {
return getFloat(attribute);
}
return defaultValue;
}
static public float getFloat(String attribute) {
return Float.parseFloat(get(attribute));
}
// get a copy of the Preferences
static public PreferencesMap getMap() {
return new PreferencesMap(prefs);

View File

@ -49,30 +49,30 @@ public class Serial implements SerialPortEventListener {
public Serial() throws SerialException {
this(PreferencesData.get("serial.port"),
PreferencesData.getInteger("serial.debug_rate"),
PreferencesData.get("serial.parity").charAt(0),
PreferencesData.getInteger("serial.databits"),
Float.parseFloat(PreferencesData.get("serial.stopbits")));
PreferencesData.getInteger("serial.debug_rate", 9600),
PreferencesData.get("serial.parity", "N").charAt(0),
PreferencesData.getInteger("serial.databits", 8),
PreferencesData.getFloat("serial.stopbits", 1));
}
public Serial(int irate) throws SerialException {
this(PreferencesData.get("serial.port"), irate,
PreferencesData.get("serial.parity").charAt(0),
PreferencesData.getInteger("serial.databits"),
Float.parseFloat(PreferencesData.get("serial.stopbits")));
PreferencesData.get("serial.parity", "N").charAt(0),
PreferencesData.getInteger("serial.databits", 8),
PreferencesData.getFloat("serial.stopbits", 1));
}
public Serial(String iname, int irate) throws SerialException {
this(iname, irate, PreferencesData.get("serial.parity").charAt(0),
PreferencesData.getInteger("serial.databits"),
Float.parseFloat(PreferencesData.get("serial.stopbits")));
this(iname, irate, PreferencesData.get("serial.parity", "N").charAt(0),
PreferencesData.getInteger("serial.databits", 8),
PreferencesData.getFloat("serial.stopbits", 1));
}
public Serial(String iname) throws SerialException {
this(iname, PreferencesData.getInteger("serial.debug_rate"),
PreferencesData.get("serial.parity").charAt(0),
PreferencesData.getInteger("serial.databits"),
Float.parseFloat(PreferencesData.get("serial.stopbits")));
this(iname, PreferencesData.getInteger("serial.debug_rate", 9600),
PreferencesData.get("serial.parity", "N").charAt(0),
PreferencesData.getInteger("serial.databits", 8),
PreferencesData.getFloat("serial.stopbits", 1));
}
public static boolean touchForCDCReset(String iname) throws SerialException {