mirror of https://github.com/rusefi/RomRaider.git
Added Phidgets InterfaceKit external plugin
This commit is contained in:
parent
34c31f87be
commit
0522dbbd6f
|
@ -41,5 +41,6 @@
|
|||
<attribute name="javadoc_location" value="http://twall.github.com/jna/3.4.0/javadoc/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="lib/common/phidget21.jar"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
src/com/romraider/Version.java
|
||||
build/
|
||||
lib/common/libjinvoke.so
|
||||
*.jar
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
datasource.class=com.romraider.logger.external.phidget.interfacekit.plugin.IntfKitDataSource
|
|
@ -125,7 +125,8 @@ public final class FileLoggerImpl implements FileLogger {
|
|||
logDir += File.separator;
|
||||
}
|
||||
logDir += "romraiderlog_";
|
||||
if (!settings.getLogfileNameText().isEmpty()) {
|
||||
if (settings.getLogfileNameText() != null
|
||||
&& !settings.getLogfileNameText().isEmpty()) {
|
||||
logDir += settings.getLogfileNameText() + "_";
|
||||
}
|
||||
logDir += dateFormat.format(new Date()) + ".csv";
|
||||
|
|
79
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitConnector.java
vendored
Normal file
79
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitConnector.java
vendored
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.phidget.interfacekit.io;
|
||||
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.phidgets.InterfaceKitPhidget;
|
||||
import com.phidgets.PhidgetException;
|
||||
|
||||
/**
|
||||
* IntfKitConnector will open a connection to each serial number provided
|
||||
* and return those connections in a Set for use by the runner.
|
||||
*/
|
||||
public final class IntfKitConnector {
|
||||
private static final Logger LOGGER = getLogger(IntfKitConnector.class);
|
||||
|
||||
/**
|
||||
* Open a connection to each serial number provided and
|
||||
* return those connections in a Set for use by the runner.
|
||||
* @param ikr - the instance of IntfKitRunner calling this class
|
||||
* @param serials - array of serial numbers to open
|
||||
* @return a Set of InterfaceKitPhidget connections
|
||||
* @throws InterruptedException
|
||||
* @throws PhidgetException
|
||||
* @see IntfKitRunner
|
||||
*/
|
||||
public static Set<InterfaceKitPhidget> openIkSerial(
|
||||
final IntfKitRunner ikr,
|
||||
final Integer[] serials) {
|
||||
|
||||
final Set<InterfaceKitPhidget> kits = new HashSet<InterfaceKitPhidget>();
|
||||
try {
|
||||
for (int serial : serials) {
|
||||
final InterfaceKitPhidget ik = new InterfaceKitPhidget();
|
||||
final IntfKitSensorChangeListener scl = new IntfKitSensorChangeListener(ikr);
|
||||
ik.addSensorChangeListener(scl);
|
||||
ik.open(serial);
|
||||
final long timeout = currentTimeMillis() + 500L;
|
||||
do {
|
||||
Thread.sleep(50);
|
||||
} while (!ik.isAttached() && (currentTimeMillis() < timeout));
|
||||
final int inputCount = ik.getSensorCount();
|
||||
for (int i = 0; i < inputCount; i++) {
|
||||
ik.setSensorChangeTrigger(i, 1);
|
||||
}
|
||||
kits.add(ik);
|
||||
}
|
||||
}
|
||||
catch (PhidgetException e) {
|
||||
LOGGER.error("InterfaceKit open error: " + e);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.info("Sleep interrupted " + e);
|
||||
}
|
||||
return kits;
|
||||
}
|
||||
}
|
201
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitManager.java
vendored
Normal file
201
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitManager.java
vendored
Normal file
|
@ -0,0 +1,201 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.phidget.interfacekit.io;
|
||||
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.phidgets.InterfaceKitPhidget;
|
||||
import com.phidgets.Manager;
|
||||
import com.phidgets.Phidget;
|
||||
import com.phidgets.PhidgetException;
|
||||
|
||||
/**
|
||||
* IntfKitManager is used to discover all the attached PhidgetInterfaceKits
|
||||
* by serial number, load the Phidgets library and get a list of all sensors
|
||||
* on all PhidgetInterfaceKits.
|
||||
*/
|
||||
public final class IntfKitManager {
|
||||
private static final Logger LOGGER = getLogger(IntfKitManager.class);
|
||||
private static final String INTFKIT = "PhidgetInterfaceKit";
|
||||
private static InterfaceKitPhidget ik;
|
||||
|
||||
/**
|
||||
* Using the Phidgets Manager find all of the attached PhidgetInterfaceKits.
|
||||
* @return an array of serial numbers
|
||||
* @throws PhidgetException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static Integer[] findIntfkits() {
|
||||
final List<Integer> serials = new ArrayList<Integer>();
|
||||
try {
|
||||
final Manager fm = new Manager();
|
||||
fm.open();
|
||||
Thread.sleep(100);
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<Phidget> phidgets = fm.getPhidgets();
|
||||
for (Phidget phidget : phidgets) {
|
||||
if (phidget.getDeviceType().equalsIgnoreCase(INTFKIT)) {
|
||||
serials.add(phidget.getSerialNumber());
|
||||
}
|
||||
}
|
||||
fm.close();
|
||||
}
|
||||
catch (PhidgetException e) {
|
||||
LOGGER.error("Phidget Manager error: " + e);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOGGER.info("Sleep interrupted " + e);
|
||||
}
|
||||
return serials.toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the Phidgets Library and report the library version in the
|
||||
* RomRaider system log file.
|
||||
* @throws PhidgetException
|
||||
*/
|
||||
public static void loadIk() {
|
||||
try {
|
||||
ik = new InterfaceKitPhidget();
|
||||
LOGGER.info(Phidget.getLibraryVersion());
|
||||
}
|
||||
catch (PhidgetException e) {
|
||||
LOGGER.error("InterfaceKit error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For the serial number provided report the name of the
|
||||
* associated PhidgetInterfaceKit.
|
||||
* @param serial - the serial number previously discovered to be opened
|
||||
* @return a format string of the name and serial number
|
||||
* @throws PhidgetException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static String getIkName(final int serial) {
|
||||
String result = null;
|
||||
try {
|
||||
ik.open(serial);
|
||||
waitForAttached();
|
||||
try {
|
||||
if (ik.getDeviceType().equalsIgnoreCase(INTFKIT)) {
|
||||
result = String.format(
|
||||
"%s serial: %d",
|
||||
ik.getDeviceName(),
|
||||
serial);
|
||||
}
|
||||
}
|
||||
catch (PhidgetException e) {
|
||||
LOGGER.error("InterfaceKit read device error: " + e);
|
||||
}
|
||||
finally {
|
||||
ik.close();
|
||||
}
|
||||
}
|
||||
catch (PhidgetException e) {
|
||||
LOGGER.error("InterfaceKit open serial error: " + e);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* For the serial number provided create a Set of sensors found on the
|
||||
* associated PhidgetInterfaceKit.
|
||||
* @param serial - the serial number previously discovered to open
|
||||
* @return a Set of <b>IntfKitSensor</b>
|
||||
* @throws PhidgetException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static Set<IntfKitSensor> getSensors(final int serial) {
|
||||
Set<IntfKitSensor> sensors = new HashSet<IntfKitSensor>();
|
||||
try {
|
||||
ik.open(serial);
|
||||
waitForAttached();
|
||||
try {
|
||||
if (ik.isAttached()) {
|
||||
if (ik.getDeviceType().equalsIgnoreCase(INTFKIT)) {
|
||||
final String result = String.format(
|
||||
"Plugin found: %s Serial: %d",
|
||||
ik.getDeviceName(),
|
||||
serial);
|
||||
LOGGER.info(result);
|
||||
final int inputCount = ik.getSensorCount();
|
||||
for (int i = 0; i < inputCount; i++) {
|
||||
final IntfKitSensor sensor = new IntfKitSensor();
|
||||
sensor.setInputNumber(i);
|
||||
final String inputName = String.format("Sensor %d:%d",
|
||||
serial,
|
||||
i);
|
||||
sensor.setInputName(inputName);
|
||||
sensor.setUnits("raw value");
|
||||
sensor.setMinValue(0);
|
||||
sensor.setMaxValue(1000);
|
||||
sensors.add(sensor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOGGER.info("No InterfaceKits attached");
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOGGER.info("No Phidget devices attached");
|
||||
}
|
||||
}
|
||||
catch (PhidgetException e) {
|
||||
LOGGER.error("InterfaceKit read error: " + e);
|
||||
}
|
||||
finally {
|
||||
ik.close();
|
||||
}
|
||||
}
|
||||
catch (PhidgetException e) {
|
||||
LOGGER.error("InterfaceKit open error: " + e);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return sensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the Attach signal after opening the PhidgetInterfaceKit
|
||||
* or a maximum timeout of 500msec.
|
||||
* @throws PhidgetException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private static void waitForAttached()
|
||||
throws InterruptedException, PhidgetException {
|
||||
final long timeout = currentTimeMillis() + 500L;
|
||||
do {
|
||||
Thread.sleep(50);
|
||||
} while (!ik.isAttached() && (currentTimeMillis() < timeout));
|
||||
}
|
||||
}
|
110
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitRunner.java
vendored
Normal file
110
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitRunner.java
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.phidget.interfacekit.io;
|
||||
|
||||
import static com.romraider.util.ThreadUtil.sleep;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.phidgets.InterfaceKitPhidget;
|
||||
import com.phidgets.PhidgetException;
|
||||
import com.romraider.logger.external.core.Stoppable;
|
||||
import com.romraider.logger.external.phidget.interfacekit.plugin.IntfKitDataItem;
|
||||
|
||||
/**
|
||||
* IntfKitRunner manages the connections to the PhidgetInterfaceKits. It
|
||||
* also responds to the sensor change events to update the appropriate
|
||||
* sensor's value.
|
||||
*/
|
||||
public final class IntfKitRunner implements Stoppable {
|
||||
private static final Logger LOGGER = getLogger(IntfKitRunner.class);
|
||||
private final Map<String, IntfKitDataItem> dataItems;
|
||||
private Set<InterfaceKitPhidget> connections;
|
||||
private boolean stop;
|
||||
|
||||
/**
|
||||
* IntfKitRunner interrogates the PhidgetInterfaceKits for data and updates
|
||||
* the appropriate sensor result.
|
||||
* @param kits - array of serial numbers of the PhidgetInterfaceKits
|
||||
* @param dataItems - a Map of PhidgetInterfaceKit data items (sensors)
|
||||
*/
|
||||
public IntfKitRunner(
|
||||
final Integer[] kits,
|
||||
final Map<String, IntfKitDataItem> dataItems) {
|
||||
this.dataItems = dataItems;
|
||||
this.connections = IntfKitConnector.openIkSerial(this, kits);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to start and stop the reading of the
|
||||
* PhidgetInterfaceKits data. Each data item value is set by the
|
||||
* sensor change Listener. When stop is issued the connection is
|
||||
* closed to the device.
|
||||
* @throws PhidgetException
|
||||
* @see IntfKitSensorChangeListener
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
while (!stop) {
|
||||
sleep(500L);
|
||||
}
|
||||
for (InterfaceKitPhidget connector : connections) {
|
||||
connector.close();
|
||||
}
|
||||
} catch (PhidgetException e) {
|
||||
LOGGER.error("InterfaceKit close error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used stop the reading of the PhidgetInterfaceKits data
|
||||
* and close the connections to the devices.
|
||||
*/
|
||||
public void stop() {
|
||||
stop = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is event driven and called by the SensorChangeListner
|
||||
* with the sensor ID and the new value to be set.
|
||||
* @param serial - serial number of the InterfaceKit reporting the change
|
||||
* @param sensor - the sensor number reporting the change
|
||||
* @param value - the new value to set
|
||||
*/
|
||||
public void updateDataItem(final int serial, final int sensor, final int value) {
|
||||
if (serial != -1) {
|
||||
final String inputName = String.format("%d:%d", serial, sensor);
|
||||
dataItems.get(inputName).setData((double) value);
|
||||
final String result = String.format(
|
||||
"Phidget InterfaceKit sensor %s event - raw value: %d",
|
||||
inputName,
|
||||
sensor,
|
||||
value);
|
||||
LOGGER.trace(result);
|
||||
}
|
||||
else {
|
||||
LOGGER.error("Phidget InterfaceKit dataitem update error");
|
||||
}
|
||||
}
|
||||
}
|
79
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitSensor.java
vendored
Normal file
79
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitSensor.java
vendored
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.phidget.interfacekit.io;
|
||||
|
||||
/**
|
||||
* IntfKitSensor contains all the relevant information about a sensor as
|
||||
* reported from information gathered from the Phidget device. An IntfKitSensor
|
||||
* is created for each input found on the Phidget device.
|
||||
*/
|
||||
public final class IntfKitSensor {
|
||||
private int inputNumber;
|
||||
private String inputName;
|
||||
private String units;
|
||||
private float minValue;
|
||||
private float maxValue;
|
||||
|
||||
/**
|
||||
* Create an IntfKitSensor with all fields set to type default values.
|
||||
*/
|
||||
public IntfKitSensor() {
|
||||
}
|
||||
|
||||
public int getInputNumber() {
|
||||
return inputNumber;
|
||||
}
|
||||
|
||||
public void setInputNumber(int input) {
|
||||
inputNumber = input;
|
||||
}
|
||||
|
||||
public String getInputName() {
|
||||
return inputName;
|
||||
}
|
||||
|
||||
public void setInputName(String name) {
|
||||
inputName = name;
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public void setUnits(String unit) {
|
||||
units = unit;
|
||||
}
|
||||
|
||||
public float getMinValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public void setMinValue(float value) {
|
||||
minValue = value;
|
||||
}
|
||||
|
||||
public float getMaxValue() {
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public void setMaxValue(float value) {
|
||||
maxValue = value;
|
||||
}
|
||||
}
|
60
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitSensorChangeListener.java
vendored
Normal file
60
src/com/romraider/logger/external/phidget/interfacekit/io/IntfKitSensorChangeListener.java
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.phidget.interfacekit.io;
|
||||
|
||||
import com.phidgets.PhidgetException;
|
||||
import com.phidgets.event.SensorChangeListener;
|
||||
import com.phidgets.event.SensorChangeEvent;
|
||||
|
||||
/**
|
||||
* IntfKitSensorChangeListener responds to Sensor changes. It filters
|
||||
* the exact sensor to be updated and provides the update to the
|
||||
* IntfKitRunner's data items.
|
||||
*/
|
||||
public class IntfKitSensorChangeListener implements SensorChangeListener {
|
||||
private final IntfKitRunner ikr;
|
||||
|
||||
/**
|
||||
* Creates a new instance of IntfKitSensorChangeListener to be
|
||||
* registered against each PhidgetInterfaceKit opened.
|
||||
* @param ikr - the instance of the InterfaceKitRunner
|
||||
*/
|
||||
public IntfKitSensorChangeListener(IntfKitRunner ikr) {
|
||||
this.ikr = ikr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the sensor change, isolates the serial number, sensor
|
||||
* number and value then calls to the InterfaceKitRunner to
|
||||
* update the matching data item.
|
||||
* @param sensorChangeEvent - the event from the Phidget device
|
||||
*/
|
||||
public void sensorChanged(final SensorChangeEvent sensorChangeEvent) {
|
||||
try {
|
||||
ikr.updateDataItem(
|
||||
sensorChangeEvent.getSource().getSerialNumber(),
|
||||
sensorChangeEvent.getIndex(),
|
||||
sensorChangeEvent.getValue());
|
||||
}
|
||||
catch (PhidgetException e) {
|
||||
ikr.updateDataItem(-1, -1, -1);
|
||||
}
|
||||
}
|
||||
}
|
94
src/com/romraider/logger/external/phidget/interfacekit/plugin/IntfKitDataItem.java
vendored
Normal file
94
src/com/romraider/logger/external/phidget/interfacekit/plugin/IntfKitDataItem.java
vendored
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.phidget.interfacekit.plugin;
|
||||
|
||||
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.DataListener;
|
||||
import com.romraider.logger.external.core.ExternalDataItem;
|
||||
|
||||
/**
|
||||
* IntfKitDataItem contains all the relevant information about a data item as
|
||||
* reported from information gathered from the Phidget device. A data item
|
||||
* is created for each input found on the Phidget device. Only raw data values
|
||||
* are recorded for these sensors as we don't know the conversion formula of
|
||||
* the analog device attached to the sensor input. Data will need to be post-
|
||||
* processed in a spreadsheet application with the formula of the device.
|
||||
*/
|
||||
public final class IntfKitDataItem implements ExternalDataItem, DataListener {
|
||||
private final String name;
|
||||
private final GaugeMinMax gaugeMinMax;
|
||||
private double data;
|
||||
private String units;
|
||||
|
||||
/**
|
||||
* Create a new data item and set its fields according to the supplied
|
||||
* parameters.
|
||||
* @param name - unique name of the data item
|
||||
* @param units - the units of the data
|
||||
* @param minValue - the minimum value expected for the data item
|
||||
* @param maxValue - the maximum value expected for the data item
|
||||
*/
|
||||
public IntfKitDataItem(String name, String units, float minValue, float maxValue) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.units = units;
|
||||
float step = (Math.abs(maxValue) + Math.abs(minValue)) / 10f;
|
||||
if (step > 0.5f) {
|
||||
step = (float) Math.round(step);
|
||||
}
|
||||
else {
|
||||
step = 0.5f;
|
||||
}
|
||||
gaugeMinMax = new GaugeMinMax(minValue, maxValue, step);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Phidget IK " + name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "Phidget IK " + name + " data";
|
||||
}
|
||||
|
||||
public double getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public void setData(double data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public EcuDataConvertor[] getConvertors() {
|
||||
EcuDataConvertor[] convertors = {
|
||||
new ExternalDataConvertorImpl(
|
||||
this,
|
||||
units,
|
||||
"x",
|
||||
"0.##",
|
||||
gaugeMinMax)};
|
||||
return convertors;
|
||||
}
|
||||
}
|
115
src/com/romraider/logger/external/phidget/interfacekit/plugin/IntfKitDataSource.java
vendored
Normal file
115
src/com/romraider/logger/external/phidget/interfacekit/plugin/IntfKitDataSource.java
vendored
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.phidget.interfacekit.plugin;
|
||||
|
||||
import static com.romraider.util.ThreadUtil.runAsDaemon;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.Action;
|
||||
|
||||
import com.romraider.logger.ecu.EcuLogger;
|
||||
import com.romraider.logger.external.core.ExternalDataItem;
|
||||
import com.romraider.logger.external.core.ExternalDataSource;
|
||||
import com.romraider.logger.external.phidget.interfacekit.io.IntfKitManager;
|
||||
import com.romraider.logger.external.phidget.interfacekit.io.IntfKitRunner;
|
||||
import com.romraider.logger.external.phidget.interfacekit.io.IntfKitSensor;
|
||||
|
||||
/**
|
||||
* The IntfKitDataSource class is called when the Logger starts up and the
|
||||
* call to load the external plug-ins is made. This class with its helpers
|
||||
* will open each PhidgetInterfaceKit and find all available inputs. It will
|
||||
* interrogate the inputs then dynamically build a list of inputs found based
|
||||
* on the serial number and input number.
|
||||
* @see ExternalDataSource
|
||||
*/
|
||||
public final class IntfKitDataSource implements ExternalDataSource {
|
||||
private final Map<String, IntfKitDataItem> dataItems =
|
||||
new HashMap<String, IntfKitDataItem>();
|
||||
private IntfKitRunner runner;
|
||||
private Integer[] kits;
|
||||
|
||||
{
|
||||
kits = IntfKitManager.findIntfkits();
|
||||
if (kits.length > 0) {
|
||||
IntfKitManager.loadIk();
|
||||
for (int serial : kits) {
|
||||
final Set<IntfKitSensor> sensors = IntfKitManager.getSensors(serial);
|
||||
if (!sensors.isEmpty()) {
|
||||
for (IntfKitSensor sensor : sensors) {
|
||||
final String inputName = String.format("%d:%d",
|
||||
serial,
|
||||
sensor.getInputNumber());
|
||||
dataItems.put(
|
||||
inputName,
|
||||
new IntfKitDataItem(
|
||||
sensor.getInputName(),
|
||||
sensor.getUnits(),
|
||||
sensor.getMinValue(),
|
||||
sensor.getMaxValue()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Phidget InterfaceKit";
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "0.01";
|
||||
}
|
||||
|
||||
public List<? extends ExternalDataItem> getDataItems() {
|
||||
return unmodifiableList(new ArrayList<IntfKitDataItem>(dataItems.values()));
|
||||
}
|
||||
|
||||
public Action getMenuAction(final EcuLogger logger) {
|
||||
return new IntfKitPluginMenuAction(logger);
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
runner = new IntfKitRunner(kits, dataItems);
|
||||
runAsDaemon(runner);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (runner != null) runner.stop();
|
||||
}
|
||||
|
||||
public void setPort(final String port) {
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return "HID USB";
|
||||
}
|
||||
}
|
81
src/com/romraider/logger/external/phidget/interfacekit/plugin/IntfKitPluginMenuAction.java
vendored
Normal file
81
src/com/romraider/logger/external/phidget/interfacekit/plugin/IntfKitPluginMenuAction.java
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.phidget.interfacekit.plugin;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.romraider.logger.ecu.EcuLogger;
|
||||
import com.romraider.logger.external.phidget.interfacekit.io.IntfKitManager;
|
||||
import com.romraider.swing.menubar.action.AbstractAction;
|
||||
|
||||
/**
|
||||
* IntfKitPluginMenuAction is used to populate the Phidgets Plugins menu
|
||||
* of the Logger. It will report the device type and serial number of each
|
||||
* PhidgetInterfaceKit found connected to the system.
|
||||
* This is informational only.
|
||||
*/
|
||||
public final class IntfKitPluginMenuAction extends AbstractAction {
|
||||
|
||||
/**
|
||||
* Initialise the Phidgets Plugins menu item.
|
||||
* @param logger - the parent frame to bind the dialog message to
|
||||
*/
|
||||
public IntfKitPluginMenuAction(final EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
JOptionPane.showMessageDialog(
|
||||
logger,
|
||||
getKits(),
|
||||
"Interface Kits found",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a list of device types with serial numbers attached to the system.
|
||||
* @return a formated string to be displayed in the message box
|
||||
* @see IntfKitManager
|
||||
*/
|
||||
private String getKits() {
|
||||
final Integer[] kits = IntfKitManager.findIntfkits();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
if (kits.length < 1) {
|
||||
sb.append("No Interface Kits attached");
|
||||
}
|
||||
else {
|
||||
IntfKitManager.loadIk();
|
||||
for (int serial : kits) {
|
||||
final String result = IntfKitManager.getIkName(serial);
|
||||
if (result != null) {
|
||||
sb.append(result);
|
||||
}
|
||||
else {
|
||||
sb.append("Unable to read properties of serial # " + serial +
|
||||
", it may be in use");
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue