public SerialPortSelectorViewModel(ISerialPortService serialPort, IWorkSituation work)
        {
            m_serialPort = serialPort;

            //PortNames = new ObservableCollection<string>(SerialPortService.GetPortNames());
            PortNames = new ObservableCollection <string>(new[] { "COM1", "COM2", "COM3", "COM4" });

            SelectedPortName = new ReactiveProperty <string>().AddTo(Disposables);
            SelectedPortName.Subscribe(n => Connect(n)).AddTo(Disposables);

            SelectedPortNameIndex       = new ReactiveProperty <int>().AddTo(Disposables);
            SelectedPortNameIndex.Value = (PortNames.Count == 1) ? 0 : -1;

            IsConnected = m_serialPort.ObserveProperty(p => p.IsOpen).ToReactiveProperty().AddTo(Disposables);
            IsBusy      = work.ObserveProperty(w => w.IsBusy).ToReactiveProperty().AddTo(Disposables);
        }
Ejemplo n.º 2
0
        public ControllerPanelViewModel(ISwitchController controller, ISerialPortService serialPort, IWorkSituation work)
        {
            m_switchController = controller;

            IsConnected = serialPort.ObserveProperty(p => p.IsOpen).ToReactiveProperty().AddTo(Disposables);
            IsBusy      = work.ObserveProperty(w => w.IsBusy).ToReactiveProperty().AddTo(Disposables);

            PushButtonCommand = new[] { IsConnected, IsBusy }.CombineLatest(x => x[0] && !x[1]).ToReactiveCommand <ButtonType?>().AddTo(Disposables);
            PushButtonCommand.Subscribe(PushButton).AddTo(Disposables);

            PushDPadCommand = new[] { IsConnected, IsBusy }.CombineLatest(x => x[0] && !x[1]).ToReactiveCommand <DPadCommand?>().AddTo(Disposables);
            PushDPadCommand.Subscribe(PushDPad).AddTo(Disposables);

            MoveStickCommand = new[] { IsConnected, IsBusy }.CombineLatest(x => x[0] && !x[1]).ToReactiveCommand <StickParameter>().AddTo(Disposables);
            MoveStickCommand.Subscribe(MoveStick).AddTo(Disposables);
        }
        public MacroPanelViewModel(IMacroService macro, IMacroPool pool, ICanceler canceler, IWorkSituation work, ISwitchClock clock, ISerialPortService serialPort, ICancellationRequest cancelRequest, IGameCapture gameCapture)
        {
            m_macro         = macro;
            m_macroCanceler = canceler;
            m_macroPool     = pool;

            IsConnected = serialPort.ObserveProperty(p => p.IsOpen).ToReactiveProperty().AddTo(Disposables);
            IsBusy      = work.ObserveProperty(w => w.IsBusy).ToReactiveProperty().AddTo(Disposables);

            Clock       = clock.ToReactivePropertyAsSynchronized(m => m.DateTime).AddTo(Disposables);
            Clock.Value = DateTime.Now;

            DrawLotoIdCommand    = CreateExecuteMacroCommand <DrawLotoIdMacro>();
            GainWattsCommand     = CreateExecuteMacroCommand <GainWattsMacro>();
            BattleMaxRaidCommand = CreateExecuteMacroCommand <BattleMaxRaidMacro>();
            //SeekPokemonCommand = CreateExecuteMacroCommand<SeekPokemonMacro>();
            RapidTimeTravelCommand     = CreateExecuteMacroCommand <RapidTimeTravelMacro>();
            RapidTimeTravelDays        = clock.ToReactivePropertyAsSynchronized(m => m.DaysCount).AddTo(Disposables);
            RapidTimeTravelDays.Value  = 0;
            ThreeDaysTravelCommand     = CreateExecuteMacroCommand <ThreeDaysTravelMacro>();
            CanGoNextThreeDays         = (m_macroPool.Get <ThreeDaysTravelMacro>() as ThreeDaysTravelMacro).ObserveProperty(m => m.CanGoNext).ToReactiveProperty().AddTo(Disposables);
            ThreeDaysTravelNextCommand = CanGoNextThreeDays.ToReactiveCommand().AddTo(Disposables);
            ThreeDaysTravelNextCommand.Subscribe(() =>
            {
                using (var wait = new EventWaitHandle(false, EventResetMode.ManualReset, "WAIT_NEXT_3_DAYS"))
                {
                    wait.Set();
                }
            });
            MashAButtonCommand = CreateExecuteMacroCommand <MashAButtonMacro>();

            IsCanceling   = cancelRequest.ObserveProperty(c => c.IsCancellationRequested).ToReactiveProperty().AddTo(Disposables);
            CancelCommand = new[] { IsBusy, IsCanceling }.CombineLatest(x => x[0] && !x[1]).ToReactiveCommand().AddTo(Disposables);
            CancelCommand.Subscribe(m_macroCanceler.Cancel);

            SaveImageCommand = new ReactiveCommand().AddTo(Disposables);
            SaveImageCommand.Subscribe(() => gameCapture.SaveFrame(null));
        }