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