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 /**
011 * Interface for counting the number of ticks on a digital input channel.
012 * Encoders, Gear tooth sensors, and counters should all subclass this so it can be used to
013 * build more advanced classes for control and driving.
014 */
015 public interface CounterBase {
016
017 /**
018 * The number of edges for the counterbase to increment or decrement on
019 */
020 public static class EncodingType {
021
022 /**
023 * The integer value representing this enumeration
024 */
025 public final int value;
026 static final int k1X_val = 0;
027 static final int k2X_val = 1;
028 static final int k4X_val = 2;
029 /**
030 * Count only the rising edge
031 */
032 public static final EncodingType k1X = new EncodingType(k1X_val);
033 /**
034 * Count both the rising and falling edge
035 */
036 public static final EncodingType k2X = new EncodingType(k2X_val);
037 /**
038 * Count rising and falling on both channels
039 */
040 public static final EncodingType k4X = new EncodingType(k4X_val);
041
042 private EncodingType(int value) {
043 this.value = value;
044 }
045 }
046
047 /**
048 * Start the counter
049 */
050 public void start();
051
052 /**
053 * Get the count
054 * @return the count
055 */
056 int get();
057
058 /**
059 * Reset the count to zero
060 */
061 void reset();
062
063 /**
064 * Stop counting
065 */
066 void stop();
067
068 /**
069 * Get the time between the last two edges counted
070 * @return the time beteween the last two ticks in seconds
071 */
072 double getPeriod();
073
074 /**
075 * Set the maximum time between edges to be considered stalled
076 * @param maxPeriod the maximum period in seconds
077 */
078 void setMaxPeriod(double maxPeriod);
079
080 /**
081 * Determine if the counter is not moving
082 * @return true if the counter has not changed for the max period
083 */
084 boolean getStopped();
085
086 /**
087 * Determine which direction the counter is going
088 * @return true for one direction, false for the other
089 */
090 boolean getDirection();
091 }