// DigitalRead reads from a pin
17990
func (b *IOPinDriver) DigitalRead(pin string) (val int, err error) {
	p, err := validatedPin(pin)
	if err != nil {
		return
	}

	b.ensureDigital(p)
	b.ensureInput(p)

	pins := b.ReadAllPinData()
	return int(pins[p].value), nil
}
1032465
func (g *Driver) AnalogRead(pin string) (value int, err error) {
	var (
		grovePin, grovePort Grove
		analogCmd           byte
	)
	grovePin, grovePort, analogCmd, _, err = getGroveAddresses(pin)
	if err != nil {
		return value, err
	}
	err = g.SetGroveType(grovePort, CUSTOM)
	if err != nil {
		return value, err
	}
	time.Sleep(10 * time.Millisecond)
	err = g.SetGroveMode(grovePin, GROVE_INPUT_ANALOG)
	if err != nil {
		return value, err
	}
	time.Sleep(10 * time.Millisecond)
	response, err := g.readBytes(goPiGo3Address, analogCmd, 7)
	if err != nil {
		return value, err
	}
	if err := g.responseValid(response); err != nil {
		return value, err
	}
	if err := g.valueValid(response); err != nil {
		return value, err
	}
	highBytes := uint16(response[5])
	lowBytes := uint16(response[6])
	return int((highBytes<<8)&0xFF00) | int(lowBytes&0xFF), nil
}
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
}
1105495
func (d *GrovePiDriver) AnalogRead(pin string) (value int, err error) {
	pin = getPin(pin)

	var pinNum int
	pinNum, err = strconv.Atoi(pin)
	if err != nil {
		return
	}

	value, err = d.readAnalog(byte(pinNum))

	return
}
449130
func (r *importReader) readIdent() {
	c := r.peekByte(true)
	if !isIdent(c) {
		r.syntaxError()
		return
	}
	for isIdent(r.peekByte(false)) {
		r.peek = 0
	}
}
558820
func (s *UDPSession) SetReadDeadline(t time.Time) error {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.rd = t
	s.notifyReadEvent()
	return nil
}
182643
func (r *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) {
	i, err := r.translatePin(pin)

	if err != nil {
		return
	}

	currentPin, err := r.getExportedDigitalPin(i, dir)

	if err != nil {
		return
	}

	if err = currentPin.Direction(dir); err != nil {
		return
	}

	return currentPin, nil
}
384497
func (b *IOPinDriver) DigitalWrite(pin string, level byte) (err error) {
	p, err := validatedPin(pin)
	if err != nil {
		return
	}

	b.ensureDigital(p)
	b.ensureOutput(p)

	return b.WritePinData(pin, level)
}
583263
func (e *Adaptor) DigitalRead(pin string) (i int, err error) {
	sysfsPin, err := e.DigitalPin(pin, "in")
	if err != nil {
		return
	}
	return sysfsPin.Read()
}
1127747
func (b *Adaptor) DigitalWrite(pin string, val byte) (err error) {
	if strings.Contains(pin, "usr") {
		fi, e := sysfs.OpenFile(b.usrLed+pin+"/brightness", os.O_WRONLY|os.O_APPEND, 0666)
		defer fi.Close()
		if e != nil {
			return e
		}
		_, err = fi.WriteString(strconv.Itoa(int(val)))
		return err
	}
	sysfsPin, err := b.DigitalPin(pin, sysfs.OUT)
	if err != nil {
		return err
	}
	return sysfsPin.Write(int(val))
}
1232810
func readDigits(s *source.Source, start int, firstCode rune, codeLength int) (int, error) {
	body := s.Body
	position := start
	code := firstCode
	if code >= '0' && code <= '9' { // 0 - 9
		for {
			if code >= '0' && code <= '9' { // 0 - 9
				position += codeLength
				code, codeLength = runeAt(body, position)
				continue
			} else {
				break
			}
		}
		return position, nil
	}
	var description string
	description = fmt.Sprintf("Invalid number, expected digit but got: %v.", printCharCode(code))
	return position, gqlerrors.NewSyntaxError(s, position, description)
}
1033656
func (d *MCP3002Driver) AnalogRead(pin string) (value int, err error) {
	channel, _ := strconv.Atoi(pin)
	value, err = d.Read(channel)

	return
}
899442
func (bd *BinaryDecoder) ReadFixed(bytes []byte) error {
	return bd.readBytes(bytes, 0, len(bytes))
}
1272318
func AnalogRead(pin Pin) (int, error) {
	analog, e := GetAnalogModule()
	if e != nil {
		return 0, e
	}

	return analog.AnalogRead(pin)
}
1205670
func (pder *MemProvider) SessionRead(sid string) (Store, error) {
	pder.lock.RLock()
	if element, ok := pder.sessions[sid]; ok {
		go pder.SessionUpdate(sid)
		pder.lock.RUnlock()
		return element.Value.(*MemSessionStore), nil
	}
	pder.lock.RUnlock()
	pder.lock.Lock()
	newsess := &MemSessionStore{sid: sid, timeAccessed: time.Now(), value: make(map[interface{}]interface{})}
	element := pder.list.PushFront(newsess)
	pder.sessions[sid] = element
	pder.lock.Unlock()
	return newsess, nil
}
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
}
503022
func AnalogRead(key interface{}) (int, error) {
	pin, err := NewAnalogPin(key)
	if err != nil {
		return 0, err
	}

	return pin.Read()
}