From 87693b3f29dc89f2c1150ef4a33c92bd34ae6229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Fr=C3=B6ssman?= Date: Tue, 9 May 2023 20:01:25 +0200 Subject: [PATCH] expose control menu type and step size via public API (#62) --- examples/getcontrols/getcontrols.go | 2 +- v4l2.go | 2 ++ webcam.go | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/getcontrols/getcontrols.go b/examples/getcontrols/getcontrols.go index eefd062..246e947 100644 --- a/examples/getcontrols/getcontrols.go +++ b/examples/getcontrols/getcontrols.go @@ -35,6 +35,6 @@ func main() { cmap := cam.GetControls() fmt.Println("Available controls: ") for id, c := range cmap { - fmt.Printf("ID:%08x %-32s Min: %4d Max: %5d\n", id, c.Name, c.Min, c.Max) + fmt.Printf("ID:%08x %-32s Type: %1d Min: %6d Max: %6d Step: %6d\n", id, c.Name, c.Type, c.Min, c.Max, c.Step) } } diff --git a/v4l2.go b/v4l2.go index 8a67002..7e538fe 100644 --- a/v4l2.go +++ b/v4l2.go @@ -28,6 +28,7 @@ type control struct { id uint32 name string c_type controlType + step int32 min int32 max int32 } @@ -654,6 +655,7 @@ func queryControls(fd uintptr) []control { c.name = CToGoString(query.name[:]) c.min = query.minimum c.max = query.maximum + c.step = query.step controls = append(controls, c) } } diff --git a/webcam.go b/webcam.go index 97790d2..dcb5ca5 100644 --- a/webcam.go +++ b/webcam.go @@ -25,6 +25,8 @@ type Control struct { Name string Min int32 Max int32 + Type int32 + Step int32 } // Open a webcam with a given path @@ -179,7 +181,13 @@ func (w *Webcam) SetBufferCount(count uint32) error { func (w *Webcam) GetControls() map[ControlID]Control { cmap := make(map[ControlID]Control) for _, c := range queryControls(w.fd) { - cmap[ControlID(c.id)] = Control{c.name, c.min, c.max} + cmap[ControlID(c.id)] = Control{ + Name: c.name, + Min: c.min, + Max: c.max, + Type: int32(c.c_type), + Step: c.step, + } } return cmap }