summaryrefslogtreecommitdiff
path: root/m4p
diff options
context:
space:
mode:
authorMathias Fredriksson <mafredri@gmail.com>2022-02-08 23:50:49 +0200
committerMathias Fredriksson <mafredri@gmail.com>2022-02-08 23:51:02 +0200
commit2bf53f0397f16ee0367be99373b57dadf1742195 (patch)
tree3669265f12b38742d86ef53a2d8f7f19096ea4ee /m4p
parenteb2617ac12b2432e8d8d22c7cae64b887d1c70e5 (diff)
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
Diffstat (limited to 'm4p')
-rw-r--r--m4p/client.go9
-rw-r--r--m4p/message.go20
2 files changed, 26 insertions, 3 deletions
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 }