Esempio n. 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])
			}
		}

		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")
}
Esempio n. 2
0
func (c *Calibrate) Update(entity *ecs.Entity, dt float32) {
	if c.frameIndex != 0 {
		return
	}

	var (
		cal *CalibrateComponent
		ok  bool
	)

	if cal, ok = entity.ComponentFast(cal).(*CalibrateComponent); !ok {
		return
	}

	// Render the image again
	plt, err := plot.New()
	if err != nil {
		log.Fatal(err)
	}

	plotutil.AddLinePoints(plt,
		"CH"+strconv.Itoa(int(cal.ChannelIndex)), plotter.XYer(c.channels[cal.ChannelIndex]))
	img := image.NewRGBA(image.Rect(0, 0, 3*dpi, 3*dpi))
	canv := vgimg.NewWith(vgimg.UseImage(img))
	plt.Draw(draw.New(canv))
	bgTexture := engi.NewImageRGBA(img)

	// Give it to engi

	erender := &engi.RenderComponent{
		Display:      engi.NewRegion(engi.NewTexture(bgTexture), 0, 0, 3*dpi, 3*dpi),
		Scale:        engi.Point{1, 1},
		Transparency: 1,
		Color:        color.RGBA{255, 255, 255, 255},
	}
	erender.SetPriority(engi.HUDGround)

	entity.AddComponent(erender)
}