コード例 #1
0
        public void ReloadStatus(BotSource <PokeBotConfig> b)
        {
            ReloadStatus();
            var bot = b.Bot;

            L_Description.Text = $"[{bot.LastTime:hh:mm:ss}] {bot.Connection.Name}: {bot.LastLogged}";
            L_Left.Text        = Config.ConnectionType == ConnectionType.WiFi ? $"{Config.IP}{Environment.NewLine}{Config.InitialRoutine}" : $"{Config.ConnectionType}{Config.UsbPortIndex}{Environment.NewLine}{Config.InitialRoutine}";

            var lastTime = bot.LastTime;

            if (!b.IsRunning)
            {
                PB_Lamp.BackColor = Color.Transparent;
                return;
            }

            var cfg = bot.Config;

            if (cfg.CurrentRoutineType == PokeRoutineType.Idle && cfg.NextRoutineType == PokeRoutineType.Idle)
            {
                PB_Lamp.BackColor = Color.Yellow;
                return;
            }
            if (LastUpdateStatus == lastTime)
            {
                return;
            }

            // Color decay from Green based on time
            const int threshold = 100;
            Color     good      = Color.Green;
            Color     goodUSB   = Color.DeepSkyBlue;
            Color     bad       = Color.Red;

            var delta   = DateTime.Now - lastTime;
            var seconds = delta.Seconds;

            LastUpdateStatus = lastTime;
            if (seconds > 2 * threshold)
            {
                return; // already changed by now
            }
            if (seconds > threshold)
            {
                if (PB_Lamp.BackColor == bad)
                {
                    return; // should we notify on change instead?
                }
                PB_Lamp.BackColor = bad;
            }
            else
            {
                // blend from green->red, favoring green until near saturation
                var factor = seconds / (double)threshold;
                var blend  = Blend(bad, Config.ConnectionType == ConnectionType.WiFi ? good : goodUSB, factor * factor);
                PB_Lamp.BackColor = blend;
            }
        }
コード例 #2
0
        private async Task ClickAsyncImpl(SwitchButton b, BotSource <PokeBotConfig> bot)
        {
            if (!Enum.IsDefined(typeof(SwitchButton), b))
            {
                await ReplyAsync($"Unknown button value: {b}").ConfigureAwait(false);

                return;
            }

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

            await ReplyAsync($"{bot.Bot.Connection.Name} has performed: {b}").ConfigureAwait(false);
        }
コード例 #3
0
        private async Task ClickAsyncImpl(SwitchButton button, BotSource <PokeBotState> bot)
        {
            if (!Enum.IsDefined(typeof(SwitchButton), button))
            {
                await ReplyAsync($"Unknown button value: {button}").ConfigureAwait(false);

                return;
            }

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

            await ReplyAsync($"{b.Connection.Name} has performed: {button}").ConfigureAwait(false);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
    }