[wpilib] Counter: Fix default distance per pulse, add distance and rate to C++ (#5796)

- Default distance per pulse in java was 0; 1 is a more reasonable default
- C++ was missing this functionality
This commit is contained in:
Ryan Blue
2023-10-20 02:42:53 -04:00
committed by GitHub
parent b14a61e1c0
commit abb2857e03
3 changed files with 42 additions and 1 deletions

View File

@@ -260,6 +260,18 @@ int Counter::GetFPGAIndex() const {
return m_index;
}
void Counter::SetDistancePerPulse(double distancePerPulse) {
m_distancePerPulse = distancePerPulse;
}
double Counter::GetDistance() const {
return Get() * m_distancePerPulse;
}
double Counter::GetRate() const {
return m_distancePerPulse / GetPeriod().value();
}
int Counter::Get() const {
int32_t status = 0;
int value = HAL_GetCounter(m_counter, &status);