Пример #1
0
func main() {
	// Connecting
	log.Println("Trying to connect to localhost:1972 ...")

	conn, err := gobci.Connect("localhost:1972")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	// Getting header information
	log.Println("Requesting header data ...")

	header, err := conn.GetHeader()
	if err != nil {
		log.Fatal(err)
	}

	for {
		// Getting samples
		log.Println("Requesting sample data ...")

		var amountOfSamples uint32 = 100
		if header.NSamples < amountOfSamples {
			log.Fatal("Not enough samples avialable")
		}

		samples, err := conn.GetData(0, 0)
		if err != nil {
			log.Fatal(err)
		}

		// Visualizing the channels
		channels := make([]channelXYer, header.NChannels)
		for _, sample := range samples {
			for i := uint32(0); i < header.NChannels; i++ {
				channels[i].Values = append(channels[i].Values, sample[i])
			}
		}
		for chIndex := range channels {
			channels[chIndex].freq = header.SamplingFrequency
		}

		log.Println("Plotting samples ...")
		plt, err := plot.New()
		plotutil.AddLinePoints(plt,
			"CH0", plotter.XYer(channels[0]))
		//"CH1", plotter.XYer(channels[1]),
		//"CH2", plotter.XYer(channels[2]))

		log.Println("Saving plot to output.jpg ...")
		plt.Save(10*vg.Inch, 5*vg.Inch, "output.jpg")

	}

	log.Println("Done")
}
Пример #2
0
func (c *Calibrate) New(w *ecs.World) {
	ActiveCalibrateSystem = c
	c.System = ecs.NewSystem()
	c.World = w

	var err error

	c.Connection, err = gobci.Connect("")
	if err != nil {
		log.Fatal(err)
	}

	err = c.Connection.FlushData()
	if err != nil {
		log.Fatal("FlushData error: ", err)
	}

	// Get latest header info
	c.Header, err = c.Connection.GetHeader()
	if err != nil {
		log.Fatal("GetHeader error: ", err)
	}

	for i := uint32(0); i < c.Header.NChannels; i++ {
		e := ecs.NewEntity([]string{c.Type(), "RenderSystem"})
		espace := &engi.SpaceComponent{engi.Point{0, float32(i * (3*dpi + 10))}, 0, 0}
		e.AddComponent(espace)

		if c.Visualize {
			e.AddComponent(&CalibrateComponent{i})
		}

		c.AddEntity(e)
		c.World.AddEntity(e)
	}
}