Skip to content

Commit

Permalink
stickManager.rightStickX -> stickManager.rightStick.horizontal
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Oct 4, 2023
1 parent e0e94a9 commit 7d99d92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions appendix/GamePadViewer/src/EventObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ public class EventObserver: ObservableObject {
if usagePage == 0x1, usage == 0x32 {
counter += 1
Task { @MainActor in
stickManager.rightStickX.add(logicalMax, logicalMin, integerValue)
stickManager.rightStick.horizontal.add(logicalMax, logicalMin, integerValue)

stickManager.rightStickX.update()
stickManager.rightStickY.update()
stickManager.rightStick.horizontal.update()
stickManager.rightStick.vertical.update()
}
}

// usage::generic_desktop::rz
if usagePage == 0x1, usage == 0x35 {
counter += 1
Task { @MainActor in
stickManager.rightStickY.add(logicalMax, logicalMin, integerValue)
stickManager.rightStick.vertical.add(logicalMax, logicalMin, integerValue)

stickManager.rightStickX.update()
stickManager.rightStickY.update()
stickManager.rightStick.horizontal.update()
stickManager.rightStick.vertical.update()
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions appendix/GamePadViewer/src/StickManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public class StickManager: ObservableObject {
}
}

@Published var rightStickX = StickSensor()
@Published var rightStickY = StickSensor()
class Stick: ObservableObject {
@Published var horizontal = StickSensor()
@Published var vertical = StickSensor()
}

@Published var rightStick = Stick()
}
8 changes: 4 additions & 4 deletions appendix/GamePadViewer/src/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ struct ContentView: View {
VStack(alignment: .leading) {
Text("counter: \(eventObserver.counter)")

StickSensorInfo(label: "Right Stick X", stick: stickManager.rightStickX)
StickSensorInfo(label: "Right Stick Y", stick: stickManager.rightStickY)
StickSensorInfo(label: "Right Stick X", stick: stickManager.rightStick.horizontal)
StickSensorInfo(label: "Right Stick Y", stick: stickManager.rightStick.vertical)
}

ZStack(alignment: .center) {
Expand All @@ -26,9 +26,9 @@ struct ContentView: View {
path.move(to: CGPoint(x: circleSize / 2.0, y: circleSize / 2.0))
path.addLine(
to: CGPoint(
x: stickManager.rightStickX.lastAcceleration / stickDivider * circleSize
x: stickManager.rightStick.horizontal.lastAcceleration / stickDivider * circleSize
+ circleSize / 2.0,
y: stickManager.rightStickY.lastAcceleration / stickDivider * circleSize
y: stickManager.rightStick.vertical.lastAcceleration / stickDivider * circleSize
+ circleSize / 2.0
))
}
Expand Down

0 comments on commit 7d99d92

Please sign in to comment.