├── EmuController
├── EmuController.rc
├── EmuController.inf
├── resource.h
├── NamedPipeServer.h
├── Driver.h
├── MessageProcessor.h
├── Queue.h
├── ReadMe.txt
├── Ioctl.h
├── Trace.h
├── Device.h
├── EmuController.vcxproj.filters
├── Driver.c
├── MessageProcessor.c
└── Queue.c
├── SetupAPI.NET
├── SetupAPI.NET.csproj
└── DeviceConfig.Native.cs
├── EmuController.Client.NET
├── EmuControllerException.cs
├── Input
│ ├── IInputState.cs
│ ├── UsageId.cs
│ ├── MessageHeader.cs
│ ├── ControlCollection.cs
│ ├── DPads.cs
│ ├── Buttons.cs
│ ├── Axes.cs
│ └── EmuControllerInputState.cs
├── PID
│ ├── PIDStateFlags.cs
│ ├── PIDSetGainReport.cs
│ ├── PIDEffectTypeEnum.cs
│ ├── PIDBlockFreeReport.cs
│ ├── PIDBloadLoadReport.cs
│ ├── FFBPacket.cs
│ ├── PIDNewEffectReport.cs
│ ├── PIDSetConstantForce.cs
│ ├── PIDDownloadSampleReport.cs
│ ├── PIDReportIdEnum.cs
│ ├── PIDSetCustomForceReport.cs
│ ├── PIDDeviceControlReport.cs
│ ├── PIDSetRampReport.cs
│ ├── PIDEffectOperationReport.cs
│ ├── PIDSetCustomForceDataReport.cs
│ ├── PIDSetPeriodicReport.cs
│ ├── PIDSetEnvelopeReport.cs
│ ├── PIDSetConditionReport.cs
│ ├── PIDSetEffectReport.cs
│ └── FFBDataReceivedEventArgs.cs
├── EmuController.Client.NET.csproj
├── WMIPnpEntity.cs
├── Utils.cs
├── Resources.Designer.cs
├── EmuControllerInfo.cs
├── Resources.resx
└── EmuControllerClient.cs
├── EmuController.Client.NET.Demo
├── Program.cs
├── EmuController.Client.NET.Demo.csproj
└── FeederReceptor.cs
├── EmuController.DevManager
├── AppSettings.xml
├── Start.xaml
├── Views
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── SingleLineInputDialog.xaml
│ ├── DeviceList.xaml
│ ├── SingleLineInputDialog.xaml.cs
│ └── DeviceList.xaml.cs
├── AssemblyInfo.cs
├── EmuController.DevManager.csproj
├── Commands
│ ├── DeviceMenuCommand.cs
│ └── DeviceCommand.cs
├── Start.xaml.cs
├── Behaviors
│ └── MaxCharactersBehavior.cs
├── XmlSerializer.cs
├── Utils.cs
├── AppSettings.cs
├── WMIPnpEntity.cs
├── SingleInstanceApplicationLock.cs
├── app.manifest
└── ViewModels
│ └── EmuControllerDevice.cs
├── EmuController.sln.licenseheader
├── EmuController.Client.NETTests
├── Input
│ ├── ControlCollectionTests.cs
│ ├── ButtonsTests.cs
│ └── EmuInputStateTests.cs
└── EmuController.Client.NETTests.csproj
├── .gitattributes
├── EmuController.sln
└── .gitignore
/EmuController/EmuController.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FirstPlatoLV/EmuController/HEAD/EmuController/EmuController.rc
--------------------------------------------------------------------------------
/EmuController/EmuController.inf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FirstPlatoLV/EmuController/HEAD/EmuController/EmuController.inf
--------------------------------------------------------------------------------
/SetupAPI.NET/SetupAPI.NET.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | x64
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/EmuControllerException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace EmuController.Client.NET
6 | {
7 | class EmuControllerException : Exception
8 | {
9 | public EmuControllerException(string message) : base(message)
10 | {
11 |
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/Input/IInputState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace EmuController.Client.NET.Input
6 | {
7 | public interface IInputState
8 | {
9 | void CreateDefaultState();
10 | byte[] GetStateUpdateMessage();
11 | byte[] GetInputReportMessage();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/EmuController.Client.NET.Demo/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EmuController.Client.NET.Demo
4 | {
5 | class Program
6 | {
7 | static void Main()
8 | {
9 | FeederReceptor feedReceive = new FeederReceptor();
10 | feedReceive.Connect();
11 | feedReceive.Feed();
12 | Console.ReadLine();
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/EmuController.DevManager/AppSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | drv\
4 |
5 | emucontroller.cat
6 | emucontroller.dll
7 | emucontroller.inf
8 |
9 |
--------------------------------------------------------------------------------
/EmuController.Client.NET.Demo/EmuController.Client.NET.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0-windows7.0
6 | x64;x86
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/EmuController/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by EmuController.rc
4 | //
5 |
6 | // Next default values for new objects
7 | //
8 | #ifdef APSTUDIO_INVOKED
9 | #ifndef APSTUDIO_READONLY_SYMBOLS
10 | #define _APS_NEXT_RESOURCE_VALUE 101
11 | #define _APS_NEXT_COMMAND_VALUE 40001
12 | #define _APS_NEXT_CONTROL_VALUE 1001
13 | #define _APS_NEXT_SYMED_VALUE 101
14 | #endif
15 | #endif
16 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDStateFlags.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace EmuController.Client.NET.PID
6 | {
7 | [Flags]
8 | public enum PIDStateFlags : byte
9 | {
10 | DevicePaused = 0x01,
11 | ActuatorsEnabled = 0x02,
12 | ActuatorsPowered = 0x10,
13 | Paused = DevicePaused | ActuatorsEnabled | ActuatorsPowered,
14 | Default = ActuatorsEnabled | ActuatorsPowered,
15 | Disabled = 0
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/EmuController.sln.licenseheader:
--------------------------------------------------------------------------------
1 | extensions: designer.cs generated.cs
2 | extensions: .cs .cpp .h .c
3 | // Copyright 2020 Maris Melbardis
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | extensions: .aspx .ascx
17 | <%--
18 | Copyright (c) 2011 rubicon IT GmbH
19 | --%>
20 | extensions: .vb
21 | 'Sample license text.
22 | extensions: .xml .config .xsd
23 |
--------------------------------------------------------------------------------
/EmuController.Client.NETTests/Input/ControlCollectionTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using EmuController.Client.NET.Input;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace EmuController.Client.NET.Input.Tests
8 | {
9 | [TestClass()]
10 | public class ControlCollectionTests
11 | {
12 | [TestMethod()]
13 | public void GetUpdatedValuesTest()
14 | {
15 | EmuControllerInputState emu = new EmuControllerInputState();
16 |
17 | emu.Buttons.SetValue(0, true);
18 | emu.Buttons.SetValue(0, false);
19 |
20 | emu.Buttons.SetValue(8, true);
21 |
22 | emu.Buttons.SetValue(16, true);
23 | emu.Buttons.SetValue(16, false);
24 |
25 | ReadOnlySpan updatedButtons = emu.Buttons.GetUpdatedValues();
26 |
27 | Assert.IsTrue(updatedButtons.Length == 2);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/EmuController.Client.NET/Input/UsageId.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | namespace EmuController.Client.NET.Input
21 | {
22 | public enum UsageId : byte
23 | {
24 | Axis = 0x10,
25 | Button = 0x11,
26 | DPad = 0x12,
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/EmuController.DevManager/Start.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/EmuController.Client.NETTests/Input/ButtonsTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using EmuController.Client.NET.Input;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 | using Xunit.Sdk;
7 | using System.Security.Cryptography;
8 |
9 | namespace EmuController.Client.NET.Input.Tests
10 | {
11 | [TestClass()]
12 | public class ButtonsTests
13 | {
14 | [TestMethod()]
15 | public void SetValueTest()
16 | {
17 | EmuControllerInputState emu = new EmuControllerInputState();
18 |
19 | Random rndVal = new Random();
20 |
21 | for (int i = 0; i < emu.Buttons.AllValues.Length * sizeof(ushort); i++)
22 | {
23 | int index = rndVal.Next(0, emu.Buttons.AllValues.Length * sizeof(ushort));
24 | emu.Buttons.SetValue(index, true);
25 |
26 | Assert.IsTrue(Utils.IsBitSet(emu.Buttons.AllValues[index / 16], index % 16));
27 |
28 | emu.Buttons.SetValue(index, false);
29 | Assert.IsFalse(Utils.IsBitSet(emu.Buttons.AllValues[index / 16], index % 16));
30 | }
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/EmuController.Client.NET/Input/MessageHeader.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | namespace EmuController.Client.NET.Input
21 | {
22 | class MessageHeader
23 | {
24 | public MessageType Type { get; set; } = MessageType.Input;
25 | public byte Length { get; set; }
26 |
27 | public enum MessageType
28 | {
29 | Input = 0x01,
30 | InputFull = 0x02,
31 | PID = 0x03,
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/EmuController.DevManager/Views/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDSetGainReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | namespace EmuController.Client.NET.PID
21 | {
22 | public class PIDSetGainReport : FFBPacket
23 | {
24 | public ushort Gain { get; private set; }
25 | public PIDSetGainReport(byte[] packet): base(packet)
26 | {
27 |
28 | }
29 |
30 | protected override void Deserialize()
31 | {
32 | Gain = BitConverter.ToUInt16(DataPacket, 1);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDEffectTypeEnum.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | namespace EmuController.Client.NET.PID
21 | {
22 | public enum PIDEffectTypeEnum
23 | {
24 | Constant = 1,
25 | Ramp = 2,
26 | Square = 3,
27 | Sine = 4,
28 | Triangle = 5,
29 | SawtoothUp = 6,
30 | SawtoothDown = 7,
31 | Spring = 8,
32 | Damper = 9,
33 | Inertia = 10,
34 | Friction = 11,
35 | CustomForce = 12
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/EmuController.DevManager/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System.Windows;
15 |
16 | [assembly: ThemeInfo(
17 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
18 | //(used if a resource is not found in the page,
19 | // or application resource dictionaries)
20 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
21 | //(used if a resource is not found in the page,
22 | // app, or any theme specific resource dictionaries)
23 | )]
24 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDBlockFreeReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDBlockFreeReport : FFBPacket
24 | {
25 | public byte FreeReportEffectBlockIndex { get; private set; }
26 | public PIDBlockFreeReport(byte[] packet): base(packet)
27 | {
28 |
29 | }
30 |
31 | protected override void Deserialize()
32 | {
33 | FreeReportEffectBlockIndex = DataPacket[1];
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDBloadLoadReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Runtime.Serialization;
19 | using System.Text;
20 | using System.Threading.Tasks;
21 |
22 | namespace EmuController.Client.NET.PID
23 | {
24 | public class PIDBloadLoadReport : FFBPacket
25 | {
26 | public byte EffectBlockIndex { get; private set; }
27 |
28 | public PIDBloadLoadReport(byte[] packet): base(packet)
29 | {
30 |
31 | }
32 |
33 | protected override void Deserialize()
34 | {
35 | EffectBlockIndex = DataPacket[1];
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/FFBPacket.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Runtime.Serialization;
19 | using System.Text;
20 | using System.Threading.Tasks;
21 |
22 | namespace EmuController.Client.NET.PID
23 | {
24 | public abstract class FFBPacket
25 | {
26 | public PIDReportIdEnum ReportId { get => (PIDReportIdEnum)DataPacket[0]; }
27 |
28 | protected byte[] DataPacket;
29 |
30 | public FFBPacket(byte[] packet)
31 | {
32 | DataPacket = packet;
33 | Deserialize();
34 | }
35 |
36 | protected abstract void Deserialize();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/EmuController/NamedPipeServer.h:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #pragma once
15 | EXTERN_C_START
16 |
17 |
18 | #define BUFFER_SIZE 128
19 | #define INPUT_INSTANCES 128
20 | #define PID_INSTANCES 128
21 |
22 | DWORD
23 | CreateNamedPipeServer(
24 | LPVOID Params
25 | );
26 |
27 | DWORD WINAPI
28 | InputPipeServerThread(
29 | LPVOID Params);
30 |
31 | DWORD WINAPI
32 | PidPipeServerThread(
33 | LPVOID Params);
34 |
35 | VOID
36 | WriteResponseToPidClient(
37 | PQUEUE_CONTEXT queueContext);
38 |
39 | VOID
40 | CompleteReadRequest(
41 | PDEVICE_CONTEXT devContext,
42 | UCHAR ReportId);
43 |
44 | BOOL
45 | CreatePipeSecurity(
46 | PSECURITY_ATTRIBUTES* pSecurityAttributes);
47 |
48 | VOID
49 | FreePipeSecurity(
50 | PSECURITY_ATTRIBUTES psa);
51 |
52 | EXTERN_C_END
--------------------------------------------------------------------------------
/EmuController.DevManager/EmuController.DevManager.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0-windows
6 | true
7 | x64
8 | app.manifest
9 | EmuController.DevManager.Start
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | PreserveNewest
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDNewEffectReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDNewEffectReport : FFBPacket
24 | {
25 | public PIDEffectTypeEnum EffectType { get; private set; }
26 | public byte ByteCount { get; private set; }
27 | public PIDNewEffectReport(byte[] packet): base(packet)
28 | {
29 |
30 | }
31 |
32 | protected override void Deserialize()
33 | {
34 | EffectType = (PIDEffectTypeEnum)DataPacket[1];
35 | ByteCount = DataPacket[2];
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDSetConstantForce.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDSetConstantForce : FFBPacket
24 | {
25 | public byte EffectBlockIndex { get; private set; }
26 | public short Magnitude { get; private set; }
27 |
28 | public PIDSetConstantForce(byte[] packet): base(packet)
29 | {
30 |
31 |
32 | }
33 |
34 | protected override void Deserialize()
35 | {
36 | EffectBlockIndex = DataPacket[1];
37 | Magnitude = BitConverter.ToInt16(DataPacket, 2);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDDownloadSampleReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDDownloadSampleReport : FFBPacket
24 | {
25 | public sbyte DownloadForceSampleX { get; private set; }
26 | public sbyte DownloadForceSampleY { get; private set; }
27 | public PIDDownloadSampleReport(byte[] packet): base(packet)
28 | {
29 |
30 | }
31 |
32 | protected override void Deserialize()
33 | {
34 | DownloadForceSampleX = (sbyte)DataPacket[1];
35 | DownloadForceSampleY = (sbyte)DataPacket[2];
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/EmuController/Driver.h:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | /*++
16 |
17 | Module Name:
18 |
19 | driver.h
20 |
21 | Abstract:
22 |
23 | This file contains the driver definitions.
24 |
25 | Environment:
26 |
27 | User-mode Driver Framework 2
28 |
29 | --*/
30 |
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 |
39 | #include "device.h"
40 | #include "queue.h"
41 | #include "ioctl.h"
42 | #include "namedpipeserver.h"
43 | #include "messageprocessor.h"
44 | #include "trace.h"
45 |
46 | EXTERN_C_START
47 |
48 | //
49 | // WDFDRIVER Events
50 | //
51 |
52 | DRIVER_INITIALIZE DriverEntry;
53 | EVT_WDF_DRIVER_DEVICE_ADD EmuControllerEvtDeviceAdd;
54 | EVT_WDF_OBJECT_CONTEXT_CLEANUP EmuControllerEvtDriverContextCleanup;
55 |
56 | EXTERN_C_END
57 |
--------------------------------------------------------------------------------
/EmuController.DevManager/Commands/DeviceMenuCommand.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Text;
17 | using System.Windows.Input;
18 |
19 | namespace EmuController.DevManager.Commands
20 | {
21 | public class DeviceMenuCommand
22 | {
23 | public DeviceCommmandEnum CommandType { get; set; }
24 | public string CommandName { get => CommandType.ToString(); }
25 | public DeviceCommand Command { get; set; }
26 |
27 | public DeviceMenuCommand(DeviceCommmandEnum commandType, DeviceCommand command)
28 | {
29 | CommandType = commandType;
30 | Command = command;
31 | }
32 | }
33 |
34 | public enum DeviceCommmandEnum
35 | {
36 | Install,
37 | Rename,
38 | Uninstall,
39 | SetActive,
40 | Toggle
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDReportIdEnum.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | namespace EmuController.Client.NET.PID
21 | {
22 | public enum PIDReportIdEnum
23 | {
24 | // Output report Ids.
25 | SetEffect = 0x10,
26 | SetEnvelope = 0x11,
27 | SetCondition = 0x12,
28 | SetPeriodic = 0x13,
29 | SetConstant = 0x14,
30 | SetRamp = 0x15,
31 | SetCustomForceData = 0x16,
32 | DownloadSample = 0x17,
33 | EffectOperation = 0x18,
34 | DeviceControl = 0x19,
35 | BlockFree = 0x1A,
36 | SetGain = 0x1B,
37 | SetCustomForce = 0x1C,
38 |
39 | // Feature report Ids.
40 | NewEffect = 0x20,
41 | BlockLoad = 0x21,
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/EmuController/MessageProcessor.h:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | EXTERN_C_START
15 |
16 | // Control type ids in input report message
17 | #define INPUT_AXIS 0x10
18 | #define INPUT_BUTTON 0x11
19 | #define INPUT_DPAD 0x12
20 |
21 | // Maximum number of value updates in message for each control type
22 | #define AXIS_COUNT 8
23 | #define BUTTON_SET_COUNT 8
24 | #define DPAD_COUNT 4
25 |
26 | //
27 | // Checks if specified bit in UCHAR value is set.
28 | //
29 | BOOL
30 | IsBitSet(
31 | UCHAR Value,
32 | INT Bit);
33 |
34 |
35 | //
36 | // Deserializes joystick input report message received from named pipe client.
37 | //
38 | VOID
39 | DeserializeJoyInput(
40 | _In_ UCHAR* JoystickInputMessage,
41 | _Out_ JOYSTICK_INPUT_REPORT* Report);
42 |
43 |
44 | //
45 | // Sets the joystick input report to default values.
46 | //
47 | VOID
48 | SetDefaultControllerState(
49 | _Out_ JOYSTICK_INPUT_REPORT* Report);
50 |
51 | EXTERN_C_END
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDSetCustomForceReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDSetCustomForceReport : FFBPacket
24 | {
25 | public byte EffectBlockIndex { get; private set; }
26 | public byte SampleCount { get; private set; }
27 | public ushort SamplePeriod { get; private set; }
28 | public PIDSetCustomForceReport(byte[] packet): base(packet)
29 | {
30 |
31 | }
32 |
33 | protected override void Deserialize()
34 | {
35 | EffectBlockIndex = DataPacket[1];
36 | SampleCount = DataPacket[2];
37 | SamplePeriod = BitConverter.ToUInt16(DataPacket, 3);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/EmuController.Client.NET.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0-windows7.0
5 | 1.0.0.0
6 | 1.0.0.0
7 | Library for communicating with EmuController device
8 | (C) Maris Melbardis 2020
9 | 1.0.0
10 | true
11 | false
12 | x64;x86
13 |
14 |
15 |
16 | x64
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | True
28 | True
29 | Resources.resx
30 |
31 |
32 |
33 |
34 |
35 | ResXFileCodeGenerator
36 | Resources.Designer.cs
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/WMIPnpEntity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Management;
4 | using System.Runtime.Versioning;
5 | using System.Text;
6 |
7 | namespace EmuController.Client.NET
8 | {
9 | public sealed class WMIPnpEntity
10 | {
11 | private static readonly string Scope = "root\\CIMV2";
12 | private const string ClassGuid = "{4DB9B76D-4379-437E-9457-4F00B3090C1F}";
13 | private readonly ManagementObjectSearcher Mos;
14 | private static readonly Lazy
15 | lazy =
16 | new Lazy
17 | (() => new WMIPnpEntity());
18 |
19 | public static WMIPnpEntity Instance { get { return lazy.Value; } }
20 |
21 | private WMIPnpEntity()
22 | {
23 | string queryString = $"SELECT * FROM Win32_PnPEntity WHERE ClassGuid = '{ClassGuid}'";
24 | Mos = new ManagementObjectSearcher(Scope, queryString);
25 | }
26 |
27 | public IList GetEmuControllers()
28 | {
29 | List devices = new List();
30 |
31 | // All active EmuController devices will be returned when quering PnPEntities
32 | // matching EmuController classGuid.
33 | foreach (ManagementObject queryObj in Mos.Get())
34 | {
35 | EmuControllerInfo info = new EmuControllerInfo(queryObj);
36 | devices.Add(info);
37 | }
38 |
39 | return devices;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDDeviceControlReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDDeviceControlReport : FFBPacket
24 | {
25 | public DeviceControlEnum ControlCommand { get; private set; }
26 |
27 | public PIDDeviceControlReport(byte[] packet): base(packet)
28 | {
29 |
30 | }
31 | public enum DeviceControlEnum
32 | {
33 | EnableActuactors = 1,
34 | DisableActuactors = 2,
35 | StopAllEffects = 3,
36 | Reset = 4,
37 | Pause = 5,
38 | Continue = 6
39 | }
40 |
41 | protected override void Deserialize()
42 | {
43 | ControlCommand = (DeviceControlEnum)DataPacket[1];
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDSetRampReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Runtime.InteropServices;
19 | using System.Text;
20 | using System.Threading.Tasks;
21 |
22 | namespace EmuController.Client.NET.PID
23 | {
24 | public class PIDSetRampReport : FFBPacket
25 | {
26 | public byte EffectBlockIndex { get; private set; }
27 | public short RampStart { get; private set; }
28 | public short RampEnd { get; private set; }
29 |
30 | public PIDSetRampReport(byte[] packet): base(packet)
31 | {
32 |
33 | }
34 |
35 | protected override void Deserialize()
36 | {
37 | EffectBlockIndex = DataPacket[1];
38 | ReadOnlySpan packetSpan = MemoryMarshal.Cast(DataPacket);
39 | RampStart = packetSpan[1];
40 | RampEnd = packetSpan[2];
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/EmuController.DevManager/Start.xaml.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Text;
17 | using System.Windows;
18 | using System.Windows.Controls;
19 | using System.Windows.Data;
20 | using System.Windows.Documents;
21 | using System.Windows.Input;
22 | using System.Windows.Media;
23 | using System.Windows.Media.Imaging;
24 | using System.Windows.Navigation;
25 | using System.Windows.Shapes;
26 |
27 | namespace EmuController.DevManager
28 | {
29 | ///
30 | /// Interaction logic for Start.xaml
31 | ///
32 | public partial class Start : Application
33 | {
34 | [STAThread]
35 | public static void Main()
36 | {
37 | using var appLock = new SingleInstanceApplicationLock();
38 | if (!appLock.TryAcquireExclusiveLock())
39 | return;
40 |
41 | Start app = new Start();
42 | app.InitializeComponent();
43 | app.Run();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/Input/ControlCollection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace EmuController.Client.NET.Input
5 | {
6 | public abstract class ControlCollection where T : IComparable, IComparable, IConvertible, IEquatable, IFormattable
7 | {
8 | protected readonly BitArray arrayMap = new BitArray(8);
9 |
10 | internal byte ArrayMap
11 | {
12 | get
13 | {
14 | byte[] b = new byte[1];
15 | arrayMap.CopyTo(b, 0);
16 | return b[0];
17 | }
18 | }
19 |
20 | private int setControls = 0;
21 |
22 | protected T[] values;
23 | public ReadOnlySpan AllValues => values;
24 |
25 | public ReadOnlySpan GetUpdatedValues()
26 | {
27 | if (setControls == 0)
28 | {
29 | return null;
30 | }
31 |
32 | T[] results = new T[setControls];
33 | int index = 0;
34 | for (int i = 0; i < arrayMap.Count; i++)
35 | {
36 | if (arrayMap[i])
37 | {
38 | results[index] = values[i];
39 | index++;
40 | }
41 | }
42 | return results;
43 |
44 | }
45 |
46 | protected void SetValue(int index, T value)
47 | {
48 | if (!arrayMap.Get(index))
49 | {
50 | setControls++;
51 | }
52 | arrayMap.Set(index, true);
53 | values[index] = value;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/EmuController/Queue.h:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | /*++
16 |
17 | Module Name:
18 |
19 | queue.h
20 |
21 | Abstract:
22 |
23 | This file contains the queue definitions.
24 |
25 | Environment:
26 |
27 | User-mode Driver Framework 2
28 |
29 | --*/
30 |
31 | EXTERN_C_START
32 |
33 | //
34 | // This is the context that can be placed per queue
35 | // and would contain per queue information.
36 | //
37 | typedef struct _QUEUE_CONTEXT {
38 |
39 | WDFQUEUE Queue;
40 | PDEVICE_CONTEXT DeviceContext;
41 |
42 | } QUEUE_CONTEXT, *PQUEUE_CONTEXT;
43 |
44 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(QUEUE_CONTEXT, QueueGetContext)
45 |
46 | NTSTATUS
47 | EmuControllerQueueInitialize(
48 | _In_ WDFDEVICE Device,
49 | _Out_ WDFQUEUE *Queue
50 | );
51 |
52 | NTSTATUS
53 | EmuControllerManualQueueInitialize(
54 | _In_ WDFDEVICE Device,
55 | _Out_ WDFQUEUE* Queue
56 | );
57 |
58 | //
59 | // Events from the IoQueue object
60 | //
61 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL EmuControllerEvtIoDeviceControl;
62 |
63 | EXTERN_C_END
64 |
--------------------------------------------------------------------------------
/EmuController.Client.NETTests/EmuController.Client.NETTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0-windows7.0
5 |
6 | false
7 |
8 | x64;x86
9 |
10 |
11 |
12 | x64
13 |
14 |
15 |
16 | x64
17 |
18 |
19 |
20 | x64
21 |
22 |
23 |
24 | x64
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | all
33 | runtime; build; native; contentfiles; analyzers; buildtransitive
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDEffectOperationReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDEffectOperationReport : FFBPacket
24 | {
25 | public byte EffectBlockIndex { get; private set; }
26 | public EffectOpEnum EffectOperation { get; private set; }
27 | public byte LoopCount { get; private set; }
28 |
29 |
30 | public PIDEffectOperationReport(byte[] packet): base(packet)
31 | {
32 |
33 | }
34 |
35 | protected override void Deserialize()
36 | {
37 | EffectBlockIndex = DataPacket[1];
38 | EffectOperation = (EffectOpEnum)DataPacket[2];
39 | LoopCount = DataPacket[3];
40 | }
41 | }
42 | public enum EffectOpEnum
43 | {
44 | Start = 1,
45 | StartSolo = 2,
46 | Stop = 3
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/EmuController.DevManager/Behaviors/MaxCharactersBehavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using Microsoft.Xaml.Behaviors;
15 | using System;
16 | using System.Collections.Generic;
17 | using System.Text;
18 | using System.Windows;
19 | using System.Windows.Input;
20 |
21 | namespace EmuController.DevManager.Behaviors
22 | {
23 | public class MaxCharactersBehavior : Behavior
24 | {
25 | public int MaxCharacters { get; set; }
26 |
27 | protected override void OnAttached()
28 | {
29 | base.OnAttached();
30 | AssociatedObject.PreviewTextInput += AssociatedObject_PreviewTextInput;
31 | }
32 |
33 | protected override void OnDetaching()
34 | {
35 | base.OnDetaching();
36 | AssociatedObject.PreviewTextInput -= AssociatedObject_PreviewTextInput;
37 | }
38 |
39 | private void AssociatedObject_PreviewTextInput(object sender, TextCompositionEventArgs e)
40 | {
41 | e.Handled = ((System.Windows.Controls.TextBox)e.OriginalSource).Text.Length >= MaxCharacters;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDSetCustomForceDataReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Collections.ObjectModel;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDSetCustomForceDataReport : FFBPacket
24 | {
25 | private const int DataLength = 12;
26 | public byte EffectBlockIndex { get; private set; }
27 | public ushort DataOffset { get; private set; }
28 |
29 | public ReadOnlyCollection Data => new ReadOnlyCollection(data);
30 |
31 | private byte[] data;
32 | public PIDSetCustomForceDataReport(byte[] packet): base(packet)
33 | {
34 |
35 | }
36 |
37 | protected override void Deserialize()
38 | {
39 | EffectBlockIndex = DataPacket[1];
40 | DataOffset = BitConverter.ToUInt16(DataPacket, 2);
41 |
42 | ReadOnlySpan packetSpan = DataPacket;
43 | data = packetSpan[4..].ToArray();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/Input/DPads.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System.Linq;
15 |
16 | namespace EmuController.Client.NET.Input
17 | {
18 | public class DPads : ControlCollection
19 | {
20 | internal DPads()
21 | {
22 | values = Enumerable.Repeat((byte)0xFF, 4).ToArray();
23 | }
24 |
25 | ///
26 | /// Set value for DPad with the specified index.
27 | ///
28 | /// Index of the DPad
29 | /// Cardinal Direction
30 | public void SetValue(int index, DPadDirectionEnum direction)
31 | {
32 | SetValue(index, (byte)direction);
33 | }
34 | }
35 |
36 | ///
37 | /// DPad values expressed as Cardinal directions
38 | ///
39 | public enum DPadDirectionEnum
40 | {
41 | Null = -1,
42 | North = 0,
43 | NorthEast = 1,
44 | East = 2,
45 | SouthEast = 3,
46 | South = 4,
47 | SouthWest = 5,
48 | West = 6,
49 | NorthWest = 7
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/EmuController.DevManager/XmlSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.IO;
17 | using System.Text;
18 | using System.Xml.Serialization;
19 |
20 | namespace EmuController.DevManager
21 | {
22 | public class XmlSerializer
23 | {
24 | private readonly Type type;
25 |
26 | public XmlSerializer()
27 | {
28 | type = typeof(T);
29 | }
30 |
31 | public void Save(string path, object obj)
32 | {
33 | using TextWriter textWriter = new StreamWriter(path);
34 | XmlSerializer serializer = new XmlSerializer(type);
35 | serializer.Serialize(textWriter, obj);
36 |
37 | }
38 |
39 | public T Read(string path)
40 | {
41 | T result;
42 | using (TextReader textReader = new StreamReader(Path.GetFullPath(path)))
43 | {
44 | XmlSerializer deserializer = new XmlSerializer(type);
45 | result = (T)deserializer.Deserialize(textReader);
46 | }
47 | return result;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/Input/Buttons.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections;
16 | using System.Collections.Generic;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.Input
22 | {
23 | public class Buttons : ControlCollection
24 | {
25 | internal Buttons()
26 | {
27 | values = new ushort[8];
28 | }
29 |
30 |
31 | ///
32 | /// Set state for button with the specified index.
33 | ///
34 | ///
35 | ///
36 |
37 | public void SetValue(int index, bool pressed)
38 | {
39 | int arrayIndex = index / 16;
40 | int bit = index % 16;
41 | int result = values[arrayIndex];
42 | if (pressed)
43 | {
44 | result |= 1 << bit;
45 | }
46 | else
47 | {
48 | result &= ~(1 << bit);
49 | }
50 |
51 | SetValue(arrayIndex, (ushort)result);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDSetPeriodicReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Runtime.InteropServices;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDSetPeriodicReport : FFBPacket
24 | {
25 | public byte EffectBlockIndex { get; private set; }
26 | public ushort Magnitude { get; private set; }
27 | public short Offset { get; private set; }
28 | public ushort Phase { get; private set; }
29 | public ushort Period { get; private set; }
30 | public PIDSetPeriodicReport(byte[] packet): base(packet)
31 | {
32 |
33 | }
34 |
35 | protected override void Deserialize()
36 | {
37 | EffectBlockIndex = DataPacket[1];
38 | ReadOnlySpan packetSpan = MemoryMarshal.Cast(DataPacket);
39 | Magnitude = packetSpan[1];
40 | Offset = BitConverter.ToInt16(DataPacket, 4);
41 | Phase = packetSpan[3];
42 | Period = packetSpan[4];
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/PID/PIDSetEnvelopeReport.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Runtime.InteropServices;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 |
21 | namespace EmuController.Client.NET.PID
22 | {
23 | public class PIDSetEnvelopeReport : FFBPacket
24 | {
25 | public byte EffectBlockIndex { get; private set; }
26 | public ushort AttackLevel { get; private set; }
27 | public ushort FadeLevel { get; private set; }
28 | public ushort AttackTime { get; private set; }
29 | public ushort FadeTime { get; private set; }
30 | public PIDSetEnvelopeReport(byte[] packet): base(packet)
31 | {
32 |
33 | }
34 |
35 | protected override void Deserialize()
36 | {
37 |
38 | ReadOnlySpan packetSpan = MemoryMarshal.Cast(DataPacket);
39 |
40 | EffectBlockIndex = DataPacket[1];
41 | AttackLevel = packetSpan[1];
42 | FadeLevel = packetSpan[2];
43 | AttackTime = packetSpan[3];
44 | FadeTime = packetSpan[4];
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/EmuController.Client.NET/Utils.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using Microsoft.Win32;
15 | using System;
16 | using System.Globalization;
17 |
18 | namespace EmuController.Client.NET
19 | {
20 | public static class Utils
21 | {
22 | public static string GetStringFromRegistry(string regPath, string regKeyName)
23 | {
24 | RegistryKey key = null;
25 | string res = string.Empty;
26 | try
27 | {
28 | key = Registry.CurrentUser.OpenSubKey(regPath);
29 | if (key != null)
30 | {
31 | res = (string)key.GetValue(regKeyName);
32 | }
33 | }
34 | finally
35 | {
36 | if (key != null)
37 | {
38 | key.Dispose();
39 | }
40 | }
41 |
42 | return res;
43 | }
44 | public static bool IsBitSet(T b, int pos) where T :
45 | IComparable, IComparable,
46 | IConvertible, IEquatable,
47 | IFormattable
48 | {
49 | long val = b.ToInt64(CultureInfo.CurrentCulture);
50 | return (val & (1 << pos)) != 0;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/EmuController/ReadMe.txt:
--------------------------------------------------------------------------------
1 | ========================================================================
2 | EmuController Project Overview
3 | ========================================================================
4 |
5 | This file contains a summary of what you will find in each of the files that make up your project.
6 |
7 | EmuController.vcxproj
8 | This is the main project file for projects generated using an Application Wizard.
9 | It contains information about the version of the product that generated the file, and
10 | information about the platforms, configurations, and project features selected with the
11 | Application Wizard.
12 |
13 | EmuController.vcxproj.filters
14 | This is the filters file for VC++ projects generated using an Application Wizard.
15 | It contains information about the association between the files in your project
16 | and the filters. This association is used in the IDE to show grouping of files with
17 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the
18 | "Source Files" filter).
19 |
20 | Public.h
21 | Header file to be shared with applications.
22 |
23 | Driver.c & Driver.h
24 | DriverEntry and WDFDRIVER related functionality and callbacks.
25 |
26 | Device.c & Device.h
27 | WDFDEVICE related functionality and callbacks.
28 |
29 | Queue.c & Queue.h
30 | WDFQUEUE related functionality and callbacks.
31 |
32 | Ioctl.c & Ioctl.h
33 | Functionality for handling various input/output control calls.
34 |
35 | NamedPipeServer.c & NamedPipeServer.h
36 | Functionality for setting up a side-communication with driver via two named pipe server instances.
37 |
38 | MessageProcessor.c & MessageProcessor.h
39 | Functionality for processing messages from input client that contains non-complete input report updates.
40 |
41 | Trace.h
42 | Definitions for WPP tracing.
43 |
--------------------------------------------------------------------------------
/EmuController.DevManager/Commands/DeviceCommand.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Maris Melbardis
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | using System;
15 | using System.Windows.Input;
16 |
17 | namespace EmuController.DevManager.Commands
18 | {
19 | public class DeviceCommand : ICommand
20 | {
21 | public DeviceCommand(Action