blob: 8a94e155a630c68c502e57f8e565adf1d05628b0 [file] [log] [blame]
Brian Silverman4da58072015-01-26 20:18:52 -05001#include "frc971/wpilib/encoder_and_potentiometer.h"
2
John Park33858a32018-09-28 23:05:48 -07003#include "aos/logging/logging.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07004#include "aos/realtime.h"
Brian Silverman4da58072015-01-26 20:18:52 -05005
Stephan Pleinesf63bde82024-01-13 15:59:33 -08006namespace frc971::wpilib {
Brian Silverman4da58072015-01-26 20:18:52 -05007
Brian Silverman7cce2d32017-02-19 21:48:48 -08008bool DMAEncoder::DoUpdateFromSample(const DMASample &sample) {
Brian Silverman4da58072015-01-26 20:18:52 -05009 if (index_last_value_) {
10 // It was already true last time, so check if it's reset back to false yet.
11 index_last_value_ = sample.Get(index_.get());
12 } else if (sample.Get(index_.get())) {
13 // This sample is posedge, so record all the values.
14 index_last_value_ = true;
15 ++index_posedge_count_;
16 last_encoder_value_ = sample.GetRaw(encoder_.get());
Brian Silverman7cce2d32017-02-19 21:48:48 -080017 return true;
Brian Silverman4da58072015-01-26 20:18:52 -050018 }
Brian Silverman7cce2d32017-02-19 21:48:48 -080019 return false;
Brian Silverman4da58072015-01-26 20:18:52 -050020}
21
Stephan Pleinesf63bde82024-01-13 15:59:33 -080022} // namespace frc971::wpilib