Skip to content

Commit 808191c

Browse files
committed
add manual poll option for QuadRotary
1 parent df6335f commit 808191c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Sources/QuadRotary/QuadRotary.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ import SwiftIO
3030

3131
@SeeSawActor
3232
public final class QuadRotary {
33-
public enum Mode: Sendable {
33+
public enum Mode: Sendable, Equatable {
3434
case poll(Duration)
3535
case interrupt(Int32)
36+
case manual
3637
}
3738

3839
public nonisolated static let NumEncoders = UInt8(4)
@@ -86,6 +87,8 @@ public final class QuadRotary {
8687
}
8788
_interrupt = DigitalIn(Id(rawValue: pin), mode: .pullDown)
8889
.risingEdgeInterrupts
90+
case .manual:
91+
_interrupt = nil
8992
}
9093

9194
var encoders = [IncrementalEncoder]()
@@ -134,6 +137,8 @@ public final class QuadRotary {
134137
}
135138

136139
public func run() {
140+
guard _mode != .manual else { return }
141+
137142
_task = Task<(), Error> { @Sendable [self] in
138143
switch _mode {
139144
case let .poll(pollInterval):
@@ -145,6 +150,8 @@ public final class QuadRotary {
145150
for try await _ in _interrupt! {
146151
await _sendEvents()
147152
}
153+
case .manual:
154+
break
148155
}
149156
}
150157
}

0 commit comments

Comments
 (0)