1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-22 13:50:14 +00:00
msfs-popout-panel-manager/WebServer/SimConnectService.cs
2022-08-18 00:12:53 -04:00

99 lines
2.7 KiB
C#

using Microsoft.Extensions.Caching.Memory;
using MSFSPopoutPanelManager.SimConnectAgent.TouchPanel;
using System;
namespace MSFSPopoutPanelManager.WebServer
{
public class SimConnectService : ISimConnectService
{
private IMemoryCache _memCache;
private TouchPanelSimConnectProvider _simConnectorProvider;
public SimConnectService(IntPtr windowHandle)
{
_simConnectorProvider = new TouchPanelSimConnectProvider(windowHandle);
_simConnectorProvider.OnConnected += (source, e) =>
{
try { _memCache.Set("msfsStatus", true); } catch { }
};
_simConnectorProvider.OnDisconnected += (source, e) =>
{
try { _memCache.Set("msfsStatus", false); } catch { }
};
_simConnectorProvider.OnDataRefreshed += (source, e) =>
{
try { _memCache.Set("simdata", e); } catch { }
};
_simConnectorProvider.OnReceiveSystemEvent += (source, e) =>
{
try
{
var value = $"{e}-{DateTime.Now.Ticks}";
_memCache.Set("simSystemEvent", value.ToString());
}
catch { }
};
_simConnectorProvider.OnArduinoConnectionChanged += (source, e) =>
{
try { _memCache.Set("arduinoStatus", e); } catch { }
};
}
public TouchPanelConfigSetting TouchPanelConfigSetting { get; set; }
public void SetMemoryCache(IMemoryCache memCache)
{
_memCache = memCache;
}
public void Start()
{
_simConnectorProvider.Start(TouchPanelConfigSetting.IsUsedArduino);
}
public void Stop()
{
if (_simConnectorProvider != null)
{
_simConnectorProvider.Stop();
}
}
public void ExecAction(SimConnectActionData actionData)
{
_simConnectorProvider.ExecAction(actionData);
}
public void ResetSimConnectDataArea(string planeId)
{
_simConnectorProvider.ResetSimConnectDataArea(planeId);
}
public string GetFlightPlan()
{
return _simConnectorProvider.GetFlightPlan();
}
}
public interface ISimConnectService
{
public void SetMemoryCache(IMemoryCache memCache);
public void Start();
public void Stop();
public void ExecAction(SimConnectActionData data);
public void ResetSimConnectDataArea(string planeId);
public string GetFlightPlan();
public TouchPanelConfigSetting TouchPanelConfigSetting { get; set; }
}
}