mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] Add frequency support to DutyCycle (#8076)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user