diff --git a/input/gvctrl/gvctrl.go b/input/gvctrl/gvctrl.go index 21b6e583..49065d82 100644 --- a/input/gvctrl/gvctrl.go +++ b/input/gvctrl/gvctrl.go @@ -190,6 +190,7 @@ func Quality(q quality) option { } } +// TODO: add check of r func BitRate(r int) option { return func(s settings) error { var ( @@ -200,17 +201,17 @@ func BitRate(r int) option { ) if s.vbr == "1" { - s.bitRate = convRate(r, vbrRates) + s.bitRate = closestValStr(r, vbrRates) return nil } switch s.res { case "12800720": - s.bitRate = convRate(r, cbrRates720) + s.bitRate = closestValStr(r, cbrRates720) case "6400360": - s.bitRate = convRate(r, cbrRates360) + s.bitRate = closestValStr(r, cbrRates360) case "4480256": - s.bitRate = convRate(r, cbrRates256) + s.bitRate = closestValStr(r, cbrRates256) default: panic("bad resolution") } @@ -218,8 +219,19 @@ func BitRate(r int) option { } } -func Refresh(r int) option { - return func(settings) error { +func Refresh(r float64) option { + return func(s settings) error { + const ( + maxRefreshPeriod = 5 + minRefreshPeriod = .25 + ) + + if minRefreshPeriod > r || r > maxRefreshPeriod { + return fmt.Errorf("invalid refresh period: %g", r) + } + + refOptions := []int{250, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000} + s.refresh = closestValStr(int(r*1000), refOptions) return nil } } diff --git a/input/gvctrl/utils.go b/input/gvctrl/utils.go index 21986341..ddd4a838 100644 --- a/input/gvctrl/utils.go +++ b/input/gvctrl/utils.go @@ -49,6 +49,6 @@ func closestValIdx(v int, l []int) int { return idx } -func convRate(v int, l []int) string { +func closestValStr(v int, l []int) string { return strconv.Itoa(l[closestValIdx(v, l)] * 1000) }