Make a DurationInSeconds function
Also, run clang-format on all the files I changed because I am too lazy
to figure out how to call clang-format on just the lines I changed.
Change-Id: I071c6f81dced533a0a269f25a258348132a7056a
diff --git a/frc971/wpilib/ADIS16448.cc b/frc971/wpilib/ADIS16448.cc
index e902691..aec4d4f 100644
--- a/frc971/wpilib/ADIS16448.cc
+++ b/frc971/wpilib/ADIS16448.cc
@@ -7,10 +7,10 @@
#include <math.h>
#include <chrono>
+#include "aos/init.h"
#include "aos/logging/queue_logging.h"
#include "aos/robot_state/robot_state.q.h"
#include "aos/time/time.h"
-#include "aos/init.h"
#include "frc971/wpilib/imu.q.h"
#include "frc971/zeroing/averager.h"
@@ -214,9 +214,8 @@
// interrupt delay among other things), but it will catch the code
// constantly falling behind, which seems like the most likely failure
// scenario.
- if (!dio1_->Get() ||
- dio1_->WaitForInterrupt(0, false) !=
- frc::InterruptableSensorBase::kTimeout) {
+ if (!dio1_->Get() || dio1_->WaitForInterrupt(0, false) !=
+ frc::InterruptableSensorBase::kTimeout) {
LOG(ERROR, "IMU read took too long\n");
continue;
}
@@ -243,10 +242,8 @@
}
auto message = imu_values.MakeMessage();
- message->fpga_timestamp =
- chrono::duration_cast<chrono::duration<double>>(
- dio1_->ReadRisingTimestamp().time_since_epoch())
- .count();
+ message->fpga_timestamp = ::aos::time::DurationInSeconds(
+ dio1_->ReadRisingTimestamp().time_since_epoch());
message->monotonic_timestamp_ns =
chrono::duration_cast<chrono::nanoseconds>(read_time.time_since_epoch())
.count();
diff --git a/frc971/wpilib/encoder_and_potentiometer.h b/frc971/wpilib/encoder_and_potentiometer.h
index 42fb86b..eb55664 100644
--- a/frc971/wpilib/encoder_and_potentiometer.h
+++ b/frc971/wpilib/encoder_and_potentiometer.h
@@ -7,6 +7,7 @@
#include "aos/macros.h"
#include "aos/mutex/mutex.h"
+#include "aos/time/time.h"
#include "frc971/wpilib/ahal/AnalogInput.h"
#include "frc971/wpilib/ahal/Counter.h"
@@ -236,9 +237,7 @@
static constexpr ::std::chrono::nanoseconds kNominalPeriod =
::std::chrono::microseconds(4096);
static constexpr double kMaxPeriod =
- (::std::chrono::duration_cast<::std::chrono::duration<double>>(
- kNominalPeriod) *
- 2).count();
+ ::aos::time::DurationInSeconds(kNominalPeriod * 2);
::std::unique_ptr<::frc::Counter> high_counter_, period_length_counter_;
::std::unique_ptr<::frc::DigitalInput> input_;