From 2cef07e33733b7277c518a9fbf11f10b844a46c2 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Fri, 22 Feb 2013 21:52:12 +0000 Subject: [PATCH] Added: converting old registry settings to new XMLs Added: framework for all converted FSX functions --- G940LEDControl/Forms/MainFrm.dfm | 2 +- G940LEDControl/Forms/MainFrm.pas | 137 +++-- G940LEDControl/G940LEDControl.dpr | 4 +- G940LEDControl/G940LEDControl.dproj | 2 + G940LEDControl/Units/ConfigConversion.pas | 118 ++-- G940LEDControl/Units/FSXLEDFunction.pas | 499 +++++++++++------ .../Units/FSXLEDFunctionProvider.pas | 57 +- G940LEDControl/Units/FSXLEDFunctionWorker.pas | 526 ++++++++++++++++++ G940LEDControl/Units/FSXResources.pas | 71 +++ G940LEDControl/Units/FSXSimConnectClient.pas | 5 +- G940LEDControl/Units/LEDStateConsumer.pas | 3 + G940LEDControl/Units/Settings.pas | 63 +++ 12 files changed, 1192 insertions(+), 295 deletions(-) create mode 100644 G940LEDControl/Units/FSXLEDFunctionWorker.pas create mode 100644 G940LEDControl/Units/Settings.pas diff --git a/G940LEDControl/Forms/MainFrm.dfm b/G940LEDControl/Forms/MainFrm.dfm index 857ac1a..f43fd5a 100644 --- a/G940LEDControl/Forms/MainFrm.dfm +++ b/G940LEDControl/Forms/MainFrm.dfm @@ -14,7 +14,6 @@ object MainForm: TMainForm Font.Style = [] OldCreateOrder = False Position = poScreenCenter - OnCloseQuery = FormCloseQuery OnCreate = FormCreate OnDestroy = FormDestroy PixelsPerInch = 96 @@ -450,6 +449,7 @@ object MainForm: TMainForm Height = 17 Caption = ' Automatically check for &updates' TabOrder = 2 + OnClick = cbCheckUpdatesClick end object btnCheckUpdates: TButton Left = 344 diff --git a/G940LEDControl/Forms/MainFrm.pas b/G940LEDControl/Forms/MainFrm.pas index 7cb4299..abed7b8 100644 --- a/G940LEDControl/Forms/MainFrm.pas +++ b/G940LEDControl/Forms/MainFrm.pas @@ -20,7 +20,8 @@ uses X2UtPersistIntf, LEDStateConsumer, - Profile, Vcl.AppEvnts; + Profile, + Settings; const @@ -96,12 +97,12 @@ type bvlProfiles: TBevel; procedure FormCreate(Sender: TObject); - procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure lblLinkLinkClick(Sender: TObject; const Link: string; LinkType: TSysLinkType); procedure btnCheckUpdatesClick(Sender: TObject); procedure LEDButtonClick(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure cmbProfilesClick(Sender: TObject); + procedure cbCheckUpdatesClick(Sender: TObject); private FLEDControls: array[0..LED_COUNT - 1] of TLEDControls; FEventMonitor: TOmniEventMonitor; @@ -114,6 +115,9 @@ type FDeviceNotification: Pointer; FG940Found: Boolean; + + FSettingsFileName: string; + FSettings: TSettings; protected procedure RegisterDeviceArrival; procedure UnregisterDeviceArrival; @@ -124,6 +128,9 @@ type procedure LoadProfiles; procedure SaveProfiles; + procedure LoadSettings; + procedure SaveSettings; + function CreateDefaultProfile: TProfile; procedure LoadActiveProfile; procedure UpdateButton(AProfile: TProfile; AButtonIndex: Integer); @@ -144,6 +151,7 @@ type property ActiveProfile: TProfile read FActiveProfile; property EventMonitor: TOmniEventMonitor read FEventMonitor; property Profiles: TProfileList read FProfiles; + property Settings: TSettings read FSettings; property StateConsumerTask: IOmniTaskControl read FStateConsumerTask; end; @@ -178,6 +186,7 @@ const DefaultProfileName = 'Default'; FILENAME_PROFILES = 'G940LEDControl\Profiles.xml'; + FILENAME_SETTINGS = 'G940LEDControl\Settings.xml'; SPECIAL_CATEGORY = -1; @@ -213,26 +222,16 @@ begin FProfiles := TProfileList.Create(True); LoadProfiles; - // TODO implement profile changing properly + FSettingsFileName := App.UserPath + FILENAME_SETTINGS; + LoadSettings; + + // #ToDo1 -oMvR: 22-2-2013: implement profile changing properly FStateConsumerTask.Comm.Send(TM_LOADPROFILE, ActiveProfile); RegisterDeviceArrival; end; -procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); -begin -// SaveProfiles; -// if Assigned(StateConsumerTask) then -// begin -// SaveDefaultProfile; -// -// LEDStateConsumer.Finalize(StateConsumerTask); -// CanClose := False; -// end; -end; - - procedure TMainForm.FormDestroy(Sender: TObject); begin UnregisterDeviceArrival; @@ -395,6 +394,55 @@ begin end; +procedure TMainForm.LoadSettings; +var + persistXML: TX2UtPersistXML; + +begin + if not FileExists(FSettingsFileName) then + begin + { Check if version 0.x settings are in the registry } + FSettings := ConfigConversion.ConvertSettings0To1; + + if not Assigned(FSettings) then + FSettings := TSettings.Create; + end else + begin + FSettings := TSettings.Create; + + persistXML := TX2UtPersistXML.Create; + try + persistXML.FileName := FSettingsFileName; + Settings.Load(persistXML.CreateReader); + finally + FreeAndNil(persistXML); + end; + end; + + cbCheckUpdates.Checked := Settings.CheckUpdates; + + if not Settings.HasCheckUpdates then + PostMessage(Self.Handle, CM_ASKAUTOUPDATE, 0, 0) + else if Settings.CheckUpdates then + CheckForUpdates(False); +end; + + +procedure TMainForm.SaveSettings; +var + persistXML: TX2UtPersistXML; + +begin + persistXML := TX2UtPersistXML.Create; + try + persistXML.FileName := FSettingsFileName; + Settings.Save(persistXML.CreateWriter); + finally + FreeAndNil(persistXML); + end; +end; + + function TMainForm.CreateDefaultProfile: TProfile; begin { Default button functions are assigned during UpdateButton } @@ -468,8 +516,12 @@ begin 'Do you want to automatically check for updates?', 'Check for updates', MB_YESNO or MB_ICONQUESTION) = ID_YES then begin cbCheckUpdates.Checked := True; + Settings.CheckUpdates := True; + CheckForUpdates(False); end; + + SaveSettings; end; @@ -485,43 +537,6 @@ begin end; -//procedure TMainForm.ReadAutoUpdate(AReader: IX2PersistReader); -//var -// checkUpdates: Boolean; -// askAutoUpdate: Boolean; -// -//begin -// askAutoUpdate := True; -// -// if AReader.BeginSection(SECTION_SETTINGS) then -// try -// if AReader.ReadBoolean('CheckUpdates', checkUpdates) then -// begin -// cbCheckUpdates.Checked := checkUpdates; -// askAutoUpdate := False; -// end; -// finally -// AReader.EndSection; -// end; -// -// if askAutoUpdate then -// PostMessage(Self.Handle, CM_ASKAUTOUPDATE, 0, 0) -// else if cbCheckUpdates.Checked then -// CheckForUpdates(False); -//end; - - -//procedure TMainForm.WriteAutoUpdate(AWriter: IX2PersistWriter); -//begin -// if AWriter.BeginSection(SECTION_SETTINGS) then -// try -// AWriter.WriteBoolean('CheckUpdates', cbCheckUpdates.Checked); -// finally -// AWriter.EndSection; -// end; -//end; - - procedure TMainForm.LEDButtonClick(Sender: TObject); var buttonIndex: NativeInt; @@ -607,7 +622,7 @@ begin try latestVersion := httpClient.Get('http://g940.x2software.net/version'); if VersionIsNewer(Format('%d.%d.%d', [App.Version.Major, App.Version.Minor, App.Version.Release]), latestVersion) then - ATask.Comm.Send(MSG_UPDATE) + ATask.Comm.Send(MSG_UPDATE, latestVersion) else begin if ATask.Param.ByName('ReportNoUpdates').AsBoolean then @@ -629,6 +644,13 @@ begin end; +procedure TMainForm.cbCheckUpdatesClick(Sender: TObject); +begin + Settings.CheckUpdates := cbCheckUpdates.Checked; + SaveSettings; +end; + + procedure TMainForm.CheckForUpdates(AReportNoUpdates: Boolean); begin btnCheckUpdates.Enabled := False; @@ -647,9 +669,10 @@ begin HandleDeviceStateMessage(task, msg); MSG_UPDATE: - if MessageBox(Self.Handle, 'An update is available on the G940 LED Control website.'#13#10'Do you want to go there now?', - 'Update available', MB_YESNO or MB_ICONINFORMATION) = ID_YES then - ShellExecute(Self.Handle, 'open', PChar('http://g940.x2software.net/#download'), nil, nil, SW_SHOWNORMAL); + if MessageBox(Self.Handle, PChar('Version ' + msg.MsgData + ' is available on the G940 LED Control website.'#13#10 + + 'Do you want to open the website now?'), 'Update available', + MB_YESNO or MB_ICONINFORMATION) = ID_YES then + ShellExecute(Self.Handle, 'open', PChar('http://g940.x2software.net/category/releases/'), nil, nil, SW_SHOWNORMAL); MSG_NOUPDATE: if msg.MsgData.AsBoolean then diff --git a/G940LEDControl/G940LEDControl.dpr b/G940LEDControl/G940LEDControl.dpr index 99c2a5c..382ee4e 100644 --- a/G940LEDControl/G940LEDControl.dpr +++ b/G940LEDControl/G940LEDControl.dpr @@ -27,7 +27,9 @@ uses FSXSimConnectClient in 'Units\FSXSimConnectClient.pas', FSXSimConnectIntf in 'Units\FSXSimConnectIntf.pas', FSXLEDFunction in 'Units\FSXLEDFunction.pas', - LEDResources in 'Units\LEDResources.pas'; + LEDResources in 'Units\LEDResources.pas', + Settings in 'Units\Settings.pas', + FSXLEDFunctionWorker in 'Units\FSXLEDFunctionWorker.pas'; {$R *.res} diff --git a/G940LEDControl/G940LEDControl.dproj b/G940LEDControl/G940LEDControl.dproj index d357a23..25ff0fd 100644 --- a/G940LEDControl/G940LEDControl.dproj +++ b/G940LEDControl/G940LEDControl.dproj @@ -190,6 +190,8 @@ + + Cfg_2 Base diff --git a/G940LEDControl/Units/ConfigConversion.pas b/G940LEDControl/Units/ConfigConversion.pas index 90b04ae..a7e6790 100644 --- a/G940LEDControl/Units/ConfigConversion.pas +++ b/G940LEDControl/Units/ConfigConversion.pas @@ -2,10 +2,12 @@ unit ConfigConversion; interface uses - Profile; + Profile, + Settings; { Version 0.x: registry -> 1.x: XML } function ConvertProfile0To1: TProfile; + function ConvertSettings0To1: TSettings; implementation @@ -16,6 +18,7 @@ uses X2UtPersistIntf, X2UtPersistRegistry, + FSXResources, LEDColorIntf, StaticResources; @@ -46,7 +49,7 @@ const V0_FUNCTIONFSX_SPOILERS = V0_FUNCTIONPROVIDER_OFFSET + 13; V0_FUNCTIONFSX_PRESSURIZATIONDUMPSWITCH = V0_FUNCTIONPROVIDER_OFFSET + 14; - V0_FUNCTIONFSX_CARBHEAT = V0_FUNCTIONPROVIDER_OFFSET + 15; + V0_FUNCTIONFSX_ENGINEANTIICE = V0_FUNCTIONPROVIDER_OFFSET + 15; V0_FUNCTIONFSX_AUTOPILOT = V0_FUNCTIONPROVIDER_OFFSET + 16; V0_FUNCTIONFSX_FUELPUMP = V0_FUNCTIONPROVIDER_OFFSET + 17; @@ -62,7 +65,7 @@ const V0_FUNCTIONFSX_TAXILIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 25; V0_FUNCTIONFSX_RECOGNITIONLIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 26; - // TODO 27 (de-ice) + V0_FUNCTIONFSX_DEICE = V0_FUNCTIONPROVIDER_OFFSET + 27; @@ -76,45 +79,50 @@ procedure ConvertProfileFunction0To1(AOldFunction: Integer; AButton: TProfileBut begin + { Default states are handled by the specific functions } case AOldFunction of { Static } - V0_FUNCTION_OFF: SetButton(StaticProviderUID, StaticFunctionUID[lcOff]); - V0_FUNCTION_RED: SetButton(StaticProviderUID, StaticFunctionUID[lcRed]); - V0_FUNCTION_AMBER: SetButton(StaticProviderUID, StaticFunctionUID[lcAmber]); - V0_FUNCTION_GREEN: SetButton(StaticProviderUID, StaticFunctionUID[lcGreen]); + V0_FUNCTION_OFF: SetButton(StaticProviderUID, StaticFunctionUID[lcOff]); + V0_FUNCTION_RED: SetButton(StaticProviderUID, StaticFunctionUID[lcRed]); + V0_FUNCTION_AMBER: SetButton(StaticProviderUID, StaticFunctionUID[lcAmber]); + V0_FUNCTION_GREEN: SetButton(StaticProviderUID, StaticFunctionUID[lcGreen]); { FSX } - { - V0_FUNCTIONFSX_GEAR: - V0_FUNCTIONFSX_LANDINGLIGHTS: - V0_FUNCTIONFSX_INSTRUMENTLIGHTS: - V0_FUNCTIONFSX_PARKINGBRAKE: - V0_FUNCTIONFSX_ENGINE: + V0_FUNCTIONFSX_GEAR: SetButton(FSXProviderUID, FSXFunctionUIDGear); + V0_FUNCTIONFSX_LANDINGLIGHTS: SetButton(FSXProviderUID, FSXFunctionUIDLandingLights); + V0_FUNCTIONFSX_INSTRUMENTLIGHTS: SetButton(FSXProviderUID, FSXFunctionUIDInstrumentLights); + V0_FUNCTIONFSX_PARKINGBRAKE: SetButton(FSXProviderUID, FSXFunctionUIDParkingBrake); + V0_FUNCTIONFSX_ENGINE: SetButton(FSXProviderUID, FSXFunctionUIDEngine); - V0_FUNCTIONFSX_EXITDOOR: - V0_FUNCTIONFSX_STROBELIGHTS: - V0_FUNCTIONFSX_NAVLIGHTS: - V0_FUNCTIONFSX_BEACONLIGHTS: - V0_FUNCTIONFSX_FLAPS: - V0_FUNCTIONFSX_BATTERYMASTER: - V0_FUNCTIONFSX_AVIONICSMASTER: - V0_FUNCTIONFSX_SPOILERS: - V0_FUNCTIONFSX_PRESSURIZATIONDUMPSWITCH: - V0_FUNCTIONFSX_CARBHEAT: + V0_FUNCTIONFSX_EXITDOOR: SetButton(FSXProviderUID, FSXFunctionUIDExitDoor); + V0_FUNCTIONFSX_STROBELIGHTS: SetButton(FSXProviderUID, FSXFunctionUIDStrobeLights); + V0_FUNCTIONFSX_NAVLIGHTS: SetButton(FSXProviderUID, FSXFunctionUIDNavLights); + V0_FUNCTIONFSX_BEACONLIGHTS: SetButton(FSXProviderUID, FSXFunctionUIDBeaconLights); + V0_FUNCTIONFSX_FLAPS: SetButton(FSXProviderUID, FSXFunctionUIDFlaps); + V0_FUNCTIONFSX_BATTERYMASTER: SetButton(FSXProviderUID, FSXFunctionUIDBatteryMaster); + V0_FUNCTIONFSX_AVIONICSMASTER: SetButton(FSXProviderUID, FSXFunctionUIDAvionicsMaster); + V0_FUNCTIONFSX_SPOILERS: SetButton(FSXProviderUID, FSXFunctionUIDSpoilers); + V0_FUNCTIONFSX_PRESSURIZATIONDUMPSWITCH: SetButton(FSXProviderUID, FSXFunctionUIDPressDumpSwitch); + V0_FUNCTIONFSX_ENGINEANTIICE: SetButton(FSXProviderUID, FSXFunctionUIDEngineAntiIce); V0_FUNCTIONFSX_AUTOPILOT: - V0_FUNCTIONFSX_FUELPUMP: - V0_FUNCTIONFSX_TAILHOOK: - V0_FUNCTIONFSX_AUTOPILOT_AMBER: - V0_FUNCTIONFSX_AUTOPILOT_HEADING: - V0_FUNCTIONFSX_AUTOPILOT_APPROACH: - V0_FUNCTIONFSX_AUTOPILOT_BACKCOURSE: - V0_FUNCTIONFSX_AUTOPILOT_ALTITUDE: - V0_FUNCTIONFSX_AUTOPILOT_NAV: - V0_FUNCTIONFSX_TAXILIGHTS: - V0_FUNCTIONFSX_RECOGNITIONLIGHTS: - } - else - SetButton(StaticProviderUID, StaticFunctionUID[lcGreen]); + begin + { The only exception regarding states; the new default is Amber / Off } + SetButton(FSXProviderUID, FSXFunctionUIDAutoPilot); + AButton.SetStateColor(FSXStateUIDOn, lcGreen); + AButton.SetStateColor(FSXStateUIDOff, lcRed); + end; + + V0_FUNCTIONFSX_FUELPUMP: SetButton(FSXProviderUID, FSXFunctionUIDFuelPump); + V0_FUNCTIONFSX_TAILHOOK: SetButton(FSXProviderUID, FSXFunctionUIDTailHook); + V0_FUNCTIONFSX_AUTOPILOT_AMBER: SetButton(FSXProviderUID, FSXFunctionUIDAutoPilot); + V0_FUNCTIONFSX_AUTOPILOT_HEADING: SetButton(FSXProviderUID, FSXFunctionUIDAutoPilotHeading); + V0_FUNCTIONFSX_AUTOPILOT_APPROACH: SetButton(FSXProviderUID, FSXFunctionUIDAutoPilotApproach); + V0_FUNCTIONFSX_AUTOPILOT_BACKCOURSE: SetButton(FSXProviderUID, FSXFunctionUIDAutoPilotBackcourse); + V0_FUNCTIONFSX_AUTOPILOT_ALTITUDE: SetButton(FSXProviderUID, FSXFunctionUIDAutoPilotAltitude); + V0_FUNCTIONFSX_AUTOPILOT_NAV: SetButton(FSXProviderUID, FSXFunctionUIDAutoPilotNav); + V0_FUNCTIONFSX_TAXILIGHTS: SetButton(FSXProviderUID, FSXFunctionUIDTaxiLights); + V0_FUNCTIONFSX_RECOGNITIONLIGHTS: SetButton(FSXProviderUID, FSXFunctionUIDRecognitionLights); + V0_FUNCTIONFSX_DEICE: SetButton(FSXProviderUID, FSXFunctionUIDDeIce); end; end; @@ -124,7 +132,6 @@ const KEY_SETTINGS = '\Software\X2Software\G940LEDControl\'; SECTION_DEFAULTPROFILE = 'DefaultProfile'; SECTION_FSX = 'FSX'; - SECTION_SETTINGS = 'Settings'; var registryReader: TX2UtPersistRegistry; @@ -162,9 +169,42 @@ begin finally reader.EndSection; end; + finally + FreeAndNil(registryReader); + end; +end; - // TODO auto update settings - //ReadAutoUpdate(reader); + +function ConvertSettings0To1: TSettings; +const + KEY_SETTINGS = '\Software\X2Software\G940LEDControl\'; + SECTION_SETTINGS = 'Settings'; + +var + registryReader: TX2UtPersistRegistry; + reader: IX2PersistReader; + value: Boolean; + +begin + Result := nil; + + registryReader := TX2UtPersistRegistry.Create; + try + registryReader.RootKey := HKEY_CURRENT_USER; + registryReader.Key := KEY_SETTINGS; + + reader := registryReader.CreateReader; + + if reader.BeginSection(SECTION_SETTINGS) then + try + if reader.ReadBoolean('CheckUpdates', value) then + begin + Result := TSettings.Create; + Result.CheckUpdates := value; + end; + finally + reader.EndSection; + end; finally FreeAndNil(registryReader); end; diff --git a/G940LEDControl/Units/FSXLEDFunction.pas b/G940LEDControl/Units/FSXLEDFunction.pas index f829279..acf7aa6 100644 --- a/G940LEDControl/Units/FSXLEDFunction.pas +++ b/G940LEDControl/Units/FSXLEDFunction.pas @@ -8,14 +8,13 @@ uses type - { Base classes } - TFSXOnOffFunction = class(TCustomFSXFunction) + TCustomFSXOnOffFunction = class(TCustomFSXFunction) protected procedure RegisterStates; override; end; - { Function implementations } + { Misc } TFSXEngineFunction = class(TCustomFSXFunction) protected procedure RegisterStates; override; @@ -28,8 +27,74 @@ type function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; end; + TFSXParkingBrakeFunction = class(TCustomFSXOnOffFunction) + protected + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; - TFSXLightFunction = class(TFSXOnOffFunction) + TFSXExitDoorFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXTailHookFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXFlapsFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXSpoilersFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXBatteryMasterFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXAvionicsMasterFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXPressDumpSwitchFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXEngineAntiIceFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXFuelPumpFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXDeIceFunction = class(TCustomFSXFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + + { Lights } + TCustomFSXLightFunction = class(TCustomFSXOnOffFunction) protected function GetCategoryName: string; override; @@ -39,82 +104,96 @@ type function GetLightMask: Integer; virtual; abstract; end; - TFSXLandingLightsFunction = class(TFSXLightFunction) + TFSXLandingLightsFunction = class(TCustomFSXLightFunction) protected function GetLightMask: Integer; override; end; - TFSXInstrumentLightsFunction = class(TFSXLightFunction) + TFSXInstrumentLightsFunction = class(TCustomFSXLightFunction) protected function GetLightMask: Integer; override; end; - TFSXBeaconLightsFunction = class(TFSXLightFunction) + TFSXBeaconLightsFunction = class(TCustomFSXLightFunction) protected function GetLightMask: Integer; override; end; - TFSXNavLightsFunction = class(TFSXLightFunction) + TFSXNavLightsFunction = class(TCustomFSXLightFunction) protected function GetLightMask: Integer; override; end; - TFSXStrobeLightsFunction = class(TFSXLightFunction) + TFSXStrobeLightsFunction = class(TCustomFSXLightFunction) protected function GetLightMask: Integer; override; end; - TFSXTaxiLightsFunction = class(TFSXLightFunction) + TFSXTaxiLightsFunction = class(TCustomFSXLightFunction) protected function GetLightMask: Integer; override; end; - TFSXRecognitionLightsFunction = class(TFSXLightFunction) + TFSXRecognitionLightsFunction = class(TCustomFSXLightFunction) protected function GetLightMask: Integer; override; end; + { Autopilot } + TCustomFSXAutoPilotFunction = class(TCustomFSXFunction) + protected + function GetCategoryName: string; override; + end; + + TFSXAutoPilotFunction = class(TCustomFSXAutoPilotFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXAutoPilotHeadingFunction = class(TCustomFSXAutoPilotFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXAutoPilotApproachFunction = class(TCustomFSXAutoPilotFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXAutoPilotBackcourseFunction = class(TCustomFSXAutoPilotFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXAutoPilotAltitudeFunction = class(TCustomFSXAutoPilotFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + TFSXAutoPilotNavFunction = class(TCustomFSXAutoPilotFunction) + protected + procedure RegisterStates; override; + function GetWorkerClass: TCustomLEDFunctionWorkerClass; override; + end; + + implementation uses - System.Math, - System.SysUtils, - - FSXSimConnectIntf, + FSXLEDFunctionWorker, FSXResources, + FSXSimConnectIntf, LEDColorIntf, - LEDState, - LEDStateIntf, - SimConnect; - - -type - { Worker implementations } - TFSXEngineFunctionWorker = class(TCustomFSXFunctionWorker) - protected - procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; - procedure HandleData(AData: Pointer); override; - end; - - TFSXGearFunctionWorker = class(TCustomFSXFunctionWorker) - protected - procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; - procedure HandleData(AData: Pointer); override; - end; - - TFSXLightStatesFunctionWorker = class(TCustomFSXFunctionWorker) - private - FStateMask: Integer; - protected - procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; - procedure HandleData(AData: Pointer); override; - public - property StateMask: Integer read FStateMask write FStateMask; - end; + LEDState; { TFSXOnOffFunction } -procedure TFSXOnOffFunction.RegisterStates; +procedure TCustomFSXOnOffFunction.RegisterStates; begin RegisterState(TLEDState.Create(FSXStateUIDOn, FSXStateDisplayNameOn, lcGreen)); RegisterState(TLEDState.Create(FSXStateUIDOff, FSXStateDisplayNameOff, lcRed)); @@ -139,84 +218,6 @@ begin end; -{ TFSXEngineFunctionWorker } -procedure TFSXEngineFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); -var - engineIndex: Integer; - -begin - ADefinition.AddVariable('NUMBER OF ENGINES', FSX_UNIT_NUMBER, SIMCONNECT_DATAType_INT32); - - for engineIndex := 1 to FSX_MAX_ENGINES do - ADefinition.AddVariable(Format('GENERAL ENG COMBUSTION:%d', [engineIndex]), FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); - - for engineIndex := 1 to FSX_MAX_ENGINES do - ADefinition.AddVariable(Format('ENG FAILED:%d', [engineIndex]), FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); - - for engineIndex := 1 to FSX_MAX_ENGINES do - ADefinition.AddVariable(Format('ENG ON FIRE:%d', [engineIndex]), FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); -end; - - -procedure TFSXEngineFunctionWorker.HandleData(AData: Pointer); -type - PEngineData = ^TEngineData; - TEngineData = packed record - NumberOfEngines: Integer; - Combustion: array[1..FSX_MAX_ENGINES] of Integer; - Failed: array[1..FSX_MAX_ENGINES] of Integer; - OnFire: array[1..FSX_MAX_ENGINES] of Integer; - end; - -var - engineData: PEngineData; - engineCount: Integer; - engineIndex: Integer; - hasFire: Boolean; - hasFailure: Boolean; - runningCount: Integer; - -begin - engineData := AData; - - if engineData^.NumberOfEngines > 0 then - begin - engineCount := Min(engineData^.NumberOfEngines, FSX_MAX_ENGINES); - hasFire := False; - hasFailure := False; - runningCount := 0; - - for engineIndex := 1 to engineCount do - begin - if engineData^.OnFire[engineIndex] <> 0 then - hasFire := True; - - if engineData^.Failed[engineIndex] <> 0 then - hasFailure := True; - - if engineData^.Combustion[engineIndex] <> 0 then - Inc(runningCount); - end; - - if hasFire then - SetCurrentState(FSXStateUIDEngineOnFire) - - else if hasFailure then - SetCurrentState(FSXStateUIDEngineFailed) - - else if runningCount = 0 then - SetCurrentState(FSXStateUIDEngineAllOff) - - else if runningCount = engineCount then - SetCurrentState(FSXStateUIDEngineAllRunning) - - else - SetCurrentState(FSXStateUIDEnginePartiallyRunning); - end else - SetCurrentState(FSXStateUIDEngineNoEngines); -end; - - { TFSXGearFunction } procedure TFSXGearFunction.RegisterStates; begin @@ -235,64 +236,161 @@ begin end; -{ TFSXGearFunctionWorker } -procedure TFSXGearFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +{ TFSXParkingBrakeFunction } +function TFSXParkingBrakeFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; begin - ADefinition.AddVariable('IS GEAR RETRACTABLE', FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); - ADefinition.AddVariable('GEAR TOTAL PCT EXTENDED', FSX_UNIT_PERCENT, SIMCONNECT_DATAType_FLOAT64); - ADefinition.AddVariable('GEAR DAMAGE BY SPEED', FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); - ADefinition.AddVariable('GEAR SPEED EXCEEDED', FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); + Result := TFSXParkingBrakeFunctionWorker; end; -procedure TFSXGearFunctionWorker.HandleData(AData: Pointer); -type - PGearData = ^TGearData; - TGearData = packed record - IsGearRetractable: Cardinal; - TotalPctExtended: Double; - DamageBySpeed: Integer; - SpeedExceeded: Integer; - end; - -var - gearData: PGearData; - +{ TFSXExitDoorFunction } +procedure TFSXExitDoorFunction.RegisterStates; begin - gearData := AData; + RegisterState(TLEDState.Create(FSXStateUIDExitDoorClosed, FSXStateDisplayNameExitDoorClosed, lcGreen)); + RegisterState(TLEDState.Create(FSXStateUIDExitDoorBetween, FSXStateDisplayNameExitDoorBetween, lcAmber)); + RegisterState(TLEDState.Create(FSXStateUIDExitDoorOpen, FSXStateDisplayNameExitDoorOpen, lcRed)); +end; - if gearData^.DamageBySpeed <> 0 then - SetCurrentState(FSXStateUIDGearDamageBySpeed) - else if gearData^.SpeedExceeded <> 0 then - SetCurrentState(FSXStateUIDGearSpeedExceeded) +function TFSXExitDoorFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXExitDoorFunctionWorker; +end; - else if gearData^.IsGearRetractable <> 0 then - begin - case Trunc(gearData ^.TotalPctExtended * 100) of - 0: SetCurrentState(FSXStateUIDGearRetracted); - 95..100: SetCurrentState(FSXStateUIDGearExtended); - else SetCurrentState(FSXStateUIDGearBetween); - end; - end else - SetCurrentState(FSXStateUIDGearNotRetractable); + +{ TFSXTailHookFunction } +procedure TFSXTailHookFunction.RegisterStates; +begin + RegisterState(TLEDState.Create(FSXStateUIDTailHookRetracted, FSXStateDisplayNameTailHookRetracted, lcGreen)); + RegisterState(TLEDState.Create(FSXStateUIDTailHookBetween, FSXStateDisplayNameTailHookBetween, lcAmber)); + RegisterState(TLEDState.Create(FSXStateUIDTailHookExtended, FSXStateDisplayNameTailHookExtended, lcRed)); +end; + + +function TFSXTailHookFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXTailHookFunctionWorker; +end; + + +{ TFSXFlapsFunction } +procedure TFSXFlapsFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXFlapsFunction.RegisterStates +end; + + +function TFSXFlapsFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXFlapsFunctionWorker; +end; + + +{ TFSXSpoilersFunction } +procedure TFSXSpoilersFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXSpoilersFunction.RegisterStates +end; + + +function TFSXSpoilersFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXSpoilersFunctionWorker; +end; + + +{ TFSXBatteryMasterFunction } +procedure TFSXBatteryMasterFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXBatteryMasterFunction.RegisterStates +end; + + +function TFSXBatteryMasterFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXBatteryMasterFunctionWorker; +end; + + +{ TFSXAvionicsMasterFunction } +procedure TFSXAvionicsMasterFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAvionicsMasterFunction.RegisterStates +end; + + +function TFSXAvionicsMasterFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXAvionicsMasterFunctionWorker; +end; + + +{ TFSXPressDumpSwitchFunction } +procedure TFSXPressDumpSwitchFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXPressDumpSwitchFunction.RegisterStates +end; + + +function TFSXPressDumpSwitchFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXPressDumpSwitchFunctionWorker; +end; + + +{ TFSXEngineAntiIceFunction } +procedure TFSXEngineAntiIceFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXEngineAntiIceFunction.RegisterStates +end; + + +function TFSXEngineAntiIceFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXEngineAntiIceFunctionWorker; +end; + + +{ TFSXFuelPumpFunction } +procedure TFSXFuelPumpFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXFuelPumpFunction.RegisterStates +end; + + +function TFSXFuelPumpFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXFuelPumpFunctionWorker; +end; + + +{ TFSXDeIceFunction } +procedure TFSXDeIceFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXDeIceFunction.RegisterStates +end; + + +function TFSXDeIceFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXDeIceFunctionWorker; end; { TFSXLightFunction } -function TFSXLightFunction.GetCategoryName: string; +function TCustomFSXLightFunction.GetCategoryName: string; begin Result := FSXCategoryLights; end; -function TFSXLightFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +function TCustomFSXLightFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; begin Result := TFSXLightStatesFunctionWorker; end; -function TFSXLightFunction.DoCreateWorker(ASettings: ILEDFunctionWorkerSettings): TCustomLEDFunctionWorker; +function TCustomFSXLightFunction.DoCreateWorker(ASettings: ILEDFunctionWorkerSettings): TCustomLEDFunctionWorker; begin Result := inherited DoCreateWorker(ASettings); (Result as TFSXLightStatesFunctionWorker).StateMask := GetLightMask; @@ -348,19 +446,88 @@ begin end; -{ TFSXLightStatesFunctionWorker } -procedure TFSXLightStatesFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +{ TCustomFSXAutoPilotFunction } +function TCustomFSXAutoPilotFunction.GetCategoryName: string; begin - ADefinition.AddVariable('LIGHT ON STATES', FSX_UNIT_MASK, SIMCONNECT_DATATYPE_INT32); + Result := FSXCategoryAutoPilot; end; -procedure TFSXLightStatesFunctionWorker.HandleData(AData: Pointer); +{ TFSXAutoPilotFunction } +procedure TFSXAutoPilotFunction.RegisterStates; begin - if (PCardinal(AData)^ and StateMask) <> 0 then - SetCurrentState(FSXStateUIDOn) - else - SetCurrentState(FSXStateUIDOff); + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotFunction.RegisterStates +end; + + +function TFSXAutoPilotFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXAutoPilotFunctionWorker; +end; + + +{ TFSXAutoPilotHeadingFunction } +procedure TFSXAutoPilotHeadingFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotHeadingFunction.RegisterState +end; + + +function TFSXAutoPilotHeadingFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXAutoPilotHeadingFunctionWorker; +end; + + +{ TFSXAutoPilotApproachFunction } +procedure TFSXAutoPilotApproachFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotApproachFunction.RegisterStates +end; + + +function TFSXAutoPilotApproachFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXAutoPilotApproachFunctionWorker; +end; + + +{ TFSXAutoPilotBackcourseFunction } +procedure TFSXAutoPilotBackcourseFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotBackcourseFunction.RegisterStates +end; + + +function TFSXAutoPilotBackcourseFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXAutoPilotBackcourseFunctionWorker; +end; + + +{ TFSXAutoPilotAltitudeFunction } +procedure TFSXAutoPilotAltitudeFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotAltitudeFunction.RegisterStates +end; + + +function TFSXAutoPilotAltitudeFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXAutoPilotAltitudeFunctionWorker; +end; + + +{ TFSXAutoPilotNavFunction } +procedure TFSXAutoPilotNavFunction.RegisterStates; +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotNavFunction.RegisterStates +end; + + +function TFSXAutoPilotNavFunction.GetWorkerClass: TCustomLEDFunctionWorkerClass; +begin + Result := TFSXAutoPilotNavFunctionWorker; end; end. diff --git a/G940LEDControl/Units/FSXLEDFunctionProvider.pas b/G940LEDControl/Units/FSXLEDFunctionProvider.pas index 2a7d61b..e02864f 100644 --- a/G940LEDControl/Units/FSXLEDFunctionProvider.pas +++ b/G940LEDControl/Units/FSXLEDFunctionProvider.pas @@ -129,38 +129,37 @@ end; procedure TFSXLEDFunctionProvider.RegisterFunctions; begin - { - AConsumer.AddFunction(FUNCTION_FSX_CARBHEAT, 'Anti-ice'); - AConsumer.AddFunction(FUNCTION_FSX_AUTOPILOT, 'Auto pilot (main)'); - AConsumer.AddFunction(FUNCTION_FSX_AUTOPILOT_AMBER, 'Auto pilot (main - off / amber)'); - AConsumer.AddFunction(FUNCTION_FSX_AUTOPILOT_ALTITUDE, 'Auto pilot - Altitude'); - AConsumer.AddFunction(FUNCTION_FSX_AUTOPILOT_APPROACH, 'Auto pilot - Approach'); - AConsumer.AddFunction(FUNCTION_FSX_AUTOPILOT_BACKCOURSE, 'Auto pilot - Backcourse'); - AConsumer.AddFunction(FUNCTION_FSX_AUTOPILOT_HEADING, 'Auto pilot - Heading'); - AConsumer.AddFunction(FUNCTION_FSX_AUTOPILOT_NAV, 'Auto pilot - Nav'); - AConsumer.AddFunction(FUNCTION_FSX_AVIONICSMASTER, 'Avionics master switch'); - AConsumer.AddFunction(FUNCTION_FSX_BATTERYMASTER, 'Battery master switch'); - AConsumer.AddFunction(FUNCTION_FSX_ENGINE, 'Engine'); - AConsumer.AddFunction(FUNCTION_FSX_EXITDOOR, 'Exit door'); - AConsumer.AddFunction(FUNCTION_FSX_FLAPS, 'Flaps'); - AConsumer.AddFunction(FUNCTION_FSX_PARKINGBRAKE, 'Parking brake'); - AConsumer.AddFunction(FUNCTION_FSX_PRESSURIZATIONDUMPSWITCH, 'Pressurization dump switch'); - AConsumer.AddFunction(FUNCTION_FSX_SPOILERS, 'Spoilers (air brake)'); - AConsumer.AddFunction(FUNCTION_FSX_TAILHOOK, 'Tail hook'); - } - { Misc } - RegisterFunction(TFSXEngineFunction.Create( Self, FSXFunctionDisplayNameEngine, FSXFunctionUIDEngine)); - RegisterFunction(TFSXGearFunction.Create( Self, FSXFunctionDisplayNameGear, FSXFunctionUIDGear)); + RegisterFunction(TFSXAvionicsMasterFunction.Create( Self, FSXFunctionDisplayNameAvionicsMaster, FSXFunctionUIDAvionicsMaster)); + RegisterFunction(TFSXBatteryMasterFunction.Create( Self, FSXFunctionDisplayNameBatteryMaster, FSXFunctionUIDBatteryMaster)); + RegisterFunction(TFSXDeIceFunction.Create( Self, FSXFunctionDisplayNameDeIce, FSXFunctionUIDDeIce)); + RegisterFunction(TFSXEngineAntiIceFunction.Create( Self, FSXFunctionDisplayNameEngineAntiIce, FSXFunctionUIDEngineAntiIce)); + RegisterFunction(TFSXEngineFunction.Create( Self, FSXFunctionDisplayNameEngine, FSXFunctionUIDEngine)); + RegisterFunction(TFSXExitDoorFunction.Create( Self, FSXFunctionDisplayNameExitDoor, FSXFunctionUIDExitDoor)); + RegisterFunction(TFSXFlapsFunction.Create( Self, FSXFunctionDisplayNameFlaps, FSXFunctionUIDFlaps)); + RegisterFunction(TFSXFuelPumpFunction.Create( Self, FSXFunctionDisplayNameFuelPump, FSXFunctionUIDFuelPump)); + RegisterFunction(TFSXGearFunction.Create( Self, FSXFunctionDisplayNameGear, FSXFunctionUIDGear)); + RegisterFunction(TFSXParkingBrakeFunction.Create( Self, FSXFunctionDisplayNameParkingBrake, FSXFunctionUIDParkingBrake)); + RegisterFunction(TFSXPressDumpSwitchFunction.Create( Self, FSXFunctionDisplayNamePressDumpSwitch, FSXFunctionUIDPressDumpSwitch)); + RegisterFunction(TFSXSpoilersFunction.Create( Self, FSXFunctionDisplayNameSpoilers, FSXFunctionUIDSpoilers)); + RegisterFunction(TFSXTailHookFunction.Create( Self, FSXFunctionDisplayNameTailHook, FSXFunctionUIDTailHook)); { Lights } - RegisterFunction(TFSXBeaconLightsFunction.Create( Self, FSXFunctionDisplayNameBeaconLights, FSXFunctionUIDBeaconLights)); - RegisterFunction(TFSXInstrumentLightsFunction.Create( Self, FSXFunctionDisplayNameInstrumentLights, FSXFunctionUIDInstrumentLights)); - RegisterFunction(TFSXLandingLightsFunction.Create( Self, FSXFunctionDisplayNameLandingLights, FSXFunctionUIDLandingLights)); - RegisterFunction(TFSXNavLightsFunction.Create( Self, FSXFunctionDisplayNameNavLights, FSXFunctionUIDNavLights)); - RegisterFunction(TFSXRecognitionLightsFunction.Create(Self, FSXFunctionDisplayNameRecognitionLights, FSXFunctionUIDRecognitionLights)); - RegisterFunction(TFSXStrobeLightsFunction.Create( Self, FSXFunctionDisplayNameStrobeLights, FSXFunctionUIDStrobeLights)); - RegisterFunction(TFSXTaxiLightsFunction.Create( Self, FSXFunctionDisplayNameTaxiLights, FSXFunctionUIDTaxiLights)); + RegisterFunction(TFSXBeaconLightsFunction.Create( Self, FSXFunctionDisplayNameBeaconLights, FSXFunctionUIDBeaconLights)); + RegisterFunction(TFSXInstrumentLightsFunction.Create( Self, FSXFunctionDisplayNameInstrumentLights, FSXFunctionUIDInstrumentLights)); + RegisterFunction(TFSXLandingLightsFunction.Create( Self, FSXFunctionDisplayNameLandingLights, FSXFunctionUIDLandingLights)); + RegisterFunction(TFSXNavLightsFunction.Create( Self, FSXFunctionDisplayNameNavLights, FSXFunctionUIDNavLights)); + RegisterFunction(TFSXRecognitionLightsFunction.Create( Self, FSXFunctionDisplayNameRecognitionLights, FSXFunctionUIDRecognitionLights)); + RegisterFunction(TFSXStrobeLightsFunction.Create( Self, FSXFunctionDisplayNameStrobeLights, FSXFunctionUIDStrobeLights)); + RegisterFunction(TFSXTaxiLightsFunction.Create( Self, FSXFunctionDisplayNameTaxiLights, FSXFunctionUIDTaxiLights)); + + { Autopilot } + RegisterFunction(TFSXAutoPilotFunction.Create( Self, FSXFunctionDisplayNameAutoPilot, FSXFunctionUIDAutoPilot)); + RegisterFunction(TFSXAutoPilotAltitudeFunction.Create( Self, FSXFunctionDisplayNameAutoPilotAltitude, FSXFunctionUIDAutoPilotAltitude)); + RegisterFunction(TFSXAutoPilotApproachFunction.Create( Self, FSXFunctionDisplayNameAutoPilotApproach, FSXFunctionUIDAutoPilotApproach)); + RegisterFunction(TFSXAutoPilotBackcourseFunction.Create(Self, FSXFunctionDisplayNameAutoPilotBackcourse, FSXFunctionUIDAutoPilotBackcourse)); + RegisterFunction(TFSXAutoPilotHeadingFunction.Create( Self, FSXFunctionDisplayNameAutoPilotHeading, FSXFunctionUIDAutoPilotHeading)); + RegisterFunction(TFSXAutoPilotNavFunction.Create( Self, FSXFunctionDisplayNameAutoPilotNav, FSXFunctionUIDAutoPilotNav)); end; diff --git a/G940LEDControl/Units/FSXLEDFunctionWorker.pas b/G940LEDControl/Units/FSXLEDFunctionWorker.pas new file mode 100644 index 0000000..7d97d89 --- /dev/null +++ b/G940LEDControl/Units/FSXLEDFunctionWorker.pas @@ -0,0 +1,526 @@ +unit FSXLEDFunctionWorker; + +interface +uses + FSXLEDFunctionProvider, + FSXSimConnectIntf; + + +type + { Misc } + TFSXEngineFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + TFSXGearFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + TFSXParkingBrakeFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + TFSXExitDoorFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + TFSXTailHookFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXFlapsFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXSpoilersFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXBatteryMasterFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXAvionicsMasterFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXPressDumpSwitchFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXEngineAntiIceFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXFuelPumpFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXDeIceFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXLightStatesFunctionWorker = class(TCustomFSXFunctionWorker) + private + FStateMask: Integer; + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + public + property StateMask: Integer read FStateMask write FStateMask; + end; + + + TFSXAutoPilotFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXAutoPilotHeadingFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXAutoPilotApproachFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXAutoPilotBackcourseFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXAutoPilotAltitudeFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + + TFSXAutoPilotNavFunctionWorker = class(TCustomFSXFunctionWorker) + protected + procedure RegisterVariables(ADefinition: IFSXSimConnectDefinition); override; + procedure HandleData(AData: Pointer); override; + end; + + +implementation +uses + System.Math, + System.SysUtils, + + FSXResources, + LEDStateIntf, + SimConnect; + + +{ TFSXEngineFunctionWorker } +procedure TFSXEngineFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +var + engineIndex: Integer; + +begin + ADefinition.AddVariable('NUMBER OF ENGINES', FSX_UNIT_NUMBER, SIMCONNECT_DATAType_INT32); + + for engineIndex := 1 to FSX_MAX_ENGINES do + ADefinition.AddVariable(Format('GENERAL ENG COMBUSTION:%d', [engineIndex]), FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); + + for engineIndex := 1 to FSX_MAX_ENGINES do + ADefinition.AddVariable(Format('ENG FAILED:%d', [engineIndex]), FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); + + for engineIndex := 1 to FSX_MAX_ENGINES do + ADefinition.AddVariable(Format('ENG ON FIRE:%d', [engineIndex]), FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); +end; + + +procedure TFSXEngineFunctionWorker.HandleData(AData: Pointer); +type + PEngineData = ^TEngineData; + TEngineData = packed record + NumberOfEngines: Integer; + Combustion: array[1..FSX_MAX_ENGINES] of Integer; + Failed: array[1..FSX_MAX_ENGINES] of Integer; + OnFire: array[1..FSX_MAX_ENGINES] of Integer; + end; + +var + engineData: PEngineData; + engineCount: Integer; + engineIndex: Integer; + hasFire: Boolean; + hasFailure: Boolean; + runningCount: Integer; + +begin + engineData := AData; + + if engineData^.NumberOfEngines > 0 then + begin + engineCount := Min(engineData^.NumberOfEngines, FSX_MAX_ENGINES); + hasFire := False; + hasFailure := False; + runningCount := 0; + + for engineIndex := 1 to engineCount do + begin + if engineData^.OnFire[engineIndex] <> 0 then + hasFire := True; + + if engineData^.Failed[engineIndex] <> 0 then + hasFailure := True; + + if engineData^.Combustion[engineIndex] <> 0 then + Inc(runningCount); + end; + + if hasFire then + SetCurrentState(FSXStateUIDEngineOnFire) + + else if hasFailure then + SetCurrentState(FSXStateUIDEngineFailed) + + else if runningCount = 0 then + SetCurrentState(FSXStateUIDEngineAllOff) + + else if runningCount = engineCount then + SetCurrentState(FSXStateUIDEngineAllRunning) + + else + SetCurrentState(FSXStateUIDEnginePartiallyRunning); + end else + SetCurrentState(FSXStateUIDEngineNoEngines); +end; + + +{ TFSXGearFunctionWorker } +procedure TFSXGearFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + ADefinition.AddVariable('IS GEAR RETRACTABLE', FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); + ADefinition.AddVariable('GEAR TOTAL PCT EXTENDED', FSX_UNIT_PERCENT, SIMCONNECT_DATAType_FLOAT64); + ADefinition.AddVariable('GEAR DAMAGE BY SPEED', FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); + ADefinition.AddVariable('GEAR SPEED EXCEEDED', FSX_UNIT_BOOL, SIMCONNECT_DATAType_INT32); +end; + + +procedure TFSXGearFunctionWorker.HandleData(AData: Pointer); +type + PGearData = ^TGearData; + TGearData = packed record + IsGearRetractable: Cardinal; + TotalPctExtended: Double; + DamageBySpeed: Integer; + SpeedExceeded: Integer; + end; + +var + gearData: PGearData; + +begin + gearData := AData; + + if gearData^.DamageBySpeed <> 0 then + SetCurrentState(FSXStateUIDGearDamageBySpeed) + + else if gearData^.SpeedExceeded <> 0 then + SetCurrentState(FSXStateUIDGearSpeedExceeded) + + else if gearData^.IsGearRetractable <> 0 then + begin + case Trunc(gearData ^.TotalPctExtended * 100) of + 0: SetCurrentState(FSXStateUIDGearRetracted); + 95..100: SetCurrentState(FSXStateUIDGearExtended); + else SetCurrentState(FSXStateUIDGearBetween); + end; + end else + SetCurrentState(FSXStateUIDGearNotRetractable); +end; + + +{ TFSXParkingBrakeFunctionWorker } +procedure TFSXParkingBrakeFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + ADefinition.AddVariable('BRAKE PARKING INDICATOR', FSX_UNIT_BOOL, SIMCONNECT_DATATYPE_INT32); +end; + + +procedure TFSXParkingBrakeFunctionWorker.HandleData(AData: Pointer); +begin + if PCardinal(AData)^ <> 0 then + SetCurrentState(FSXStateUIDOn) + else + SetCurrentState(FSXStateUIDOff); +end; + + +{ TFSXExitDoorFunctionWorker } +procedure TFSXExitDoorFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + ADefinition.AddVariable('CANOPY OPEN', FSX_UNIT_PERCENT, SIMCONNECT_DATAType_FLOAT64); +end; + + +procedure TFSXExitDoorFunctionWorker.HandleData(AData: Pointer); +begin + case Trunc(PDouble(AData)^) of + 0..5: SetCurrentState(FSXStateUIDExitDoorClosed); + 95..100: SetCurrentState(FSXStateUIDExitDoorOpen); + else SetCurrentState(FSXStateUIDExitDoorBetween); + end; +end; + + +{ TFSXTailHookFunctionWorker } +procedure TFSXTailHookFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXTailHookFunctionWorker.RegisterVariables +end; + + +procedure TFSXTailHookFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXTailHookFunctionWorker.HandleData +end; + + +{ TFSXFlapsFunctionWorker } +procedure TFSXFlapsFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXFlapsFunctionWorker.RegisterVariables +end; + + +procedure TFSXFlapsFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXFlapsFunctionWorker.HandleData +end; + + +{ TFSXSpoilersFunctionWorker } +procedure TFSXSpoilersFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXSpoilersFunctionWorker.RegisterVariables +end; + + +procedure TFSXSpoilersFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXSpoilersFunctionWorker.HandleData +end; + + +{ TFSXBatteryMasterFunctionWorker } +procedure TFSXBatteryMasterFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXBatteryMasterFunctionWorker.RegisterVariables +end; + + +procedure TFSXBatteryMasterFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXBatteryMasterFunctionWorker.HandleData +end; + + +{ TFSXAvionicsMasterFunctionWorker } +procedure TFSXAvionicsMasterFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAvionicsMasterFunctionWorker.RegisterVariables +end; + + +procedure TFSXAvionicsMasterFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAvionicsMasterFunctionWorker.HandleData +end; + + +{ TFSXPressDumpSwitchFunctionWorker } +procedure TFSXPressDumpSwitchFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXPressDumpSwitchFunctionWorker.RegisterVariables +end; + + +procedure TFSXPressDumpSwitchFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXPressDumpSwitchFunctionWorker.HandleData +end; + + +{ TFSXEngineAntiIceFunctionWorker } +procedure TFSXEngineAntiIceFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXEngineAntiIceFunctionWorker.RegisterVariables +end; + + +procedure TFSXEngineAntiIceFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXEngineAntiIceFunctionWorker.HandleData +end; + + +{ TFSXFuelPumpFunctionWorker } +procedure TFSXFuelPumpFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXFuelPumpFunctionWorker.RegisterVariables +end; + + +procedure TFSXFuelPumpFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXFuelPumpFunctionWorker.HandleData +end; + + +{ TFSXDeIceFunctionWorker } +procedure TFSXDeIceFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXDeIceFunctionWorker.RegisterVariables +end; + + +procedure TFSXDeIceFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXDeIceFunctionWorker.HandleData +end; + + +{ TFSXLightStatesFunctionWorker } +procedure TFSXLightStatesFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + ADefinition.AddVariable('LIGHT ON STATES', FSX_UNIT_MASK, SIMCONNECT_DATATYPE_INT32); +end; + + +procedure TFSXLightStatesFunctionWorker.HandleData(AData: Pointer); +begin + if (PCardinal(AData)^ and StateMask) <> 0 then + SetCurrentState(FSXStateUIDOn) + else + SetCurrentState(FSXStateUIDOff); +end; + + +{ TFSXAutoPilotFunctionWorker } +procedure TFSXAutoPilotFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotFunctionWorker.RegisterVariables +end; + + +procedure TFSXAutoPilotFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotFunctionWorker.HandleData +end; + + +{ TFSXAutoPilotHeadingFunctionWorker } +procedure TFSXAutoPilotHeadingFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotHeadingFunctionWorker.RegisterVariables +end; + + +procedure TFSXAutoPilotHeadingFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotHeadingFunctionWorker.HandleData +end; + + +{ TFSXAutoPilotApproachFunctionWorker } +procedure TFSXAutoPilotApproachFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotApproachFunctionWorker.RegisterVariables +end; + + +procedure TFSXAutoPilotApproachFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotApproachFunctionWorker.HandleData +end; + + +{ TFSXAutoPilotBackcourseFunctionWorker } +procedure TFSXAutoPilotBackcourseFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotBackcourseFunctionWorker.RegisterVariables +end; + + +procedure TFSXAutoPilotBackcourseFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotBackcourseFunctionWorker.HandleData +end; + + +{ TFSXAutoPilotAltitudeFunctionWorker } +procedure TFSXAutoPilotAltitudeFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotAltitudeFunctionWorker.RegisterVariables +end; + + +procedure TFSXAutoPilotAltitudeFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotAltitudeFunctionWorker.HandleData +end; + + +{ TFSXAutoPilotNavFunctionWorker } +procedure TFSXAutoPilotNavFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotNavFunctionWorker.RegisterVariables +end; + + +procedure TFSXAutoPilotNavFunctionWorker.HandleData(AData: Pointer); +begin + // #ToDo1 -cEmpty -oMvR: 22-2-2013: TFSXAutoPilotNavFunctionWorker.HandleData +end; + +end. diff --git a/G940LEDControl/Units/FSXResources.pas b/G940LEDControl/Units/FSXResources.pas index b6f6300..f22919e 100644 --- a/G940LEDControl/Units/FSXResources.pas +++ b/G940LEDControl/Units/FSXResources.pas @@ -7,6 +7,7 @@ const FSXProviderUID = 'fsx'; FSXCategory = 'Flight Simulator X'; FSXCategoryLights = FSXCategory + ' - Lights'; + FSXCategoryAutoPilot = FSXCategory + ' - Autopilot'; FSXStateUIDOn = 'on'; FSXStateUIDOff = 'off'; @@ -72,6 +73,76 @@ const FSXFunctionUIDRecognitionLights = 'recognitionLights'; FSXFunctionDisplayNameRecognitionLights = 'Recognition lights'; + FSXFunctionUIDParkingBrake = 'parkingBrake'; + FSXFunctionDisplayNameParkingBrake = 'Parking brake'; + + FSXFunctionUIDExitDoor = 'exitDoor'; + FSXFunctionDisplayNameExitDoor = 'Exit door'; + + FSXStateUIDExitDoorClosed = 'closed'; + FSXStateUIDExitDoorBetween = 'between'; + FSXStateUIDExitDoorOpen = 'open'; + + FSXStateDisplayNameExitDoorClosed = 'Closed'; + FSXStateDisplayNameExitDoorBetween = 'Opening / closing'; + FSXStateDisplayNameExitDoorOpen = 'Open'; + + FSXFunctionUIDTailHook = 'tailHook'; + FSXFunctionDisplayNameTailHook = 'Tail hook'; + + FSXStateUIDTailHookRetracted = 'retracted'; + FSXStateUIDTailHookBetween = 'between'; + FSXStateUIDTailHookExtended = 'extended'; + + FSXStateDisplayNameTailHookRetracted = 'Retracted'; + FSXStateDisplayNameTailHookBetween = 'Extending / retracting'; + FSXStateDisplayNameTailHookExtended = 'Extended'; + + + FSXFunctionUIDFlaps = 'flaps'; + FSXFunctionDisplayNameFlaps = 'Flaps'; + + FSXFunctionUIDSpoilers = 'spoilers'; + FSXFunctionDisplayNameSpoilers = 'Spoilers'; + + FSXFunctionUIDBatteryMaster = 'batteryMaster'; + FSXFunctionDisplayNameBatteryMaster = 'Battery master'; + + FSXFunctionUIDAvionicsMaster = 'avionicsMaster'; + FSXFunctionDisplayNameAvionicsMaster = 'Avionics master'; + + FSXFunctionUIDPressDumpSwitch = 'pressurizationDumpSwitch'; + FSXFunctionDisplayNamePressDumpSwitch = 'Pressurization dump switch'; + + FSXFunctionUIDEngineAntiIce = 'engineAntiIce'; + FSXFunctionDisplayNameEngineAntiIce = 'Engine anti-ice'; + + FSXFunctionUIDFuelPump = 'fuelPump'; + FSXFunctionDisplayNameFuelPump = 'Fuel pump'; + + FSXFunctionUIDDeIce = 'structuralDeIce'; + FSXFunctionDisplayNameDeIce = 'De-ice'; + + FSXFunctionUIDAutoPilot = 'autoPilotMaster'; + FSXFunctionDisplayNameAutoPilot = 'Autopilot master'; + + FSXFunctionUIDAutoPilotHeading = 'autoPilotHeading'; + FSXFunctionDisplayNameAutoPilotHeading = 'Autopilot heading'; + + FSXFunctionUIDAutoPilotApproach = 'autoPilotApproach'; + FSXFunctionDisplayNameAutoPilotApproach = 'Autopilot approach'; + + FSXFunctionUIDAutoPilotBackcourse = 'autoPilotBackcourse'; + FSXFunctionDisplayNameAutoPilotBackcourse = 'Autopilot backcourse'; + + FSXFunctionUIDAutoPilotAltitude = 'autoPilotAltitude'; + FSXFunctionDisplayNameAutoPilotAltitude = 'Autopilot altitude'; + + FSXFunctionUIDAutoPilotNav = 'autoPilotNav'; + FSXFunctionDisplayNameAutoPilotNav = 'Autopilot nav'; + + + implementation diff --git a/G940LEDControl/Units/FSXSimConnectClient.pas b/G940LEDControl/Units/FSXSimConnectClient.pas index 70a4c37..bfd34e7 100644 --- a/G940LEDControl/Units/FSXSimConnectClient.pas +++ b/G940LEDControl/Units/FSXSimConnectClient.pas @@ -306,7 +306,8 @@ end; procedure TFSXSimConnectClient.Cleanup; begin - // TODO unregister definitions ? + // #ToDo1 -oMvR: 22-2-2013: unregister definitions + if SimConnectHandle <> 0 then SimConnect_Close(SimConnectHandle); @@ -491,7 +492,7 @@ var begin removeDefinition := Msg.MsgData; - // TODO actually remove the definition + // #ToDo1 -oMvR: 22-2-2013: actually remove the definition removeDefinition.Signal; end; diff --git a/G940LEDControl/Units/LEDStateConsumer.pas b/G940LEDControl/Units/LEDStateConsumer.pas index 09b998a..f7c1912 100644 --- a/G940LEDControl/Units/LEDStateConsumer.pas +++ b/G940LEDControl/Units/LEDStateConsumer.pas @@ -192,7 +192,10 @@ begin for oldWorker in ButtonWorkers do begin if Assigned(oldWorker) then + begin + (oldWorker as ILEDFunctionWorker).Detach(Self); oldWorkers.Add(oldWorker); + end; end; ButtonWorkers.Clear; diff --git a/G940LEDControl/Units/Settings.pas b/G940LEDControl/Units/Settings.pas new file mode 100644 index 0000000..14c9d4a --- /dev/null +++ b/G940LEDControl/Units/Settings.pas @@ -0,0 +1,63 @@ +unit Settings; + +interface +uses + X2UtPersistIntf; + +type + TSettings = class(TObject) + private + FCheckUpdates: Boolean; + FHasCheckUpdates: Boolean; + + procedure SetCheckUpdates(const Value: Boolean); + public + procedure Load(AReader: IX2PersistReader); + procedure Save(AWriter: IX2PersistWriter); + + property CheckUpdates: Boolean read FCheckUpdates write SetCheckUpdates; + property HasCheckUpdates: Boolean read FHasCheckUpdates; + end; + + +implementation +const + SectionSettings = 'Settings'; + + KeyCheckUpdates = 'CheckUpdates'; + + +{ TSettings } +procedure TSettings.Load(AReader: IX2PersistReader); +var + value: Boolean; + +begin + if AReader.BeginSection(SectionSettings) then + try + if AReader.ReadBoolean(KeyCheckUpdates, value) then + CheckUpdates := value; + finally + AReader.EndSection; + end; +end; + + +procedure TSettings.Save(AWriter: IX2PersistWriter); +begin + if AWriter.BeginSection(SectionSettings) then + try + AWriter.WriteBoolean(KeyCheckUpdates, CheckUpdates); + finally + AWriter.EndSection; + end; +end; + + +procedure TSettings.SetCheckUpdates(const Value: Boolean); +begin + FCheckUpdates := Value; + FHasCheckUpdates := True; +end; + +end.