Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 2 | /* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 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 "frc/GearTooth.h" |
| 9 | |
| 10 | #include "frc/smartdashboard/SendableBuilder.h" |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 11 | #include "frc/smartdashboard/SendableRegistry.h" |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 12 | |
| 13 | using namespace frc; |
| 14 | |
| 15 | constexpr double GearTooth::kGearToothThreshold; |
| 16 | |
| 17 | GearTooth::GearTooth(int channel, bool directionSensitive) : Counter(channel) { |
| 18 | EnableDirectionSensing(directionSensitive); |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 19 | SendableRegistry::GetInstance().SetName(this, "GearTooth", channel); |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | GearTooth::GearTooth(DigitalSource* source, bool directionSensitive) |
| 23 | : Counter(source) { |
| 24 | EnableDirectionSensing(directionSensitive); |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 25 | SendableRegistry::GetInstance().SetName(this, "GearTooth", |
| 26 | source->GetChannel()); |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | GearTooth::GearTooth(std::shared_ptr<DigitalSource> source, |
| 30 | bool directionSensitive) |
| 31 | : Counter(source) { |
| 32 | EnableDirectionSensing(directionSensitive); |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 33 | SendableRegistry::GetInstance().SetName(this, "GearTooth", |
| 34 | source->GetChannel()); |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void GearTooth::EnableDirectionSensing(bool directionSensitive) { |
| 38 | if (directionSensitive) { |
| 39 | SetPulseLengthMode(kGearToothThreshold); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void GearTooth::InitSendable(SendableBuilder& builder) { |
| 44 | Counter::InitSendable(builder); |
| 45 | builder.SetSmartDashboardType("Gear Tooth"); |
| 46 | } |