WPILib 2012
WPILibRoboticsLibraryforFRC
|
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #ifndef CPPCOUNTER_H_ 00008 #define CPPCOUNTER_H_ 00009 00010 #include "AnalogTriggerOutput.h" 00011 #include "CounterBase.h" 00012 #include "SensorBase.h" 00013 00020 class Counter : public SensorBase, public CounterBase 00021 { 00022 public: 00023 typedef enum {kTwoPulse=0, kSemiperiod=1, kPulseLength=2, kExternalDirection=3} Mode; 00024 00025 Counter(); 00026 explicit Counter(UINT32 channel); 00027 Counter(UINT8 moduleNumber, UINT32 channel); 00028 explicit Counter(DigitalSource *source); 00029 explicit Counter(DigitalSource &source); 00030 explicit Counter(AnalogTrigger *trigger); 00031 explicit Counter(AnalogTrigger &trigger); 00032 Counter(EncodingType encodingType, DigitalSource *upSource, DigitalSource *downSource, bool inverted); 00033 virtual ~Counter(); 00034 00035 void SetUpSource(UINT32 channel); 00036 void SetUpSource(UINT8 moduleNumber, UINT32 channel); 00037 void SetUpSource(AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType); 00038 void SetUpSource(AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType); 00039 void SetUpSource(DigitalSource *source); 00040 void SetUpSource(DigitalSource &source); 00041 void SetUpSourceEdge(bool risingEdge, bool fallingEdge); 00042 void ClearUpSource(); 00043 00044 void SetDownSource(UINT32 channel); 00045 void SetDownSource(UINT8 moduleNumber, UINT32 channel); 00046 void SetDownSource(AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType); 00047 void SetDownSource(AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType); 00048 void SetDownSource(DigitalSource *source); 00049 void SetDownSource(DigitalSource &source); 00050 void SetDownSourceEdge(bool risingEdge, bool fallingEdge); 00051 void ClearDownSource(); 00052 00053 void SetUpDownCounterMode(); 00054 void SetExternalDirectionMode(); 00055 void SetSemiPeriodMode(bool highSemiPeriod); 00056 void SetPulseLengthMode(float threshold); 00057 00058 void SetReverseDirection(bool reverseDirection); 00059 00060 // CounterBase interface 00061 void Start(); 00062 INT32 Get(); 00063 void Reset(); 00064 void Stop(); 00065 double GetPeriod(); 00066 void SetMaxPeriod(double maxPeriod); 00067 void SetUpdateWhenEmpty(bool enabled); 00068 bool GetStopped(); 00069 bool GetDirection(); 00070 private: 00071 void InitCounter(Mode mode = kTwoPulse); 00072 00073 DigitalSource *m_upSource; 00074 DigitalSource *m_downSource; 00075 bool m_allocatedUpSource; 00076 bool m_allocatedDownSource; 00077 tCounter *m_counter; 00078 UINT32 m_index; 00079 }; 00080 00081 #endif