Add duration to log

This commit is contained in:
Torjus Håkestad 2024-03-10 19:07:34 +01:00
parent 4ebf6dd715
commit c3b35cdd2d

View File

@ -6,6 +6,7 @@ import (
"log/slog"
"os"
"os/signal"
"time"
"github.com/godbus/dbus/v5"
"github.com/holoplot/go-evdev"
@ -49,6 +50,7 @@ func main() {
input.Close()
}()
var lastOn time.Time
// Start listening for PTT key
slog.Info("Starting event listener", "version", Version)
for !done {
@ -62,10 +64,12 @@ func main() {
}
if ev.Code == evdev.KEY_F24 && ev.Value == 1 {
slog.Info("PTT ON")
lastOn = time.Now()
obj.Call("net.sourceforge.mumble.Mumble.startTalking", 0)
}
if ev.Code == evdev.KEY_F24 && ev.Value == 0 {
slog.Info("PTT OFF")
speakDuration := time.Since(lastOn).String()
slog.Info("PTT OFF", "duration", speakDuration)
obj.Call("net.sourceforge.mumble.Mumble.stopTalking", 0)
}
}