1
0
mirror of synced 2024-11-04 18:49:16 +00:00

Added: start of configuration conversion

Added: registration of states
Added: prototype FSX function implemention
- subject to change; separation of definition and running state will be added later
This commit is contained in:
Mark van Renswoude 2013-02-14 21:45:25 +00:00
parent b1035c6db2
commit 32f411c1b8
12 changed files with 546 additions and 158 deletions

View File

@ -32,12 +32,8 @@ object MainForm: TMainForm
ActivePage = tsFSX ActivePage = tsFSX
Align = alClient Align = alClient
TabOrder = 1 TabOrder = 1
ExplicitWidth = 390
ExplicitHeight = 510
object tsFSX: TTabSheet object tsFSX: TTabSheet
Caption = 'Configuration' Caption = 'Configuration'
ExplicitWidth = 382
ExplicitHeight = 482
DesignSize = ( DesignSize = (
441 441
446) 446)
@ -346,7 +342,6 @@ object MainForm: TMainForm
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
Caption = 'Save as...' Caption = 'Save as...'
TabOrder = 9 TabOrder = 9
ExplicitLeft = 340
end end
object btnDeleteProfile: TButton object btnDeleteProfile: TButton
Left = 364 Left = 364
@ -356,12 +351,13 @@ object MainForm: TMainForm
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
Caption = 'Delete' Caption = 'Delete'
TabOrder = 10 TabOrder = 10
ExplicitLeft = 421
end end
end end
object tsAbout: TTabSheet object tsAbout: TTabSheet
Caption = 'About' Caption = 'About'
ImageIndex = 1 ImageIndex = 1
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 382 ExplicitWidth = 382
ExplicitHeight = 482 ExplicitHeight = 482
object lblVersionCaption: TLabel object lblVersionCaption: TLabel
@ -479,7 +475,6 @@ object MainForm: TMainForm
Align = alTop Align = alTop
BevelOuter = bvNone BevelOuter = bvNone
TabOrder = 0 TabOrder = 0
ExplicitWidth = 390
DesignSize = ( DesignSize = (
449 449
64) 64)
@ -861,7 +856,6 @@ object MainForm: TMainForm
TabOrder = 0 TabOrder = 0
Visible = False Visible = False
OnClick = btnRetryClick OnClick = btnRetryClick
ExplicitLeft = 315
end end
end end
end end

View File

@ -175,7 +175,7 @@ uses
LEDColorIntf, LEDColorIntf,
LEDFunctionIntf, LEDFunctionIntf,
LEDFunctionRegistry, LEDFunctionRegistry,
StaticLEDFunction; StaticResources;
{$R *.dfm} {$R *.dfm}
@ -192,11 +192,6 @@ const
TEXT_STATE_NOTFOUND = 'Not found'; TEXT_STATE_NOTFOUND = 'Not found';
TEXT_STATE_FOUND = 'Connected'; TEXT_STATE_FOUND = 'Connected';
KEY_SETTINGS = '\Software\X2Software\G940LEDControl\';
SECTION_DEFAULTPROFILE = 'DefaultProfile';
SECTION_FSX = 'FSX';
SECTION_SETTINGS = 'Settings';
type type
TComboBoxFunctionConsumer = class(TInterfacedObject, IFunctionConsumer) TComboBoxFunctionConsumer = class(TInterfacedObject, IFunctionConsumer)
@ -306,7 +301,7 @@ begin
if not FileExists(FProfilesFilename) then if not FileExists(FProfilesFilename) then
begin begin
{ Check if version 0.x settings are in the registry } { Check if version 0.x settings are in the registry }
defaultProfile := ConfigConversion.Convert0To1; defaultProfile := ConfigConversion.ConvertProfile0To1;
if not Assigned(defaultProfile) then if not Assigned(defaultProfile) then
defaultProfile := CreateDefaultProfile; defaultProfile := CreateDefaultProfile;
@ -519,61 +514,6 @@ end;
//end; //end;
//procedure TMainForm.LoadDefaultProfile;
//var
// registryReader: TX2UtPersistRegistry;
// reader: IX2PersistReader;
//
//begin
// registryReader := TX2UtPersistRegistry.Create;
// try
// registryReader.RootKey := HKEY_CURRENT_USER;
// registryReader.Key := KEY_SETTINGS;
//
// reader := registryReader.CreateReader;
//
// if reader.BeginSection(SECTION_DEFAULTPROFILE) then
// try
// ReadFunctions(reader, FFSXComboBoxes);
// ReadFSXExtra(reader);
// finally
// reader.EndSection;
// end;
//
// ReadAutoUpdate(reader);
// finally
// FreeAndNil(registryReader);
// end;
//end;
//
//
//procedure TMainForm.SaveDefaultProfile;
//var
// registryWriter: TX2UtPersistRegistry;
// writer: IX2PersistWriter;
//
//begin
// registryWriter := TX2UtPersistRegistry.Create;
// try
// registryWriter.RootKey := HKEY_CURRENT_USER;
// registryWriter.Key := KEY_SETTINGS;
//
// writer := registryWriter.CreateWriter;
// if writer.BeginSection(SECTION_DEFAULTPROFILE) then
// try
// WriteFunctions(writer, FFSXComboBoxes);
// WriteFSXExtra(writer);
// finally
// writer.EndSection;
// end;
//
// WriteAutoUpdate(writer);
// finally
// FreeAndNil(registryWriter);
// end;
//end;
//procedure TMainForm.InitializeStateProvider(AProviderClass: TLEDStateProviderClass); //procedure TMainForm.InitializeStateProvider(AProviderClass: TLEDStateProviderClass);
//begin //begin
// UpdateMapping; // UpdateMapping;

View File

@ -25,7 +25,11 @@ uses
LEDState in 'Units\LEDState.pas', LEDState in 'Units\LEDState.pas',
Profile in 'Units\Profile.pas', Profile in 'Units\Profile.pas',
LEDColorPool in 'Units\LEDColorPool.pas', LEDColorPool in 'Units\LEDColorPool.pas',
ButtonFunctionFrm in 'Forms\ButtonFunctionFrm.pas' {ButtonFunctionForm}; ButtonFunctionFrm in 'Forms\ButtonFunctionFrm.pas' {ButtonFunctionForm},
FSXLEDFunction in 'Units\FSXLEDFunction.pas',
StaticResources in 'Units\StaticResources.pas',
FSXResources in 'Units\FSXResources.pas',
FSXSimConnectClient in 'Units\FSXSimConnectClient.pas';
{$R *.res} {$R *.res}

View File

@ -191,6 +191,10 @@
<Form>ButtonFunctionForm</Form> <Form>ButtonFunctionForm</Form>
<FormType>dfm</FormType> <FormType>dfm</FormType>
</DCCReference> </DCCReference>
<DCCReference Include="Units\FSXLEDFunction.pas"/>
<DCCReference Include="Units\StaticResources.pas"/>
<DCCReference Include="Units\FSXResources.pas"/>
<DCCReference Include="Units\FSXSimConnectClient.pas"/>
<BuildConfiguration Include="Debug"> <BuildConfiguration Include="Debug">
<Key>Cfg_2</Key> <Key>Cfg_2</Key>
<CfgParent>Base</CfgParent> <CfgParent>Base</CfgParent>

View File

@ -5,59 +5,167 @@ uses
Profile; Profile;
{ Version 0.x: registry -> 1.x: XML } { Version 0.x: registry -> 1.x: XML }
function Convert0To1: TProfile; function ConvertProfile0To1: TProfile;
implementation implementation
uses
System.SysUtils,
Winapi.Windows,
X2UtPersistIntf,
X2UtPersistRegistry,
LEDColorIntf,
StaticResources;
const
V0_FUNCTION_NONE = 0;
V0_FUNCTION_OFF = 1;
V0_FUNCTION_RED = 2;
V0_FUNCTION_AMBER = 3;
V0_FUNCTION_GREEN = 4;
V0_FUNCTIONPROVIDER_OFFSET = V0_FUNCTION_GREEN;
V0_FUNCTIONFSX_GEAR = V0_FUNCTIONPROVIDER_OFFSET + 1;
V0_FUNCTIONFSX_LANDINGLIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 2;
V0_FUNCTIONFSX_INSTRUMENTLIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 3;
V0_FUNCTIONFSX_PARKINGBRAKE = V0_FUNCTIONPROVIDER_OFFSET + 4;
V0_FUNCTIONFSX_ENGINE = V0_FUNCTIONPROVIDER_OFFSET + 5;
V0_FUNCTIONFSX_EXITDOOR = V0_FUNCTIONPROVIDER_OFFSET + 6;
V0_FUNCTIONFSX_STROBELIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 7;
V0_FUNCTIONFSX_NAVLIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 8;
V0_FUNCTIONFSX_BEACONLIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 9;
V0_FUNCTIONFSX_FLAPS = V0_FUNCTIONPROVIDER_OFFSET + 10;
V0_FUNCTIONFSX_BATTERYMASTER = V0_FUNCTIONPROVIDER_OFFSET + 11;
V0_FUNCTIONFSX_AVIONICSMASTER = V0_FUNCTIONPROVIDER_OFFSET + 12;
V0_FUNCTIONFSX_SPOILERS = V0_FUNCTIONPROVIDER_OFFSET + 13;
V0_FUNCTIONFSX_PRESSURIZATIONDUMPSWITCH = V0_FUNCTIONPROVIDER_OFFSET + 14;
V0_FUNCTIONFSX_CARBHEAT = V0_FUNCTIONPROVIDER_OFFSET + 15;
V0_FUNCTIONFSX_AUTOPILOT = V0_FUNCTIONPROVIDER_OFFSET + 16;
V0_FUNCTIONFSX_FUELPUMP = V0_FUNCTIONPROVIDER_OFFSET + 17;
V0_FUNCTIONFSX_TAILHOOK = V0_FUNCTIONPROVIDER_OFFSET + 18;
V0_FUNCTIONFSX_AUTOPILOT_AMBER = V0_FUNCTIONPROVIDER_OFFSET + 19;
V0_FUNCTIONFSX_AUTOPILOT_HEADING = V0_FUNCTIONPROVIDER_OFFSET + 20;
V0_FUNCTIONFSX_AUTOPILOT_APPROACH = V0_FUNCTIONPROVIDER_OFFSET + 21;
V0_FUNCTIONFSX_AUTOPILOT_BACKCOURSE = V0_FUNCTIONPROVIDER_OFFSET + 22;
V0_FUNCTIONFSX_AUTOPILOT_ALTITUDE = V0_FUNCTIONPROVIDER_OFFSET + 23;
V0_FUNCTIONFSX_AUTOPILOT_NAV = V0_FUNCTIONPROVIDER_OFFSET + 24;
V0_FUNCTIONFSX_TAXILIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 25;
V0_FUNCTIONFSX_RECOGNITIONLIGHTS = V0_FUNCTIONPROVIDER_OFFSET + 26;
procedure ConvertProfileFunction0To1(AOldFunction: Integer; AButton: TProfileButton);
procedure SetButton(const AProviderUID, AFunctionUID: string);
begin
AButton.ProviderUID := AProviderUID;
AButton.FunctionUID := AFunctionUID;
end;
begin
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]);
{ FSX }
{
V0_FUNCTIONFSX_GEAR:
V0_FUNCTIONFSX_LANDINGLIGHTS:
V0_FUNCTIONFSX_INSTRUMENTLIGHTS:
V0_FUNCTIONFSX_PARKINGBRAKE:
V0_FUNCTIONFSX_ENGINE:
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_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]);
end;
end;
function ConvertProfile0To1: TProfile;
const
KEY_SETTINGS = '\Software\X2Software\G940LEDControl\';
SECTION_DEFAULTPROFILE = 'DefaultProfile';
SECTION_FSX = 'FSX';
SECTION_SETTINGS = 'Settings';
var
registryReader: TX2UtPersistRegistry;
reader: IX2PersistReader;
buttonIndex: Integer;
value: Integer;
function Convert0To1: TProfile;
begin begin
Result := nil; Result := nil;
registryReader := TX2UtPersistRegistry.Create;
try
registryReader.RootKey := HKEY_CURRENT_USER;
registryReader.Key := KEY_SETTINGS;
reader := registryReader.CreateReader;
// FUNCTION_NONE = 0; if reader.BeginSection(SECTION_DEFAULTPROFILE) then
// FUNCTION_OFF = 1; try
// FUNCTION_RED = 2; if reader.BeginSection(SECTION_FSX) then
// FUNCTION_AMBER = 3; try
// FUNCTION_GREEN = 4; for buttonIndex := 0 to 7 do
begin
if reader.ReadInteger('Function' + IntToStr(buttonIndex), value) then
begin
if not Assigned(Result) then
Result := TProfile.Create;
{ ConvertProfileFunction0To1(value, Result.Buttons[buttonIndex]);
FUNCTION_PROVIDER_OFFSET = 4 end;
end;
finally
reader.EndSection;
end;
finally
reader.EndSection;
end;
FUNCTION_FSX_GEAR = FUNCTION_PROVIDER_OFFSET + 1; // TODO auto update settings
FUNCTION_FSX_LANDINGLIGHTS = FUNCTION_PROVIDER_OFFSET + 2; //ReadAutoUpdate(reader);
FUNCTION_FSX_INSTRUMENTLIGHTS = FUNCTION_PROVIDER_OFFSET + 3; finally
FUNCTION_FSX_PARKINGBRAKE = FUNCTION_PROVIDER_OFFSET + 4; FreeAndNil(registryReader);
FUNCTION_FSX_ENGINE = FUNCTION_PROVIDER_OFFSET + 5; end;
FUNCTION_FSX_EXITDOOR = FUNCTION_PROVIDER_OFFSET + 6;
FUNCTION_FSX_STROBELIGHTS = FUNCTION_PROVIDER_OFFSET + 7;
FUNCTION_FSX_NAVLIGHTS = FUNCTION_PROVIDER_OFFSET + 8;
FUNCTION_FSX_BEACONLIGHTS = FUNCTION_PROVIDER_OFFSET + 9;
FUNCTION_FSX_FLAPS = FUNCTION_PROVIDER_OFFSET + 10;
FUNCTION_FSX_BATTERYMASTER = FUNCTION_PROVIDER_OFFSET + 11;
FUNCTION_FSX_AVIONICSMASTER = FUNCTION_PROVIDER_OFFSET + 12;
FUNCTION_FSX_SPOILERS = FUNCTION_PROVIDER_OFFSET + 13;
FUNCTION_FSX_PRESSURIZATIONDUMPSWITCH = FUNCTION_PROVIDER_OFFSET + 14;
FUNCTION_FSX_CARBHEAT = FUNCTION_PROVIDER_OFFSET + 15;
FUNCTION_FSX_AUTOPILOT = FUNCTION_PROVIDER_OFFSET + 16;
FUNCTION_FSX_FUELPUMP = FUNCTION_PROVIDER_OFFSET + 17;
FUNCTION_FSX_TAILHOOK = FUNCTION_PROVIDER_OFFSET + 18;
FUNCTION_FSX_AUTOPILOT_AMBER = FUNCTION_PROVIDER_OFFSET + 19;
FUNCTION_FSX_AUTOPILOT_HEADING = FUNCTION_PROVIDER_OFFSET + 20;
FUNCTION_FSX_AUTOPILOT_APPROACH = FUNCTION_PROVIDER_OFFSET + 21;
FUNCTION_FSX_AUTOPILOT_BACKCOURSE = FUNCTION_PROVIDER_OFFSET + 22;
FUNCTION_FSX_AUTOPILOT_ALTITUDE = FUNCTION_PROVIDER_OFFSET + 23;
FUNCTION_FSX_AUTOPILOT_NAV = FUNCTION_PROVIDER_OFFSET + 24;
FUNCTION_FSX_TAXILIGHTS = FUNCTION_PROVIDER_OFFSET + 25;
FUNCTION_FSX_RECOGNITIONLIGHTS = FUNCTION_PROVIDER_OFFSET + 26;
}
end; end;
end. end.

View File

@ -0,0 +1,231 @@
unit FSXLEDFunction;
interface
uses
Generics.Collections,
LEDFunction,
LEDStateIntf,
ObserverIntf;
type
TCustomFSXFunction = class;
TCustomFSXFunctionList = TObjectList<TCustomFSXFunction>;
TFSXLEDFunctionProvider = class(TCustomLEDFunctionProvider)
private
FConnectedFunctions: TCustomFSXFunctionList;
FSimConnectHandle: THandle;
protected
procedure SimConnect;
procedure SimDisconnect;
procedure Connect(AFunction: TCustomFSXFunction); virtual;
procedure Disconnect(AFunction: TCustomFSXFunction); virtual;
property ConnectedFunctions: TCustomFSXFunctionList read FConnectedFunctions;
property SimConnectHandle: THandle read FSimConnectHandle;
protected
procedure RegisterFunctions; override;
function GetUID: string; override;
end;
TCustomFSXFunction = class(TCustomMultiStateLEDFunction)
private
FProvider: TFSXLEDFunctionProvider;
protected
procedure SimConnected; virtual;
procedure SimDisconnected; virtual;
property Provider: TFSXLEDFunctionProvider read FProvider;
protected
procedure Attach(AObserver: IObserver); override;
procedure Detach(AObserver: IObserver); override;
function GetCategoryName: string; override;
public
constructor Create(AProvider: TFSXLEDFunctionProvider);
end;
TFSXGearFunction = class(TCustomFSXFunction)
private
FRetractedState: ILEDState;
FBetweenState: ILEDState;
FExtendedState: ILEDState;
FSpeedExceededState: ILEDState;
FDamageBySpeedState: ILEDState;
protected
procedure RegisterStates; override;
function GetDisplayName: string; override;
function GetUID: string; override;
function GetCurrentState: ILEDState; override;
end;
implementation
uses
FSXResources,
LEDColorPool,
LEDFunctionRegistry,
LEDState;
{ TFSXLEDFunctionProvider }
procedure TFSXLEDFunctionProvider.RegisterFunctions;
begin
RegisterFunction(TFSXGearFunction.Create(Self));
end;
function TFSXLEDFunctionProvider.GetUID: string;
begin
Result := FSXProviderUID;
end;
procedure TFSXLEDFunctionProvider.SimConnect;
var
fsxFunction: TCustomFSXFunction;
begin
if SimConnectHandle <> 0 then
exit;
// FSimConnectHandle :=
if SimConnectHandle <> 0 then
begin
for fsxFunction in ConnectedFunctions do
fsxFunction.SimConnected;
end;
end;
procedure TFSXLEDFunctionProvider.SimDisconnect;
begin
if SimConnectHandle = 0 then
exit;
end;
procedure TFSXLEDFunctionProvider.Connect(AFunction: TCustomFSXFunction);
begin
if ConnectedFunctions.IndexOf(AFunction) = -1 then
begin
ConnectedFunctions.Add(AFunction);
if ConnectedFunctions.Count > 0 then
SimConnect;
end;
end;
procedure TFSXLEDFunctionProvider.Disconnect(AFunction: TCustomFSXFunction);
begin
ConnectedFunctions.Remove(AFunction);
if ConnectedFunctions.Count = 0 then
SimDisconnect;
end;
{ TCustomFSXFunction }
constructor TCustomFSXFunction.Create(AProvider: TFSXLEDFunctionProvider);
begin
inherited Create;
FProvider := AProvider;
end;
procedure TCustomFSXFunction.Attach(AObserver: IObserver);
begin
if Observers.Count = 0 then
Provider.Connect(Self);
inherited Attach(AObserver);
end;
procedure TCustomFSXFunction.Detach(AObserver: IObserver);
begin
if Assigned(Provider) and (Observers.Count > 0) then
begin
inherited Detach(AObserver);
if Observers.Count = 0 then
Provider.Disconnect(Self);
end else
inherited Detach(AObserver);
end;
function TCustomFSXFunction.GetCategoryName: string;
begin
Result := FSXCategory;
end;
procedure TCustomFSXFunction.SimConnected;
begin
end;
procedure TCustomFSXFunction.SimDisconnected;
begin
end;
{ TFSXGearFunction }
procedure TFSXGearFunction.RegisterStates;
begin
FRetractedState := RegisterState(TLEDState.Create(FSXStateUIDGearRetracted,
FSXStateDisplayNameGearRetracted,
TLEDColorPool.GetColor(cpeStaticRed)));
FBetweenState := RegisterState(TLEDState.Create(FSXStateUIDGearBetween,
FSXStateDisplayNameGearBetween,
TLEDColorPool.GetColor(cpeStaticAmber)));
FExtendedState := RegisterState(TLEDState.Create(FSXStateUIDGearExtended,
FSXStateDisplayNameGearExtended,
TLEDColorPool.GetColor(cpeStaticGreen)));
FSpeedExceededState := RegisterState(TLEDState.Create(FSXStateUIDGearSpeedExceeded,
FSXStateDisplayNameGearSpeedExceeded,
TLEDColorPool.GetColor(cpeFlashingAmberNormal)));
FDamageBySpeedState := RegisterState(TLEDState.Create(FSXStateUIDGearDamageBySpeed,
FSXStateDisplayNameGearDamageBySpeed,
TLEDColorPool.GetColor(cpeFlashingRedFast)));
end;
function TFSXGearFunction.GetDisplayName: string;
begin
Result := FSXFunctionDisplayNameGear;
end;
function TFSXGearFunction.GetUID: string;
begin
Result := FSXFunctionUIDGear;
end;
function TFSXGearFunction.GetCurrentState: ILEDState;
begin
// TODO TFSXGearFunction.GetCurrentState
end;
initialization
TLEDFunctionRegistry.Register(TFSXLEDFunctionProvider.Create);
end.

View File

@ -0,0 +1,28 @@
unit FSXResources;
interface
const
FSXProviderUID = 'fsx';
FSXCategory = 'Flight Simulator X';
FSXFunctionUIDGear = 'gear';
FSXFunctionDisplayNameGear = 'Gear';
FSXStateUIDGearRetracted = 'retracted';
FSXStateUIDGearBetween = 'between';
FSXStateUIDGearExtended = 'extended';
FSXStateUIDGearSpeedExceeded = 'speedExceeded';
FSXStateUIDGearDamageBySpeed = 'damageBySpeed';
FSXStateDisplayNameGearRetracted = 'Retracted';
FSXStateDisplayNameGearBetween = 'Extending / retracting';
FSXStateDisplayNameGearExtended = 'Extended';
FSXStateDisplayNameGearSpeedExceeded = 'Speed exceeded';
FSXStateDisplayNameGearDamageBySpeed = 'Damage by speed';
implementation
end.

View File

@ -0,0 +1,14 @@
unit FSXSimConnectClient;
interface
uses
OtlTaskControl;
type
TFSXSimConnectClient = class(TOmniWorker)
end;
implementation
end.

View File

@ -26,7 +26,8 @@ type
function DoGetColor(AEntry: TLEDColorPoolEntry): ILEDColor; function DoGetColor(AEntry: TLEDColorPoolEntry): ILEDColor;
public public
class function GetColor(AEntry: TLEDColorPoolEntry): ILEDColor; class function GetColor(AEntry: TLEDColorPoolEntry): ILEDColor; overload;
class function GetColor(AColor: TLEDColor): ILEDColor; overload;
end; end;
@ -49,6 +50,19 @@ begin
end; end;
class function TLEDColorPool.GetColor(AColor: TLEDColor): ILEDColor;
begin
Result := nil;
case AColor of
lcOff: Result := GetColor(cpeStaticOff);
lcGreen: Result := GetColor(cpeStaticGreen);
lcAmber: Result := GetColor(cpeStaticAmber);
lcRed: Result := GetColor(cpeStaticRed);
end;
end;
class function TLEDColorPool.Instance: TLEDColorPool; class function TLEDColorPool.Instance: TLEDColorPool;
begin begin
if not Assigned(LEDColorPoolInstance) then if not Assigned(LEDColorPoolInstance) then

View File

@ -14,7 +14,8 @@ type
private private
FFunctions: TInterfaceList; FFunctions: TInterfaceList;
protected protected
procedure RegisterFunction(AFunction: ILEDFunction); procedure RegisterFunctions; virtual; abstract;
function RegisterFunction(AFunction: ILEDFunction): ILEDFunction; virtual;
protected protected
{ ILEDFunctionProvider } { ILEDFunctionProvider }
function GetUID: string; virtual; abstract; function GetUID: string; virtual; abstract;
@ -30,24 +31,20 @@ type
TCustomLEDFunction = class(TInterfacedObject, IObservable, ILEDFunction) TCustomLEDFunction = class(TInterfacedObject, IObservable, ILEDFunction)
private private
FObservers: TInterfaceList; FObservers: TInterfaceList;
FStates: TInterfaceList;
protected protected
// procedure SetCurrentState(AState: ILEDState); virtual;
procedure NotifyObservers; virtual; procedure NotifyObservers; virtual;
property Observers: TInterfaceList read FObservers; property Observers: TInterfaceList read FObservers;
protected protected
{ IObservable } { IObservable }
procedure Attach(AObserver: IObserver); procedure Attach(AObserver: IObserver); virtual;
procedure Detach(AObserver: IObserver); procedure Detach(AObserver: IObserver); virtual;
{ ILEDFunction } { ILEDFunction }
function GetCategoryName: string; virtual; abstract; function GetCategoryName: string; virtual; abstract;
function GetDisplayName: string; virtual; abstract; function GetDisplayName: string; virtual; abstract;
function GetUID: string; virtual; abstract; function GetUID: string; virtual; abstract;
function GetEnumerator: ILEDStateEnumerator; virtual;
function GetCurrentState: ILEDState; virtual; abstract; function GetCurrentState: ILEDState; virtual; abstract;
public public
constructor Create; constructor Create;
@ -55,6 +52,22 @@ type
end; end;
TCustomMultiStateLEDFunction = class(TCustomLEDFunction, ILEDMultiStateFunction)
private
FStates: TInterfaceList;
protected
// procedure SetCurrentState(AState: ILEDState); virtual;
procedure RegisterStates; virtual; abstract;
function RegisterState(AState: ILEDState): ILEDState; virtual;
protected
{ ILEDMultiStateFunction }
function GetEnumerator: ILEDStateEnumerator; virtual;
public
constructor Create;
destructor Destroy; override;
end;
TLEDFunctionEnumerator = class(TInterfacedObject, ILEDFunctionEnumerator) TLEDFunctionEnumerator = class(TInterfacedObject, ILEDFunctionEnumerator)
private private
FList: TInterfaceList; FList: TInterfaceList;
@ -93,13 +106,11 @@ begin
inherited Create; inherited Create;
FObservers := TInterfaceList.Create; FObservers := TInterfaceList.Create;
FStates := TInterfaceList.Create;
end; end;
destructor TCustomLEDFunction.Destroy; destructor TCustomLEDFunction.Destroy;
begin begin
FreeAndNil(FStates);
FreeAndNil(FObservers); FreeAndNil(FObservers);
inherited Destroy; inherited Destroy;
@ -118,13 +129,38 @@ begin
end; end;
function TCustomLEDFunction.GetEnumerator: ILEDStateEnumerator; { TCustomMultiStateLEDFunction }
constructor TCustomMultiStateLEDFunction.Create;
begin
inherited Create;
FStates := TInterfaceList.Create;
RegisterStates;
end;
destructor TCustomMultiStateLEDFunction.Destroy;
begin
FreeAndNil(FStates);
inherited;
end;
function TCustomMultiStateLEDFunction.RegisterState(AState: ILEDState): ILEDState;
begin
Result := AState as ILEDState;
FStates.Add(Result);
end;
function TCustomMultiStateLEDFunction.GetEnumerator: ILEDStateEnumerator;
begin begin
Result := TLEDStateEnumerator.Create(FStates); Result := TLEDStateEnumerator.Create(FStates);
end; end;
//procedure TCustomLEDFunction.SetCurrentState(AState: ILEDState); //procedure TCustomMultiStateLEDFunction.SetCurrentState(AState: ILEDState);
//begin //begin
// FCurrentState := AState; // FCurrentState := AState;
// NotifyObservers; // NotifyObservers;
@ -147,6 +183,7 @@ begin
inherited Create; inherited Create;
FFunctions := TInterfaceList.Create; FFunctions := TInterfaceList.Create;
RegisterFunctions;
end; end;
@ -174,9 +211,10 @@ begin
end; end;
procedure TCustomLEDFunctionProvider.RegisterFunction(AFunction: ILEDFunction); function TCustomLEDFunctionProvider.RegisterFunction(AFunction: ILEDFunction): ILEDFunction;
begin begin
FFunctions.Add(AFunction as ILEDFunction); Result := AFunction as ILEDFunction;
FFunctions.Add(Result);
end; end;

View File

@ -10,15 +10,16 @@ uses
type type
TStaticLEDFunctionProvider = class(TCustomLEDFunctionProvider) TStaticLEDFunctionProvider = class(TCustomLEDFunctionProvider)
protected protected
procedure RegisterFunctions; override;
function GetUID: string; override; function GetUID: string; override;
public
constructor Create;
end; end;
TStaticLEDFunction = class(TCustomLEDFunction) TStaticLEDFunction = class(TCustomLEDFunction)
private private
FColor: TLEDColor; FColor: TLEDColor;
FState: ILEDState;
protected protected
function GetCategoryName: string; override; function GetCategoryName: string; override;
function GetDisplayName: string; override; function GetDisplayName: string; override;
@ -30,42 +31,20 @@ type
end; end;
const
StaticProviderUID = 'static';
StaticFunctionUID: array[TLEDColor] of string =
(
'off',
'green',
'amber',
'red'
);
implementation implementation
uses uses
LEDFunctionRegistry; LEDColorPool,
LEDFunctionRegistry,
LEDState,
const StaticResources;
CategoryStatic = 'Static';
FunctionDisplayName: array[TLEDColor] of string =
(
'Off',
'Green',
'Amber',
'Red'
);
{ TStaticLEDFunctionProvider } { TStaticLEDFunctionProvider }
constructor TStaticLEDFunctionProvider.Create; procedure TStaticLEDFunctionProvider.RegisterFunctions;
var var
color: TLEDColor; color: TLEDColor;
begin begin
inherited Create;
for color := Low(TLEDColor) to High(TLEDColor) do for color := Low(TLEDColor) to High(TLEDColor) do
RegisterFunction(TStaticLEDFunction.Create(color)); RegisterFunction(TStaticLEDFunction.Create(color));
end; end;
@ -88,13 +67,13 @@ end;
function TStaticLEDFunction.GetCategoryName: string; function TStaticLEDFunction.GetCategoryName: string;
begin begin
Result := CategoryStatic; Result := StaticCategory;
end; end;
function TStaticLEDFunction.GetDisplayName: string; function TStaticLEDFunction.GetDisplayName: string;
begin begin
Result := FunctionDisplayName[FColor]; Result := StaticFunctionDisplayName[FColor];
end; end;
@ -106,7 +85,10 @@ end;
function TStaticLEDFunction.GetCurrentState: ILEDState; function TStaticLEDFunction.GetCurrentState: ILEDState;
begin begin
if not Assigned(FState) then
FState := TLEDState.Create('', '', TLEDColorPool.GetColor(FColor));
Result := FState;
end; end;

View File

@ -0,0 +1,31 @@
unit StaticResources;
interface
uses
LEDColorIntf;
const
StaticProviderUID = 'static';
StaticFunctionUID: array[TLEDColor] of string =
(
'off',
'green',
'amber',
'red'
);
StaticCategory = 'Static';
StaticFunctionDisplayName: array[TLEDColor] of string =
(
'Off',
'Green',
'Amber',
'Red'
);
implementation
end.