blob: c79d7f2800a9ab4ee2365d022212d4e6a91bf3a5 [file] [log] [blame]
Maxwell Hendersonf29e3182023-05-25 06:51:24 -07001#ifndef FRC971_WPILIB_CAN_SENSOR_READER_H_
2#define FRC971_WPILIB_CAN_SENSOR_READER_H_
3
4#include <vector>
5
6#include "aos/containers/sized_array.h"
7#include "aos/events/event_loop.h"
8#include "aos/events/shm_event_loop.h"
9#include "aos/realtime.h"
Maxwell Henderson10ed5c32024-01-09 12:40:54 -080010#include "frc971/wpilib/talonfx.h"
Maxwell Hendersonf29e3182023-05-25 06:51:24 -070011
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080012namespace frc971::wpilib {
Maxwell Hendersonf29e3182023-05-25 06:51:24 -070013class CANSensorReader {
14 public:
Maxwell Henderson3d68e142024-02-25 09:58:11 -080015 enum class SignalSync {
16 kDoSync,
17 kNoSync,
18 };
Maxwell Hendersonf29e3182023-05-25 06:51:24 -070019 CANSensorReader(
20 aos::EventLoop *event_loop,
Maxwell Hendersonfcc0d122023-08-05 17:03:34 -070021 std::vector<ctre::phoenix6::BaseStatusSignal *> signals_registry,
Maxwell Henderson10ed5c32024-01-09 12:40:54 -080022 std::vector<std::shared_ptr<TalonFX>> talonfxs,
Maxwell Henderson3d68e142024-02-25 09:58:11 -080023 std::function<void(ctre::phoenix::StatusCode status)> flatbuffer_callback,
24 SignalSync sync = SignalSync::kDoSync);
Maxwell Hendersonf29e3182023-05-25 06:51:24 -070025
26 private:
27 void Loop();
28
29 aos::EventLoop *event_loop_;
30
Maxwell Henderson3d68e142024-02-25 09:58:11 -080031 const SignalSync sync_;
Maxwell Hendersonfcc0d122023-08-05 17:03:34 -070032 const std::vector<ctre::phoenix6::BaseStatusSignal *> signals_;
Maxwell Hendersonf29e3182023-05-25 06:51:24 -070033
Maxwell Henderson10ed5c32024-01-09 12:40:54 -080034 // This is a vector of talonfxs becuase we don't need to care
35 // about talonfxs individually.
36 std::vector<std::shared_ptr<TalonFX>> talonfxs_;
Maxwell Hendersonf29e3182023-05-25 06:51:24 -070037
38 // Pointer to the timer handler used to modify the wakeup.
39 ::aos::TimerHandler *timer_handler_;
Maxwell Henderson6c6faaf2023-07-26 19:44:24 -070040
41 // Callback used to send the CANPosition flatbuffer
42 std::function<void(ctre::phoenix::StatusCode status)> flatbuffer_callback_;
Maxwell Hendersonf29e3182023-05-25 06:51:24 -070043};
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080044} // namespace frc971::wpilib
Maxwell Hendersonf29e3182023-05-25 06:51:24 -070045#endif // FRC971_WPILIB_CAN_SENSOR_READER_H_