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 008package edu.wpi.first.wpilibj; 009 010import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; 011import edu.wpi.first.wpilibj.communication.UsageReporting; 012import edu.wpi.first.wpilibj.livewindow.LiveWindow; 013 014/** 015 * Alias for counter class. 016 * Implement the gear tooth sensor supplied by FIRST. Currently there is no reverse sensing on 017 * the gear tooth sensor, but in future versions we might implement the necessary timing in the 018 * FPGA to sense direction. 019 */ 020public class GearTooth extends Counter { 021 022 private static final double kGearToothThreshold = 55e-6; 023 024 /** 025 * Common code called by the constructors. 026 */ 027 public void enableDirectionSensing(boolean directionSensitive) { 028 if (directionSensitive) { 029 setPulseLengthMode(kGearToothThreshold); 030 } 031 } 032 033 /** 034 * Construct a GearTooth sensor given a channel. 035 * 036 * No direction sensing is assumed. 037 * 038 * @param channel The GPIO channel that the sensor is connected to. 039 */ 040 public GearTooth(final int channel) { 041 this(channel,false); 042 } 043 044 /** 045 * Construct a GearTooth sensor given a channel. 046 * 047 * @param channel The DIO channel that the sensor is connected to. 0-9 are on-board, 10-25 are on the MXP port 048 * @param directionSensitive True to enable the pulse length decoding in hardware to specify count direction. 049 */ 050 public GearTooth(final int channel, boolean directionSensitive) { 051 super(channel); 052 enableDirectionSensing(directionSensitive); 053 if(directionSensitive) { 054 UsageReporting.report(tResourceType.kResourceType_GearTooth, channel, 0, "D"); 055 } else { 056 UsageReporting.report(tResourceType.kResourceType_GearTooth, channel, 0); 057 } 058 LiveWindow.addSensor("GearTooth", channel, this); 059 } 060 061 /** 062 * Construct a GearTooth sensor given a digital input. 063 * This should be used when sharing digital inputs. 064 * 065 * @param source An existing DigitalSource object (such as a DigitalInput) 066 * @param directionSensitive True to enable the pulse length decoding in hardware to specify count direction. 067 */ 068 public GearTooth(DigitalSource source, boolean directionSensitive) { 069 super(source); 070 enableDirectionSensing(directionSensitive); 071 } 072 073 /** 074 * Construct a GearTooth sensor given a digital input. 075 * This should be used when sharing digial inputs. 076 * 077 * No direction sensing is assumed. 078 * 079 * @param source An object that fully descibes the input that the sensor is connected to. 080 */ 081 public GearTooth(DigitalSource source) { 082 this(source,false); 083 } 084 085 /* 086 * Live Window code, only does anything if live window is activated. 087 */ 088 public String getSmartDashboardType() { 089 return "Gear Tooth"; 090 } 091}