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;
006
007public interface PneumaticsBase extends AutoCloseable {
008  /**
009   * For internal use to get a module for a specific type.
010   *
011   * @param module module number
012   * @param type module type
013   * @return module
014   */
015  static PneumaticsBase getForType(int module, PneumaticsModuleType type) {
016    if (type == PneumaticsModuleType.CTREPCM) {
017      return new PneumaticsControlModule(module);
018    } else if (type == PneumaticsModuleType.REVPH) {
019      return new PneumaticHub(module);
020    }
021    throw new IllegalArgumentException("Unknown module type");
022  }
023
024  /**
025   * For internal use to get the default for a specific type.
026   *
027   * @param type module type
028   * @return module default
029   */
030  static int getDefaultForType(PneumaticsModuleType type) {
031    if (type == PneumaticsModuleType.CTREPCM) {
032      return SensorUtil.getDefaultCTREPCMModule();
033    } else if (type == PneumaticsModuleType.REVPH) {
034      return SensorUtil.getDefaultREVPHModule();
035    }
036    throw new IllegalArgumentException("Unknown module type");
037  }
038
039  /**
040   * Sets solenoids on a pneumatics module.
041   *
042   * @param mask mask
043   * @param values values
044   */
045  void setSolenoids(int mask, int values);
046
047  /**
048   * Gets solenoid values.
049   *
050   * @return values
051   */
052  int getSolenoids();
053
054  /**
055   * Get module number for this module.
056   *
057   * @return module number
058   */
059  int getModuleNumber();
060
061  /**
062   * Get the disabled solenoids.
063   *
064   * @return disabled list
065   */
066  int getSolenoidDisabledList();
067
068  /**
069   * Fire a single solenoid shot.
070   *
071   * @param index solenoid index
072   */
073  void fireOneShot(int index);
074
075  /**
076   * Set the duration for a single solenoid shot.
077   *
078   * @param index solenoid index
079   * @param durMs shot duration
080   */
081  void setOneShotDuration(int index, int durMs);
082
083  boolean getCompressor();
084
085  boolean getPressureSwitch();
086
087  double getCompressorCurrent();
088
089  void disableCompressor();
090
091  void enableCompressorDigital();
092
093  void enableCompressorAnalog(double minPressure, double maxPressure);
094
095  void enableCompressorHybrid(double minPressure, double maxPressure);
096
097  double getAnalogVoltage(int channel);
098
099  double getPressure(int channel);
100
101  CompressorConfigType getCompressorConfigType();
102
103  /**
104   * Check if a solenoid channel is valid.
105   *
106   * @param channel Channel to check
107   * @return True if channel exists
108   */
109  boolean checkSolenoidChannel(int channel);
110
111  /**
112   * Check to see if the masked solenoids can be reserved, and if not reserve them.
113   *
114   * @param mask The solenoid mask to reserve
115   * @return 0 if successful, mask of solenoids that couldn't be allocated otherwise
116   */
117  int checkAndReserveSolenoids(int mask);
118
119  /**
120   * Unreserve the masked solenoids.
121   *
122   * @param mask The solenoid mask to unreserve
123   */
124  void unreserveSolenoids(int mask);
125
126  boolean reserveCompressor();
127
128  void unreserveCompressor();
129
130  @Override
131  void close();
132
133  Solenoid makeSolenoid(int channel);
134
135  DoubleSolenoid makeDoubleSolenoid(int forwardChannel, int reverseChannel);
136
137  Compressor makeCompressor();
138}