-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
36 lines (30 loc) · 865 Bytes
/
options.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
34
35
36
package buttonshim
import "time"
// Option allows specifying behavior for the driver.
type Option func(*options)
// WithGamma allows overriding the gamma curve for the LED. Must include 256
// level mappings.
func WithGamma(gamma []byte) Option {
return func(options *options) {
if len(gamma) != 256 {
panic("Must pass 256 gamma levels")
}
options.gamma = gamma
}
}
// WithButtonPollInterval allows modifying the button poll interval. A longer
// interval will use fewer system resources, but risks not registering a fast
// button press. Default 50ms.
func WithButtonPollInterval(interval time.Duration) Option {
return func(options *options) {
options.buttonPoll = interval
}
}
type options struct {
gamma []byte
buttonPoll time.Duration
}
var defaultOptions = options{
gamma: defaultGamma,
buttonPoll: 50 * time.Millisecond,
}