WIP robeaux support
This commit is contained in:
parent
409756ca04
commit
396c9cf466
|
@ -1,10 +1,10 @@
|
|||
package gobot
|
||||
|
||||
type Adaptor struct {
|
||||
Name string
|
||||
Port string
|
||||
Connected bool
|
||||
Params map[string]interface{}
|
||||
Name string `json:"name"`
|
||||
Port string `json:"port"`
|
||||
Connected bool `json:"Connected"`
|
||||
Params map[string]interface{} `json:"params"`
|
||||
}
|
||||
|
||||
type AdaptorInterface interface {
|
||||
|
|
18
api.go
18
api.go
|
@ -42,8 +42,24 @@ func Api(bot *Master) {
|
|||
return toJson(bot.FindRobot(params["robotname"]).GetDevices())
|
||||
})
|
||||
|
||||
type jsonDevice struct {
|
||||
Name string `json:"name"`
|
||||
Driver string `json:"driver"`
|
||||
Connection map[string]interface{} `json:"connection"`
|
||||
Commands []string `json:"commands"`
|
||||
}
|
||||
|
||||
m.Get("/robots/:robotname/devices/:devicename", func(params martini.Params) string {
|
||||
return toJson(bot.FindRobotDevice(params["robotname"], params["devicename"]))
|
||||
device := bot.FindRobotDevice(params["robotname"], params["devicename"])
|
||||
jsonDevice := new(jsonDevice)
|
||||
jsonDevice.Name = device.Name
|
||||
jsonDevice.Driver = FieldByNamePtr(device.Driver, "Name").Interface().(string)
|
||||
jsonDevice.Connection = make(map[string]interface{})
|
||||
jsonDevice.Connection["name"] = FieldByNamePtr(FieldByNamePtr(device.Driver, "Adaptor").Interface().(AdaptorInterface), "Name").Interface().(string)
|
||||
jsonDevice.Connection["port"] = FieldByNamePtr(FieldByNamePtr(device.Driver, "Adaptor").Interface().(AdaptorInterface), "Port").Interface().(string)
|
||||
jsonDevice.Connection["adaptor"] = FieldByNamePtr(FieldByNamePtr(device.Driver, "Adaptor").Interface().(AdaptorInterface), "Name").Interface().(string)
|
||||
jsonDevice.Commands = FieldByNamePtr(device.Driver, "Commands").Interface().([]string)
|
||||
return toJson(jsonDevice)
|
||||
})
|
||||
|
||||
m.Get("/robots/:robotname/devices/:devicename/commands", func(params martini.Params) string {
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
)
|
||||
|
||||
type connection struct {
|
||||
Name string
|
||||
Adaptor AdaptorInterface
|
||||
Name string `json:"name"`
|
||||
Adaptor AdaptorInterface `json:"adaptor"`
|
||||
Port string `json:"-"`
|
||||
Robot *Robot `json:"-"`
|
||||
Params map[string]interface{} `json:"-"`
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
)
|
||||
|
||||
type device struct {
|
||||
Name string
|
||||
Name string `json:"name"`
|
||||
Interval string `json:"-"`
|
||||
Robot *Robot `json:"-"`
|
||||
Driver DriverInterface
|
||||
Driver DriverInterface `json:"driver"`
|
||||
}
|
||||
|
||||
type Device interface {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package gobot
|
||||
|
||||
type Driver struct {
|
||||
Interval string
|
||||
Pin string
|
||||
Name string
|
||||
Commands []string
|
||||
Interval string `json:"interval"`
|
||||
Pin string `json:"pin"`
|
||||
Name string `json:"name"`
|
||||
Commands []string `json:"commands"`
|
||||
Events map[string]chan interface{} `json:"-"`
|
||||
}
|
||||
|
||||
|
|
8
robot.go
8
robot.go
|
@ -8,11 +8,11 @@ import (
|
|||
)
|
||||
|
||||
type Robot struct {
|
||||
Connections []Connection
|
||||
Devices []Device
|
||||
Name string
|
||||
Connections []Connection `json:"connections"`
|
||||
Devices []Device `json:"devices"`
|
||||
Name string `json:"name"`
|
||||
Commands map[string]interface{} `json:"-"`
|
||||
RobotCommands []string `json:"Commands"`
|
||||
RobotCommands []string `json:"commands"`
|
||||
Work func() `json:"-"`
|
||||
connections []*connection `json:"-"`
|
||||
devices []*device `json:"-"`
|
||||
|
|
Loading…
Reference in New Issue