public void get_button_from_raw_value_backward_directional_not_multi_action() { var map = new HOTASAxis(); map.IsDirectional = true; map.IsMultiAction = false; map.CalculateSegmentRange(4); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(700);//set direction backward Assert.Equal("Reverse Axis Button 1", map.GetButtonMapFromRawValue(16383).MapName); Assert.Equal("Reverse Axis Button 1", map.GetButtonMapFromRawValue(32766).MapName); Assert.Equal("Reverse Axis Button 1", map.GetButtonMapFromRawValue(49149).MapName); Assert.Equal("Reverse Axis Button 1", map.GetButtonMapFromRawValue(65535).MapName); }
public void calculate_segment_is_directional_Is_multi_action() { var map = new HOTASAxis(); map.IsDirectional = true; map.IsMultiAction = true;//should create action button map for each segment map.ButtonMap.Clear(); map.ReverseButtonMap.Clear(); map.CalculateSegmentRange(3); Assert.NotEmpty(map.Segments); Assert.Equal(3, map.Segments.Count); Assert.NotEmpty(map.ButtonMap); Assert.Equal("Axis Button 1", map.ButtonMap[0].MapName); Assert.Equal("Axis Button 2", map.ButtonMap[1].MapName); Assert.Equal("Axis Button 3", map.ButtonMap[2].MapName); Assert.NotEmpty(map.ReverseButtonMap); Assert.Equal("Reverse Axis Button 1", map.ReverseButtonMap[0].MapName); Assert.Equal("Reverse Axis Button 2", map.ReverseButtonMap[1].MapName); Assert.Equal("Reverse Axis Button 3", map.ReverseButtonMap[2].MapName); map.CalculateSegmentRange(4); Assert.Equal(4, map.Segments.Count); Assert.Equal("Axis Button 4", map.ButtonMap[3].MapName); Assert.Equal(4, map.Segments.Count); Assert.Equal("Reverse Axis Button 4", map.ReverseButtonMap[3].MapName); }
public void calculate_segment_is_directional_is_multi_action_less_segments_than_buttons() { var map = new HOTASAxis(); map.IsDirectional = true; map.IsMultiAction = true;//should create action button map for each segment map.ButtonMap.Clear(); map.ReverseButtonMap.Clear(); map.ReverseButtonMap.Add(new HOTASButton() { MapName = "kept" }); map.ReverseButtonMap.Add(new HOTASButton() { MapName = "removed 1" }); map.ReverseButtonMap.Add(new HOTASButton() { MapName = "removed 2" }); map.CalculateSegmentRange(1); Assert.NotEmpty(map.Segments); Assert.Single(map.Segments); Assert.NotEmpty(map.ButtonMap); Assert.NotEmpty(map.ReverseButtonMap); Assert.Equal("kept", map.ReverseButtonMap[0].MapName); }
public void calculate_segment_is_directional_not_multi_action_existing_buttons() { var map = new HOTASAxis(); map.IsDirectional = true; map.IsMultiAction = false;//should leave a single action button map list map.ButtonMap.Add(new HOTASButton() { MapName = "kept" }); map.ButtonMap.Add(new HOTASButton() { MapName = "removed" }); map.ReverseButtonMap.Add(new HOTASButton() { MapName = "kept" }); map.ReverseButtonMap.Add(new HOTASButton() { MapName = "removed" }); map.CalculateSegmentRange(2); Assert.NotEmpty(map.Segments); Assert.Equal(2, map.Segments.Count); Assert.Single(map.ButtonMap); Assert.Equal("kept", map.ButtonMap[0].MapName); Assert.Single(map.ReverseButtonMap); Assert.Equal("kept", map.ReverseButtonMap[0].MapName); }
public void get_segment_from_raw_value_not_found() { var map = new HOTASAxis(); map.CalculateSegmentRange(4); Assert.Equal(4, map.Segments.Count); Assert.Equal(0, map.GetSegmentFromRawValue(65536)); }
public void segment_filter() { var map = new HOTASAxis(); Assert.False(map.SegmentFilter(new Segment(1, ushort.MaxValue))); Assert.True(map.SegmentFilter(new Segment(1, ushort.MinValue))); Assert.True(map.SegmentFilter(new Segment(1, ushort.MaxValue - 1))); }
public void clear_segments() { var map = new HOTASAxis(); map.CalculateSegmentRange(4); Assert.Equal(4, map.Segments.Count); map.ClearSegments(); Assert.Empty(map.Segments); }
public void constructor() { var map = new HOTASAxis(); Assert.NotNull(map.Segments); Assert.NotNull(map.ButtonMap); Assert.NotNull(map.ReverseButtonMap); Assert.Equal(1d, map.SoundVolume); }
public void constructor_test_valid_sound_file_from_deserialization() { var map = new HOTASAxis(); map.SoundFileName = "file name"; CreateAxisMapViewModel(out var subMediaPlayer, map); map.SoundFileName = "bob"; Assert.False(subMediaPlayer.IsMuted); Assert.Equal(0, subMediaPlayer.Volume); }
public void calculate_segment_range_no_segments() { var map = new HOTASAxis(); map.ButtonMap.Add(new HOTASButton()); map.ReverseButtonMap.Add(new HOTASButton()); map.CalculateSegmentRange(0); Assert.Empty(map.Segments); Assert.Empty(map.ButtonMap); Assert.Empty(map.ReverseButtonMap); }
public void segment_boundary_test() { var map = new HOTASAxis(); map.CalculateSegmentRange(4); map.Segments[0].Value = 34000;//adjusting the first segment passed the second segment will pump the second segment up by 655 passed the new value of the first segment Assert.Equal(34655, map.Segments[1].Value); map.Segments[3].Value = ushort.MaxValue + 100;//can't push the last segment any further Assert.Equal(64880, map.Segments[3].Value); }
public void set_value_detect_segment_changed() { var map = new HOTASAxis(); map.Segments.Clear(); map.Segments.Add(new Segment(1, 0)); map.Segments.Add(new Segment(2, 10)); map.Segments.Add(new Segment(3, 20)); Assert.Raises <AxisSegmentChangedEventArgs>(a => map.OnAxisSegmentChanged += a, a => map.OnAxisSegmentChanged -= a, () => map.SetAxis(5)); Assert.True(map.IsSegmentChanged); }
public void set_value_detect_segment_changed_not_enough_segments() { var map = new HOTASAxis(); map.Segments.Clear(); map.SetAxis(1000); Assert.False(map.IsSegmentChanged); map.Segments.Add(new Segment(1, 1)); map.SetAxis(1000); Assert.False(map.IsSegmentChanged); }
public void set_value_same_segment() { var map = new HOTASAxis(); map.Segments.Clear(); map.Segments.Add(new Segment(1, 0)); map.Segments.Add(new Segment(2, 10)); map.Segments.Add(new Segment(3, 20)); map.SetAxis(5); Assert.True(map.IsSegmentChanged); map.SetAxis(5); Assert.False(map.IsSegmentChanged); }
public void get_button_from_raw_value_forward_directional_is_multi_action() { var map = new HOTASAxis(); map.IsDirectional = true; map.IsMultiAction = true; map.CalculateSegmentRange(4); Assert.Equal("Axis Button 1", map.GetButtonMapFromRawValue(16383).MapName); Assert.Equal("Axis Button 2", map.GetButtonMapFromRawValue(32766).MapName); Assert.Equal("Axis Button 3", map.GetButtonMapFromRawValue(49149).MapName); Assert.Equal("Axis Button 4", map.GetButtonMapFromRawValue(65535).MapName); }
public void load_new_sound_command_no_file_name() { var subFileSystem = Substitute.For <IFileSystem>(); var subMediaPlayer = Substitute.For <IMediaPlayer>(); var subDispatcherFactory = Substitute.For <DispatcherFactory>(); var subMediaPlayerFactory = Substitute.For <MediaPlayerFactory>(); subMediaPlayerFactory.CreateMediaPlayer().Returns(subMediaPlayer); subFileSystem.GetSoundFileName().Returns(string.Empty); var map = new HOTASAxis(); var mapVm = new AxisMapViewModel(subDispatcherFactory.CreateDispatcher(), subMediaPlayerFactory, subFileSystem, map); mapVm.OpenFileCommand.Execute(default);
private AxisMapViewModel CreateAxisMapViewModel(out IFileSystem subFileSystem, out IMediaPlayer subMediaPlayer, out HOTASAxis map) { subFileSystem = Substitute.For <IFileSystem>(); var subDispatcherFactory = new DispatcherFactory(); var subMediaPlayerFactory = Substitute.For <MediaPlayerFactory>(); map = new HOTASAxis(); subMediaPlayer = Substitute.For <IMediaPlayer>(); subMediaPlayerFactory.CreateMediaPlayer().Returns(subMediaPlayer); var mapVm = new AxisMapViewModel(subDispatcherFactory.CreateDispatcher(), subMediaPlayerFactory, subFileSystem, map); return(mapVm); }
public void get_segment_from_raw_value() { var map = new HOTASAxis(); map.CalculateSegmentRange(4); Assert.Equal(4, map.Segments.Count); Assert.Equal(1, map.GetSegmentFromRawValue(0)); Assert.Equal(1, map.GetSegmentFromRawValue(16383)); Assert.Equal(2, map.GetSegmentFromRawValue(16384)); Assert.Equal(2, map.GetSegmentFromRawValue(32766)); Assert.Equal(3, map.GetSegmentFromRawValue(32767)); Assert.Equal(3, map.GetSegmentFromRawValue(49149)); Assert.Equal(4, map.GetSegmentFromRawValue(49150)); Assert.Equal(4, map.GetSegmentFromRawValue(65535)); }
public void calculate_segment_not_directional_not_multi_action() { var map = new HOTASAxis(); map.IsDirectional = false; map.IsMultiAction = false;//should create single action button map list map.ButtonMap.Clear(); map.ReverseButtonMap.Clear(); map.CalculateSegmentRange(2); Assert.NotEmpty(map.Segments); Assert.Equal(2, map.Segments.Count); Assert.NotEmpty(map.ButtonMap); Assert.Equal("Axis Button 1", map.ButtonMap[0].MapName); Assert.Empty(map.ReverseButtonMap); }
public void constructor_test_valid_map() { var map = new HOTASAxis(); map.ButtonMap.Add(new HOTASButton() { MapId = 1, MapName = "test 1", Type = HOTASButton.ButtonType.AxisLinear }); map.ButtonMap.Add(new HOTASButton() { MapId = 2, MapName = "test 2", Type = HOTASButton.ButtonType.AxisRadial }); map.ReverseButtonMap.Add(new HOTASButton() { MapId = 3, MapName = "test 3", Type = HOTASButton.ButtonType.AxisLinear }); map.ReverseButtonMap.Add(new HOTASButton() { MapId = 4, MapName = "test 4", Type = HOTASButton.ButtonType.AxisRadial }); var mapVm = CreateAxisMapViewModel(out var subMediaPlayer, map); mapVm.ButtonName = "new name"; Assert.NotEmpty(map.MapName); map.Type = HOTASButton.ButtonType.Button; Assert.Equal(mapVm.Type, map.Type); Assert.Equal(2, mapVm.ButtonMap.Count); Assert.Equal(2, mapVm.ReverseButtonMap.Count); Assert.Equal(mapVm.ButtonMap[0].ButtonId, map.ButtonMap[0].MapId); Assert.Equal(mapVm.ButtonMap[1].ButtonId, map.ButtonMap[1].MapId); Assert.Equal(mapVm.ReverseButtonMap[0].ButtonId, map.ReverseButtonMap[0].MapId); Assert.Equal(mapVm.ReverseButtonMap[1].ButtonId, map.ReverseButtonMap[1].MapId); Assert.True(subMediaPlayer.IsMuted); Assert.Equal(0, subMediaPlayer.Volume); }
public void set_value_direction_changed_when_is_directional_true() { var map = new HOTASAxis(); map.IsDirectional = true; Assert.True(map.Direction == AxisDirection.Forward); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); Assert.True(map.Direction == AxisDirection.Forward); Assert.Raises <AxisDirectionChangedEventArgs>(a => map.OnAxisDirectionChanged += a, a => map.OnAxisDirectionChanged -= a, () => map.SetAxis(700)); Assert.True(map.Direction == AxisDirection.Backward); }
public void set_value_direction_not_changed_when_is_directional_false() { var map = new HOTASAxis(); map.IsDirectional = false; Assert.True(map.Direction == AxisDirection.Forward); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); map.SetAxis(800); Assert.True(map.Direction == AxisDirection.Forward); map.SetAxis(700); Assert.True(map.Direction == AxisDirection.Forward); }
public void apply_activation_button_to_all_profiles() { var subDevice = Substitute.For <IHOTASDevice>(); var buttonMapProfile1 = new ObservableCollection <IHotasBaseMap>(); var button_1_1 = new HOTASButton() { MapId = 1, IsShift = false, ShiftModePage = 1 }; var button_1_2 = new HOTASButton() { MapId = 2, IsShift = false, ShiftModePage = 2 }; var button_1_3 = new HOTASAxis() { MapId = 3, ButtonMap = new ObservableCollection <HOTASButton>() { new HOTASButton() { MapId = 3, ShiftModePage = 3 } } }; buttonMapProfile1.Add(button_1_1); buttonMapProfile1.Add(button_1_2); buttonMapProfile1.Add(button_1_3); var buttonMapProfile2 = new ObservableCollection <IHotasBaseMap>(); var button_2_1 = new HOTASButton() { MapId = 1, IsShift = false, ShiftModePage = 0 }; //simulate a new profile that does not have links back to previous profiles var button_2_2 = new HOTASButton() { MapId = 2, IsShift = false, ShiftModePage = 0 }; //simulate a new profile that does not have links back to previous profiles var button_2_3 = new HOTASAxis() { MapId = 3, ButtonMap = new ObservableCollection <HOTASButton>() { new HOTASButton() { MapId = 3, ShiftModePage = 0 } } }; buttonMapProfile2.Add(button_2_1); buttonMapProfile2.Add(button_2_2); buttonMapProfile2.Add(button_2_3); subDevice.ButtonMap.Returns(buttonMapProfile1); var deviceId = Guid.NewGuid(); subDevice.DeviceId = deviceId; var subDeviceFactory = Substitute.For <HOTASDeviceFactory>(); subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice); var profiles = new Dictionary <int, ObservableCollection <IHotasBaseMap> >() { { 1, buttonMapProfile1 }, { 2, buttonMapProfile2 }, { 3, buttonMapProfile2 } }; subDevice.ModeProfiles.Returns(profiles); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); list.AddDevice(subDevice); list.ListenToAllDevices(); var item1 = new ModeActivationItem() { DeviceId = deviceId, ButtonId = 1, Mode = 1 }; var item2 = new ModeActivationItem() { DeviceId = deviceId, ButtonId = 2, Mode = 2 }; var item3 = new ModeActivationItem() { DeviceId = deviceId, ButtonId = 3, Mode = 3 }; list.ModeProfileActivationButtons.Add(1, item1); list.ModeProfileActivationButtons.Add(2, item2); list.ModeProfileActivationButtons.Add(3, item3); Assert.Equal(0, button_2_1.ShiftModePage); Assert.Equal(0, button_2_2.ShiftModePage); Assert.Equal(0, button_2_3.ButtonMap[0].ShiftModePage); list.ApplyActivationButtonToAllProfiles(); Assert.Equal(1, button_2_1.ShiftModePage); Assert.Equal(2, button_2_2.ShiftModePage); Assert.Equal(3, button_2_3.ButtonMap[0].ShiftModePage); }
private static void SerializeAxis(JsonWriter writer, JsonSerializer serializer, HOTASAxis axis) { var propList = typeof(HOTASAxis).GetProperties(); writer.WriteStartObject(); foreach (var prop in propList) { if (prop.GetCustomAttributes(true).Any(x => x is JsonIgnoreAttribute)) { continue; } var value = prop.GetValue(axis); if (prop.Name == nameof(axis.IsDirectional) && (bool)prop.GetValue(axis) == true) { continue; } if (prop.Name == nameof(axis.IsMultiAction) && (bool)prop.GetValue(axis) == false) { continue; } if (prop.Name == nameof(axis.SoundFileName) && string.IsNullOrEmpty((string)prop.GetValue(axis))) { continue; } if (prop.Name == nameof(axis.SoundVolume) && Math.Abs((double)prop.GetValue(axis) - 1.0d) < 0.01) { continue; } writer.WritePropertyName(prop.Name); serializer.Serialize(writer, value); } writer.WriteEndObject(); }
public void clear_unassigned_actions() { var map = new HOTASAxis(); map.ButtonMap.Add(new HOTASButton() { ActionCatalogItem = new ActionCatalogItem() { ActionName = "<No Action>", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction(), new ButtonAction() } } }); map.ButtonMap.Add(new HOTASButton() { ActionCatalogItem = new ActionCatalogItem() { ActionName = "item 1", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction(), new ButtonAction() } } }); map.ButtonMap.Add(new HOTASButton() { ActionCatalogItem = new ActionCatalogItem() { ActionName = "item 2", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction(), new ButtonAction() } } }); map.ReverseButtonMap.Add(new HOTASButton() { ActionCatalogItem = new ActionCatalogItem() { ActionName = "<No Action>", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction(), new ButtonAction() } } }); map.ReverseButtonMap.Add(new HOTASButton() { ActionCatalogItem = new ActionCatalogItem() { ActionName = "item 1", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction(), new ButtonAction() } } }); map.ReverseButtonMap.Add(new HOTASButton() { ActionCatalogItem = new ActionCatalogItem() { ActionName = "item 2", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction(), new ButtonAction() } } }); map.ClearUnassignedActions(); Assert.Empty(map.ButtonMap[0].ActionCatalogItem.Actions); Assert.Equal(2, map.ButtonMap[1].ActionCatalogItem.Actions.Count); Assert.Equal(2, map.ButtonMap[2].ActionCatalogItem.Actions.Count); Assert.Empty(map.ReverseButtonMap[0].ActionCatalogItem.Actions); Assert.Equal(2, map.ReverseButtonMap[1].ActionCatalogItem.Actions.Count); Assert.Equal(2, map.ReverseButtonMap[2].ActionCatalogItem.Actions.Count); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (objectType == typeof(IHOTASDevice)) { var device = new HOTASDevice(); try { serializer.Populate(reader, device); } catch (Exception e) { Logging.Log.Error(e, "Failed to deserialize a HOTASDevice"); throw; } return(device); } if (objectType == typeof(HOTASButton)) { var buttonMap = new HOTASButton(); try { serializer.Populate(reader, buttonMap); } catch (Exception e) { Logging.Log.Error(e, "Failed to deserialize a HOTASButton"); throw; } return(buttonMap); } if (objectType == typeof(ButtonAction)) { var action = new ButtonAction(); try { serializer.Populate(reader, action); } catch (Exception e) { Logging.Log.Error(e, "Failed to deserialize a ButtonAction"); throw; } return(action); } var dic = new Dictionary <int, ObservableCollection <IHotasBaseMap> >(); var jsonDictionary = JObject.Load(reader); foreach (var kv in jsonDictionary) { var key = int.Parse(kv.Key); var jsonArray = kv.Value; var list = new ObservableCollection <IHotasBaseMap>(); foreach (var jsonObject in jsonArray) { IHotasBaseMap map; var testValue = jsonObject.Value <string>("Type"); Enum.TryParse(testValue, out HOTASButton.ButtonType testType); try { switch (testType) { case HOTASButton.ButtonType.AxisLinear: case HOTASButton.ButtonType.AxisRadial: map = new HOTASAxis(); serializer.Populate(jsonObject.CreateReader(), map); break; default: map = new HOTASButton(); serializer.Populate(jsonObject.CreateReader(), map); break; } } catch (Exception e) { Console.WriteLine(e); throw; } list.Add(map); } dic.Add(key, list); } return(dic); }