Skip to content

Commit

Permalink
beaglebone: auto-detect Linux kernel version
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Nov 27, 2016
1 parent 24479a2 commit 20235ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
12 changes: 0 additions & 12 deletions platforms/beaglebone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,3 @@ func main() {
robot.Start()
}
```

### Using with older kernel version

The new default for the Gobot Beaglebone adaptor is for the 4.x kernel, such as that used with the Debian Jessie.

If you want to use the older kernel version, such as that on the Angstrom Linux, use the `SetKernel()` function as follows:

```go
beagleboneAdaptor := beaglebone.NewAdaptor()
beagleboneAdaptor.SetKernel("3")

```
22 changes: 12 additions & 10 deletions platforms/beaglebone/beaglebone_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -35,7 +36,6 @@ type Adaptor struct {
func NewAdaptor() *Adaptor {
b := &Adaptor{
name: "Beaglebone",
kernel: "4",
digitalPins: make([]sysfs.DigitalPin, 120),
pwmPins: make(map[string]*pwmPin),
}
Expand All @@ -47,13 +47,15 @@ func NewAdaptor() *Adaptor {
func (b *Adaptor) setSlots() {
ocp := "/sys/devices/ocp.*"
slots := "/sys/devices/bone_capemgr.*"
b.usrLed = "/sys/class/leds/beaglebone:green:"

if b.kernel == "4" {
b.kernel = getKernel()
if string(b.kernel[0]) == "4" {
ocp = "/sys/devices/platform/ocp/ocp*"
slots = "/sys/devices/platform/bone_capemgr"
}

b.usrLed = "/sys/class/leds/beaglebone:green:"

g, _ := glob(ocp)
b.ocp = g[0]

Expand All @@ -67,15 +69,9 @@ func (b *Adaptor) Name() string { return b.name }
// SetName sets the Adaptor name
func (b *Adaptor) SetName(n string) { b.name = n }

// Kernel returns the kernel major version for the BeagleBone
// Kernel returns the Linux kernel version for the BeagleBone
func (b *Adaptor) Kernel() string { return b.kernel }

// SetKernel sets the Adaptor kernel
func (b *Adaptor) SetKernel(n string) {
b.kernel = n
b.setSlots()
}

// Connect initializes the pwm and analog dts.
func (b *Adaptor) Connect() error {
if err := ensureSlot(b.slots, "cape-bone-iio"); err != nil {
Expand Down Expand Up @@ -327,3 +323,9 @@ func ensureSlot(slots, item string) (err error) {
}
return
}

func getKernel() string {
result, _ := exec.Command("uname", "-r").Output()

return strings.TrimSpace(string(result))
}

0 comments on commit 20235ff

Please sign in to comment.