-
Notifications
You must be signed in to change notification settings - Fork 110
/
config.go
33 lines (29 loc) · 1.09 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package picommon
import (
"github.com/pkg/errors"
"go.viam.com/rdk/resource"
)
// ServoConfig is the config for a pi servo.
type ServoConfig struct {
Pin string `json:"pin"`
Min int `json:"min,omitempty"`
Max int `json:"max,omitempty"` // specifies a user inputted position limitation
StartPos *float64 `json:"starting_position_degs,omitempty"`
HoldPos *bool `json:"hold_position,omitempty"` // defaults True. False holds for 500 ms then disables servo
BoardName string `json:"board"`
MaxRotation int `json:"max_rotation_deg,omitempty"` // specifies a hardware position limitation. Defaults to 180
}
// Validate ensures all parts of the config are valid.
func (config *ServoConfig) Validate(path string) ([]string, error) {
var deps []string
if config.Pin == "" {
return nil, resource.NewConfigValidationError(path,
errors.New("need pin for pi servo"))
}
if config.BoardName == "" {
return nil, resource.NewConfigValidationError(path,
errors.New("need the name of the board"))
}
deps = append(deps, config.BoardName)
return deps, nil
}