// doneWithPins is a handy shortcut that prints a pinInfo slice and
// deduces process exit code based on presence of errors there.
//
// This just calls through to doneWithPinMap.
518486
func (c *cipdSubcommand) doneWithPins(pins []pinInfo, err error) int {
	return c.doneWithPinMap(map[string][]pinInfo{"": pins}, err)
}
1274847
func (b *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
	b.mutex.Lock()
	defer b.mutex.Unlock()

	pinInfo, err := b.translatePwmPin(pin)
	if err != nil {
		return nil, err
	}

	if b.pwmPins[pin] == nil {
		newPin := sysfs.NewPWMPin(pinInfo.channel)
		if err = muxPin(pin, "pwm"); err != nil {
			return
		}

		if newPin.Path, err = b.findPin(pinInfo.path); err != nil {
			return
		}
		if err = newPin.Export(); err != nil {
			return
		}
		if err = newPin.SetPeriod(pwmDefaultPeriod); err != nil {
			return
		}
		if err = newPin.Enable(true); err != nil {
			return
		}
		b.pwmPins[pin] = newPin
	}

	sysfsPin = b.pwmPins[pin]

	return
}
1186672
func (b *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) {
	b.mutex.Lock()
	defer b.mutex.Unlock()

	i, err := b.translatePin(pin)
	if err != nil {
		return
	}
	if b.digitalPins[i] == nil {
		b.digitalPins[i] = sysfs.NewDigitalPin(i)
		if err = muxPin(pin, "gpio"); err != nil {
			return
		}

		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
}
648958
func (e *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
	e.mutex.Lock()
	defer e.mutex.Unlock()

	sysPin, ok := sysfsPinMap[pin]
	if !ok {
		err = errors.New("Not a valid pin")
		return
	}
	if sysPin.pwmPin != -1 {
		if e.pwmPins[sysPin.pwmPin] == nil {
			e.pwmPins[sysPin.pwmPin] = sysfs.NewPWMPin(sysPin.pwmPin)
			if err = e.pwmPins[sysPin.pwmPin].Export(); err != nil {
				return
			}
			if err = e.pwmPins[sysPin.pwmPin].SetPeriod(10000000); err != nil {
				return
			}
			if err = e.pwmPins[sysPin.pwmPin].Enable(true); err != nil {
				return
			}
		}

		sysfsPin = e.pwmPins[sysPin.pwmPin]
		return
	}
	err = errors.New("Not a PWM pin")
	return
}
1100102
func (b *Adaptor) translatePin(pin string) (value int, err error) {
	if val, ok := b.pinMap[pin]; ok {
		value = val
	} else {
		err = errors.New("Not a valid pin")
	}
	return
}
81339
func (e *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) {
	e.mutex.Lock()
	defer e.mutex.Unlock()

	i := e.pinmap[pin]
	if e.digitalPins[i.pin] == nil {
		e.digitalPins[i.pin], err = e.newExportedPin(i.pin)
		if err != nil {
			return
		}

		if i.resistor > 0 {
			e.digitalPins[i.resistor], err = e.newExportedPin(i.resistor)
			if err != nil {
				return
			}
		}

		if i.levelShifter > 0 {
			e.digitalPins[i.levelShifter], err = e.newExportedPin(i.levelShifter)
			if err != nil {
				return
			}
		}

		if len(i.mux) > 0 {
			for _, mux := range i.mux {
				e.digitalPins[mux.pin], err = e.newExportedPin(mux.pin)
				if err != nil {
					return
				}

				err = pinWrite(e.digitalPins[mux.pin], sysfs.OUT, mux.value)
				if err != nil {
					return
				}
			}
		}
	}

	if dir == "in" {
		if err = e.digitalPins[i.pin].Direction(sysfs.IN); err != nil {
			return
		}

		if i.resistor > 0 {
			err = pinWrite(e.digitalPins[i.resistor], sysfs.OUT, sysfs.LOW)
			if err != nil {
				return
			}
		}

		if i.levelShifter > 0 {
			err = pinWrite(e.digitalPins[i.levelShifter], sysfs.OUT, sysfs.LOW)
			if 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 {
			err = pinWrite(e.digitalPins[i.levelShifter], sysfs.OUT, sysfs.HIGH)
			if err != nil {
				return
			}
		}
	}
	return e.digitalPins[i.pin], nil
}
1120766
func (api *Client) AddPinContext(ctx context.Context, channel string, item ItemRef) error {
	values := url.Values{
		"channel": {channel},
		"token":   {api.token},
	}
	if item.Timestamp != "" {
		values.Set("timestamp", item.Timestamp)
	}
	if item.File != "" {
		values.Set("file", item.File)
	}
	if item.Comment != "" {
		values.Set("file_comment", item.Comment)
	}

	response := &SlackResponse{}
	if err := api.postMethod(ctx, "pins.add", values, response); err != nil {
		return err
	}

	return response.Err()
}
167307
func (r *cmdRun) done(err error) int {
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		if err, ok := err.(*exitCode); ok {
			return err.code
		}
		return ecOtherError
	}
	return 0
}
805346
func (t *TeamDiscussion) GetPinned() bool {
	if t == nil || t.Pinned == nil {
		return false
	}
	return *t.Pinned
}
871892
func GetPinWithMode(cname string, mode PinIOMode) (pin Pin, e error) {
	p, e := GetPin(cname)
	if e != nil {
		return
	}

	e = PinMode(p, mode)
	return p, e
}
613689
func (module *BBPWMModule) EnablePin(pin Pin, enabled bool) error {
	if module.definedPins[pin] == nil {
		return fmt.Errorf("Pin %d is not known as a PWM pin on module %s", pin, module.GetName())
	}

	openPin := module.openPins[pin]
	if enabled {
		// ensure pin is enabled by creating an open pin
		if openPin == nil {
			p, e := module.makeOpenPin(pin)
			if e != nil {
				return e
			}
			module.openPins[pin] = p
			return p.enabled(true)
		}
	} else {
		// disable the pin if enabled
		if openPin != nil {
			return openPin.enabled(false)
		}
	}
	return nil
}
1285282
func (c *Client) updatePin(new string) {
	c.mu.Lock()
	defer c.mu.Unlock()
	c.pinned = new
}
1308625
func (p *pinner) RemovePinWithMode(c cid.Cid, mode Mode) {
	p.lock.Lock()
	defer p.lock.Unlock()
	switch mode {
	case Direct:
		p.directPin.Remove(c)
	case Recursive:
		p.recursePin.Remove(c)
	default:
		// programmer error, panic OK
		panic("unrecognized pin type")
	}
}
1357014
func (w *upgradeSeriesWorker) pinLeaders() (err error) {
	// if we encounter an error,
	// attempt to ensure that no application leaders remain pinned.
	defer func() {
		if err != nil {
			if unpinErr := w.unpinLeaders(); unpinErr != nil {
				err = errors.Wrap(err, unpinErr)
			}
		}
	}()

	results, err := w.PinMachineApplications()
	if err != nil {
		// If pin machine applications method return not implemented because it's
		// utilising the legacy leases store, then we should display the warning
		// in the log and return out. Unpinning leaders should be safe as that
		// should be considered a no-op
		if params.IsCodeNotImplemented(err) {
			w.logger.Infof("failed to pin machine applications, with legacy lease manager leadership pinning is not implemented")
			return nil
		}
		return errors.Trace(err)
	}

	var lastErr error
	for app, err := range results {
		if err == nil {
			w.logger.Infof("unpin leader for application %q", app)
			continue
		}
		w.logger.Errorf("failed to pin leader for application %q: %s", app, err.Error())
		lastErr = err
	}

	if lastErr == nil {
		w.leadersPinned = true
		return nil
	}
	return errors.Trace(lastErr)
}
974198
func PullDown(key interface{}) error {
	pin, err := NewDigitalPin(key)
	if err != nil {
		return err
	}

	return pin.PullDown()
}
297650
func (p *pinner) IsPinnedWithType(c cid.Cid, mode Mode) (string, bool, error) {
	p.lock.RLock()
	defer p.lock.RUnlock()
	return p.isPinnedWithType(c, mode)
}
979145
func OpenPin(number int, mode gpio.Mode) (gpio.Pin, error) {
	initOnce.Do(initRPi)
	p, err := gpio.OpenPin(number, mode)
	return &pin{Pin: p, pin: uint8(number)}, err
}