Skip to content

Commit

Permalink
Develop (#68)
Browse files Browse the repository at this point in the history
* now supports both 4.35 DX32 and 4.36 DX128 key mapping

* DRY but I don't know if it is a good way

* added comment

* fixed AB/IDLE detent bytes to little endian

* Fixed AB/IDLE detent when throttle axis is inverted.

* Fixed throttle invert doesn't apply AB/IDLE position properly

* formatting

* invelid value check and format

* Removed resorting device order by assigned callback numbers as it may causing some issues. Also no more needed as 4.36 supports DX128 * 16 devices.
  • Loading branch information
chihirobelmo authored Jul 1, 2022
1 parent 34059fb commit 6f884b8
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 44 deletions.
3 changes: 3 additions & 0 deletions Falcon BMS Alternative Launcher/Input/CommonConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ public static class CommonConstants

public static readonly int AXISMIN = 0;
public static readonly int AXISMAX = 65536;

public static readonly int BINAXISMIN = 0;
public static readonly int BINAXISMAX = 15000;
}
}
11 changes: 6 additions & 5 deletions Falcon BMS Alternative Launcher/Input/JoyAssgn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ public string GetDeviceSortingLine()

/// <summary>
/// Get whole DX button assignment line to write a key file.
/// DXnumber: total DXnumber per device BMS can handle.
/// </summary>
public string GetKeyLineDX(int joynum, int numOfDevices)
public string GetKeyLineDX(int joynum, int numOfDevices, int DXnumber)
{
string assign = "";
assign += "\n#======== " + GetProductName() + " ========\n";
Expand All @@ -212,15 +213,15 @@ public string GetKeyLineDX(int joynum, int numOfDevices)
if (ii != 0)
continue;
assign += dx[i].assign[ii].GetCallback();
assign += " " + (joynum * CommonConstants.DX128 + i);
assign += " " + (joynum * DXnumber + i);
assign += " " + (int)Invoke.Default;
assign += " " + "-2";
assign += " " + "0";
assign += " " + "0x0";
assign += " " + dx[i].assign[ii].GetSoundID();
assign += "\n";
assign += dx[i].assign[ii].GetCallback();
assign += " " + (numOfDevices * CommonConstants.DX128 + joynum * CommonConstants.DX128 + i);
assign += " " + (numOfDevices * DXnumber + joynum * DXnumber + i);
assign += " " + (int)Invoke.Default;
assign += " " + "-2";
assign += " " + "0";
Expand All @@ -233,9 +234,9 @@ public string GetKeyLineDX(int joynum, int numOfDevices)
assign += dx[i].assign[ii].GetCallback();

if (ii == CommonConstants.DX_PRESS | ii == CommonConstants.DX_RELEASE)
assign += " " + (joynum * CommonConstants.DX128 + i);
assign += " " + (joynum * DXnumber + i);
if (ii == CommonConstants.DX_PRESS_SHIFT | ii == CommonConstants.DX_RELEASE_SHIFT)
assign += " " + (numOfDevices * CommonConstants.DX128 + joynum * CommonConstants.DX128 + i);
assign += " " + (numOfDevices * DXnumber + joynum * DXnumber + i);

assign += " " + (int)dx[i].assign[ii].GetInvoke();
assign += " " + "-2";
Expand Down
29 changes: 16 additions & 13 deletions Falcon BMS Alternative Launcher/Override/OverrideSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public void Execute(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile k
if (!Directory.Exists(appReg.GetInstallDir() + "/User/Config/Backup/"))
Directory.CreateDirectory(appReg.GetInstallDir() + "/User/Config/Backup/");

MainWindow.deviceControl.SortDevice();

SaveAxisMapping(inGameAxis, deviceControl);
SaveJoystickCal(inGameAxis, deviceControl);
SaveDeviceSorting(deviceControl);
Expand Down Expand Up @@ -202,10 +200,7 @@ protected void SaveDeviceSorting(DeviceControl deviceControl)
ds.Close();
}

/// <summary>
/// As the name implies...
/// </summary>
protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile, int DXnumber)
{
string filename = appReg.GetInstallDir() + "/User/Config/" + appReg.getAutoKeyFileName();

Expand All @@ -218,14 +213,19 @@ protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl device
sw.Write(keyFile.keyAssign[i].GetKeyLine());
for (int i = 0; i < deviceControl.joyAssign.Length; i++)
{
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length));
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, DXnumber));
// PRIMARY DEVICE POV
if (((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == i)
sw.Write(deviceControl.joyAssign[i].GetKeyLinePOV());
}
sw.Close();
}

protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
{
SaveKeyMapping(inGameAxis, deviceControl, keyFile, CommonConstants.DX32);
}

/// <summary>
/// Overwrite callsign.pop file.
/// </summary>
Expand Down Expand Up @@ -443,17 +443,20 @@ protected virtual void SaveJoystickCal(Hashtable inGameAxis, DeviceControl devic
double iAB = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetAB();
double iIdle = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetIDLE();

const double MAXIN = 65536;
const double MAXOUT = 14848;
iAB = iAB * CommonConstants.BINAXISMAX / CommonConstants.AXISMAX;
iIdle = iIdle * CommonConstants.BINAXISMAX / CommonConstants.AXISMAX;

iAB = -iAB * (MAXOUT / MAXIN) + MAXOUT;
iIdle = -iIdle * (MAXOUT / MAXIN) + MAXOUT;
if (((InGameAxAssgn)inGameAxis[nme.ToString()]).GetInvert() == false)
{
iAB = CommonConstants.BINAXISMAX - iAB;
iIdle = CommonConstants.BINAXISMAX - iIdle;
}

byte[] ab = BitConverter.GetBytes((int)iAB).Reverse().ToArray();
byte[] idle = BitConverter.GetBytes((int)iIdle).Reverse().ToArray();

bs[1] = ab[1];
bs[5] = idle[1];
bs[1] = ab[2];
bs[5] = idle[2];
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions Falcon BMS Alternative Launcher/Override/OverrideSettingFor434.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

Expand Down Expand Up @@ -58,20 +59,23 @@ protected override void SaveJoystickCal(Hashtable inGameAxis, DeviceControl devi
{
if (((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber() >= 0)
{
double iAB = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetAB();
double iAB = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetAB();
double iIdle = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetIDLE();

const double MAXIN = 65536;
const double MAXOUT = 14848;
iAB = iAB * CommonConstants.BINAXISMAX / CommonConstants.AXISMAX;
iIdle = iIdle * CommonConstants.BINAXISMAX / CommonConstants.AXISMAX;

iAB = -iAB * (MAXOUT / MAXIN) + MAXOUT;
iIdle = -iIdle * (MAXOUT / MAXIN) + MAXOUT;
if (((InGameAxAssgn)inGameAxis[nme.ToString()]).GetInvert() == false)
{
iAB = CommonConstants.BINAXISMAX - iAB;
iIdle = CommonConstants.BINAXISMAX - iIdle;
}

byte[] ab = BitConverter.GetBytes((int)iAB);
byte[] idle = BitConverter.GetBytes((int)iIdle);
byte[] ab = BitConverter.GetBytes((int)iAB).Reverse().ToArray();
byte[] idle = BitConverter.GetBytes((int)iIdle).Reverse().ToArray();

bs[1] = ab[1];
bs[5] = idle[1];
bs[1] = ab[2];
bs[5] = idle[2];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void SaveConfigfile(Hashtable inGameAxis, DeviceControl devic
cfg.Close();
}

protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile, int DXnumber)
{
string filename = appReg.GetInstallDir() + "/User/Config/" + appReg.getAutoKeyFileName();

Expand All @@ -72,7 +72,7 @@ protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl devic
sw.Write(keyFile.keyAssign[i].GetKeyLine());
for (int i = 0; i < deviceControl.joyAssign.Length; i++)
{
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length));
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, DXnumber));
// PRIMARY DEVICE POV
if (((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == i && ((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == ((InGameAxAssgn)inGameAxis["Throttle"]).GetDeviceNumber())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ protected override void SaveConfigfile(Hashtable inGameAxis, DeviceControl devic
cfg.Write("set g_nPOV2ID 0 // SETUP OVERRIDE\r\n");
cfg.Close();
}

protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
{
SaveKeyMapping(inGameAxis, deviceControl, keyFile, CommonConstants.DX128);
}
}
}
30 changes: 18 additions & 12 deletions Falcon BMS Alternative Launcher/Windows/AxisAssignWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,25 +518,31 @@ private void SetAB_Click(object sender, RoutedEventArgs e)
{
if (status != Status.ShowAxisStatus)
return;
int ABposition;
ABposition = CommonConstants.AXISMAX - MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp);
if (MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp) > CommonConstants.AXISMAX)
ABposition = CommonConstants.AXISMAX;
AB = ABposition;
if (AB > CommonConstants.AXISMAX - CommonConstants.AXISMAX / 128)

if (Invert.IsChecked == true)
AB = CommonConstants.AXISMIN + MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp);
else
AB = CommonConstants.AXISMAX - MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp);

if (AB > CommonConstants.AXISMAX)
AB = CommonConstants.AXISMAX;
if (AB < CommonConstants.AXISMIN)
AB = CommonConstants.AXISMIN;
}

private void SetIDLE_Click(object sender, RoutedEventArgs e)
{
if (status != Status.ShowAxisStatus)
return;
int IDLEposition;
IDLEposition = CommonConstants.AXISMAX - MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp);
if (MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp) < 0)
IDLEposition = CommonConstants.AXISMIN;
IDLE = IDLEposition;
if (IDLE < CommonConstants.AXISMAX / 128)

if (Invert.IsChecked == true)
IDLE = CommonConstants.AXISMIN + MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp);
else
IDLE = CommonConstants.AXISMAX - MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp);

if (IDLE > CommonConstants.AXISMAX)
IDLE = CommonConstants.AXISMAX;
if (IDLE < CommonConstants.AXISMIN)
IDLE = CommonConstants.AXISMIN;
}

Expand Down
1 change: 0 additions & 1 deletion Falcon BMS Alternative Launcher/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ public void ReloadDevices()
{
// Get Devices
deviceControl = new DeviceControl(appReg);
deviceControl.SortDevice();

neutralButtons = new NeutralButtons[deviceControl.joyAssign.Length];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ private void DataGrid_MouseButtonDoubleClick(object sender, MouseButtonEventArgs
return;

KeyMappingWindow.ShowKeyMappingWindow(this, selectedItem, keyFile, deviceControl, sender);

deviceControl.SortDevice();
ResortDevices();

KeyMappingGrid.Items.Refresh();
Expand Down

0 comments on commit 6f884b8

Please sign in to comment.