001/* Copyright (C) Cross The Road Electronics 2024 */ 002package com.ctre.phoenix.sensors; 003 004/** 005 * Faults available to CANCoder (Currently has none) 006 * 007 * @deprecated This device's Phoenix 5 API is deprecated for removal in the 008 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the 009 * Phoenix 6 API. A migration guide is available at 010 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html. 011 * <p> 012 * If the Phoenix 5 API must be used for this device, the device must have 22.X 013 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in 014 * the firmware year dropdown. 015 */ 016@Deprecated(since = "2024", forRemoval = true) 017public class CANCoderFaults { 018 /** 019 * Device detects hardware failure 020 */ 021 public boolean HardwareFault; 022 /** 023 * API error detected. Make sure API and firmware versions are compatible. 024 */ 025 public boolean APIError; 026 /** 027 * Device is under 6.5V 028 */ 029 public boolean UnderVoltage; 030 /** 031 * Device was powered-on or reset while robot is enabled. 032 * Check your breakers and wiring. 033 */ 034 public boolean ResetDuringEn; 035 /** 036 * Magnet strength is too weak to provide reliable results 037 * Make sure CANCoder is close to the magnet being used 038 */ 039 public boolean MagnetTooWeak; 040 /** 041 * @return true if any faults are tripped 042 */ 043 public boolean hasAnyFault() { 044 return HardwareFault | 045 APIError | 046 UnderVoltage | 047 ResetDuringEn | 048 MagnetTooWeak; 049 } 050 /** 051 * @return Current fault list as a bit field 052 */ 053 public int toBitfield() { 054 int retval = 0; 055 int mask = 1; 056 retval |= HardwareFault ? mask : 0; mask <<= 1; 057 retval |= APIError ? mask : 0; mask <<= 1; 058 retval |= UnderVoltage ? mask : 0; mask <<= 1; 059 retval |= ResetDuringEn ? mask : 0; mask <<= 1; 060 mask <<= 3; /* 3 faults currently unused */ 061 retval |= MagnetTooWeak ? mask : 0; mask <<= 1; 062 return retval; 063 } 064 /** 065 * Updates current fault list with specified bit field of faults 066 * 067 * @param bits bit field of faults to update with 068 */ 069 public void update(int bits) { 070 int mask = 1; 071 HardwareFault = (bits & mask) != 0; mask <<= 1; 072 APIError = (bits & mask) != 0; mask <<= 1; 073 UnderVoltage = (bits & mask) != 0; mask <<= 1; 074 ResetDuringEn = (bits & mask) != 0; mask <<= 1; 075 mask <<= 3; /* 3 faults currently unused */ 076 MagnetTooWeak = (bits & mask) != 0; mask <<= 1; 077 } 078 public CANCoderFaults() { 079 } 080};