예제 #1
0
파일: bbb.go 프로젝트: gavincabbage/embd
func ensureFeatureEnabled(id string) error {
	glog.V(3).Infof("bbb: enabling feature %v", id)
	pattern := "/sys/devices/bone_capemgr.*/slots"
	file, err := embd.FindFirstMatchingFile(pattern)
	if err != nil {
		return err
	}
	bytes, err := ioutil.ReadFile(file)
	if err != nil {
		return err
	}
	str := string(bytes)
	if strings.Contains(str, id) {
		glog.V(3).Infof("bbb: feature %v already enabled", id)
		return nil
	}
	slots, err := os.OpenFile(file, os.O_WRONLY, os.ModeExclusive)
	if err != nil {
		return err
	}
	defer slots.Close()
	glog.V(3).Infof("bbb: writing %v to slots file", id)
	_, err = slots.WriteString(id)
	return err
}
예제 #2
0
파일: bbb.go 프로젝트: gavincabbage/embd
// This cannot be currently used to disable things like the
// analog and pwm modules. Removing them from slots file can
// potentially cause a kernel panic and unsettle things. So the
// recommended thing to do is to simply reboot.
func ensureFeatureDisabled(id string) error {
	pattern := "/sys/devices/bone_capemgr.*/slots"
	file, err := embd.FindFirstMatchingFile(pattern)
	if err != nil {
		return err
	}
	slots, err := os.OpenFile(file, os.O_RDWR, os.ModeExclusive)
	if err != nil {
		return err
	}
	defer slots.Close()
	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
	}
	// Could not disable the feature
	return fmt.Errorf("embd: could not disable feature %q", id)
}
예제 #3
0
파일: pwmpin.go 프로젝트: gavincabbage/embd
func (p *pwmPin) basePath() (string, error) {
	pattern := "/sys/devices/ocp.*/pwm_test_" + p.n + ".*"
	return embd.FindFirstMatchingFile(pattern)
}
예제 #4
0
func (p *analogPin) valueFilePath() (string, error) {
	pattern := fmt.Sprintf("/sys/devices/ocp.*/helper.*/AIN%v", p.n)
	return embd.FindFirstMatchingFile(pattern)
}