// arduinoSetup does needed setup for the Arduino compatible breakout board func (e *Adaptor) arduinoSetup() (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 }
func (e *Adaptor) arduinoI2CSetup() (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 } return }
// digitalPin retrieves digital pin value by name func (b *Adaptor) digitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPin, err error) { i, err := b.translatePin(pin) if err != nil { return } if b.digitalPins[i] == nil { b.digitalPins[i] = sysfs.NewDigitalPin(i) err := b.digitalPins[i].Export() if err != nil { return nil, err } } if err = b.digitalPins[i].Direction(dir); err != nil { return } return b.digitalPins[i], nil }
// digitalPin returns matched digitalPin for specified values func (r *Adaptor) digitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPin, err error) { i, err := r.translatePin(pin) if err != nil { return } if r.digitalPins[i] == nil { r.digitalPins[i] = sysfs.NewDigitalPin(i) if err = r.digitalPins[i].Export(); err != nil { return } } if err = r.digitalPins[i].Direction(dir); err != nil { return } return r.digitalPins[i], nil }
// digitalPin returns matched digitalPin for specified values func (e *Adaptor) digitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPin, err error) { i := sysfsPinMap[pin] if e.digitalPins[i.pin] == nil { e.digitalPins[i.pin] = sysfs.NewDigitalPin(i.pin) if err = e.digitalPins[i.pin].Export(); err != nil { // TODO: log error return } } if dir == "in" { if err = e.digitalPins[i.pin].Direction(sysfs.IN); err != nil { return } } else if dir == "out" { if err = e.digitalPins[i.pin].Direction(sysfs.OUT); err != nil { return } } return e.digitalPins[i.pin], nil }
// digitalPin returns matched digitalPin for specified values func (e *Adaptor) digitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPin, err error) { i := e.pinmap[pin] if e.digitalPins[i.pin] == nil { e.digitalPins[i.pin] = sysfs.NewDigitalPin(i.pin) if err = e.digitalPins[i.pin].Export(); err != nil { return } if i.resistor > 0 { e.digitalPins[i.resistor] = sysfs.NewDigitalPin(i.resistor) if err = e.digitalPins[i.resistor].Export(); err != nil { return } } if i.levelShifter > 0 { e.digitalPins[i.levelShifter] = sysfs.NewDigitalPin(i.levelShifter) if err = e.digitalPins[i.levelShifter].Export(); err != nil { return } } if len(i.mux) > 0 { for _, mux := range i.mux { e.digitalPins[mux.pin] = sysfs.NewDigitalPin(mux.pin) if err = e.digitalPins[mux.pin].Export(); err != nil { return } if err = e.digitalPins[mux.pin].Direction(sysfs.OUT); err != nil { return } if err = e.digitalPins[mux.pin].Write(mux.value); err != nil { return } } } } if dir == "in" { if err = e.digitalPins[i.pin].Direction(sysfs.IN); err != nil { return } if i.resistor > 0 { if err = e.digitalPins[i.resistor].Direction(sysfs.OUT); err != nil { return } if err = e.digitalPins[i.resistor].Write(sysfs.LOW); err != nil { return } } if i.levelShifter > 0 { if err = e.digitalPins[i.levelShifter].Direction(sysfs.OUT); err != nil { return } if err = e.digitalPins[i.levelShifter].Write(sysfs.LOW); err != nil { return } } } else if dir == "out" { if err = e.digitalPins[i.pin].Direction(sysfs.OUT); err != nil { return } if i.resistor > 0 { if err = e.digitalPins[i.resistor].Direction(sysfs.IN); err != nil { return } } if i.levelShifter > 0 { if err = e.digitalPins[i.levelShifter].Direction(sysfs.OUT); err != nil { return } if err = e.digitalPins[i.levelShifter].Write(sysfs.HIGH); err != nil { return } } } return e.digitalPins[i.pin], nil }