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