-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimpleton.go
72 lines (60 loc) · 1.82 KB
/
simpleton.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-FileCopyrightText: 2023 Kent Gibson <warthog618@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
package gpiosim
type Simpleton struct {
Sim
}
func NewSimpleton(numLines int) (*Simpleton, error) {
s, err := NewSim(WithBank(NewBank("simpleton", numLines)))
if s == nil {
return nil, err
}
return &Simpleton{*s}, err
}
// ChipName returns the name of the gpiochip.
//
// e.g. "gpiochip0"
func (s *Simpleton) ChipName() string {
return s.Chips[0].chipName
}
// Config returns the configuration used for the Chip.
func (s *Simpleton) Config() Bank {
return s.Chips[0].cfg
}
// DevPath returns the path to the gpiochip device.
//
// e.g. "/dev/gpiochip0"
func (s *Simpleton) DevPath() string {
return s.Chips[0].devPath
}
// Level returns the level the line is being pulled to.
//
// If the line is requested as an output then this is the level userspace is
// driving it to, and otherwise there is little point calling this method -
// you probably should be calling Pull instead.
func (s *Simpleton) Level(offset int) (int, error) {
return s.Chips[0].Level(offset)
}
// Pull returns the current the pull of the given line.
func (s *Simpleton) Pull(offset int) (int, error) {
return s.Chips[0].Pull(offset)
}
// Pulldown sets the pull of the given line to pull-down.
func (s *Simpleton) Pulldown(offset int) error {
return s.Chips[0].Pulldown(offset)
}
// Pullup sets the pull of the given line to pull-up.
func (s *Simpleton) Pullup(offset int) error {
return s.Chips[0].Pullup(offset)
}
// SetPull sets the pull of the given line.
func (s *Simpleton) SetPull(offset int, level int) error {
return s.Chips[0].SetPull(offset, level)
}
// Toggle flips the pull of the given line.
//
// If it was pull-up it becomes pull-down, and vice versa.
func (s *Simpleton) Toggle(offset int) error {
return s.Chips[0].Toggle(offset)
}