Added Omar's changes to the compressor interface

Change-Id: Iff22b0eaa319065b06795b381c4d6072f8087da8
This commit is contained in:
thomasclark
2014-06-12 12:43:03 -04:00
parent 5d646536fb
commit 8d5c67e6aa
8 changed files with 270 additions and 405 deletions

View File

@@ -1,129 +1,119 @@
package edu.wpi.first.wpilibj;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import edu.wpi.first.wpilibj.SensorBase;
import edu.wpi.first.wpilibj.hal.CompressorJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.IDevice;
import edu.wpi.first.wpilibj.tables.ITable;
public class Compressor extends SensorBase implements IDevice, LiveWindowSendable {
private ByteBuffer m_pcm;
public Compressor(int module) {
initCompressor(module);
}
public Compressor() {
initCompressor(getDefaultSolenoidModule());
}
private void initCompressor(int module) {
m_table = null;
m_pcm = CompressorJNI.initializeCompressor((byte)module);
}
public void start() {
setClosedLoopControl(false);
setCompressor(true);
}
public void stop() {
setClosedLoopControl(false);
setCompressor(false);
}
public boolean enabled() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getCompressor(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
public boolean getPressureSwitchValue() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getPressureSwitch(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
public float getCompressorCurrent() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
float current = CompressorJNI.getCompressorCurrent(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return current;
}
public void setClosedLoopControl(boolean on) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CompressorJNI.setClosedLoopControl(m_pcm, on, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
public boolean getClosedLoopControl() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getClosedLoopControl(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
@Override
public void startLiveWindowMode() {
}
@Override
public void stopLiveWindowMode() {
}
private void setCompressor(boolean on) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CompressorJNI.setCompressor(m_pcm, on, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
@Override
public String getSmartDashboardType() {
return "Compressor";
}
private ITable m_table;
@Override
public void initTable(ITable subtable) {
m_table = subtable;
updateTable();
}
@Override
public ITable getTable() {
return m_table;
}
@Override
public void updateTable() {
if (m_table != null) {
m_table.putBoolean("Enabled", enabled());
m_table.putBoolean("Pressure Switch", getPressureSwitchValue());
}
}
}
package edu.wpi.first.wpilibj;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import edu.wpi.first.wpilibj.SensorBase;
import edu.wpi.first.wpilibj.hal.CompressorJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.IDevice;
import edu.wpi.first.wpilibj.tables.ITable;
public class Compressor extends SensorBase implements IDevice, LiveWindowSendable {
private ByteBuffer m_pcm;
public Compressor(int module) {
initCompressor(module);
}
public Compressor() {
initCompressor(getDefaultSolenoidModule());
}
private void initCompressor(int module) {
m_table = null;
m_pcm = CompressorJNI.initializeCompressor((byte)module);
}
public void start() {
setClosedLoopControl(true);
}
public void stop() {
setClosedLoopControl(false);
}
public boolean enabled() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getCompressor(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
public boolean getPressureSwitchValue() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getPressureSwitch(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
public float getCompressorCurrent() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
float current = CompressorJNI.getCompressorCurrent(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return current;
}
public void setClosedLoopControl(boolean on) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CompressorJNI.setClosedLoopControl(m_pcm, on, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
public boolean getClosedLoopControl() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getClosedLoopControl(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
@Override
public void startLiveWindowMode() {
}
@Override
public void stopLiveWindowMode() {
}
@Override
public String getSmartDashboardType() {
return "Compressor";
}
private ITable m_table;
@Override
public void initTable(ITable subtable) {
m_table = subtable;
updateTable();
}
@Override
public ITable getTable() {
return m_table;
}
@Override
public void updateTable() {
if (m_table != null) {
m_table.putBoolean("Enabled", enabled());
m_table.putBoolean("Pressure Switch", getPressureSwitchValue());
}
}
}

View File

@@ -1,18 +1,17 @@
package edu.wpi.first.wpilibj.hal;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class CompressorJNI extends JNIWrapper {
public static native ByteBuffer initializeCompressor(byte module);
public static native boolean checkCompressorModule(byte module);
public static native void setCompressor(ByteBuffer pcm_pointer, boolean value, IntBuffer status);
public static native boolean getCompressor(ByteBuffer pcm_pointer, IntBuffer status);
public static native void setClosedLoopControl(ByteBuffer pcm_pointer, boolean value, IntBuffer status);
public static native boolean getClosedLoopControl(ByteBuffer pcm_pointer, IntBuffer status);
public static native boolean getPressureSwitch(ByteBuffer pcm_pointer, IntBuffer status);
public static native float getCompressorCurrent(ByteBuffer pcm_pointer, IntBuffer status);
}
package edu.wpi.first.wpilibj.hal;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class CompressorJNI extends JNIWrapper {
public static native ByteBuffer initializeCompressor(byte module);
public static native boolean checkCompressorModule(byte module);
public static native boolean getCompressor(ByteBuffer pcm_pointer, IntBuffer status);
public static native void setClosedLoopControl(ByteBuffer pcm_pointer, boolean value, IntBuffer status);
public static native boolean getClosedLoopControl(ByteBuffer pcm_pointer, IntBuffer status);
public static native boolean getPressureSwitch(ByteBuffer pcm_pointer, IntBuffer status);
public static native float getCompressorCurrent(ByteBuffer pcm_pointer, IntBuffer status);
}