-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
68 lines (60 loc) · 1.37 KB
/
types.go
File metadata and controls
68 lines (60 loc) · 1.37 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package tinygo_pullup
import (
"machine"
)
type (
// DefaultHandler is the default implementation to handle pull-up resistor.
DefaultHandler struct {
inputPin machine.Pin
}
)
// NewDefaultHandler creates a new instance of DefaultHandler
//
// Parameters:
//
// inputPin: The GPIO pin to be used as the input pin.
//
// Returns:
//
// An instance of DefaultHandler.
func NewDefaultHandler(inputPin machine.Pin) *DefaultHandler {
return &DefaultHandler{
inputPin,
}
}
// Setup initializes the input pin for the DefaultHandler
func (d *DefaultHandler) Setup() {
d.inputPin.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
}
// IsHigh checks if the input pin is high.
//
// Returns:
//
// True if the input pin is high, otherwise false.
func (d *DefaultHandler) IsHigh() bool {
return d.inputPin.Get()
}
// IsLow checks if the input pin is low.
//
// Returns:
//
// True if the input pin is low, otherwise false.
func (d *DefaultHandler) IsLow() bool {
return !d.inputPin.Get()
}
// IsOpen checks if the input pin is open (not connected).
//
// Returns:
//
// True if the input pin is open, otherwise false.
func (d *DefaultHandler) IsOpen() bool {
return d.IsHigh()
}
// IsShorted checks if the input pin is shorted (connected to ground).
//
// Returns:
//
// True if the input pin is shorted, otherwise false.
func (d *DefaultHandler) IsShorted() bool {
return d.IsLow()
}