Skip to content

Commit

Permalink
Decode dial up and down events
Browse files Browse the repository at this point in the history
  • Loading branch information
emorydunn committed Dec 14, 2023
1 parent defc065 commit adda2fe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Sources/StreamDeck/Events/Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ extension ReceivableEvent {
case keyUp
case dialRotate
case dialPress
case dialDown
case dialUp
case touchTap
case willAppear
case willDisappear
Expand Down
25 changes: 23 additions & 2 deletions Sources/StreamDeck/StreamDeck Plugin/Action/Action+Support.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ extension Action {
dialRotate(device: action.device, payload: action.payload)
}

/// Decode and deliver a dial rotation event.
@available(*, deprecated, message: "Please note, from Stream Deck 6.5 onwards, dialPress will not be emitted by the API. Plugins should use dialDown and dialUp to receive events relating to dial presses.")
/// Decode and deliver a dial press event.
/// - Parameters:
/// - data: Event data
/// - decoder: The decoder to use
Expand All @@ -132,7 +133,27 @@ extension Action {

dialPress(device: action.device, payload: action.payload)
}


/// Decode and deliver a dial down event.
/// - Parameters:
/// - data: Event data
/// - decoder: The decoder to use
func decodeDialDown(_ data: Data, using decoder: JSONDecoder) throws {
let action = try decoder.decode(ActionEvent<EncoderPressEvent<Settings>>.self, from: data)

dialDown(device: action.device, payload: action.payload)
}

/// Decode and deliver a dial up event.
/// - Parameters:
/// - data: Event data
/// - decoder: The decoder to use
func decodeDialUp(_ data: Data, using decoder: JSONDecoder) throws {
let action = try decoder.decode(ActionEvent<EncoderPressEvent<Settings>>.self, from: data)

dialUp(device: action.device, payload: action.payload)
}

/// Decode and deliver a dial rotation event.
/// - Parameters:
/// - data: Event data
Expand Down
10 changes: 10 additions & 0 deletions Sources/StreamDeck/StreamDeck Plugin/StreamDeckPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ public final class StreamDeckPlugin {

try self[context]?.decodeDialPress(data, using: decoder)

case .dialDown:
log.info("Forwarding \(event) to \(context ?? "no context")")

try self[context]?.decodeDialDown(data, using: decoder)

case .dialUp:
log.info("Forwarding \(event) to \(context ?? "no context")")

try self[context]?.decodeDialUp(data, using: decoder)

case .touchTap:
log.info("Forwarding \(event) to \(context ?? "no context")")

Expand Down

0 comments on commit adda2fe

Please sign in to comment.