Skip to content

Commit

Permalink
add encoder mask
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Jan 2, 2025
1 parent 669090f commit 21f7254
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/QuadRotary/QuadRotary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class QuadRotary {
public let value: Value
}

private let _mask: UInt8
private let _mode: Mode
private let _eventChannel = AsyncThrowingChannel<Event, Error>()
private var _task: Task<(), Error>?
Expand All @@ -68,10 +69,12 @@ public final class QuadRotary {

public init(
deviceNumber: Int32 = 1,
mask: UInt8 = 0xF,
mode: Mode = Mode.poll(DefaultPollInterval)
) async throws {
let i2c = I2C(Id(rawValue: deviceNumber))
let seeSaw = try await SeeSaw(i2c: i2c)
_mask = mask
_mode = mode
switch _mode {
case .poll:
Expand Down Expand Up @@ -107,6 +110,8 @@ public final class QuadRotary {
var events = [Event]()

for i in 0..<Int(QuadRotary.NumEncoders) {
guard _mask & (1 << i) != 0 else { continue }

if let newValue = try? await _switches[i].value, newValue != _switchStates[i] {
_switchStates[i] = newValue
events.append(Event(index: UInt8(i), value: .switched(newValue)))
Expand Down

0 comments on commit 21f7254

Please sign in to comment.