001    /*----------------------------------------------------------------------------*/
002    /* Copyright (c) FIRST 2008-2012. All Rights Reserved.                        */
003    /* Open Source Software - may be modified and shared by FRC teams. The code   */
004    /* must be accompanied by the FIRST BSD license file in the root directory of */
005    /* the project.                                                               */
006    /*----------------------------------------------------------------------------*/
007    
008    package edu.wpi.first.wpilibj;
009    
010    import edu.wpi.first.wpilibj.communication.UsageReporting;
011    import edu.wpi.first.wpilibj.livewindow.LiveWindow;
012    import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
013    import edu.wpi.first.wpilibj.parsing.ISensor;
014    import edu.wpi.first.wpilibj.tables.ITable;
015    
016    /**
017     * Alias for counter class.
018     * Implement the gear tooth sensor supplied by FIRST. Currently there is no reverse sensing on
019     * the gear tooth sensor, but in future versions we might implement the necessary timing in the
020     * FPGA to sense direction.
021     */
022    public class GearTooth extends Counter implements ISensor {
023    
024        private static final double kGearToothThreshold = 55e-6;
025    
026        /**
027         * Common code called by the constructors.
028         */
029        public void enableDirectionSensing(boolean directionSensitive) {
030            if (directionSensitive) {
031                setPulseLengthMode(kGearToothThreshold);
032            }
033        }
034    
035        /**
036         * Construct a GearTooth sensor given a channel.
037         *
038         * The default module is assumed.
039         *
040         * @param channel The GPIO channel on the digital module that the sensor is connected to.
041         * @param directionSensitive Enable the pulse length decoding in hardware to specify count direction.
042         */
043        public GearTooth(final int channel, boolean directionSensitive) {
044            super(channel);
045            enableDirectionSensing(directionSensitive);
046            if(directionSensitive){
047            UsageReporting.report(UsageReporting.kResourceType_GearTooth, channel, DigitalModule.getDefaultDigitalModule()-1, "D");
048            }else{
049            UsageReporting.report(UsageReporting.kResourceType_GearTooth, channel, DigitalModule.getDefaultDigitalModule()-1);
050            }
051        }
052    
053        /**
054         * Construct a GearTooth sensor given a channel.
055         *
056         * The default module is assumed.
057         * No direction sensing is assumed.
058         *
059         * @param channel The GPIO channel on the digital module that the sensor is connected to.
060         */
061        public GearTooth(final int channel) {
062            this(channel,false);
063        }
064    
065        /**
066         * Construct a GearTooth sensor given a channel and module.
067         *
068         * @param slot The slot in the chassis that the digital module is plugged in to.
069         * @param channel The GPIO channel on the digital module that the sensor is connected to.
070         * @param directionSensitive Enable the pulse length decoding in hardware to specify count direction.
071         */
072        public GearTooth(final int slot, final int channel, boolean directionSensitive) {
073            super(slot, channel);
074            enableDirectionSensing(directionSensitive);
075            if(directionSensitive) {
076                UsageReporting.report(UsageReporting.kResourceType_GearTooth, channel, DigitalModule.getDefaultDigitalModule()-1, "D");
077            }
078            else {
079                UsageReporting.report(UsageReporting.kResourceType_GearTooth, channel, DigitalModule.getDefaultDigitalModule()-1);
080            }
081            LiveWindow.addSensor("GearTooth", slot, channel, this);
082        }
083    
084        /**
085         * Construct a GearTooth sensor given a channel and module.
086         *
087         * No direction sensing is assumed.
088         *
089         * @param slot The slot in the chassis that the digital module is plugged in to.
090         * @param channel The GPIO channel on the digital module that the sensor is connected to.
091         */
092        public GearTooth(final int slot, final int channel) {
093            this(slot, channel,false);
094        }
095    
096        /**
097         * Construct a GearTooth sensor given a digital input.
098         * This should be used when sharing digial inputs.
099         *
100         * @param source An object that fully descibes the input that the sensor is connected to.
101         * @param directionSensitive Enable the pulse length decoding in hardware to specify count direction.
102         */
103        public GearTooth(DigitalSource source, boolean directionSensitive) {
104            super(source);
105            enableDirectionSensing(directionSensitive);
106        }
107    
108        /**
109         * Construct a GearTooth sensor given a digital input.
110         * This should be used when sharing digial inputs.
111         *
112         * No direction sensing is assumed.
113         *
114         * @param source An object that fully descibes the input that the sensor is connected to.
115         */
116        public GearTooth(DigitalSource source) {
117            this(source,false);
118        }
119    
120        /*
121         * Live Window code, only does anything if live window is activated.
122         */
123        public String getSmartDashboardType(){
124            return "Gear Tooth";
125        }
126    }