mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[hal, wpilib] Update Addressable LED support (#8100)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user