Exemplo n.º 1
0
func main() {
	flagInit()

	if passwd == "" {
		passwd = venuelib.GetPasswd()
	}

	v, err := venue.New()
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()
	// TODO(kward:20161124) Fix how the context value is handled.
	if *maxProtoVersion != "" {
		ctx = context.WithValue(ctx, "vnc_max_proto_version", *maxProtoVersion)
	}

	// Establish connection with the VENUE VNC server.
	if err := v.Connect(ctx, *host, *port, passwd); err != nil {
		log.Fatal(err)
	}
	defer v.Close()
	log.Println("Venue connection established.")

	v.Initialize()
	go v.ListenAndHandle()

	// Randomly adjust an input.
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for {
		v.VNC.SelectInput(uint16(r.Intn(int(*numInputs))))

		if *period == 0 {
			break
		}
		time.Sleep(*period)
	}
}
Exemplo n.º 2
0
func main() {
	flagInit()

	log.SetFlags(log.Flags() | log.Lmicroseconds | log.Lshortfile)

	if venuePasswd == "" {
		venuePasswd = venuelib.GetPasswd()
	}

	v, err := venue.New()
	if err != nil {
		log.Fatal(err)
	}

	// Establish connection with the VENUE VNC server.
	ctx, cancel := context.WithTimeout(context.Background(), *venueTimeout)
	defer cancel()
	if err := v.Connect(ctx, *venueHost, *venuePort, venuePasswd); err != nil {
		log.Fatal(err)
	}
	defer v.Close()
	log.Println("Venue connection established.")

	v.Initialize()
	// time.Sleep(1 * time.Second)
	go v.ListenAndHandle()

	o := &osc.Server{}
	conn, err := net.ListenPacket("udp", fmt.Sprintf("%v:%v", *oscServerHost, *oscServerPort))
	if err != nil {
		log.Fatal("Error starting OSC server:", err)
	}
	defer conn.Close()
	log.Println("OSC server started.")

	go func() {
		s := NewState()

		for {
			p, remote, err := o.ReceivePacket(context.Background(), conn)
			if err != nil {
				log.Fatalf("OSC error: %v", err)
			}
			if p == nil {
				continue
			}

			switch p.(type) {
			case *osc.Bundle:
				s.handleBundle(p.(*osc.Bundle), remote)
			case *osc.Message:
				s.handleMessage(v, p.(*osc.Message), remote)
			default:
				log.Println("Error: Unrecognized packet type.")
			}
		}
	}()

	for {
		log.Println("--- checkpoint ---")
		time.Sleep(1 * time.Minute)
	}
}