Example #1
0
func main() {
	gbot := gobot.NewGobot()
	a := api.NewAPI(gbot)

	a.Get("/brain/:a", func(res http.ResponseWriter, req *http.Request) {
		path := req.URL.Path
		t := strings.Split(path, "/")
		buf, err := Asset("assets/" + t[2])
		if err != nil {
			http.Error(res, err.Error(), http.StatusNotFound)
			return
		}
		t = strings.Split(path, ".")
		if t[len(t)-1] == "js" {
			res.Header().Set("Content-Type", "text/javascript; charset=utf-8")
		} else if t[len(t)-1] == "css" {
			res.Header().Set("Content-Type", "text/css; charset=utf-8")
		}
		res.Write(buf)
	})
	adaptor := neurosky.NewNeuroskyAdaptor("neurosky", "/dev/rfcomm0")
	neuro := neurosky.NewNeuroskyDriver(adaptor, "neurosky")

	gbot.AddRobot(gobot.NewRobot("brain",
		[]gobot.Connection{adaptor},
		[]gobot.Device{neuro},
	))

	a.Start()
	gbot.Start()
}
Example #2
0
func main() {
	gbot := gobot.NewGobot()

	adaptor := neurosky.NewNeuroskyAdaptor("neurosky", "/dev/rfcomm0")
	neuro := neurosky.NewNeuroskyDriver(adaptor, "neuro")

	work := func() {
		gobot.On(neuro.Event("extended"), func(data interface{}) {
			fmt.Println("Extended", data)
		})
		gobot.On(neuro.Event("signal"), func(data interface{}) {
			fmt.Println("Signal", data)
		})
		gobot.On(neuro.Event("attention"), func(data interface{}) {
			fmt.Println("Attention", data)
		})
		gobot.On(neuro.Event("meditation"), func(data interface{}) {
			fmt.Println("Meditation", data)
		})
		gobot.On(neuro.Event("blink"), func(data interface{}) {
			fmt.Println("Blink", data)
		})
		gobot.On(neuro.Event("wave"), func(data interface{}) {
			fmt.Println("Wave", data)
		})
		gobot.On(neuro.Event("eeg"), func(data interface{}) {
			eeg := data.(neurosky.EEG)
			fmt.Println("Delta", eeg.Delta)
			fmt.Println("Theta", eeg.Theta)
			fmt.Println("LoAlpha", eeg.LoAlpha)
			fmt.Println("HiAlpha", eeg.HiAlpha)
			fmt.Println("LoBeta", eeg.LoBeta)
			fmt.Println("HiBeta", eeg.HiBeta)
			fmt.Println("LoGamma", eeg.LoGamma)
			fmt.Println("MidGamma", eeg.MidGamma)
			fmt.Println("\n")
		})
	}

	robot := gobot.NewRobot("brainBot",
		[]gobot.Connection{adaptor},
		[]gobot.Device{neuro},
		work,
	)

	gbot.AddRobot(robot)
	gbot.Start()
}