Update wpilib_interface.

Change-Id: If0e00a97faf0653a43e9acff9a8cff6ce3d3e6cb
diff --git a/frc971/wpilib/dma_edge_counting.cc b/frc971/wpilib/dma_edge_counting.cc
index 4b0349c..77d84b5 100644
--- a/frc971/wpilib/dma_edge_counting.cc
+++ b/frc971/wpilib/dma_edge_counting.cc
@@ -5,7 +5,7 @@
 namespace frc971 {
 namespace wpilib {
 
-bool DMAEdgeCounter::ExtractValue(const DMASample &sample) {
+bool DMAEdgeCounter::ExtractValue(const DMASample &sample) const {
   if (inverted_) {
     return !sample.Get(input_);
   } else {
diff --git a/frc971/wpilib/dma_edge_counting.h b/frc971/wpilib/dma_edge_counting.h
index 5d6808d..939dc5e 100644
--- a/frc971/wpilib/dma_edge_counting.h
+++ b/frc971/wpilib/dma_edge_counting.h
@@ -46,34 +46,34 @@
   DMAEdgeCounter(Encoder *encoder, HallEffect *input)
       : encoder_(encoder), input_(input), inverted_(true) {}
 
-  virtual void UpdateFromSample(const DMASample &sample) override;
-  virtual void UpdatePolledValue() override {
-    polled_value_ = input_->Get();
-    polled_encoder_ = encoder_->GetRaw();
-  }
-  virtual void PollFromSample(const DMASample &sample) override {
-    polled_value_ = ExtractValue(sample);
-    polled_encoder_ = sample.GetRaw(encoder_);
-  }
-  virtual void AddToDMA(DMA *dma) override {
-    dma->Add(encoder_);
-    dma->Add(input_);
-  }
-
-  int positive_count() { return pos_edge_count_; }
-  int negative_count() { return neg_edge_count_; }
-  int last_positive_encoder_value() { return pos_last_encoder_; }
-  int last_negative_encoder_value() { return neg_last_encoder_; }
+  int positive_count() const { return pos_edge_count_; }
+  int negative_count() const { return neg_edge_count_; }
+  int last_positive_encoder_value() const { return pos_last_encoder_; }
+  int last_negative_encoder_value() const { return neg_last_encoder_; }
 
   // Returns the value of the sensor in the last-read DMA sample.
-  bool last_value() { return ExtractValue(prev_sample_); }
+  bool last_value() const { return ExtractValue(prev_sample_); }
   // Returns the most recent polled value of the sensor.
   bool polled_value() const { return polled_value_; }
   // Returns the most recent polled reading from the encoder.
   int polled_encoder() const { return polled_encoder_; }
 
  private:
-  bool ExtractValue(const DMASample &sample);
+  void UpdateFromSample(const DMASample &sample) override;
+  void UpdatePolledValue() override {
+    polled_value_ = input_->Get();
+    polled_encoder_ = encoder_->GetRaw();
+  }
+  void PollFromSample(const DMASample &sample) override {
+    polled_value_ = ExtractValue(sample);
+    polled_encoder_ = sample.GetRaw(encoder_);
+  }
+  void AddToDMA(DMA *dma) override {
+    dma->Add(encoder_);
+    dma->Add(input_);
+  }
+
+  bool ExtractValue(const DMASample &sample) const;
 
   Encoder *const encoder_;
   DigitalSource *const input_;
@@ -100,6 +100,36 @@
   DISALLOW_COPY_AND_ASSIGN(DMAEdgeCounter);
 };
 
+// Reads a hall effect in sync with DMA samples.
+class DMADigitalReader : public DMASampleHandlerInterface {
+ public:
+  DMADigitalReader(DigitalSource *input) : input_(input), inverted_(false) {}
+  DMADigitalReader(HallEffect *input) : input_(input), inverted_(true) {}
+
+  bool value() const { return value_; }
+
+ private:
+  void UpdateFromSample(const DMASample & /*sample*/) override {}
+  void UpdatePolledValue() override { value_ = input_->Get(); }
+  void PollFromSample(const DMASample &sample) override {
+    if (inverted_) {
+      value_ = !sample.Get(input_);
+    } else {
+      value_ = sample.Get(input_);
+    }
+  }
+  void AddToDMA(DMA *dma) override {
+    dma->Add(input_);
+  }
+
+  DigitalSource *const input_;
+  const bool inverted_;
+
+  bool value_;
+
+  DISALLOW_COPY_AND_ASSIGN(DMADigitalReader);
+};
+
 // This class handles updating the sampled data on multiple
 // DMASampleHandlerInterfaces. The caller should create an instance and then
 // periodically call RunIteration, retrieving whatever data from the
diff --git a/frc971/wpilib/interrupt_edge_counting.h b/frc971/wpilib/interrupt_edge_counting.h
index bd76d7c..f0b5e32 100644
--- a/frc971/wpilib/interrupt_edge_counting.h
+++ b/frc971/wpilib/interrupt_edge_counting.h
@@ -153,6 +153,23 @@
   DISALLOW_COPY_AND_ASSIGN(EdgeCounter);
 };
 
+// Synchronizes reading an encoder with interrupt handling.
+class InterruptSynchronizedEncoder : public InterruptHandler {
+ public:
+  InterruptSynchronizedEncoder(Encoder *encoder) : encoder_(encoder) {}
+
+  int32_t get() const { return output_; }
+
+ private:
+  void GatherPolledValue() override { shadow_ = encoder_->GetRaw(); }
+  void CommitValue() override { output_ = shadow_; }
+  void operator()() override {}
+
+  Encoder *const encoder_;
+
+  int32_t shadow_, output_;
+};
+
 // Synchronizes interrupts with poll-based sampling on multiple
 // InterruptHandlers.
 //
@@ -167,10 +184,10 @@
   InterruptSynchronizer(int interrupt_priority)
       : interrupt_priority_(interrupt_priority) {}
 
-  void Add(::std::unique_ptr<InterruptHandler> handler) {
+  void Add(InterruptHandler *handler) {
     handler->set_mutex(&mutex_);
     handler->set_priority(interrupt_priority_);
-    handlers_.emplace_back(::std::move(handler));
+    handlers_.emplace_back(handler);
   }
 
   void Start() {
@@ -206,7 +223,7 @@
   // The mutex used to synchronize all the sampling.
   ::aos::stl_mutex mutex_;
 
-  ::std::vector<::std::unique_ptr<InterruptHandler>> handlers_;
+  ::std::vector<InterruptHandler *> handlers_;
 
   DISALLOW_COPY_AND_ASSIGN(InterruptSynchronizer);
 };