Example #1
0
// I2cStart initializes i2c device for addresss
func (e *EdisonAdaptor) I2cStart(address byte) (err error) {
	if err = e.tristate.Write(sysfs.LOW); err != nil {
		return
	}

	for _, i := range []int{14, 165, 212, 213} {
		io := sysfs.NewDigitalPin(i)
		if err = io.Export(); err != nil {
			return
		}
		if err = io.Direction(sysfs.IN); err != nil {
			return
		}
		if err = io.Unexport(); err != nil {
			return
		}
	}

	for _, i := range []int{236, 237, 204, 205} {
		io := sysfs.NewDigitalPin(i)
		if err = io.Export(); err != nil {
			return
		}
		if err = io.Direction(sysfs.OUT); err != nil {
			return
		}
		if err = io.Write(sysfs.LOW); err != nil {
			return
		}
		if err = io.Unexport(); err != nil {
			return
		}
	}

	for _, i := range []string{"28", "27"} {
		if err = changePinMode(i, "1"); err != nil {
			return
		}
	}

	if err = e.tristate.Write(sysfs.HIGH); err != nil {
		return
	}

	e.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-6", address)
	return
}
Example #2
0
// NewEdisonAdaptor returns a new EdisonAdaptor with specified name
func NewEdisonAdaptor(name string) *EdisonAdaptor {
	return &EdisonAdaptor{
		name: name,
		connect: func(e *EdisonAdaptor) (err error) {
			e.tristate = sysfs.NewDigitalPin(214)
			if err = e.tristate.Export(); err != nil {
				return err
			}
			if err = e.tristate.Direction(sysfs.OUT); err != nil {
				return err
			}
			if err = e.tristate.Write(sysfs.LOW); err != nil {
				return err
			}

			for _, i := range []int{263, 262} {
				io := sysfs.NewDigitalPin(i)
				if err = io.Export(); err != nil {
					return err
				}
				if err = io.Direction(sysfs.OUT); err != nil {
					return err
				}
				if err = io.Write(sysfs.HIGH); err != nil {
					return err
				}
				if err = io.Unexport(); err != nil {
					return err
				}
			}

			for _, i := range []int{240, 241, 242, 243} {
				io := sysfs.NewDigitalPin(i)
				if err = io.Export(); err != nil {
					return err
				}
				if err = io.Direction(sysfs.OUT); err != nil {
					return err
				}
				if err = io.Write(sysfs.LOW); err != nil {
					return err
				}
				if err = io.Unexport(); err != nil {
					return err
				}

			}

			for _, i := range []string{"111", "115", "114", "109"} {
				if err = changePinMode(i, "1"); err != nil {
					return err
				}
			}

			for _, i := range []string{"131", "129", "40"} {
				if err = changePinMode(i, "0"); err != nil {
					return err
				}
			}

			err = e.tristate.Write(sysfs.HIGH)
			return
		},
	}
}