func Open() error { ctx := usb.NewContext() // ctx.Debug(10) devs, err := ctx.ListDevices(func(desc *usb.Descriptor) bool { if desc.Vendor.String() == "0590" { return true } return false }) if err != nil { for _, v := range devs { err := v.Close() if err != nil { lg.Errorln(err) } } return err } usbdevice = devs[0] return nil }
// Turret executes the turret command on the minion. func Turret(data string) { cmd, value := SplitTwo(data) if cmd == "" { Send("turret error no command") log.Printf("turret: no command") return } ctx := usb.NewContext() turrets, err := turret.Find(ctx) if err != nil { Send("turret error " + err.Error()) log.Printf("turret: %s", err) return } for _, t := range turrets { switch cmd { case "blinkon": t.BlinkOn(getBlinks(value)) case "blinkoff": t.BlinkOff(getBlinks(value)) case "light": t.Light(getBoolean(value)) case "stop": t.Stop() case "fire": t.Fire(getShots(value)) case "left": t.Left(getDuration(value)) t.Stop() case "dance": t.BlinkOn(3) t.Left(2 * time.Second) t.Stop() t.BlinkOn(3) t.Up(2 * time.Second) t.Stop() t.BlinkOn(3) t.Right(2 * time.Second) t.Stop() t.BlinkOn(3) t.Down(2 * time.Second) t.Stop() case "right": t.Right(getDuration(value)) t.Stop() case "up": t.Up(getDuration(value)) t.Stop() case "down": t.Down(getDuration(value)) t.Stop() case "reset": t.Reset() case "type": Send("turret type " + t.HumanReadableType()) } } for _, t := range turrets { t.Close() } ctx.Close() Send("turret ok") }