Fixed DMA time comparison.
Change-Id: I9aa454f3a3c75bd2ad65c0bcb62591e1acbc17f8
diff --git a/aos/externals/forwpilib/dma.cc b/aos/externals/forwpilib/dma.cc
index 3d41c43..ce8bbd3 100644
--- a/aos/externals/forwpilib/dma.cc
+++ b/aos/externals/forwpilib/dma.cc
@@ -350,8 +350,12 @@
ssize_t DMASample::offset(int index) const { return dma_->channel_offsets_[index]; }
+uint32_t DMASample::GetTime() const {
+ return read_buffer_[dma_->capture_size_ - 1];
+}
+
double DMASample::GetTimestamp() const {
- return static_cast<double>(read_buffer_[dma_->capture_size_ - 1]) * 0.000001;
+ return static_cast<double>(GetTime()) * 0.000001;
}
bool DMASample::Get(DigitalSource *input) const {
diff --git a/aos/externals/forwpilib/dma.h b/aos/externals/forwpilib/dma.h
index 754b0a5..2f5b331 100644
--- a/aos/externals/forwpilib/dma.h
+++ b/aos/externals/forwpilib/dma.h
@@ -22,8 +22,10 @@
public:
DMASample() = default;
- // Returns the FPGA timestamp of the sample.
+ // Returns the FPGA timestamp of the sample in seconds.
double GetTimestamp() const;
+ // Returns the FPGA timestamp of the sample in microseconds.
+ uint32_t GetTime() const;
// All Get methods either return the requested value, or set the Error.
diff --git a/frc971/wpilib/dma_edge_counting.cc b/frc971/wpilib/dma_edge_counting.cc
index 102d12b..7f87956 100644
--- a/frc971/wpilib/dma_edge_counting.cc
+++ b/frc971/wpilib/dma_edge_counting.cc
@@ -38,7 +38,7 @@
}
if (remaining == 0) {
- if (sample_time_ < current_sample.GetTimestamp()) {
+ if (sample_time_ < current_sample.GetTime()) {
// If the latest DMA sample happened after we started polling, then
// just use the values from it because they're more recent.
for (auto &c : handlers_) {
diff --git a/frc971/wpilib/dma_edge_counting.h b/frc971/wpilib/dma_edge_counting.h
index c145268..9347c83 100644
--- a/frc971/wpilib/dma_edge_counting.h
+++ b/frc971/wpilib/dma_edge_counting.h
@@ -165,7 +165,7 @@
::std::vector<DMASampleHandlerInterface *> handlers_;
// The time at which we most recently read the sensor values.
- double sample_time_ = 0.0;
+ uint32_t sample_time_ = 0.0;
DISALLOW_COPY_AND_ASSIGN(DMASynchronizer);
};