Skip to content

How to add new channels

David Gray edited this page May 22, 2015 · 1 revision

Please note, this needs to be confirmed and tested.

  • Add a schema (current schemas are here: https://github.com/ninjasphere/schemas) in the protocol folder
  • Add a new go file in go-ninja/channels. For example, a time travel channel would look like this:

package channels

`// Anything that uses the TimeTravel channel must include SetYear(year int)`
`type TimeTravelDevice interface {`
    `SetYear(year int) error`
`}`

`type TimeTravelChannel struct {`
    `baseChannel`
    `device TimeTravelDevice`
`}`

`func NewTimeTravelChannel(device TimeTravelDevice) *TimeTravelChannel {`
    `return &TimeTravelChannel{baseChannel{`
        `protocol: "time",`
    `}, device}`
`}`

`func (c *TimeTravelChannel) Set(year int) error {`
    `c.device.SetYear(year)`
    `return nil`
`}`

`func (c *TimeTravelChannel) SendState(year int) error {`
    `return c.SendEvent("state", state)`
`}`
  • Recompile
  • ???
  • PROFIT!!

Note, there might be more steps. Also, a UI would need to be added to the Sphere app / web app / whatever your method of control is, as the Sphere app needs to know how to display the information.