001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.wpilibj.simulation; 006 007import edu.wpi.first.hal.simulation.NotifyCallback; 008import edu.wpi.first.hal.simulation.REVPHDataJNI; 009import edu.wpi.first.wpilibj.PneumaticHub; 010import edu.wpi.first.wpilibj.SensorUtil; 011 012/** Class to control a simulated PneumaticHub (PH). */ 013public class REVPHSim extends PneumaticsBaseSim { 014 /** Constructs for the default PH. */ 015 public REVPHSim() { 016 super(SensorUtil.getDefaultREVPHModule()); 017 } 018 019 /** 020 * Constructs from a PH module number (CAN ID). 021 * 022 * @param module module number 023 */ 024 public REVPHSim(int module) { 025 super(module); 026 } 027 028 /** 029 * Constructs from a PneumaticHum object. 030 * 031 * @param module PCM module to simulate 032 */ 033 public REVPHSim(PneumaticHub module) { 034 super(module); 035 } 036 037 /** 038 * Check whether the closed loop compressor control is active. 039 * 040 * @return config type 041 */ 042 public int getCompressorConfigType() { 043 return REVPHDataJNI.getCompressorConfigType(m_index); 044 } 045 046 /** 047 * Turn on/off the closed loop control of the compressor. 048 * 049 * @param compressorConfigType compressor config type 050 */ 051 public void setCompressorConfigType(int compressorConfigType) { 052 REVPHDataJNI.setCompressorConfigType(m_index, compressorConfigType); 053 } 054 055 /** 056 * Register a callback to be run whenever the closed loop state changes. 057 * 058 * @param callback the callback 059 * @param initialNotify whether the callback should be called with the initial value 060 * @return the {@link CallbackStore} object associated with this callback. Save a reference to 061 * this object so GC doesn't cancel the callback. 062 */ 063 public CallbackStore registerCompressorConfigTypeCallback( 064 NotifyCallback callback, boolean initialNotify) { 065 int uid = REVPHDataJNI.registerCompressorConfigTypeCallback(m_index, callback, initialNotify); 066 return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorConfigTypeCallback); 067 } 068 069 @Override 070 public boolean getInitialized() { 071 return REVPHDataJNI.getInitialized(m_index); 072 } 073 074 @Override 075 public void setInitialized(boolean initialized) { 076 REVPHDataJNI.setInitialized(m_index, initialized); 077 } 078 079 @Override 080 public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { 081 int uid = REVPHDataJNI.registerInitializedCallback(m_index, callback, initialNotify); 082 return new CallbackStore(m_index, uid, REVPHDataJNI::cancelInitializedCallback); 083 } 084 085 @Override 086 public boolean getCompressorOn() { 087 return REVPHDataJNI.getCompressorOn(m_index); 088 } 089 090 @Override 091 public void setCompressorOn(boolean compressorOn) { 092 REVPHDataJNI.setCompressorOn(m_index, compressorOn); 093 } 094 095 @Override 096 public CallbackStore registerCompressorOnCallback( 097 NotifyCallback callback, boolean initialNotify) { 098 int uid = REVPHDataJNI.registerCompressorOnCallback(m_index, callback, initialNotify); 099 return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorOnCallback); 100 } 101 102 @Override 103 public boolean getSolenoidOutput(int channel) { 104 return REVPHDataJNI.getSolenoidOutput(m_index, channel); 105 } 106 107 @Override 108 public void setSolenoidOutput(int channel, boolean solenoidOutput) { 109 REVPHDataJNI.setSolenoidOutput(m_index, channel, solenoidOutput); 110 } 111 112 @Override 113 public CallbackStore registerSolenoidOutputCallback( 114 int channel, NotifyCallback callback, boolean initialNotify) { 115 int uid = 116 REVPHDataJNI.registerSolenoidOutputCallback(m_index, channel, callback, initialNotify); 117 return new CallbackStore(m_index, channel, uid, REVPHDataJNI::cancelSolenoidOutputCallback); 118 } 119 120 @Override 121 public boolean getPressureSwitch() { 122 return REVPHDataJNI.getPressureSwitch(m_index); 123 } 124 125 @Override 126 public void setPressureSwitch(boolean pressureSwitch) { 127 REVPHDataJNI.setPressureSwitch(m_index, pressureSwitch); 128 } 129 130 @Override 131 public CallbackStore registerPressureSwitchCallback( 132 NotifyCallback callback, boolean initialNotify) { 133 int uid = REVPHDataJNI.registerPressureSwitchCallback(m_index, callback, initialNotify); 134 return new CallbackStore(m_index, uid, REVPHDataJNI::cancelPressureSwitchCallback); 135 } 136 137 @Override 138 public double getCompressorCurrent() { 139 return REVPHDataJNI.getCompressorCurrent(m_index); 140 } 141 142 @Override 143 public void setCompressorCurrent(double compressorCurrent) { 144 REVPHDataJNI.setCompressorCurrent(m_index, compressorCurrent); 145 } 146 147 @Override 148 public CallbackStore registerCompressorCurrentCallback( 149 NotifyCallback callback, boolean initialNotify) { 150 int uid = REVPHDataJNI.registerCompressorCurrentCallback(m_index, callback, initialNotify); 151 return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorCurrentCallback); 152 } 153 154 @Override 155 public void resetData() { 156 REVPHDataJNI.resetData(m_index); 157 } 158}