mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
Added Omar's changes to the compressor interface
Change-Id: Iff22b0eaa319065b06795b381c4d6072f8087da8
This commit is contained in:
@@ -16,7 +16,6 @@ extern "C" {
|
||||
void *initializeCompressor(uint8_t module);
|
||||
bool checkCompressorModule(uint8_t module);
|
||||
|
||||
void setCompressor(void *pcm_pointer, bool value, int32_t *status);
|
||||
bool getCompressor(void *pcm_pointer, int32_t *status);
|
||||
|
||||
void setClosedLoopControl(void *pcm_pointer, bool value, int32_t *status);
|
||||
|
||||
@@ -17,13 +17,6 @@ bool checkCompressorModule(uint8_t module) {
|
||||
}
|
||||
|
||||
|
||||
void setCompressor(void *pcm_pointer, bool value, int32_t *status) {
|
||||
PCM *module = (PCM *)pcm_pointer;
|
||||
|
||||
*status = module->SetCompressor(value);
|
||||
}
|
||||
|
||||
|
||||
bool getCompressor(void *pcm_pointer, int32_t *status) {
|
||||
PCM *module = (PCM *)pcm_pointer;
|
||||
bool value;
|
||||
|
||||
@@ -93,19 +93,6 @@ CTR_Code PCM::SetClosedLoopControl(bool en) {
|
||||
return CTR_OKAY;
|
||||
}
|
||||
|
||||
/* Set Compressor state
|
||||
*
|
||||
* @Return - void
|
||||
*
|
||||
* @Param - en - Enable / Disable compressor
|
||||
*/
|
||||
CTR_Code PCM::SetCompressor(bool en) {
|
||||
_PcmControl.compressorOn = en;
|
||||
if (GetTimeSinceLastTx() >= 50)
|
||||
return CTR_TxTimeout;
|
||||
return CTR_OKAY;
|
||||
}
|
||||
|
||||
/* Get solenoid state
|
||||
*
|
||||
* @Return - True/False - True if solenoid enabled, false otherwise
|
||||
@@ -158,21 +145,10 @@ CTR_Code PCM::GetClosedLoopControl(bool &status) {
|
||||
* @Return - Amperes - Compressor current
|
||||
*/
|
||||
CTR_Code PCM::GetCompressorCurrent(float &status) {
|
||||
uint8_t bt = _PcmStatus.compressorCurrentTop6;
|
||||
uint16_t bt = _PcmStatus.compressorCurrentTop6;
|
||||
bt <<= 4;
|
||||
bt |= _PcmStatus.compressorCurrentBtm4;
|
||||
status = 20.1612903225806 * bt;
|
||||
if (GetTimeSinceLastRx() >= 50)
|
||||
return CTR_RxTimeout;
|
||||
return CTR_OKAY;
|
||||
}
|
||||
|
||||
/* Get suggested compressor state determined by Closed Loop logic
|
||||
*
|
||||
* @Return - True/False - True if closed loop suggests enabling compressor, false if otherwise
|
||||
*/
|
||||
CTR_Code PCM::GetClosedLoopSuggestedOutput(bool &status) {
|
||||
status = _PcmStatus.closedLoopOutput;
|
||||
status = 0.0201612903225806 * bt;
|
||||
if (GetTimeSinceLastRx() >= 50)
|
||||
return CTR_RxTimeout;
|
||||
return CTR_OKAY;
|
||||
@@ -409,9 +385,6 @@ extern "C" {
|
||||
CTR_Code c_SetSolenoid(void * handle, unsigned char idx, INT8 param) {
|
||||
return ((PCM*) handle)->SetSolenoid(idx, param);
|
||||
}
|
||||
CTR_Code c_SetCompressor(void * handle, INT8 param) {
|
||||
return ((PCM*) handle)->SetCompressor(param);
|
||||
}
|
||||
CTR_Code c_SetClosedLoopControl(void * handle, INT8 param) {
|
||||
return ((PCM*) handle)->SetClosedLoopControl(param);
|
||||
}
|
||||
@@ -446,12 +419,6 @@ extern "C" {
|
||||
CTR_Code retval = ((PCM*) handle)->GetCompressorCurrent(*status);
|
||||
return retval;
|
||||
}
|
||||
CTR_Code c_GetClosedLoopSuggestedOutput(void * handle, INT8 * status) {
|
||||
bool bstatus;
|
||||
CTR_Code retval = ((PCM*) handle)->GetClosedLoopSuggestedOutput(bstatus);
|
||||
*status = bstatus;
|
||||
return retval;
|
||||
}
|
||||
|
||||
CTR_Code c_GetSolenoidVoltage(void * handle, float*status) {
|
||||
return ((PCM*) handle)->GetSolenoidVoltage(*status);
|
||||
|
||||
@@ -42,9 +42,8 @@ typedef struct _PcmControl_t{
|
||||
/* Byte 2 */
|
||||
unsigned solenoidBits:8;
|
||||
/* Byte 3*/
|
||||
unsigned reserved:4;
|
||||
unsigned closeLoopOutput:1;
|
||||
unsigned compressorOn:1;
|
||||
unsigned reserved:5;
|
||||
unsigned CompressorOn_deprecated:1; //!< This is ignored by PCM firm now.
|
||||
unsigned closedLoopEnable:1;
|
||||
unsigned clearStickyFaults:1;
|
||||
}PcmControl_t;
|
||||
@@ -78,34 +77,20 @@ public:
|
||||
~PCM();
|
||||
|
||||
/* Set PCM solenoid state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
*
|
||||
* @Param - idx - ID of solenoid (1-8)
|
||||
* @Param - en - Enable / Disable identified solenoid
|
||||
*/
|
||||
CTR_Code SetSolenoid(unsigned char idx, bool en);
|
||||
|
||||
/* Set Compressor state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
*
|
||||
* @Param - en - Enable / Disable compressor
|
||||
*/
|
||||
CTR_Code SetCompressor(bool en);
|
||||
|
||||
/* Enables PCM Closed Loop Control of Compressor via pressure switch
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
*
|
||||
* @Param - en - Enable / Disable Closed Loop Control
|
||||
*/
|
||||
CTR_Code SetClosedLoopControl(bool en);
|
||||
|
||||
/* Clears PCM sticky faults (indicators of past faults
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
*
|
||||
* @Param - clr - Clear / do not clear faults
|
||||
*/
|
||||
CTR_Code ClearStickyFaults(bool clr);
|
||||
@@ -113,107 +98,77 @@ public:
|
||||
/* Get solenoid state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - idx - ID of solenoid (1-8) to return status of
|
||||
*
|
||||
* @Param - status - True if solenoid enabled, false otherwise
|
||||
* @Param - status - True if solenoid output is set to be enabled, false otherwise.
|
||||
* If the phsyical output led still isn't on, then check webdash for
|
||||
* any faults/is PCM enabled.
|
||||
*/
|
||||
CTR_Code GetSolenoid(UINT8 idx, bool &status);
|
||||
|
||||
/* Get pressure switch state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if pressure adequate, false if low
|
||||
*/
|
||||
CTR_Code GetPressure(bool &status);
|
||||
|
||||
/* Get compressor state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if enabled, false if otherwise
|
||||
* @Param - status - True if compress ouput is on, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressor(bool &status);
|
||||
|
||||
/* Get closed loop control state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if closed loop enabled, false if otherwise
|
||||
*/
|
||||
CTR_Code GetClosedLoopControl(bool &status);
|
||||
|
||||
/* Get compressor current draw
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - Compressor current returned in Amperes (A)
|
||||
*/
|
||||
CTR_Code GetCompressorCurrent(float &status);
|
||||
|
||||
/* Get suggested compressor state determined by Closed Loop logic
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if closed loop suggests enabling compressor, false if otherwise
|
||||
*/
|
||||
CTR_Code GetClosedLoopSuggestedOutput(bool &status);
|
||||
|
||||
/* Get voltage across solenoid rail
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - Voltage across solenoid rail in Volts (V)
|
||||
*/
|
||||
CTR_Code GetSolenoidVoltage(float &status);
|
||||
|
||||
/* Get hardware fault value
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if hardware failure detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetHardwareFault(bool &status);
|
||||
|
||||
/* Get compressor fault value
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if shorted compressor detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorFault(bool &status);
|
||||
|
||||
/* Get solenoid fault value
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if shorted solenoid detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetSolenoidFault(bool &status);
|
||||
|
||||
/* Get compressor sticky fault value
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if solenoid had previously been shorted
|
||||
* (and sticky fault was not cleared), false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorStickyFault(bool &status);
|
||||
|
||||
/* Get solenoid sticky fault value
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - True if compressor had previously been shorted
|
||||
* (and sticky fault was not cleared), false if otherwise
|
||||
*/
|
||||
CTR_Code GetSolenoidStickyFault(bool &status);
|
||||
|
||||
/* Get battery voltage
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - Voltage across PCM power ports in Volts (V)
|
||||
*/
|
||||
CTR_Code GetBatteryVoltage(float &status);
|
||||
@@ -223,31 +178,7 @@ public:
|
||||
* @Param - deviceNumber - Device number of PCM to control
|
||||
*/
|
||||
void SetDeviceNumber(UINT8 deviceNumber);
|
||||
|
||||
/* Seek PCM Status Frames on CAN bus
|
||||
* @Return - void
|
||||
* @Param - en - Enable / Disable seeking of PCM Status Frame
|
||||
* @Notes - Status Frames identify
|
||||
*/
|
||||
void EnableSeekStatusFrames(bool en);
|
||||
|
||||
/* Seek PCM Status Fault Frames on CAN bus
|
||||
* @Return - void
|
||||
* @Param - en - Enable / Disable seeking of PCM Status Fault Frame
|
||||
* @Notes - Status Fault Frames identify Blacklisted Solenoids
|
||||
*/
|
||||
void EnableSeekStatusFaultFrames(bool en);
|
||||
|
||||
/* Seek PCM Debug Frames on CAN bus
|
||||
*
|
||||
* @Return - void
|
||||
* @Param - en - Enable / Disable seeking of PCM Debug Frame
|
||||
* @Notes - Debug Frames identify the number of failed tokens (for exclusive, secure control of PCM by RoboRIO)
|
||||
*/
|
||||
void EnableSeekDebugFrames(bool en);
|
||||
|
||||
/* Get number of total failed PCM Control Frame
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Number of failed control frames (tokenization fails)
|
||||
* @WARNING - Return only valid if [SeekDebugFrames] is enabled
|
||||
@@ -257,12 +188,9 @@ public:
|
||||
CTR_Code GetNumberOfFailedControlFrames(UINT16 &status);
|
||||
|
||||
/* Get raw Solenoid Blacklist
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - Raw binary breakdown of Solenoid Blacklist
|
||||
* BIT7 = Solenoid 1, BIT6 = Solenoid 2, etc.
|
||||
*
|
||||
* @WARNING - Return only valid if [SeekStatusFaultFrames] is enabled
|
||||
* See function SeekStatusFaultFrames
|
||||
* See function EnableSeekStatusFaultFrames
|
||||
@@ -271,13 +199,9 @@ public:
|
||||
|
||||
/* Get solenoid Blacklist status
|
||||
* - Blacklisted solenoids cannot be enabled until PCM is power cycled
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - idx - ID of solenoid
|
||||
*
|
||||
* @Param - status - True if Solenoid is blacklisted, false if otherwise
|
||||
*
|
||||
* @WARNING - Return only valid if [SeekStatusFaultFrames] is enabled
|
||||
* See function SeekStatusFaultFrames
|
||||
* See function EnableSeekStatusFaultFrames
|
||||
@@ -300,6 +224,27 @@ public:
|
||||
*/
|
||||
int GetTimeSinceLastRx(void) { return _timeSinceLastRx;}
|
||||
private:
|
||||
|
||||
/* Seek PCM Status Frames on CAN bus
|
||||
* @Return - void
|
||||
* @Param - en - Enable / Disable seeking of PCM Status Frame
|
||||
* @Notes - Status Frames identify
|
||||
*/
|
||||
void EnableSeekStatusFrames(bool en);
|
||||
|
||||
/* Seek PCM Status Fault Frames on CAN bus
|
||||
* @Return - void
|
||||
* @Param - en - Enable / Disable seeking of PCM Status Fault Frame
|
||||
* @Notes - Status Fault Frames identify Blacklisted Solenoids
|
||||
*/
|
||||
void EnableSeekStatusFaultFrames(bool en);
|
||||
|
||||
/* Seek PCM Debug Frames on CAN bus
|
||||
* @Return - void
|
||||
* @Param - en - Enable / Disable seeking of PCM Debug Frame
|
||||
* @Notes - Debug Frames identify the number of failed tokens (for exclusive, secure control of PCM by RoboRIO)
|
||||
*/
|
||||
void EnableSeekDebugFrames(bool en);
|
||||
/* frames to receive */
|
||||
PcmDebug_t _PcmDebug;
|
||||
PcmStatus_t _PcmStatus;
|
||||
@@ -337,7 +282,6 @@ private:
|
||||
extern "C" {
|
||||
void * c_PCM_Init(void);
|
||||
CTR_Code c_SetSolenoid(void * handle,unsigned char idx,INT8 param);
|
||||
CTR_Code c_SetCompressor(void * handle,INT8 param);
|
||||
CTR_Code c_SetClosedLoopControl(void * handle,INT8 param);
|
||||
CTR_Code c_ClearStickyFaults(void * handle,INT8 param);
|
||||
CTR_Code c_GetSolenoid(void * handle,UINT8 idx,INT8 * status);
|
||||
@@ -345,7 +289,6 @@ extern "C" {
|
||||
CTR_Code c_GetCompressor(void * handle,INT8 * status);
|
||||
CTR_Code c_GetClosedLoopControl(void * handle,INT8 * status);
|
||||
CTR_Code c_GetCompressorCurrent(void * handle,float * status);
|
||||
CTR_Code c_GetClosedLoopSuggestedOutput(void * handle,INT8 * status);
|
||||
CTR_Code c_GetSolenoidVoltage(void * handle,float*status);
|
||||
CTR_Code c_GetHardwareFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetCompressorFault(void * handle,INT8*status);
|
||||
|
||||
@@ -35,32 +35,19 @@ Compressor::~Compressor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the compressor and disables automatic closed-loop control
|
||||
* Starts closed-loop control
|
||||
*/
|
||||
void Compressor::Start() {
|
||||
SetClosedLoopControl(false);
|
||||
SetCompressor(true);
|
||||
SetClosedLoopControl(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the compressor and disables automatic closed-loop control
|
||||
* Stops closed-loop control
|
||||
*/
|
||||
void Compressor::Stop() {
|
||||
SetClosedLoopControl(false);
|
||||
SetCompressor(false);
|
||||
}
|
||||
|
||||
void Compressor::SetCompressor(bool on) {
|
||||
int32_t status = 0;
|
||||
|
||||
setCompressor(m_pcm_pointer, on, &status);
|
||||
|
||||
if(status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if the compressor is on
|
||||
*/
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,115 +1,102 @@
|
||||
#include "Log.hpp"
|
||||
#include "edu_wpi_first_wpilibj_hal_CompressorJNI.h"
|
||||
#include "HAL/HAL.hpp"
|
||||
|
||||
typedef void *VoidPointer;
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: initializeCompressor
|
||||
* Signature: (B)Ljava/nio/ByteBuffer;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor
|
||||
(JNIEnv *env, jclass, jbyte module)
|
||||
{
|
||||
VoidPointer *pcm_pointer = new VoidPointer;
|
||||
*pcm_pointer = initializeCompressor(module);
|
||||
|
||||
return env->NewDirectByteBuffer(pcm_pointer, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: checkCompressorModule
|
||||
* Signature: (B)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_checkCompressorModule
|
||||
(JNIEnv *env, jclass, jbyte module)
|
||||
{
|
||||
return checkCompressorModule(module);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: setCompressor
|
||||
* Signature: (Ljava/nio/ByteBuffer;ZLjava/nio/IntBuffer;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setCompressor
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jboolean value, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
setCompressor(*pcm_pointer, value, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: getCompressor
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
return getCompressor(*pcm_pointer, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: setClosedLoopControl
|
||||
* Signature: (Ljava/nio/ByteBuffer;ZLjava/nio/IntBuffer;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setClosedLoopControl
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jboolean value, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
setClosedLoopControl(*pcm_pointer, value, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: getClosedLoopControl
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getClosedLoopControl
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
return getClosedLoopControl(*pcm_pointer, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: getPressureSwitch
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getPressureSwitch
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
return getPressureSwitch(*pcm_pointer, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: getCompressorCurrent
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
return getCompressorCurrent(*pcm_pointer, status_pointer);
|
||||
}
|
||||
|
||||
#include "Log.hpp"
|
||||
#include "edu_wpi_first_wpilibj_hal_CompressorJNI.h"
|
||||
#include "HAL/HAL.hpp"
|
||||
|
||||
typedef void *VoidPointer;
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: initializeCompressor
|
||||
* Signature: (B)Ljava/nio/ByteBuffer;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor
|
||||
(JNIEnv *env, jclass, jbyte module)
|
||||
{
|
||||
VoidPointer *pcm_pointer = new VoidPointer;
|
||||
*pcm_pointer = initializeCompressor(module);
|
||||
|
||||
return env->NewDirectByteBuffer(pcm_pointer, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: checkCompressorModule
|
||||
* Signature: (B)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_checkCompressorModule
|
||||
(JNIEnv *env, jclass, jbyte module)
|
||||
{
|
||||
return checkCompressorModule(module);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: getCompressor
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
return getCompressor(*pcm_pointer, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: setClosedLoopControl
|
||||
* Signature: (Ljava/nio/ByteBuffer;ZLjava/nio/IntBuffer;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setClosedLoopControl
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jboolean value, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
setClosedLoopControl(*pcm_pointer, value, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: getClosedLoopControl
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getClosedLoopControl
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
return getClosedLoopControl(*pcm_pointer, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: getPressureSwitch
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getPressureSwitch
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
return getPressureSwitch(*pcm_pointer, status_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
|
||||
* Method: getCompressorCurrent
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent
|
||||
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
|
||||
{
|
||||
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
|
||||
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
|
||||
|
||||
return getCompressorCurrent(*pcm_pointer, status_pointer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user