2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
led_subsystem.h
Go to the documentation of this file.
1
4
5#pragma once
6
9#include <ctre/Phoenix.h>
10#include <frc/AddressableLED.h>
11#include <frc2/command/SubsystemBase.h>
12
13#include <vector>
14
15namespace argos_lib {
19 struct LEDState {
20 bool animated{false};
21 frc::AddressableLED::LEDData color;
22
29 bool operator==(const LEDState& other) const;
36 bool operator!=(const LEDState& other) const;
37
44 LEDState& operator=(const frc::AddressableLED::LEDData& other);
45 };
46
47 class LEDSubsystem : public frc2::SubsystemBase {
48 private:
49 // Forward declaration
50 struct LEDUpdateGroup;
51
52 public:
58 explicit LEDSubsystem(unsigned numAuxLEDs);
59
63 void Periodic() override;
64
71 void StockAnimateAuxLEDs(ctre::phoenix::led::Animation& animation, int slot);
72
79 void StockAnimateIntegratedLEDs(ctre::phoenix::led::Animation& animation, int slot);
80
88
96
97 private:
98 std::vector<LEDState> m_currentLEDs;
99 std::vector<LEDState> m_prevLEDs;
100 std::vector<argos_lib::led::Animation> m_customAnimations;
101 ctre::phoenix::led::CANdle m_controller;
102
103 constexpr static unsigned numIntegratedLEDs = 8;
104
112 std::vector<LEDUpdateGroup> GetDeltaUpdate(const std::vector<LEDState>& prev, const std::vector<LEDState>& current);
113
125 LEDUpdateGroup(unsigned startIndex, unsigned numLEDs, frc::AddressableLED::LEDData color)
127
128 unsigned startIndex;
129 unsigned numLEDs;
130 frc::AddressableLED::LEDData color;
131 };
132 };
133} // namespace argos_lib
Definition led_subsystem.h:47
void StockAnimateIntegratedLEDs(ctre::phoenix::led::Animation &animation, int slot)
Set LEDs built into CANdle to use stock animation.
Definition led_subsystem.cpp:56
static constexpr unsigned numIntegratedLEDs
Number of LEDs addressed before attached LED strip/panel.
Definition led_subsystem.h:103
std::vector< LEDState > m_prevLEDs
LED status prior to last update.
Definition led_subsystem.h:99
std::vector< LEDState > m_currentLEDs
LED status to send as update.
Definition led_subsystem.h:98
std::vector< argos_lib::led::Animation > m_customAnimations
Active animations.
Definition led_subsystem.h:100
void CustomAnimateAuxLEDs(argos_lib::led::Animation animation)
Set LEDs in attached strip/panel to use custom animation. The LEDs will be updated on every call of t...
Definition led_subsystem.cpp:64
void StockAnimateAuxLEDs(ctre::phoenix::led::Animation &animation, int slot)
Set LEDs in attached strip/panel to use stock animation.
Definition led_subsystem.cpp:50
void Periodic() override
Definition led_subsystem.cpp:36
std::vector< LEDUpdateGroup > GetDeltaUpdate(const std::vector< LEDState > &prev, const std::vector< LEDState > &current)
Get sendable LED block updates to change from prev to current.
Definition led_subsystem.cpp:82
void CustomAnimateIntegratedLEDs(argos_lib::led::Animation animation)
Set LEDs built into CANdle to use custom animation. The LEDs will be updated on every call of the sub...
Definition led_subsystem.cpp:72
ctre::phoenix::led::CANdle m_controller
LED controller instance with attached LEDs.
Definition led_subsystem.h:101
Definition swap_controllers_command.h:12
Color and animation status for an individual LED.
Definition led_subsystem.h:19
bool operator==(const LEDState &other) const
It's an equality comparison operator...
Definition led_subsystem.cpp:19
bool animated
True indicates this is using a stock animation.
Definition led_subsystem.h:20
frc::AddressableLED::LEDData color
Color of LED. Only used when animated is false.
Definition led_subsystem.h:21
LEDState & operator=(const frc::AddressableLED::LEDData &other)
Copy assignment operator.
Definition led_subsystem.cpp:26
bool operator!=(const LEDState &other) const
It's an inequality comparison operator...
Definition led_subsystem.cpp:22
Represents a contiguous block of LEDs that have the same color.
Definition led_subsystem.h:117
unsigned startIndex
Address of first LED.
Definition led_subsystem.h:128
unsigned numLEDs
Number of LEDs in group.
Definition led_subsystem.h:129
LEDUpdateGroup(unsigned startIndex, unsigned numLEDs, frc::AddressableLED::LEDData color)
Construct a new LEDUpdateGroup with specified color.
Definition led_subsystem.h:125
frc::AddressableLED::LEDData color
Color of LEDs.
Definition led_subsystem.h:130
A representation of a custom LED animation.
Definition animiation.h:20