Пример #1
0
 private void RebuildMapForNewDevice(IHOTASDevice device, IHOTASDevice newDevice)
 {
     newDevice.ApplyButtonMap(device.ButtonMap.ToObservableCollection());
     newDevice.SetModeProfile(device.ModeProfiles);
     newDevice.SetModeActivation(ModeProfileActivationButtons);
     Devices.Add(newDevice);
 }
Пример #2
0
 private void RemoveDevice(IHOTASDevice device)
 {
     if (device == null)
     {
         return;
     }
     StopDevice(device);
     Devices.Remove(device);
 }
Пример #3
0
 public void ReplaceDevice(IHOTASDevice newDevice)
 {
     _hotasDevice.LostConnectionToDevice -= _hotasDevice_LostConnectionToDevice;
     _hotasDevice = newDevice;
     InstanceId   = _hotasDevice.DeviceId;
     Name         = _hotasDevice.Name;
     _hotasDevice.LostConnectionToDevice += _hotasDevice_LostConnectionToDevice;
     OnPropertyChanged(nameof(IsDeviceLoaded));
 }
Пример #4
0
        public void ReplaceDevice(IHOTASDevice newDevice)
        {
            var deviceToReplace = Devices.FirstOrDefault(e => e.DeviceId == newDevice.DeviceId);

            if (deviceToReplace == null)
            {
                return;
            }

            Devices.Remove(deviceToReplace);
            RebuildMapForNewDevice(deviceToReplace, newDevice);
        }
Пример #5
0
        public DeviceViewModel(IDispatcher dispatcher, IFileSystem fileSystem, MediaPlayerFactory mediaPlayerFactory, IHOTASDevice device)
        {
            _appDispatcher      = dispatcher;
            _fileSystem         = fileSystem;
            _mediaPlayerFactory = mediaPlayerFactory;
            _hotasDevice        = device;
            InstanceId          = _hotasDevice.DeviceId;
            Name = _hotasDevice.Name;
            _hotasDevice.LostConnectionToDevice += _hotasDevice_LostConnectionToDevice;
            _hotasDevice.AxisChanged            += _hotasDevice_AxisChanged;

            ButtonMap = new ObservableCollection <IBaseMapViewModel>();
            RebuildMap();
        }
Пример #6
0
        public void ListenToDevice(IHOTASDevice device)
        {
            device.ButtonPressed          += Device_ButtonPressed;
            device.AxisChanged            += Device_AxisChanged;
            device.KeystrokeDownSent      += Device_KeystrokeDownSent;
            device.KeystrokeUpSent        += Device_KeystrokeUpSent;
            device.MacroStarted           += Device_MacroStarted;
            device.MacroCancelled         += Device_MacroCancelled;
            device.ModeProfileSelected    += Device_ModeProfileSelected;
            device.ShiftReleased          += Device_ShiftReleased;
            device.LostConnectionToDevice += Device_LostConnectionToDevice;

            device.SetModeActivation(ModeProfileActivationButtons);
            device.ListenAsync();
        }
Пример #7
0
        private void StopDevice(IHOTASDevice device)
        {
            if (device == null)
            {
                return;
            }

            device.ButtonPressed          -= Device_ButtonPressed;
            device.AxisChanged            -= Device_AxisChanged;
            device.KeystrokeDownSent      -= Device_KeystrokeDownSent;
            device.KeystrokeUpSent        -= Device_KeystrokeUpSent;
            device.MacroStarted           -= Device_MacroStarted;
            device.MacroCancelled         -= Device_MacroCancelled;
            device.ModeProfileSelected    -= Device_ModeProfileSelected;
            device.ShiftReleased          -= Device_ShiftReleased;
            device.LostConnectionToDevice -= Device_LostConnectionToDevice;

            device.Stop();
        }
Пример #8
0
        private static DeviceViewModel CreateDeviceViewMode(string deviceName, out IHOTASDevice hotasDevice)
        {
            var subFileSystem         = Substitute.For <IFileSystem>();
            var subDispatcherFactory  = Substitute.For <DispatcherFactory>();
            var subDirectInputFactory = Substitute.For <DirectInputFactory>();
            var subMediaPlayerFactory = Substitute.For <MediaPlayerFactory>();
            var subHotasQueueFactory  = Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>());

            var hotasDeviceFactory = new HOTASDeviceFactory();

            var deviceId  = Guid.NewGuid();
            var productId = Guid.NewGuid();

            hotasDevice = hotasDeviceFactory.CreateHOTASDevice(subDirectInputFactory.CreateDirectInput(), productId, deviceId, deviceName, subHotasQueueFactory.CreateHOTASQueue());
            hotasDevice.Capabilities = new Capabilities()
            {
                AxeCount = 0, ButtonCount = 2
            };

            var deviceVm = new DeviceViewModel(subDispatcherFactory.CreateDispatcher(), subFileSystem, subMediaPlayerFactory, hotasDevice);

            return(deviceVm);
        }
Пример #9
0
        private static DeviceViewModel CreateDeviceViewMode_AxesChanged(out IHOTASQueue hotasQueue, out IHOTASDevice subHotasDevice)
        {
            var subFileSystem         = Substitute.For <IFileSystem>();
            var subDispatcherFactory  = Substitute.For <DispatcherFactory>();
            var subMediaPlayerFactory = Substitute.For <MediaPlayerFactory>();
            var subJoystickFactory    = Substitute.For <JoystickFactory>();

            var hotasQueueFactory = new HOTASQueueFactory(Substitute.For <IKeyboard>());
            var testJoystick      = new TestJoystick_AxisChanged();

            subJoystickFactory.CreateJoystick(Arg.Any <IDirectInput>(), Arg.Any <Guid>()).Returns(j => testJoystick);

            IDispatcher testDispatcher = new TestDispatcher_AxisChanged();

            subDispatcherFactory.CreateDispatcher().Returns(d => testDispatcher);

            hotasQueue     = hotasQueueFactory.CreateHOTASQueue();
            subHotasDevice = Substitute.For <IHOTASDevice>();

            var axisMap = Substitute.For <HOTASAxis>();

            axisMap.MapId = (int)JoystickOffset.Slider1;
            axisMap.Type  = HOTASButton.ButtonType.AxisLinear;
            subHotasDevice.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>()
            {
                axisMap
            });

            var deviceVm = new DeviceViewModel(subDispatcherFactory.CreateDispatcher(), subFileSystem, subMediaPlayerFactory, subHotasDevice);

            return(deviceVm);
        }
 public LostConnectionToDeviceEventArgs(IHOTASDevice device)
 {
     HOTASDevice = device;
 }
Пример #11
0
        public void AddDevice(IHOTASDevice device)
        {
            var newDevice = _hotasDeviceFactory.CreateHOTASDevice(_directInput, device.ProductId, device.DeviceId, device.Name, _hotasQueueFactory.CreateHOTASQueue());

            RebuildMapForNewDevice(device, newDevice);
        }
Пример #12
0
        private static DeviceViewModel CreateDeviceViewMode(out IHOTASQueue hotasQueue, out IHOTASDevice hotasDevice, out IJoystick subJoystick)
        {
            var subFileSystem         = Substitute.For <IFileSystem>();
            var subDispatchFactory    = Substitute.For <DispatcherFactory>();
            var subDirectInputFactory = Substitute.For <DirectInputFactory>();
            var subMediaPlayerFactory = Substitute.For <MediaPlayerFactory>();
            var subJoystickFactory    = Substitute.For <JoystickFactory>();

            var hotasQueueFactory  = new HOTASQueueFactory(Substitute.For <IKeyboard>());
            var hotasDeviceFactory = new HOTASDeviceFactory();

            var deviceId    = Guid.NewGuid();
            var productId   = Guid.NewGuid();
            var directInput = subDirectInputFactory.CreateDirectInput();

            subJoystick = subJoystickFactory.CreateJoystick(directInput, deviceId);
            subJoystick.Capabilities.Returns(new Capabilities());

            hotasQueue  = hotasQueueFactory.CreateHOTASQueue();
            hotasDevice = hotasDeviceFactory.CreateHOTASDevice(directInput, subJoystickFactory, productId, deviceId, "test", hotasQueue);
            hotasDevice.Capabilities = new Capabilities()
            {
                AxeCount = 0, ButtonCount = 2
            };

            var deviceVm = new DeviceViewModel(subDispatchFactory.CreateDispatcher(), subFileSystem, subMediaPlayerFactory, hotasDevice);

            return(deviceVm);
        }
Пример #13
0
 private void OnButtonPress(object sender, ButtonPressedEventArgs e)
 {
     _selectedDevice = e.Device;
     ButtonPressed?.Invoke(sender, e);
 }
Пример #14
0
 private void Device_AxisChanged(object sender, AxisChangedEventArgs e)
 {
     _selectedDevice = e.Device;
     AxisChanged?.Invoke(sender, e);
 }
Пример #15
0
 public void ForceButtonPress(IHOTASDevice device, JoystickOffset offset, bool isDown)
 {
     device.ForceButtonPress(offset, isDown);
 }
Пример #16
0
 public virtual DeviceViewModel CreateDeviceViewModel(IDispatcher dispatcher, IFileSystem fileSystem, MediaPlayerFactory mediaPlayerFactory, IHOTASDevice device)
 {
     return(new DeviceViewModel(dispatcher, fileSystem, mediaPlayerFactory, device));
 }
Пример #17
0
        private static DeviceViewModel CreateDeviceViewMode_LostConnection(out IHOTASQueue hotasQueue, out IHOTASDevice subHotasDevice)
        {
            var subFileSystem         = Substitute.For <IFileSystem>();
            var subDispatcherFactory  = Substitute.For <DispatcherFactory>();
            var subMediaPlayerFactory = Substitute.For <MediaPlayerFactory>();
            var subJoystickFactory    = Substitute.For <JoystickFactory>();

            var hotasQueueFactory = new HOTASQueueFactory(Substitute.For <IKeyboard>());
            var testJoystick      = new TestJoystick_LostConnection();

            subJoystickFactory.CreateJoystick(Arg.Any <IDirectInput>(), Arg.Any <Guid>()).Returns(j => testJoystick);

            hotasQueue     = hotasQueueFactory.CreateHOTASQueue();
            subHotasDevice = Substitute.For <IHOTASDevice>();
            subHotasDevice.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>());
            subHotasDevice.Capabilities.Returns(new Capabilities()
            {
                AxeCount = 0, ButtonCount = 2
            });

            var deviceVm = new DeviceViewModel(subDispatcherFactory.CreateDispatcher(), subFileSystem, subMediaPlayerFactory, subHotasDevice);

            return(deviceVm);
        }