Update to implement the new ConvertorManger interface. Convertors can now be applied to the Phidget data items immediately, no Logger restart required.

This commit is contained in:
Dale Schultz 2013-07-21 23:38:38 -04:00
parent b8a26f69a5
commit ae9b6f8fbb
2 changed files with 43 additions and 21 deletions

View File

@ -22,6 +22,7 @@ package com.romraider.logger.external.phidget.interfacekit.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor; import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl; import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.ecu.ui.handler.dash.GaugeMinMax; import com.romraider.logger.ecu.ui.handler.dash.GaugeMinMax;
import com.romraider.logger.external.core.ConvertorManager;
import com.romraider.logger.external.core.DataListener; import com.romraider.logger.external.core.DataListener;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
import com.romraider.logger.external.phidget.interfacekit.io.IntfKitSensor; import com.romraider.logger.external.phidget.interfacekit.io.IntfKitSensor;
@ -33,10 +34,11 @@ import com.romraider.logger.external.phidget.interfacekit.io.IntfKitSensor;
* of each sensor input is set to raw defaults and can be modified by the user * of each sensor input is set to raw defaults and can be modified by the user
* using the Phidget InterfaceKit dialog from the Logger Plugins menu item. * using the Phidget InterfaceKit dialog from the Logger Plugins menu item.
*/ */
public final class IntfKitDataItem implements ExternalDataItem, DataListener { public final class IntfKitDataItem implements
ExternalDataItem, DataListener, ConvertorManager {
private final String name; private final String name;
private double data; private double data;
private String units;
private EcuDataConvertor[] convertors; private EcuDataConvertor[] convertors;
/** /**
@ -49,9 +51,9 @@ public final class IntfKitDataItem implements ExternalDataItem, DataListener {
public IntfKitDataItem(IntfKitSensor sensor) { public IntfKitDataItem(IntfKitSensor sensor) {
super(); super();
this.name = sensor.getInputName(); this.name = sensor.getInputName();
this.units = sensor.getUnits();
int convertorCount = 1; int convertorCount = 1;
if (!sensor.getExpression().equals("x")) { if (!sensor.getExpression().equals("x") &&
!sensor.getUnits().equals("raw value")) {
convertorCount = 2; convertorCount = 2;
} }
GaugeMinMax gaugeMinMax = new GaugeMinMax( GaugeMinMax gaugeMinMax = new GaugeMinMax(
@ -59,7 +61,7 @@ public final class IntfKitDataItem implements ExternalDataItem, DataListener {
convertors = new EcuDataConvertor[convertorCount]; convertors = new EcuDataConvertor[convertorCount];
convertors[0] = new ExternalDataConvertorImpl( convertors[0] = new ExternalDataConvertorImpl(
this, this,
units, sensor.getUnits(),
sensor.getExpression(), sensor.getExpression(),
sensor.getFormat(), sensor.getFormat(),
gaugeMinMax); gaugeMinMax);
@ -74,27 +76,33 @@ public final class IntfKitDataItem implements ExternalDataItem, DataListener {
} }
} }
@Override
public String getName() { public String getName() {
return name; return name;
} }
@Override
public String getDescription() { public String getDescription() {
return name + " data"; return name + " data";
} }
@Override
public double getData() { public double getData() {
return data; return data;
} }
public String getUnits() { @Override
return units;
}
public void setData(double data) { public void setData(double data) {
this.data = data; this.data = data;
} }
@Override
public EcuDataConvertor[] getConvertors() { public EcuDataConvertor[] getConvertors() {
return convertors; return convertors;
} }
@Override
public void setConvertors(EcuDataConvertor[] convertors) {
this.convertors = convertors;
}
} }

View File

@ -31,6 +31,9 @@ import javax.swing.table.TableModel;
import com.romraider.Settings; import com.romraider.Settings;
import com.romraider.logger.ecu.EcuLogger; import com.romraider.logger.ecu.EcuLogger;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.ecu.ui.handler.dash.GaugeMinMax;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
import com.romraider.logger.external.core.ExternalDataSource; import com.romraider.logger.external.core.ExternalDataSource;
import com.romraider.logger.external.phidget.interfacekit.io.IntfKitSensor; import com.romraider.logger.external.phidget.interfacekit.io.IntfKitSensor;
@ -65,7 +68,6 @@ public final class IntfKitPluginMenuAction extends AbstractAction {
} }
private List<List<String>> getDataItems() { private List<List<String>> getDataItems() {
final StringBuilder sb = new StringBuilder();
final List<List<String>> ikDataItems = new ArrayList<List<String>>(); final List<List<String>> ikDataItems = new ArrayList<List<String>>();
final List<ExternalDataSource> externalSources = logger.getExternalDataSources(); final List<ExternalDataSource> externalSources = logger.getExternalDataSources();
dataItems = new ArrayList<ExternalDataItem>(); dataItems = new ArrayList<ExternalDataItem>();
@ -86,12 +88,6 @@ public final class IntfKitPluginMenuAction extends AbstractAction {
String.valueOf(item.getConvertors()[0].getGaugeMinMax().step) String.valueOf(item.getConvertors()[0].getGaugeMinMax().step)
)); ));
} }
for (List<String> ikData : ikDataItems) {
for (int i = 0; i < ikData.size(); i++) {
sb.append(ikData.get(i) + " : ");
}
sb.append("\n");
}
return ikDataItems; return ikDataItems;
} }
@ -100,11 +96,11 @@ public final class IntfKitPluginMenuAction extends AbstractAction {
final Map<String, IntfKitSensor> phidgets = Settings.getPhidgetSensors(); final Map<String, IntfKitSensor> phidgets = Settings.getPhidgetSensors();
for (int i = 0; i < tm.getRowCount(); i++) { for (int i = 0; i < tm.getRowCount(); i++) {
String value = (String) tm.getValueAt(i, 0); String column0 = (String) tm.getValueAt(i, 0);
String key = value.replaceAll("Phidget IK Sensor ", ""); String key = column0.replaceAll("Phidget IK Sensor ", "");
if (phidgets.containsKey(key)) { if (phidgets.containsKey(key)) {
for (int j = 1; j < tm.getColumnCount(); j++) { for (int j = 1; j < tm.getColumnCount(); j++) {
value = (String) tm.getValueAt(i, j); String value = (String) tm.getValueAt(i, j);
switch (j) { switch (j) {
case 1: case 1:
phidgets.get(key).setExpression(value); phidgets.get(key).setExpression(value);
@ -129,12 +125,30 @@ public final class IntfKitPluginMenuAction extends AbstractAction {
} }
} }
} }
final IntfKitDataItem ikDataItem = (IntfKitDataItem) dataItems.get(i);
final GaugeMinMax gaugeMinMax = new GaugeMinMax(
Float.parseFloat((String) tm.getValueAt(i, 4)),
Float.parseFloat((String) tm.getValueAt(i, 5)),
Float.parseFloat((String) tm.getValueAt(i, 6)));
final EcuDataConvertor[] convertors = ikDataItem.getConvertors();
convertors[0] = new ExternalDataConvertorImpl(
ikDataItem,
(String) tm.getValueAt(i, 3),
(String) tm.getValueAt(i, 1),
(String) tm.getValueAt(i, 2),
gaugeMinMax);
ikDataItem.setConvertors(convertors);
} }
Settings.setPhidgetSensors(phidgets); Settings.setPhidgetSensors(phidgets);
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
logger, logger,
"Exit and restart the Logger to activate the changes.", "Un-select each updated External Phidget data item on each Data,\n" +
"Phidget InterfaceKit Settings Saved", "Graph and Dashboard Logger tabs to complete the update.\n\n" +
"Logging profiles using the old Phidget settings must be loaded\n" +
"and re-saved with the new settings.",
"Phidget InterfaceKit Settings Applied",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
} }
} }