Added cangrabber auto.
Change-Id: I67c2b363df5fc3e431acf0cfd56c9537bb89804b
diff --git a/frc971/wpilib/loop_output_handler.cc b/frc971/wpilib/loop_output_handler.cc
index cb5e4ec..658b064 100644
--- a/frc971/wpilib/loop_output_handler.cc
+++ b/frc971/wpilib/loop_output_handler.cc
@@ -11,9 +11,8 @@
namespace frc971 {
namespace wpilib {
-constexpr ::aos::time::Time LoopOutputHandler::kStopTimeout;
-
-LoopOutputHandler::LoopOutputHandler() : watchdog_(this) {}
+LoopOutputHandler::LoopOutputHandler(const ::aos::time::Time &timeout)
+ : watchdog_(this, timeout) {}
void LoopOutputHandler::operator()() {
::aos::SetCurrentThreadName("OutputHandler");
@@ -44,8 +43,10 @@
watchdog_thread.join();
}
-LoopOutputHandler::Watchdog::Watchdog(LoopOutputHandler *handler)
+LoopOutputHandler::Watchdog::Watchdog(LoopOutputHandler *handler,
+ const ::aos::time::Time &timeout)
: handler_(handler),
+ timeout_(timeout),
timerfd_(timerfd_create(::aos::time::Time::kDefaultClock, 0)) {
if (timerfd_.get() == -1) {
PLOG(FATAL, "timerfd_create(Time::kDefaultClock, 0)");
@@ -64,7 +65,7 @@
void LoopOutputHandler::Watchdog::Reset() {
itimerspec value = itimerspec();
- value.it_value = kStopTimeout.ToTimespec();
+ value.it_value = timeout_.ToTimespec();
PCHECK(timerfd_settime(timerfd_.get(), 0, &value, nullptr));
}
diff --git a/frc971/wpilib/loop_output_handler.h b/frc971/wpilib/loop_output_handler.h
index fe32763..d7b6283 100644
--- a/frc971/wpilib/loop_output_handler.h
+++ b/frc971/wpilib/loop_output_handler.h
@@ -20,7 +20,8 @@
// loops writing values until Quit() is called.
class LoopOutputHandler {
public:
- LoopOutputHandler();
+ LoopOutputHandler(
+ const ::aos::time::Time &timeout = ::aos::time::Time::InSeconds(0.10));
void Quit() { run_ = false; }
@@ -52,7 +53,7 @@
// LoopOutputHandler whenever the timerfd expires.
class Watchdog {
public:
- Watchdog(LoopOutputHandler *handler);
+ Watchdog(LoopOutputHandler *handler, const ::aos::time::Time &timeout);
void operator()();
@@ -63,14 +64,13 @@
private:
LoopOutputHandler *const handler_;
+ const ::aos::time::Time timeout_;
+
::aos::ScopedFD timerfd_;
::std::atomic<bool> run_{true};
};
- static constexpr ::aos::time::Time kStopTimeout =
- ::aos::time::Time::InSeconds(0.02);
-
Watchdog watchdog_;
::std::atomic<bool> run_{true};