hybridgroup.gobot/examples/leap_motion_hands.go

38 lines
665 B
Go
Raw Normal View History

2014-04-28 08:43:15 +08:00
package main
import (
"fmt"
2014-07-11 08:21:21 +08:00
2014-04-28 08:43:15 +08:00
"github.com/hybridgroup/gobot"
2014-05-23 11:35:45 +08:00
"github.com/hybridgroup/gobot/platforms/leap"
2014-04-28 08:43:15 +08:00
)
func main() {
2014-05-23 11:35:45 +08:00
gbot := gobot.NewGobot()
2014-07-09 09:36:14 +08:00
2014-05-23 11:35:45 +08:00
leapMotionAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
2014-06-09 09:05:52 +08:00
l := leap.NewLeapMotionDriver(leapMotionAdaptor, "leap")
2014-04-28 08:43:15 +08:00
work := func() {
2014-07-09 09:36:14 +08:00
gobot.On(l.Event("message"), func(data interface{}) {
2014-04-28 08:43:15 +08:00
printHands(data.(leap.Frame))
})
}
2014-07-09 09:36:14 +08:00
robot := gobot.NewRobot("leapBot",
[]gobot.Connection{leapMotionAdaptor},
[]gobot.Device{l},
work,
)
gbot.AddRobot(robot)
2014-04-28 08:43:15 +08:00
2014-05-23 11:35:45 +08:00
gbot.Start()
2014-04-28 08:43:15 +08:00
}
func printHands(frame leap.Frame) {
for key, hand := range frame.Hands {
fmt.Println("Hand", key, hand)
}
}