From b30d1ec59dc9ce9e5818002475ce6d58f8c5cda9 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Wed, 2 Jul 2014 22:23:17 +0000 Subject: [PATCH] Added fuel level function --- G940LEDControl/Forms/ButtonFunctionFrm.dfm | 14 +++-- G940LEDControl/G940LEDControl.dproj | 8 +-- G940LEDControl/G940LEDControl.res | Bin 28524 -> 27828 bytes G940LEDControl/Units/FSXLEDFunction.pas | 37 ++++++++++++ .../Units/FSXLEDFunctionProvider.pas | 3 + G940LEDControl/Units/FSXLEDFunctionWorker.pas | 53 +++++++++++++++++- G940LEDControl/Units/FSXResources.pas | 26 +++++++++ 7 files changed, 130 insertions(+), 11 deletions(-) diff --git a/G940LEDControl/Forms/ButtonFunctionFrm.dfm b/G940LEDControl/Forms/ButtonFunctionFrm.dfm index a9f3300..ddbe85c 100644 --- a/G940LEDControl/Forms/ButtonFunctionFrm.dfm +++ b/G940LEDControl/Forms/ButtonFunctionFrm.dfm @@ -5,7 +5,7 @@ object ButtonFunctionForm: TButtonFunctionForm BorderIcons = [biSystemMenu] BorderStyle = bsDialog Caption = 'Configure button' - ClientHeight = 484 + ClientHeight = 561 ClientWidth = 692 Color = clBtnFace Font.Charset = DEFAULT_CHARSET @@ -31,7 +31,7 @@ object ButtonFunctionForm: TButtonFunctionForm object pnlButtons: TPanel AlignWithMargins = True Left = 0 - Top = 441 + Top = 518 Width = 692 Height = 43 Margins.Left = 0 @@ -41,6 +41,7 @@ object ButtonFunctionForm: TButtonFunctionForm Align = alBottom BevelOuter = bvNone TabOrder = 3 + ExplicitTop = 441 DesignSize = ( 692 43) @@ -80,7 +81,7 @@ object ButtonFunctionForm: TButtonFunctionForm Left = 8 Top = 60 Width = 257 - Height = 373 + Height = 450 Margins.Left = 8 Margins.Top = 8 Margins.Right = 0 @@ -103,6 +104,7 @@ object ButtonFunctionForm: TButtonFunctionForm OnGetText = vstFunctionsGetText OnPaintText = vstFunctionsPaintText OnIncrementalSearch = vstFunctionsIncrementalSearch + ExplicitHeight = 373 Columns = < item Position = 0 @@ -115,7 +117,7 @@ object ButtonFunctionForm: TButtonFunctionForm Left = 273 Top = 60 Width = 411 - Height = 373 + Height = 450 Margins.Left = 8 Margins.Top = 8 Margins.Right = 8 @@ -123,6 +125,7 @@ object ButtonFunctionForm: TButtonFunctionForm Align = alClient BevelOuter = bvNone TabOrder = 2 + ExplicitHeight = 373 object pnlName: TPanel Left = 0 Top = 0 @@ -190,10 +193,11 @@ object ButtonFunctionForm: TButtonFunctionForm Left = 0 Top = 97 Width = 411 - Height = 276 + Height = 353 Align = alClient BorderStyle = bsNone TabOrder = 1 + ExplicitHeight = 276 end end object pnlHeader: TPanel diff --git a/G940LEDControl/G940LEDControl.dproj b/G940LEDControl/G940LEDControl.dproj index c318d2e..813da3d 100644 --- a/G940LEDControl/G940LEDControl.dproj +++ b/G940LEDControl/G940LEDControl.dproj @@ -8,7 +8,7 @@ VCL 13.4 True - Release + Debug Win32 1 Application @@ -103,7 +103,7 @@ false CompanyName=;FileDescription=;FileVersion=0.2.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=0.2;Comments= - F:\Components\X2Utils\Resources\VistaManAsInvoker.manifest + $(BDS)\bin\default_app.manifest 1033 @@ -200,9 +200,7 @@ 1.0.0.0 - - ExpressPivotGrid 2 OLAP by Developer Express Inc. - + False diff --git a/G940LEDControl/G940LEDControl.res b/G940LEDControl/G940LEDControl.res index 906ddee2cba7b0ebdff29348afd88ed20b99346a..4ed79be010dbe416f03dd8eaf98310de00f0dc36 100644 GIT binary patch delta 13 VcmaEJk8#UQ#t90WZ!k^C0RS>q2A2Q; delta 714 zcmaKqy-EX75QV=D5ezo|yucQg5)z4mg$O25BOwtZ!A^q47>K(eiKx}Sf`vt1!BVmH zEo^M8ECpLD*gK|s}Uo|&D2i@Gwea1K!uVGHpF(xMSu zNg3I+W7!j+&j}Zr$RIY(2$ZH`RJ 0 then begin @@ -651,4 +659,47 @@ begin SetCurrentState(FSXStateUIDOff); end; + +{ TFSXFuelFunctionWorker } +procedure TFSXFuelFunctionWorker.RegisterVariables(ADefinition: IFSXSimConnectDefinition); +begin + ADefinition.AddVariable('FUEL TOTAL CAPACITY', FSX_UNIT_NUMBER, SIMCONNECT_DATAType_FLOAT64); + ADefinition.AddVariable('FUEL TOTAL QUANTITY', FSX_UNIT_NUMBER, SIMCONNECT_DATAType_FLOAT64); +end; + + +procedure TFSXFuelFunctionWorker.HandleData(AData: Pointer); +type + PFuelData = ^TFuelData; + TFuelData = packed record + TotalCapacity: Double; + TotalQuantity: Double; + end; + +var + fuelData: PFuelData; + percentage: Integer; + +begin + fuelData := AData; + + if fuelData^.TotalCapacity > 0 then + begin + percentage := Ceil(fuelData^.TotalQuantity / fuelData^.TotalCapacity * 100); + case percentage of + 0: SetCurrentState(FSXStateUIDFuelEmpty); + 1: SetCurrentState(FSXStateUIDFuel0to1); + 2: SetCurrentState(FSXStateUIDFuel1to2); + 3..5: SetCurrentState(FSXStateUIDFuel2to5); + 6..10: SetCurrentState(FSXStateUIDFuel5to10); + 11..20: SetCurrentState(FSXStateUIDFuel10to20); + 21..50: SetCurrentState(FSXStateUIDFuel20to50); + 51..75: SetCurrentState(FSXStateUIDFuel50to75); + else + SetCurrentState(FSXStateUIDFuel75to100); + end; + end else + SetCurrentState(FSXStateUIDFuelNotAvailable); +end; + end. diff --git a/G940LEDControl/Units/FSXResources.pas b/G940LEDControl/Units/FSXResources.pas index 11f3dd5..55d1197 100644 --- a/G940LEDControl/Units/FSXResources.pas +++ b/G940LEDControl/Units/FSXResources.pas @@ -194,6 +194,32 @@ const FSXFunctionDisplayNameAutoPilotNav = 'Autopilot nav'; + FSXFunctionUIDFuel = 'fuelLevel'; + FSXFunctionDisplayNameFuel = 'Fuel Level'; + + FSXStateUIDFuelNotAvailable = 'notAvailable'; + FSXStateUIDFuelEmpty = 'empty'; + FSXStateUIDFuel0to1 = '0To1'; + FSXStateUIDFuel1to2 = '1To2'; + FSXStateUIDFuel2to5 = '2To5'; + FSXStateUIDFuel5to10 = '5To10'; + FSXStateUIDFuel10to20 = '10To20'; + FSXStateUIDFuel20to50 = '20To50'; + FSXStateUIDFuel50to75 = '50To75'; + FSXStateUIDFuel75to100 = '75To100'; + + FSXStateDisplayNameFuelNotAvailable = 'Not available'; + FSXStateDisplayNameFuelEmpty = 'Empty'; + FSXStateDisplayNameFuel0to1 = '< 1%'; + FSXStateDisplayNameFuel1to2 = '< 2%'; + FSXStateDisplayNameFuel2to5 = '< 5%'; + FSXStateDisplayNameFuel5to10 = '< 10%'; + FSXStateDisplayNameFuel10to20 = '< 20%'; + FSXStateDisplayNameFuel20to50 = '< 50%'; + FSXStateDisplayNameFuel50to75 = '< 75%'; + FSXStateDisplayNameFuel75to100 = '75% - Full'; + + FSXMenuProfiles = 'G940 Profile'; FSXMenuProfileFormat = 'G940: %s';