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.hal;
006
007@SuppressWarnings("MemberName")
008public class REVPHFaults {
009  public final boolean Channel0Fault;
010
011  public final boolean Channel1Fault;
012
013  public final boolean Channel2Fault;
014
015  public final boolean Channel3Fault;
016
017  public final boolean Channel4Fault;
018
019  public final boolean Channel5Fault;
020
021  public final boolean Channel6Fault;
022
023  public final boolean Channel7Fault;
024
025  public final boolean Channel8Fault;
026
027  public final boolean Channel9Fault;
028
029  public final boolean Channel10Fault;
030
031  public final boolean Channel11Fault;
032
033  public final boolean Channel12Fault;
034
035  public final boolean Channel13Fault;
036
037  public final boolean Channel14Fault;
038
039  public final boolean Channel15Fault;
040
041  public final boolean CompressorOverCurrent;
042
043  public final boolean CompressorOpen;
044
045  public final boolean SolenoidOverCurrent;
046
047  public final boolean Brownout;
048
049  public final boolean CanWarning;
050
051  public final boolean HardwareFault;
052
053  /**
054   * Gets whether there is a fault at the specified channel.
055   *
056   * @param channel Channel to check for faults.
057   * @return True if a a fault exists at the channel, otherwise false.
058   * @throws IndexOutOfBoundsException if the provided channel is outside of the range supported by
059   *     the hardware.
060   */
061  public final boolean getChannelFault(int channel) {
062    switch (channel) {
063      case 0:
064        return Channel0Fault;
065      case 1:
066        return Channel1Fault;
067      case 2:
068        return Channel2Fault;
069      case 3:
070        return Channel3Fault;
071      case 4:
072        return Channel4Fault;
073      case 5:
074        return Channel5Fault;
075      case 6:
076        return Channel6Fault;
077      case 7:
078        return Channel7Fault;
079      case 8:
080        return Channel8Fault;
081      case 9:
082        return Channel9Fault;
083      case 10:
084        return Channel10Fault;
085      case 11:
086        return Channel11Fault;
087      case 12:
088        return Channel12Fault;
089      case 13:
090        return Channel13Fault;
091      case 14:
092        return Channel14Fault;
093      case 15:
094        return Channel15Fault;
095      default:
096        throw new IndexOutOfBoundsException("Pneumatics fault channel out of bounds!");
097    }
098  }
099
100  /**
101   * Called from HAL to construct.
102   *
103   * @param faults the fault bitfields
104   */
105  public REVPHFaults(int faults) {
106    Channel0Fault = (faults & (1 << 0)) != 0;
107    Channel1Fault = (faults & (1 << 1)) != 0;
108    Channel2Fault = (faults & (1 << 2)) != 0;
109    Channel3Fault = (faults & (1 << 3)) != 0;
110    Channel4Fault = (faults & (1 << 4)) != 0;
111    Channel5Fault = (faults & (1 << 5)) != 0;
112    Channel6Fault = (faults & (1 << 6)) != 0;
113    Channel7Fault = (faults & (1 << 7)) != 0;
114    Channel8Fault = (faults & (1 << 8)) != 0;
115    Channel9Fault = (faults & (1 << 9)) != 0;
116    Channel10Fault = (faults & (1 << 10)) != 0;
117    Channel11Fault = (faults & (1 << 11)) != 0;
118    Channel12Fault = (faults & (1 << 12)) != 0;
119    Channel13Fault = (faults & (1 << 13)) != 0;
120    Channel14Fault = (faults & (1 << 14)) != 0;
121    Channel15Fault = (faults & (1 << 15)) != 0;
122    CompressorOverCurrent = (faults & (1 << 16)) != 0;
123    CompressorOpen = (faults & (1 << 17)) != 0;
124    SolenoidOverCurrent = (faults & (1 << 18)) != 0;
125    Brownout = (faults & (1 << 19)) != 0;
126    CanWarning = (faults & (1 << 20)) != 0;
127    HardwareFault = (faults & (1 << 21)) != 0;
128  }
129}