1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 21:00:05 +01:00

bbb: disable the pwm pin when closed

This commit is contained in:
Karan Misra 2014-03-29 19:19:40 +05:30
parent f7e8cb31d4
commit ea3afb8538

34
bbb.go
View File

@ -8,6 +8,7 @@
package embd package embd
import ( import (
"bufio"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -130,29 +131,37 @@ func bbbEnsureFeatureEnabled(id string) error {
return err return err
} }
// This needs a little more work.
func bbbEnsureFeatureDisabled(id string) error { func bbbEnsureFeatureDisabled(id string) error {
pattern := "/sys/devices/bone_capemgr.*/slots" pattern := "/sys/devices/bone_capemgr.*/slots"
file, err := findFirstMatchingFile(pattern) file, err := findFirstMatchingFile(pattern)
if err != nil { if err != nil {
return err return err
} }
bytes, err := ioutil.ReadFile(file) slots, err := os.OpenFile(file, os.O_RDWR, os.ModeExclusive)
if err != nil {
return err
}
str := string(bytes)
if !strings.Contains(str, id) {
return nil
}
slots, err := os.OpenFile(file, os.O_WRONLY, os.ModeExclusive)
if err != nil { if err != nil {
return err return err
} }
defer slots.Close() defer slots.Close()
_, err = slots.WriteString("-" + id) scanner := bufio.NewScanner(slots)
for scanner.Scan() {
text := scanner.Text()
if !strings.Contains(text, id) {
continue
}
// Extract the id from the line
idx := strings.Index(text, ":")
if idx < 0 {
// Something is off, bail
continue
}
dis := strings.TrimSpace(text[:idx])
slots.Seek(0, 0)
_, err = slots.WriteString("-" + dis)
return err return err
} }
// Could not disable the feature
return fmt.Errorf("embd: could not disable feature %q", id)
}
type bbbAnalogPin struct { type bbbAnalogPin struct {
n int n int
@ -317,8 +326,7 @@ func (p *bbbPWMPin) ensurePinEnabled() error {
} }
func (p *bbbPWMPin) ensurePinDisabled() error { func (p *bbbPWMPin) ensurePinDisabled() error {
return nil return bbbEnsureFeatureDisabled(p.id())
// return bbbEnsureFeatureDisabled(p.id())
} }
func (p *bbbPWMPin) basePath() (string, error) { func (p *bbbPWMPin) basePath() (string, error) {