hybridgroup.gobot/device.go

35 lines
784 B
Go
Raw Normal View History

2013-10-23 07:45:31 +08:00
package gobot
2013-10-24 13:00:03 +08:00
import (
"fmt"
"strconv"
2013-10-25 13:04:58 +08:00
"reflect"
2013-10-24 13:00:03 +08:00
)
2013-10-23 07:45:31 +08:00
type Device struct {
Name string
2013-10-25 13:04:58 +08:00
Robot *Robot
Connection *Connection
Driver *Driver
2013-10-24 13:00:03 +08:00
Params map[string]string
2013-10-23 07:45:31 +08:00
}
2013-10-25 13:04:58 +08:00
func NewDevice(d reflect.Value, r *Robot) *Device {
dt := new(Device)
dt.Name = reflect.ValueOf(d).FieldByName("Name").String()
dt.Robot = r
dt.Driver = new(Driver)
dt.Driver.Pin = reflect.ValueOf(d).FieldByName("Pin").String()
dt.Driver.Interval, _ = strconv.ParseFloat(reflect.ValueOf(d).FieldByName("Interval").String(), 64)
dt.Connection = new(Connection)
2013-10-24 13:00:03 +08:00
return dt
2013-10-23 07:45:31 +08:00
}
2013-10-25 13:04:58 +08:00
func (dt *Device) Start() {
2013-10-24 13:00:03 +08:00
fmt.Println("Device " + dt.Name + "started")
dt.Driver.Start()
2013-10-23 07:45:31 +08:00
}
2013-10-25 13:04:58 +08:00
func (dt *Device) Command(method_name string, arguments []string) {
2013-10-24 13:00:03 +08:00
//dt.Driver.Command(method_name, arguments)
2013-10-23 07:45:31 +08:00
}