Skip to content

Commit

Permalink
- ah64 auto seat detection
Browse files Browse the repository at this point in the history
- ah64 guard receiver option
- lua: read display
- lua: get param
  • Loading branch information
FalcoGer committed May 16, 2024
1 parent 2a0f815 commit 289b96e
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 137 deletions.
1 change: 1 addition & 0 deletions CoordinateConverter/CoordinateConverter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<Compile Include="GitHub\Version.cs" />
<EmbeddedResource Include="DCS\Tools\FormAH64DTC.resx">
<DependentUpon>FormAH64DTC.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="DCS\Tools\FormAH64PointDeleter.resx">
<DependentUpon>FormAH64PointDeleter.cs</DependentUpon>
Expand Down
102 changes: 82 additions & 20 deletions CoordinateConverter/DCS/Aircraft/AH64/AH64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,42 @@ namespace CoordinateConverter.DCS.Aircraft.AH64
/// <seealso cref="DCSAircraft" />
public class AH64 : DCSAircraft
{
private bool? isPilot = null;

/// <summary>
/// Gets or sets a value indicating whether the user is in the pilot or CPG seat.
/// </summary>
/// <value>
/// <c>true</c> if this instance is pilot; otherwise, <c>false</c>.
/// </value>
public bool IsPilot { get; private set; }
public bool? IsPilot {
get
{
DCSMessage message = new DCSMessage()
{
GetHandleData = new List<string>()
{
"SEAT"
},
};
message = DCSConnection.SendRequest(message);
if (message != null && message.HandleData.ContainsKey("SEAT"))
{
isPilot = message.HandleData["SEAT"] == "0";
}

return isPilot;
} private set
{
isPilot = value;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="AH64"/> class.
/// </summary>
/// <param name="isPilot">if set to <c>true</c> [is pilot].</param>
public AH64(bool isPilot)
public AH64()
{
IsPilot = isPilot;
}

/// <summary>
Expand Down Expand Up @@ -80,6 +101,42 @@ public enum EDeviceCode

}

/// <summary>
/// Display codes.
/// </summary>
public enum EDisplayCodes
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
PLT_EUFD = 17,
PLT_HMD = 21,
PLT_MFD_Left = 6,
PLT_MFD_Right = 8,
PLT_CMWS = 24,
CPG_MFD_Left = 10,
CPG_MFD_Right = 12,
CPG_EUFD = 18,
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

}

/// <summary>
/// Display characters with special meanings
/// </summary>
public enum EDisplaySpecialChars
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
IDM_Both = '~',
IDM_Own = '[',
IDM_Other = ']',
RTS_Own = '<',
RTS_Other = '>',
RTS_None = '=',
Squelch = '*',
MFD_Circle_Off = '}',
MFD_Circle_On = '{',
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}

/// <summary>
/// Key codes
/// </summary>
Expand Down Expand Up @@ -442,34 +499,36 @@ protected override List<DCSCommand> GetActions(object item)
throw new ArgumentException("Bad Point Type");
}
}
bool plt = IsPilot ?? true;
int mfd = (int)(plt ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD);

// DebugCommandList commands = new DebugCommandList
List<DCSCommand> commands = new List<DCSCommand>
{
// press ADD
new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)EKeyCode.MFD_L2),
new DCSCommand(mfd, (int)EKeyCode.MFD_L2),
// press the waypoint type button
extraData == null ? null : new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)keyMFDPointType),
extraData == null ? null : new DCSCommand(mfd, (int)keyMFDPointType),
// press ident
new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)EKeyCode.MFD_L1)
new DCSCommand(mfd, (int)EKeyCode.MFD_L1)
};
// enter ident
commands.AddRange(GetCommandsForKUText(ident, false, IsPilot));
commands.AddRange(GetCommandsForKUText(ident, false, plt));
// enter free text (max 3 chars)
commands.AddRange(GetCommandsForKUText((coordinate.Name.Length <= 3 ? coordinate.Name : coordinate.Name.Substring(0, 3)) + '\n', false, IsPilot));
commands.AddRange(GetCommandsForKUText((coordinate.Name.Length <= 3 ? coordinate.Name : coordinate.Name.Substring(0, 3)) + '\n', false, plt));
// enter MGRS coordinates
// remove spaces and append enter
string mgrsString = string.Join(string.Empty ,coordinate.GetCoordinateStrMGRS(4).Where(ch => ch != ' ')) + '\n';
commands.AddRange(GetCommandsForKUText(mgrsString, true, IsPilot));
commands.AddRange(GetCommandsForKUText(mgrsString, true, plt));

// enter altitude
if (coordinate.AltitudeInFt == 0 && coordinate.AltitudeIsAGL)
{
commands.AddRange(GetCommandsForKUText("\n", false, IsPilot));
commands.AddRange(GetCommandsForKUText("\n", false, plt));
}
else
{
commands.AddRange(GetCommandsForKUText(((int)Math.Round(coordinate.GetAltitudeValue(true))).ToString() + "\n", true, IsPilot));
commands.AddRange(GetCommandsForKUText(((int)Math.Round(coordinate.GetAltitudeValue(true))).ToString() + "\n", true, plt));
}
return commands;
}
Expand Down Expand Up @@ -520,6 +579,7 @@ public static bool GetIsValidTextForKU(string text, uint minLength = 1, uint max
/// <returns>The list of commands that is required to enter the text into the KU</returns>
public static List<DCSCommand> GetCommandsForKUText(string text, bool clearFirst, bool IsPilot)
{
int ku = (int)(IsPilot ? EDeviceCode.PLT_KU : EDeviceCode.CPG_KU);
List<DCSCommand> commands = new List<DCSCommand>();
// DebugCommandList commands = new DebugCommandList();
if (text == null)
Expand All @@ -529,7 +589,7 @@ public static List<DCSCommand> GetCommandsForKUText(string text, bool clearFirst

if (clearFirst)
{
commands.Add(new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_KU : EDeviceCode.CPG_KU), (int)EKeyCode.KU_CLR));
commands.Add(new DCSCommand(ku, (int)EKeyCode.KU_CLR));
}
// type the text
EKeyCode? prevKeyCode = null;
Expand Down Expand Up @@ -578,7 +638,7 @@ public static List<DCSCommand> GetCommandsForKUText(string text, bool clearFirst
{
commands.Last().Delay = 250;
}
commands.Add(new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_KU : EDeviceCode.CPG_KU), (int)keyCode.Value));
commands.Add(new DCSCommand(ku, (int)keyCode.Value));
prevKeyCode = keyCode;
}
}
Expand All @@ -596,7 +656,7 @@ protected override List<DCSCommand> GetPostActions()
return new List<DCSCommand>()
{
// press TSD to reset the screen
new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)EKeyCode.MFD_TSD)
new DCSCommand((int)((IsPilot ?? true) ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)EKeyCode.MFD_TSD)
};
}

Expand All @@ -608,14 +668,15 @@ protected override List<DCSCommand> GetPostActions()
/// </returns>
protected override List<DCSCommand> GetPreActions()
{
bool plt = IsPilot ?? true;
return new List<DCSCommand>
{
// press TSD
new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)EKeyCode.MFD_TSD),
new DCSCommand((int)(plt ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)EKeyCode.MFD_TSD),
// go to point page
new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)EKeyCode.MFD_B6),
new DCSCommand((int)(plt ? EDeviceCode.PLT_RMFD : EDeviceCode.CPG_RMFD), (int)EKeyCode.MFD_B6),
// clear KU
new DCSCommand((int)(IsPilot ? EDeviceCode.PLT_KU : EDeviceCode.CPG_KU), (int)EKeyCode.KU_CLR),
new DCSCommand((int)(plt ? EDeviceCode.PLT_KU : EDeviceCode.CPG_KU), (int)EKeyCode.KU_CLR),
};
}

Expand Down Expand Up @@ -662,14 +723,15 @@ public override List<string> GetPointOptionsForType(string pointTypeStr)
public int ClearPoints(EPointType pointType, int startIdx, int endIdx)
{
List<DCSCommand> commands = new List<DCSCommand>();
int deviceId = IsPilot ? (int)EDeviceCode.PLT_RMFD : (int)EDeviceCode.CPG_RMFD;
bool plt = IsPilot ?? true;
int deviceId = plt ? (int)EDeviceCode.PLT_RMFD : (int)EDeviceCode.CPG_RMFD;

for (int pointIdx = startIdx; pointIdx <= endIdx ; pointIdx++)
{
commands.Add(new DCSCommand(deviceId, (int)EKeyCode.MFD_TSD)); // Reset to TSD after every point, to avoid weirdness.
commands.Add(new DCSCommand(deviceId, (int)EKeyCode.MFD_B6)); // Point
commands.Add(new DCSCommand(deviceId, (int)EKeyCode.MFD_L1)); // Point >
commands.AddRange(GetCommandsForKUText(pointType.ToString().First() + pointIdx.ToString() + "\n", true, IsPilot)); // Enter point identifier
commands.AddRange(GetCommandsForKUText(pointType.ToString().First() + pointIdx.ToString() + "\n", true, plt)); // Enter point identifier
commands.Add(new DCSCommand(deviceId, (int)EKeyCode.MFD_L4)); // Del
commands.Add(new DCSCommand(deviceId, (int)EKeyCode.MFD_L3)); // Yes
}
Expand Down
63 changes: 60 additions & 3 deletions CoordinateConverter/DCS/Aircraft/AH64/AH64DTCData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using CoordinateConverter.DCS.Communication;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -180,7 +181,8 @@ public bool ContainsTuningData
|| UHFTuneSetting != ETuneSetting.No_Change
|| FM1TuneSetting != ETuneSetting.No_Change
|| FM2TuneSetting != ETuneSetting.No_Change
|| HFTuneSetting != ETuneSetting.No_Change;
|| HFTuneSetting != ETuneSetting.No_Change
|| UHFGuardReceiver != EUHFGuardReceiver.No_Change;
}
}

Expand Down Expand Up @@ -247,6 +249,33 @@ public decimal VHFManualFrequency
/// The uhf tune setting.
/// </value>
public ETuneSetting UHFTuneSetting { get; set; } = ETuneSetting.No_Change;

/// <summary>
/// Whether the UHF Guard receiver is on or off
/// </summary>
public enum EUHFGuardReceiver
{
/// <summary>
/// Guard receiver stays in current configuration
/// </summary>
No_Change,
/// <summary>
/// Guard receiver is disabled
/// </summary>
Off,
/// <summary>
/// Guard receivr is enabled
/// </summary>
On,
}
/// <summary>
/// Gets or sets the guard receiver option for the UHF radio
/// </summary>
/// <value>
/// The guard receiver setting
/// </value>
public EUHFGuardReceiver UHFGuardReceiver { get; set; } = EUHFGuardReceiver.No_Change;

/// <summary>
/// Gets or sets the uhf tune preset.
/// </summary>
Expand Down Expand Up @@ -984,7 +1013,35 @@ protected override List<DCSCommand> GetActions(object item)
if (ContainsTuningData)
{
commands.Add(new DCSCommand(DeviceRMFD, (int)AH64.EKeyCode.MFD_COM));
// Presets first
// UHF Guard receiver
if (UHFGuardReceiver != EUHFGuardReceiver.No_Change)
{
// get current status and press the button if not the correct one
int display = (int)(IsPilot ? AH64.EDisplayCodes.PLT_EUFD : AH64.EDisplayCodes.CPG_EUFD);
DCSMessage message = new DCSMessage()
{
GetCockpitDisplayData = new List<int>() { display }
};
message = DCSConnection.SendRequest(message);
if (message != null && message.CockpitDisplayData.ContainsKey(display))
{
Dictionary<string, string> displayData = message.CockpitDisplayData[display];
if (displayData.ContainsKey("Guard"))
{
string guardStr = displayData["Guard"];
bool currentGuardStatus = !string.IsNullOrEmpty(guardStr);

if (currentGuardStatus ^ (UHFGuardReceiver == EUHFGuardReceiver.On))
{
// need to press the buttons, currently on COM page
commands.Add(new DCSCommand(DeviceRMFD, (int)AH64.EKeyCode.MFD_T4)); // UHF
commands.Add(new DCSCommand(DeviceRMFD, (int)AH64.EKeyCode.MFD_L6)); // GUARD
commands.Add(new DCSCommand(DeviceRMFD, (int)AH64.EKeyCode.MFD_COM)); // Reset to com page
}
}
}
}
// Presets
int presetKey = -1;
if (VHFTuneSetting == ETuneSetting.Preset)
{
Expand Down
Loading

0 comments on commit 289b96e

Please sign in to comment.