Fix DMA pulse width reader
Didn't work with multiple readers because we were using the last sample
time, not the last time the reading went high.
Signed-off-by: milind-u <milind.upadhyay@gmail.com>
Change-Id: Ieedef0e8500f61d2881569bc7dfb56fbe843a97f
diff --git a/frc971/wpilib/dma_edge_counting.cc b/frc971/wpilib/dma_edge_counting.cc
index ca2a10e..8864116 100644
--- a/frc971/wpilib/dma_edge_counting.cc
+++ b/frc971/wpilib/dma_edge_counting.cc
@@ -25,8 +25,12 @@
}
void DMAPulseWidthReader::UpdateFromSample(const DMASample &sample) {
- if (have_prev_sample_ && prev_sample_.Get(input_) && !sample.Get(input_)) {
- last_width_ = sample.GetTimestamp() - prev_sample_.GetTimestamp();
+ if (have_prev_sample_ && high_time_ != 0 && prev_sample_.Get(input_) &&
+ !sample.Get(input_)) {
+ last_width_ = (sample.GetTime() - high_time_) * 0.000001;
+ } else if (have_prev_sample_ && !prev_sample_.Get(input_) &&
+ sample.Get(input_)) {
+ high_time_ = prev_sample_.GetTime();
}
have_prev_sample_ = true;
prev_sample_ = sample;