[hal] Add frequency support to DutyCycle (#8076)

This commit is contained in:
Thad House
2025-07-14 23:46:17 -07:00
committed by GitHub
parent ef24c1df97
commit 3497a7d09f
31 changed files with 153 additions and 355 deletions

View File

@@ -35,11 +35,11 @@ int32_t SmartIo::InitializeMode(SmartIoMode mode) {
modePublisher = inst.GetIntegerTopic(subTableString + "type").Publish();
getSubscriber =
inst.GetIntegerTopic(subTableString + "valget").Subscribe(0, options);
frequencySubscriber =
inst.GetIntegerTopic(subTableString + "freqget").Subscribe(0, options);
periodGetSubscriber =
inst.GetIntegerTopic(subTableString + "periodget").Subscribe(0, options);
setPublisher =
inst.GetIntegerTopic(subTableString + "valset").Publish(options);
periodPublisher =
periodSetPublisher =
inst.GetIntegerTopic(subTableString + "periodset").Publish(options);
currentMode = mode;
@@ -107,6 +107,17 @@ int32_t SmartIo::GetPwmInputMicroseconds(uint16_t* microseconds) {
return 0;
}
int32_t SmartIo::GetPwmInputPeriodMicroseconds(uint16_t* microseconds) {
if (currentMode != SmartIoMode::PwmInput) {
return INCOMPATIBLE_STATE;
}
int val = periodGetSubscriber.Get();
*microseconds = val;
return 0;
}
int32_t SmartIo::SetPwmOutputPeriod(PwmOutputPeriod period) {
if (currentMode != SmartIoMode::PwmOutput) {
return INCOMPATIBLE_STATE;
@@ -117,7 +128,7 @@ int32_t SmartIo::SetPwmOutputPeriod(PwmOutputPeriod period) {
case PwmOutputPeriod::k10ms:
case PwmOutputPeriod::k5ms:
case PwmOutputPeriod::k2ms:
periodPublisher.Set(static_cast<int>(period));
periodSetPublisher.Set(static_cast<int>(period));
return 0;
default: