Skip to content

Commit

Permalink
Allow reverse indication of booster inputs.
Browse files Browse the repository at this point in the history
Upgrate booster's RCS storage format. #192
Close #182.
  • Loading branch information
horacekj committed Jun 12, 2022
1 parent bfd6990 commit aa1e894
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 61 deletions.
71 changes: 47 additions & 24 deletions src/boosters/Booster.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ interface
TBoosterSignal = (undef = -1, error = 0, ok = 1);
TBoosterChangeEvent = procedure(Sender: TObject; state: TBoosterSignal) of object;

TBoosterRCSSignal = record
// disabled input = (addr.board = 0)
addr: TRCSAddr;
reversed: Boolean;
end;

TBoosterSettings = record
id: string;
name: string;

RCS: record
overload: TRCSAddr;
power: TRCSAddr;
DCC: TRCSAddr; // DCC input; DCC nemusi byt detekovano, to se pozna tak, ze .board = 0
rcs: record
overload: TBoosterRCSSignal;
power: TBoosterRCSSignal;
DCC: TBoosterRCSSignal;
end;
end;

Expand Down Expand Up @@ -145,26 +151,43 @@ procedure TBooster.LoadDataFromFile(var ini: TMemIniFile; const section: string)
Self.m_settings.id := section;
Self.m_settings.name := ini.ReadString(section, 'name', 'booster');

Self.m_settings.RCS.overload := RCSFromIni(ini, section, 'short', 'zkr_module', 'zkr_port');
Self.m_settings.RCS.power := RCSFromIni(ini, section, 'power', 'nap_module', 'nap_port');
Self.m_settings.RCS.DCC := RCSFromIni(ini, section, 'dcc', 'dcc_module', 'dcc_port');
Self.m_settings.rcs.overload.addr := RCSFromIni(ini, section, 'short', 'zkr_module', 'zkr_port');
Self.m_settings.rcs.overload.reversed := ini.ReadBool(section, 'shortReversed', false);
Self.m_settings.rcs.power.addr := RCSFromIni(ini, section, 'power', 'nap_module', 'nap_port');
Self.m_settings.rcs.power.reversed := ini.ReadBool(section, 'powerReversed', false);
Self.m_settings.rcs.DCC.addr := RCSFromIni(ini, section, 'dcc', 'dcc_module', 'dcc_port');
Self.m_settings.rcs.DCC.reversed := ini.ReadBool(section, 'dccReversed', false);

if (Self.isPowerDetection) then
RCSi.SetNeeded(Self.m_settings.RCS.power.board);
RCSi.SetNeeded(Self.m_settings.rcs.power.addr.board);
if (Self.isOverloadDetection) then
RCSi.SetNeeded(Self.m_settings.RCS.overload.board);
RCSi.SetNeeded(Self.m_settings.rcs.overload.addr.board);
if (Self.isDCCdetection) then
RCSi.SetNeeded(Self.m_settings.rcs.DCC.addr.board);
end;

procedure TBooster.SaveDataToFile(var ini: TMemIniFile; const section: string);
begin
ini.WriteString(section, 'name', Self.m_settings.name);

if (Self.isOverloadDetection) then
ini.WriteString(section, 'short', Self.m_settings.RCS.overload.ToString());
begin
ini.WriteString(section, 'short', Self.m_settings.rcs.overload.addr.ToString());
if (Self.m_settings.rcs.overload.reversed) then
ini.WriteBool(section, 'shortReversed', true);
end;
if (Self.isPowerDetection) then
ini.WriteString(section, 'power', Self.m_settings.RCS.power.ToString());
begin
ini.WriteString(section, 'power', Self.m_settings.rcs.power.addr.ToString());
if (Self.m_settings.rcs.power.reversed) then
ini.WriteBool(section, 'powerReversed', true);
end;
if (Self.isDCCdetection) then
ini.WriteString(section, 'dcc', Self.m_settings.RCS.DCC.ToString());
begin
ini.WriteString(section, 'dcc', Self.m_settings.rcs.DCC.addr.ToString());
if (Self.m_settings.rcs.DCC.reversed) then
ini.WriteBool(section, 'dccReversed', true);
end;
end;

/// /////////////////////////////////////////////////////////////////////////////
Expand All @@ -183,14 +206,14 @@ function TBooster.GetOverload(): TBoosterSignal;
Exit(TBoosterSignal.ok);

try
val := RCSi.GetInput(Self.m_settings.RCS.overload);
val := RCSi.GetInput(Self.m_settings.rcs.overload.addr);
except
Exit(TBoosterSignal.undef);
end;

if ((val = failure) or (val = notYetScanned) or (val = unavailableModule) or (val = unavailablePort)) then
Result := TBoosterSignal.undef
else if (val = isOn) then
else if ((val = isOn) xor (Self.m_settings.rcs.overload.reversed)) then
Result := TBoosterSignal.error
else
Result := TBoosterSignal.ok;
Expand All @@ -206,14 +229,14 @@ function TBooster.GetPower(): TBoosterSignal;
Exit(TBoosterSignal.ok);

try
val := RCSi.GetInput(Self.m_settings.RCS.power);
val := RCSi.GetInput(Self.m_settings.rcs.power.addr);
except
Exit(TBoosterSignal.undef);
end;

if ((val = failure) or (val = notYetScanned) or (val = unavailableModule) or (val = unavailablePort)) then
Result := TBoosterSignal.undef
else if (val = isOn) then
else if ((val = isOn) xor (Self.m_settings.rcs.power.reversed)) then
Result := TBoosterSignal.error
else
Result := TBoosterSignal.ok;
Expand Down Expand Up @@ -242,14 +265,14 @@ function TBooster.GetDCC(): TBoosterSignal;
end;

try
val := RCSi.GetInput(Self.m_settings.RCS.DCC);
val := RCSi.GetInput(Self.m_settings.rcs.DCC.addr);
except
Exit(TBoosterSignal.undef);
end;

if ((val = failure) or (val = notYetScanned) or (val = unavailableModule) or (val = unavailablePort)) then
Result := TBoosterSignal.undef
else if (val = isOn) then
else if ((val = isOn) xor (Self.m_settings.rcs.DCC.reversed)) then
Result := TBoosterSignal.error
else
Result := TBoosterSignal.ok;
Expand All @@ -259,26 +282,26 @@ function TBooster.GetDCC(): TBoosterSignal;

function TBooster.GetRCSPresent(): Boolean;
begin
Result := (((not Self.isOverloadDetection) or RCSi.IsModule(Self.m_settings.RCS.overload.board)) and
((not Self.isPowerDetection) or RCSi.IsModule(Self.m_settings.RCS.power.board)) and
((not Self.isDCCdetection) or RCSi.IsModule(Self.m_settings.RCS.DCC.board)));
Result := (((not Self.isOverloadDetection) or RCSi.IsModule(Self.m_settings.rcs.overload.addr.board)) and
((not Self.isPowerDetection) or RCSi.IsModule(Self.m_settings.rcs.power.addr.board)) and
((not Self.isDCCdetection) or RCSi.IsModule(Self.m_settings.rcs.DCC.addr.board)));
end;

/// /////////////////////////////////////////////////////////////////////////////

function TBooster.GetDCCDetection(): Boolean;
begin
Result := (Self.m_settings.RCS.DCC.board > 0);
Result := (Self.m_settings.rcs.DCC.addr.board > 0);
end;

function TBooster.GetOverloadDetection(): Boolean;
begin
Result := (Self.m_settings.RCS.overload.board > 0);
Result := (Self.m_settings.rcs.overload.addr.board > 0);
end;

function TBooster.GetPowerDetection(): Boolean;
begin
Result := (Self.m_settings.RCS.power.board > 0);
Result := (Self.m_settings.rcs.power.addr.board > 0);
end;

/// /////////////////////////////////////////////////////////////////////////////
Expand Down
40 changes: 32 additions & 8 deletions src/forms/fZesilovacEdit.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object F_Booster_Edit: TF_Booster_Edit
BorderIcons = [biSystemMenu]
BorderStyle = bsToolWindow
Caption = 'Zesilovac [zesilovac]'
ClientHeight = 401
ClientHeight = 462
ClientWidth = 281
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Expand Down Expand Up @@ -54,7 +54,7 @@ object F_Booster_Edit: TF_Booster_Edit
end
object B_Save: TButton
Left = 198
Top = 367
Top = 430
Width = 76
Height = 25
Margins.Left = 2
Expand All @@ -70,7 +70,7 @@ object F_Booster_Edit: TF_Booster_Edit
Left = 9
Top = 64
Width = 265
Height = 100
Height = 113
Margins.Left = 2
Margins.Top = 2
Margins.Right = 2
Expand Down Expand Up @@ -137,12 +137,20 @@ object F_Booster_Edit: TF_Booster_Edit
TabOrder = 0
OnClick = CHB_ShortClick
end
object CHB_short_reversed: TCheckBox
Left = 8
Top = 88
Width = 248
Height = 17
Caption = 'Reverzn'#237' indikace (neaktivn'#237' port = zkrat)'
TabOrder = 3
end
end
object GB_Power: TGroupBox
Left = 9
Top = 168
Top = 181
Width = 265
Height = 97
Height = 116
Margins.Left = 2
Margins.Top = 2
Margins.Right = 2
Expand Down Expand Up @@ -209,10 +217,18 @@ object F_Booster_Edit: TF_Booster_Edit
TabOrder = 0
OnClick = CHB_PowerClick
end
object CHB_power_reversed: TCheckBox
Left = 8
Top = 91
Width = 248
Height = 17
Caption = 'Reverzn'#237' indikace (aktivn'#237' port = nap'#225'jen'#237' ok)'
TabOrder = 3
end
end
object B_Storno: TButton
Left = 120
Top = 367
Top = 430
Width = 74
Height = 25
Margins.Left = 2
Expand All @@ -225,9 +241,9 @@ object F_Booster_Edit: TF_Booster_Edit
end
object GB_DCC: TGroupBox
Left = 9
Top = 269
Top = 301
Width = 265
Height = 94
Height = 116
Margins.Left = 2
Margins.Top = 2
Margins.Right = 2
Expand Down Expand Up @@ -294,6 +310,14 @@ object F_Booster_Edit: TF_Booster_Edit
TabOrder = 0
OnClick = CHB_DCCClick
end
object CHB_dcc_reversed: TCheckBox
Left = 8
Top = 90
Width = 248
Height = 17
Caption = 'Reverzn'#237' indikace (neaktivn'#237' port = DCC ok)'
TabOrder = 3
end
end
object E_ID: TEdit
Left = 97
Expand Down
62 changes: 40 additions & 22 deletions src/forms/fZesilovacEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ TF_Booster_Edit = class(TForm)
Label3: TLabel;
CHB_Power: TCheckBox;
CHB_Short: TCheckBox;
CHB_short_reversed: TCheckBox;
CHB_power_reversed: TCheckBox;
CHB_dcc_reversed: TCheckBox;
procedure B_SaveClick(Sender: TObject);
procedure B_StornoClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
Expand Down Expand Up @@ -118,29 +121,35 @@ procedure TF_Booster_Edit.B_SaveClick(Sender: TObject);

if (Self.CHB_Short.Checked) then
begin
settings.RCS.overload.board := Self.SE_Short_Module.Value;
settings.RCS.overload.port := SE_Short_Port.Value;
settings.rcs.overload.addr.board := Self.SE_Short_Module.Value;
settings.rcs.overload.addr.port := Self.SE_Short_Port.Value;
settings.rcs.overload.reversed := Self.CHB_short_reversed.Checked;
end else begin
settings.RCS.overload.board := 0;
settings.RCS.overload.port := 0;
settings.rcs.overload.addr.board := 0;
settings.rcs.overload.addr.port := 0;
settings.rcs.overload.reversed := false;
end;

if (Self.CHB_Power.Checked) then
begin
settings.RCS.power.board := Self.SE_Power_Module.Value;
settings.RCS.power.port := SE_Power_Port.Value;
settings.rcs.power.addr.board := Self.SE_Power_Module.Value;
settings.rcs.power.addr.port := Self.SE_Power_Port.Value;
settings.rcs.power.reversed := Self.CHB_power_reversed.Checked;
end else begin
settings.RCS.power.board := 0;
settings.RCS.power.port := 0;
settings.rcs.power.addr.board := 0;
settings.rcs.power.addr.port := 0;
settings.rcs.power.reversed := false;
end;

if (Self.CHB_DCC.Checked) then
begin
settings.RCS.DCC.board := Self.SE_DCC_module.Value;
settings.RCS.DCC.port := Self.SE_DCC_port.Value;
settings.rcs.DCC.addr.board := Self.SE_DCC_module.Value;
settings.rcs.DCC.addr.port := Self.SE_DCC_port.Value;
settings.rcs.DCC.reversed := Self.CHB_dcc_reversed.Checked;
end else begin
settings.RCS.DCC.board := 0;
settings.RCS.DCC.port := 0;
settings.rcs.DCC.addr.board := 0;
settings.rcs.DCC.addr.port := 0;
settings.rcs.DCC.reversed := false;
end;

Self.open_booster.settings := settings;
Expand All @@ -160,18 +169,21 @@ procedure TF_Booster_Edit.CHB_DCCClick(Sender: TObject);
begin
Self.SE_DCC_module.Enabled := Self.CHB_DCC.Checked;
Self.SE_DCC_port.Enabled := Self.CHB_DCC.Checked;
Self.CHB_dcc_reversed.Enabled := Self.CHB_DCC.Checked;
end;

procedure TF_Booster_Edit.CHB_PowerClick(Sender: TObject);
begin
Self.SE_Power_Module.Enabled := Self.CHB_Power.Checked;
Self.SE_Power_Port.Enabled := Self.CHB_Power.Checked;
Self.CHB_power_reversed.Enabled := Self.CHB_Power.Checked;
end;

procedure TF_Booster_Edit.CHB_ShortClick(Sender: TObject);
begin
Self.SE_Short_Module.Enabled := Self.CHB_Short.Checked;
Self.SE_Short_Port.Enabled := Self.CHB_Short.Checked;
Self.CHB_short_reversed.Enabled := Self.CHB_Short.Checked;
end;

procedure TF_Booster_Edit.NewBooster;
Expand All @@ -194,22 +206,25 @@ procedure TF_Booster_Edit.CommonOpenForm();
Self.SE_DCC_module.MaxValue := RCSi.maxModuleAddrSafe;
end;

procedure TF_Booster_Edit.NormalOpenForm;
procedure TF_Booster_Edit.NormalOpenForm();
var bSettings: TBoosterSettings;
begin
bSettings := open_booster.settings;

Self.E_ID.Text := bSettings.id;
Self.E_Name.Text := bSettings.name;

Self.SE_Short_Port.Value := bSettings.RCS.overload.port;
Self.SE_Power_Port.Value := bSettings.RCS.power.port;
Self.SE_Short_Module.Value := bSettings.rcs.overload.addr.board;
Self.SE_Short_Port.Value := bSettings.rcs.overload.addr.port;
Self.CHB_short_reversed.Checked := bSettings.rcs.overload.reversed;

Self.SE_Power_Module.Value := bSettings.RCS.power.board;
Self.SE_Short_Module.Value := bSettings.RCS.overload.board;
Self.SE_Power_Module.Value := bSettings.rcs.power.addr.board;
Self.SE_Power_Port.Value := bSettings.rcs.power.addr.port;
Self.CHB_power_reversed.Checked := bSettings.rcs.power.reversed;

Self.SE_DCC_module.Value := bSettings.RCS.DCC.board;
Self.SE_DCC_port.Value := bSettings.RCS.DCC.port;
Self.SE_DCC_module.Value := bSettings.rcs.DCC.addr.board;
Self.SE_DCC_port.Value := bSettings.rcs.DCC.addr.port;
Self.CHB_dcc_reversed.Checked := bSettings.rcs.DCC.reversed;

Self.CHB_Short.Checked := open_booster.isOverloadDetection;
Self.CHB_ShortClick(Self.CHB_Short);
Expand All @@ -225,19 +240,22 @@ procedure TF_Booster_Edit.NormalOpenForm;
Self.Caption := 'Zesilovač: ' + bSettings.name;
end;

procedure TF_Booster_Edit.NewOpenForm;
procedure TF_Booster_Edit.NewOpenForm();
begin
Self.E_ID.Text := '';
Self.E_Name.Text := '';

Self.SE_Short_Module.Value := 1;
Self.SE_Short_Port.Value := 0;
Self.SE_Power_Port.Value := 0;
Self.CHB_short_reversed.Checked := false;

Self.SE_Power_Module.Value := 1;
Self.SE_Short_Module.Value := 1;
Self.SE_Power_Port.Value := 0;
Self.CHB_power_reversed.Checked := false;

Self.SE_DCC_module.Value := 1;
Self.SE_DCC_port.Value := 0;
Self.CHB_dcc_reversed.Checked := false;

Self.CHB_Short.Checked := true;
Self.CHB_ShortClick(Self.CHB_Short);
Expand Down
Loading

0 comments on commit aa1e894

Please sign in to comment.