forked from mrmorphic/hwio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
capability.go
48 lines (42 loc) · 1.16 KB
/
capability.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
37
38
39
40
41
42
43
44
45
46
47
48
package hwio
// Definitions for capabilities.
import (
"strings"
)
//Define a generic way to represent pin capabilities.
type Capability int
const (
CAP_INPUT Capability = iota // digital input
CAP_OUTPUT // digital output
CAP_INPUT_PULLUP // digital input with pull up
CAP_INPUT_PULLDOWN // digital input with pull down
CAP_PWM // "analog" output using pwm
CAP_ANALOG_IN // analog input using A/D converter
)
// This represents a set of capabilities that a pin may have. There may be multiple pins on a device that have identical
// capability set.
type CapabilitySet []Capability
func (c Capability) String() string {
switch c {
case CAP_INPUT:
return "input"
case CAP_OUTPUT:
return "output"
case CAP_INPUT_PULLUP:
return "input_pullup"
case CAP_INPUT_PULLDOWN:
return "input_pulldown"
case CAP_PWM:
return "pwm"
case CAP_ANALOG_IN:
return "analog_in"
}
return ""
}
func (cs CapabilitySet) String() string {
s := []string{}
for _, c := range cs {
s = append(s, Capability(c).String())
}
return strings.Join(s, ",")
}