Functions added to comboboxes (no longer hardcoded)
Persist profile to registry
This commit is contained in:
parent
e5463b9e27
commit
789511bd56
@ -105,123 +105,115 @@ object MainForm: TMainForm
|
|||||||
Height = 13
|
Height = 13
|
||||||
Caption = 'P8'
|
Caption = 'P8'
|
||||||
end
|
end
|
||||||
object cmbFSXP1: TComboBox
|
object cmbFSXP1: TComboBoxEx
|
||||||
|
Tag = 1
|
||||||
Left = 69
|
Left = 69
|
||||||
Top = 24
|
Top = 24
|
||||||
Width = 348
|
Width = 348
|
||||||
Height = 21
|
Height = 22
|
||||||
Style = csDropDownList
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
Anchors = [akLeft, akTop, akRight]
|
Anchors = [akLeft, akTop, akRight]
|
||||||
DropDownCount = 20
|
|
||||||
Font.Charset = DEFAULT_CHARSET
|
Font.Charset = DEFAULT_CHARSET
|
||||||
Font.Color = clWindowText
|
Font.Color = clWindowText
|
||||||
Font.Height = -11
|
Font.Height = -11
|
||||||
Font.Name = 'Tahoma'
|
Font.Name = 'Tahoma'
|
||||||
Font.Style = []
|
Font.Style = []
|
||||||
ItemIndex = 0
|
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
Text = '<Not assigned>'
|
OnChange = FunctionComboBoxChange
|
||||||
Items.Strings = (
|
DropDownCount = 20
|
||||||
'<Not assigned>')
|
|
||||||
end
|
end
|
||||||
object cmbFSXP2: TComboBox
|
object cmbFSXP2: TComboBoxEx
|
||||||
|
Tag = 2
|
||||||
Left = 69
|
Left = 69
|
||||||
Top = 51
|
Top = 51
|
||||||
Width = 348
|
Width = 348
|
||||||
Height = 21
|
Height = 22
|
||||||
Style = csDropDownList
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
Anchors = [akLeft, akTop, akRight]
|
Anchors = [akLeft, akTop, akRight]
|
||||||
DropDownCount = 20
|
|
||||||
ItemIndex = 0
|
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
Text = 'Parking brake'
|
OnChange = FunctionComboBoxChange
|
||||||
Items.Strings = (
|
DropDownCount = 20
|
||||||
'Parking brake')
|
|
||||||
end
|
end
|
||||||
object cmbFSXP3: TComboBox
|
object cmbFSXP3: TComboBoxEx
|
||||||
|
Tag = 3
|
||||||
Left = 69
|
Left = 69
|
||||||
Top = 78
|
Top = 78
|
||||||
Width = 348
|
Width = 348
|
||||||
Height = 21
|
Height = 22
|
||||||
Style = csDropDownList
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
Anchors = [akLeft, akTop, akRight]
|
Anchors = [akLeft, akTop, akRight]
|
||||||
DropDownCount = 20
|
|
||||||
ItemIndex = 0
|
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
Text = 'Landing lights'
|
OnChange = FunctionComboBoxChange
|
||||||
Items.Strings = (
|
DropDownCount = 20
|
||||||
'Landing lights')
|
|
||||||
end
|
end
|
||||||
object cmbFSXP4: TComboBox
|
object cmbFSXP4: TComboBoxEx
|
||||||
|
Tag = 4
|
||||||
Left = 69
|
Left = 69
|
||||||
Top = 105
|
Top = 105
|
||||||
Width = 348
|
Width = 348
|
||||||
Height = 21
|
Height = 22
|
||||||
Style = csDropDownList
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
Anchors = [akLeft, akTop, akRight]
|
Anchors = [akLeft, akTop, akRight]
|
||||||
DropDownCount = 20
|
|
||||||
ItemIndex = 0
|
|
||||||
TabOrder = 3
|
TabOrder = 3
|
||||||
Text = 'Landing gear'
|
OnChange = FunctionComboBoxChange
|
||||||
Items.Strings = (
|
DropDownCount = 20
|
||||||
'Landing gear')
|
|
||||||
end
|
end
|
||||||
object cmbFSXP5: TComboBox
|
object cmbFSXP5: TComboBoxEx
|
||||||
|
Tag = 5
|
||||||
Left = 69
|
Left = 69
|
||||||
Top = 132
|
Top = 132
|
||||||
Width = 348
|
Width = 348
|
||||||
Height = 21
|
Height = 22
|
||||||
Style = csDropDownList
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
Anchors = [akLeft, akTop, akRight]
|
Anchors = [akLeft, akTop, akRight]
|
||||||
DropDownCount = 20
|
|
||||||
ItemIndex = 0
|
|
||||||
TabOrder = 4
|
TabOrder = 4
|
||||||
Text = '<Not assigned>'
|
OnChange = FunctionComboBoxChange
|
||||||
Items.Strings = (
|
DropDownCount = 20
|
||||||
'<Not assigned>')
|
|
||||||
end
|
end
|
||||||
object cmbFSXP6: TComboBox
|
object cmbFSXP6: TComboBoxEx
|
||||||
|
Tag = 6
|
||||||
Left = 69
|
Left = 69
|
||||||
Top = 159
|
Top = 159
|
||||||
Width = 348
|
Width = 348
|
||||||
Height = 21
|
Height = 22
|
||||||
Style = csDropDownList
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
Anchors = [akLeft, akTop, akRight]
|
Anchors = [akLeft, akTop, akRight]
|
||||||
DropDownCount = 20
|
|
||||||
ItemIndex = 0
|
|
||||||
TabOrder = 5
|
TabOrder = 5
|
||||||
Text = '<Not assigned>'
|
OnChange = FunctionComboBoxChange
|
||||||
Items.Strings = (
|
DropDownCount = 20
|
||||||
'<Not assigned>')
|
|
||||||
end
|
end
|
||||||
object cmbFSXP7: TComboBox
|
object cmbFSXP7: TComboBoxEx
|
||||||
|
Tag = 7
|
||||||
Left = 69
|
Left = 69
|
||||||
Top = 186
|
Top = 186
|
||||||
Width = 348
|
Width = 348
|
||||||
Height = 21
|
Height = 22
|
||||||
Style = csDropDownList
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
Anchors = [akLeft, akTop, akRight]
|
Anchors = [akLeft, akTop, akRight]
|
||||||
DropDownCount = 20
|
|
||||||
ItemIndex = 0
|
|
||||||
TabOrder = 6
|
TabOrder = 6
|
||||||
Text = 'Instrument lights'
|
OnChange = FunctionComboBoxChange
|
||||||
Items.Strings = (
|
DropDownCount = 20
|
||||||
'Instrument lights')
|
|
||||||
end
|
end
|
||||||
object cmbFSXP8: TComboBox
|
object cmbFSXP8: TComboBoxEx
|
||||||
|
Tag = 8
|
||||||
Left = 69
|
Left = 69
|
||||||
Top = 213
|
Top = 213
|
||||||
Width = 348
|
Width = 348
|
||||||
Height = 21
|
Height = 22
|
||||||
Style = csDropDownList
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
Anchors = [akLeft, akTop, akRight]
|
Anchors = [akLeft, akTop, akRight]
|
||||||
DropDownCount = 20
|
|
||||||
ItemIndex = 0
|
|
||||||
TabOrder = 7
|
TabOrder = 7
|
||||||
Text = '<Not assigned>'
|
OnChange = FunctionComboBoxChange
|
||||||
Items.Strings = (
|
DropDownCount = 20
|
||||||
'<Not assigned>')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
object gbFSXConnection: TGroupBox
|
object gbFSXConnection: TGroupBox
|
||||||
|
@ -3,17 +3,20 @@ unit MainFrm;
|
|||||||
interface
|
interface
|
||||||
uses
|
uses
|
||||||
Classes,
|
Classes,
|
||||||
|
Contnrs,
|
||||||
Controls,
|
Controls,
|
||||||
ComCtrls,
|
ComCtrls,
|
||||||
ExtCtrls,
|
ExtCtrls,
|
||||||
Forms,
|
Forms,
|
||||||
Messages,
|
Messages,
|
||||||
StdCtrls,
|
StdCtrls,
|
||||||
|
Windows,
|
||||||
|
|
||||||
OtlComm,
|
OtlComm,
|
||||||
OtlEventMonitor,
|
OtlEventMonitor,
|
||||||
OtlTaskControl,
|
OtlTaskControl,
|
||||||
pngimage,
|
pngimage,
|
||||||
|
X2UtPersistIntf,
|
||||||
|
|
||||||
LEDFunctionMap,
|
LEDFunctionMap,
|
||||||
LEDStateConsumer,
|
LEDStateConsumer,
|
||||||
@ -21,6 +24,9 @@ uses
|
|||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TComboBoxArray = array[0..7] of TComboBoxEx;
|
||||||
|
|
||||||
|
|
||||||
TMainForm = class(TForm)
|
TMainForm = class(TForm)
|
||||||
imgStateNotFound: TImage;
|
imgStateNotFound: TImage;
|
||||||
lblG940Throttle: TLabel;
|
lblG940Throttle: TLabel;
|
||||||
@ -32,20 +38,20 @@ type
|
|||||||
tsFSX: TTabSheet;
|
tsFSX: TTabSheet;
|
||||||
gbFSXButtons: TGroupBox;
|
gbFSXButtons: TGroupBox;
|
||||||
lblFSXP1: TLabel;
|
lblFSXP1: TLabel;
|
||||||
cmbFSXP1: TComboBox;
|
cmbFSXP1: TComboBoxEx;
|
||||||
cmbFSXP2: TComboBox;
|
cmbFSXP2: TComboBoxEx;
|
||||||
lblFSXP2: TLabel;
|
lblFSXP2: TLabel;
|
||||||
cmbFSXP3: TComboBox;
|
cmbFSXP3: TComboBoxEx;
|
||||||
lblFSXP3: TLabel;
|
lblFSXP3: TLabel;
|
||||||
cmbFSXP4: TComboBox;
|
cmbFSXP4: TComboBoxEx;
|
||||||
lblFSXP4: TLabel;
|
lblFSXP4: TLabel;
|
||||||
cmbFSXP5: TComboBox;
|
cmbFSXP5: TComboBoxEx;
|
||||||
lblFSXP5: TLabel;
|
lblFSXP5: TLabel;
|
||||||
cmbFSXP6: TComboBox;
|
cmbFSXP6: TComboBoxEx;
|
||||||
lblFSXP6: TLabel;
|
lblFSXP6: TLabel;
|
||||||
cmbFSXP7: TComboBox;
|
cmbFSXP7: TComboBoxEx;
|
||||||
lblFSXP7: TLabel;
|
lblFSXP7: TLabel;
|
||||||
cmbFSXP8: TComboBox;
|
cmbFSXP8: TComboBoxEx;
|
||||||
lblFSXP8: TLabel;
|
lblFSXP8: TLabel;
|
||||||
gbFSXConnection: TGroupBox;
|
gbFSXConnection: TGroupBox;
|
||||||
btnFSXConnect: TButton;
|
btnFSXConnect: TButton;
|
||||||
@ -57,17 +63,27 @@ type
|
|||||||
procedure btnFSXConnectClick(Sender: TObject);
|
procedure btnFSXConnectClick(Sender: TObject);
|
||||||
procedure btnFSXDisconnectClick(Sender: TObject);
|
procedure btnFSXDisconnectClick(Sender: TObject);
|
||||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||||
|
procedure FunctionComboBoxChange(Sender: TObject);
|
||||||
private
|
private
|
||||||
FEventMonitor: TOmniEventMonitor;
|
FEventMonitor: TOmniEventMonitor;
|
||||||
FStateConsumerTask: IOmniTaskControl;
|
FStateConsumerTask: IOmniTaskControl;
|
||||||
|
FFSXComboBoxes: TComboBoxArray;
|
||||||
protected
|
protected
|
||||||
|
procedure LoadFunctions(AProviderClass: TLEDStateProviderClass; AComboBoxes: TComboBoxArray);
|
||||||
|
procedure SetFunctions(AComboBoxes: TComboBoxArray);
|
||||||
|
|
||||||
|
procedure ReadFunctions(AReader: IX2PersistReader; AComboBoxes: TComboBoxArray);
|
||||||
|
procedure WriteFunctions(AWriter: IX2PersistWriter; AComboBoxes: TComboBoxArray);
|
||||||
|
|
||||||
|
procedure LoadDefaultProfile;
|
||||||
|
procedure SaveDefaultProfile;
|
||||||
|
|
||||||
procedure SetDeviceState(const AMessage: string; AFound: Boolean);
|
procedure SetDeviceState(const AMessage: string; AFound: Boolean);
|
||||||
|
|
||||||
procedure InitializeStateProvider(AProviderClass: TLEDStateProviderClass);
|
procedure InitializeStateProvider(AProviderClass: TLEDStateProviderClass);
|
||||||
procedure FinalizeStateProvider;
|
procedure FinalizeStateProvider;
|
||||||
|
|
||||||
procedure UpdateMapping;
|
procedure UpdateMapping;
|
||||||
procedure UpdateMappingFSX;
|
|
||||||
|
|
||||||
procedure EventMonitorMessage(const task: IOmniTaskControl; const msg: TOmniMessage);
|
procedure EventMonitorMessage(const task: IOmniTaskControl; const msg: TOmniMessage);
|
||||||
procedure EventMonitorTerminated(const task: IOmniTaskControl);
|
procedure EventMonitorTerminated(const task: IOmniTaskControl);
|
||||||
@ -87,10 +103,10 @@ uses
|
|||||||
ComObj,
|
ComObj,
|
||||||
Dialogs,
|
Dialogs,
|
||||||
SysUtils,
|
SysUtils,
|
||||||
Windows,
|
|
||||||
|
|
||||||
OtlCommon,
|
OtlCommon,
|
||||||
OtlTask,
|
OtlTask,
|
||||||
|
X2UtPersistRegistry,
|
||||||
|
|
||||||
FSXLEDStateProvider,
|
FSXLEDStateProvider,
|
||||||
G940LEDStateConsumer;
|
G940LEDStateConsumer;
|
||||||
@ -100,16 +116,31 @@ uses
|
|||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
|
SPECIAL_CATEGORY = -1;
|
||||||
|
|
||||||
TEXT_STATE_SEARCHING = 'Searching...';
|
TEXT_STATE_SEARCHING = 'Searching...';
|
||||||
TEXT_STATE_NOTFOUND = 'Not found';
|
TEXT_STATE_NOTFOUND = 'Not found';
|
||||||
TEXT_STATE_FOUND = 'Connected';
|
TEXT_STATE_FOUND = 'Connected';
|
||||||
|
|
||||||
|
KEY_DEFAULTPROFILE = '\Software\X2Software\G940LEDControl\DefaultProfile\';
|
||||||
|
SECTION_FSX = 'FSX';
|
||||||
|
|
||||||
|
|
||||||
procedure RunStateProvider(const task: IOmniTask);
|
type
|
||||||
begin
|
TComboBoxFunctionConsumer = class(TInterfacedObject, IFunctionConsumer)
|
||||||
|
private
|
||||||
|
FComboBox: TComboBoxEx;
|
||||||
|
protected
|
||||||
|
{ IFunctionConsumer }
|
||||||
|
procedure SetCategory(const ACategory: string);
|
||||||
|
procedure AddFunction(AFunction: Integer; const ADescription: string);
|
||||||
|
|
||||||
|
property ComboBox: TComboBoxEx read FComboBox;
|
||||||
|
public
|
||||||
|
constructor Create(AComboBox: TComboBoxEx);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ TMainForm }
|
{ TMainForm }
|
||||||
@ -123,10 +154,20 @@ begin
|
|||||||
consumer := TG940LEDStateConsumer.Create;
|
consumer := TG940LEDStateConsumer.Create;
|
||||||
FStateConsumerTask := FEventMonitor.Monitor(CreateTask(consumer)).MsgWait;
|
FStateConsumerTask := FEventMonitor.Monitor(CreateTask(consumer)).MsgWait;
|
||||||
|
|
||||||
// ToDo handle OnTerminate, check exit code for initialization errors
|
|
||||||
EventMonitor.OnTaskMessage := EventMonitorMessage;
|
EventMonitor.OnTaskMessage := EventMonitorMessage;
|
||||||
EventMonitor.OnTaskTerminated := EventMonitorTerminated;
|
EventMonitor.OnTaskTerminated := EventMonitorTerminated;
|
||||||
StateConsumerTask.Run;
|
StateConsumerTask.Run;
|
||||||
|
|
||||||
|
FFSXComboBoxes[0] := cmbFSXP1;
|
||||||
|
FFSXComboBoxes[1] := cmbFSXP2;
|
||||||
|
FFSXComboBoxes[2] := cmbFSXP3;
|
||||||
|
FFSXComboBoxes[3] := cmbFSXP4;
|
||||||
|
FFSXComboBoxes[4] := cmbFSXP5;
|
||||||
|
FFSXComboBoxes[5] := cmbFSXP6;
|
||||||
|
FFSXComboBoxes[6] := cmbFSXP7;
|
||||||
|
FFSXComboBoxes[7] := cmbFSXP8;
|
||||||
|
LoadFunctions(TFSXLEDStateProvider, FFSXComboBoxes);
|
||||||
|
LoadDefaultProfile;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -134,6 +175,8 @@ procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|||||||
begin
|
begin
|
||||||
if Assigned(StateConsumerTask) then
|
if Assigned(StateConsumerTask) then
|
||||||
begin
|
begin
|
||||||
|
SaveDefaultProfile;
|
||||||
|
|
||||||
LEDStateConsumer.Finalize(StateConsumerTask);
|
LEDStateConsumer.Finalize(StateConsumerTask);
|
||||||
CanClose := False;
|
CanClose := False;
|
||||||
end;
|
end;
|
||||||
@ -199,8 +242,126 @@ end;
|
|||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMainForm.LoadFunctions(AProviderClass: TLEDStateProviderClass; AComboBoxes: TComboBoxArray);
|
||||||
|
var
|
||||||
|
comboBox: TComboBoxEx;
|
||||||
|
|
||||||
|
begin
|
||||||
|
for comboBox in AComboBoxes do
|
||||||
|
begin
|
||||||
|
comboBox.Items.BeginUpdate;
|
||||||
|
try
|
||||||
|
comboBox.Items.Clear;
|
||||||
|
AProviderClass.EnumFunctions(TComboBoxFunctionConsumer.Create(comboBox));
|
||||||
|
|
||||||
|
comboBox.ItemIndex := 0;
|
||||||
|
if Assigned(comboBox.OnChange) then
|
||||||
|
comboBox.OnChange(comboBox);
|
||||||
|
finally
|
||||||
|
comboBox.Items.EndUpdate;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMainForm.SetFunctions(AComboBoxes: TComboBoxArray);
|
||||||
|
var
|
||||||
|
comboBox: TComboBoxEx;
|
||||||
|
|
||||||
|
begin
|
||||||
|
for comboBox in AComboBoxes do
|
||||||
|
begin
|
||||||
|
if comboBox.ItemIndex > -1 then
|
||||||
|
LEDStateConsumer.SetFunction(StateConsumerTask, comboBox.Tag, Integer(comboBox.ItemsEx[comboBox.ItemIndex].Data));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMainForm.ReadFunctions(AReader: IX2PersistReader; AComboBoxes: TComboBoxArray);
|
||||||
|
var
|
||||||
|
comboBox: TComboBoxEx;
|
||||||
|
value: Integer;
|
||||||
|
itemIndex: Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if AReader.BeginSection(SECTION_FSX) then
|
||||||
|
try
|
||||||
|
for comboBox in AComboBoxes do
|
||||||
|
begin
|
||||||
|
if AReader.ReadInteger('Function' + IntToStr(comboBox.Tag), value) then
|
||||||
|
begin
|
||||||
|
for itemIndex := 0 to Pred(comboBox.ItemsEx.Count) do
|
||||||
|
if Integer(comboBox.ItemsEx[itemIndex].Data) = value then
|
||||||
|
begin
|
||||||
|
comboBox.ItemIndex := itemIndex;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
AReader.EndSection;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMainForm.WriteFunctions(AWriter: IX2PersistWriter; AComboBoxes: TComboBoxArray);
|
||||||
|
var
|
||||||
|
comboBox: TComboBoxEx;
|
||||||
|
value: Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if AWriter.BeginSection(SECTION_FSX) then
|
||||||
|
try
|
||||||
|
for comboBox in AComboBoxes do
|
||||||
|
begin
|
||||||
|
value := -1;
|
||||||
|
if comboBox.ItemIndex > -1 then
|
||||||
|
value := Integer(comboBox.ItemsEx[comboBox.ItemIndex].Data);
|
||||||
|
|
||||||
|
AWriter.WriteInteger('Function' + IntToStr(comboBox.Tag), value);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
AWriter.EndSection;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMainForm.LoadDefaultProfile;
|
||||||
|
var
|
||||||
|
registryReader: TX2UtPersistRegistry;
|
||||||
|
|
||||||
|
begin
|
||||||
|
registryReader := TX2UtPersistRegistry.Create;
|
||||||
|
try
|
||||||
|
registryReader.RootKey := HKEY_CURRENT_USER;
|
||||||
|
registryReader.Key := KEY_DEFAULTPROFILE;
|
||||||
|
|
||||||
|
ReadFunctions(registryReader.CreateReader, FFSXComboBoxes);
|
||||||
|
finally
|
||||||
|
FreeAndNil(registryReader);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMainForm.SaveDefaultProfile;
|
||||||
|
var
|
||||||
|
registryWriter: TX2UtPersistRegistry;
|
||||||
|
|
||||||
|
begin
|
||||||
|
registryWriter := TX2UtPersistRegistry.Create;
|
||||||
|
try
|
||||||
|
registryWriter.RootKey := HKEY_CURRENT_USER;
|
||||||
|
registryWriter.Key := KEY_DEFAULTPROFILE;
|
||||||
|
|
||||||
|
WriteFunctions(registryWriter.CreateWriter, FFSXComboBoxes);
|
||||||
|
finally
|
||||||
|
FreeAndNil(registryWriter);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TMainForm.InitializeStateProvider(AProviderClass: TLEDStateProviderClass);
|
procedure TMainForm.InitializeStateProvider(AProviderClass: TLEDStateProviderClass);
|
||||||
begin
|
begin
|
||||||
UpdateMapping;
|
UpdateMapping;
|
||||||
LEDStateConsumer.InitializeStateProvider(StateConsumerTask, AProviderClass);
|
LEDStateConsumer.InitializeStateProvider(StateConsumerTask, AProviderClass);
|
||||||
end;
|
end;
|
||||||
@ -218,20 +379,7 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
|
|
||||||
LEDStateConsumer.ClearFunctions(StateConsumerTask);
|
LEDStateConsumer.ClearFunctions(StateConsumerTask);
|
||||||
UpdateMappingFSX;
|
SetFunctions(FFSXComboBoxes);
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TMainForm.UpdateMappingFSX;
|
|
||||||
begin
|
|
||||||
LEDStateConsumer.SetFunction(StateConsumerTask, 1, FUNCTION_FSX_PARKINGBRAKE);
|
|
||||||
LEDStateConsumer.SetFunction(StateConsumerTask, 2, FUNCTION_FSX_LANDINGLIGHTS);
|
|
||||||
LEDStateConsumer.SetFunction(StateConsumerTask, 3, FUNCTION_FSX_GEAR);
|
|
||||||
|
|
||||||
LEDStateConsumer.SetFunction(StateConsumerTask, 4, FUNCTION_FSX_ENGINE);
|
|
||||||
LEDStateConsumer.SetFunction(StateConsumerTask, 6, FUNCTION_FSX_INSTRUMENTLIGHTS);
|
|
||||||
|
|
||||||
// LEDStateConsumer.SetFunction(StateConsumerTask, 7, FUNCTION_OFF);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -306,6 +454,7 @@ end;
|
|||||||
|
|
||||||
procedure TMainForm.btnFSXConnectClick(Sender: TObject);
|
procedure TMainForm.btnFSXConnectClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
|
SaveDefaultProfile;
|
||||||
InitializeStateProvider(TFSXLEDStateProvider);
|
InitializeStateProvider(TFSXLEDStateProvider);
|
||||||
|
|
||||||
btnFSXDisconnect.Enabled := True;
|
btnFSXDisconnect.Enabled := True;
|
||||||
@ -327,4 +476,47 @@ begin
|
|||||||
StateConsumerTask.Comm.Send(MSG_FINDTHROTTLEDEVICE);
|
StateConsumerTask.Comm.Send(MSG_FINDTHROTTLEDEVICE);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMainForm.FunctionComboBoxChange(Sender: TObject);
|
||||||
|
var
|
||||||
|
comboBox: TComboBoxEx;
|
||||||
|
|
||||||
|
begin
|
||||||
|
comboBox := TComboBoxEx(Sender);
|
||||||
|
if comboBox.ItemIndex > -1 then
|
||||||
|
begin
|
||||||
|
if not Assigned(comboBox.ItemsEx[comboBox.ItemIndex].Data) then
|
||||||
|
comboBox.ItemIndex := Succ(comboBox.ItemIndex);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TComboBoxFunctionConsumer }
|
||||||
|
constructor TComboBoxFunctionConsumer.Create(AComboBox: TComboBoxEx);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
|
||||||
|
FComboBox := AComboBox;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TComboBoxFunctionConsumer.SetCategory(const ACategory: string);
|
||||||
|
begin
|
||||||
|
with ComboBox.ItemsEx.Add do
|
||||||
|
begin
|
||||||
|
Caption := ACategory;
|
||||||
|
Data := nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TComboBoxFunctionConsumer.AddFunction(AFunction: Integer; const ADescription: string);
|
||||||
|
begin
|
||||||
|
with ComboBox.ItemsEx.Add do
|
||||||
|
begin
|
||||||
|
Caption := ADescription;
|
||||||
|
Indent := 1;
|
||||||
|
Data := Pointer(AFunction);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -39,6 +39,8 @@ type
|
|||||||
|
|
||||||
property SimConnectHandle: THandle read FSimConnectHandle;
|
property SimConnectHandle: THandle read FSimConnectHandle;
|
||||||
public
|
public
|
||||||
|
class procedure EnumFunctions(AConsumer: IFunctionConsumer); override;
|
||||||
|
|
||||||
constructor Create(AConsumer: ILEDStateConsumer); override;
|
constructor Create(AConsumer: ILEDStateConsumer); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
@ -85,6 +87,14 @@ const
|
|||||||
FSX_LIGHTON_CABIN = $0200;
|
FSX_LIGHTON_CABIN = $0200;
|
||||||
|
|
||||||
|
|
||||||
|
CATEGORY_DYNAMIC = 'Dynamic';
|
||||||
|
FUNCTION_DESC_FSX_ENGINE = 'Engine';
|
||||||
|
FUNCTION_DESC_FSX_INSTRUMENTLIGHTS = 'Instrument lights';
|
||||||
|
FUNCTION_DESC_FSX_GEAR = 'Landing gear';
|
||||||
|
FUNCTION_DESC_FSX_LANDINGLIGHTS = 'Landing lights';
|
||||||
|
FUNCTION_DESC_FSX_PARKINGBRAKE = 'Parking brake';
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
TGearData = packed record
|
TGearData = packed record
|
||||||
IsGearRetractable: Integer;
|
IsGearRetractable: Integer;
|
||||||
@ -102,6 +112,19 @@ type
|
|||||||
|
|
||||||
|
|
||||||
{ TFSXLEDStateProvider }
|
{ TFSXLEDStateProvider }
|
||||||
|
class procedure TFSXLEDStateProvider.EnumFunctions(AConsumer: IFunctionConsumer);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
|
||||||
|
AConsumer.SetCategory(CATEGORY_DYNAMIC);
|
||||||
|
AConsumer.AddFunction(FUNCTION_FSX_ENGINE, FUNCTION_DESC_FSX_ENGINE);
|
||||||
|
AConsumer.AddFunction(FUNCTION_FSX_INSTRUMENTLIGHTS, FUNCTION_DESC_FSX_INSTRUMENTLIGHTS);
|
||||||
|
AConsumer.AddFunction(FUNCTION_FSX_GEAR, FUNCTION_DESC_FSX_GEAR);
|
||||||
|
AConsumer.AddFunction(FUNCTION_FSX_LANDINGLIGHTS, FUNCTION_DESC_FSX_LANDINGLIGHTS);
|
||||||
|
AConsumer.AddFunction(FUNCTION_FSX_PARKINGBRAKE, FUNCTION_DESC_FSX_PARKINGBRAKE);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
constructor TFSXLEDStateProvider.Create(AConsumer: ILEDStateConsumer);
|
constructor TFSXLEDStateProvider.Create(AConsumer: ILEDStateConsumer);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
@ -20,6 +20,13 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
IFunctionConsumer = interface
|
||||||
|
['{97B47A29-BA7F-4C48-934D-EB66D2741647}']
|
||||||
|
procedure SetCategory(const ACategory: string);
|
||||||
|
procedure AddFunction(AFunction: Integer; const ADescription: string);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
TLEDStateProvider = class(TObject)
|
TLEDStateProvider = class(TObject)
|
||||||
private
|
private
|
||||||
FConsumer: ILEDStateConsumer;
|
FConsumer: ILEDStateConsumer;
|
||||||
@ -31,6 +38,8 @@ type
|
|||||||
|
|
||||||
property Consumer: ILEDStateConsumer read FConsumer;
|
property Consumer: ILEDStateConsumer read FConsumer;
|
||||||
public
|
public
|
||||||
|
class procedure EnumFunctions(AConsumer: IFunctionConsumer); virtual;
|
||||||
|
|
||||||
constructor Create(AConsumer: ILEDStateConsumer); virtual;
|
constructor Create(AConsumer: ILEDStateConsumer); virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
@ -55,9 +64,26 @@ const
|
|||||||
EXIT_PROVIDER_OFFSET = 200;
|
EXIT_PROVIDER_OFFSET = 200;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
const
|
||||||
|
CATEGORY_STATIC = 'Static';
|
||||||
|
|
||||||
|
FUNCTION_DESC_OFF = 'Light off';
|
||||||
|
FUNCTION_DESC_GREEN = 'Green';
|
||||||
|
FUNCTION_DESC_AMBER = 'Amber';
|
||||||
|
FUNCTION_DESC_RED = 'Red';
|
||||||
|
|
||||||
|
|
||||||
{ TCustomLEDStateProvider }
|
{ TCustomLEDStateProvider }
|
||||||
|
class procedure TLEDStateProvider.EnumFunctions(AConsumer: IFunctionConsumer);
|
||||||
|
begin
|
||||||
|
AConsumer.SetCategory(CATEGORY_STATIC);
|
||||||
|
AConsumer.AddFunction(FUNCTION_OFF, FUNCTION_DESC_OFF);
|
||||||
|
AConsumer.AddFunction(FUNCTION_GREEN, FUNCTION_DESC_GREEN);
|
||||||
|
AConsumer.AddFunction(FUNCTION_AMBER, FUNCTION_DESC_AMBER);
|
||||||
|
AConsumer.AddFunction(FUNCTION_RED, FUNCTION_DESC_RED);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
constructor TLEDStateProvider.Create(AConsumer: ILEDStateConsumer);
|
constructor TLEDStateProvider.Create(AConsumer: ILEDStateConsumer);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
Loading…
Reference in New Issue
Block a user