// internal function to get a Pin. It does not use GetPin because that relies on the driver having already been initialised. This
// method can be called while stil initialising. Only matches names[0], which is the Pn.nn expansion header name.
977398
func (d *BeagleBoneBlackDriver) getPin(name string) Pin {
	for i, hw := range d.beaglePins {
		if hw.names[0] == name {
			return Pin(i)
		}
	}
	return Pin(0)
}
28365
func (b *boundManager) Pin(leaseName string, entity string) error {
	return errors.Trace(b.pinOp(leaseName, entity, b.manager.pins))
}
102362
func AssignPin(pin Pin, module Module) error {
	if a := assignedPins[pin]; a != nil {
		return fmt.Errorf("Pin %d is already assigned to module %s", pin, a.module.GetName())
	}
	assignedPins[pin] = &assignedPin{pin, module}
	return nil
}
645557
func (s *Session) verifyPin(pin []byte) error {
	if _, err := s.Channel.transmitEncrypted(claSCWallet, insVerifyPin, 0, 0, pin); err != nil {
		return err
	}
	s.verified = true
	return nil
}
1202410
func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
	hnsResponse, err := HNSListEndpointRequest()
	if err != nil {
		return nil, err
	}
	for _, hnsEndpoint := range hnsResponse {
		if hnsEndpoint.Name == endpointName {
			return &hnsEndpoint, nil
		}
	}
	return nil, EndpointNotFoundError{EndpointName: endpointName}
}
393711
func (p pointer) getInterfacePointer() pointer {
	// Super-tricky - read pointer out of data word of interface value.
	return pointer{p: (*(*[2]unsafe.Pointer)(p.p))[1]}
}
631109
func (c *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	i, err := c.translatePwmPin(pin)
	if err != nil {
		return nil, err
	}
	if i == -1 {
		return nil, errors.New("Not a PWM pin")
	}

	if c.pwmPins[i] == nil {
		newPin := sysfs.NewPWMPin(i)
		if err = newPin.Export(); err != nil {
			return
		}
		// Make sure pwm is disabled when setting polarity
		if err = newPin.Enable(false); err != nil {
			return
		}
		if err = newPin.InvertPolarity(false); err != nil {
			return
		}
		if err = newPin.Enable(true); err != nil {
			return
		}
		if err = newPin.SetPeriod(10000000); err != nil {
			return
		}
		c.pwmPins[i] = newPin
	}

	sysfsPin = c.pwmPins[i]
	return
}
1285282
func (c *Client) updatePin(new string) {
	c.mu.Lock()
	defer c.mu.Unlock()
	c.pinned = new
}
683524
func OpenPin(n int, mode Mode) (Pin, error) {
	// export this pin to create the virtual files on the system
	pinBase, err := expose(n)
	if err != nil {
		return nil, err
	}
	value, err := os.OpenFile(filepath.Join(pinBase, "value"), os.O_RDWR, 0600)
	if err != nil {
		return nil, err
	}
	p := &pin{
		number:    n,
		modePath:  filepath.Join(pinBase, "direction"),
		edgePath:  filepath.Join(pinBase, "edge"),
		valueFile: value,
		initial:   true,
	}
	if err := p.setMode(mode); err != nil {
		p.Close()
		return nil, err
	}
	return p, nil
}
590188
func (c *InstanceCache) Get(ctx context.Context, pin common.Pin, now time.Time) (pkg.Source, error) {
	if err := common.ValidatePin(pin, common.AnyHash); err != nil {
		return nil, err
	}

	path, err := c.fs.RootRelToAbs(pin.InstanceID)
	if err != nil {
		return nil, fmt.Errorf("invalid instance ID %q", pin.InstanceID)
	}

	f, err := c.fs.OpenFile(path)
	if err != nil {
		return nil, err
	}

	c.withState(ctx, now, func(s *messages.InstanceCache) {
		touch(s, pin.InstanceID, now)
	})

	return &cacheFile{f, c.fs}, nil
}
868446
func (s *DriversStore) Get(driverName string) (Driver, bool) {
	s.RLock()
	defer s.RUnlock()

	driver, ok := s.store[driverName]
	return driver, ok
}
295263
func (c *Client) GetPin() ([]byte, error) {
	if _, err := c.in.Write([]byte("GETPIN\n")); err != nil {
		return nil, err
	}
	pin, _, err := c.out.ReadLine()
	if err != nil {
		return nil, err
	}
	if bytes.HasPrefix(pin, []byte("OK")) {
		return nil, nil
	}
	if !bytes.HasPrefix(pin, []byte("D ")) {
		return nil, fmt.Errorf("unexpected response: %s", pin)
	}

	ok, _, err := c.out.ReadLine()
	if err != nil {
		return nil, err
	}
	if !bytes.HasPrefix(ok, []byte("OK")) {
		return nil, fmt.Errorf("unexpected response: %s", ok)
	}
	return pin[2:], nil
}
857788
func (b *DeviceInformationDriver) GetPnPId() (model string) {
	c, _ := b.adaptor().ReadCharacteristic("2a50")
	buf := bytes.NewBuffer(c)
	val := buf.String()
	return val
}
693552
func (p *pinner) Flush() error {
	p.lock.Lock()
	defer p.lock.Unlock()

	ctx := context.TODO()

	internalset := cid.NewSet()
	recordInternal := internalset.Add

	root := &mdag.ProtoNode{}
	{
		n, err := storeSet(ctx, p.internal, p.directPin.Keys(), recordInternal)
		if err != nil {
			return err
		}
		if err := root.AddNodeLink(linkDirect, n); err != nil {
			return err
		}
	}

	{
		n, err := storeSet(ctx, p.internal, p.recursePin.Keys(), recordInternal)
		if err != nil {
			return err
		}
		if err := root.AddNodeLink(linkRecursive, n); err != nil {
			return err
		}
	}

	// add the empty node, its referenced by the pin sets but never created
	err := p.internal.Add(ctx, new(mdag.ProtoNode))
	if err != nil {
		return err
	}

	err = p.internal.Add(ctx, root)
	if err != nil {
		return err
	}

	k := root.Cid()

	internalset.Add(k)
	if err := p.dstore.Put(pinDatastoreKey, k.Bytes()); err != nil {
		return fmt.Errorf("cannot store pin state: %v", err)
	}
	p.internalPin = internalset
	return nil
}
101933
func getNameAddr(keysDir, name, addr string) (string, error) {
	if name == "" && addr == "" {
		return "", fmt.Errorf("at least one of name or addr must be provided")
	}

	// name takes precedent if both are given
	var err error
	if name != "" {
		addr, err = coreNameGet(keysDir, name)
		if err != nil {
			return "", err
		}
	}
	return strings.ToUpper(addr), nil
}
65974
func WithDCPin(val string) func(Config) {
	return func(c Config) {
		d, ok := c.(*SSD1306Driver)
		if ok {
			d.DCPin = val
		} else {
			panic("unable to set dc pin for ssd1306")
		}
	}
}
146774
func (e *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) {
	e.mutex.Lock()
	defer e.mutex.Unlock()

	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 {
			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
}