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