├── .gitignore
├── FS_Tool
├── CodeSign.ps1
├── FS_Tool.sln
├── GUI
│ ├── App.config
│ ├── FS_Tool.vbproj
│ ├── FS_Tool.vbproj.user
│ ├── Joystick.vb
│ ├── JoystickForm.Designer.vb
│ ├── JoystickForm.resx
│ ├── JoystickForm.vb
│ ├── JoystickMapping.ods
│ ├── JoystickMappings-Alpha.xml
│ ├── JoystickMappings.xml
│ ├── MainForm.Designer.vb
│ ├── MainForm.resx
│ ├── MainForm.vb
│ ├── My Project
│ │ ├── Application.Designer.vb
│ │ ├── Application.myapp
│ │ ├── AssemblyInfo.vb
│ │ ├── Resources.Designer.vb
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.vb
│ │ └── Settings.settings
│ ├── ReadMe-JoystickMapping.odt
│ ├── ReadMe-JoystickMapping.pdf
│ ├── SettingsForm.designer.vb
│ ├── SettingsForm.resx
│ ├── SettingsForm.vb
│ ├── SimConnectDebugForm.Designer.vb
│ ├── SimConnectDebugForm.resx
│ └── SimConnectDebugForm.vb
├── HidSharp
│ ├── AsyncResult.cs
│ ├── CommonException.cs
│ ├── Device.cs
│ ├── DeviceException.cs
│ ├── DeviceFilter.cs
│ ├── DeviceList.cs
│ ├── DeviceListChangedEventArgs.cs
│ ├── DeviceOpenUtility.cs
│ ├── DeviceStream.cs
│ ├── DeviceTypes.cs
│ ├── Exceptions
│ │ ├── DeviceIOException.cs
│ │ ├── DeviceUnauthorizedAccessException.cs
│ │ └── IDeviceException.cs
│ ├── Experimental
│ │ ├── BleCccd.cs
│ │ ├── BleCharacteristic.cs
│ │ ├── BleCharacteristicProperties.cs
│ │ ├── BleDescriptor.cs
│ │ ├── BleDevice.cs
│ │ ├── BleDiscovery.cs
│ │ ├── BleEvent.cs
│ │ ├── BleRequestFlags.cs
│ │ ├── BleService.cs
│ │ ├── BleStream.cs
│ │ ├── BleUuid.cs
│ │ └── BleUuids.cs
│ ├── FilteredDeviceList.cs
│ ├── HidDevice.cs
│ ├── HidDeviceLoader.cs
│ ├── HidSharp.NETStandard.csproj
│ ├── HidSharp.csproj
│ ├── HidStream.cs
│ ├── ImplementationDetail.cs
│ ├── LICENSE.txt
│ ├── LocalDeviceList.cs
│ ├── NOTICE.txt
│ ├── OpenConfiguration.cs
│ ├── OpenOption.cs
│ ├── OpenPriority.cs
│ ├── Platform
│ │ ├── HidManager.cs
│ │ ├── HidSelector.cs
│ │ ├── Libusb
│ │ │ ├── LibusbHidManager.cs
│ │ │ └── NativeMethods.cs
│ │ ├── Linux
│ │ │ ├── LinuxHidDevice.cs
│ │ │ ├── LinuxHidManager.cs
│ │ │ ├── LinuxHidStream.cs
│ │ │ ├── LinuxSerialDevice.cs
│ │ │ ├── LinuxSerialStream.cs
│ │ │ ├── NativeMethods.cs
│ │ │ ├── NativeMethodsLibudev.cs
│ │ │ ├── NativeMethodsLibudev0.cs
│ │ │ └── NativeMethodsLibudev1.cs
│ │ ├── MacOS
│ │ │ ├── MacHidDevice.cs
│ │ │ ├── MacHidManager.cs
│ │ │ ├── MacHidStream.cs
│ │ │ ├── MacSerialDevice.cs
│ │ │ ├── MacSerialStream.cs
│ │ │ └── NativeMethods.cs
│ │ ├── SysBleStream.cs
│ │ ├── SysHidStream.cs
│ │ ├── SysRefCountHelper.cs
│ │ ├── SysSerialStream.cs
│ │ ├── SystemEvents.cs
│ │ ├── Unsupported
│ │ │ └── UnsupportedHidManager.cs
│ │ ├── Utf8Marshaler.cs
│ │ └── Windows
│ │ │ ├── NativeMethods.cs
│ │ │ ├── WinBleCharacteristic.cs
│ │ │ ├── WinBleDescriptor.cs
│ │ │ ├── WinBleDevice.cs
│ │ │ ├── WinBleService.cs
│ │ │ ├── WinBleStream.cs
│ │ │ ├── WinHidDevice.ReportDescriptorBuilder.cs
│ │ │ ├── WinHidDevice.ReportDescriptorReconstructor.cs
│ │ │ ├── WinHidDevice.cs
│ │ │ ├── WinHidManager.cs
│ │ │ ├── WinHidStream.cs
│ │ │ ├── WinSerialDevice.cs
│ │ │ └── WinSerialStream.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Reports
│ │ ├── DataConvert.cs
│ │ ├── DataItem.cs
│ │ ├── DataItemFlags.cs
│ │ ├── DataValue.cs
│ │ ├── DescriptorCollectionItem.cs
│ │ ├── DescriptorItem.cs
│ │ ├── DeviceItem.cs
│ │ ├── Encodings
│ │ │ ├── CollectionType.cs
│ │ │ ├── EncodedItem.cs
│ │ │ ├── GlobalItemTag.cs
│ │ │ ├── ItemType.cs
│ │ │ ├── LocalItemTag.cs
│ │ │ └── MainItemTag.cs
│ │ ├── ExpectedUsageType.cs
│ │ ├── IndexList.cs
│ │ ├── IndexRange.cs
│ │ ├── Indexes.cs
│ │ ├── Input
│ │ │ ├── DeviceItemInputParser.cs
│ │ │ └── HidDeviceInputReceiver.cs
│ │ ├── Report.cs
│ │ ├── ReportDescriptor.cs
│ │ ├── ReportDescriptorParseState.cs
│ │ ├── ReportType.cs
│ │ ├── Units
│ │ │ ├── CurrentUnit.cs
│ │ │ ├── LengthUnit.cs
│ │ │ ├── LuminousIntensityUnit.cs
│ │ │ ├── MassUnit.cs
│ │ │ ├── TemperatureUnit.cs
│ │ │ ├── TimeUnit.cs
│ │ │ ├── Unit.cs
│ │ │ ├── UnitKind.cs
│ │ │ └── UnitSystem.cs
│ │ └── Usage.cs
│ ├── SerialDevice.cs
│ ├── SerialParity.cs
│ ├── SerialSettings.cs
│ ├── SerialStream.cs
│ ├── Throw.cs
│ ├── Utility
│ │ ├── BcdHelper.cs
│ │ ├── HResult.cs
│ │ └── HidSharpDiagnostics.cs
│ └── WinAPI.cs
├── LICENSE
├── SelfSignRelease.bat
└── SimConLib
│ ├── AsyncSocket.vb
│ ├── CircularBuffer.vb
│ ├── HeartbeatLabel.vb
│ ├── KeyCodes,SimVars,SimEvents.ods
│ ├── My Project
│ ├── Application.Designer.vb
│ ├── Application.myapp
│ ├── AssemblyInfo.vb
│ ├── Resources.Designer.vb
│ ├── Resources.resx
│ ├── Settings.Designer.vb
│ └── Settings.settings
│ ├── SendInput.vb
│ ├── SimConnectLib.vb
│ ├── SimConnectLib.vbproj
│ ├── SimData.vb
│ ├── SimMessage.vb
│ └── UtilityClasses.vb
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
3 | .vs/
4 | /SS.png
5 | /FS_Tool/CustomControls/gifs/knobcontrol.jpg
6 | /FS_Tool/FS_Control/CustomControls/Images/MWSnap 2020-10-04, 17_06_16.bmp
7 | /FS_Tool/FS_Control/CustomControls/Images/MWSnap 2020-10-04, 17_06_52.bmp
8 | /FS_Tool/FS_Control/CustomControls/Images/MWSnap 2020-10-04, 17_08_22.bmp
9 | /FS_Tool/FS_Control/CustomControls/Images/round-analog-off-turn-button-set_1284-14084.jpg
10 |
--------------------------------------------------------------------------------
/FS_Tool/CodeSign.ps1:
--------------------------------------------------------------------------------
1 |
2 | param (
3 | [string]$file_path = "C:\Temp",
4 | [string]$cert_path = "Cert:\CurrentUser\My\*99E9FCA2F8D1EFBD1BFB5A62D85CC1E1DB3438FA",
5 | [string]$ts_svr = "http://timestamp.digicert.com"
6 | )
7 |
8 | Set-AuthenticodeSignature $file_path -Certificate (Get-ChildItem -path $cert_path) -TimestampServer $ts_svr
9 |
--------------------------------------------------------------------------------
/FS_Tool/FS_Tool.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30503.244
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "FS_Tool", "GUI\FS_Tool.vbproj", "{E8F67517-F8AA-4B70-91EE-AC2A488AC354}"
7 | EndProject
8 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "SimConnectLib", "SimConLib\SimConnectLib.vbproj", "{EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HidSharp", "HidSharp\HidSharp.csproj", "{0DB86674-2A7B-4BDC-93C1-3F7DC771426C}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Debug|x64 = Debug|x64
16 | Debug|x86 = Debug|x86
17 | Release|Any CPU = Release|Any CPU
18 | Release|x64 = Release|x64
19 | Release|x86 = Release|x86
20 | EndGlobalSection
21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
22 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Debug|x64.ActiveCfg = Debug|x64
25 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Debug|x64.Build.0 = Debug|x64
26 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Debug|x86.ActiveCfg = Debug|Any CPU
27 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Debug|x86.Build.0 = Debug|Any CPU
28 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Release|x64.ActiveCfg = Release|x64
31 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Release|x64.Build.0 = Release|x64
32 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Release|x86.ActiveCfg = Release|Any CPU
33 | {E8F67517-F8AA-4B70-91EE-AC2A488AC354}.Release|x86.Build.0 = Release|Any CPU
34 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Debug|x64.ActiveCfg = Debug|x64
37 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Debug|x64.Build.0 = Debug|x64
38 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Debug|x86.ActiveCfg = Debug|Any CPU
39 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Debug|x86.Build.0 = Debug|Any CPU
40 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
41 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Release|Any CPU.Build.0 = Release|Any CPU
42 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Release|x64.ActiveCfg = Release|x64
43 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Release|x64.Build.0 = Release|x64
44 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Release|x86.ActiveCfg = Release|Any CPU
45 | {EDA0118C-B465-4A29-9AD2-3B0AEA2B3E0C}.Release|x86.Build.0 = Release|Any CPU
46 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Debug|Any CPU.Build.0 = Debug|Any CPU
48 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Debug|x64.ActiveCfg = Debug|x64
49 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Debug|x64.Build.0 = Debug|x64
50 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Debug|x86.ActiveCfg = Debug|Any CPU
51 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Debug|x86.Build.0 = Debug|Any CPU
52 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Release|Any CPU.ActiveCfg = Release|Any CPU
53 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Release|Any CPU.Build.0 = Release|Any CPU
54 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Release|x64.ActiveCfg = Release|x64
55 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Release|x64.Build.0 = Release|x64
56 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Release|x86.ActiveCfg = Release|Any CPU
57 | {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Release|x86.Build.0 = Release|Any CPU
58 | EndGlobalSection
59 | GlobalSection(SolutionProperties) = preSolution
60 | HideSolutionNode = FALSE
61 | EndGlobalSection
62 | GlobalSection(ExtensibilityGlobals) = postSolution
63 | SolutionGuid = {4448D2FC-7DD2-4DB4-97DE-5505B1436DFA}
64 | EndGlobalSection
65 | EndGlobal
66 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | 500
15 |
16 |
17 | 0
18 |
19 |
20 | 0
21 |
22 |
23 | False
24 |
25 |
26 | 0
27 |
28 |
29 | 0
30 |
31 |
32 | 12345
33 |
34 |
35 | False
36 |
37 |
38 | True
39 |
40 |
41 | 0
42 |
43 |
44 | 0
45 |
46 |
47 | True
48 |
49 |
50 | True
51 |
52 |
53 | True
54 |
55 |
56 | Default
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/FS_Tool.vbproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | en-US
11 | false
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/JoystickForm.Designer.vb:
--------------------------------------------------------------------------------
1 | _
2 | Partial Class JoystickForm
3 | Inherits System.Windows.Forms.Form
4 |
5 | 'Form overrides dispose to clean up the component list.
6 | _
7 | Protected Overrides Sub Dispose(ByVal disposing As Boolean)
8 | Try
9 | If disposing AndAlso components IsNot Nothing Then
10 | components.Dispose()
11 | End If
12 | Finally
13 | MyBase.Dispose(disposing)
14 | End Try
15 | End Sub
16 |
17 | 'Required by the Windows Form Designer
18 | Private components As System.ComponentModel.IContainer
19 |
20 | 'NOTE: The following procedure is required by the Windows Form Designer
21 | 'It can be modified using the Windows Form Designer.
22 | 'Do not modify it using the code editor.
23 | _
24 | Private Sub InitializeComponent()
25 | Me.components = New System.ComponentModel.Container()
26 | Me.cbJoysticks = New System.Windows.Forms.ComboBox()
27 | Me.txtDisplay = New System.Windows.Forms.TextBox()
28 | Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
29 | Me.btnClose = New System.Windows.Forms.Button()
30 | Me.cbThrottle = New System.Windows.Forms.CheckBox()
31 | Me.cbIgnoreAxes = New System.Windows.Forms.CheckBox()
32 | Me.btnClipboard = New System.Windows.Forms.Button()
33 | Me.SuspendLayout()
34 | '
35 | 'cbJoysticks
36 | '
37 | Me.cbJoysticks.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
38 | Me.cbJoysticks.FormattingEnabled = True
39 | Me.cbJoysticks.Location = New System.Drawing.Point(12, 12)
40 | Me.cbJoysticks.Name = "cbJoysticks"
41 | Me.cbJoysticks.Size = New System.Drawing.Size(578, 21)
42 | Me.cbJoysticks.TabIndex = 0
43 | '
44 | 'txtDisplay
45 | '
46 | Me.txtDisplay.Font = New System.Drawing.Font("Cascadia Code", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
47 | Me.txtDisplay.Location = New System.Drawing.Point(12, 64)
48 | Me.txtDisplay.Multiline = True
49 | Me.txtDisplay.Name = "txtDisplay"
50 | Me.txtDisplay.ReadOnly = True
51 | Me.txtDisplay.Size = New System.Drawing.Size(675, 586)
52 | Me.txtDisplay.TabIndex = 1
53 | '
54 | 'Timer1
55 | '
56 | '
57 | 'btnClose
58 | '
59 | Me.btnClose.Location = New System.Drawing.Point(612, 11)
60 | Me.btnClose.Name = "btnClose"
61 | Me.btnClose.Size = New System.Drawing.Size(75, 21)
62 | Me.btnClose.TabIndex = 2
63 | Me.btnClose.Text = "&Close"
64 | Me.btnClose.UseVisualStyleBackColor = True
65 | '
66 | 'cbThrottle
67 | '
68 | Me.cbThrottle.AutoSize = True
69 | Me.cbThrottle.CheckAlign = System.Drawing.ContentAlignment.MiddleRight
70 | Me.cbThrottle.Location = New System.Drawing.Point(12, 39)
71 | Me.cbThrottle.Name = "cbThrottle"
72 | Me.cbThrottle.Size = New System.Drawing.Size(190, 17)
73 | Me.cbThrottle.TabIndex = 3
74 | Me.cbThrottle.Text = "Throttle display updates to 10/sec:"
75 | Me.cbThrottle.UseVisualStyleBackColor = True
76 | '
77 | 'cbIgnoreAxes
78 | '
79 | Me.cbIgnoreAxes.AutoSize = True
80 | Me.cbIgnoreAxes.CheckAlign = System.Drawing.ContentAlignment.MiddleRight
81 | Me.cbIgnoreAxes.Location = New System.Drawing.Point(281, 39)
82 | Me.cbIgnoreAxes.Name = "cbIgnoreAxes"
83 | Me.cbIgnoreAxes.Size = New System.Drawing.Size(84, 17)
84 | Me.cbIgnoreAxes.TabIndex = 4
85 | Me.cbIgnoreAxes.Text = "Ignore axes:"
86 | Me.cbIgnoreAxes.UseVisualStyleBackColor = True
87 | '
88 | 'btnClipboard
89 | '
90 | Me.btnClipboard.Location = New System.Drawing.Point(414, 39)
91 | Me.btnClipboard.Name = "btnClipboard"
92 | Me.btnClipboard.Size = New System.Drawing.Size(176, 21)
93 | Me.btnClipboard.TabIndex = 5
94 | Me.btnClipboard.Text = "Copy Blank Profile to Clipboard"
95 | Me.btnClipboard.UseVisualStyleBackColor = True
96 | '
97 | 'JoystickForm
98 | '
99 | Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
100 | Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
101 | Me.ClientSize = New System.Drawing.Size(694, 662)
102 | Me.Controls.Add(Me.btnClipboard)
103 | Me.Controls.Add(Me.cbIgnoreAxes)
104 | Me.Controls.Add(Me.cbThrottle)
105 | Me.Controls.Add(Me.btnClose)
106 | Me.Controls.Add(Me.txtDisplay)
107 | Me.Controls.Add(Me.cbJoysticks)
108 | Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
109 | Me.MaximizeBox = False
110 | Me.MinimizeBox = False
111 | Me.Name = "JoystickForm"
112 | Me.ShowIcon = False
113 | Me.ShowInTaskbar = False
114 | Me.Text = "JoystickForm"
115 | Me.ResumeLayout(False)
116 | Me.PerformLayout()
117 |
118 | End Sub
119 |
120 | Friend WithEvents cbJoysticks As ComboBox
121 | Friend WithEvents txtDisplay As TextBox
122 | Friend WithEvents Timer1 As Timer
123 | Friend WithEvents btnClose As Button
124 | Friend WithEvents cbThrottle As CheckBox
125 | Friend WithEvents cbIgnoreAxes As CheckBox
126 | Friend WithEvents btnClipboard As Button
127 | End Class
128 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/JoystickMapping.ods:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Elephant42/FS_Tool/634ed2e76a987dcbd0dff6c1f354619cba695eed/FS_Tool/GUI/JoystickMapping.ods
--------------------------------------------------------------------------------
/FS_Tool/GUI/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | 'NOTE: This file is auto-generated; do not modify it directly. To make changes,
18 | ' or if you encounter build errors in this file, go to the Project Designer
19 | ' (go to Project Properties or double-click the My Project node in
20 | ' Solution Explorer), and make changes on the Application tab.
21 | '
22 | Partial Friend Class MyApplication
23 |
24 | _
25 | Public Sub New()
26 | MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
27 | Me.IsSingleInstance = false
28 | Me.EnableVisualStyles = true
29 | Me.SaveMySettingsOnExit = true
30 | Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
31 | End Sub
32 |
33 | _
34 | Protected Overrides Sub OnCreateMainForm()
35 | Me.MainForm = Global.FS_Tool.MainForm
36 | End Sub
37 | End Class
38 | End Namespace
39 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | true
4 | MainForm
5 | false
6 | 0
7 | true
8 | 0
9 | true
10 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Reflection
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
21 |
22 |
23 | ' Version information for an assembly consists of the following four values:
24 | '
25 | ' Major Version
26 | ' Minor Version
27 | ' Build Number
28 | ' Revision
29 | '
30 | ' You can specify all the values or you can default the Build and Revision Numbers
31 | ' by using the '*' as shown below:
32 | '
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/My Project/Resources.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 | Imports System
15 |
16 | Namespace My.Resources
17 |
18 | 'This class was auto-generated by the StronglyTypedResourceBuilder
19 | 'class via a tool like ResGen or Visual Studio.
20 | 'To add or remove a member, edit your .ResX file then rerun ResGen
21 | 'with the /str option, or rebuild your VS project.
22 | '''
23 | ''' A strongly-typed resource class, for looking up localized strings, etc.
24 | '''
25 | _
29 | Friend Module Resources
30 |
31 | Private resourceMan As Global.System.Resources.ResourceManager
32 |
33 | Private resourceCulture As Global.System.Globalization.CultureInfo
34 |
35 | '''
36 | ''' Returns the cached ResourceManager instance used by this class.
37 | '''
38 | _
39 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
40 | Get
41 | If Object.ReferenceEquals(resourceMan, Nothing) Then
42 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("FS_Tool.Resources", GetType(Resources).Assembly)
43 | resourceMan = temp
44 | End If
45 | Return resourceMan
46 | End Get
47 | End Property
48 |
49 | '''
50 | ''' Overrides the current thread's CurrentUICulture property for all
51 | ''' resource lookups using this strongly typed resource class.
52 | '''
53 | _
54 | Friend Property Culture() As Global.System.Globalization.CultureInfo
55 | Get
56 | Return resourceCulture
57 | End Get
58 | Set
59 | resourceCulture = value
60 | End Set
61 | End Property
62 | End Module
63 | End Namespace
64 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/My Project/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 500
7 |
8 |
9 | 0
10 |
11 |
12 | 0
13 |
14 |
15 | False
16 |
17 |
18 | 0
19 |
20 |
21 | 0
22 |
23 |
24 | 12345
25 |
26 |
27 | False
28 |
29 |
30 | True
31 |
32 |
33 | 0
34 |
35 |
36 | 0
37 |
38 |
39 | True
40 |
41 |
42 | True
43 |
44 |
45 | True
46 |
47 |
48 | Default
49 |
50 |
51 |
--------------------------------------------------------------------------------
/FS_Tool/GUI/ReadMe-JoystickMapping.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Elephant42/FS_Tool/634ed2e76a987dcbd0dff6c1f354619cba695eed/FS_Tool/GUI/ReadMe-JoystickMapping.odt
--------------------------------------------------------------------------------
/FS_Tool/GUI/ReadMe-JoystickMapping.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Elephant42/FS_Tool/634ed2e76a987dcbd0dff6c1f354619cba695eed/FS_Tool/GUI/ReadMe-JoystickMapping.pdf
--------------------------------------------------------------------------------
/FS_Tool/GUI/SettingsForm.vb:
--------------------------------------------------------------------------------
1 | Option Explicit On
2 | Option Strict On
3 | Imports System.IO
4 |
5 | Public Class SettingsForm
6 |
7 | Public Property StartMinimised As Boolean
8 | Get
9 | Return Me.chkStartMinim.Checked
10 | End Get
11 | Set(value As Boolean)
12 | Me.chkStartMinim.Checked = value
13 | End Set
14 | End Property
15 |
16 | Public Property ServerPort As Integer
17 | Get
18 | Return CInt(Me.txtPort.Text)
19 | End Get
20 | Set(value As Integer)
21 | Me.txtPort.Text = value.ToString
22 | End Set
23 | End Property
24 |
25 | Public Property AutoStartJoyMap As Boolean
26 | Get
27 | Return Me.chkAutoJoy.Checked
28 | End Get
29 | Set(value As Boolean)
30 | Me.chkAutoJoy.Checked = value
31 | End Set
32 | End Property
33 |
34 | Public Property AutoStartServer As Boolean
35 | Get
36 | Return Me.chkStartServer.Checked
37 | End Get
38 | Set(value As Boolean)
39 | Me.chkStartServer.Checked = value
40 | End Set
41 | End Property
42 |
43 | Public Property AutoStartSimConnect As Boolean
44 | Get
45 | Return Me.chkAutoSim.Checked
46 | End Get
47 | Set(value As Boolean)
48 | Me.chkAutoSim.Checked = value
49 | End Set
50 | End Property
51 |
52 | Public Property SimConnectPollingInterval As Integer
53 | Get
54 | Return CInt(Me.txtSimPoll_ms.Text)
55 | End Get
56 | Set(value As Integer)
57 | Me.txtSimPoll_ms.Text = value.ToString
58 | End Set
59 | End Property
60 |
61 | Private Sub doSave()
62 |
63 | If Not IsNumeric(Me.txtPort.Text) Then
64 | MessageBox.Show("Port Number is not numeric", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
65 | Exit Sub
66 | End If
67 |
68 | If Not IsNumeric(Me.txtSimPoll_ms.Text) Then
69 | MessageBox.Show("SimConnect Poll Interval is not numeric", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
70 | Exit Sub
71 | End If
72 |
73 | Me.DialogResult = DialogResult.OK
74 |
75 | End Sub
76 |
77 | Private Sub doSaveGrunt()
78 |
79 | Try
80 | Me.DialogResult = DialogResult.OK
81 | Me.Close()
82 | Catch ex As Exception
83 | MessageBox.Show("Exception: " & ex.Message)
84 | End Try
85 |
86 | End Sub
87 |
88 | Private Sub formNotBusy()
89 | formBusy(False)
90 | End Sub
91 |
92 | Private Sub formBusy()
93 | formBusy(True)
94 | End Sub
95 | Private Sub formBusy(ByVal pBusyFlag As Boolean)
96 |
97 | Me.btnSave.Enabled = Not pBusyFlag
98 |
99 | End Sub
100 |
101 | Private Sub doFormLoad()
102 |
103 | End Sub
104 |
105 | #Region "Event Handlers"
106 |
107 | Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
108 | doFormLoad()
109 | End Sub
110 |
111 | Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
112 | doSave()
113 | End Sub
114 |
115 | Private Sub chkAutoJoy_CheckedChanged(sender As Object, e As EventArgs) Handles chkAutoJoy.CheckedChanged
116 | If chkAutoJoy.Checked Then chkAutoSim.Checked = True
117 | End Sub
118 |
119 | Private Sub chkAutoSim_CheckedChanged(sender As Object, e As EventArgs) Handles chkAutoSim.CheckedChanged
120 | If Not chkAutoSim.Checked Then chkAutoJoy.Checked = False
121 | End Sub
122 |
123 | #End Region
124 |
125 | End Class
126 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/AsyncResult.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2012 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Threading;
20 |
21 | namespace HidSharp
22 | {
23 | sealed class AsyncResult : IAsyncResult
24 | {
25 | volatile bool _isCompleted;
26 | ManualResetEvent _waitHandle;
27 |
28 | AsyncResult(AsyncCallback callback, object state)
29 | {
30 | AsyncCallback = callback; AsyncState = state;
31 | }
32 |
33 | void Complete()
34 | {
35 | lock (this)
36 | {
37 | if (_isCompleted) { return; } _isCompleted = true;
38 | if (_waitHandle != null) { _waitHandle.Set(); }
39 | }
40 |
41 | if (AsyncCallback != null) { AsyncCallback(this); }
42 | }
43 |
44 | internal delegate T OperationCallback();
45 |
46 | internal static IAsyncResult BeginOperation(OperationCallback operation,
47 | AsyncCallback callback, object state)
48 | {
49 | var ar = new AsyncResult(callback, state);
50 | ThreadPool.QueueUserWorkItem(delegate(object self)
51 | {
52 | try { ar.Result = operation(); }
53 | catch (Exception e) { ar.Exception = e; }
54 | ar.Complete();
55 | }, ar);
56 | return ar;
57 | }
58 |
59 | internal T EndOperation()
60 | {
61 | while (true)
62 | {
63 | if (IsCompleted)
64 | {
65 | if (Exception != null) { throw Exception; }
66 | return Result;
67 | }
68 | AsyncWaitHandle.WaitOne();
69 | }
70 | }
71 |
72 | internal static T EndOperation(IAsyncResult asyncResult)
73 | {
74 | Throw.If.Null(asyncResult);
75 | return ((AsyncResult)asyncResult).EndOperation();
76 | }
77 |
78 | public AsyncCallback AsyncCallback
79 | {
80 | get;
81 | private set;
82 | }
83 |
84 | public object AsyncState
85 | {
86 | get;
87 | private set;
88 | }
89 |
90 | public WaitHandle AsyncWaitHandle
91 | {
92 | get
93 | {
94 | lock (this)
95 | {
96 | if (_waitHandle == null)
97 | {
98 | _waitHandle = new ManualResetEvent(_isCompleted);
99 | }
100 | }
101 |
102 | return _waitHandle;
103 | }
104 | }
105 |
106 | public bool CompletedSynchronously
107 | {
108 | get { return false; }
109 | }
110 |
111 | public bool IsCompleted
112 | {
113 | get { return _isCompleted; }
114 | }
115 |
116 | Exception Exception
117 | {
118 | get;
119 | set;
120 | }
121 |
122 | T Result
123 | {
124 | get;
125 | set;
126 | }
127 | }
128 | }
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/CommonException.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp
21 | {
22 | static class CommonException
23 | {
24 | public static ObjectDisposedException CreateClosedException()
25 | {
26 | return new ObjectDisposedException("Closed.", (Exception)null);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Device.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Diagnostics;
20 | using HidSharp.Utility;
21 |
22 | namespace HidSharp
23 | {
24 | public abstract class Device
25 | {
26 | ///
27 | /// Makes a connection to the device, or throws an exception if the connection cannot be made.
28 | ///
29 | /// The stream to use to communicate with the device.
30 | public DeviceStream Open()
31 | {
32 | return Open(null);
33 | }
34 |
35 | public DeviceStream Open(OpenConfiguration openConfig)
36 | {
37 | return OpenDeviceAndRestrictAccess(openConfig ?? new OpenConfiguration());
38 | }
39 |
40 | protected virtual DeviceStream OpenDeviceAndRestrictAccess(OpenConfiguration openConfig)
41 | {
42 | bool exclusive = (bool)openConfig.GetOption(OpenOption.Exclusive);
43 |
44 | DeviceOpenUtility openUtility = null;
45 | if (exclusive)
46 | {
47 | string streamPath = GetStreamPath(openConfig);
48 | openUtility = new DeviceOpenUtility(this, streamPath, openConfig);
49 | openUtility.Open();
50 | }
51 |
52 | DeviceStream stream;
53 | try
54 | {
55 | stream = OpenDeviceDirectly(openConfig);
56 | if (exclusive)
57 | {
58 | stream.Closed += (sender, e) => openUtility.Close();
59 | openUtility.InterruptRequested += (sender, e) =>
60 | {
61 | stream.OnInterruptRequested();
62 | HidSharpDiagnostics.Trace("Delivered an interrupt request.");
63 | };
64 | }
65 | }
66 | catch
67 | {
68 | if (exclusive) { openUtility.Close(); }
69 | throw;
70 | }
71 |
72 | return stream;
73 | }
74 |
75 | protected abstract DeviceStream OpenDeviceDirectly(OpenConfiguration openConfig);
76 |
77 | // Used for exclusion... and also may be used inside OpenDeviceDirectly if desired.
78 | protected virtual string GetStreamPath(OpenConfiguration openConfig)
79 | {
80 | return DevicePath;
81 | }
82 |
83 | ///
84 | /// Tries to make a connection to the device.
85 | ///
86 | /// The stream to use to communicate with the device.
87 | /// true if the connection was successful.
88 | public bool TryOpen(out DeviceStream stream)
89 | {
90 | return TryOpen(null, out stream);
91 | }
92 |
93 | public bool TryOpen(OpenConfiguration openConfig, out DeviceStream stream)
94 | {
95 | Exception exception;
96 | return TryOpen(openConfig, out stream, out exception);
97 | }
98 |
99 | public bool TryOpen(OpenConfiguration openConfig, out DeviceStream stream, out Exception exception)
100 | {
101 | try
102 | {
103 | stream = Open(openConfig); exception = null; return true;
104 | }
105 | catch (Exception e)
106 | {
107 | Debug.WriteLine(e);
108 | stream = null; exception = e; return false;
109 | }
110 | }
111 |
112 | ///
113 | /// Returns the file system path of the device.
114 | /// This can be used to check permissions on Linux hidraw, for instance.
115 | ///
116 | /// The file system path.
117 | public abstract string GetFileSystemName();
118 |
119 | ///
120 | /// Returns a name appropriate for display.
121 | ///
122 | /// The friendly name.
123 | public abstract string GetFriendlyName();
124 |
125 | ///
126 | /// Checks if a particular implementation detail, such as the use of the Linux hidraw API, applies to this device.
127 | /// See for a list of possible details.
128 | ///
129 | /// The detail to check.
130 | /// true if the implementation detail applies.
131 | public virtual bool HasImplementationDetail(Guid detail)
132 | {
133 | return false;
134 | }
135 |
136 | ///
137 | /// The operating system's name for the device.
138 | ///
139 | /// If you have multiple devices with the same Vendor ID, Product ID, Serial Number, etc.,
140 | /// this may be useful for differentiating them.
141 | ///
142 | public abstract string DevicePath
143 | {
144 | get;
145 | }
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/DeviceException.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.IO;
20 |
21 | namespace HidSharp
22 | {
23 | public static class DeviceException
24 | {
25 | ///
26 | /// Initializes a new instance of the class, and associates a with it.
27 | ///
28 | /// The device that caused the exception.
29 | /// A description of the error.
30 | /// The new .
31 | public static IOException CreateIOException(Device device, string message)
32 | {
33 | return new Exceptions.DeviceIOException(device, message);
34 | }
35 |
36 | ///
37 | /// Initializes a new instance of the class, and associates a with it.
38 | ///
39 | /// The device that caused the exception.
40 | /// A description of the error.
41 | /// An integer identifying the error that has occurred.
42 | /// The new .
43 | public static IOException CreateIOException(Device device, string message, int hresult)
44 | {
45 | return new Exceptions.DeviceIOException(device, message, hresult);
46 | }
47 |
48 | ///
49 | /// Initializes a new instance of the class, and associates a with it.
50 | ///
51 | /// The device that caused the exception.
52 | /// A description of the error.
53 | /// The new .
54 | public static UnauthorizedAccessException CreateUnauthorizedAccessException(Device device, string message)
55 | {
56 | return new Exceptions.DeviceUnauthorizedAccessException(device, message);
57 | }
58 |
59 | ///
60 | /// Gets the associated with the exception, if any.
61 | ///
62 | /// The exception to get the associated for.
63 | /// The associated , or null if none is associated with it.
64 | public static Device GetDevice(Exception exception)
65 | {
66 | var hidException = exception as Exceptions.IDeviceException;
67 | return hidException != null ? hidException.Device : null;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/DeviceFilter.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp
19 | {
20 | public delegate bool DeviceFilter(Device device);
21 |
22 | public static class DeviceFilterHelper
23 | {
24 | public static bool MatchHidDevices(Device device, int? vendorID = null, int? productID = null, int? releaseNumberBcd = null, string serialNumber = null)
25 | {
26 | var hidDevice = device as HidDevice;
27 | if (hidDevice != null)
28 | {
29 | int vid = vendorID ?? -1, pid = productID ?? -1, ver = releaseNumberBcd ?? -1;
30 |
31 | if ((vid < 0 || hidDevice.VendorID == vendorID) &&
32 | (pid < 0 || hidDevice.ProductID == productID) &&
33 | (ver < 0 || hidDevice.ReleaseNumberBcd == releaseNumberBcd))
34 | {
35 | try
36 | {
37 | if (string.IsNullOrEmpty(serialNumber) || hidDevice.GetSerialNumber() == serialNumber) { return true; }
38 | }
39 | catch
40 | {
41 |
42 | }
43 | }
44 | }
45 |
46 | return false;
47 | }
48 |
49 | public static bool MatchSerialDevices(Device device, string portName = null)
50 | {
51 | var serialDevice = device as SerialDevice;
52 | if (serialDevice != null)
53 | {
54 | if (string.IsNullOrEmpty(portName) || serialDevice.DevicePath == portName)
55 | {
56 | return true;
57 | }
58 | }
59 |
60 | return false;
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/DeviceListChangedEventArgs.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2016 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp
21 | {
22 | public class DeviceListChangedEventArgs : EventArgs
23 | {
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/DeviceTypes.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp
21 | {
22 | [Flags]
23 | public enum DeviceTypes
24 | {
25 | Hid = 1,
26 | Serial = 2,
27 | Ble = 4
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Exceptions/DeviceIOException.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.IO;
19 |
20 | namespace HidSharp.Exceptions
21 | {
22 | sealed class DeviceIOException : IOException, IDeviceException
23 | {
24 | public DeviceIOException(Device device, string message)
25 | : base(message)
26 | {
27 | Device = device;
28 | }
29 |
30 | public DeviceIOException(Device device, string message, int hresult)
31 | : base(message, hresult)
32 | {
33 | Device = device;
34 | }
35 |
36 | public Device Device
37 | {
38 | get;
39 | private set;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Exceptions/DeviceUnauthorizedAccessException.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Exceptions
21 | {
22 | sealed class DeviceUnauthorizedAccessException : UnauthorizedAccessException, IDeviceException
23 | {
24 | public DeviceUnauthorizedAccessException(Device device, string message)
25 | : base(message)
26 | {
27 | Device = device;
28 | }
29 |
30 | public Device Device
31 | {
32 | get;
33 | private set;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Exceptions/IDeviceException.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Exceptions
19 | {
20 | interface IDeviceException
21 | {
22 | Device Device { get; }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleCccd.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Experimental
21 | {
22 | [Flags]
23 | public enum BleCccd : ushort
24 | {
25 | None = 0,
26 | Notification = 1,
27 | Indication = 2
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleCharacteristic.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Experimental
21 | {
22 | public abstract class BleCharacteristic
23 | {
24 | public override string ToString()
25 | {
26 | return string.Format("{0} (properties: {1})", Uuid, Properties);
27 | }
28 |
29 | public abstract BleDescriptor[] GetDescriptors();
30 |
31 | public bool HasDescriptor(BleUuid uuid)
32 | {
33 | BleDescriptor descriptor;
34 | return TryGetDescriptor(uuid, out descriptor);
35 | }
36 |
37 | public BleDescriptor GetDescriptorOrNull(BleUuid uuid)
38 | {
39 | BleDescriptor descriptor;
40 | return TryGetDescriptor(uuid, out descriptor) ? descriptor : null;
41 | }
42 |
43 | public virtual bool TryGetDescriptor(BleUuid uuid, out BleDescriptor descriptor)
44 | {
45 | foreach (var d in GetDescriptors())
46 | {
47 | if (d.Uuid == uuid) { descriptor = d; return true; }
48 | }
49 |
50 | descriptor = null; return false;
51 | }
52 |
53 | public abstract BleUuid Uuid
54 | {
55 | get;
56 | }
57 |
58 | public abstract BleCharacteristicProperties Properties
59 | {
60 | get;
61 | }
62 |
63 | public bool IsReadable
64 | {
65 | get { return (Properties & BleCharacteristicProperties.Read) != 0; }
66 | }
67 |
68 | public bool IsWritable
69 | {
70 | get { return (Properties & BleCharacteristicProperties.Write) != 0; }
71 | }
72 |
73 | public bool IsWritableWithoutResponse
74 | {
75 | get { return (Properties & BleCharacteristicProperties.WriteWithoutResponse) != 0; }
76 | }
77 |
78 | public bool IsNotifiable
79 | {
80 | get { return (Properties & BleCharacteristicProperties.Notify) != 0; }
81 | }
82 |
83 | public bool IsIndicatable
84 | {
85 | get { return (Properties & BleCharacteristicProperties.Indicate) != 0; }
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleCharacteristicProperties.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Experimental
21 | {
22 | [Flags]
23 | public enum BleCharacteristicProperties : byte
24 | {
25 | None = 0x00,
26 | Broadcast = 0x01,
27 | Read = 0x02,
28 | WriteWithoutResponse = 0x04,
29 | Write = 0x08,
30 | Notify = 0x10,
31 | Indicate = 0x20,
32 | SignedWrite = 0x40,
33 | ExtendedProperties = 0x80
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleDescriptor.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Experimental
21 | {
22 | public abstract class BleDescriptor
23 | {
24 | public override string ToString()
25 | {
26 | return Uuid.ToString();
27 | }
28 |
29 | public abstract BleUuid Uuid
30 | {
31 | get;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleDevice.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.ComponentModel;
20 | using System.Runtime.CompilerServices;
21 | using System.Runtime.InteropServices;
22 |
23 | namespace HidSharp.Experimental
24 | {
25 | ///
26 | /// Represents a Bluetooth Low Energy device.
27 | ///
28 | [ComVisible(true), Guid("A7AEE7B8-893D-41B6-84F7-6BDA4EE3AA3F")]
29 | public abstract class BleDevice : Device
30 | {
31 | ///
32 | [EditorBrowsable(EditorBrowsableState.Never)]
33 | public new BleStream Open()
34 | {
35 | return (BleStream)base.Open();
36 | }
37 |
38 | ///
39 | [EditorBrowsable(EditorBrowsableState.Never)]
40 | public new BleStream Open(OpenConfiguration openConfig)
41 | {
42 | return (BleStream)base.Open(openConfig);
43 | }
44 |
45 | public BleStream Open(BleService service)
46 | {
47 | return Open(service, new OpenConfiguration());
48 | }
49 |
50 | public BleStream Open(BleService service, OpenConfiguration openConfig)
51 | {
52 | Throw.If.Null(service).Null(openConfig);
53 |
54 | openConfig = openConfig.Clone();
55 | openConfig.SetOption(OpenOption.BleService, service);
56 | return Open(openConfig);
57 | }
58 |
59 | /*
60 | public abstract bool GetConnectionState();
61 | */
62 |
63 | public abstract BleService[] GetServices();
64 |
65 | public BleService GetServiceOrNull(BleUuid uuid)
66 | {
67 | BleService service;
68 | return TryGetService(uuid, out service) ? service : null;
69 | }
70 |
71 | public virtual bool HasService(BleUuid uuid)
72 | {
73 | BleService service;
74 | return TryGetService(uuid, out service);
75 | }
76 |
77 | public virtual bool TryGetService(BleUuid uuid, out BleService service)
78 | {
79 | foreach (var s in GetServices())
80 | {
81 | if (s.Uuid == uuid) { service = s; return true; }
82 | }
83 |
84 | service = null; return false;
85 | }
86 |
87 | public override bool HasImplementationDetail(Guid detail)
88 | {
89 | return base.HasImplementationDetail(detail) || detail == ImplementationDetail.BleDevice;
90 | }
91 |
92 | public override string ToString()
93 | {
94 | string friendlyName = "(unknown friendly name)";
95 | try { friendlyName = GetFriendlyName(); }
96 | catch { }
97 |
98 | return friendlyName;
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleDiscovery.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Experimental
21 | {
22 | abstract class BleDiscovery : IDisposable
23 | {
24 | public abstract void StopDiscovery();
25 |
26 | void IDisposable.Dispose()
27 | {
28 | StopDiscovery();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleEvent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace HidSharp.Experimental
7 | {
8 | public struct BleEvent
9 | {
10 | BleCharacteristic _characteristic;
11 | byte[] _value;
12 |
13 | public BleEvent(BleCharacteristic characteristic, byte[] value)
14 | {
15 | _characteristic = characteristic; _value = value;
16 | }
17 |
18 | public BleCharacteristic Characteristic
19 | {
20 | get { return _characteristic; }
21 | }
22 |
23 | public byte[] Value
24 | {
25 | get { return _value; }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleRequestFlags.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Experimental
21 | {
22 | [Flags]
23 | public enum BleRequestFlags
24 | {
25 | None = 0,
26 | Authenticated = 1,
27 | Encrypted = 2,
28 | Cacheable = 4
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleService.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Experimental
21 | {
22 | public abstract class BleService
23 | {
24 | public override string ToString()
25 | {
26 | return Uuid.ToString();
27 | }
28 |
29 | public abstract BleCharacteristic[] GetCharacteristics();
30 |
31 | public BleCharacteristic GetCharacteristicOrNull(BleUuid uuid)
32 | {
33 | BleCharacteristic characteristic;
34 | return TryGetCharacteristic(uuid, out characteristic) ? characteristic : null;
35 | }
36 |
37 | public virtual bool HasCharacteristic(BleUuid uuid)
38 | {
39 | BleCharacteristic characteristic;
40 | return TryGetCharacteristic(uuid, out characteristic);
41 | }
42 |
43 | public virtual bool TryGetCharacteristic(BleUuid uuid, out BleCharacteristic characteristic)
44 | {
45 | foreach (var c in GetCharacteristics())
46 | {
47 | if (c.Uuid == uuid) { characteristic = c; return true; }
48 | }
49 |
50 | characteristic = null; return false;
51 | }
52 |
53 | public abstract BleDevice Device
54 | {
55 | get;
56 | }
57 |
58 | public abstract BleUuid Uuid
59 | {
60 | get;
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleUuid.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Globalization;
20 |
21 | namespace HidSharp.Experimental
22 | {
23 | public struct BleUuid : IEquatable
24 | {
25 | Guid _guid;
26 |
27 | public BleUuid(int uuid) : this()
28 | {
29 | Initialize(uuid);
30 | }
31 |
32 | public BleUuid(Guid guid) : this()
33 | {
34 | Initialize(guid);
35 | }
36 |
37 | public BleUuid(string uuid) : this()
38 | {
39 | Initialize(uuid);
40 | }
41 |
42 | void Initialize(int uuid)
43 | {
44 | _guid = new Guid(uuid, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
45 | }
46 |
47 | void Initialize(Guid guid)
48 | {
49 | _guid = guid;
50 | }
51 |
52 | void Initialize(string guid)
53 | {
54 | uint shortUuid;
55 | if (uint.TryParse(guid, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out shortUuid))
56 | {
57 | Initialize((int)shortUuid);
58 | }
59 | else
60 | {
61 | Initialize(new Guid(guid));
62 | }
63 | }
64 |
65 | public override bool Equals(object other)
66 | {
67 | return other is BleUuid && Equals((BleUuid)other);
68 | }
69 |
70 | public bool Equals(BleUuid other)
71 | {
72 | return _guid.Equals(other._guid);
73 | }
74 |
75 | public override int GetHashCode()
76 | {
77 | return _guid.GetHashCode();
78 | }
79 |
80 | public static implicit operator BleUuid(Guid guid)
81 | {
82 | return new BleUuid(guid);
83 | }
84 |
85 | public static implicit operator Guid(BleUuid uuid)
86 | {
87 | return uuid.ToGuid();
88 | }
89 |
90 | public int ToShortUuid()
91 | {
92 | if (!IsShortUuid) { throw new InvalidOperationException(); }
93 |
94 | byte[] bytes = _guid.ToByteArray();
95 | return (ushort)(bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24);
96 | }
97 |
98 | static void SwapNetworkOrder(byte[] guid)
99 | {
100 | byte temp;
101 | temp = guid[0]; guid[0] = guid[3]; guid[3] = temp;
102 | temp = guid[1]; guid[1] = guid[2]; guid[2] = temp;
103 | temp = guid[4]; guid[4] = guid[5]; guid[5] = temp;
104 | temp = guid[6]; guid[6] = guid[7]; guid[7] = temp;
105 | }
106 |
107 | public byte[] ToByteArray()
108 | {
109 | var guid = _guid.ToByteArray();
110 | SwapNetworkOrder(guid);
111 | return guid;
112 | }
113 |
114 | public Guid ToGuid()
115 | {
116 | return _guid;
117 | }
118 |
119 | public override string ToString()
120 | {
121 | return IsShortUuid ? ToShortUuid().ToString("X", CultureInfo.InvariantCulture) : ToGuid().ToString("D", CultureInfo.InvariantCulture);
122 | }
123 |
124 | public bool IsShortUuid
125 | {
126 | get
127 | {
128 | byte[] bytes = _guid.ToByteArray();
129 | return bytes[4] == 0x00 && bytes[5] == 0x00
130 | && bytes[6] == 0x00 && bytes[7] == 0x10
131 | && bytes[8] == 0x80 && bytes[9] == 0x00 && bytes[10] == 0x00 && bytes[11] == 0x80 && bytes[12] == 0x5F && bytes[13] == 0x9B && bytes[14] == 0x34 && bytes[15] == 0xFB;
132 | }
133 | }
134 |
135 | public static bool operator ==(BleUuid lhs, BleUuid rhs)
136 | {
137 | return lhs.Equals(rhs);
138 | }
139 |
140 | public static bool operator !=(BleUuid lhs, BleUuid rhs)
141 | {
142 | return !lhs.Equals(rhs);
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Experimental/BleUuids.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Experimental
19 | {
20 | static class BleUuids
21 | {
22 | public static readonly BleUuid Cccd = new BleUuid(0x2902);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/FilteredDeviceList.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2016-2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 | using System.Linq;
21 | using System.Threading;
22 |
23 | namespace HidSharp
24 | {
25 | public class FilteredDeviceList : DeviceList
26 | {
27 | int _dirty;
28 | List> _areDriversBeingInstalled;
29 | Dictionary _refCounts;
30 |
31 | public FilteredDeviceList()
32 | {
33 | _areDriversBeingInstalled = new List>();
34 | _refCounts = new Dictionary();
35 | }
36 |
37 | /*
38 | public override BleDiscovery BeginBleDiscovery()
39 | {
40 | throw new NotImplementedException();
41 | }
42 | */
43 |
44 | public void Add(Device device)
45 | {
46 | Throw.If.Null(device, "device");
47 |
48 | lock (_refCounts)
49 | {
50 | IncrementRefCount(device);
51 | }
52 |
53 | RaiseChangedIfDirty();
54 | }
55 |
56 | public void Add(DeviceList deviceList)
57 | {
58 | Add(deviceList, device => true);
59 | }
60 |
61 | public void Add(DeviceList deviceList, DeviceFilter filter)
62 | {
63 | Throw.If.Null(deviceList, "deviceList").Null(filter, "filter");
64 |
65 | var oldDevices = new Device[0];
66 | Action updateDeviceList = () =>
67 | {
68 | var newDevices = deviceList.GetAllDevices(filter).ToArray();
69 |
70 | lock (_refCounts)
71 | {
72 | foreach (var newDevice in newDevices)
73 | {
74 | IncrementRefCount(newDevice);
75 | }
76 |
77 | foreach (var oldDevice in oldDevices)
78 | {
79 | DecrementRefCount(oldDevice);
80 | }
81 | }
82 |
83 | oldDevices = newDevices;
84 | RaiseChangedIfDirty();
85 | };
86 |
87 | _areDriversBeingInstalled.Add(() => deviceList.AreDriversBeingInstalled);
88 | deviceList.Changed += (sender, e) => updateDeviceList();
89 | updateDeviceList();
90 | }
91 |
92 | ///
93 | public override IEnumerable GetAllDevices()
94 | {
95 | lock (_refCounts)
96 | {
97 | return _refCounts.Keys.ToList();
98 | }
99 | }
100 |
101 | void IncrementRefCount(Device device)
102 | {
103 | if (_refCounts.ContainsKey(device))
104 | {
105 | _refCounts[device]++;
106 | }
107 | else
108 | {
109 | _refCounts[device] = 1; _dirty = 1;
110 | }
111 | }
112 |
113 | void DecrementRefCount(Device device)
114 | {
115 | if (--_refCounts[device] == 0)
116 | {
117 | _refCounts.Remove(device); _dirty = 1;
118 | }
119 | }
120 |
121 | void RaiseChangedIfDirty()
122 | {
123 | if (1 == Interlocked.CompareExchange(ref _dirty, 0, 1))
124 | {
125 | RaiseChanged();
126 | }
127 | }
128 |
129 | ///
130 | public override bool AreDriversBeingInstalled
131 | {
132 | get { return _areDriversBeingInstalled.Any(callback => callback()); }
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/HidDeviceLoader.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2010, 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections;
20 | using System.Collections.Generic;
21 | using System.ComponentModel;
22 | using System.Runtime.InteropServices;
23 |
24 | namespace HidSharp
25 | {
26 | ///
27 | [ComVisible(true), Guid("CD7CBD7D-7204-473c-AA2A-2B9622CFC6CC")]
28 | [Obsolete, EditorBrowsable(EditorBrowsableState.Never)]
29 | public class HidDeviceLoader
30 | {
31 | ///
32 | [Obsolete, EditorBrowsable(EditorBrowsableState.Never)]
33 | public HidDeviceLoader()
34 | {
35 |
36 | }
37 |
38 | ///
39 | [Obsolete, EditorBrowsable(EditorBrowsableState.Never)]
40 | public IEnumerable GetDevicesVB()
41 | {
42 | return DeviceList.Local.GetHidDevices();
43 | }
44 |
45 | ///
46 | [Obsolete, EditorBrowsable(EditorBrowsableState.Never)]
47 | public IEnumerable GetDevices()
48 | {
49 | return DeviceList.Local.GetHidDevices();
50 | }
51 |
52 | ///
53 | [Obsolete, EditorBrowsable(EditorBrowsableState.Never)]
54 | public IEnumerable GetDevices(int? vendorID = null, int? productID = null, int? productVersion = null, string serialNumber = null)
55 | {
56 | return DeviceList.Local.GetHidDevices(vendorID, productID, productVersion, serialNumber);
57 | }
58 |
59 | ///
60 | [Obsolete, EditorBrowsable(EditorBrowsableState.Never)]
61 | public HidDevice GetDeviceOrDefault(int? vendorID = null, int? productID = null, int? productVersion = null, string serialNumber = null)
62 | {
63 | return DeviceList.Local.GetHidDeviceOrNull(vendorID, productID, productVersion, serialNumber);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/HidSharp.NETStandard.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | true
6 | false
7 | HidSharp
8 | HidSharp
9 | ..\bin
10 | ..\bin\netstandard2.0\HidSharp.XML
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/HidStream.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2012-2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Runtime.InteropServices;
20 |
21 | #pragma warning disable 420
22 |
23 | namespace HidSharp
24 | {
25 | ///
26 | /// Communicates with a USB HID class device.
27 | ///
28 | [ComVisible(true), Guid("0C263D05-0D58-4c6c-AEA7-EB9E0C5338A2")]
29 | public abstract class HidStream : DeviceStream
30 | {
31 | ///
32 | protected HidStream(HidDevice device)
33 | : base(device)
34 | {
35 | ReadTimeout = 3000;
36 | WriteTimeout = 3000;
37 | }
38 |
39 | ///
40 | public override void Flush()
41 | {
42 |
43 | }
44 |
45 | ///
46 | /// Sends a Get Feature setup request.
47 | ///
48 | /// The buffer to fill. Place the Report ID in the first byte.
49 | public void GetFeature(byte[] buffer)
50 | {
51 | Throw.If.Null(buffer, "buffer");
52 | GetFeature(buffer, 0, buffer.Length);
53 | }
54 |
55 | ///
56 | /// Sends a Get Feature setup request.
57 | ///
58 | /// The buffer to fill. Place the Report ID in the byte at index .
59 | /// The index in the buffer to begin filling with data.
60 | /// The number of bytes in the feature request.
61 | public abstract void GetFeature(byte[] buffer, int offset, int count);
62 |
63 | ///
64 | /// Reads HID Input Reports.
65 | ///
66 | /// The data read.
67 | public byte[] Read()
68 | {
69 | byte[] buffer = new byte[Device.GetMaxInputReportLength()];
70 | int bytes = Read(buffer); Array.Resize(ref buffer, bytes);
71 | return buffer;
72 | }
73 |
74 | ///
75 | /// Reads HID Input Reports.
76 | ///
77 | /// The buffer to place the reports into.
78 | /// The number of bytes read.
79 | public int Read(byte[] buffer)
80 | {
81 | Throw.If.Null(buffer, "buffer");
82 | return Read(buffer, 0, buffer.Length);
83 | }
84 |
85 | ///
86 | /// Sends a Set Feature setup request.
87 | ///
88 | /// The buffer of data to send. Place the Report ID in the first byte.
89 | public void SetFeature(byte[] buffer)
90 | {
91 | Throw.If.Null(buffer, "buffer");
92 | SetFeature(buffer, 0, buffer.Length);
93 | }
94 |
95 | ///
96 | /// Sends a Set Feature setup request.
97 | ///
98 | /// The buffer of data to send. Place the Report ID in the byte at index .
99 | /// The index in the buffer to start the write from.
100 | /// The number of bytes in the feature request.
101 | public abstract void SetFeature(byte[] buffer, int offset, int count);
102 |
103 | ///
104 | /// Writes an HID Output Report to the device.
105 | ///
106 | /// The buffer containing the report. Place the Report ID in the first byte.
107 | public void Write(byte[] buffer)
108 | {
109 | Throw.If.Null(buffer, "buffer");
110 | Write(buffer, 0, buffer.Length);
111 | }
112 |
113 | ///
114 | /// Gets the associated with this stream.
115 | ///
116 | public new HidDevice Device
117 | {
118 | get { return (HidDevice)base.Device; }
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/ImplementationDetail.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp
21 | {
22 | ///
23 | /// Specifies the 's low-level implementation.
24 | ///
25 | public static class ImplementationDetail
26 | {
27 | ///
28 | /// The device is running on Windows.
29 | ///
30 | public static Guid Windows { get; private set; }
31 |
32 | ///
33 | /// The device is running on a Mac.
34 | ///
35 | public static Guid MacOS { get; private set; }
36 |
37 | ///
38 | /// The device is running on Linux.
39 | ///
40 | public static Guid Linux { get; private set; }
41 |
42 | ///
43 | /// The device is a Bluetooth Low Energy device.
44 | ///
45 | public static Guid BleDevice { get; private set; }
46 |
47 | ///
48 | /// The device is a HID device.
49 | ///
50 | public static Guid HidDevice { get; private set; }
51 |
52 | ///
53 | /// The device is a serial device.
54 | ///
55 | public static Guid SerialDevice { get; private set; }
56 |
57 | ///
58 | /// The device is implemented using the Linux hidraw API.
59 | ///
60 | public static Guid HidrawApi { get; private set; }
61 |
62 | static ImplementationDetail()
63 | {
64 | Windows = new Guid("{3540D886-E329-419F-8033-1D7355D53A7E}");
65 | MacOS = new Guid("{9FE992E5-F804-41B6-A35F-3B60F7CAC9E2}");
66 | Linux = new Guid("{A4123219-6BC8-49B7-84D3-699A66373109}");
67 |
68 | BleDevice = new Guid("{AAFD1479-29A0-42B8-A0A9-5C88A18B5504}");
69 | HidDevice = new Guid("{DFF209D7-131E-4958-8F47-C23DAC7B62DA}");
70 | SerialDevice = new Guid("{45A96DA9-AA48-4BF7-978D-A845F185F38C}");
71 |
72 | HidrawApi = new Guid("{1199D7C6-F99F-471F-9730-B16BA615938F}");
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/LocalDeviceList.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Collections.Generic;
19 |
20 | namespace HidSharp
21 | {
22 | sealed class LocalDeviceList : DeviceList
23 | {
24 | /*
25 | public override BleDiscovery BeginBleDiscovery()
26 | {
27 | return Platform.HidSelector.Instance.BeginBleDiscovery();
28 | }
29 | */
30 |
31 | public override IEnumerable GetDevices(DeviceTypes types)
32 | {
33 | return Platform.HidSelector.Instance.GetDevices(types);
34 | }
35 |
36 | public override IEnumerable GetAllDevices()
37 | {
38 | return GetDevices(DeviceTypes.Hid | DeviceTypes.Serial | DeviceTypes.Ble);
39 | }
40 |
41 | public override string ToString()
42 | {
43 | return Platform.HidSelector.Instance.FriendlyName; // This value is useful for debugging.
44 | }
45 |
46 | public override bool AreDriversBeingInstalled
47 | {
48 | get { return Platform.HidSelector.Instance.AreDriversBeingInstalled; }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/NOTICE.txt:
--------------------------------------------------------------------------------
1 | HIDSharp
2 | Copyright 2010-2019 James F. Bellinger
3 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/OpenConfiguration.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2016, 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 |
21 | namespace HidSharp
22 | {
23 | ///
24 | /// Describes all options for opening a device stream.
25 | ///
26 | public class OpenConfiguration : ICloneable
27 | {
28 | Dictionary _options;
29 |
30 | ///
31 | /// Initializes a new instance of the class.
32 | ///
33 | public OpenConfiguration()
34 | {
35 | _options = new Dictionary();
36 | }
37 |
38 | OpenConfiguration(Dictionary options)
39 | {
40 | _options = new Dictionary(options);
41 | }
42 |
43 | public OpenConfiguration Clone()
44 | {
45 | return new OpenConfiguration(_options);
46 | }
47 |
48 | object ICloneable.Clone()
49 | {
50 | return Clone();
51 | }
52 |
53 | ///
54 | /// Gets the current value of an option.
55 | ///
56 | /// The option.
57 | /// The option's value.
58 | public object GetOption(OpenOption option)
59 | {
60 | Throw.If.Null(option, "option");
61 |
62 | object value;
63 | return _options.TryGetValue(option, out value) ? value : option.DefaultValue;
64 | }
65 |
66 | ///
67 | /// Gets a list of all currently set options.
68 | ///
69 | /// The options list.
70 | public IEnumerable GetOptionsList()
71 | {
72 | return _options.Keys;
73 | }
74 |
75 | ///
76 | /// Checks if an option has been set.
77 | ///
78 | /// The option.
79 | /// true if the option has been set.
80 | public bool IsOptionSet(OpenOption option)
81 | {
82 | Throw.If.Null(option, "option");
83 |
84 | return _options.ContainsKey(option);
85 | }
86 |
87 | ///
88 | /// Sets the current value of an option.
89 | ///
90 | /// The option.
91 | /// The value to set it to.
92 | public void SetOption(OpenOption option, object value)
93 | {
94 | Throw.If.Null(option, "option");
95 |
96 | if (value != null)
97 | {
98 | _options[option] = value;
99 | }
100 | else
101 | {
102 | _options.Remove(option);
103 | }
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/OpenPriority.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2016 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp
19 | {
20 | ///
21 | /// The priority at which to open a device stream.
22 | ///
23 | public enum OpenPriority
24 | {
25 | ///
26 | /// The lowest priority.
27 | ///
28 | Idle = -2,
29 |
30 | ///
31 | /// Very low priority.
32 | ///
33 | VeryLow = -1,
34 |
35 | ///
36 | /// Low priority.
37 | ///
38 | Low = 0,
39 |
40 | ///
41 | /// The default priority.
42 | ///
43 | Normal = 1,
44 |
45 | ///
46 | /// High priority.
47 | ///
48 | High = 2,
49 |
50 | ///
51 | /// The highest priority.
52 | ///
53 | VeryHigh = 3
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/HidSelector.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2012-2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Threading;
19 |
20 | namespace HidSharp.Platform
21 | {
22 | sealed class HidSelector
23 | {
24 | public static readonly HidManager Instance;
25 | static readonly Thread ManagerThread;
26 |
27 | static HidSelector()
28 | {
29 | foreach (var hidManager in new HidManager[]
30 | {
31 | new Windows.WinHidManager(),
32 | new Linux.LinuxHidManager(),
33 | new MacOS.MacHidManager(),
34 | new Unsupported.UnsupportedHidManager()
35 | })
36 | {
37 | if (hidManager.IsSupported)
38 | {
39 | var readyEvent = new ManualResetEvent(false);
40 |
41 | Instance = hidManager;
42 | Instance.InitializeEventManager();
43 | ManagerThread = new Thread(Instance.RunImpl) { IsBackground = true, Name = "HID Manager" };
44 | ManagerThread.Start(readyEvent);
45 | readyEvent.WaitOne();
46 | break;
47 | }
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Libusb/LibusbHidManager.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2012 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Platform.Libusb
21 | {
22 | sealed class LibusbHidManager
23 | {
24 | // TODO
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Linux/LinuxSerialDevice.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017-2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Platform.Linux
21 | {
22 | sealed class LinuxSerialDevice : SerialDevice
23 | {
24 | string _portName;
25 |
26 | protected override DeviceStream OpenDeviceDirectly(OpenConfiguration openConfig)
27 | {
28 | return new LinuxSerialStream(this);
29 | }
30 |
31 | internal static LinuxSerialDevice TryCreate(string portName)
32 | {
33 | return new LinuxSerialDevice() { _portName = portName };
34 | }
35 |
36 | public override string GetFileSystemName()
37 | {
38 | return _portName;
39 | }
40 |
41 | public override bool HasImplementationDetail(Guid detail)
42 | {
43 | return base.HasImplementationDetail(detail) || detail == ImplementationDetail.Linux;
44 | }
45 |
46 | public override string DevicePath
47 | {
48 | get { return _portName; }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Linux/NativeMethodsLibudev.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2016 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Platform.Linux
21 | {
22 | abstract class NativeMethodsLibudev
23 | {
24 | static NativeMethodsLibudev()
25 | {
26 | foreach (var instance in new NativeMethodsLibudev[] { new NativeMethodsLibudev1(), new NativeMethodsLibudev0() })
27 | {
28 | try
29 | {
30 | IntPtr udev = instance.udev_new();
31 | if (IntPtr.Zero != udev)
32 | {
33 | instance.udev_unref(udev);
34 | Instance = instance; break;
35 | }
36 | }
37 | catch
38 | {
39 |
40 | }
41 | }
42 | }
43 |
44 | public static NativeMethodsLibudev Instance
45 | {
46 | get;
47 | private set;
48 | }
49 |
50 | public abstract string FriendlyName
51 | {
52 | get;
53 | }
54 |
55 | public abstract IntPtr udev_new();
56 |
57 | public abstract IntPtr udev_ref(IntPtr udev);
58 |
59 | public abstract void udev_unref(IntPtr udev);
60 |
61 | public abstract IntPtr udev_monitor_new_from_netlink(IntPtr udev, string name);
62 |
63 | public abstract void udev_monitor_unref(IntPtr monitor);
64 |
65 | public abstract int udev_monitor_filter_add_match_subsystem_devtype(IntPtr monitor, string subsystem, string devtype);
66 |
67 | public abstract int udev_monitor_enable_receiving(IntPtr monitor);
68 |
69 | public abstract int udev_monitor_get_fd(IntPtr monitor);
70 |
71 | public abstract IntPtr udev_monitor_receive_device(IntPtr monitor);
72 |
73 | public abstract IntPtr udev_enumerate_new(IntPtr udev);
74 |
75 | public abstract IntPtr udev_enumerate_ref(IntPtr enumerate);
76 |
77 | public abstract void udev_enumerate_unref(IntPtr enumerate);
78 |
79 | public abstract int udev_enumerate_add_match_subsystem(IntPtr enumerate, string subsystem);
80 |
81 | public abstract int udev_enumerate_scan_devices(IntPtr enumerate);
82 |
83 | public abstract IntPtr udev_enumerate_get_list_entry(IntPtr enumerate);
84 |
85 | public abstract IntPtr udev_list_entry_get_next(IntPtr entry);
86 |
87 | public abstract string udev_list_entry_get_name(IntPtr entry);
88 |
89 | public abstract IntPtr udev_device_new_from_syspath(IntPtr udev, string syspath);
90 |
91 | public abstract IntPtr udev_device_ref(IntPtr device);
92 |
93 | public abstract void udev_device_unref(IntPtr device);
94 |
95 | public abstract string udev_device_get_devnode(IntPtr device);
96 |
97 | public abstract IntPtr udev_device_get_parent_with_subsystem_devtype(IntPtr device, string subsystem, string devtype);
98 |
99 | public abstract string udev_device_get_sysattr_value(IntPtr device, string sysattr);
100 |
101 | public abstract int udev_device_get_is_initialized(IntPtr device);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/MacOS/MacSerialDevice.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Platform.MacOS
21 | {
22 | sealed class MacSerialDevice : SerialDevice
23 | {
24 | NativeMethods.io_string_t _path;
25 | string _fileSystemName;
26 |
27 | protected override DeviceStream OpenDeviceDirectly(OpenConfiguration openConfig)
28 | {
29 | return new MacSerialStream(this);
30 | }
31 |
32 | internal static MacSerialDevice TryCreate(NativeMethods.io_string_t path)
33 | {
34 | var d = new MacSerialDevice() { _path = path };
35 |
36 | var handle = NativeMethods.IORegistryEntryFromPath(0, ref path).ToIOObject();
37 | if (!handle.IsSet) { return null; }
38 |
39 | using (handle)
40 | {
41 | d._fileSystemName = NativeMethods.IORegistryEntryGetCFProperty_String(handle, NativeMethods.kIOCalloutDeviceKey);
42 | if (d._fileSystemName == null) { return null; }
43 | }
44 |
45 | return d;
46 | }
47 |
48 | public override string GetFileSystemName()
49 | {
50 | return _fileSystemName;
51 | }
52 |
53 | public override bool HasImplementationDetail(Guid detail)
54 | {
55 | return base.HasImplementationDetail(detail) || detail == ImplementationDetail.MacOS;
56 | }
57 |
58 | public override string DevicePath
59 | {
60 | get { return _path.ToString(); }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/SysBleStream.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2012-2013, 2016, 2018-2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Platform
19 | {
20 | abstract class SysBleStream : Experimental.BleStream
21 | {
22 | internal SysBleStream(Experimental.BleDevice device, Experimental.BleService service)
23 | : base(device, service)
24 | {
25 |
26 | }
27 |
28 | #region Reference Counting
29 | SysRefCountHelper _rch;
30 |
31 | internal void HandleInitAndOpen()
32 | {
33 | _rch.HandleInitAndOpen();
34 | }
35 |
36 | internal bool HandleClose()
37 | {
38 | return _rch.HandleClose();
39 | }
40 |
41 | internal bool HandleAcquire()
42 | {
43 | return _rch.HandleAcquire();
44 | }
45 |
46 | internal void HandleAcquireIfOpenOrFail()
47 | {
48 | _rch.HandleAcquireIfOpenOrFail();
49 | }
50 |
51 | internal void HandleRelease()
52 | {
53 | if (_rch.HandleRelease()) { HandleFree(); }
54 | }
55 |
56 | internal abstract void HandleFree();
57 | #endregion
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/SysRefCountHelper.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2012-2013, 2016, 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 | using System.Linq;
21 | using System.Text;
22 | using System.Threading;
23 |
24 | namespace HidSharp.Platform
25 | {
26 | struct SysRefCountHelper
27 | {
28 | int _opened, _closed;
29 | int _refCount;
30 |
31 | internal void HandleInitAndOpen()
32 | {
33 | _opened = 1; _refCount = 1;
34 | }
35 |
36 | internal bool HandleClose()
37 | {
38 | return 0 == Interlocked.CompareExchange(ref _closed, 1, 0) && _opened != 0;
39 | }
40 |
41 | internal bool HandleAcquire()
42 | {
43 | while (true)
44 | {
45 | int refCount = _refCount;
46 | if (refCount == 0) { return false; }
47 |
48 | if (refCount == Interlocked.CompareExchange
49 | (ref _refCount, refCount + 1, refCount))
50 | {
51 | return true;
52 | }
53 | }
54 | }
55 |
56 | internal void HandleAcquireIfOpenOrFail()
57 | {
58 | if (_closed != 0 || !HandleAcquire()) { throw ExceptionForClosed(); }
59 | }
60 |
61 | internal bool HandleRelease()
62 | {
63 | if (0 == Interlocked.Decrement(ref _refCount))
64 | {
65 | if (_opened != 0) { return true; }
66 | }
67 |
68 | return false;
69 | }
70 |
71 | internal void ThrowIfClosed()
72 | {
73 | if (_closed != 0) { throw ExceptionForClosed(); }
74 | }
75 |
76 | static Exception ExceptionForClosed()
77 | {
78 | return CommonException.CreateClosedException();
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/SysSerialStream.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 | using System.IO;
21 | using System.Threading;
22 |
23 | namespace HidSharp.Platform
24 | {
25 | abstract class SysSerialStream : SerialStream
26 | {
27 | protected SysSerialStream(SerialDevice device)
28 | : base(device)
29 | {
30 |
31 | }
32 |
33 | #region Reference Counting
34 | int _opened, _closed;
35 | int _refCount;
36 |
37 | internal void HandleInitAndOpen()
38 | {
39 | _opened = 1; _refCount = 1;
40 | }
41 |
42 | internal bool HandleClose()
43 | {
44 | return 0 == Interlocked.CompareExchange(ref _closed, 1, 0) && _opened != 0;
45 | }
46 |
47 | internal bool HandleAcquire()
48 | {
49 | while (true)
50 | {
51 | int refCount = _refCount;
52 | if (refCount == 0) { return false; }
53 |
54 | if (refCount == Interlocked.CompareExchange
55 | (ref _refCount, refCount + 1, refCount))
56 | {
57 | return true;
58 | }
59 | }
60 | }
61 |
62 | internal void HandleAcquireIfOpenOrFail()
63 | {
64 | if (_closed != 0 || !HandleAcquire()) { throw ExceptionForClosed(); }
65 | }
66 |
67 | internal void HandleRelease()
68 | {
69 | if (0 == Interlocked.Decrement(ref _refCount))
70 | {
71 | if (_opened != 0) { HandleFree(); }
72 | }
73 | }
74 |
75 | static Exception ExceptionForClosed()
76 | {
77 | return CommonException.CreateClosedException();
78 | }
79 |
80 | internal abstract void HandleFree();
81 | #endregion
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Unsupported/UnsupportedHidManager.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2012 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Platform.Unsupported
21 | {
22 | sealed class UnsupportedHidManager : HidManager
23 | {
24 | protected override object[] GetBleDeviceKeys()
25 | {
26 | return new object[0];
27 | }
28 |
29 | protected override object[] GetHidDeviceKeys()
30 | {
31 | return new object[0];
32 | }
33 |
34 | protected override object[] GetSerialDeviceKeys()
35 | {
36 | return new object[0];
37 | }
38 |
39 | protected override bool TryCreateBleDevice(object key, out Device device)
40 | {
41 | throw new NotImplementedException();
42 | }
43 |
44 | protected override bool TryCreateHidDevice(object key, out Device device)
45 | {
46 | throw new NotImplementedException();
47 | }
48 |
49 | protected override bool TryCreateSerialDevice(object key, out Device device)
50 | {
51 | throw new NotImplementedException();
52 | }
53 |
54 | public override string FriendlyName
55 | {
56 | get { return "Platform Not Supported"; }
57 | }
58 |
59 | public override bool IsSupported
60 | {
61 | get { return true; }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Utf8Marshaler.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2012 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 | using System.Reflection;
21 | using System.Runtime.InteropServices;
22 | using System.Text;
23 |
24 | namespace HidSharp.Platform
25 | {
26 | sealed class Utf8Marshaler : ICustomMarshaler
27 | {
28 | [ThreadStatic]
29 | static HashSet _allocations; // Workaround for Mono bug 4722.
30 |
31 | static HashSet GetAllocations()
32 | {
33 | if (_allocations == null) { _allocations = new HashSet(); }
34 | return _allocations;
35 | }
36 |
37 | public void CleanUpManagedData(object obj)
38 | {
39 |
40 | }
41 |
42 | public void CleanUpNativeData(IntPtr ptr)
43 | {
44 | var allocations = GetAllocations();
45 | if (IntPtr.Zero == ptr || !allocations.Contains(ptr)) { return; }
46 | Marshal.FreeHGlobal(ptr); allocations.Remove(ptr);
47 | }
48 |
49 | public int GetNativeDataSize()
50 | {
51 | return -1;
52 | }
53 |
54 | public IntPtr MarshalManagedToNative(object obj)
55 | {
56 | string str = obj as string;
57 | if (str == null) { return IntPtr.Zero; }
58 |
59 | byte[] bytes = Encoding.UTF8.GetBytes(str);
60 | IntPtr ptr = Marshal.AllocHGlobal(bytes.Length + 1);
61 | Marshal.Copy(bytes, 0, ptr, bytes.Length);
62 | Marshal.WriteByte(ptr, bytes.Length, 0);
63 |
64 | var allocations = GetAllocations();
65 | allocations.Add(ptr); return ptr;
66 | }
67 |
68 | public object MarshalNativeToManaged(IntPtr ptr)
69 | {
70 | if (ptr == IntPtr.Zero) { return null; }
71 |
72 | int length;
73 | for (length = 0; Marshal.ReadByte(ptr, length) != 0; length++) ;
74 |
75 | byte[] bytes = new byte[length];
76 | Marshal.Copy(ptr, bytes, 0, bytes.Length);
77 | string str = Encoding.UTF8.GetString(bytes);
78 | return str;
79 | }
80 |
81 | // This method needs to keep its original name.
82 | [Obfuscation(Exclude = true)]
83 | public static ICustomMarshaler GetInstance(string cookie)
84 | {
85 | return new Utf8Marshaler();
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Windows/WinBleCharacteristic.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using HidSharp.Experimental;
20 |
21 | namespace HidSharp.Platform.Windows
22 | {
23 | sealed class WinBleCharacteristic : Experimental.BleCharacteristic
24 | {
25 | internal NativeMethods.BTH_LE_GATT_CHARACTERISTIC NativeData;
26 |
27 | internal WinBleDescriptor[] _characteristicDescriptors;
28 | BleCharacteristicProperties _properties;
29 |
30 | public WinBleCharacteristic(NativeMethods.BTH_LE_GATT_CHARACTERISTIC nativeData)
31 | {
32 | NativeData = nativeData;
33 |
34 | _properties = (nativeData.IsBroadcastable != 0 ? BleCharacteristicProperties.Broadcast : 0)
35 | | (nativeData.IsReadable != 0 ? BleCharacteristicProperties.Read : 0)
36 | | (nativeData.IsWritableWithoutResponse != 0 ? BleCharacteristicProperties.WriteWithoutResponse : 0)
37 | | (nativeData.IsWritable != 0 ? BleCharacteristicProperties.Write : 0)
38 | | (nativeData.IsNotifiable != 0 ? BleCharacteristicProperties.Notify : 0)
39 | | (nativeData.IsIndicatable != 0 ? BleCharacteristicProperties.Indicate : 0)
40 | | (nativeData.IsSignedWritable != 0 ? BleCharacteristicProperties.SignedWrite : 0)
41 | | (nativeData.HasExtendedProperties != 0 ? BleCharacteristicProperties.ExtendedProperties : 0)
42 | ;
43 | }
44 |
45 | public override BleDescriptor[] GetDescriptors()
46 | {
47 | return (BleDescriptor[])_characteristicDescriptors.Clone();
48 | }
49 |
50 | public override BleUuid Uuid
51 | {
52 | get { return NativeData.CharacteristicUuid.ToGuid(); }
53 | }
54 |
55 | public override BleCharacteristicProperties Properties
56 | {
57 | get { return _properties; }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Windows/WinBleDescriptor.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using HidSharp.Experimental;
20 |
21 | namespace HidSharp.Platform.Windows
22 | {
23 | sealed class WinBleDescriptor : BleDescriptor
24 | {
25 | internal NativeMethods.BTH_LE_GATT_DESCRIPTOR NativeData;
26 |
27 | public WinBleDescriptor(NativeMethods.BTH_LE_GATT_DESCRIPTOR nativeData)
28 | {
29 | NativeData = nativeData;
30 | }
31 |
32 | public override BleUuid Uuid
33 | {
34 | get { return NativeData.DescriptorUuid.ToGuid(); }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Windows/WinBleService.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Collections.Generic;
19 | using HidSharp.Experimental;
20 |
21 | namespace HidSharp.Platform.Windows
22 | {
23 | sealed class WinBleService : BleService
24 | {
25 | internal NativeMethods.BTH_LE_GATT_SERVICE NativeData;
26 |
27 | WinBleCharacteristic[] _characteristics;
28 | WinBleDevice _device;
29 | object _syncObject;
30 |
31 | public WinBleService(WinBleDevice device, NativeMethods.BTH_LE_GATT_SERVICE nativeData)
32 | {
33 | _device = device; NativeData = nativeData; _syncObject = new object();
34 | }
35 |
36 | public override BleCharacteristic[] GetCharacteristics()
37 | {
38 | lock (_syncObject)
39 | {
40 | if (_characteristics == null)
41 | {
42 | if (!_device.TryOpenToGetInfo(handle =>
43 | {
44 | var nativeCharacteristics = NativeMethods.BluetoothGATTGetCharacteristics(handle, ref NativeData);
45 | if (nativeCharacteristics == null) { return false; }
46 |
47 | var characteristics = new List();
48 | foreach (var nativeCharacteristic in nativeCharacteristics)
49 | {
50 | var characteristic = new WinBleCharacteristic(nativeCharacteristic);
51 | characteristics.Add(characteristic);
52 |
53 | var nativeDescriptors = NativeMethods.BluetoothGATTGetDescriptors(handle, ref characteristic.NativeData);
54 | if (nativeDescriptors == null) { return false; }
55 |
56 | var descriptors = new List();
57 | foreach (var nativeDescriptor in nativeDescriptors)
58 | {
59 | var descriptor = new WinBleDescriptor(nativeDescriptor);
60 | descriptors.Add(descriptor);
61 | }
62 |
63 | characteristic._characteristicDescriptors = descriptors.ToArray();
64 | }
65 |
66 | _characteristics = characteristics.ToArray();
67 | return true;
68 | }))
69 | {
70 | throw DeviceException.CreateIOException(_device, "BLE service information could not be retrieved.");
71 | }
72 | }
73 | }
74 |
75 | return (BleCharacteristic[])_characteristics.Clone();
76 | }
77 |
78 | public override BleDevice Device
79 | {
80 | get { return _device; }
81 | }
82 |
83 | public override BleUuid Uuid
84 | {
85 | get { return NativeData.ServiceUuid.ToGuid(); }
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Windows/WinHidDevice.ReportDescriptorBuilder.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 | using System.IO;
21 | using System.Linq;
22 | using HidSharp.Reports;
23 | using HidSharp.Reports.Encodings;
24 |
25 | namespace HidSharp.Platform.Windows
26 | {
27 | partial class WinHidDevice
28 | {
29 | sealed class ReportDescriptorBuilder
30 | {
31 | Dictionary _globals;
32 | List _items;
33 |
34 | public ReportDescriptorBuilder()
35 | {
36 | _globals = new Dictionary();
37 | _items = new List();
38 | }
39 |
40 | public void AddGlobalItem(GlobalItemTag globalItemTag, uint dataValue)
41 | {
42 | uint oldDataValue;
43 | if (_globals.TryGetValue(globalItemTag, out oldDataValue) && oldDataValue == dataValue) { return; }
44 | _globals[globalItemTag] = dataValue;
45 |
46 | var item = new EncodedItem() { ItemType = ItemType.Global, TagForGlobal = globalItemTag, DataValue = dataValue };
47 | _items.Add(item);
48 | }
49 |
50 | public void AddGlobalItemSigned(GlobalItemTag globalItemTag, int dataValue)
51 | {
52 | uint oldDataValue;
53 | if (_globals.TryGetValue(globalItemTag, out oldDataValue) && oldDataValue == (uint)dataValue) { return; }
54 | _globals[globalItemTag] = (uint)dataValue;
55 |
56 | var item = new EncodedItem() { ItemType = ItemType.Global, TagForGlobal = globalItemTag, DataValueSigned = dataValue };
57 | _items.Add(item);
58 | }
59 |
60 | public void AddLocalItem(LocalItemTag localItemTag, uint dataValue)
61 | {
62 | _items.Add(new EncodedItem() { ItemType = ItemType.Local, TagForLocal = localItemTag, DataValue = dataValue });
63 | }
64 |
65 | public void AddMainItem(MainItemTag mainItemTag, uint dataValue)
66 | {
67 | _items.Add(new EncodedItem() { ItemType = ItemType.Main, TagForMain = mainItemTag, DataValue = dataValue });
68 | }
69 |
70 | public byte[] GetReportDescriptor()
71 | {
72 | var bytes = new List();
73 | EncodedItem.EncodeItems(_items, bytes);
74 | return bytes.ToArray();
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Platform/Windows/WinSerialDevice.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017-2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Platform.Windows
19 | {
20 | sealed class WinSerialDevice : SerialDevice
21 | {
22 | string _path;
23 | string _fileSystemName;
24 | string _friendlyName;
25 |
26 | protected override DeviceStream OpenDeviceDirectly(OpenConfiguration openConfig)
27 | {
28 | var stream = new WinSerialStream(this);
29 | stream.Init(DevicePath);
30 | return stream;
31 | }
32 |
33 | internal static WinSerialDevice TryCreate(string portName, string fileSystemName, string friendlyName)
34 | {
35 | return new WinSerialDevice() { _path = portName, _fileSystemName = fileSystemName, _friendlyName = friendlyName };
36 | }
37 |
38 | public override string GetFileSystemName()
39 | {
40 | return _fileSystemName;
41 | }
42 |
43 | public override string GetFriendlyName()
44 | {
45 | return _friendlyName;
46 | }
47 |
48 | public override string DevicePath
49 | {
50 | get { return _path; }
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | [assembly: AssemblyCompany("Illusory Studios LLC")]
5 | [assembly: AssemblyCopyright("Copyright © 2010-2019 James F. Bellinger ")]
6 | [assembly: AssemblyDescription("C# HID wrappers")]
7 | [assembly: AssemblyProduct("HidSharp")]
8 | [assembly: AssemblyTitle("HidSharp")]
9 | [assembly: AssemblyVersion("2.1.0.0")]
10 | [assembly: AssemblyFileVersion("2.1.0.0")]
11 | [assembly: AssemblyInformationalVersion("2.1.0")]
12 |
13 | [assembly: ComVisible(false)]
14 | [assembly: Guid("1b874372-4c6c-4acb-9f4a-906f6738cff9")]
15 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/DataConvert.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Reports
21 | {
22 | public static class DataConvert
23 | {
24 | public static int LogicalFromPhysical(DataItem item, double physicalValue)
25 | {
26 | Throw.If.Null(item);
27 | if (item.IsArray) { return (physicalValue > 0) ? 1 : 0; }
28 | return LogicalFromCustom(item, physicalValue, item.PhysicalMinimum, item.PhysicalMaximum);
29 | }
30 |
31 | public static int LogicalFromCustom(DataItem item, double physicalValue, double minimum, double maximum)
32 | {
33 | return Math.Max(item.LogicalMinimum, Math.Min(item.LogicalMaximum, (int)Math.Round((physicalValue - minimum) * item.LogicalRange / (maximum - minimum))));
34 | }
35 |
36 | public static int LogicalFromRaw(DataItem item, uint value)
37 | {
38 | Throw.If.Null(item);
39 | uint signBit = 1u << (item.ElementBits - 1), mask = signBit - 1;
40 | return (value & signBit) != 0 ? (int)(value | ~mask) : (int)value;
41 | }
42 |
43 | public static int DataIndexFromLogical(DataItem item, int logicalValue)
44 | {
45 | Throw.If.Null(item);
46 | if (!item.IsArray) { throw new ArgumentException("Data item is not an array.", "item"); }
47 | return IsLogicalOutOfRange(item, logicalValue) ? -1 : logicalValue - item.LogicalMinimum;
48 | }
49 |
50 | public static double PhysicalFromLogical(DataItem item, int logicalValue)
51 | {
52 | Throw.If.Null(item);
53 | if (item.IsArray) { return (logicalValue > 0) ? 1 : 0; }
54 | return CustomFromLogical(item, logicalValue, item.PhysicalMinimum, item.PhysicalRange);
55 | }
56 |
57 | public static double CustomFromLogical(DataItem item, int logicalValue, double minimum, double maximum)
58 | {
59 | if (IsLogicalOutOfRange(item, logicalValue)) { return double.NaN; }
60 | return minimum + (logicalValue - item.LogicalMinimum) * (maximum - minimum) / item.LogicalRange;
61 | }
62 |
63 | public static uint RawFromLogical(DataItem item, int value)
64 | {
65 | Throw.If.Null(item);
66 | uint usValue = (uint)value;
67 | uint signBit = 1u << (item.ElementBits - 1), mask = signBit - 1;
68 | return (usValue & mask) | (value < 0 ? signBit : 0);
69 | }
70 |
71 | public static bool IsLogicalOutOfRange(DataItem item, int logicalValue)
72 | {
73 | Throw.If.Null(item);
74 | return item.IsLogicalSigned
75 | ? (logicalValue < item.LogicalMinimum || logicalValue > item.LogicalMaximum)
76 | : ((uint)logicalValue < (uint)item.LogicalMinimum || (uint)logicalValue > (uint)item.LogicalMaximum)
77 | ;
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/DataItemFlags.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Reports
21 | {
22 | [Flags]
23 | public enum DataItemFlags : uint
24 | {
25 | ///
26 | /// No flags are set.
27 | ///
28 | None = 0,
29 |
30 | ///
31 | /// Constant values cannot be changed.
32 | ///
33 | Constant = 1 << 0,
34 |
35 | ///
36 | /// Each variable field corresponds to a particular value.
37 | /// The alternative is an array, where each field specifies an index.
38 | /// For example, with eight buttons, a variable field would have eight bits.
39 | /// An array would have an index of which button is pressed.
40 | ///
41 | Variable = 1 << 1,
42 |
43 | ///
44 | /// Mouse motion is in relative coordinates.
45 | /// Most sensors -- joysticks, accelerometers, etc. -- output absolute coordinates.
46 | ///
47 | Relative = 1 << 2,
48 |
49 | ///
50 | /// The value wraps around in a continuous manner.
51 | ///
52 | Wrap = 1 << 3,
53 |
54 | Nonlinear = 1 << 4,
55 |
56 | NoPreferred = 1 << 5,
57 |
58 | NullState = 1 << 6,
59 |
60 | Volatile = 1 << 7,
61 |
62 | BufferedBytes = 1 << 8
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/DataValue.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Collections.Generic;
19 | using System.Linq;
20 |
21 | namespace HidSharp.Reports
22 | {
23 | public struct DataValue
24 | {
25 | int _logicalValue;
26 |
27 | public int GetLogicalValue()
28 | {
29 | return _logicalValue;
30 | }
31 |
32 | public void SetLogicalValue(int logicalValue)
33 | {
34 | _logicalValue = logicalValue;
35 | }
36 |
37 | public double GetFractionalValue()
38 | {
39 | return GetScaledValue(0, 1);
40 | }
41 |
42 | public double GetScaledValue(double minimum, double maximum)
43 | {
44 | return DataConvert.CustomFromLogical(DataItem, GetLogicalValue(), minimum, maximum);
45 | }
46 |
47 | public double GetPhysicalValue()
48 | {
49 | return DataConvert.PhysicalFromLogical(DataItem, GetLogicalValue());
50 | }
51 |
52 | public DataItem DataItem
53 | {
54 | get;
55 | set;
56 | }
57 |
58 | public int DataIndex
59 | {
60 | get;
61 | set;
62 | }
63 |
64 | public bool IsNull
65 | {
66 | get { return !IsValid || (DataItem.IsVariable && DataConvert.IsLogicalOutOfRange(DataItem, GetLogicalValue())); }
67 | }
68 |
69 | public bool IsValid
70 | {
71 | get { return DataItem != null; }
72 | }
73 |
74 | public Report Report
75 | {
76 | get { return IsValid ? DataItem.Report : null; }
77 | }
78 |
79 | public IEnumerable Designators
80 | {
81 | get { return IsValid ? DataItem.Designators.GetValuesFromIndex(DataIndex) : Enumerable.Empty(); }
82 | }
83 |
84 | public IEnumerable Strings
85 | {
86 | get { return IsValid ? DataItem.Strings.GetValuesFromIndex(DataIndex) : Enumerable.Empty(); }
87 | }
88 |
89 | public IEnumerable Usages
90 | {
91 | get { return IsValid ? DataItem.Usages.GetValuesFromIndex(DataIndex) : Enumerable.Empty(); }
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/DescriptorCollectionItem.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 | using System.Collections.ObjectModel;
21 | using System.Diagnostics;
22 | using HidSharp.Reports.Encodings;
23 |
24 | namespace HidSharp.Reports
25 | {
26 | public class DescriptorCollectionItem : DescriptorItem
27 | {
28 | ReportCollectionItemChildren _children;
29 |
30 | public DescriptorCollectionItem()
31 | {
32 | _children = new ReportCollectionItemChildren(this);
33 | }
34 |
35 | public override IList ChildItems
36 | {
37 | get { return _children; }
38 | }
39 |
40 | public CollectionType CollectionType
41 | {
42 | get;
43 | set;
44 | }
45 |
46 | #region ReportCollectionItemChildren
47 | sealed class ReportCollectionItemChildren : Collection
48 | {
49 | DescriptorCollectionItem _item;
50 |
51 | public ReportCollectionItemChildren(DescriptorCollectionItem item)
52 | {
53 | Debug.Assert(item != null);
54 | _item = item;
55 | }
56 |
57 | protected override void ClearItems()
58 | {
59 | foreach (var item in this) { item.ParentItem = null; }
60 | base.ClearItems();
61 | }
62 |
63 | protected override void InsertItem(int index, DescriptorItem item)
64 | {
65 | Throw.If.Null(item).False(item.ParentItem == null);
66 | item.ParentItem = _item;
67 | base.InsertItem(index, item);
68 | }
69 |
70 | protected override void RemoveItem(int index)
71 | {
72 | this[index].ParentItem = null;
73 | base.RemoveItem(index);
74 | }
75 |
76 | protected override void SetItem(int index, DescriptorItem item)
77 | {
78 | throw new NotImplementedException();
79 | }
80 | }
81 | #endregion
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/DescriptorItem.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Collections.Generic;
19 | using System.Collections.ObjectModel;
20 |
21 | namespace HidSharp.Reports
22 | {
23 | public class DescriptorItem
24 | {
25 | static readonly IList _noChildren = new ReadOnlyCollection(new DescriptorItem[0]);
26 |
27 | Indexes _designator, _string, _usage;
28 |
29 | public DescriptorItem()
30 | {
31 |
32 | }
33 |
34 | public virtual IList ChildItems
35 | {
36 | get { return _noChildren; }
37 | }
38 |
39 | public DescriptorCollectionItem ParentItem
40 | {
41 | get;
42 | internal set;
43 | }
44 |
45 | public Indexes Designators
46 | {
47 | get { return _designator ?? Indexes.Unset; }
48 | set { _designator = value; }
49 | }
50 |
51 | public Indexes Strings
52 | {
53 | get { return _string ?? Indexes.Unset; }
54 | set { _string = value; }
55 | }
56 |
57 | public Indexes Usages
58 | {
59 | get { return _usage ?? Indexes.Unset; }
60 | set { _usage = value; }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/DeviceItem.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 | using System.Collections.ObjectModel;
21 | using System.Diagnostics;
22 | using System.Linq;
23 |
24 | namespace HidSharp.Reports
25 | {
26 | public class DeviceItem : DescriptorCollectionItem
27 | {
28 | ReportCollectionItemReports _reports;
29 |
30 | public DeviceItem()
31 | {
32 | _reports = new ReportCollectionItemReports(this);
33 | }
34 |
35 | ///
36 | /// Creates a appropriate for parsing reports for this device item.
37 | ///
38 | /// The new .
39 | ///
40 | /// Pair this with a for the .
41 | ///
42 | public Input.DeviceItemInputParser CreateDeviceItemInputParser()
43 | {
44 | return new Input.DeviceItemInputParser(this);
45 | }
46 |
47 | public IList Reports
48 | {
49 | get { return _reports; }
50 | }
51 |
52 | public IEnumerable InputReports
53 | {
54 | get { return Reports.Where(report => report.ReportType == ReportType.Input); }
55 | }
56 |
57 | public IEnumerable OutputReports
58 | {
59 | get { return Reports.Where(report => report.ReportType == ReportType.Output); }
60 | }
61 |
62 | public IEnumerable FeatureReports
63 | {
64 | get { return Reports.Where(report => report.ReportType == ReportType.Feature); }
65 | }
66 |
67 | #region ReportCollectionItemReports
68 | sealed class ReportCollectionItemReports : Collection
69 | {
70 | DeviceItem _item;
71 |
72 | public ReportCollectionItemReports(DeviceItem item)
73 | {
74 | Debug.Assert(item != null);
75 | _item = item;
76 | }
77 |
78 | protected override void ClearItems()
79 | {
80 | foreach (var item in this) { item.DeviceItem = null; }
81 | base.ClearItems();
82 | }
83 |
84 | protected override void InsertItem(int index, Report item)
85 | {
86 | Throw.If.Null(item).False(item.DeviceItem == null);
87 | item.DeviceItem = _item;
88 | base.InsertItem(index, item);
89 | }
90 |
91 | protected override void RemoveItem(int index)
92 | {
93 | this[index].DeviceItem = null;
94 | base.RemoveItem(index);
95 | }
96 |
97 | protected override void SetItem(int index, Report item)
98 | {
99 | throw new NotImplementedException();
100 | }
101 | }
102 | #endregion
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Encodings/CollectionType.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Encodings
19 | {
20 | public enum CollectionType : byte
21 | {
22 | Physical = 0,
23 | Application,
24 | Logical,
25 | Report,
26 | NamedArray,
27 | UsageSwitch,
28 | UsageModifier
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Encodings/GlobalItemTag.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Encodings
19 | {
20 | public enum GlobalItemTag : byte
21 | {
22 | UsagePage = 0,
23 | LogicalMinimum,
24 | LogicalMaximum,
25 | PhysicalMinimum,
26 | PhysicalMaximum,
27 | UnitExponent,
28 | Unit,
29 | ReportSize,
30 | ReportID,
31 | ReportCount,
32 | Push,
33 | Pop
34 | }
35 | }
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Encodings/ItemType.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Encodings
19 | {
20 | ///
21 | /// Describes the manner in which an item affects the descriptor.
22 | ///
23 | public enum ItemType : byte
24 | {
25 | ///
26 | /// Main items determine the report being described.
27 | /// For example, a main item switches between Input and Output reports.
28 | ///
29 | Main = 0,
30 |
31 | ///
32 | /// Global items affect all reports later in the descriptor.
33 | ///
34 | Global,
35 |
36 | ///
37 | /// Local items only affect the current report.
38 | ///
39 | Local,
40 |
41 | ///
42 | /// Long items use this type.
43 | ///
44 | Reserved
45 | }
46 | }
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Encodings/LocalItemTag.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Encodings
19 | {
20 | public enum LocalItemTag : byte
21 | {
22 | Usage = 0,
23 | UsageMinimum,
24 | UsageMaximum,
25 | DesignatorIndex,
26 | DesignatorMinimum,
27 | DesignatorMaximum,
28 | StringIndex = 7,
29 | StringMinimum,
30 | StringMaximum,
31 | Delimiter
32 | }
33 | }
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Encodings/MainItemTag.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Encodings
19 | {
20 | public enum MainItemTag : byte
21 | {
22 | Input = 8,
23 | Output,
24 | Collection,
25 | Feature,
26 | EndCollection
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/ExpectedUsageType.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports
19 | {
20 | public enum ExpectedUsageType
21 | {
22 | ///
23 | /// Level-triggered. A momentary button. 0 indicates not pressed, 1 indicates pressed.
24 | ///
25 | PushButton = 1,
26 |
27 | ///
28 | /// Level-triggered. Toggle buttons maintain their state. 0 indicates not pressed, 1 indicates pressed.
29 | ///
30 | ToggleButton,
31 |
32 | ///
33 | /// Edge-triggered. A 0-to-1 transition should activate the one-shot function.
34 | ///
35 | OneShot,
36 |
37 | ///
38 | /// Edge-triggered. Each report of -1 goes down. Each report of 1 goes up.
39 | ///
40 | UpDown
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/IndexList.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Collections.Generic;
19 |
20 | namespace HidSharp.Reports
21 | {
22 | public class IndexList : Indexes
23 | {
24 | public IndexList()
25 | {
26 | Indices = new List>();
27 | }
28 |
29 | public override bool TryGetIndexFromValue(uint value, out int index)
30 | {
31 | for (int i = 0; i < Indices.Count; i ++)
32 | {
33 | foreach (uint thisValue in Indices[i])
34 | {
35 | if (thisValue == value) { index = i; return true; }
36 | }
37 | }
38 |
39 | return base.TryGetIndexFromValue(value, out index);
40 | }
41 |
42 | public override IEnumerable GetValuesFromIndex(int index)
43 | {
44 | if (index < 0 || index >= Count) { yield break; }
45 | foreach (uint value in Indices[index]) { yield return value; }
46 | }
47 |
48 | public override int Count
49 | {
50 | get { return Indices.Count; }
51 | }
52 |
53 | public IList> Indices
54 | {
55 | get;
56 | private set;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/IndexRange.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Collections.Generic;
19 |
20 | namespace HidSharp.Reports
21 | {
22 | public class IndexRange : Indexes
23 | {
24 | public IndexRange()
25 | {
26 |
27 | }
28 |
29 | public IndexRange(uint minimum, uint maximum)
30 | {
31 | Minimum = minimum; Maximum = maximum;
32 | }
33 |
34 | public override bool TryGetIndexFromValue(uint value, out int index)
35 | {
36 | if (value >= Minimum && value <= Maximum)
37 | {
38 | index = (int)(value - Minimum); return true;
39 | }
40 |
41 | return base.TryGetIndexFromValue(value, out index);
42 | }
43 |
44 | public override IEnumerable GetValuesFromIndex(int index)
45 | {
46 | if (index < 0 || index >= Count) { yield break; }
47 | yield return (uint)(Minimum + index);
48 | }
49 |
50 | public override int Count
51 | {
52 | get { return (int)(Maximum - Minimum + 1); }
53 | }
54 |
55 | public uint Minimum
56 | {
57 | get;
58 | set;
59 | }
60 |
61 | public uint Maximum
62 | {
63 | get;
64 | set;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Indexes.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Collections.Generic;
19 | using System.Linq;
20 |
21 | namespace HidSharp.Reports
22 | {
23 | public class Indexes
24 | {
25 | static readonly Indexes _unset = new Indexes();
26 |
27 | public bool ContainsValue(uint value)
28 | {
29 | int index; return TryGetIndexFromValue(value, out index);
30 | }
31 |
32 | public IEnumerable GetAllValues()
33 | {
34 | return Enumerable.Range(0, Count).SelectMany(index => GetValuesFromIndex(index));
35 | }
36 |
37 | public virtual bool TryGetIndexFromValue(uint value, out int elementIndex)
38 | {
39 | elementIndex = -1; return false;
40 | }
41 |
42 | public virtual IEnumerable GetValuesFromIndex(int elementIndex)
43 | {
44 | yield break;
45 | }
46 |
47 | public virtual int Count
48 | {
49 | get { return 0; }
50 | }
51 |
52 | public static Indexes Unset
53 | {
54 | get { return _unset; }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/ReportDescriptorParseState.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2013, 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 | using HidSharp.Reports.Encodings;
21 |
22 | namespace HidSharp.Reports
23 | {
24 | // TODO: Make this public if anyone finds value in doing so. For now let's not lock ourselves in.
25 | sealed class ReportDescriptorParseState
26 | {
27 | public ReportDescriptorParseState()
28 | {
29 | RootItem = new DescriptorCollectionItem();
30 | GlobalItemStateStack = new List>();
31 | LocalItemState = new List>();
32 | Reset();
33 | }
34 |
35 | public void Reset()
36 | {
37 | CurrentCollectionItem = RootItem;
38 | RootItem.ChildItems.Clear();
39 | RootItem.CollectionType = 0;
40 |
41 | GlobalItemStateStack.Clear();
42 | GlobalItemStateStack.Add(new Dictionary());
43 | LocalItemState.Clear();
44 | }
45 |
46 | public EncodedItem GetGlobalItem(GlobalItemTag tag)
47 | {
48 | EncodedItem value;
49 | GlobalItemState.TryGetValue(tag, out value);
50 | return value;
51 | }
52 |
53 | public uint GetGlobalItemValue(GlobalItemTag tag)
54 | {
55 | EncodedItem item = GetGlobalItem(tag);
56 | return item != null ? item.DataValue : 0;
57 | }
58 |
59 | public bool IsGlobalItemSet(GlobalItemTag tag)
60 | {
61 | return GlobalItemState.ContainsKey(tag);
62 | }
63 |
64 | public DescriptorCollectionItem CurrentCollectionItem
65 | {
66 | get;
67 | set;
68 | }
69 |
70 | public DescriptorCollectionItem RootItem
71 | {
72 | get;
73 | private set;
74 | }
75 |
76 | public IDictionary GlobalItemState
77 | {
78 | get { return GlobalItemStateStack[GlobalItemStateStack.Count - 1]; }
79 | }
80 |
81 | public IList> GlobalItemStateStack
82 | {
83 | get;
84 | private set;
85 | }
86 |
87 | public IList> LocalItemState
88 | {
89 | get;
90 | private set;
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/ReportType.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports
19 | {
20 | public enum ReportType
21 | {
22 | Input,
23 | Output,
24 | Feature
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Units/CurrentUnit.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Units
19 | {
20 | ///
21 | /// Defines the possible units of current.
22 | ///
23 | public enum CurrentUnit
24 | {
25 | ///
26 | /// The unit system has no unit of current.
27 | ///
28 | None,
29 |
30 | ///
31 | /// The unit of current is the Ampere.
32 | ///
33 | Ampere
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Units/LengthUnit.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Units
19 | {
20 | ///
21 | /// Defines the possible units of length.
22 | ///
23 | public enum LengthUnit
24 | {
25 | ///
26 | /// The unit system has no unit of length.
27 | ///
28 | None,
29 |
30 | ///
31 | /// The unit of length is the centimeter (occurs in the SI Linear unit system).
32 | ///
33 | Centimeter,
34 |
35 | ///
36 | /// The unit of length is the radian (occurs in the SI Rotation unit system).
37 | ///
38 | Radians,
39 |
40 | ///
41 | /// The unit of length is the inch (occurs in the English Linear unit system).
42 | ///
43 | Inch,
44 |
45 | ///
46 | /// The unit of length is the degree (occurs in the English Rotation unit system).
47 | ///
48 | Degrees
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Units/LuminousIntensityUnit.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Units
19 | {
20 | ///
21 | /// Defines the possible units of luminous intensity.
22 | ///
23 | public enum LuminousIntensityUnit
24 | {
25 | ///
26 | /// The unit system has no unit of luminous intensity.
27 | ///
28 | None,
29 |
30 | ///
31 | /// The unit of luminous intensity is the candela.
32 | ///
33 | Candela
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Units/MassUnit.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Units
19 | {
20 | ///
21 | /// Defines the possible units of mass.
22 | ///
23 | public enum MassUnit
24 | {
25 | ///
26 | /// The unit system has no unit of mass.
27 | ///
28 | None,
29 |
30 | ///
31 | /// The unit of mass is the gram (occurs in the SI Linear and Rotation unit systems).
32 | ///
33 | Gram,
34 |
35 | ///
36 | /// The unit of mass is the slug (occurs in the English Linear and Rotation unit systems).
37 | ///
38 | Slug
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Units/TemperatureUnit.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Units
19 | {
20 | ///
21 | /// Defines the possible units of temperature.
22 | ///
23 | public enum TemperatureUnit
24 | {
25 | ///
26 | /// The unit system has no unit of temperature.
27 | ///
28 | None,
29 |
30 | ///
31 | /// The unit of temperature is Kelvin (occurs in SI Linear and Rotation unit systems).
32 | ///
33 | Kelvin,
34 |
35 | ///
36 | /// The unit of temperature is Fahrenheit (occurs in English Linear and Rotation unit systems).
37 | ///
38 | Fahrenheit
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Units/TimeUnit.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Units
19 | {
20 | ///
21 | /// Defines the possible units of time.
22 | ///
23 | public enum TimeUnit
24 | {
25 | ///
26 | /// The unit system has no unit of time.
27 | ///
28 | None,
29 |
30 | ///
31 | /// The unit of time is seconds.
32 | ///
33 | Seconds
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Units/UnitKind.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2018 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Units
19 | {
20 | public enum UnitKind
21 | {
22 | Length = 1,
23 | Mass,
24 | Time,
25 | Temperature,
26 | Current,
27 | LuminousIntensity
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Reports/Units/UnitSystem.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2011, 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp.Reports.Units
19 | {
20 | ///
21 | /// Defines the possible unit systems.
22 | ///
23 | public enum UnitSystem
24 | {
25 | ///
26 | /// No units are used.
27 | ///
28 | None = 0,
29 |
30 | ///
31 | /// The SI Linear unit system uses centimeters for length, grams for mass, seconds for time,
32 | /// Kelvin for temperature, Amperes for current, and candelas for luminous intensity.
33 | ///
34 | SILinear,
35 |
36 | ///
37 | /// The SI Rotation unit system uses radians for length, grams for mass, seconds for time,
38 | /// Kelvin for temperature, Amperes for current, and candelas for luminous intensity.
39 | ///
40 | SIRotation,
41 |
42 | ///
43 | /// The English Linear unit system uses inches for length, slugs for mass, seconds for time,
44 | /// Fahrenheit for temperature, Amperes for current, and candelas for luminous intensity.
45 | ///
46 | EnglishLinear,
47 |
48 | ///
49 | /// The English Rotation unit system uses degrees for length, slugs for mass, seconds for time,
50 | /// Fahrenheit for temperature, Amperes for current, and candelas for luminous intensity.
51 | ///
52 | EnglishRotation
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/SerialDevice.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp
21 | {
22 | ///
23 | /// Represents a serial device.
24 | ///
25 | public abstract class SerialDevice : Device
26 | {
27 | ///
28 | public new SerialStream Open()
29 | {
30 | return Open(null);
31 | }
32 |
33 | ///
34 | public new SerialStream Open(OpenConfiguration openConfig)
35 | {
36 | return (SerialStream)base.Open(openConfig);
37 | }
38 |
39 | ///
40 | public bool TryOpen(out SerialStream stream)
41 | {
42 | return TryOpen(null, out stream);
43 | }
44 |
45 | ///
46 | public bool TryOpen(OpenConfiguration openConfig, out SerialStream stream)
47 | {
48 | DeviceStream baseStream;
49 | bool result = base.TryOpen(openConfig, out baseStream);
50 | stream = (SerialStream)baseStream; return result;
51 | }
52 |
53 | ///
54 | public override string GetFriendlyName()
55 | {
56 | return GetFileSystemName();
57 | }
58 |
59 | public override bool HasImplementationDetail(Guid detail)
60 | {
61 | return base.HasImplementationDetail(detail) || detail == ImplementationDetail.SerialDevice;
62 | }
63 |
64 | ///
65 | public override string ToString()
66 | {
67 | string fileSystemName = "(unknown filesystem name)";
68 | try { fileSystemName = GetFileSystemName(); } catch { }
69 |
70 | return string.Format("{0} ({1})", fileSystemName, DevicePath);
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/SerialParity.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | namespace HidSharp
19 | {
20 | public enum SerialParity
21 | {
22 | None = 0,
23 | Odd = 1,
24 | Even = 2
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/SerialSettings.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp
21 | {
22 | struct SerialSettings
23 | {
24 | public static readonly SerialSettings Default = new SerialSettings()
25 | {
26 | BaudRate = 9600, DataBits = 8, Parity = SerialParity.None, StopBits = 1
27 | };
28 |
29 | public int BaudRate;
30 | public int DataBits;
31 | public SerialParity Parity;
32 | public int StopBits;
33 |
34 | public void SetBaudRate(int baudRate, object @lock, ref bool settingsChanged)
35 | {
36 | if (baudRate < 0) { throw new NotSupportedException(); }
37 |
38 | lock (@lock)
39 | {
40 | if (BaudRate == baudRate) { return; }
41 | //Console.WriteLine(string.Format("Baud {0} -> {1}", BaudRate, baudRate));
42 | BaudRate = baudRate; settingsChanged = true;
43 | }
44 | }
45 |
46 | public void SetDataBits(int dataBits, object @lock, ref bool settingsChanged)
47 | {
48 | if (dataBits < 7 || dataBits > 8) { throw new NotSupportedException(); }
49 |
50 | lock (@lock)
51 | {
52 | if (DataBits == dataBits) { return; }
53 | //Console.WriteLine(string.Format("Data Bits {0} -> {1}", DataBits, dataBits));
54 | DataBits = dataBits; settingsChanged = true;
55 | }
56 | }
57 |
58 | public void SetParity(SerialParity parity, object @lock, ref bool settingsChanged)
59 | {
60 | lock (@lock)
61 | {
62 | if (Parity == parity) { return; }
63 | //Console.WriteLine(string.Format("Parity {0} -> {1}", Parity, parity));
64 | Parity = parity; settingsChanged = true;
65 | }
66 | }
67 |
68 | public void SetStopBits(int stopBits, object @lock, ref bool settingsChanged)
69 | {
70 | if (stopBits < 1 || stopBits > 2) { throw new NotSupportedException(); }
71 |
72 | lock (@lock)
73 | {
74 | if (StopBits == stopBits) { return; }
75 | //Console.WriteLine(string.Format("Stop Bits {0} -> {1}", StopBits, stopBits));
76 | StopBits = stopBits; settingsChanged = true;
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/SerialStream.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System.Collections.Generic;
19 | using System.Reflection;
20 | using System.Text;
21 |
22 | namespace HidSharp
23 | {
24 | ///
25 | /// Communicates with a serial device.
26 | ///
27 | public abstract class SerialStream : DeviceStream
28 | {
29 | string _newLine;
30 |
31 | ///
32 | protected SerialStream(SerialDevice device)
33 | : base(device)
34 | {
35 | ReadTimeout = 3000;
36 | WriteTimeout = 3000;
37 |
38 | NewLine = "\r\n";
39 | BaudRate = SerialSettings.Default.BaudRate;
40 | DataBits = SerialSettings.Default.DataBits;
41 | Parity = SerialSettings.Default.Parity;
42 | StopBits = SerialSettings.Default.StopBits;
43 | }
44 |
45 | public string ReadTo(string ending)
46 | {
47 | Throw.If.NullOrEmpty(ending, "ending");
48 |
49 | var bytes = new List();
50 | var endingBytes = Encoding.GetBytes(ending);
51 | int matchBytes = 0;
52 |
53 | while (true)
54 | {
55 | int @byte = ReadByte();
56 | if (@byte < 0) { break; }
57 | bytes.Add((byte)@byte);
58 |
59 | if (@byte == endingBytes[matchBytes])
60 | {
61 | if (++matchBytes == endingBytes.Length)
62 | {
63 | break;
64 | }
65 | }
66 | else
67 | {
68 | matchBytes = 0;
69 | }
70 | }
71 |
72 | @bytes.RemoveRange(bytes.Count - matchBytes, matchBytes);
73 | return Encoding.GetString(@bytes.ToArray());
74 | }
75 |
76 | [Obfuscation(Exclude = true)]
77 | public string ReadLine()
78 | {
79 | return ReadTo(NewLine);
80 | }
81 |
82 | [Obfuscation(Exclude = true)]
83 | public void Write(string s)
84 | {
85 | Throw.If.Null(s, "s");
86 | byte[] bytes = Encoding.GetBytes(s);
87 | Write(bytes, 0, bytes.Length);
88 | }
89 |
90 | [Obfuscation(Exclude = true)]
91 | public void WriteLine(string s)
92 | {
93 | Throw.If.Null(s, "s");
94 | Write(s + NewLine);
95 | }
96 |
97 | public abstract int BaudRate
98 | {
99 | get;
100 | set;
101 | }
102 |
103 | public abstract int DataBits
104 | {
105 | get;
106 | set;
107 | }
108 |
109 | public abstract SerialParity Parity
110 | {
111 | get;
112 | set;
113 | }
114 |
115 | public abstract int StopBits
116 | {
117 | get;
118 | set;
119 | }
120 |
121 | Encoding Encoding
122 | {
123 | get { return Encoding.UTF8; }
124 | }
125 |
126 | public string NewLine
127 | {
128 | get { return _newLine; }
129 | set
130 | {
131 | Throw.If.NullOrEmpty(value, "NewLine");
132 | _newLine = value;
133 | }
134 | }
135 |
136 | ///
137 | /// Gets the associated with this stream.
138 | ///
139 | public new SerialDevice Device
140 | {
141 | get { return (SerialDevice)base.Device; }
142 | }
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Throw.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2013 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Collections.Generic;
20 |
21 | namespace HidSharp
22 | {
23 | sealed class Throw
24 | {
25 | Throw()
26 | {
27 |
28 | }
29 |
30 | public static Throw If
31 | {
32 | get { return null; }
33 | }
34 | }
35 |
36 | static class ThrowExtensions
37 | {
38 | public static Throw False(this Throw self, bool condition)
39 | {
40 | if (!condition) { throw new ArgumentException(); }
41 | return null;
42 | }
43 |
44 | public static Throw False(this Throw self, bool condition, string message, string paramName)
45 | {
46 | if (!condition) { throw new ArgumentException(message, paramName); }
47 | return null;
48 | }
49 |
50 | public static Throw Negative(this Throw self, int value, string paramName)
51 | {
52 | if (value < 0) { throw new ArgumentOutOfRangeException(paramName); }
53 | return null;
54 | }
55 |
56 | public static Throw Null(this Throw self, T value)
57 | {
58 | if (value == null) { throw new ArgumentNullException(); }
59 | return null;
60 | }
61 |
62 | public static Throw Null(this Throw self, T value, string paramName)
63 | {
64 | if (value == null) { throw new ArgumentNullException(paramName); }
65 | return null;
66 | }
67 |
68 | public static Throw NullOrEmpty(this Throw self, string value, string paramName)
69 | {
70 | Throw.If.Null(value, paramName);
71 | if (value.Length == 0) { throw new ArgumentException("Must not be empty.", paramName); }
72 | return null;
73 | }
74 |
75 | public static Throw OutOfRange(this Throw self, int bufferSize, int offset, int count)
76 | {
77 | if (offset < 0 || offset > bufferSize) { throw new ArgumentOutOfRangeException("offset"); }
78 | if (count < 0 || count > bufferSize - offset) { throw new ArgumentOutOfRangeException("count"); }
79 | return null;
80 | }
81 |
82 | public static Throw OutOfRange(this Throw self, IList buffer, int offset, int count)
83 | {
84 | Throw.If.Null(buffer, "buffer").OutOfRange(buffer.Count, offset, count);
85 | return null;
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Utility/BcdHelper.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 |
20 | namespace HidSharp.Utility
21 | {
22 | ///
23 | /// Converts USB device release numbers to and from binary-coded decimal.
24 | ///
25 | static class BcdHelper
26 | {
27 | ///
28 | /// Converts a USB device release number to binary-coded decimal.
29 | ///
30 | /// The device release number.
31 | /// The device release number, in binary-coded decimal.
32 | public static int FromVersion(Version version)
33 | {
34 | Throw.If.Null(version);
35 | return (version.Major / 10) << 12 | (version.Major % 10) << 8 | (version.Minor / 10) << 4 | (version.Minor % 10);
36 | }
37 |
38 | ///
39 | /// Converts a USB device release number from binary-coded decimal.
40 | ///
41 | /// The device release number, in binary-coded decimal.
42 | /// The device release number.
43 | public static Version ToVersion(int bcd)
44 | {
45 | Throw.If.False(bcd >= ushort.MinValue && bcd <= ushort.MaxValue);
46 | return new Version(((bcd >> 12) & 0xf) * 10 + ((bcd >> 8) & 0xf), ((bcd >> 4) & 0xf) * 10 + (bcd & 0xf));
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Utility/HResult.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2017 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Reflection;
20 | using System.Runtime.InteropServices;
21 |
22 | namespace HidSharp.Utility
23 | {
24 | [Obsolete("This class is experimental and its functionality may be moved elsewhere in the future. Please do not rely on it.")]
25 | public static class HResult
26 | {
27 | public const int FileNotFound = unchecked((int)0x80070002); // ERROR_FILE_NOT_FOUND
28 | public const int SharingViolation = unchecked((int)0x80070020); // ERROR_SHARING_VIOLATION
29 | public const int SemTimeout = unchecked((int)0x80070079); // ERROR_SEM_TIMEOUT
30 |
31 | public static int FromException(Exception exception)
32 | {
33 | Throw.If.Null(exception);
34 |
35 | try
36 | {
37 | // This works with .NET 4.0 as well as later versions. Also, it does not change any state.
38 | return (int)exception.GetType().InvokeMember("HResult",
39 | BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
40 | null, exception, new object[0]);
41 | }
42 | catch
43 | {
44 | return Marshal.GetHRForException(exception);
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/FS_Tool/HidSharp/Utility/HidSharpDiagnostics.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /* Copyright 2019 James F. Bellinger
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing,
11 | software distributed under the License is distributed on an
12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | KIND, either express or implied. See the License for the
14 | specific language governing permissions and limitations
15 | under the License. */
16 | #endregion
17 |
18 | using System;
19 | using System.Diagnostics;
20 |
21 | namespace HidSharp.Utility
22 | {
23 | public static class HidSharpDiagnostics
24 | {
25 | static HidSharpDiagnostics()
26 | {
27 | PerformStrictChecks = false;
28 | }
29 |
30 | internal static void PerformStrictCheck(bool condition, string message)
31 | {
32 | if (!condition)
33 | {
34 | message += "\n\nTo disable this exception, set HidSharpDiagnostics.PerformStrictChecks to false.";
35 | throw new InvalidOperationException(message);
36 | }
37 | }
38 |
39 | internal static void Trace(string message)
40 | {
41 | if (!EnableTracing) { return; }
42 | System.Diagnostics.Trace.WriteLine(message, "HIDSharp");
43 | }
44 |
45 | internal static void Trace(string formattedMessage, object arg)
46 | {
47 | if (!EnableTracing) { return; }
48 | Trace(string.Format(formattedMessage, arg));
49 | }
50 |
51 | internal static void Trace(string formattedMessage, params object[] args)
52 | {
53 | if (!EnableTracing) { return; }
54 | Trace(string.Format(formattedMessage, args));
55 | }
56 |
57 | public static bool EnableTracing
58 | {
59 | get;
60 | set;
61 | }
62 |
63 | public static bool PerformStrictChecks
64 | {
65 | get;
66 | set;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/FS_Tool/SelfSignRelease.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | SET CERT_PATH=Cert:\CurrentUser\My\*99E9FCA2F8D1EFBD1BFB5A62D85CC1E1DB3438FA
4 | SET TS_SVR=http://timestamp.digicert.com
5 |
6 | SET TARGET_DIR=bin\Release
7 | xcopy LICENSE "%TARGET_DIR%" /y
8 | xcopy ..\README.md "%TARGET_DIR%" /y
9 | powershell CodeSign.ps1 -file_path "%TARGET_DIR%\FS_Tool.exe" -cert_path "%CERT_PATH%" -ts_svr "%TS_SVR%"
10 | powershell CodeSign.ps1 -file_path "%TARGET_DIR%\SimConnectLib.dll" -cert_path "%CERT_PATH%" -ts_svr "%TS_SVR%"
11 | powershell CodeSign.ps1 -file_path "%TARGET_DIR%\HidSharp.dll" -cert_path "%CERT_PATH%" -ts_svr "%TS_SVR%"
12 |
13 | pause
14 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/CircularBuffer.vb:
--------------------------------------------------------------------------------
1 | Option Explicit On
2 | Option Strict On
3 |
4 | Public Class CircularBuffer
5 |
6 | Public Sub New(ByVal bufSz As Integer)
7 | Resize(bufSz)
8 | End Sub
9 |
10 | Public Sub Append(ByVal strVal As String)
11 |
12 | myBuffer(currentIndex) = strVal
13 | currentIndex += 1
14 | If currentIndex > mySize - 1 Then currentIndex = 0
15 |
16 | End Sub
17 |
18 | Public Sub Resize(ByVal bufSz As Integer)
19 |
20 | ReDim Preserve myBuffer(bufSz - 1)
21 |
22 | Dim ti As Integer = 0
23 | If mySize > 0 Then
24 | If bufSz <= mySize Then
25 | Exit Sub
26 | Else
27 | ti = mySize
28 | End If
29 | End If
30 |
31 | For i = ti To bufSz - 1
32 | myBuffer(i) = ""
33 | Next
34 |
35 | mySize = bufSz
36 |
37 | End Sub
38 |
39 | Public Shadows Function ToString() As String
40 |
41 | Dim t As String = ""
42 |
43 | Dim ndx As Integer = currentIndex
44 | For i = 0 To mySize - 1
45 | Dim temp As String = myBuffer(ndx)
46 | If temp <> "" Then
47 | If t = "" Then
48 | t = temp & vbNewLine
49 | Else
50 | t &= temp & vbNewLine
51 | End If
52 | End If
53 |
54 | ndx += 1
55 | If ndx > mySize - 1 Then
56 | ndx = 0
57 | End If
58 | Next
59 |
60 | Return t
61 |
62 | End Function
63 |
64 | Private currentIndex As Integer = 0
65 | Private myBuffer(0) As String
66 | Private mySize As Integer = 0
67 |
68 | End Class
69 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/HeartbeatLabel.vb:
--------------------------------------------------------------------------------
1 | Option Strict On
2 | Option Explicit On
3 |
4 | Imports System.Windows.Forms
5 |
6 | Public Class HeartbeatLabel
7 | Inherits Label
8 |
9 | Public Property HeartbeatString As String = "*"
10 |
11 | Public Property HeartbeatMilliSeconds As Integer = 1
12 |
13 | Public Sub Tick()
14 |
15 | If Now > lastBeat.AddMilliseconds(Me.HeartbeatMilliSeconds) Then
16 | lastBeat = Now
17 | Me.Toggle()
18 | End If
19 |
20 | End Sub
21 |
22 | Public Sub Toggle()
23 |
24 | If Me.Text = "" Then
25 | Me.Text = Me.HeartbeatString
26 | Else
27 | Me.Text = ""
28 | End If
29 |
30 | End Sub
31 |
32 | Private lastBeat As Date = Date.MinValue
33 |
34 | End Class
35 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/KeyCodes,SimVars,SimEvents.ods:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Elephant42/FS_Tool/634ed2e76a987dcbd0dff6c1f354619cba695eed/FS_Tool/SimConLib/KeyCodes,SimVars,SimEvents.ods
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 | false
5 | 0
6 | true
7 | 0
8 | 1
9 | true
10 |
11 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Reflection
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
21 |
22 |
23 | ' Version information for an assembly consists of the following four values:
24 | '
25 | ' Major Version
26 | ' Minor Version
27 | ' Build Number
28 | ' Revision
29 | '
30 | ' You can specify all the values or you can default the Build and Revision Numbers
31 | ' by using the '*' as shown below:
32 | '
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/My Project/Resources.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 | Imports System
15 |
16 | Namespace My.Resources
17 |
18 | 'This class was auto-generated by the StronglyTypedResourceBuilder
19 | 'class via a tool like ResGen or Visual Studio.
20 | 'To add or remove a member, edit your .ResX file then rerun ResGen
21 | 'with the /str option, or rebuild your VS project.
22 | '''
23 | ''' A strongly-typed resource class, for looking up localized strings, etc.
24 | '''
25 | _
29 | Friend Module Resources
30 |
31 | Private resourceMan As Global.System.Resources.ResourceManager
32 |
33 | Private resourceCulture As Global.System.Globalization.CultureInfo
34 |
35 | '''
36 | ''' Returns the cached ResourceManager instance used by this class.
37 | '''
38 | _
39 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
40 | Get
41 | If Object.ReferenceEquals(resourceMan, Nothing) Then
42 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("SimConLib.Resources", GetType(Resources).Assembly)
43 | resourceMan = temp
44 | End If
45 | Return resourceMan
46 | End Get
47 | End Property
48 |
49 | '''
50 | ''' Overrides the current thread's CurrentUICulture property for all
51 | ''' resource lookups using this strongly typed resource class.
52 | '''
53 | _
54 | Friend Property Culture() As Global.System.Globalization.CultureInfo
55 | Get
56 | Return resourceCulture
57 | End Get
58 | Set
59 | resourceCulture = value
60 | End Set
61 | End Property
62 | End Module
63 | End Namespace
64 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/My Project/Settings.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 |
16 | _
19 | Partial Friend NotInheritable Class MySettings
20 | Inherits Global.System.Configuration.ApplicationSettingsBase
21 |
22 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
23 |
24 | #Region "My.Settings Auto-Save Functionality"
25 | #If _MyType = "WindowsForms" Then
26 | Private Shared addedHandler As Boolean
27 |
28 | Private Shared addedHandlerLockObject As New Object
29 |
30 | _
31 | Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
32 | If My.Application.SaveMySettingsOnExit Then
33 | My.Settings.Save()
34 | End If
35 | End Sub
36 | #End If
37 | #End Region
38 |
39 | Public Shared ReadOnly Property [Default]() As MySettings
40 | Get
41 |
42 | #If _MyType = "WindowsForms" Then
43 | If Not addedHandler Then
44 | SyncLock addedHandlerLockObject
45 | If Not addedHandler Then
46 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
47 | addedHandler = True
48 | End If
49 | End SyncLock
50 | End If
51 | #End If
52 | Return defaultInstance
53 | End Get
54 | End Property
55 | End Class
56 |
57 | Namespace My
58 |
59 | _
62 | Friend Module MySettingsProperty
63 |
64 |
65 | Friend ReadOnly Property Settings() As Global.SimConLib.MySettings
66 | Get
67 | Return Global.SimConLib.MySettings.Default
68 | End Get
69 | End Property
70 | End Module
71 | End Namespace
72 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/FS_Tool/SimConLib/UtilityClasses.vb:
--------------------------------------------------------------------------------
1 | Option Explicit On
2 | Option Strict On
3 |
4 | Imports System.ComponentModel
5 | Imports System.Threading
6 | Imports System.Windows.Forms
7 |
8 | Public Class CircularBuffer
9 |
10 | Public Sub New(ByVal bufSz As Integer)
11 | Resize(bufSz)
12 | End Sub
13 |
14 | Public Sub Append(ByVal strVal As String)
15 |
16 | myBuffer(currentIndex) = strVal
17 | currentIndex += 1
18 | If currentIndex > mySize - 1 Then currentIndex = 0
19 |
20 | End Sub
21 |
22 | Public Sub Resize(ByVal bufSz As Integer)
23 |
24 | ReDim Preserve myBuffer(bufSz - 1)
25 |
26 | Dim ti As Integer = 0
27 | If mySize > 0 Then
28 | If bufSz <= mySize Then
29 | Exit Sub
30 | Else
31 | ti = mySize
32 | End If
33 | End If
34 |
35 | For i = ti To bufSz - 1
36 | myBuffer(i) = ""
37 | Next
38 |
39 | mySize = bufSz
40 |
41 | End Sub
42 |
43 | Public Shadows Function ToString() As String
44 |
45 | Dim t As String = ""
46 |
47 | Dim ndx As Integer = currentIndex
48 | For i = 0 To mySize - 1
49 | Dim temp As String = myBuffer(ndx)
50 | If temp <> "" Then
51 | If t = "" Then
52 | t = temp & vbNewLine
53 | Else
54 | t &= temp & vbNewLine
55 | End If
56 | End If
57 |
58 | ndx += 1
59 | If ndx > mySize - 1 Then
60 | ndx = 0
61 | End If
62 | Next
63 |
64 | Return t
65 |
66 | End Function
67 |
68 | Private currentIndex As Integer = 0
69 | Private myBuffer(0) As String
70 | Private mySize As Integer = 0
71 |
72 | End Class
73 |
74 | Public Class WaitTimer
75 |
76 | Public Shared Sub Wait(ByVal ms As Integer)
77 |
78 | Dim are As New AutoResetEvent(False)
79 | Dim tmr As New Threading.Timer(New TimerCallback(AddressOf timerThread), are, ms, 0)
80 | are.WaitOne()
81 | tmr.Dispose()
82 |
83 | End Sub
84 |
85 | Private Shared Sub timerThread(ByVal state As Object)
86 |
87 | Dim are = CType(state, AutoResetEvent)
88 | are.Set()
89 |
90 | End Sub
91 |
92 | End Class
93 |
--------------------------------------------------------------------------------