|
@@ -9,7 +9,7 @@ interface
|
|
|
uses
|
|
|
Windows, Classes, SysUtils, FileUtil, SdpoSerial, Forms, Controls, Graphics, Dialogs,
|
|
|
Grids, ExtCtrls, Menus, ComCtrls, ActnList, StdActns, LCLProc, StdCtrls, Spin,
|
|
|
- XMLPropStorage, uSPS, LCLType, Buttons, types, MCSWINAPI, Math;
|
|
|
+ XMLPropStorage, uSPS, LCLType, Buttons, types, MCSWINAPI, Math, fpjson, jsonparser;
|
|
|
|
|
|
type
|
|
|
|
|
@@ -38,6 +38,8 @@ type
|
|
|
EditDelay: TLabeledEdit;
|
|
|
EditPage: TLabeledEdit;
|
|
|
EditRAdr: TLabeledEdit;
|
|
|
+ acPresetLoad: TFileOpen;
|
|
|
+ acPresetSave: TFileSaveAs;
|
|
|
GroupBox4: TGroupBox;
|
|
|
ImageList2: TImageList;
|
|
|
Label3: TLabel;
|
|
@@ -94,6 +96,8 @@ type
|
|
|
StatusBar1: TStatusBar;
|
|
|
StringGrid1: TStringGrid;
|
|
|
tbPrg: TToggleBox;
|
|
|
+ tbPreLoad: TToolButton;
|
|
|
+ tbPreSave: TToolButton;
|
|
|
tbSel: TToggleBox;
|
|
|
Timer1: TTimer;
|
|
|
ToolBar1: TToolBar;
|
|
@@ -126,6 +130,8 @@ type
|
|
|
ToolButton7: TToolButton;
|
|
|
ToolButton8: TToolButton;
|
|
|
ToolButton9: TToolButton;
|
|
|
+ TOpenDialogPreset: TOpenDialog;
|
|
|
+ TSaveDialogPreset: TSaveDialog;
|
|
|
XMLPropStorage1: TXMLPropStorage;
|
|
|
procedure acDeleteRowExecute(Sender: TObject);
|
|
|
procedure acExitExecute(Sender: TObject);
|
|
@@ -137,6 +143,8 @@ type
|
|
|
procedure acNewExecute(Sender: TObject);
|
|
|
procedure acNewRowExecute(Sender: TObject);
|
|
|
procedure acNextStepExecute(Sender: TObject);
|
|
|
+ procedure acPresetLoadAccept(Sender: TObject);
|
|
|
+ procedure acPresetSaveAccept(Sender: TObject);
|
|
|
procedure acShowHexFileExecute(Sender: TObject);
|
|
|
procedure acStopExecute(Sender: TObject);
|
|
|
procedure acThisStepExecute(Sender: TObject);
|
|
@@ -155,8 +163,7 @@ type
|
|
|
procedure StringGrid1EditingDone(Sender: TObject);
|
|
|
procedure StringGrid1Selection(Sender: TObject; aCol, aRow: integer);
|
|
|
procedure tbPreset1Click(Sender: TObject);
|
|
|
- procedure tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint;
|
|
|
- var Handled: boolean);
|
|
|
+ procedure tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: boolean);
|
|
|
procedure tbResetClick(Sender: TObject);
|
|
|
procedure Timer1Timer(Sender: TObject);
|
|
|
private
|
|
@@ -165,6 +172,9 @@ type
|
|
|
stopit: boolean;
|
|
|
activeFile: string;
|
|
|
dirty: boolean;
|
|
|
+ procedure saveSection(filename: string; key: string);
|
|
|
+ procedure loadSection(filename: string; key: string);
|
|
|
+
|
|
|
procedure loadFile(filename: string);
|
|
|
procedure programSps;
|
|
|
procedure nextStep;
|
|
@@ -180,6 +190,8 @@ type
|
|
|
procedure makeHexFile(fileName: string);
|
|
|
procedure setCaption;
|
|
|
procedure addHeaderText;
|
|
|
+ procedure loadPreset(filename: string);
|
|
|
+ procedure savePreset(filename: string);
|
|
|
public
|
|
|
{ public declarations }
|
|
|
end;
|
|
@@ -190,7 +202,7 @@ var
|
|
|
implementation
|
|
|
|
|
|
uses MCSAbout, uTextUi, uSelectCom, MCSTools, MCSStrings, synaser,
|
|
|
- MCSIO, mcsintelhex, fpjson, MCSLSU;
|
|
|
+ MCSIO, mcsintelhex, MCSLSU, MCSIniFiles;
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
@@ -396,8 +408,8 @@ begin
|
|
|
begin
|
|
|
if (StringGrid1.Cells[1, x] <> '') then
|
|
|
begin
|
|
|
- line := StringGrid1.Cells[0, x] + ',' + StringGrid1.Cells[1, x] +
|
|
|
- ',' + StringGrid1.Cells[2, x] + ',"' + StringGrid1.Cells[4, x] + '"';
|
|
|
+ line := StringGrid1.Cells[0, x] + ',' + StringGrid1.Cells[1, x] + ',' +
|
|
|
+ StringGrid1.Cells[2, x] + ',"' + StringGrid1.Cells[4, x] + '"';
|
|
|
Writeln(f, line);
|
|
|
end;
|
|
|
end;
|
|
@@ -465,33 +477,42 @@ end;
|
|
|
|
|
|
procedure TForm1.acNewExecute(Sender: TObject);
|
|
|
begin
|
|
|
- StringGrid1.RowCount := 2;
|
|
|
- StringGrid1.Clean;
|
|
|
- addHeaderText();
|
|
|
- renumberGrid();
|
|
|
- activeFile := '';
|
|
|
- setCaption();
|
|
|
- setDirty(False);
|
|
|
+ if (checkDirty()) then
|
|
|
+ begin
|
|
|
+ StringGrid1.RowCount := 2;
|
|
|
+ StringGrid1.Clean;
|
|
|
+ addHeaderText();
|
|
|
+ renumberGrid();
|
|
|
+ activeFile := '';
|
|
|
+ setCaption();
|
|
|
+ setDirty(False);
|
|
|
+ end;
|
|
|
end;
|
|
|
|
|
|
procedure TForm1.acNewRowExecute(Sender: TObject);
|
|
|
var
|
|
|
myPos: integer;
|
|
|
i, x: integer;
|
|
|
+ eot: boolean;
|
|
|
begin
|
|
|
myPos := StringGrid1.Row;
|
|
|
+ if (myPos = StringGrid1.RowCount - 1) then
|
|
|
+ eot := True;
|
|
|
StringGrid1.RowCount := StringGrid1.RowCount + 1;
|
|
|
- for i := StringGrid1.RowCount - 2 downto myPos do
|
|
|
+ if (not eot) then
|
|
|
begin
|
|
|
+ for i := StringGrid1.RowCount - 2 downto myPos do
|
|
|
+ begin
|
|
|
+ for x := 1 to StringGrid1.ColCount - 1 do
|
|
|
+ begin
|
|
|
+ StringGrid1.Cells[x, i + 1] := StringGrid1.Cells[x, i];
|
|
|
+ end;
|
|
|
+ end;
|
|
|
for x := 1 to StringGrid1.ColCount - 1 do
|
|
|
begin
|
|
|
- StringGrid1.Cells[x, i + 1] := StringGrid1.Cells[x, i];
|
|
|
+ StringGrid1.Cells[x, myPos] := '';
|
|
|
end;
|
|
|
end;
|
|
|
- for x := 1 to StringGrid1.ColCount - 1 do
|
|
|
- begin
|
|
|
- StringGrid1.Cells[x, myPos] := '';
|
|
|
- end;
|
|
|
renumberGrid();
|
|
|
end;
|
|
|
|
|
@@ -528,6 +549,22 @@ begin
|
|
|
selectAddress(sps.getAddress());
|
|
|
end;
|
|
|
|
|
|
+procedure TForm1.acPresetLoadAccept(Sender: TObject);
|
|
|
+var
|
|
|
+ filename: string;
|
|
|
+begin
|
|
|
+ filename := (Sender as TFileOpen).Dialog.FileName;
|
|
|
+ loadPreset(filename);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TForm1.acPresetSaveAccept(Sender: TObject);
|
|
|
+var
|
|
|
+ filename: string;
|
|
|
+begin
|
|
|
+ filename := (Sender as TFileSaveAs).Dialog.FileName;
|
|
|
+ savePreset(filename);
|
|
|
+end;
|
|
|
+
|
|
|
procedure TForm1.nextStep;
|
|
|
begin
|
|
|
if (not sps.isActive()) then
|
|
@@ -628,8 +665,7 @@ begin
|
|
|
tmp := tmp + '0';
|
|
|
line := line + tmp;
|
|
|
|
|
|
- line := line + ' ' + StringGrid1.Cells[3, x] + ' ,"' +
|
|
|
- StringGrid1.Cells[4, x] + '"';
|
|
|
+ line := line + ' ' + StringGrid1.Cells[3, x] + ' ,"' + StringGrid1.Cells[4, x] + '"';
|
|
|
list.add(line);
|
|
|
end;
|
|
|
end;
|
|
@@ -721,8 +757,7 @@ begin
|
|
|
begin
|
|
|
KeyName := 'SOFTWARE\WOW6432Node\Arduino';
|
|
|
StringValue := 'Install_Dir';
|
|
|
- Res := RegistryReadString(HKEY_LOCAL_MACHINE, WideString(KeyName),
|
|
|
- WideString(StringValue));
|
|
|
+ Res := RegistryReadString(HKEY_LOCAL_MACHINE, WideString(KeyName), WideString(StringValue));
|
|
|
if Res <> '' then
|
|
|
begin
|
|
|
line := string(Res);
|
|
@@ -808,8 +843,7 @@ var
|
|
|
begin
|
|
|
if (dirty) then
|
|
|
begin
|
|
|
- i := MCSLSU.LSUAutoMsgBox('Messages', 'SAVE_CHANGES', MB_ICONQUESTION or
|
|
|
- MB_YESNOCANCEL);
|
|
|
+ i := MCSLSU.LSUAutoMsgBox('Messages', 'SAVE_CHANGES', MB_ICONQUESTION or MB_YESNOCANCEL);
|
|
|
if (i = mrYes) then
|
|
|
begin
|
|
|
saveFile(activeFile);
|
|
@@ -834,21 +868,37 @@ end;
|
|
|
procedure TForm1.checkPresets;
|
|
|
begin
|
|
|
if XMLPropStorage1.ReadBoolean('preset_1.set', False) then
|
|
|
- tbPreset1.Caption := '1*';
|
|
|
+ tbPreset1.Caption := '1*'
|
|
|
+ else
|
|
|
+ tbPreset1.Caption := '1';
|
|
|
if XMLPropStorage1.ReadBoolean('preset_2.set', False) then
|
|
|
- tbPreset2.Caption := '2*';
|
|
|
+ tbPreset2.Caption := '2*'
|
|
|
+ else
|
|
|
+ tbPreset2.Caption := '2';
|
|
|
if XMLPropStorage1.ReadBoolean('preset_3.set', False) then
|
|
|
- tbPreset3.Caption := '3*';
|
|
|
+ tbPreset3.Caption := '3*'
|
|
|
+ else
|
|
|
+ tbPreset3.Caption := '3';
|
|
|
if XMLPropStorage1.ReadBoolean('preset_4.set', False) then
|
|
|
- tbPreset4.Caption := '4*';
|
|
|
+ tbPreset4.Caption := '4*'
|
|
|
+ else
|
|
|
+ tbPreset4.Caption := '4';
|
|
|
if XMLPropStorage1.ReadBoolean('preset_5.set', False) then
|
|
|
- tbPreset5.Caption := '5*';
|
|
|
+ tbPreset5.Caption := '5*'
|
|
|
+ else
|
|
|
+ tbPreset5.Caption := '5';
|
|
|
if XMLPropStorage1.ReadBoolean('preset_6.set', False) then
|
|
|
- tbPreset6.Caption := '6*';
|
|
|
+ tbPreset6.Caption := '6*'
|
|
|
+ else
|
|
|
+ tbPreset6.Caption := '6';
|
|
|
if XMLPropStorage1.ReadBoolean('preset_7.set', False) then
|
|
|
- tbPreset7.Caption := '7*';
|
|
|
+ tbPreset7.Caption := '7*'
|
|
|
+ else
|
|
|
+ tbPreset7.Caption := '7';
|
|
|
if XMLPropStorage1.ReadBoolean('preset_8.set', False) then
|
|
|
- tbPreset8.Caption := '8*';
|
|
|
+ tbPreset7.Caption := '8*'
|
|
|
+ else
|
|
|
+ tbPreset7.Caption := '8';
|
|
|
end;
|
|
|
|
|
|
procedure TForm1.makeHexFile(fileName: string);
|
|
@@ -893,8 +943,7 @@ begin
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
- Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode) +
|
|
|
- ':' + ExtractFileName(activeFile);
|
|
|
+ Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode) + ':' + ExtractFileName(activeFile);
|
|
|
end;
|
|
|
|
|
|
end;
|
|
@@ -909,8 +958,7 @@ begin
|
|
|
StringGrid1.Columns[i].Title.Caption :=
|
|
|
MCSLSU.GetLSUText('form1Captions', StringGrid1.Columns[i].Title.Caption, lsuCode);
|
|
|
end;
|
|
|
- StringGrid1.Cells[0, 0] := MCSLSU.GetLSUText('form1Captions',
|
|
|
- 'ID_GRID_STORAGE', lsuCode);
|
|
|
+ StringGrid1.Cells[0, 0] := MCSLSU.GetLSUText('form1Captions', 'ID_GRID_STORAGE', lsuCode);
|
|
|
StringGrid1.Repaint;
|
|
|
end;
|
|
|
|
|
@@ -1050,8 +1098,7 @@ begin
|
|
|
begin
|
|
|
x := StringGrid1.Row;
|
|
|
StringGrid1.Cells[3, x] :=
|
|
|
- sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]),
|
|
|
- HexToInt(StringGrid1.Cells[2, x]));
|
|
|
+ sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]), HexToInt(StringGrid1.Cells[2, x]));
|
|
|
setDirty(True);
|
|
|
end;
|
|
|
end;
|
|
@@ -1066,6 +1113,61 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+procedure TForm1.loadPreset(filename : string);
|
|
|
+var
|
|
|
+ x: integer;
|
|
|
+ key: string;
|
|
|
+begin
|
|
|
+ for x := 1 to 8 do
|
|
|
+ begin
|
|
|
+ key := 'preset_' + IntToStr(x);
|
|
|
+ loadSection(filename, key);
|
|
|
+ end;
|
|
|
+ checkPresets;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TForm1.savePreset(filename : string);
|
|
|
+var
|
|
|
+ x: integer;
|
|
|
+ key: string;
|
|
|
+begin
|
|
|
+ for x := 1 to 8 do
|
|
|
+ begin
|
|
|
+ key := 'preset_' + IntToStr(x);
|
|
|
+ saveSection(filename, key);
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TForm1.saveSection(filename: string; key: string);
|
|
|
+begin
|
|
|
+ WriteIniBool(key, 'set', XMLPropStorage1.ReadBoolean(key + '.set', False), filename);
|
|
|
+ WriteIniBool(key, 'prg', XMLPropStorage1.ReadBoolean(key + '.prg', False), filename);
|
|
|
+ WriteIniBool(key, 'sel', XMLPropStorage1.ReadBoolean(key + '.sel', False), filename);
|
|
|
+ WriteIniBool(key, 'input1', XMLPropStorage1.ReadBoolean(key + '.input1', False), filename);
|
|
|
+ WriteIniBool(key, 'input2', XMLPropStorage1.ReadBoolean(key + '.input2', False), filename);
|
|
|
+ WriteIniBool(key, 'input3', XMLPropStorage1.ReadBoolean(key + '.input3', False), filename);
|
|
|
+ WriteIniBool(key, 'input4', XMLPropStorage1.ReadBoolean(key + '.input4', False), filename);
|
|
|
+ WriteIniInteger(key, 'adc1', XMLPropStorage1.ReadInteger(key + '.adc1', 0), filename);
|
|
|
+ WriteIniInteger(key, 'adc2', XMLPropStorage1.ReadInteger(key + '.adc2', 0), filename);
|
|
|
+ WriteIniInteger(key, 'rc1', XMLPropStorage1.ReadInteger(key + '.rc1', 0), filename);
|
|
|
+ WriteIniInteger(key, 'rc2', XMLPropStorage1.ReadInteger(key + '.rc2', 0), filename);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TForm1.loadSection(filename: string; key: string);
|
|
|
+begin
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.set', ReadIniBool(key, 'set', False, filename));
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.prg', ReadIniBool(key, 'prg', False, filename));
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.sel', ReadIniBool(key, 'sel', False, filename));
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.input1', ReadIniBool(key, 'input1', False, filename));
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.input2', ReadIniBool(key, 'input2', False, filename));
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.input3', ReadIniBool(key, 'input3', False, filename));
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.input4', ReadIniBool(key, 'input4', False, filename));
|
|
|
+ XMLPropStorage1.WriteInteger(key + '.adc1', ReadIniInteger(key, 'adc1', 0, filename));
|
|
|
+ XMLPropStorage1.WriteInteger(key + '.adc2', ReadIniInteger(key, 'adc2', 0, filename));
|
|
|
+ XMLPropStorage1.WriteInteger(key + '.rc1', ReadIniInteger(key, 'rc1', 0, filename));
|
|
|
+ XMLPropStorage1.WriteInteger(key + '.rc2', ReadIniInteger(key, 'rc2', 0, filename));
|
|
|
+end;
|
|
|
+
|
|
|
procedure TForm1.tbPreset1Click(Sender: TObject);
|
|
|
var
|
|
|
key: string;
|
|
@@ -1094,6 +1196,8 @@ begin
|
|
|
if Sender = tbPreset8 then
|
|
|
key := 'preset_8';
|
|
|
|
|
|
+ tbSel.Checked := XMLPropStorage1.ReadBoolean(key + '.prg', tbSel.Checked);
|
|
|
+ tbPrg.Checked := XMLPropStorage1.ReadBoolean(key + '.sel', tbPrg.Checked);
|
|
|
Din1.Checked := XMLPropStorage1.ReadBoolean(key + '.input1', Din1.Checked);
|
|
|
Din2.Checked := XMLPropStorage1.ReadBoolean(key + '.input2', Din2.Checked);
|
|
|
Din3.Checked := XMLPropStorage1.ReadBoolean(key + '.input3', Din3.Checked);
|
|
@@ -1104,8 +1208,7 @@ begin
|
|
|
RC2.Value := XMLPropStorage1.ReadInteger(key + '.rc2', RC2.Value);
|
|
|
end;
|
|
|
|
|
|
-procedure TForm1.tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint;
|
|
|
- var Handled: boolean);
|
|
|
+procedure TForm1.tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: boolean);
|
|
|
var
|
|
|
key: string;
|
|
|
begin
|
|
@@ -1134,6 +1237,8 @@ begin
|
|
|
key := 'preset_8';
|
|
|
|
|
|
XMLPropStorage1.WriteBoolean(key + '.set', True);
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.prg', tbPrg.Checked);
|
|
|
+ XMLPropStorage1.WriteBoolean(key + '.sel', tbSel.Checked);
|
|
|
XMLPropStorage1.WriteBoolean(key + '.input1', Din1.Checked);
|
|
|
XMLPropStorage1.WriteBoolean(key + '.input2', Din2.Checked);
|
|
|
XMLPropStorage1.WriteBoolean(key + '.input3', Din3.Checked);
|
|
@@ -1147,6 +1252,8 @@ end;
|
|
|
|
|
|
procedure TForm1.tbResetClick(Sender: TObject);
|
|
|
begin
|
|
|
+ tbPrg.Checked := False;
|
|
|
+ tbSel.Checked := False;
|
|
|
Din1.Checked := False;
|
|
|
Din2.Checked := False;
|
|
|
Din3.Checked := False;
|
|
@@ -1171,8 +1278,8 @@ begin
|
|
|
if (InfoBox.newVersion) then
|
|
|
begin
|
|
|
MCSLabel.Font.Color := clred;
|
|
|
- MCSLabel.Hint := InfoBox.versionHint + chr($0a) + chr($0d) +
|
|
|
- MCSLSU.GetLSUText('form1Captions', 'ID_CLICK_HERE', lsuCode);
|
|
|
+ MCSLabel.Hint := InfoBox.versionHint + chr($0a) + chr($0d) + MCSLSU.GetLSUText(
|
|
|
+ 'form1Captions', 'ID_CLICK_HERE', lsuCode);
|
|
|
end;
|
|
|
MCSLabel.Caption := InfoBox.versionText;
|
|
|
end;
|
|
@@ -1185,9 +1292,12 @@ begin
|
|
|
for x := 1 to i - 1 do
|
|
|
begin
|
|
|
StringGrid1.Cells[0, x] := '0x' + inttohex(x - 1, 2);
|
|
|
+ if (StringGrid1.Cells[1, x] = '') then
|
|
|
+ StringGrid1.Cells[1, x] := '0';
|
|
|
+ if (StringGrid1.Cells[2, x] = '') then
|
|
|
+ StringGrid1.Cells[2, x] := '0';
|
|
|
StringGrid1.Cells[3, x] :=
|
|
|
- sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]),
|
|
|
- HexToInt(StringGrid1.Cells[2, x]));
|
|
|
+ sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]), HexToInt(StringGrid1.Cells[2, x]));
|
|
|
end;
|
|
|
end;
|
|
|
|