1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00

71 lines
1.4 KiB
Go
Raw Normal View History

2013-10-22 16:45:31 -07:00
package gobot
2013-10-23 22:00:03 -07:00
import (
"fmt"
"strconv"
)
2013-10-22 16:45:31 -07:00
type Device struct {
Name string
Pin string
Connection string
Interval string
Driver string
2013-10-23 22:00:03 -07:00
Params map[string]string
Robot Robot
2013-10-22 16:45:31 -07:00
}
2013-10-23 22:00:03 -07:00
type DeviceType struct {
Name string
Pin string
Robot Robot
Connection ConnectionType
Interval float64
Driver Driver
Params map[string]string
2013-10-22 16:45:31 -07:00
}
2013-10-23 22:00:03 -07:00
func NewDevice(d Device) *DeviceType {
dt := new(DeviceType)
dt.Name = d.Name
dt.Pin = d.Pin
dt.Robot = d.Robot
dt.Params = d.Params
// dt.Connection = determine_connection(params[:connection]) || default_connection
dt.Connection = ConnectionType{Name: d.Connection,}
if d.Interval == "" {
dt.Interval = 0.5
} else {
f, err := strconv.ParseFloat(d.Interval, 64)
if err == nil {
dt.Interval = f
} else {
fmt.Println(err)
dt.Interval = 0.5
}
}
//dt.Driver = Driver.New(Driver{Robot: d.Robot, Params: d.Params,})
return dt
2013-10-22 16:45:31 -07:00
}
2013-10-23 22:00:03 -07:00
func (dt *DeviceType) Start() {
fmt.Println("Device " + dt.Name + "started")
dt.Driver.Start()
2013-10-22 16:45:31 -07:00
}
2013-10-23 22:00:03 -07:00
// def publish(event, *data)
// if data.first
// driver.publish(event_topic_name(event), *data)
// else
// driver.publish(event_topic_name(event))
// end
// end
2013-10-22 16:45:31 -07:00
2013-10-23 22:00:03 -07:00
// Execute driver command
func (dt *DeviceType) Command(method_name string, arguments []string) {
//dt.Driver.Command(method_name, arguments)
2013-10-22 16:45:31 -07:00
}