[hal, wpilib] Update Addressable LED support (#8100)

This commit is contained in:
Peter Johnson
2025-07-21 21:52:10 -07:00
committed by GitHub
parent 8aa312fb6f
commit f3af50fc8e
40 changed files with 857 additions and 1104 deletions

View File

@@ -8,6 +8,8 @@
#include "HALInitializer.h"
#include "SystemServerInternal.h"
#include "hal/AddressableLEDTypes.h"
#include "hal/Errors.h"
namespace hal {
@@ -42,6 +44,10 @@ int32_t SmartIo::InitializeMode(SmartIoMode mode) {
inst.GetIntegerTopic(subTableString + "valset").Publish(options);
periodSetPublisher =
inst.GetIntegerTopic(subTableString + "periodset").Publish(options);
ledcountPublisher =
inst.GetIntegerTopic(subTableString + "ledcount").Publish(options);
ledoffsetPublisher =
inst.GetIntegerTopic(subTableString + "ledoffset").Publish(options);
currentMode = mode;
switch (mode) {
@@ -50,6 +56,10 @@ int32_t SmartIo::InitializeMode(SmartIoMode mode) {
case SmartIoMode::PwmOutput:
setPublisher.Set(0);
break;
case SmartIoMode::AddressableLED:
ledcountPublisher.Set(0);
ledoffsetPublisher.Set(0);
break;
// These don't need to set any value
case SmartIoMode::DigitalInput:
@@ -189,4 +199,26 @@ int32_t SmartIo::GetCounter(int32_t* value) {
return 0;
}
int32_t SmartIo::SetLedStart(int32_t start) {
if (currentMode != SmartIoMode::AddressableLED) {
return INCOMPATIBLE_STATE;
}
if (start < 0 || start >= HAL_kAddressableLEDMaxLength) {
return PARAMETER_OUT_OF_RANGE;
}
ledoffsetPublisher.Set(start);
return 0;
}
int32_t SmartIo::SetLedLength(int32_t length) {
if (currentMode != SmartIoMode::AddressableLED) {
return INCOMPATIBLE_STATE;
}
if (length < 0 || length >= HAL_kAddressableLEDMaxLength) {
return PARAMETER_OUT_OF_RANGE;
}
ledcountPublisher.Set(length);
return 0;
}
} // namespace hal