mirror of
https://github.com/kidoman/embd
synced 2025-07-03 03:47:33 +02:00
make the process of registered available hosts less clunky
This commit is contained in:
parent
2504678ba9
commit
ef87ad7879
7 changed files with 66 additions and 69 deletions
31
host/descriptor.go
Normal file
31
host/descriptor.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/kidoman/embd/gpio"
|
||||
"github.com/kidoman/embd/i2c"
|
||||
)
|
||||
|
||||
type Descriptor struct {
|
||||
GPIO func() gpio.GPIO
|
||||
I2C func() i2c.I2C
|
||||
}
|
||||
|
||||
type Describer func(rev int) *Descriptor
|
||||
|
||||
var Describers = map[Host]Describer{}
|
||||
|
||||
func Describe() (*Descriptor, error) {
|
||||
host, rev, err := Detect()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
describer, ok := Describers[host]
|
||||
if !ok {
|
||||
return nil, errors.New("host: invalid host")
|
||||
}
|
||||
|
||||
return describer(rev), nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue