Skip to content

Commit 998d036

Browse files
committed
Added the ability to run chip-related scripts from the main program window
1 parent 01982f3 commit 998d036

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

software/findchip.pas

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TChipSearchForm = class(TForm)
3535

3636
implementation
3737

38-
uses main;
38+
uses main, scriptsfunc;
3939

4040
{$R *.lfm}
4141

@@ -181,9 +181,16 @@ procedure SelectChip(XMLfile: TXMLDocument; chipname: string);
181181
Main.CurrentICParam.Size := 0;
182182

183183
if ChipNode.Attributes.GetNamedItem('script') <> nil then
184-
Main.CurrentICParam.Script:= UTF16ToUTF8(ChipNode.Attributes.GetNamedItem('script').NodeValue)
184+
begin
185+
Main.CurrentICParam.Script:= UTF16ToUTF8(ChipNode.Attributes.GetNamedItem('script').NodeValue);
186+
MainForm.ComboBox_chip_scriptrun.Items := scriptsfunc.GetScriptSectionsFromFile(Main.CurrentICParam.Script);
187+
MainForm.ComboBox_chip_scriptrun.ItemIndex := 0;
188+
end
185189
else
190+
begin
186191
Main.CurrentICParam.Script := '';
192+
MainForm.ComboBox_chip_scriptrun.Items.Clear;
193+
end;
187194

188195

189196
MainForm.LabelChipName.Caption := CurrentICParam.Name;

software/main.lfm

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ object MainForm: TMainForm
221221
Text = 'Chip size'
222222
end
223223
object Label2: TLabel
224-
Left = 8
224+
Left = 24
225225
Height = 16
226-
Top = 40
226+
Top = 32
227227
Width = 100
228228
Alignment = taCenter
229229
AutoSize = False
@@ -494,6 +494,36 @@ object MainForm: TMainForm
494494
TabOrder = 7
495495
end
496496
end
497+
object ComboBox_chip_scriptrun: TComboBox
498+
Left = 15
499+
Height = 23
500+
Top = 248
501+
Width = 100
502+
ItemHeight = 15
503+
Style = csDropDownList
504+
TabOrder = 6
505+
end
506+
object SpeedButton1: TSpeedButton
507+
Left = 124
508+
Height = 22
509+
Hint = 'Выполнить скрипт'
510+
Top = 248
511+
Width = 23
512+
Caption = '->'
513+
OnClick = SpeedButton1Click
514+
ShowHint = True
515+
ParentShowHint = False
516+
end
517+
object Label_chip_scripts: TLabel
518+
Left = 15
519+
Height = 15
520+
Top = 233
521+
Width = 97
522+
Alignment = taCenter
523+
AutoSize = False
524+
Caption = 'Скрипты'
525+
ParentColor = False
526+
end
497527
end
498528
object MPHexEditorEx: TMPHexEditorEx
499529
Cursor = crIBeam

software/main.pas

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ TMainForm = class(TForm)
3030
CheckBox_I2C_DevA4: TToggleBox;
3131
CheckBox_I2C_A2: TToggleBox;
3232
ComboAddrType: TComboBox;
33+
ComboBox_chip_scriptrun: TComboBox;
3334
ComboSPICMD: TComboBox;
3435
ComboChipSize: TComboBox;
3536
ComboMWBitLen: TComboBox;
@@ -41,6 +42,7 @@ TMainForm = class(TForm)
4142
Label3: TLabel;
4243
Label4: TLabel;
4344
Label5: TLabel;
45+
Label_chip_scripts: TLabel;
4446
Label_I2C_DevAddr: TLabel;
4547
LabelSPICMD: TLabel;
4648
LabelChipName: TLabel;
@@ -114,6 +116,7 @@ TMainForm = class(TForm)
114116
RadioMw: TRadioButton;
115117
RadioSPI: TRadioButton;
116118
SaveDialog: TSaveDialog;
119+
SpeedButton1: TSpeedButton;
117120
Splitter1: TSplitter;
118121
StatusBar: TStatusBar;
119122
CheckBox_I2C_DevA7: TToggleBox;
@@ -171,6 +174,7 @@ TMainForm = class(TForm)
171174
procedure ButtonCancelClick(Sender: TObject);
172175
procedure I2C_DevAddrChange(Sender: TObject);
173176
procedure ScriptsMenuItemClick(Sender: TObject);
177+
procedure SpeedButton1Click(Sender: TObject);
174178
procedure VerifyFlash(BlankCheck: boolean = false);
175179
private
176180
{ private declarations }
@@ -2632,6 +2636,13 @@ procedure TMainForm.ScriptsMenuItemClick(Sender: TObject);
26322636
ScriptEditForm.Show;
26332637
end;
26342638

2639+
procedure TMainForm.SpeedButton1Click(Sender: TObject);
2640+
begin
2641+
if ComboBox_chip_scriptrun.Items.Capacity < 1 then Exit;;
2642+
if not OpenDevice() then exit;
2643+
if RunScriptFromFile(CurrentICParam.Script, ComboBox_chip_scriptrun.Text) then Exit;
2644+
end;
2645+
26352646
procedure LoadChipList(XMLfile: TXMLDocument);
26362647
var
26372648
Node: TDOMNode;
@@ -2690,7 +2701,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
26902701
ScriptsFunc.SetScriptFunctions(ScriptEngine);
26912702

26922703
MPHexEditorEx.NoSizeChange := true;
2693-
MPHexEditorEx.InsertMode:= false;
2704+
MPHexEditorEx.InsertMode := false;
26942705
LoadOptions(SettingsFile);
26952706
LoadLangList();
26962707
end;

software/scriptsfunc.pas

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ procedure SetScriptVars();
1212
procedure RunScript(ScriptText: TStrings);
1313
function RunScriptFromFile(ScriptFile: string; Section: string): boolean;
1414
function ParseScriptText(Script: TStrings; SectionName: string; var ScriptText: TStrings ): Boolean;
15+
function GetScriptSectionsFromFile(ScriptFile: string): TStrings;
1516

1617
implementation
1718

@@ -20,6 +21,34 @@ implementation
2021
const _SPI_SPEED_MAX = 255;
2122

2223

24+
function GetScriptSectionsFromFile(ScriptFile: string): TStrings;
25+
var
26+
st, SectionName: string;
27+
i: integer;
28+
ScriptText: TStrings;
29+
begin
30+
if not FileExists(ScriptsPath+ScriptFile) then Exit;
31+
32+
Result:= TStringList.Create;
33+
ScriptText:= TStringList.Create;
34+
35+
ScriptText.LoadFromFile(ScriptsPath+ScriptFile);
36+
37+
for i:= 0 to ScriptText.Count-1 do
38+
begin
39+
st := Trim(Upcase(ScriptText.Strings[i]));
40+
if Copy(st, 1, 2) = '{$' then
41+
begin
42+
SectionName := Trim(Copy(st, 3, pos('}', st)-3));
43+
if SectionName <> '' then
44+
begin
45+
Result.Add(SectionName);
46+
end;
47+
end;
48+
end;
49+
50+
end;
51+
2352
{Возвращает текст выбранной секции
2453
Если секция не найдена возвращает false}
2554
function ParseScriptText(Script: TStrings; SectionName: string; var ScriptText: TStrings ): Boolean;

0 commit comments

Comments
 (0)