Skip to content

Commit

Permalink
expose control menu type and step size via public API (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasf authored May 9, 2023
1 parent 3b52e93 commit 87693b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/getcontrols/getcontrols.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 2 additions & 0 deletions v4l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type control struct {
id uint32
name string
c_type controlType
step int32
min int32
max int32
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
10 changes: 9 additions & 1 deletion webcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Control struct {
Name string
Min int32
Max int32
Type int32
Step int32
}

// Open a webcam with a given path
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 87693b3

Please sign in to comment.