Ejemplo n.º 1
0
        public async Task SetStick(SwitchStick stick, short x, short y, int delay, CancellationToken token)
        {
            var cmd = SwitchCommand.SetStick(stick, x, y);
            await Connection.SendAsync(cmd, Config.ConnectionType, token).ConfigureAwait(false);

            await Task.Delay(delay, token).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
 public void SetStick(SwitchStick s, short x, short y)
 {
     Debug.Log($"StickState: {x}, {y}");
     ExecutionQueue.Enqueue(new SysBotExecution()
     {
         PType       = PressType.Joystick,
         StickToMove = s,
         X           = x,
         Y           = y
     });
 }
Ejemplo n.º 3
0
        public async Task SetStickAsync(string ip, SwitchStick s, short x, short y, ushort ms = 1_000)
        {
            var bot = SysCordInstance.Runner.GetBot(ip);

            if (bot == null)
            {
                await ReplyAsync($"No bot has that {(bot?.Bot.Config.ConnectionType == ConnectionType.WiFi ? "IP address" : "USB port index")} ({ip}).").ConfigureAwait(false);

                return;
            }

            await SetStickAsyncImpl(s, x, y, ms, bot).ConfigureAwait(false);
        }
Ejemplo n.º 4
0
        public async Task SetStickAsync(SwitchStick s, short x, short y, ushort ms = 1_000)
        {
            var bot = SysCordInstance.Runner.Bots.Find(z => z.Bot is RemoteControlBot);

            if (bot == null)
            {
                await ReplyAsync($"No bot is available to execute your command: {s}").ConfigureAwait(false);

                return;
            }

            await SetStickAsyncImpl(s, x, y, ms, bot).ConfigureAwait(false);
        }
Ejemplo n.º 5
0
        public async Task SetStickAsync(string ip, SwitchStick s, short x, short y, ushort ms = 1_000)
        {
            var bot = SysCord <T> .Runner.GetBot(ip);

            if (bot == null)
            {
                await ReplyAsync($"No bot has that IP address ({ip}).").ConfigureAwait(false);

                return;
            }

            await SetStickAsyncImpl(s, x, y, ms, bot).ConfigureAwait(false);
        }
Ejemplo n.º 6
0
        private async Task SetStickAsyncImpl(SwitchStick s, short x, short y, ushort ms, BotSource <PokeBotConfig> bot)
        {
            if (!Enum.IsDefined(typeof(SwitchStick), s))
            {
                await ReplyAsync($"Unknown stick: {s}").ConfigureAwait(false);

                return;
            }

            await bot.Bot.Connection.SendAsync(SwitchCommand.SetStick(s, x, y), bot.Bot.Config.ConnectionType, CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{bot.Bot.Connection.Name} has performed: {s}").ConfigureAwait(false);

            await Task.Delay(ms).ConfigureAwait(false);

            await bot.Bot.Connection.SendAsync(SwitchCommand.ResetStick(s), bot.Bot.Config.ConnectionType, CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{bot.Bot.Connection.Name} has reset the stick position.").ConfigureAwait(false);
        }
        private async Task SetStickAsyncImpl(SwitchStick s, short x, short y, ushort ms)
        {
            if (!Enum.IsDefined(typeof(SwitchStick), s))
            {
                await ReplyAsync($"Unknown stick: {s}").ConfigureAwait(false);

                return;
            }

            var b = Bot;
            await b.Connection.SendAsync(SwitchCommand.SetStick(s, x, y, b.UseCRLF), CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{b.Connection.Name} has performed: {s}").ConfigureAwait(false);

            await Task.Delay(ms).ConfigureAwait(false);

            await b.Connection.SendAsync(SwitchCommand.ResetStick(s, b.UseCRLF), CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{b.Connection.Name} has reset the stick position.").ConfigureAwait(false);
        }
Ejemplo n.º 8
0
        private async Task SetStickAsyncImpl(SwitchStick s, short x, short y, ushort ms, BotSource <PokeBotState> bot)
        {
            if (!Enum.IsDefined(typeof(SwitchStick), s))
            {
                await ReplyAsync($"Unknown stick: {s}").ConfigureAwait(false);

                return;
            }

            var b = bot.Bot;
            var crlf = b is SwitchRoutineExecutor <PokeBotState> {
                UseCRLF : true
            };
            await b.Connection.SendAsync(SwitchCommand.SetStick(s, x, y, crlf), CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{b.Connection.Name} has performed: {s}").ConfigureAwait(false);

            await Task.Delay(ms).ConfigureAwait(false);

            await b.Connection.SendAsync(SwitchCommand.ResetStick(s, crlf), CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{b.Connection.Name} has reset the stick position.").ConfigureAwait(false);
        }
    }
Ejemplo n.º 9
0
 public async Task SetStick(SwitchStick stick, short x, short y, int delayMin, int delayMax, CancellationToken token) =>
 await SetStick(stick, x, y, Util.Rand.Next(delayMin, delayMax), token).ConfigureAwait(false);
Ejemplo n.º 10
0
 /// <summary>
 /// Resets the specified <see cref="stick"/> to (0,0)
 /// </summary>
 /// <returns>Encoded command bytes</returns>
 public static byte[] ResetStick(SwitchStick stick) => SetStick(stick, 0, 0);
Ejemplo n.º 11
0
 /// <summary>
 /// Sets the specified <see cref="stick"/> to the desired <see cref="x"/> and <see cref="y"/> positions.
 /// </summary>
 /// <returns>Encoded command bytes</returns>
 public static byte[] SetStick(SwitchStick stick, int x, int y) => Encode($"setStick {stick} {x} {y}");
Ejemplo n.º 12
0
 /// <summary>
 /// Resets the specified <see cref="stick"/> to (0,0)
 /// </summary>
 /// <param name="stick">LEFT or RIGHT joystick enumerator.</param>
 /// <param name="addrn">Encoding selector. Default "true" for sys-botbase.</param>
 /// <returns>Encoded command bytes</returns>
 public static byte[] ResetStick(SwitchStick stick, bool addrn = true) => SetStick(stick, 0, 0, addrn);
Ejemplo n.º 13
0
        /*
         *
         * Controller Stick Commands
         *
         */

        /// <summary>
        /// Sets the specified <see cref="stick"/> to the desired <see cref="x"/> and <see cref="y"/> positions.
        /// </summary>
        /// <param name="stick">LEFT or RIGHT joystick enumerator.</param>
        /// <param name="x">X axis magnitude.</param>
        /// <param name="y">Y axis magnitude.</param>
        /// <param name="addrn">Encoding selector. Default "true" for sys-botbase.</param>
        /// <returns>Encoded command bytes</returns>
        public static byte[] SetStick(SwitchStick stick, int x, int y, bool addrn = true) => Encode($"setStick {stick} {x} {y}", addrn);
Ejemplo n.º 14
0
 /// <summary>
 /// Resets the specified <see cref="stick"/> to (0,0)
 /// </summary>
 /// <param name="stick">Stick to reset</param>
 /// <param name="crlf">Line terminator (unused by USB's protocol)</param>
 /// <returns>Encoded command bytes</returns>
 public static byte[] ResetStick(SwitchStick stick, bool crlf = true) => SetStick(stick, 0, 0, crlf);
Ejemplo n.º 15
0
        /*
         *
         * Controller Stick Commands
         *
         */

        /// <summary>
        /// Sets the specified <see cref="stick"/> to the desired <see cref="x"/> and <see cref="y"/> positions.
        /// </summary>
        /// <param name="stick">Stick to reset</param>
        /// <param name="x">X position</param>
        /// <param name="y">Y position</param>
        /// <param name="crlf">Line terminator (unused by USB's protocol)</param>
        /// <returns>Encoded command bytes</returns>
        public static byte[] SetStick(SwitchStick stick, short x, short y, bool crlf = true) => Encode($"setStick {stick} {x} {y}", crlf);
 public async Task SetStickAsync(SwitchStick s, short x, short y, ushort ms = 1_000)
 {
     await SetStickAsyncImpl(s, x, y, ms).ConfigureAwait(false);
 }