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