Checkpoint
This commit is contained in:
138 files changed
+1898
-57607
No files matched your search
+37
-9
@@ -1,17 +1,45 @@
|
||||
// Package hardware contains all hardware interface implementations.
|
||||
package hardware
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
// Resource is a basic resource (like an input) or a device.
|
||||
type Resource interface {
|
||||
// String returns the human readable name of the resource.
|
||||
String() string
|
||||
"periph.io/x/conn/v3/gpio"
|
||||
"periph.io/x/conn/v3/gpio/gpioreg"
|
||||
)
|
||||
|
||||
// Halt stops the resource.
|
||||
// Driver is a piece of hardware that can be stopped.
|
||||
type Driver interface {
|
||||
// Type of the driver.
|
||||
Type() string
|
||||
|
||||
// Halt shuts down the driver.
|
||||
Halt() error
|
||||
}
|
||||
|
||||
// IsNotFound for resources that return a NotFound error.
|
||||
func IsNotFound(err error) bool {
|
||||
return errors.Is(err, PinNotFound{})
|
||||
// PinNotFound error indicating that the requested pin could not be found.
|
||||
type PinNotFound struct {
|
||||
Alias string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (err PinNotFound) Error() string {
|
||||
if err.Alias == "" {
|
||||
return fmt.Sprintf("invalid pin %q", err.Name)
|
||||
}
|
||||
return fmt.Sprintf("invalid %s pin %q", err.Alias, err.Name)
|
||||
}
|
||||
|
||||
// LookupPin returns a GPIO pin by name or number.
|
||||
func LookupPin(name string) (gpio.PinIO, error) {
|
||||
pin := gpioreg.ByName(name)
|
||||
if !IsValidPin(pin) {
|
||||
return nil, PinNotFound{Name: name}
|
||||
}
|
||||
return pin, nil
|
||||
}
|
||||
|
||||
// IsValidPin checks if the provided GPIO pin can be used.
|
||||
func IsValidPin(pin gpio.PinIO) bool {
|
||||
return pin != nil && pin != gpio.INVALID
|
||||
}
|
||||
Reference in new issue
Block a user