1
0
Fork 0
mirror of https://github.com/kidoman/embd synced 2025-07-03 11:57:38 +02:00

more streamlining

This commit is contained in:
Karan Misra 2014-02-27 04:44:50 +05:30
parent b5e2d0acc7
commit 6ea4e31399
4 changed files with 11 additions and 13 deletions

View file

@ -1,28 +0,0 @@
package host
import (
"errors"
"github.com/kidoman/embd/gpio"
"github.com/kidoman/embd/host/rpi"
"github.com/kidoman/embd/i2c"
)
type Descriptor interface {
GPIO() gpio.GPIO
I2C() i2c.I2C
}
func Describe() (Descriptor, error) {
host, rev, err := Detect()
if err != nil {
return nil, err
}
switch host {
case RPi:
return rpi.Descriptor(rev), nil
default:
return nil, errors.New("host: invalid host")
}
}

View file

@ -1,78 +0,0 @@
package host
import (
"fmt"
"os/exec"
"strconv"
"strings"
)
type Host int
const (
Null Host = iota
RPi
BBB
)
func execOutput(name string, arg ...string) (output string, err error) {
var out []byte
if out, err = exec.Command(name, arg...).Output(); err != nil {
return
}
output = string(out)
return
}
func nodeName() (string, error) {
return execOutput("uname", "-n")
}
func kernelVersion() (major, minor, patch int, err error) {
output, err := execOutput("uname", "-r")
if err != nil {
return
}
parts := strings.Split(output, ".")
if major, err = strconv.Atoi(parts[0]); err != nil {
return
}
if minor, err = strconv.Atoi(parts[1]); err != nil {
return
}
if patch, err = strconv.Atoi(parts[2]); err != nil {
return
}
return
}
func Detect() (host Host, rev int, err error) {
major, minor, patch, err := kernelVersion()
if err != nil {
return
}
if major < 3 || (major == 3 && minor < 8) {
err = fmt.Errorf("embd: linux kernel versions lower than 3.8 are not supported. you have %v.%v.%v", major, minor, patch)
return
}
node, err := nodeName()
if err != nil {
return
}
switch node {
case "raspberrypi":
host = RPi
case "beaglebone":
host = BBB
default:
err = fmt.Errorf("embd: your host %q is not supported at this moment. please request support at https://github.com/kidoman/embd/issues", node)
}
return
}