blob: 210f12d77b01a23f51dce8d447bf66d5c2c1d1f0 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#include "GearTooth.h"
9
10#include "LiveWindow/LiveWindow.h"
11
12using namespace frc;
13
14constexpr double GearTooth::kGearToothThreshold;
15
16/**
17 * Common code called by the constructors.
18 */
19void GearTooth::EnableDirectionSensing(bool directionSensitive) {
20 if (directionSensitive) {
21 SetPulseLengthMode(kGearToothThreshold);
22 }
23}
24
25/**
26 * Construct a GearTooth sensor given a channel.
27 *
28 * @param channel The DIO channel that the sensor is connected to.
29 * 0-9 are on-board, 10-25 are on the MXP.
30 * @param directionSensitive True to enable the pulse length decoding in
31 * hardware to specify count direction.
32 */
33GearTooth::GearTooth(int channel, bool directionSensitive) : Counter(channel) {
34 EnableDirectionSensing(directionSensitive);
35 LiveWindow::GetInstance()->AddSensor("GearTooth", channel, this);
36}
37
38/**
39 * Construct a GearTooth sensor given a digital input.
40 *
41 * This should be used when sharing digital inputs.
42 *
43 * @param source A pointer to the existing DigitalSource object
44 * (such as a DigitalInput)
45 * @param directionSensitive True to enable the pulse length decoding in
46 * hardware to specify count direction.
47 */
48GearTooth::GearTooth(DigitalSource* source, bool directionSensitive)
49 : Counter(source) {
50 EnableDirectionSensing(directionSensitive);
51}
52
53/**
54 * Construct a GearTooth sensor given a digital input.
55 *
56 * This should be used when sharing digital inputs.
57 *
58 * @param source A reference to the existing DigitalSource object
59 * (such as a DigitalInput)
60 * @param directionSensitive True to enable the pulse length decoding in
61 * hardware to specify count direction.
62 */
63GearTooth::GearTooth(std::shared_ptr<DigitalSource> source,
64 bool directionSensitive)
65 : Counter(source) {
66 EnableDirectionSensing(directionSensitive);
67}
68
69std::string GearTooth::GetSmartDashboardType() const { return "GearTooth"; }