Skip to content

Commit

Permalink
Changed targeted .NET version to Framework 4.8 (same as MobiFlight Co…
Browse files Browse the repository at this point in the history
…nnector)

Fixed base button zero-indexing (now one-indexed like all good buttons do)
  • Loading branch information
cbrauers committed May 30, 2024
1 parent cc4558f commit 373d921
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 95 deletions.
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
108 changes: 79 additions & 29 deletions VKB-Mobiflight-Definer.csproj
Original file line number Diff line number Diff line change
@@ -1,73 +1,123 @@
<Project Sdk="Microsoft.NET.Sdk">

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<RootNamespace>VKB_Mobiflight_Definer</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Nullable>disable</Nullable>
<ProjectGuid>{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}</ProjectGuid>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup>
<StartupObject>VKB_Mobiflight_Definer.Program</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HidSharp" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
<None Update="Bases.csv">
<None Include="Bases.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\EVO.csv">
<None Include="Buttons\EVO.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\FSMGA.csv">
<None Include="Buttons\FSMGA.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\NXT.csv">
<None Include="Buttons\NXT.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\SEM.csv">
<None Include="Buttons\SEM.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\STECS.csv">
<None Include="Buttons\STECS.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\STECS_ATEM.csv">
<None Include="Buttons\STECS_ATEM.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\STEM.csv">
<None Include="Buttons\STEM.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\THQ.csv">
<None Include="Buttons\THQ.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Buttons\THQ_WW2.csv">
<None Include="Buttons\THQ_WW2.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="LEDs\FSMGA.csv">
<None Include="LEDs\FSMGA.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="LEDs\SCG.csv">
<None Include="LEDs\NXT.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="LEDs\SEM.csv">
<None Include="LEDs\SCG.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="LEDs\STECS.csv">
<None Include="LEDs\SEM.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="LEDs\NXT.csv">
<None Include="LEDs\STECS.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="LEDs\STEM.csv">
<None Include="LEDs\STEM.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Modules.csv">
<None Include="Modules.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>

<ItemGroup>
<Folder Include="output\" />
</ItemGroup>

</Project>
<ItemGroup>
<Reference Include="HidSharp, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\HidSharp.2.1.0\lib\net35\HidSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="src\Base.cs" />
<Compile Include="src\BaseArchetype.cs" />
<Compile Include="src\Button.cs" />
<Compile Include="src\JoystickDevice.cs" />
<Compile Include="src\Led.cs" />
<Compile Include="src\Module.cs" />
<Compile Include="src\ModuleArchetype.cs" />
<Compile Include="src\Program.cs" />
<Compile Include="src\SubDevice.cs" />
<Compile Include="src\SubDeviceArchetype.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
12 changes: 6 additions & 6 deletions VKB-Mobiflight-Definer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VKB-Mobiflight-Definer", "V
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Debug|AnyCPU = Debug|AnyCPU
Release|AnyCPU = Release|AnyCPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}.Release|Any CPU.Build.0 = Release|Any CPU
{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{58BEFDE8-1FDF-45CA-9A9E-3706D12A1CC7}.Release|AnyCPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HidSharp" version="2.1.0" targetFramework="net48" />
</packages>
6 changes: 5 additions & 1 deletion src/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

namespace VKB_Mobiflight_Definer
{
internal class Base(string DescName, string ButtonFile, string LedFile) : SubDevice(DescName, ButtonFile, LedFile)
internal class Base : SubDevice
{
public Base(string DescName, string ButtonFile, string LedFile) : base(DescName, ButtonFile, LedFile)
{
}

public static Base FromCsv(string csv)
{
string[] csvparts = csv.Split(',');
Expand Down
8 changes: 6 additions & 2 deletions src/BaseArchetype.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
namespace VKB_Mobiflight_Definer
{
internal class BaseArchetype(string DescName, string ButtonFile, string LedFile) : SubDeviceArchetype(DescName, ButtonFile, LedFile)
internal class BaseArchetype : SubDeviceArchetype
{
public Base Instantiate() => new(DescriptiveName, ButtonFileName, LedFileName);
public BaseArchetype(string DescName, string ButtonFile, string LedFile) : base(DescName, ButtonFile, LedFile)
{
}

public Base Instantiate() => new Base(DescriptiveName, ButtonFileName, LedFileName);
public static BaseArchetype FromCsv(string csv)
{
string[] csvparts = csv.Split(',');
Expand Down
17 changes: 12 additions & 5 deletions src/Button.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VKB_Mobiflight_Definer
{
internal class Button(int number, string label)
internal class Button
{
private readonly int buttonNoInSubDevice = number;
private readonly string buttonBaseLabel = label;
public int buttonBaseId = 0;
private readonly int buttonNoInSubDevice;
private readonly string buttonBaseLabel;
public int buttonBaseId = 1;
public string buttonLabelPrefix = "";

public Button(int number, string label)
{
buttonNoInSubDevice = number;
buttonBaseLabel = label;
}

public static Button FromCsv(string csv)
{
string[] csvparts = csv.Split(",");
string[] csvparts = csv.Split(',');
int buttonNo = ((int)Convert.ToDecimal(csvparts[0]));
string label = csvparts[1];
return new Button(buttonNo, label);
Expand Down
26 changes: 17 additions & 9 deletions src/JoystickDevice.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
using HidSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VKB_Mobiflight_Definer
{
internal class JoystickDevice(HidDevice device)
internal class JoystickDevice
{
public readonly int Pid = device.ProductID;
public readonly string InstanceName = device.GetProductName();
private Base? BaseType;
private readonly List<Module> Modules = [];
public readonly int Pid;
public readonly string InstanceName;
private Base BaseType = null;
private readonly List<Module> Modules = new List<Module>();

public JoystickDevice(HidDevice device)
{
Pid = device.ProductID;
InstanceName = device.GetProductName();
}

public void SetBase(Base baseref)
{
BaseType = baseref;
Expand All @@ -34,8 +42,8 @@ public Module AddModule(ModuleArchetype arch)
}
public List<Button> GetButtons()
{
if (BaseType == null) return [];
List<Button> ret = new(BaseType.GetButtons());
if (BaseType == null) return new List<Button>();
List<Button> ret = new List<Button>(BaseType.GetButtons());
foreach (var module in Modules)
{
ret.AddRange(module.GetButtons());
Expand All @@ -44,8 +52,8 @@ public List<Button> GetButtons()
}
public List<Led> GetLeds()
{
if (BaseType == null) return [];
List<Led> ret = new(BaseType.GetLeds());
if (BaseType == null) return new List<Led>();
List<Led> ret = new List<Led>(BaseType.GetLeds());
foreach (var module in Modules)
{
ret.AddRange(module.GetLeds());
Expand Down
41 changes: 29 additions & 12 deletions src/Led.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VKB_Mobiflight_Definer
{
internal class Led(int number, string colors, string label, string id)
internal class Led
{
private readonly int ledNoInSubDevice = number;
private readonly string ledBaseLabel = label;
private readonly string ledBaseId = id;
private readonly int ledNoInSubDevice;
private readonly string ledBaseLabel;
private readonly string ledBaseId;
public int ledBaseNo = 1;
public string ledLabelPrefix = "";
public string ledIdPrefix = "";
private readonly string colorChannels = colors;
private readonly string colorChannels;

public Led(int number, string colors, string label, string id)
{
ledNoInSubDevice = number;
ledBaseLabel = label;
ledBaseId = id;
colorChannels = colors;
}

public static Led FromCsv(string csv)
{
string[] csvparts = csv.Split(",");
string[] csvparts = csv.Split(',');
int buttonNo = ((int)Convert.ToDecimal(csvparts[0]));
string colors = csvparts[1];
string label = csvparts[2];
Expand Down Expand Up @@ -65,13 +74,21 @@ public string GetLedId(char channel)
return GetLedId() + "." + ColorName(channel);
}
}
private static string ColorName(char channel) => channel switch
private static string ColorName(char channel)
{
'R' => "Red",
'G' => "Green",
'B' => "Blue",
_ => string.Format("{0}", channel),
};
switch (channel)
{
case 'R':
return "Red";
case 'G':
return "Green";
case 'B':
return "Blue";
default:
return string.Format("{0}", channel);
}
}

public void WriteOut(StreamWriter sw)
{
int channelno = 0;
Expand Down
13 changes: 10 additions & 3 deletions src/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@

namespace VKB_Mobiflight_Definer
{
internal class Module(string DescName, string Label, string Id, string ButtonFile, string LedFile) : SubDevice(DescName, ButtonFile, LedFile)
internal class Module : SubDevice
{
public string LabelPrefix = Label;
public string IdPrefix = Id;
public string LabelPrefix;
public string IdPrefix;
public int LedBase = 10;
public int ButtonBase = 1;

public Module(string DescName, string Label, string Id, string ButtonFile, string LedFile) : base(DescName, ButtonFile, LedFile)
{
LabelPrefix = Label;
IdPrefix = Id;
}

public static Module FromCsv(string csv)
{
string[] csvparts = csv.Split(',');
Expand Down
Loading

0 comments on commit 373d921

Please sign in to comment.