mirror of
https://github.com/hawkeye-stan/msfs-popout-panel-manager.git
synced 2024-11-22 05:40:11 +00:00
Fix avionics power on issue for Cessna 208B and Cessna 172
This commit is contained in:
parent
93442a0150
commit
5a6757f267
5 changed files with 32 additions and 38 deletions
|
@ -4,10 +4,6 @@
|
||||||
{
|
{
|
||||||
KEY_MASTER_BATTERY_SET,
|
KEY_MASTER_BATTERY_SET,
|
||||||
KEY_ALTERNATOR_SET,
|
KEY_ALTERNATOR_SET,
|
||||||
|
KEY_TOGGLE_AVIONICS_MASTER
|
||||||
KEY_AVIONICS_MASTER_SET,
|
|
||||||
KEY_AVIONICS_MASTER_2_SET,
|
|
||||||
|
|
||||||
LIGHT_POTENTIOMETER_2_SET
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@ namespace MSFSPopoutPanelManager.FsConnector
|
||||||
{
|
{
|
||||||
("Title", "Title", null, SIMCONNECT_DATATYPE.STRING256, typeof(string)),
|
("Title", "Title", null, SIMCONNECT_DATATYPE.STRING256, typeof(string)),
|
||||||
("ElectricalMasterBattery", "ELECTRICAL MASTER BATTERY", "Bool", SIMCONNECT_DATATYPE.FLOAT64, typeof(bool)),
|
("ElectricalMasterBattery", "ELECTRICAL MASTER BATTERY", "Bool", SIMCONNECT_DATATYPE.FLOAT64, typeof(bool)),
|
||||||
("TrackIREnable", "TRACK IR ENABLE", "Bool", SIMCONNECT_DATATYPE.FLOAT64, typeof(bool))
|
("TrackIREnable", "TRACK IR ENABLE", "Bool", SIMCONNECT_DATATYPE.FLOAT64, typeof(bool)),
|
||||||
|
("AtcOnParkingSpot", "ATC ON PARKING SPOT", "Bool", SIMCONNECT_DATATYPE.FLOAT64, typeof(bool))
|
||||||
};
|
};
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|
|
@ -10,5 +10,6 @@ namespace MSFSPopoutPanelManager.FsConnector
|
||||||
|
|
||||||
public double Prop02;
|
public double Prop02;
|
||||||
public double Prop03;
|
public double Prop03;
|
||||||
|
public double Prop04;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,10 @@ namespace MSFSPopoutPanelManager.Provider
|
||||||
|
|
||||||
public class PInvoke
|
public class PInvoke
|
||||||
{
|
{
|
||||||
[DllImport("user32")]
|
[DllImport("user32", SetLastError = true)]
|
||||||
public static extern int EnumWindows(CallBack callback, int lParam);
|
public static extern int EnumWindows(CallBack callback, int lParam);
|
||||||
|
|
||||||
[DllImport("user32")]
|
[DllImport("user32", SetLastError = true)]
|
||||||
public static extern bool EnumChildWindows(IntPtr window, CallBack callback, IntPtr lParam);
|
public static extern bool EnumChildWindows(IntPtr window, CallBack callback, IntPtr lParam);
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
|
@ -62,7 +62,7 @@ namespace MSFSPopoutPanelManager.Provider
|
||||||
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
|
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
|
||||||
public static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
|
public static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
private static extern int GetClassName(IntPtr hWnd, StringBuilder strPtrClassName, Int32 nMaxCount);
|
private static extern int GetClassName(IntPtr hWnd, StringBuilder strPtrClassName, Int32 nMaxCount);
|
||||||
|
|
||||||
public static string GetClassName(IntPtr hwnd)
|
public static string GetClassName(IntPtr hwnd)
|
||||||
|
@ -72,21 +72,21 @@ namespace MSFSPopoutPanelManager.Provider
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);
|
public static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool GetCursorPos(out Point lpPoint);
|
public static extern bool GetCursorPos(out Point lpPoint);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
|
public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
|
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern int GetWindowRect(IntPtr hwnd, out Rectangle lpRect);
|
public static extern int GetWindowRect(IntPtr hwnd, out Rectangle lpRect);
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||||
|
@ -99,50 +99,50 @@ namespace MSFSPopoutPanelManager.Provider
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool IsWindow(IntPtr hWnd);
|
public static extern bool IsWindow(IntPtr hWnd);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
|
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern void mouse_event(uint dwFlags, int dx, int dy, uint cButtons, uint dwExtraInfo);
|
public static extern void mouse_event(uint dwFlags, int dx, int dy, uint cButtons, uint dwExtraInfo);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
|
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
|
||||||
|
|
||||||
[DllImport("User32.dll")]
|
[DllImport("User32.dll", SetLastError = true)]
|
||||||
public static extern bool SetCursorPos(int X, int Y);
|
public static extern bool SetCursorPos(int X, int Y);
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern IntPtr SetFocus(IntPtr hWnd);
|
public static extern IntPtr SetFocus(IntPtr hWnd);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||||
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
|
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern bool ShowWindowAsync(HandleRef hWnd, int nCmdShow);
|
public static extern bool ShowWindowAsync(HandleRef hWnd, int nCmdShow);
|
||||||
|
|
||||||
[DllImport("USER32.dll")]
|
[DllImport("USER32.dll", SetLastError = true)]
|
||||||
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
|
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern IntPtr SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint wFlags);
|
public static extern IntPtr SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint wFlags);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern bool SetWindowText(System.IntPtr hwnd, System.String lpString);
|
public static extern bool SetWindowText(System.IntPtr hwnd, System.String lpString);
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventProc lpfnWinEventProc, int idProcess, int idThread, uint dwflags);
|
public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventProc lpfnWinEventProc, int idProcess, int idThread, uint dwflags);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
public static extern int UnhookWinEvent(IntPtr hWinEventHook);
|
public static extern int UnhookWinEvent(IntPtr hWinEventHook);
|
||||||
|
|
||||||
public delegate bool CallBack(IntPtr hwnd, int lParam);
|
public delegate bool CallBack(IntPtr hwnd, int lParam);
|
||||||
|
|
|
@ -59,16 +59,15 @@ namespace MSFSPopoutPanelManager.Provider
|
||||||
|
|
||||||
public void TurnOnPower(bool isRequiredForColdStart)
|
public void TurnOnPower(bool isRequiredForColdStart)
|
||||||
{
|
{
|
||||||
if (isRequiredForColdStart && _simData != null && !_simData.ElectricalMasterBattery)
|
// Wait for _simData.AtcOnParkingSpot to refresh
|
||||||
|
Thread.Sleep(MSFS_DATA_REFRESH_TIMEOUT + 250);
|
||||||
|
|
||||||
|
if (isRequiredForColdStart && _simData != null && (_simData.AtcOnParkingSpot || !_simData.ElectricalMasterBattery))
|
||||||
{
|
{
|
||||||
_isPowerOnForPopOut = true;
|
_isPowerOnForPopOut = true;
|
||||||
_simConnector.TransmitActionEvent(ActionEvent.KEY_MASTER_BATTERY_SET, 1);
|
_simConnector.TransmitActionEvent(ActionEvent.KEY_MASTER_BATTERY_SET, 1);
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
_simConnector.TransmitActionEvent(ActionEvent.KEY_ALTERNATOR_SET, 1);
|
_simConnector.TransmitActionEvent(ActionEvent.KEY_TOGGLE_AVIONICS_MASTER, 1);
|
||||||
Thread.Sleep(100);
|
|
||||||
_simConnector.TransmitActionEvent(ActionEvent.KEY_AVIONICS_MASTER_SET, 1);
|
|
||||||
Thread.Sleep(100);
|
|
||||||
_simConnector.TransmitActionEvent(ActionEvent.KEY_AVIONICS_MASTER_2_SET, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,11 +75,7 @@ namespace MSFSPopoutPanelManager.Provider
|
||||||
{
|
{
|
||||||
if (_isPowerOnForPopOut)
|
if (_isPowerOnForPopOut)
|
||||||
{
|
{
|
||||||
_simConnector.TransmitActionEvent(ActionEvent.KEY_AVIONICS_MASTER_2_SET, 0);
|
_simConnector.TransmitActionEvent(ActionEvent.KEY_TOGGLE_AVIONICS_MASTER, 1);
|
||||||
Thread.Sleep(100);
|
|
||||||
_simConnector.TransmitActionEvent(ActionEvent.KEY_AVIONICS_MASTER_SET, 0);
|
|
||||||
Thread.Sleep(100);
|
|
||||||
_simConnector.TransmitActionEvent(ActionEvent.KEY_ALTERNATOR_SET, 0);
|
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
_simConnector.TransmitActionEvent(ActionEvent.KEY_MASTER_BATTERY_SET, 0);
|
_simConnector.TransmitActionEvent(ActionEvent.KEY_MASTER_BATTERY_SET, 0);
|
||||||
|
|
||||||
|
@ -115,8 +110,9 @@ namespace MSFSPopoutPanelManager.Provider
|
||||||
SimConnectStruct simConnectStruct = new SimConnectStruct();
|
SimConnectStruct simConnectStruct = new SimConnectStruct();
|
||||||
|
|
||||||
simConnectStruct.Prop01 = _simData.Title; // must set "Title" for TrackIR variable to write correctly
|
simConnectStruct.Prop01 = _simData.Title; // must set "Title" for TrackIR variable to write correctly
|
||||||
simConnectStruct.Prop02 = _simData.ElectricalMasterBattery ? Convert.ToDouble(1) : Convert.ToDouble(0); // must set "ElectricalMasterBattery" for TrackIR variable to write correctly
|
simConnectStruct.Prop02 = _simData.ElectricalMasterBattery ? Convert.ToDouble(1) : Convert.ToDouble(0); // must set "ElectricalMasterBattery" for TrackIR variable to write correctly
|
||||||
simConnectStruct.Prop03 = enable ? Convert.ToDouble(1) : Convert.ToDouble(0); // this is the TrackIR variable
|
simConnectStruct.Prop03 = enable ? Convert.ToDouble(1) : Convert.ToDouble(0); // this is the TrackIR variable
|
||||||
|
simConnectStruct.Prop04 = _simData.AtcOnParkingSpot ? Convert.ToDouble(1) : Convert.ToDouble(0); // must set "AtcOnParkingSpot" for TrackIR variable to write correctly
|
||||||
_simConnector.SetDataObject(simConnectStruct);
|
_simConnector.SetDataObject(simConnectStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue