diff --git a/G940LEDControl/Forms/MainFrm.dfm b/G940LEDControl/Forms/MainFrm.dfm index 65e216e..85a5514 100644 --- a/G940LEDControl/Forms/MainFrm.dfm +++ b/G940LEDControl/Forms/MainFrm.dfm @@ -32,12 +32,8 @@ object MainForm: TMainForm ActivePage = tsFSX Align = alClient TabOrder = 1 - ExplicitWidth = 390 - ExplicitHeight = 510 object tsFSX: TTabSheet Caption = 'Configuration' - ExplicitWidth = 382 - ExplicitHeight = 482 DesignSize = ( 441 446) @@ -346,7 +342,6 @@ object MainForm: TMainForm Anchors = [akTop, akRight] Caption = 'Save as...' TabOrder = 9 - ExplicitLeft = 340 end object btnDeleteProfile: TButton Left = 364 @@ -356,12 +351,13 @@ object MainForm: TMainForm Anchors = [akTop, akRight] Caption = 'Delete' TabOrder = 10 - ExplicitLeft = 421 end end object tsAbout: TTabSheet Caption = 'About' ImageIndex = 1 + ExplicitLeft = 0 + ExplicitTop = 0 ExplicitWidth = 382 ExplicitHeight = 482 object lblVersionCaption: TLabel @@ -479,7 +475,6 @@ object MainForm: TMainForm Align = alTop BevelOuter = bvNone TabOrder = 0 - ExplicitWidth = 390 DesignSize = ( 449 64) @@ -861,7 +856,6 @@ object MainForm: TMainForm TabOrder = 0 Visible = False OnClick = btnRetryClick - ExplicitLeft = 315 end end end diff --git a/G940LEDControl/Forms/MainFrm.pas b/G940LEDControl/Forms/MainFrm.pas index f47f618..51bd1c9 100644 --- a/G940LEDControl/Forms/MainFrm.pas +++ b/G940LEDControl/Forms/MainFrm.pas @@ -175,7 +175,7 @@ uses LEDColorIntf, LEDFunctionIntf, LEDFunctionRegistry, - StaticLEDFunction; + StaticResources; {$R *.dfm} @@ -192,11 +192,6 @@ const TEXT_STATE_NOTFOUND = 'Not found'; TEXT_STATE_FOUND = 'Connected'; - KEY_SETTINGS = '\Software\X2Software\G940LEDControl\'; - SECTION_DEFAULTPROFILE = 'DefaultProfile'; - SECTION_FSX = 'FSX'; - SECTION_SETTINGS = 'Settings'; - type TComboBoxFunctionConsumer = class(TInterfacedObject, IFunctionConsumer) @@ -306,7 +301,7 @@ begin if not FileExists(FProfilesFilename) then begin { Check if version 0.x settings are in the registry } - defaultProfile := ConfigConversion.Convert0To1; + defaultProfile := ConfigConversion.ConvertProfile0To1; if not Assigned(defaultProfile) then defaultProfile := CreateDefaultProfile; @@ -519,61 +514,6 @@ 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); //begin // UpdateMapping; diff --git a/G940LEDControl/G940LEDControl.dpr b/G940LEDControl/G940LEDControl.dpr index 8ccefcb..da5f91d 100644 --- a/G940LEDControl/G940LEDControl.dpr +++ b/G940LEDControl/G940LEDControl.dpr @@ -25,7 +25,11 @@ uses LEDState in 'Units\LEDState.pas', Profile in 'Units\Profile.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} diff --git a/G940LEDControl/G940LEDControl.dproj b/G940LEDControl/G940LEDControl.dproj index 6257cfb..5638f7d 100644 --- a/G940LEDControl/G940LEDControl.dproj +++ b/G940LEDControl/G940LEDControl.dproj @@ -191,6 +191,10 @@
ButtonFunctionForm
dfm + + + + Cfg_2 Base diff --git a/G940LEDControl/Units/ConfigConversion.pas b/G940LEDControl/Units/ConfigConversion.pas index f8adcd0..2b4b7e5 100644 --- a/G940LEDControl/Units/ConfigConversion.pas +++ b/G940LEDControl/Units/ConfigConversion.pas @@ -5,59 +5,167 @@ uses Profile; { Version 0.x: registry -> 1.x: XML } - function Convert0To1: TProfile; + function ConvertProfile0To1: TProfile; 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 Result := nil; + registryReader := TX2UtPersistRegistry.Create; + try + registryReader.RootKey := HKEY_CURRENT_USER; + registryReader.Key := KEY_SETTINGS; + reader := registryReader.CreateReader; -// FUNCTION_NONE = 0; -// FUNCTION_OFF = 1; -// FUNCTION_RED = 2; -// FUNCTION_AMBER = 3; -// FUNCTION_GREEN = 4; + if reader.BeginSection(SECTION_DEFAULTPROFILE) then + try + if reader.BeginSection(SECTION_FSX) then + try + for buttonIndex := 0 to 7 do + begin + if reader.ReadInteger('Function' + IntToStr(buttonIndex), value) then + begin + if not Assigned(Result) then + Result := TProfile.Create; -{ -FUNCTION_PROVIDER_OFFSET = 4 + ConvertProfileFunction0To1(value, Result.Buttons[buttonIndex]); + end; + end; + finally + reader.EndSection; + end; + finally + reader.EndSection; + end; - FUNCTION_FSX_GEAR = FUNCTION_PROVIDER_OFFSET + 1; - FUNCTION_FSX_LANDINGLIGHTS = FUNCTION_PROVIDER_OFFSET + 2; - FUNCTION_FSX_INSTRUMENTLIGHTS = FUNCTION_PROVIDER_OFFSET + 3; - FUNCTION_FSX_PARKINGBRAKE = FUNCTION_PROVIDER_OFFSET + 4; - FUNCTION_FSX_ENGINE = FUNCTION_PROVIDER_OFFSET + 5; - - 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; - } + // TODO auto update settings + //ReadAutoUpdate(reader); + finally + FreeAndNil(registryReader); + end; end; end. diff --git a/G940LEDControl/Units/FSXLEDFunction.pas b/G940LEDControl/Units/FSXLEDFunction.pas new file mode 100644 index 0000000..a9f0684 --- /dev/null +++ b/G940LEDControl/Units/FSXLEDFunction.pas @@ -0,0 +1,231 @@ +unit FSXLEDFunction; + +interface +uses + Generics.Collections, + + LEDFunction, + LEDStateIntf, + ObserverIntf; + + +type + TCustomFSXFunction = class; + TCustomFSXFunctionList = TObjectList; + + + 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. diff --git a/G940LEDControl/Units/FSXResources.pas b/G940LEDControl/Units/FSXResources.pas new file mode 100644 index 0000000..c256474 --- /dev/null +++ b/G940LEDControl/Units/FSXResources.pas @@ -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. diff --git a/G940LEDControl/Units/FSXSimConnectClient.pas b/G940LEDControl/Units/FSXSimConnectClient.pas new file mode 100644 index 0000000..563492b --- /dev/null +++ b/G940LEDControl/Units/FSXSimConnectClient.pas @@ -0,0 +1,14 @@ +unit FSXSimConnectClient; + +interface +uses + OtlTaskControl; + +type + TFSXSimConnectClient = class(TOmniWorker) + + end; + +implementation + +end. diff --git a/G940LEDControl/Units/LEDColorPool.pas b/G940LEDControl/Units/LEDColorPool.pas index 720c3be..8b91516 100644 --- a/G940LEDControl/Units/LEDColorPool.pas +++ b/G940LEDControl/Units/LEDColorPool.pas @@ -26,7 +26,8 @@ type function DoGetColor(AEntry: TLEDColorPoolEntry): ILEDColor; public - class function GetColor(AEntry: TLEDColorPoolEntry): ILEDColor; + class function GetColor(AEntry: TLEDColorPoolEntry): ILEDColor; overload; + class function GetColor(AColor: TLEDColor): ILEDColor; overload; end; @@ -49,6 +50,19 @@ begin 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; begin if not Assigned(LEDColorPoolInstance) then diff --git a/G940LEDControl/Units/LEDFunction.pas b/G940LEDControl/Units/LEDFunction.pas index 9dab8b5..d810e22 100644 --- a/G940LEDControl/Units/LEDFunction.pas +++ b/G940LEDControl/Units/LEDFunction.pas @@ -14,7 +14,8 @@ type private FFunctions: TInterfaceList; protected - procedure RegisterFunction(AFunction: ILEDFunction); + procedure RegisterFunctions; virtual; abstract; + function RegisterFunction(AFunction: ILEDFunction): ILEDFunction; virtual; protected { ILEDFunctionProvider } function GetUID: string; virtual; abstract; @@ -30,24 +31,20 @@ type TCustomLEDFunction = class(TInterfacedObject, IObservable, ILEDFunction) private FObservers: TInterfaceList; - FStates: TInterfaceList; protected -// procedure SetCurrentState(AState: ILEDState); virtual; - procedure NotifyObservers; virtual; property Observers: TInterfaceList read FObservers; protected { IObservable } - procedure Attach(AObserver: IObserver); - procedure Detach(AObserver: IObserver); + procedure Attach(AObserver: IObserver); virtual; + procedure Detach(AObserver: IObserver); virtual; { ILEDFunction } function GetCategoryName: string; virtual; abstract; function GetDisplayName: string; virtual; abstract; function GetUID: string; virtual; abstract; - function GetEnumerator: ILEDStateEnumerator; virtual; function GetCurrentState: ILEDState; virtual; abstract; public constructor Create; @@ -55,6 +52,22 @@ type 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) private FList: TInterfaceList; @@ -93,13 +106,11 @@ begin inherited Create; FObservers := TInterfaceList.Create; - FStates := TInterfaceList.Create; end; destructor TCustomLEDFunction.Destroy; begin - FreeAndNil(FStates); FreeAndNil(FObservers); inherited Destroy; @@ -118,13 +129,38 @@ begin 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 Result := TLEDStateEnumerator.Create(FStates); end; -//procedure TCustomLEDFunction.SetCurrentState(AState: ILEDState); +//procedure TCustomMultiStateLEDFunction.SetCurrentState(AState: ILEDState); //begin // FCurrentState := AState; // NotifyObservers; @@ -147,6 +183,7 @@ begin inherited Create; FFunctions := TInterfaceList.Create; + RegisterFunctions; end; @@ -174,9 +211,10 @@ begin end; -procedure TCustomLEDFunctionProvider.RegisterFunction(AFunction: ILEDFunction); +function TCustomLEDFunctionProvider.RegisterFunction(AFunction: ILEDFunction): ILEDFunction; begin - FFunctions.Add(AFunction as ILEDFunction); + Result := AFunction as ILEDFunction; + FFunctions.Add(Result); end; diff --git a/G940LEDControl/Units/StaticLEDFunction.pas b/G940LEDControl/Units/StaticLEDFunction.pas index bf4eeeb..02864ec 100644 --- a/G940LEDControl/Units/StaticLEDFunction.pas +++ b/G940LEDControl/Units/StaticLEDFunction.pas @@ -10,15 +10,16 @@ uses type TStaticLEDFunctionProvider = class(TCustomLEDFunctionProvider) protected + procedure RegisterFunctions; override; + function GetUID: string; override; - public - constructor Create; end; TStaticLEDFunction = class(TCustomLEDFunction) private FColor: TLEDColor; + FState: ILEDState; protected function GetCategoryName: string; override; function GetDisplayName: string; override; @@ -30,42 +31,20 @@ type end; -const - StaticProviderUID = 'static'; - StaticFunctionUID: array[TLEDColor] of string = - ( - 'off', - 'green', - 'amber', - 'red' - ); - - implementation uses - LEDFunctionRegistry; - - -const - CategoryStatic = 'Static'; - FunctionDisplayName: array[TLEDColor] of string = - ( - 'Off', - 'Green', - 'Amber', - 'Red' - ); - + LEDColorPool, + LEDFunctionRegistry, + LEDState, + StaticResources; { TStaticLEDFunctionProvider } -constructor TStaticLEDFunctionProvider.Create; +procedure TStaticLEDFunctionProvider.RegisterFunctions; var color: TLEDColor; begin - inherited Create; - for color := Low(TLEDColor) to High(TLEDColor) do RegisterFunction(TStaticLEDFunction.Create(color)); end; @@ -88,13 +67,13 @@ end; function TStaticLEDFunction.GetCategoryName: string; begin - Result := CategoryStatic; + Result := StaticCategory; end; function TStaticLEDFunction.GetDisplayName: string; begin - Result := FunctionDisplayName[FColor]; + Result := StaticFunctionDisplayName[FColor]; end; @@ -106,7 +85,10 @@ end; function TStaticLEDFunction.GetCurrentState: ILEDState; begin + if not Assigned(FState) then + FState := TLEDState.Create('', '', TLEDColorPool.GetColor(FColor)); + Result := FState; end; diff --git a/G940LEDControl/Units/StaticResources.pas b/G940LEDControl/Units/StaticResources.pas new file mode 100644 index 0000000..b3d2588 --- /dev/null +++ b/G940LEDControl/Units/StaticResources.pas @@ -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.