示例#1
0
文件: device.go 项目: zdebeer99/zhome
func (this *ZIOBoardDevice) SetValue(address string, value se.ValueMap) error {
	if !this.OK() {
		return fmt.Errorf("arduino device %s is in error state. %s", this.ID(), this.StatusText())
	}
	if pin, ok := this.pins[address]; ok {
		if pin.mode == MODE_OUTPUT {
			switch pin.ptype {
			case DATA_TYPE_DIGITAL:
				var dv1 bool
				switch value.Value() {
				case "on":
					dv1 = true
				case "off":
					dv1 = false
				default:
					return fmt.Errorf("Invalid Digital Value. `%s` expecting on or off", value)
				}
				log.Println("Write", pin.pin, dv1)
				err := this.board.WriteDigital(pin.pin, dv1)
				if err != nil {
					return fmt.Errorf("ZIOBoard write failed. %s", err)
				}
			case DATA_TYPE_ANALOG:
				//this.board.WriteAnalog(pin.pin, wval)
			default:
				return fmt.Errorf("ZIOBoard.SetValue() pin type Invalid.")
			}
		} else {
			return fmt.Errorf("ZIOBoard.SetValue() pin mode Invalid. Can only set a value of a output pin.")
		}
	}
	return nil
}
示例#2
0
文件: device.go 项目: zdebeer99/zhome
func (this *FirmataDevice) SetValue(address string, value se.ValueMap) error {
	wval, err := encodeValue(value.Value())
	if err != nil {
		err = fmt.Errorf("Firmata.SetValue() Invalid Value '%s', error: %s", value, err)
		log.Println(err)
		return err
	}
	if !this.OK() {
		return fmt.Errorf("arduino device %s is in error state. %s", address, value)
	}
	if pin, ok := this.pins[address]; ok {
		if pin.mode == firmata.Output {
			switch pin.ptype {
			case DIGITAL:
				log.Println("Write", pin.pin, wval)
				err = this.board.DigitalWrite(pin.pin, wval == 1)
				if err != nil {
					return fmt.Errorf("Firmata.SetValue() write failed. %s", err)
				}
			case ANALOG:
				//this.board.WriteAnalog(pin.pin, wval)
			default:
				return fmt.Errorf("Firmata.SetValue() pin type Invalid.")
			}
		} else {
			return fmt.Errorf("Firmata.SetValue() pin mode Invalid. Can only set a value of a output pin.")
		}
	}
	return nil
}
示例#3
0
文件: device.go 项目: zdebeer99/zhome
//TODO: parse qs results and send the correct rsponse.
func (this *QwikSwitchDevice) SetValue(address string, value se.ValueMap) error {
	res, err := this.send(fmt.Sprintf("%s=%s", address, encodeValue(value.Value())))
	log.Println("SetValue ", res, err)
	return err
}