// AnalogRead returns value from analog reading of specified pin
544327
func (d *ADS1x15Driver) AnalogRead(pin string) (value int, err error) {
	var useDifference = false
	var channel int
	var read float64

	// First case: the ADC is used in difference mode
	switch pin {
	case "0-1":
		useDifference = true
		channel = 0
		break
	case "0-3":
		useDifference = true
		channel = 1
		break
	case "1-3":
		useDifference = true
		channel = 2
		break
	case "2-3":
		useDifference = true
		channel = 3
		break
	}

	if useDifference {
		read, err = d.ReadDifferenceWithDefaults(channel)
	} else {
		// Second case: read the voltage at a specific pin, compared to the ground
		channel, err = strconv.Atoi(pin)
		if err != nil {
			return
		}

		read, err = d.ReadWithDefaults(channel)
	}

	if err == nil {
		value = int(gobot.ToScale(gobot.FromScale(read, 0, d.gainVoltage[d.DefaultGain]), 0, 1023))
	}

	return
}
317007
func (m *MonotonicEntropy) MonotonicRead(ms uint64, entropy []byte) (err error) {
	if !m.entropy.IsZero() && m.ms == ms {
		err = m.increment()
		m.entropy.AppendTo(entropy)
	} else if _, err = io.ReadFull(m.Reader, entropy); err == nil {
		m.ms = ms
		m.entropy.SetBytes(entropy)
	}
	return err
}
222669
func (f *Adaptor) DigitalWrite(pin string, level byte) (err error) {
	p, err := strconv.Atoi(pin)
	if err != nil {
		return
	}

	if f.Board.Pins()[p].Mode != client.Output {
		err = f.Board.SetPinMode(p, client.Output)
		if err != nil {
			return
		}
	}

	err = f.Board.DigitalWrite(p, int(level))
	return
}
1267585
func (f *inFlow) onRead(n uint32) uint32 {
	f.mu.Lock()
	if f.pendingData == 0 {
		f.mu.Unlock()
		return 0
	}
	f.pendingData -= n
	if n > f.delta {
		n -= f.delta
		f.delta = 0
	} else {
		f.delta -= n
		n = 0
	}
	f.pendingUpdate += n
	if f.pendingUpdate >= f.limit/4 {
		wu := f.pendingUpdate
		f.pendingUpdate = 0
		f.mu.Unlock()
		return wu
	}
	f.mu.Unlock()
	return 0
}
384816
func (i *UI) read(opts *readOptions) (string, error) {
	i.once.Do(i.setDefault)

	// sigCh is channel which is watch Interruptted signal (SIGINT)
	sigCh := make(chan os.Signal, 1)
	signal.Notify(sigCh, os.Interrupt)
	defer signal.Stop(sigCh)

	var resultStr string
	var resultErr error
	doneCh := make(chan struct{})

	go func() {
		defer close(doneCh)

		if opts.mask {
			f, ok := i.Reader.(*os.File)
			if !ok {
				resultErr = fmt.Errorf("reader must be a file")
				return
			}

			i.mask, i.maskVal = opts.mask, opts.maskVal
			resultStr, resultErr = i.rawRead(f)
		} else {
			line, err := i.bReader.ReadString('\n')
			if err != nil && err != io.EOF {
				resultErr = fmt.Errorf("failed to read the input: %s", err)
			}

			resultStr = strings.TrimSuffix(line, LineSep)
			// brute force for the moment
			resultStr = strings.TrimSuffix(line, "\n")
		}
	}()

	select {
	case <-sigCh:
		return "", ErrInterrupted
	case <-doneCh:
		return resultStr, resultErr
	}
}
979530
func (b *IOPinDriver) AnalogRead(pin string) (val int, err error) {
	p, err := validatedPin(pin)
	if err != nil {
		return
	}

	b.ensureAnalog(p)
	b.ensureInput(p)

	pins := b.ReadAllPinData()
	return int(pins[p].value), nil
}
738480
func (b *IOPinDriver) ReadPinADConfig() (config int, err error) {
	c, e := b.adaptor().ReadCharacteristic(pinADConfigCharacteristic)
	if e != nil {
		return 0, e
	}
	var result byte
	for i := 0; i < 4; i++ {
		result |= c[i] << uint(i)
	}

	b.adMask = int(result)
	return int(result), nil
}
192287
func NewDigitalPin(pin int, v ...string) *DigitalPin {
	d := &DigitalPin{pin: strconv.Itoa(pin)}
	if len(v) > 0 {
		d.label = v[0]
	} else {
		d.label = "gpio" + d.pin
	}

	return d
}
261803
func (b *Adaptor) translateAnalogPin(pin string) (value string, err error) {
	if val, ok := b.analogPinMap[pin]; ok {
		value = val
	} else {
		err = errors.New("Not a valid analog pin")
	}
	return
}
751554
func (p Pin) Read() (value uint, err error) {
	if p.direction != inDirection {
		return 0, errors.New("pin is not configured for input")
	}
	return readPin(p)
}
865274
func (e *Adaptor) AnalogRead(pin string) (val int, err error) {
	buf, err := e.readFile(
		"/sys/bus/iio/devices/iio:device1/in_voltage" + pin + "_raw",
	)
	if err != nil {
		return
	}

	val, err = strconv.Atoi(string(buf[0 : len(buf)-1]))

	return val / 4, err
}
621264
func (sp *serverPeer) OnRead(_ *peer.Peer, bytesRead int, msg wire.Message, err error) {
	sp.server.AddBytesReceived(uint64(bytesRead))
}
973984
func (self *qbsWrapped) AllowRead(pb PBundle) bool {
	allow, ok := self.index.(AllowReader)
	if !ok {
		return true
	}
	return allow.AllowRead(pb)
}
36363
func (elt ZeroIsNullMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{}, err error) {
	// create a pointer to this element
	// the database driver will set it to nil if the column value is null
	return reflect.New(reflect.TypeOf(fieldAddr)).Interface(), nil
}
890667
func (dec *Reader) ReadQuad() (quad.Quad, error) {
	dec.line = dec.line[:0]
	var line []byte
	for {
		for {
			l, pre, err := dec.r.ReadLine()
			if err != nil {
				return quad.Quad{}, err
			}
			dec.line = append(dec.line, l...)
			if !pre {
				break
			}
		}
		if line = bytes.TrimSpace(dec.line); len(line) != 0 && line[0] != '#' {
			break
		}
		dec.line = dec.line[:0]
	}
	var (
		q   quad.Quad
		err error
	)
	if dec.raw {
		q, err = ParseRaw(string(line))
	} else {
		q, err = Parse(string(line))
	}
	if err != nil {
		return quad.Quad{}, fmt.Errorf("failed to parse %q: %v", dec.line, err)
	}
	if !q.IsValid() {
		return dec.ReadQuad()
	}
	return q, nil
}
448640
func (a *ACL) TokenRead(tokenID string, q *QueryOptions) (*ACLToken, *QueryMeta, error) {
	r := a.c.newRequest("GET", "/v1/acl/token/"+tokenID)
	r.setQueryOptions(q)
	rtt, resp, err := requireOK(a.c.doRequest(r))
	if err != nil {
		return nil, nil, err
	}
	defer resp.Body.Close()

	qm := &QueryMeta{}
	parseQueryMeta(resp, qm)
	qm.RequestTime = rtt

	var out ACLToken
	if err := decodeBody(resp, &out); err != nil {
		return nil, nil, err
	}

	return &out, qm, nil
}
1033656
func (d *MCP3002Driver) AnalogRead(pin string) (value int, err error) {
	channel, _ := strconv.Atoi(pin)
	value, err = d.Read(channel)

	return
}