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.wpilibj.PneumaticsBase; 009import edu.wpi.first.wpilibj.PneumaticsModuleType; 010 011/** Common base class for pneumatics module simulation classes. */ 012public abstract class PneumaticsBaseSim { 013 protected final int m_index; 014 015 /** 016 * Get a module sim for a specific type. 017 * 018 * @param module the module number / CAN ID. 019 * @param type the module type. 020 * @return the module object. 021 */ 022 public static PneumaticsBaseSim getForType(int module, PneumaticsModuleType type) { 023 switch (type) { 024 case CTREPCM: 025 return new CTREPCMSim(module); 026 case REVPH: 027 return new REVPHSim(module); 028 default: 029 throw new IllegalArgumentException("Unknown module type"); 030 } 031 } 032 033 protected PneumaticsBaseSim(int index) { 034 m_index = index; 035 } 036 037 protected PneumaticsBaseSim(PneumaticsBase module) { 038 this(module.getModuleNumber()); 039 } 040 041 /** 042 * Check whether the PCM/PH has been initialized. 043 * 044 * @return true if initialized 045 */ 046 public abstract boolean getInitialized(); 047 048 /** 049 * Define whether the PCM/PH has been initialized. 050 * 051 * @param initialized true for initialized 052 */ 053 public abstract void setInitialized(boolean initialized); 054 055 /** 056 * Register a callback to be run when the PCM/PH is initialized. 057 * 058 * @param callback the callback 059 * @param initialNotify whether to run the callback with the initial state 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 abstract CallbackStore registerInitializedCallback( 064 NotifyCallback callback, boolean initialNotify); 065 066 /** 067 * Check if the compressor is on. 068 * 069 * @return true if the compressor is active 070 */ 071 public abstract boolean getCompressorOn(); 072 073 /** 074 * Set whether the compressor is active. 075 * 076 * @param compressorOn the new value 077 */ 078 public abstract void setCompressorOn(boolean compressorOn); 079 080 /** 081 * Register a callback to be run when the compressor activates. 082 * 083 * @param callback the callback 084 * @param initialNotify whether to run the callback with the initial state 085 * @return the {@link CallbackStore} object associated with this callback. Save a reference to 086 * this object so GC doesn't cancel the callback. 087 */ 088 public abstract CallbackStore registerCompressorOnCallback( 089 NotifyCallback callback, boolean initialNotify); 090 091 /** 092 * Check the solenoid output on a specific channel. 093 * 094 * @param channel the channel to check 095 * @return the solenoid output 096 */ 097 public abstract boolean getSolenoidOutput(int channel); 098 099 /** 100 * Change the solenoid output on a specific channel. 101 * 102 * @param channel the channel to check 103 * @param solenoidOutput the new solenoid output 104 */ 105 public abstract void setSolenoidOutput(int channel, boolean solenoidOutput); 106 107 /** 108 * Register a callback to be run when the solenoid output on a channel changes. 109 * 110 * @param channel the channel to monitor 111 * @param callback the callback 112 * @param initialNotify should the callback be run with the initial value 113 * @return the {@link CallbackStore} object associated with this callback. Save a reference to 114 * this object so GC doesn't cancel the callback. 115 */ 116 public abstract CallbackStore registerSolenoidOutputCallback( 117 int channel, NotifyCallback callback, boolean initialNotify); 118 119 /** 120 * Check the value of the pressure switch. 121 * 122 * @return the pressure switch value 123 */ 124 public abstract boolean getPressureSwitch(); 125 126 /** 127 * Set the value of the pressure switch. 128 * 129 * @param pressureSwitch the new value 130 */ 131 public abstract void setPressureSwitch(boolean pressureSwitch); 132 133 /** 134 * Register a callback to be run whenever the pressure switch value changes. 135 * 136 * @param callback the callback 137 * @param initialNotify whether the callback should be called with the initial value 138 * @return the {@link CallbackStore} object associated with this callback. Save a reference to 139 * this object so GC doesn't cancel the callback. 140 */ 141 public abstract CallbackStore registerPressureSwitchCallback( 142 NotifyCallback callback, boolean initialNotify); 143 144 /** 145 * Read the compressor current. 146 * 147 * @return the current of the compressor connected to this module 148 */ 149 public abstract double getCompressorCurrent(); 150 151 /** 152 * Set the compressor current. 153 * 154 * @param compressorCurrent the new compressor current 155 */ 156 public abstract void setCompressorCurrent(double compressorCurrent); 157 158 /** 159 * Register a callback to be run whenever the compressor current changes. 160 * 161 * @param callback the callback 162 * @param initialNotify whether to call the callback with the initial state 163 * @return the {@link CallbackStore} object associated with this callback. Save a reference to 164 * this object so GC doesn't cancel the callback. 165 */ 166 public abstract CallbackStore registerCompressorCurrentCallback( 167 NotifyCallback callback, boolean initialNotify); 168 169 /** Reset all simulation data for this object. */ 170 public abstract void resetData(); 171}