diff --git a/appendix/GamePadViewer/src/EventObserver.swift b/appendix/GamePadViewer/src/EventObserver.swift index 2517b2d2b..570516912 100644 --- a/appendix/GamePadViewer/src/EventObserver.swift +++ b/appendix/GamePadViewer/src/EventObserver.swift @@ -47,10 +47,10 @@ 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() } } @@ -58,10 +58,10 @@ public class EventObserver: ObservableObject { 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() } } } diff --git a/appendix/GamePadViewer/src/StickManager.swift b/appendix/GamePadViewer/src/StickManager.swift index b7d17de82..bd0940f16 100644 --- a/appendix/GamePadViewer/src/StickManager.swift +++ b/appendix/GamePadViewer/src/StickManager.swift @@ -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() } diff --git a/appendix/GamePadViewer/src/View/ContentView.swift b/appendix/GamePadViewer/src/View/ContentView.swift index d94c29aab..257671109 100644 --- a/appendix/GamePadViewer/src/View/ContentView.swift +++ b/appendix/GamePadViewer/src/View/ContentView.swift @@ -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) { @@ -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 )) }