001/*----------------------------------------------------------------------------*/
002/* Copyright (c) 2008-2018 FIRST. All Rights Reserved.                        */
003/* Open Source Software - may be modified and shared by FRC teams. The code   */
004/* must be accompanied by the FIRST BSD license file in the root directory of */
005/* the project.                                                               */
006/*----------------------------------------------------------------------------*/
007
008package edu.wpi.first.wpilibj;
009
010import edu.wpi.first.wpilibj.hal.SolenoidJNI;
011
012/**
013 * SolenoidBase class is the common base class for the {@link Solenoid} and {@link DoubleSolenoid}
014 * classes.
015 */
016public abstract class SolenoidBase extends SendableBase {
017  protected final int m_moduleNumber; // The number of the solenoid module being used.
018
019  /**
020   * Constructor.
021   *
022   * @param moduleNumber The PCM CAN ID
023   */
024  public SolenoidBase(final int moduleNumber) {
025    m_moduleNumber = moduleNumber;
026  }
027
028  /**
029   * Read all 8 solenoids from the specified module as a single byte.
030   *
031   * @param moduleNumber the module number to read
032   * @return The current value of all 8 solenoids on the module.
033   */
034  public static int getAll(int moduleNumber) {
035    return SolenoidJNI.getAllSolenoids(moduleNumber);
036  }
037
038  /**
039   * Read all 8 solenoids from the module used by this solenoid as a single byte.
040   *
041   * @return The current value of all 8 solenoids on this module.
042   */
043  public int getAll() {
044    return SolenoidBase.getAll(m_moduleNumber);
045  }
046
047  /**
048   * Reads complete solenoid blacklist for all 8 solenoids as a single byte. If a solenoid is
049   * shorted, it is added to the blacklist and disabled until power cycle, or until faults are
050   * cleared.
051   *
052   * @param moduleNumber the module number to read
053   * @return The solenoid blacklist of all 8 solenoids on the module.
054   * @see #clearAllPCMStickyFaults()
055   */
056  public static int getPCMSolenoidBlackList(int moduleNumber) {
057    return SolenoidJNI.getPCMSolenoidBlackList(moduleNumber);
058  }
059
060  /**
061   * Reads complete solenoid blacklist for all 8 solenoids as a single byte. If a solenoid is
062   * shorted, it is added to the blacklist and disabled until power cycle, or until faults are
063   * cleared.
064   *
065   * @return The solenoid blacklist of all 8 solenoids on the module.
066   * @see #clearAllPCMStickyFaults()
067   */
068  public int getPCMSolenoidBlackList() {
069    return SolenoidBase.getPCMSolenoidBlackList(m_moduleNumber);
070  }
071
072  /**
073   * If true, the common highside solenoid voltage rail is too low, most likely a solenoid channel
074   * is shorted.
075   *
076   * @param moduleNumber the module number to read
077   * @return true if PCM sticky fault is set
078   */
079  public static boolean getPCMSolenoidVoltageStickyFault(int moduleNumber) {
080    return SolenoidJNI.getPCMSolenoidVoltageStickyFault(moduleNumber);
081  }
082
083  /**
084   * If true, the common highside solenoid voltage rail is too low, most likely a solenoid channel
085   * is shorted.
086   *
087   * @return true if PCM sticky fault is set
088   */
089  public boolean getPCMSolenoidVoltageStickyFault() {
090    return SolenoidBase.getPCMSolenoidVoltageStickyFault(m_moduleNumber);
091  }
092
093  /**
094   * The common highside solenoid voltage rail is too low, most likely a solenoid channel is
095   * shorted.
096   *
097   * @param moduleNumber the module number to read
098   * @return true if PCM is in fault state.
099   */
100  public static boolean getPCMSolenoidVoltageFault(int moduleNumber) {
101    return SolenoidJNI.getPCMSolenoidVoltageFault(moduleNumber);
102  }
103
104  /**
105   * The common highside solenoid voltage rail is too low, most likely a solenoid channel is
106   * shorted.
107   *
108   * @return true if PCM is in fault state.
109   */
110  public boolean getPCMSolenoidVoltageFault() {
111    return SolenoidBase.getPCMSolenoidVoltageFault(m_moduleNumber);
112  }
113
114  /**
115   * Clear ALL sticky faults inside PCM that Compressor is wired to.
116   *
117   * <p>If a sticky fault is set, then it will be persistently cleared. Compressor drive maybe
118   * momentarily disable while flags are being cleared. Care should be taken to not call this too
119   * frequently, otherwise normal compressor functionality may be prevented.
120   *
121   * <p>If no sticky faults are set then this call will have no effect.
122   *
123   * @param moduleNumber the module number to read
124   */
125  public static void clearAllPCMStickyFaults(int moduleNumber) {
126    SolenoidJNI.clearAllPCMStickyFaults(moduleNumber);
127  }
128
129  /**
130   * Clear ALL sticky faults inside PCM that Compressor is wired to.
131   *
132   * <p>If a sticky fault is set, then it will be persistently cleared. Compressor drive maybe
133   * momentarily disable while flags are being cleared. Care should be taken to not call this too
134   * frequently, otherwise normal compressor functionality may be prevented.
135   *
136   * <p>If no sticky faults are set then this call will have no effect.
137   */
138  public void clearAllPCMStickyFaults() {
139    SolenoidBase.clearAllPCMStickyFaults(m_moduleNumber);
140  }
141}