1
0
Fork 0
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:
Karan Misra 2014-02-27 05:59:38 +05:30
parent 2504678ba9
commit ef87ad7879
7 changed files with 66 additions and 69 deletions

31
host/descriptor.go Normal file
View 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
}