Move PDP measurement fetching to a separate thread

Stupid CAN messages are too slow for being inline with the normal
path...

Change-Id: I160a24eb3216fc54083df576555b5bcad062ceb8
diff --git a/y2014/wpilib/wpilib_interface.cc b/y2014/wpilib/wpilib_interface.cc
index 77e478e..fdd9b5c 100644
--- a/y2014/wpilib/wpilib_interface.cc
+++ b/y2014/wpilib/wpilib_interface.cc
@@ -18,7 +18,6 @@
 #ifndef WPILIB2015
 #include "DigitalGlitchFilter.h"
 #endif
-#include "PowerDistributionPanel.h"
 #undef ERROR
 
 #include "aos/common/logging/logging.h"
@@ -49,6 +48,7 @@
 #include "frc971/wpilib/encoder_and_potentiometer.h"
 #include "frc971/wpilib/logging.q.h"
 #include "frc971/wpilib/wpilib_interface.h"
+#include "frc971/wpilib/pdp_fetcher.h"
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
@@ -122,7 +122,8 @@
 
 class SensorReader {
  public:
-  SensorReader() {
+  SensorReader(::frc971::wpilib::PDPFetcher *pdp_fetcher)
+      : pdp_fetcher_(pdp_fetcher) {
     // Set it to filter out anything shorter than 1/4 of the minimum pulse width
     // we should ever see.
     encoder_filter_.SetPeriodNanoSeconds(
@@ -255,7 +256,6 @@
 #else
         &DriverStation::GetInstance();
 #endif
-    pdp_.reset(new PowerDistributionPanel());
 
     top_reader_.Start();
     bottom_reader_.Start();
@@ -280,7 +280,7 @@
   }
 
   void RunIteration() {
-    ::frc971::wpilib::SendRobotState(my_pid_, ds_, pdp_.get());
+    ::frc971::wpilib::SendRobotState(my_pid_, ds_, pdp_fetcher_);
 
     const auto &values = constants::GetValues();
 
@@ -443,7 +443,7 @@
 
   int32_t my_pid_;
   DriverStation *ds_;
-  ::std::unique_ptr<PowerDistributionPanel> pdp_;
+  ::frc971::wpilib::PDPFetcher *const pdp_fetcher_;
 
   ::std::unique_ptr<::frc971::wpilib::DMASynchronizer> dma_synchronizer_;
 
@@ -699,7 +699,9 @@
     ::frc971::wpilib::JoystickSender joystick_sender;
     ::std::thread joystick_thread(::std::ref(joystick_sender));
 
-    SensorReader reader;
+    ::frc971::wpilib::PDPFetcher pdp_fetcher;
+    ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher));
+    SensorReader reader(&pdp_fetcher);
 
     // Create this first to make sure it ends up in one of the lower-numbered
     // FPGA slots so we can use it with DMA.
@@ -775,6 +777,8 @@
 
     joystick_sender.Quit();
     joystick_thread.join();
+    pdp_fetcher.Quit();
+    pdp_fetcher_thread.join();
     reader.Quit();
     reader_thread.join();
     gyro_sender.Quit();