Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit 17fb06a

Browse files
committed
Added diagnostics
1 parent d9baa4a commit 17fb06a

19 files changed

+556
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using XOutput.Diagnostics;
7+
8+
namespace XOutput.Devices.Input
9+
{
10+
public class InputDiagnostics : IDiagnostics
11+
{
12+
protected IInputDevice device;
13+
14+
public object Source => device;
15+
16+
public InputDiagnostics(IInputDevice device)
17+
{
18+
this.device = device;
19+
}
20+
21+
public IEnumerable<DiagnosticsResult> GetResults()
22+
{
23+
return new DiagnosticsResult[]
24+
{
25+
GetAxesResult(),
26+
GetButtonsResult(),
27+
GetDPadResult(),
28+
GetForceFeedbackResult(),
29+
};
30+
}
31+
32+
public DiagnosticsResult GetAxesResult()
33+
{
34+
int axesCount = device.Axes.Count();
35+
DiagnosticsResult result = new DiagnosticsResult
36+
{
37+
Value = axesCount,
38+
Type = InputDiagnosticsTypes.AxesCount,
39+
};
40+
if (axesCount < 4)
41+
{
42+
result.State = DiagnosticsResultState.Warning;
43+
}
44+
else
45+
{
46+
result.State = DiagnosticsResultState.Passed;
47+
}
48+
return result;
49+
}
50+
51+
public DiagnosticsResult GetButtonsResult()
52+
{
53+
int buttonsCount = device.Buttons.Count();
54+
DiagnosticsResult result = new DiagnosticsResult
55+
{
56+
Value = buttonsCount,
57+
Type = InputDiagnosticsTypes.ButtonsCount,
58+
};
59+
if (buttonsCount < 8)
60+
{
61+
result.State = DiagnosticsResultState.Warning;
62+
}
63+
else
64+
{
65+
result.State = DiagnosticsResultState.Passed;
66+
}
67+
return result;
68+
}
69+
70+
public DiagnosticsResult GetDPadResult()
71+
{
72+
int dPadsCount = device.DPads.Count();
73+
DiagnosticsResult result = new DiagnosticsResult
74+
{
75+
Value = dPadsCount,
76+
Type = InputDiagnosticsTypes.DPadCount,
77+
};
78+
if (dPadsCount < 1)
79+
{
80+
result.State = DiagnosticsResultState.Warning;
81+
}
82+
else
83+
{
84+
result.State = DiagnosticsResultState.Passed;
85+
}
86+
return result;
87+
}
88+
89+
public DiagnosticsResult GetForceFeedbackResult()
90+
{
91+
int forceFeedbackCount = device.ForceFeedbackCount;
92+
DiagnosticsResult result = new DiagnosticsResult
93+
{
94+
Value = forceFeedbackCount,
95+
Type = InputDiagnosticsTypes.ForceFeedbackCount,
96+
};
97+
if (forceFeedbackCount < 1)
98+
{
99+
result.State = DiagnosticsResultState.Warning;
100+
}
101+
else
102+
{
103+
result.State = DiagnosticsResultState.Passed;
104+
}
105+
return result;
106+
}
107+
}
108+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace XOutput.Devices.Input
8+
{
9+
public enum InputDiagnosticsTypes
10+
{
11+
12+
AxesCount,
13+
ButtonsCount,
14+
DPadCount,
15+
ForceFeedbackCount,
16+
}
17+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using XOutput.Devices.XInput.SCPToolkit;
7+
using XOutput.Devices.XInput.Vigem;
8+
using XOutput.Diagnostics;
9+
10+
namespace XOutput.Devices.XInput
11+
{
12+
public class XInputDiagnostics : IDiagnostics
13+
{
14+
public object Source => null;
15+
16+
public IEnumerable<DiagnosticsResult> GetResults()
17+
{
18+
return new DiagnosticsResult[]
19+
{
20+
GetScpDeviceResult(),
21+
GetVigemDeviceResult(),
22+
GetXDeviceResult(),
23+
};
24+
}
25+
26+
public DiagnosticsResult GetXDeviceResult()
27+
{
28+
DiagnosticsResult result = new DiagnosticsResult
29+
{
30+
Type = XInputDiagnosticsTypes.XDevice,
31+
};
32+
if (GetVigemDeviceResult().State != DiagnosticsResultState.Passed)
33+
{
34+
if (GetScpDeviceResult().State != DiagnosticsResultState.Passed)
35+
{
36+
result.Value = false;
37+
result.State = DiagnosticsResultState.Failed;
38+
}
39+
else
40+
{
41+
result.Value = true;
42+
result.State = DiagnosticsResultState.Warning;
43+
}
44+
}
45+
else
46+
{
47+
result.Value = true;
48+
result.State = DiagnosticsResultState.Passed;
49+
}
50+
return result;
51+
}
52+
53+
public DiagnosticsResult GetScpDeviceResult()
54+
{
55+
DiagnosticsResult result = new DiagnosticsResult
56+
{
57+
Type = XInputDiagnosticsTypes.ScpDevice,
58+
};
59+
if (ScpDevice.IsAvailable())
60+
{
61+
result.Value = true;
62+
result.State = DiagnosticsResultState.Passed;
63+
}
64+
else
65+
{
66+
result.Value = false;
67+
result.State = DiagnosticsResultState.Warning;
68+
}
69+
return result;
70+
}
71+
72+
public DiagnosticsResult GetVigemDeviceResult()
73+
{
74+
DiagnosticsResult result = new DiagnosticsResult
75+
{
76+
Type = XInputDiagnosticsTypes.VigemDevice,
77+
};
78+
if (VigemDevice.IsAvailable())
79+
{
80+
result.Value = true;
81+
result.State = DiagnosticsResultState.Passed;
82+
}
83+
else
84+
{
85+
result.Value = false;
86+
result.State = DiagnosticsResultState.Warning;
87+
}
88+
return result;
89+
}
90+
}
91+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace XOutput.Devices.XInput
8+
{
9+
public enum XInputDiagnosticsTypes
10+
{
11+
XDevice,
12+
ScpDevice,
13+
VigemDevice,
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace XOutput.Diagnostics
8+
{
9+
public class DiagnosticsResult
10+
{
11+
public Enum Type { get; set; }
12+
public object Value { get; set; }
13+
public DiagnosticsResultState State { get; set; }
14+
public string Reason { get; set; }
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace XOutput.Diagnostics
8+
{
9+
public enum DiagnosticsResultState
10+
{
11+
Failed,
12+
Warning,
13+
Passed,
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace XOutput.Diagnostics
8+
{
9+
public interface IDiagnostics
10+
{
11+
object Source { get; }
12+
IEnumerable<DiagnosticsResult> GetResults();
13+
}
14+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using XOutput.Devices.Mapper;
9+
using XOutput.Devices.XInput;
10+
using XOutput.Diagnostics;
11+
12+
namespace XOutput.UI
13+
{
14+
public class DiagnosticsItemModel : ModelBase
15+
{
16+
private readonly ObservableCollection<DiagnosticsResult> results = new ObservableCollection<DiagnosticsResult>();
17+
public ObservableCollection<DiagnosticsResult> Results => results;
18+
19+
private string source;
20+
public string Source
21+
{
22+
get => source;
23+
set
24+
{
25+
if (source != value)
26+
{
27+
source = value;
28+
OnPropertyChanged(nameof(Source));
29+
}
30+
}
31+
}
32+
}
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<UserControl x:Class="XOutput.UI.Component.DiagnosticsItemView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:XOutput.UI.Component"
7+
mc:Ignorable="d"
8+
d:DataContext="{d:DesignInstance Type=local:DiagnosticsItemViewModel, IsDesignTimeCreatable=False}"
9+
d:DesignHeight="30" d:DesignWidth="490">
10+
<UserControl.Resources>
11+
<DataTemplate x:Key="ResultTemplate">
12+
<Grid>
13+
<Grid.ColumnDefinitions>
14+
<ColumnDefinition Width="4*" />
15+
<ColumnDefinition Width="*" />
16+
<ColumnDefinition Width="2*" />
17+
</Grid.ColumnDefinitions>
18+
<Label Grid.Column="0">
19+
<Label.Content>
20+
<MultiBinding Converter="{StaticResource DynamicLanguageConverter}">
21+
<Binding Path="Model.Path" RelativeSource="{RelativeSource AncestorType={x:Type local:DiagnosticsItemView}}" />
22+
<Binding Path="Type" />
23+
</MultiBinding>
24+
</Label.Content>
25+
</Label>
26+
<Label Grid.Column="1" Content="{Binding Value}"/>
27+
<Label Grid.Column="2">
28+
<Label.Content>
29+
<MultiBinding Converter="{StaticResource DynamicLanguageConverter}">
30+
<Binding Path="Model.Path" RelativeSource="{RelativeSource AncestorType={x:Type local:DiagnosticsItemView}}" />
31+
<Binding Path="State" />
32+
</MultiBinding>
33+
</Label.Content>
34+
</Label>
35+
</Grid>
36+
</DataTemplate>
37+
</UserControl.Resources>
38+
<StackPanel>
39+
<Label Content="{Binding Model.Source}"/>
40+
<ItemsControl ItemTemplate="{StaticResource ResultTemplate}" ItemsSource="{Binding Model.Results}" />
41+
</StackPanel>
42+
</UserControl>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace XOutput.UI.Component
17+
{
18+
/// <summary>
19+
/// Interaction logic for MappingView.xaml
20+
/// </summary>
21+
public partial class DiagnosticsItemView : UserControl, IViewBase<DiagnosticsItemViewModel, DiagnosticsItemModel>
22+
{
23+
protected readonly DiagnosticsItemViewModel viewModel;
24+
public DiagnosticsItemViewModel ViewModel => viewModel;
25+
26+
public DiagnosticsItemView(DiagnosticsItemViewModel viewModel)
27+
{
28+
this.viewModel = viewModel;
29+
DataContext = viewModel;
30+
InitializeComponent();
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)