001/* Copyright (C) Cross The Road Electronics 2024 */ 002package com.ctre.phoenix.sensors; 003 004/** 005 * Sticky 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 */ 012@Deprecated(since = "2024", forRemoval = true) 013public class CANCoderStickyFaults { 014 /** 015 * Device detects hardware failure 016 */ 017 public boolean HardwareFault; 018 /** 019 * API error detected. Make sure API and firmware versions are compatible. 020 */ 021 public boolean APIError; 022 /** 023 * Device is under 6.5V 024 */ 025 public boolean UnderVoltage; 026 /** 027 * Device was powered-on or reset while robot is enabled. 028 * Check your breakers and wiring. 029 */ 030 public boolean ResetDuringEn; 031 /** 032 * Magnet strength is too weak to provide reliable results 033 * Make sure CANCoder is close to the magnet being used 034 */ 035 public boolean MagnetTooWeak; 036 /** 037 * @return true if any faults are tripped 038 */ 039 public boolean hasAnyFault() { 040 return HardwareFault | 041 APIError | 042 UnderVoltage | 043 ResetDuringEn | 044 MagnetTooWeak; 045 } 046 /** 047 * @return Current fault list as a bit field 048 */ 049 public int toBitfield() { 050 int retval = 0; 051 int mask = 1; 052 retval |= HardwareFault ? mask : 0; mask <<= 1; 053 retval |= APIError ? mask : 0; mask <<= 1; 054 retval |= UnderVoltage ? mask : 0; mask <<= 1; 055 retval |= ResetDuringEn ? mask : 0; mask <<= 1; 056 mask <<= 3; /* 3 faults currently unused */ 057 retval |= MagnetTooWeak ? mask : 0; mask <<= 1; 058 return retval; 059 } 060 /** 061 * Updates current sticky fault list with specified bit field of faults 062 * 063 * @param bits bit field of sticky faults to update with 064 */ 065 public void update(int bits) { 066 int mask = 1; 067 HardwareFault = (bits & mask) != 0; mask <<= 1; 068 APIError = (bits & mask) != 0; mask <<= 1; 069 UnderVoltage = (bits & mask) != 0; mask <<= 1; 070 ResetDuringEn = (bits & mask) != 0; mask <<= 1; 071 mask <<= 3; /* 3 faults currently unused */ 072 MagnetTooWeak = (bits & mask) != 0; mask <<= 1; 073 } 074 public CANCoderStickyFaults() { 075 } 076};