From 2bf53f0397f16ee0367be99373b57dadf1742195 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 8 Feb 2022 23:50:49 +0200 Subject: Add support for mouse click and scroll wheel Requires the webos client to have support for these events, see: https://github.com/Wouterdek/magic4pc/pull/10 --- m4p/client.go | 9 +++++++-- m4p/message.go | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'm4p') diff --git a/m4p/client.go b/m4p/client.go index 45f8b77..3467b3f 100644 --- a/m4p/client.go +++ b/m4p/client.go @@ -2,7 +2,6 @@ package m4p import ( "context" - "encoding/hex" "encoding/json" "errors" "fmt" @@ -132,8 +131,14 @@ recvLoop: case InputMessage: log.Printf("m4p: Client: recv: got %s: %v", m.Type, m.Input) + case MouseMessage: + log.Printf("m4p: Client: recv: got %s: %v", m.Type, m.Mouse) + + case WheelMessage: + log.Printf("m4p: Client: recv: got %s: %v", m.Type, m.Wheel) + case RemoteUpdateMessage: - log.Printf("m4p: Client: recv: got %s: %s", m.Type, hex.EncodeToString(m.RemoteUpdate.Payload)) + // log.Printf("m4p: Client: recv: got %s: %s", m.Type, hex.EncodeToString(m.RemoteUpdate.Payload)) default: log.Printf("m4p: Client: recv: unknown message: %s", m.Type) diff --git a/m4p/message.go b/m4p/message.go index 34a9383..0a9ebeb 100644 --- a/m4p/message.go +++ b/m4p/message.go @@ -13,6 +13,8 @@ const ( SubSensorMessage MessageType = "sub_sensor" RemoteUpdateMessage MessageType = "remote_update" InputMessage MessageType = "input" + MouseMessage MessageType = "mouse" + WheelMessage MessageType = "wheel" KeepAliveMessage MessageType = "keepalive" ) @@ -24,6 +26,8 @@ type Message struct { *Register *RemoteUpdate *Input + Mouse Mouse `json:"mouse"` + Wheel Wheel `json:"wheel"` } // NewMessage initializes a message with the type and protocol version. @@ -62,10 +66,24 @@ type RemoteUpdate struct { Payload []byte `json:"payload"` } +type Coordinates struct { + X int32 `json:"x"` + Y int32 `json:"y"` +} + +type Mouse struct { + Type string `json:"type"` // mousedown, mouseup + Coordinates +} + +type Wheel struct { + Delta int32 `json:"delta"` + Coordinates +} + // type ( // ReturnValue uint8 // DeviceID uint8 -// Coordinates struct{ X, Y int32 } // Gyroscope struct{ X, Y, Z float32 } // Acceleration struct{ X, Y, Z float32 } // Quaternion struct{ Q0, Q1, Q2, Q3 float32 } -- cgit v1.2.3