Merged in config-fix (pull request #174)

revid: improved logic in config.Validate for raspivid options
This commit is contained in:
Saxon Milton 2019-03-18 00:36:54 +00:00
commit 78894ae972
1 changed files with 22 additions and 7 deletions

View File

@ -152,6 +152,9 @@ const (
defaultRtpAddr = "localhost:6970"
defaultBurstPeriod = 10 // Seconds
defaultRotation = 0 // Degrees
defaultBrightness = 50
defaultExposure = "auto"
defaultAutoWhiteBalance = "auto"
)
// Validate checks for any errors in the config fields and defaults settings
@ -292,20 +295,32 @@ func (c *Config) Validate(r *Revid) error {
c.RtpAddress = defaultRtpAddr
}
if c.Brightness < 0 || c.Brightness > 100 {
return errors.New("bad brightness setting in config")
switch {
case c.Brightness == 0:
c.Logger.Log(logger.Info, pkg+"brightness undefined, defaulting", "brightness", defaultBrightness)
c.Brightness = defaultBrightness
case c.Brightness < 0 || c.Brightness > 100:
return errors.New(pkg + "bad brightness defined in config")
}
if c.Saturation < -100 || c.Saturation > 100 {
return errors.New("bad saturation setting in config")
return errors.New(pkg + "bad saturation setting in config")
}
if !stringInSlice(c.Exposure, ExposureModes[:]) {
return errors.New("bad exposure setting in config")
switch {
case c.Exposure == "":
c.Logger.Log(logger.Info, pkg+"exposure undefined, defaulting", "exposure", defaultExposure)
c.Exposure = defaultExposure
case !stringInSlice(c.Exposure, ExposureModes[:]):
return errors.New(pkg + "bad exposure setting in config")
}
if !stringInSlice(c.AutoWhiteBalance, AutoWhiteBalanceModes[:]) {
return errors.New("bad awb setting in config")
switch {
case c.AutoWhiteBalance == "":
c.Logger.Log(logger.Info, pkg+"auto white balance undefined, defaulting", "autoWhiteBalance", defaultAutoWhiteBalance)
c.AutoWhiteBalance = defaultAutoWhiteBalance
case !stringInSlice(c.AutoWhiteBalance, AutoWhiteBalanceModes[:]):
return errors.New(pkg + "bad auto white balance setting in config")
}
return nil