mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal, wpilib] Update Addressable LED support (#8100)
This commit is contained in:
@@ -19,22 +19,22 @@ using namespace halsimgui;
|
||||
namespace {
|
||||
class AddressableLEDModel : public glass::LEDDisplayModel {
|
||||
public:
|
||||
explicit AddressableLEDModel(int32_t index) : m_index{index} {}
|
||||
explicit AddressableLEDModel(int32_t channel) : m_channel{channel} {}
|
||||
|
||||
void Update() override {}
|
||||
bool Exists() override {
|
||||
return HALSIM_GetAddressableLEDInitialized(m_index);
|
||||
return HALSIM_GetAddressableLEDInitialized(m_channel);
|
||||
}
|
||||
|
||||
bool IsRunning() override { return HALSIM_GetAddressableLEDRunning(m_index); }
|
||||
|
||||
std::span<const Data> GetData(wpi::SmallVectorImpl<Data>&) override {
|
||||
size_t length = HALSIM_GetAddressableLEDData(m_index, m_data);
|
||||
size_t length = HALSIM_GetAddressableLEDData(
|
||||
HALSIM_GetAddressableLEDStart(m_channel),
|
||||
HALSIM_GetAddressableLEDLength(m_channel), m_data);
|
||||
return {reinterpret_cast<Data*>(m_data), length};
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t m_index;
|
||||
int32_t m_channel;
|
||||
|
||||
HAL_AddressableLEDData m_data[HAL_kAddressableLEDMaxLength];
|
||||
};
|
||||
@@ -49,7 +49,7 @@ class AddressableLEDsModel : public glass::LEDDisplaysModel {
|
||||
size_t GetNumLEDDisplays() override { return m_models.size(); }
|
||||
|
||||
void ForEachLEDDisplay(
|
||||
wpi::function_ref<void(glass::LEDDisplayModel& model, int index)> func)
|
||||
wpi::function_ref<void(glass::LEDDisplayModel& model, int channel)> func)
|
||||
override;
|
||||
|
||||
private:
|
||||
@@ -83,7 +83,7 @@ bool AddressableLEDsModel::Exists() {
|
||||
}
|
||||
|
||||
void AddressableLEDsModel::ForEachLEDDisplay(
|
||||
wpi::function_ref<void(glass::LEDDisplayModel& model, int index)> func) {
|
||||
wpi::function_ref<void(glass::LEDDisplayModel& model, int channel)> func) {
|
||||
for (int i = 0; i < static_cast<int>(m_models.size()); ++i) {
|
||||
if (m_models[i]) {
|
||||
func(*m_models[i], i);
|
||||
|
||||
@@ -28,9 +28,6 @@ class PWMSimModel : public glass::PWMModel {
|
||||
|
||||
bool Exists() override { return HALSIM_GetPWMInitialized(m_index); }
|
||||
|
||||
void SetAddressableLED(int led) { m_led = led; }
|
||||
int GetAddressableLED() const override { return m_led; }
|
||||
|
||||
glass::DoubleSource* GetSpeedData() override { return &m_speed; }
|
||||
|
||||
void SetSpeed(double val) override {
|
||||
@@ -39,7 +36,6 @@ class PWMSimModel : public glass::PWMModel {
|
||||
|
||||
private:
|
||||
int32_t m_index;
|
||||
int m_led = -1;
|
||||
PWMPulseMicrosecondSource m_speed;
|
||||
};
|
||||
|
||||
@@ -68,21 +64,10 @@ void PWMsSimModel::Update() {
|
||||
if (!model) {
|
||||
model = std::make_unique<PWMSimModel>(i);
|
||||
}
|
||||
model->SetAddressableLED(-1);
|
||||
} else {
|
||||
model.reset();
|
||||
}
|
||||
}
|
||||
|
||||
static const int32_t numLED = HAL_GetNumAddressableLEDs();
|
||||
for (int32_t i = 0; i < numLED; ++i) {
|
||||
if (HALSIM_GetAddressableLEDInitialized(i)) {
|
||||
int32_t channel = HALSIM_GetAddressableLEDOutputPort(i);
|
||||
if (channel >= 0 && channel < numPWM && m_sources[channel]) {
|
||||
m_sources[channel]->SetAddressableLED(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PWMsSimModel::ForEachPWM(
|
||||
|
||||
Reference in New Issue
Block a user