Convert all year's robots to proper event loops

Each robot has a couple of event loops, one per thread.  Each of these
threads corresponds to the threads from before the change.  y2016 has
been tested on real hardware.

Change-Id: I99f726a8bc0498204c1a3b99f15508119eed9ad3
diff --git a/frc971/wpilib/ADIS16448.cc b/frc971/wpilib/ADIS16448.cc
index 75f082d..38d194d 100644
--- a/frc971/wpilib/ADIS16448.cc
+++ b/frc971/wpilib/ADIS16448.cc
@@ -139,6 +139,17 @@
 
   dio1_->RequestInterrupts();
   dio1_->SetUpSourceEdge(true, false);
+
+  // NI's SPI driver defaults to SCHED_OTHER.  Find it's PID with ps, and change
+  // it to a RT priority of 33.
+  PCHECK(
+      system("ps -ef | grep '\\[spi0\\]' | awk '{print $1}' | xargs chrt -f -p "
+             "33") == 0);
+
+  event_loop_->set_name("IMU");
+  event_loop_->SetRuntimeRealtimePriority(33);
+
+  event_loop_->OnRun([this]() { DoRun(); });
 }
 
 void ADIS16448::SetDummySPI(frc::SPI::Port port) {
@@ -155,7 +166,7 @@
 }
 
 void ADIS16448::InitializeUntilSuccessful() {
-  while (run_ && !Initialize()) {
+  while (event_loop_->is_running() && !Initialize()) {
     if (reset_) {
       reset_->Set(false);
       // Datasheet says this needs to be at least 10 us long, so 10 ms is
@@ -170,19 +181,9 @@
     }
   }
   LOG(INFO, "IMU initialized successfully\n");
-
-  ::aos::SetCurrentThreadRealtimePriority(33);
 }
 
-void ADIS16448::operator()() {
-  // NI's SPI driver defaults to SCHED_OTHER.  Find it's PID with ps, and change
-  // it to a RT priority of 33.
-  PCHECK(
-      system("ps -ef | grep '\\[spi0\\]' | awk '{print $1}' | xargs chrt -f -p "
-             "33") == 0);
-
-  ::aos::SetCurrentThreadName("IMU");
-
+void ADIS16448::DoRun() {
   InitializeUntilSuccessful();
 
   // Rounded to approximate the 204.8 Hz.
@@ -193,8 +194,10 @@
   zeroing::Averager<double, 6 * kImuSendRate> average_gyro_z;
 
   bool got_an_interrupt = false;
-  while (run_) {
+  while (event_loop_->is_running()) {
     {
+      // Wait for an interrupt.  (This prevents us from going to sleep in the
+      // event loop like we normally would)
       const frc::InterruptableSensorBase::WaitResult result =
           dio1_->WaitForInterrupt(0.1, !got_an_interrupt);
       if (result == frc::InterruptableSensorBase::kTimeout) {