WPILibC++  2020.3.2-60-g3011ebe
AddressableLED.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 
12 #include <hal/AddressableLEDTypes.h>
13 #include <hal/Types.h>
14 #include <units/units.h>
15 #include <wpi/ArrayRef.h>
16 
17 #include "frc/ErrorBase.h"
18 #include "util/Color.h"
19 #include "util/Color8Bit.h"
20 
21 namespace frc {
22 
28 class AddressableLED : public ErrorBase {
29  public:
31  public:
32  LEDData() : LEDData(0, 0, 0) {}
33  LEDData(int _r, int _g, int _b) {
34  r = _r;
35  g = _g;
36  b = _b;
37  padding = 0;
38  }
39 
47  void SetRGB(int r, int g, int b) {
48  this->r = r;
49  this->g = g;
50  this->b = b;
51  }
52 
60  void SetHSV(int h, int s, int v);
61 
62  /*
63  * Sets a specific LED in the buffer.
64  *
65  * @param color The color of the LED
66  */
67  void SetLED(const Color& color) {
68  this->r = color.red * 255;
69  this->g = color.green * 255;
70  this->b = color.blue * 255;
71  }
72 
73  /*
74  * Sets a specific LED in the buffer.
75  *
76  * @param color The color of the LED
77  */
78  void SetLED(const Color8Bit& color) {
79  this->r = color.red;
80  this->g = color.green;
81  this->b = color.blue;
82  }
83  };
84 
90  explicit AddressableLED(int port);
91 
92  ~AddressableLED() override;
93 
104  void SetLength(int length);
105 
114  void SetData(wpi::ArrayRef<LEDData> ledData);
115 
124  void SetData(std::initializer_list<LEDData> ledData);
125 
137  void SetBitTiming(units::nanosecond_t lowTime0, units::nanosecond_t highTime0,
138  units::nanosecond_t lowTime1,
139  units::nanosecond_t highTime1);
140 
149  void SetSyncTime(units::microsecond_t syncTime);
150 
156  void Start();
157 
161  void Stop();
162 
163  private:
164  hal::Handle<HAL_DigitalHandle> m_pwmHandle;
165  hal::Handle<HAL_AddressableLEDHandle> m_handle;
166 };
167 } // namespace frc
HAL_AddressableLEDData
Definition: AddressableLEDTypes.h:14
frc::AddressableLED::LEDData::SetRGB
void SetRGB(int r, int g, int b)
A helper method to set all values of the LED.
Definition: AddressableLED.h:47
frc::AddressableLED::SetBitTiming
void SetBitTiming(units::nanosecond_t lowTime0, units::nanosecond_t highTime0, units::nanosecond_t lowTime1, units::nanosecond_t highTime1)
Sets the bit timing.
wpi::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
frc::AddressableLED::Stop
void Stop()
Stops the output.
frc::AddressableLED::Start
void Start()
Starts the output.
frc::Color
Represents colors that can be used with Addressable LEDs.
Definition: Color.h:19
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::AddressableLED::SetData
void SetData(wpi::ArrayRef< LEDData > ledData)
Sets the led output data.
frc::AddressableLED::LEDData
Definition: AddressableLED.h:30
frc::AddressableLED::AddressableLED
AddressableLED(int port)
Constructs a new driver for a specific port.
frc::AddressableLED::SetLength
void SetLength(int length)
Sets the length of the LED strip.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::AddressableLED::SetSyncTime
void SetSyncTime(units::microsecond_t syncTime)
Sets the sync time.
frc::Color8Bit
Represents colors that can be used with Addressable LEDs.
Definition: Color8Bit.h:19
frc::AddressableLED
A class for driving addressable LEDs, such as WS2812s and NeoPixels.
Definition: AddressableLED.h:28
frc::AddressableLED::LEDData::SetHSV
void SetHSV(int h, int s, int v)
A helper method to set all values of the LED.