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 PowerDistributionFaults {
009  public final boolean Channel0BreakerFault;
010
011  public final boolean Channel1BreakerFault;
012
013  public final boolean Channel2BreakerFault;
014
015  public final boolean Channel3BreakerFault;
016
017  public final boolean Channel4BreakerFault;
018
019  public final boolean Channel5BreakerFault;
020
021  public final boolean Channel6BreakerFault;
022
023  public final boolean Channel7BreakerFault;
024
025  public final boolean Channel8BreakerFault;
026
027  public final boolean Channel9BreakerFault;
028
029  public final boolean Channel10BreakerFault;
030
031  public final boolean Channel11BreakerFault;
032
033  public final boolean Channel12BreakerFault;
034
035  public final boolean Channel13BreakerFault;
036
037  public final boolean Channel14BreakerFault;
038
039  public final boolean Channel15BreakerFault;
040
041  public final boolean Channel16BreakerFault;
042
043  public final boolean Channel17BreakerFault;
044
045  public final boolean Channel18BreakerFault;
046
047  public final boolean Channel19BreakerFault;
048
049  public final boolean Channel20BreakerFault;
050
051  public final boolean Channel21BreakerFault;
052
053  public final boolean Channel22BreakerFault;
054
055  public final boolean Channel23BreakerFault;
056
057  public final boolean Brownout;
058
059  public final boolean CanWarning;
060
061  public final boolean HardwareFault;
062
063  /**
064   * Gets whether there is a breaker fault at the specified channel.
065   *
066   * @param channel Channel to check for faults.
067   * @return True if there is a breaker fault at the channel, otherwise false.
068   * @throws IndexOutOfBoundsException if the provided channel is outside of the range supported by
069   *     the hardware.
070   */
071  public final boolean getBreakerFault(int channel) {
072    switch (channel) {
073      case 0:
074        return Channel0BreakerFault;
075      case 1:
076        return Channel1BreakerFault;
077      case 2:
078        return Channel2BreakerFault;
079      case 3:
080        return Channel3BreakerFault;
081      case 4:
082        return Channel4BreakerFault;
083      case 5:
084        return Channel5BreakerFault;
085      case 6:
086        return Channel6BreakerFault;
087      case 7:
088        return Channel7BreakerFault;
089      case 8:
090        return Channel8BreakerFault;
091      case 9:
092        return Channel9BreakerFault;
093      case 10:
094        return Channel10BreakerFault;
095      case 11:
096        return Channel11BreakerFault;
097      case 12:
098        return Channel12BreakerFault;
099      case 13:
100        return Channel13BreakerFault;
101      case 14:
102        return Channel14BreakerFault;
103      case 15:
104        return Channel15BreakerFault;
105      case 16:
106        return Channel16BreakerFault;
107      case 17:
108        return Channel17BreakerFault;
109      case 18:
110        return Channel18BreakerFault;
111      case 19:
112        return Channel19BreakerFault;
113      case 20:
114        return Channel20BreakerFault;
115      case 21:
116        return Channel21BreakerFault;
117      case 22:
118        return Channel22BreakerFault;
119      case 23:
120        return Channel23BreakerFault;
121      default:
122        throw new IndexOutOfBoundsException("Power distribution fault channel out of bounds!");
123    }
124  }
125
126  /**
127   * Constructs from a bitfield.
128   *
129   * @param faults faults
130   */
131  public PowerDistributionFaults(int faults) {
132    Channel0BreakerFault = (faults & 0x1) != 0;
133    Channel1BreakerFault = (faults & 0x2) != 0;
134    Channel2BreakerFault = (faults & 0x4) != 0;
135    Channel3BreakerFault = (faults & 0x8) != 0;
136    Channel4BreakerFault = (faults & 0x10) != 0;
137    Channel5BreakerFault = (faults & 0x20) != 0;
138    Channel6BreakerFault = (faults & 0x40) != 0;
139    Channel7BreakerFault = (faults & 0x80) != 0;
140    Channel8BreakerFault = (faults & 0x100) != 0;
141    Channel9BreakerFault = (faults & 0x200) != 0;
142    Channel10BreakerFault = (faults & 0x400) != 0;
143    Channel11BreakerFault = (faults & 0x800) != 0;
144    Channel12BreakerFault = (faults & 0x1000) != 0;
145    Channel13BreakerFault = (faults & 0x2000) != 0;
146    Channel14BreakerFault = (faults & 0x4000) != 0;
147    Channel15BreakerFault = (faults & 0x8000) != 0;
148    Channel16BreakerFault = (faults & 0x10000) != 0;
149    Channel17BreakerFault = (faults & 0x20000) != 0;
150    Channel18BreakerFault = (faults & 0x40000) != 0;
151    Channel19BreakerFault = (faults & 0x80000) != 0;
152    Channel20BreakerFault = (faults & 0x100000) != 0;
153    Channel21BreakerFault = (faults & 0x200000) != 0;
154    Channel22BreakerFault = (faults & 0x400000) != 0;
155    Channel23BreakerFault = (faults & 0x800000) != 0;
156    Brownout = (faults & 0x1000000) != 0;
157    CanWarning = (faults & 0x2000000) != 0;
158    HardwareFault = (faults & 0x4000000) != 0;
159  }
160}