001/*----------------------------------------------------------------------------*/
002/* Copyright (c) FIRST 2008-2017. 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 SensorBase {
017
018  protected final byte m_moduleNumber; // The number of the solenoid module being used.
019
020  /**
021   * Constructor.
022   *
023   * @param moduleNumber The PCM CAN ID
024   */
025  public SolenoidBase(final int moduleNumber) {
026    m_moduleNumber = (byte) moduleNumber;
027  }
028
029  /**
030   * Read all 8 solenoids from the module used by this solenoid as a single byte.
031   *
032   * @return The current value of all 8 solenoids on this module.
033   */
034  public byte getAll() {
035    return SolenoidJNI.getAllSolenoids(m_moduleNumber);
036  }
037
038  /**
039   * Reads complete solenoid blacklist for all 8 solenoids as a single byte. If a solenoid is
040   * shorted, it is added to the blacklist and disabled until power cycle, or until faults are
041   * cleared.
042   *
043   * @return The solenoid blacklist of all 8 solenoids on the module.
044   * @see #clearAllPCMStickyFaults()
045   */
046  public byte getPCMSolenoidBlackList() {
047    return (byte) SolenoidJNI.getPCMSolenoidBlackList(m_moduleNumber);
048  }
049
050  /**
051   * If true, the common highside solenoid voltage rail is too low, most likely a solenoid channel
052   * is shorted.
053   *
054   * @return true if PCM sticky fault is set
055   */
056  public boolean getPCMSolenoidVoltageStickyFault() {
057    return SolenoidJNI.getPCMSolenoidVoltageStickyFault(m_moduleNumber);
058  }
059
060  /**
061   * The common highside solenoid voltage rail is too low, most likely a solenoid channel is
062   * shorted.
063   *
064   * @return true if PCM is in fault state.
065   */
066  public boolean getPCMSolenoidVoltageFault() {
067    return SolenoidJNI.getPCMSolenoidVoltageFault(m_moduleNumber);
068  }
069
070  /**
071   * Clear ALL sticky faults inside PCM that Compressor is wired to.
072   *
073   * <p>If a sticky fault is set, then it will be persistently cleared. Compressor drive maybe
074   * momentarily disable while flags are being cleared. Care should be taken to not call this too
075   * frequently, otherwise normal compressor functionality may be prevented.
076   *
077   * <p>If no sticky faults are set then this call will have no effect.
078   */
079  public void clearAllPCMStickyFaults() {
080    SolenoidJNI.clearAllPCMStickyFaults(m_moduleNumber);
081  }
082}