From cc7f3556296556bca7d1474b3c1b717f04f90f00 Mon Sep 17 00:00:00 2001 From: datalore Date: Mon, 4 Aug 2025 15:42:19 +0200 Subject: [PATCH] feat(Controller): Added error logging in update loop --- controller.go | 7 ++++++- mapping.go | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/controller.go b/controller.go index 2698b13..d2f95ce 100644 --- a/controller.go +++ b/controller.go @@ -1,6 +1,8 @@ package main import ( + "log" + "gitlab.com/gomidi/midi/v2" "github.com/bendahl/uinput" ) @@ -53,6 +55,9 @@ func (c Controller) Stop() { func (c Controller) update(msg midi.Message) { for _, mapping := range c.mappings { - mapping.TriggerIfMatch(msg, c.virtGamepad) + err := mapping.TriggerIfMatch(msg, c.virtGamepad) + if err != nil { + log.Printf("Error in Mapping \"%s\": %v\n", mapping.Comment(), err) + } } } diff --git a/mapping.go b/mapping.go index 28d9b01..adca5a5 100644 --- a/mapping.go +++ b/mapping.go @@ -10,6 +10,7 @@ import ( type Mapping interface { Is(midi.Message) bool TriggerIfMatch(midi.Message, uinput.Gamepad) error + Comment() string } type ButtonMapping struct { @@ -45,6 +46,10 @@ func (m ButtonMapping) TriggerIfMatch(msg midi.Message, virtGamepad uinput.Gamep return nil } +func (m ButtonMapping) Comment() string { + return m.comment +} + type ControllerAxis int const ( @@ -102,3 +107,7 @@ func (m ControlMapping) TriggerIfMatch(msg midi.Message, virtGamepad uinput.Game return nil } + +func (m ControlMapping) Comment() string { + return m.comment +}