ugui.pas 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  1. unit uGUI;
  2. {$mode objfpc}{$H+}
  3. {$define DebugLCLComponents}
  4. interface
  5. uses
  6. Windows, Classes, SysUtils, FileUtil, SdpoSerial, Forms, Controls, Graphics, Dialogs,
  7. Grids, ExtCtrls, Menus, ComCtrls, ActnList, StdActns, LCLProc, StdCtrls, Spin,
  8. XMLPropStorage, uSPS, LCLType, Buttons, types, MCSWINAPI, Math, fpjson, jsonparser;
  9. type
  10. { TForm1 }
  11. TForm1 = class(TForm)
  12. acExit: TAction;
  13. acDebug: TAction;
  14. acNextStep: TAction;
  15. acStop: TAction;
  16. acThisStep: TAction;
  17. acShowHexFile: TAction;
  18. acNew: TAction;
  19. acNewRow: TAction;
  20. acDeleteRow: TAction;
  21. acFileSave: TAction;
  22. acHelpAbout: TAction;
  23. acHexFile: TAction;
  24. acUpload: TAction;
  25. ActionList1: TActionList;
  26. acFileOpen: TFileOpen;
  27. acFileSaveAs: TFileSaveAs;
  28. btnTone: TBitBtn;
  29. cbTPSVersion: TComboBox;
  30. cbAdrActual: TCheckBox;
  31. EditDelay: TLabeledEdit;
  32. EditJump: TLabeledEdit;
  33. EditPage: TLabeledEdit;
  34. EditRAdr: TLabeledEdit;
  35. acPresetLoad: TFileOpen;
  36. acPresetSave: TFileSaveAs;
  37. GBControl: TGroupBox;
  38. ImageList2: TImageList;
  39. Label3: TLabel;
  40. Label4: TLabel;
  41. Label5: TLabel;
  42. lbStack: TListBox;
  43. MCSLabel: TLabel;
  44. RC1: TSpinEdit;
  45. RC2: TSpinEdit;
  46. cbCommand: TComboBox;
  47. cbData: TComboBox;
  48. Din1: TCheckBox;
  49. Din2: TCheckBox;
  50. Din3: TCheckBox;
  51. Din4: TCheckBox;
  52. GBOutput: TGroupBox;
  53. GBInput: TGroupBox;
  54. GBInternal: TGroupBox;
  55. ImageList1: TImageList;
  56. Label1: TLabel;
  57. Label10: TLabel;
  58. Label11: TLabel;
  59. Label12: TLabel;
  60. Label13: TLabel;
  61. Label14: TLabel;
  62. Label15: TLabel;
  63. Label16: TLabel;
  64. Label17: TLabel;
  65. Label2: TLabel;
  66. Panel2: TPanel;
  67. Panel3: TPanel;
  68. PWM1: TLabeledEdit;
  69. PWM2: TLabeledEdit;
  70. Panel1: TPanel;
  71. ADC1: TSpinEdit;
  72. ADC2: TSpinEdit;
  73. SaveDialog1: TSaveDialog;
  74. SaveHexFile: TSaveDialog;
  75. Servo1: TLabeledEdit;
  76. Servo2: TLabeledEdit;
  77. EditA: TLabeledEdit;
  78. EditC: TLabeledEdit;
  79. EditE: TLabeledEdit;
  80. EditB: TLabeledEdit;
  81. EditD: TLabeledEdit;
  82. EditF: TLabeledEdit;
  83. EditAddr: TLabeledEdit;
  84. Shape1: TShape;
  85. Shape2: TShape;
  86. ShapeOut1: TShape;
  87. ShapeOut2: TShape;
  88. ShapeOut3: TShape;
  89. ShapeOut4: TShape;
  90. StatusBar1: TStatusBar;
  91. StringGrid1: TStringGrid;
  92. tbPrg: TToggleBox;
  93. tbPreLoad: TToolButton;
  94. tbPreSave: TToolButton;
  95. tbSel: TToggleBox;
  96. Timer1: TTimer;
  97. ToolBar1: TToolBar;
  98. ToolBar2: TToolBar;
  99. ToolButton1: TToolButton;
  100. ToolButton10: TToolButton;
  101. ToolButton11: TToolButton;
  102. ToolButton12: TToolButton;
  103. ToolButton13: TToolButton;
  104. ToolButton14: TToolButton;
  105. ToolButton15: TToolButton;
  106. ToolButton16: TToolButton;
  107. ToolButton17: TToolButton;
  108. ToolButton18: TToolButton;
  109. tbPreset1: TToolButton;
  110. tbReset: TToolButton;
  111. ToolButton19: TToolButton;
  112. ToolButton2: TToolButton;
  113. tbPreset2: TToolButton;
  114. tbPreset3: TToolButton;
  115. tbPreset4: TToolButton;
  116. tbPreset5: TToolButton;
  117. tbPreset6: TToolButton;
  118. tbPreset7: TToolButton;
  119. tbPreset8: TToolButton;
  120. ToolButton3: TToolButton;
  121. ToolButton4: TToolButton;
  122. ToolButton5: TToolButton;
  123. ToolButton6: TToolButton;
  124. ToolButton7: TToolButton;
  125. ToolButton8: TToolButton;
  126. ToolButton9: TToolButton;
  127. TOpenDialogPreset: TOpenDialog;
  128. TSaveDialogPreset: TSaveDialog;
  129. XMLPropStorage1: TXMLPropStorage;
  130. procedure acDeleteRowExecute(Sender: TObject);
  131. procedure acExitExecute(Sender: TObject);
  132. procedure acFileOpenAccept(Sender: TObject);
  133. procedure acFileSaveAsAccept(Sender: TObject);
  134. procedure acDebugExecute(Sender: TObject);
  135. procedure acHelpAboutExecute(Sender: TObject);
  136. procedure acHexFileExecute(Sender: TObject);
  137. procedure acNewExecute(Sender: TObject);
  138. procedure acNewRowExecute(Sender: TObject);
  139. procedure acNextStepExecute(Sender: TObject);
  140. procedure acPresetLoadAccept(Sender: TObject);
  141. procedure acPresetSaveAccept(Sender: TObject);
  142. procedure acShowHexFileExecute(Sender: TObject);
  143. procedure acStopExecute(Sender: TObject);
  144. procedure acThisStepExecute(Sender: TObject);
  145. procedure acFileSaveExecute(Sender: TObject);
  146. procedure acUploadExecute(Sender: TObject);
  147. procedure cbCommandChange(Sender: TObject);
  148. procedure cbDataChange(Sender: TObject);
  149. procedure cbTPSVersionChange(Sender: TObject);
  150. procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
  151. procedure FormCreate(Sender: TObject);
  152. procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
  153. procedure MCSLabelClick(Sender: TObject);
  154. procedure mnSaveClick(Sender: TObject);
  155. procedure Shape1Paint(Sender: TObject);
  156. procedure Shape2Paint(Sender: TObject);
  157. procedure StringGrid1EditingDone(Sender: TObject);
  158. procedure StringGrid1Selection(Sender: TObject; aCol, aRow: integer);
  159. procedure tbPreset1Click(Sender: TObject);
  160. procedure tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: boolean);
  161. procedure tbResetClick(Sender: TObject);
  162. procedure Timer1Timer(Sender: TObject);
  163. private
  164. { private declarations }
  165. sps: TSPS;
  166. stopit: boolean;
  167. activeFile: string;
  168. dirty: boolean;
  169. procedure saveSection(filename: string; key: string);
  170. procedure loadSection(filename: string; key: string);
  171. procedure loadFile(filename: string);
  172. procedure programSps;
  173. procedure nextStep;
  174. procedure renumberGrid;
  175. procedure saveFile(filename: string);
  176. procedure selectAddress(addr: byte);
  177. procedure inputSps;
  178. procedure outputSps;
  179. procedure uploadFile;
  180. procedure setDirty(Value: boolean);
  181. function checkDirty: boolean;
  182. procedure checkPresets;
  183. procedure makeHexFile(fileName: string);
  184. procedure setCaption;
  185. procedure addHeaderText;
  186. procedure loadPreset(filename: string);
  187. procedure savePreset(filename: string);
  188. procedure activateSps(enable: boolean);
  189. public
  190. { public declarations }
  191. end;
  192. var
  193. Form1: TForm1;
  194. implementation
  195. uses MCSAbout, uTextUi, uSelectCom, MCSTools, MCSStrings, synaser,
  196. MCSIO, mcsintelhex, MCSLSU, MCSIniFiles;
  197. {$R *.lfm}
  198. procedure delayCallback(Value: integer);
  199. begin
  200. Form1.EditDelay.Text := IntToStr(Value);
  201. Application.ProcessMessages;
  202. end;
  203. { TForm1 }
  204. var
  205. lsuCode: integer;
  206. procedure TForm1.FormCreate(Sender: TObject);
  207. var
  208. line: string;
  209. begin
  210. Infobox.AppTitel := MCSLSU.GetLSUText('infobox', 'ID_APPTITLE', lsuCode);
  211. Infobox.CopyRight := MCSLSU.GetLSUText('infobox', 'ID_COPYRIGHT', lsuCode);
  212. Infobox.Build := MCSGetVersion(Application.ExeName);
  213. Infobox.AppID := 31;
  214. Infobox.AppURL :=
  215. 'http://www.wk-music.de/pages/mcs/microcontroller/tps-sps-emulator.php';
  216. sps := TSPS.Create();
  217. sps.setDelayCallback(@delayCallback);
  218. addHeaderText;
  219. renumberGrid();
  220. cbTPSVersionChange(Sender);
  221. acStop.Enabled := False;
  222. ToolButton18.Align := alRight;
  223. MCSLabel.Align := alRight;
  224. cbAdrActual.Enabled := False;
  225. checkPresets();
  226. tbResetClick(nil);
  227. if Application.ParamCount >= 1 then
  228. begin
  229. line := Application.Params[1];
  230. loadFile(line);
  231. end;
  232. activateSps(False);
  233. Timer1.Enabled := True;
  234. MCSLSU.MakeForm('form1', 'ID_', form1);
  235. end;
  236. procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
  237. var
  238. line: string;
  239. begin
  240. if (SizeOF(FileNames) > 0) then
  241. begin
  242. line := FileNames[0];
  243. loadFile(line);
  244. end;
  245. end;
  246. procedure TForm1.MCSLabelClick(Sender: TObject);
  247. begin
  248. ShExec2(self.Handle, InfoBox.AppURL);
  249. end;
  250. procedure TForm1.mnSaveClick(Sender: TObject);
  251. begin
  252. Statusbar1.SimpleText := Sender.ClassName;
  253. end;
  254. procedure TForm1.Shape1Paint(Sender: TObject);
  255. var
  256. radius: integer;
  257. x, y: integer;
  258. begin
  259. radius := round(Shape1.Width / 2);
  260. Shape1.Canvas.Brush.Color := clBlack;
  261. Shape1.canvas.MoveTo(radius, radius);
  262. x := radius - round(radius * cos(degtorad(sps.getServo1())));
  263. y := radius - round(radius * sin(degtorad(sps.getServo1())));
  264. Shape1.Canvas.LineTo(x, y);
  265. end;
  266. procedure TForm1.Shape2Paint(Sender: TObject);
  267. var
  268. radius: integer;
  269. x, y: integer;
  270. begin
  271. radius := round(Shape1.Width / 2);
  272. Shape2.Canvas.Brush.Color := clBlack;
  273. Shape2.canvas.MoveTo(radius, radius);
  274. x := radius - round(radius * cos(degtorad(sps.getServo2())));
  275. y := radius - round(radius * sin(degtorad(sps.getServo2())));
  276. Shape2.Canvas.LineTo(x, y);
  277. end;
  278. procedure TForm1.acExitExecute(Sender: TObject);
  279. begin
  280. Close;
  281. end;
  282. procedure TForm1.acDeleteRowExecute(Sender: TObject);
  283. var
  284. i: integer;
  285. begin
  286. i := StringGrid1.Row;
  287. StringGrid1.DeleteRow(i);
  288. renumberGrid();
  289. end;
  290. procedure TForm1.acFileOpenAccept(Sender: TObject);
  291. var
  292. filename: string;
  293. begin
  294. filename := (Sender as TFileOpen).Dialog.FileName;
  295. loadFile(filename);
  296. end;
  297. procedure TForm1.loadFile(filename: string);
  298. var
  299. i: integer;
  300. f: Text;
  301. line: string;
  302. list: TStringList;
  303. begin
  304. if (checkDirty()) then
  305. begin
  306. if (FileExists(filename)) then
  307. begin
  308. acNew.Execute;
  309. list := TStringList.Create;
  310. i := 1;
  311. AssignFile(f, filename);
  312. Reset(f);
  313. while (not EOF(f)) do
  314. begin
  315. if (i + 1 > StringGrid1.RowCount) then
  316. begin
  317. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  318. end;
  319. readln(f, line);
  320. if (Pos('#', line) = 1) then
  321. begin
  322. line := RightstrPos(line, 2);
  323. if (Pos('TPS:', line) = 1) then
  324. begin
  325. line := RightstrPos(line, 5);
  326. cbTPSVersion.Text := line;
  327. cbTPSVersionChange(nil);
  328. end;
  329. end
  330. else
  331. begin
  332. MCSStrings.DelimSepTextToStringlist(line, '"', ',', list);
  333. if list.Count > 0 then
  334. Stringgrid1.Cells[0, i] := list[0];
  335. if list.Count > 1 then
  336. Stringgrid1.Cells[1, i] := list[1];
  337. if list.Count > 2 then
  338. Stringgrid1.Cells[2, i] := list[2];
  339. if list.Count > 3 then
  340. Stringgrid1.Cells[4, i] := list[3];
  341. list.Clear;
  342. i := i + 1;
  343. end;
  344. end;
  345. CloseFile(f);
  346. list.Free;
  347. activeFile := filename;
  348. renumberGrid();
  349. addHeaderText;
  350. setCaption();
  351. setDirty(False);
  352. end;
  353. end;
  354. end;
  355. procedure TForm1.acFileSaveAsAccept(Sender: TObject);
  356. var
  357. filename: string;
  358. begin
  359. filename := (Sender as TFileSaveAs).Dialog.FileName;
  360. saveFile(filename);
  361. end;
  362. procedure TForm1.saveFile(filename: string);
  363. var
  364. x, i: integer;
  365. f: Text;
  366. line: string;
  367. begin
  368. if (filename = '') then
  369. begin
  370. if SaveDialog1.Execute() then
  371. begin
  372. filename := SaveDialog1.FileName;
  373. end;
  374. end;
  375. if (filename <> '') then
  376. begin
  377. AssignFile(f, filename);
  378. Rewrite(f);
  379. line := '#TPS:' + cbTPSVersion.Text;
  380. Writeln(f, line);
  381. i := StringGrid1.RowCount;
  382. for x := 1 to i - 1 do
  383. begin
  384. if (StringGrid1.Cells[1, x] <> '') then
  385. begin
  386. line := StringGrid1.Cells[0, x] + ',' + StringGrid1.Cells[1, x] + ',' +
  387. StringGrid1.Cells[2, x] + ',"' + StringGrid1.Cells[4, x] + '"';
  388. Writeln(f, line);
  389. end;
  390. end;
  391. CloseFile(f);
  392. setDirty(False);
  393. activeFile := filename;
  394. setCaption();
  395. end;
  396. end;
  397. procedure TForm1.acDebugExecute(Sender: TObject);
  398. begin
  399. if (sps.isActive()) then
  400. begin
  401. acStopExecute(Sender);
  402. end
  403. else
  404. begin
  405. activateSps(True);
  406. acDebug.Enabled := True;
  407. acDebug.ImageIndex := 10;
  408. cbAdrActual.Enabled := True;
  409. acNextStep.Enabled := False;
  410. // sps programmieren
  411. programSps();
  412. // programm starten
  413. Statusbar1.SimpleText := MCSLSU.GetLSUText('statusbar', 'ID_SPS_START', lsuCode);
  414. sps.start();
  415. stopit := False;
  416. Statusbar1.SimpleText := MCSLSU.GetLSUText('statusbar', 'ID_SPS_RUNNING', lsuCode);
  417. while (not stopit) do
  418. begin
  419. nextStep();
  420. if (cbAdrActual.Checked) then
  421. selectAddress(sps.getAddress());
  422. Application.ProcessMessages;
  423. end;
  424. Statusbar1.SimpleText := MCSLSU.GetLSUText('statusbar', 'ID_SPS_STOPPED', lsuCode);
  425. cbAdrActual.Enabled := False;
  426. acNextStep.Enabled := True;
  427. sps.doReset();
  428. end;
  429. end;
  430. procedure TForm1.acHelpAboutExecute(Sender: TObject);
  431. begin
  432. Infobox.Show;
  433. end;
  434. procedure TForm1.acHexFileExecute(Sender: TObject);
  435. var
  436. filename: string;
  437. begin
  438. filename := MCSIO.MCSExtractFileNameExlExt(activeFile) + '.hex';
  439. SaveHexFile.FileName := filename;
  440. if (SaveHexFile.Execute) then
  441. begin
  442. filename := SaveHexFile.FileName;
  443. makeHexFile(filename);
  444. end;
  445. end;
  446. procedure TForm1.acNewExecute(Sender: TObject);
  447. begin
  448. if (checkDirty()) then
  449. begin
  450. StringGrid1.RowCount := 2;
  451. StringGrid1.Clean;
  452. addHeaderText();
  453. renumberGrid();
  454. activeFile := '';
  455. setCaption();
  456. setDirty(False);
  457. end;
  458. end;
  459. procedure TForm1.acNewRowExecute(Sender: TObject);
  460. var
  461. myPos: integer;
  462. i, x: integer;
  463. eot: boolean;
  464. begin
  465. eot := False;
  466. myPos := StringGrid1.Row;
  467. if (myPos = StringGrid1.RowCount - 1) then
  468. eot := True;
  469. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  470. if (not eot) then
  471. begin
  472. for i := StringGrid1.RowCount - 2 downto myPos do
  473. begin
  474. for x := 1 to StringGrid1.ColCount - 1 do
  475. begin
  476. StringGrid1.Cells[x, i + 1] := StringGrid1.Cells[x, i];
  477. end;
  478. end;
  479. for x := 1 to StringGrid1.ColCount - 1 do
  480. begin
  481. StringGrid1.Cells[x, myPos] := '';
  482. end;
  483. end;
  484. renumberGrid();
  485. end;
  486. procedure TForm1.programSps;
  487. var
  488. x, i: integer;
  489. com, Data: byte;
  490. tmp: string;
  491. begin
  492. Statusbar1.SimpleText := MCSLSU.GetLSUText('statusbar', 'ID_SPS_PROGRAMMING', lsuCode);
  493. i := StringGrid1.RowCount;
  494. for x := 1 to i - 1 do
  495. begin
  496. com := 0;
  497. Data := 0;
  498. tmp := StringGrid1.Cells[1, x];
  499. if (tmp <> '') then
  500. begin
  501. com := HexToInt(tmp);
  502. tmp := StringGrid1.Cells[2, x];
  503. if (tmp <> '') then
  504. Data := HexToInt(tmp);
  505. Data := com * 16 + Data;
  506. end;
  507. sps.writeEEProm(x - 1, Data);
  508. end;
  509. // endekennzeichnung schreiben
  510. sps.writeEEProm(i, $ff);
  511. end;
  512. procedure TForm1.acNextStepExecute(Sender: TObject);
  513. begin
  514. nextStep();
  515. selectAddress(sps.getAddress());
  516. end;
  517. procedure TForm1.acPresetLoadAccept(Sender: TObject);
  518. var
  519. filename: string;
  520. begin
  521. filename := (Sender as TFileOpen).Dialog.FileName;
  522. loadPreset(filename);
  523. end;
  524. procedure TForm1.acPresetSaveAccept(Sender: TObject);
  525. var
  526. filename: string;
  527. begin
  528. filename := (Sender as TFileSaveAs).Dialog.FileName;
  529. savePreset(filename);
  530. end;
  531. procedure TForm1.nextStep;
  532. begin
  533. if (not sps.isActive()) then
  534. begin
  535. activateSps(True);
  536. programSps;
  537. sps.start();
  538. acStop.Enabled := True;
  539. acDebug.Enabled := False;
  540. end
  541. else
  542. begin
  543. acNextStep.Enabled := False;
  544. acStop.Enabled := False;
  545. inputSps();
  546. sps.nextStep();
  547. outputSps();
  548. acNextStep.Enabled := True;
  549. acStop.Enabled := True;
  550. end;
  551. end;
  552. procedure TForm1.acShowHexFileExecute(Sender: TObject);
  553. var
  554. list: TStringList;
  555. i, x: integer;
  556. line, tmp: string;
  557. Value: byte;
  558. begin
  559. Form2 := TForm2.Create(self);
  560. list := TStringList.Create();
  561. line := MCSLSU.GetLSUText('hexfile', 'ID_START_LINE', lsuCode);
  562. list.add(line);
  563. i := StringGrid1.RowCount;
  564. for x := 1 to i - 1 do
  565. begin
  566. if (StringGrid1.Cells[1, x] <> '') then
  567. begin
  568. tmp := '';
  569. if (StringGrid1.Cells[1, x] = '') then
  570. begin
  571. tmp := ' ';
  572. end
  573. else
  574. begin
  575. tmp := StringGrid1.Cells[1, x];
  576. end;
  577. if (StringGrid1.Cells[2, x] = '') then
  578. begin
  579. tmp := tmp + ' ';
  580. end
  581. else
  582. begin
  583. tmp := tmp + StringGrid1.Cells[2, x];
  584. end;
  585. line := StringGrid1.Cells[0, x] + ': ' + tmp + ' ';
  586. Value := HexToInt(StringGrid1.Cells[1, x]);
  587. tmp := '';
  588. if (Value and 8) > 0 then
  589. tmp := tmp + 'X'
  590. else
  591. tmp := tmp + '0';
  592. if (Value and 4) > 0 then
  593. tmp := tmp + 'X'
  594. else
  595. tmp := tmp + '0';
  596. if (Value and 2) > 0 then
  597. tmp := tmp + 'X'
  598. else
  599. tmp := tmp + '0';
  600. if (Value and 1) > 0 then
  601. tmp := tmp + 'X'
  602. else
  603. tmp := tmp + '0';
  604. line := line + tmp + ' ';
  605. Value := HexToInt(StringGrid1.Cells[2, x]);
  606. tmp := '';
  607. if (Value and 8) > 0 then
  608. tmp := tmp + 'X'
  609. else
  610. tmp := tmp + '0';
  611. if (Value and 4) > 0 then
  612. tmp := tmp + 'X'
  613. else
  614. tmp := tmp + '0';
  615. if (Value and 2) > 0 then
  616. tmp := tmp + 'X'
  617. else
  618. tmp := tmp + '0';
  619. if (Value and 1) > 0 then
  620. tmp := tmp + 'X'
  621. else
  622. tmp := tmp + '0';
  623. line := line + tmp;
  624. line := line + ' ' + StringGrid1.Cells[3, x] + ' ,"' + StringGrid1.Cells[4, x] + '"';
  625. list.add(line);
  626. end;
  627. end;
  628. Form2.addHexFile(list);
  629. Form2.ShowModal;
  630. list.Free;
  631. end;
  632. procedure TForm1.acStopExecute(Sender: TObject);
  633. begin
  634. if (sps.isActive()) then
  635. begin
  636. stopit := True;
  637. sps.break();
  638. acDebug.ImageIndex := 18;
  639. repeat
  640. Application.ProcessMessages;
  641. until (not sps.isDelayActive());
  642. sps.doReset();
  643. acStop.Enabled := False;
  644. acDebug.Enabled := True;
  645. outputSps();
  646. selectAddress(0);
  647. activateSps(False);
  648. end;
  649. end;
  650. procedure TForm1.acThisStepExecute(Sender: TObject);
  651. var
  652. Data, com: byte;
  653. tmp: string;
  654. begin
  655. inputSps();
  656. try
  657. tmp := StringGrid1.Cells[1, StringGrid1.Row];
  658. if (tmp <> '') then
  659. begin
  660. com := HexToInt(tmp);
  661. tmp := StringGrid1.Cells[2, StringGrid1.Row];
  662. if (tmp <> '') then
  663. Data := HexToInt(tmp);
  664. Data := com * 16 + Data;
  665. end;
  666. sps.doSingleCommand(Data);
  667. except
  668. end;
  669. outputSps();
  670. end;
  671. procedure TForm1.acFileSaveExecute(Sender: TObject);
  672. begin
  673. saveFile(activeFile);
  674. end;
  675. procedure TForm1.acUploadExecute(Sender: TObject);
  676. begin
  677. uploadFile();
  678. end;
  679. procedure TForm1.uploadFile;
  680. var
  681. line: string;
  682. comServices: TStringList;
  683. comService: string;
  684. return: integer;
  685. hexFile: string;
  686. hexFormat: TIntelHexFormat;
  687. prgMem: array of byte;
  688. i, x: integer;
  689. com, Data: byte;
  690. tmp: string;
  691. arduinoPath: string;
  692. cmd, config, mcu: string;
  693. KeyName, StringValue: string;
  694. Res: WideString;
  695. begin
  696. line := GetSerialPortNames;
  697. // if (line <> '') then
  698. begin
  699. comServices := TStringList.Create;
  700. MCSStrings.DelimTextToStringlist(line, ',', comServices);
  701. return := mrOk;
  702. line := XMLPropStorage1.ReadString('ComPort', comServices[0]);
  703. frmSelectCom := TfrmSelectCom.Create(self);
  704. frmSelectCom.cbServices.Items.AddStrings(comServices);
  705. frmSelectCom.cbServices.Text := line;
  706. line := XMLPropStorage1.ReadString('ArduinoBin', '');
  707. if (line = '') then
  708. begin
  709. KeyName := 'SOFTWARE\WOW6432Node\Arduino';
  710. StringValue := 'Install_Dir';
  711. Res := RegistryReadString(HKEY_LOCAL_MACHINE, WideString(KeyName), WideString(StringValue));
  712. if Res <> '' then
  713. begin
  714. line := string(Res);
  715. end;
  716. end;
  717. frmSelectCom.deArduino.Text := line;
  718. return := frmSelectCom.ShowModal;
  719. comService := frmSelectCom.cbServices.Text;
  720. XMLPropStorage1.WriteString('ComPort', comService);
  721. line := frmSelectCom.deArduino.Text;
  722. arduinoPath := MCSIO.GetNormPath(line);
  723. XMLPropStorage1.WriteString('ArduinoBin', line);
  724. comServices.Free;
  725. if (return = mrOk) then
  726. begin
  727. hexFile := MCSIO.CreateUniqueFile(MCSIO.GetTempDir, 'TPS', '.hex');
  728. makeHexFile(hexFile);
  729. cmd := arduinoPath + 'hardware\tools\avr\bin\avrdude';
  730. XMLPropStorage1.WriteString('avrdude', cmd);
  731. config := arduinoPath + 'hardware\tools\avr\etc\avrdude.conf';
  732. XMLPropStorage1.WriteString('avrdudeconf', config);
  733. if (cbTPSVersion.ItemIndex = 3) then
  734. begin
  735. mcu := 'atmega328p';
  736. end
  737. else if (cbTPSVersion.ItemIndex = 2) then
  738. begin
  739. mcu := 'attiny84';
  740. end;
  741. XMLPropStorage1.WriteString('arduinomcu', mcu);
  742. line :=
  743. '-C%AVRCONF% -v -v -v -p%MCU% -carduino -P\\.\%COM% -b57600 -D -Ueeprom:w:%FILE%:i';
  744. line := Replace2('%AVRCONF%', config, line);
  745. line := Replace2('%MCU%', mcu, line);
  746. line := Replace2('%COM%', comService, line);
  747. line := Replace2('%FILE%', hexFile, line);
  748. ExecuteProcess(cmd, line);
  749. DeleteFile(hexFile);
  750. end;
  751. end;
  752. { else
  753. begin
  754. Application.MessageBox('Kein Comport vorhanden. EVt. Arduino nicht angeschlossen?',
  755. 'Kein Comport',
  756. MB_OK + MB_ICONEXCLAMATION);
  757. end;
  758. }
  759. end;
  760. procedure TForm1.setDirty(Value: boolean);
  761. begin
  762. if (dirty <> Value) then
  763. begin
  764. dirty := Value;
  765. if (dirty) then
  766. begin
  767. if (Pos('*', Caption) = 0) then
  768. begin
  769. Caption := Caption + '*';
  770. end;
  771. end
  772. else
  773. begin
  774. if (Pos('*', Caption) > 0) then
  775. begin
  776. Caption := Leftstr(Caption, Pos('*', Caption) - 1);
  777. end;
  778. end;
  779. end;
  780. end;
  781. function TForm1.checkDirty: boolean;
  782. var
  783. i: integer;
  784. begin
  785. if (dirty) then
  786. begin
  787. i := MCSLSU.LSUAutoMsgBox('Messages', 'SAVE_CHANGES', MB_ICONQUESTION or MB_YESNOCANCEL);
  788. if (i = mrYes) then
  789. begin
  790. saveFile(activeFile);
  791. Result := True;
  792. end
  793. else if (i = mrNo) then
  794. begin
  795. setDirty(False);
  796. Result := True;
  797. end
  798. else
  799. begin
  800. Result := False;
  801. end;
  802. end
  803. else
  804. begin
  805. Result := True;
  806. end;
  807. end;
  808. procedure TForm1.checkPresets;
  809. begin
  810. if XMLPropStorage1.ReadBoolean('preset_1.set', False) then
  811. tbPreset1.Caption := '1*'
  812. else
  813. tbPreset1.Caption := '1';
  814. if XMLPropStorage1.ReadBoolean('preset_2.set', False) then
  815. tbPreset2.Caption := '2*'
  816. else
  817. tbPreset2.Caption := '2';
  818. if XMLPropStorage1.ReadBoolean('preset_3.set', False) then
  819. tbPreset3.Caption := '3*'
  820. else
  821. tbPreset3.Caption := '3';
  822. if XMLPropStorage1.ReadBoolean('preset_4.set', False) then
  823. tbPreset4.Caption := '4*'
  824. else
  825. tbPreset4.Caption := '4';
  826. if XMLPropStorage1.ReadBoolean('preset_5.set', False) then
  827. tbPreset5.Caption := '5*'
  828. else
  829. tbPreset5.Caption := '5';
  830. if XMLPropStorage1.ReadBoolean('preset_6.set', False) then
  831. tbPreset6.Caption := '6*'
  832. else
  833. tbPreset6.Caption := '6';
  834. if XMLPropStorage1.ReadBoolean('preset_7.set', False) then
  835. tbPreset7.Caption := '7*'
  836. else
  837. tbPreset7.Caption := '7';
  838. if XMLPropStorage1.ReadBoolean('preset_8.set', False) then
  839. tbPreset7.Caption := '8*'
  840. else
  841. tbPreset7.Caption := '8';
  842. end;
  843. procedure TForm1.makeHexFile(fileName: string);
  844. var
  845. i, x: integer;
  846. tmp: string;
  847. hexFormat: TIntelHexFormat;
  848. prgMem: array of byte;
  849. com, Data: byte;
  850. begin
  851. i := StringGrid1.RowCount;
  852. SetLength(prgMem, i);
  853. for x := 1 to i - 1 do
  854. begin
  855. com := 0;
  856. Data := 0;
  857. tmp := StringGrid1.Cells[1, x];
  858. if (tmp <> '') then
  859. begin
  860. com := HexToInt(tmp);
  861. tmp := StringGrid1.Cells[2, x];
  862. if (tmp <> '') then
  863. Data := HexToInt(tmp);
  864. Data := com * 16 + Data;
  865. end;
  866. prgMem[x - 1] := Data;
  867. end;
  868. hexFormat := TIntelHexFormat.Create(prgMem, 8);
  869. tmp := hexFormat.Text;
  870. MCSIO.StrToFile(fileName, tmp);
  871. hexFormat.Free;
  872. SetLength(prgMem, 0);
  873. end;
  874. procedure TForm1.setCaption;
  875. begin
  876. if (activeFile = '') then
  877. begin
  878. Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode);
  879. end
  880. else
  881. begin
  882. Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode) + ':' + ExtractFileName(activeFile);
  883. end;
  884. end;
  885. procedure TForm1.addHeaderText;
  886. var
  887. i: integer;
  888. begin
  889. for i := 0 to StringGrid1.Columns.Count - 1 do
  890. begin
  891. ;
  892. StringGrid1.Columns[i].Title.Caption :=
  893. MCSLSU.GetLSUText('form1Captions', StringGrid1.Columns[i].Title.Caption, lsuCode);
  894. end;
  895. StringGrid1.Cells[0, 0] := MCSLSU.GetLSUText('form1Captions', 'ID_GRID_STORAGE', lsuCode);
  896. StringGrid1.Repaint;
  897. end;
  898. procedure TForm1.cbCommandChange(Sender: TObject);
  899. var
  900. x: integer;
  901. begin
  902. cbData.Items.Clear;
  903. x := cbCommand.ItemIndex;
  904. sps.getDatas(x, cbData.Items);
  905. if StringGrid1.Row > 0 then
  906. begin
  907. StringGrid1.Cells[1, StringGrid1.Row] := IntToHex(x, 1);
  908. end;
  909. end;
  910. procedure TForm1.cbDataChange(Sender: TObject);
  911. var
  912. x: integer;
  913. begin
  914. x := cbData.ItemIndex;
  915. if StringGrid1.Row > 0 then
  916. begin
  917. StringGrid1.Cells[2, StringGrid1.Row] := IntToHex(x, 1);
  918. StringGrid1.Cells[3, StringGrid1.Row] := sps.getCommandText(cbCommand.ItemIndex, x);
  919. end;
  920. end;
  921. procedure TForm1.cbTPSVersionChange(Sender: TObject);
  922. begin
  923. if (cbTPSVersion.ItemIndex = 0) then
  924. begin
  925. // HOLTEC
  926. sps.setTPSVersion(Holtek);
  927. Label2.Visible := True;
  928. ADC2.Visible := True;
  929. PWM2.Visible := False;
  930. Label16.Visible := False;
  931. RC1.Visible := False;
  932. Label17.Visible := False;
  933. RC2.Visible := False;
  934. Servo1.Visible := False;
  935. Servo2.Visible := False;
  936. Shape1.Visible := False;
  937. Shape2.Visible := False;
  938. EditE.Visible := False;
  939. EditF.Visible := False;
  940. acUpload.Enabled := False;
  941. Label5.Visible := False;
  942. btnTone.Visible := False;
  943. end;
  944. if (cbTPSVersion.ItemIndex = 1) then
  945. begin
  946. // ATMega8
  947. sps.setTPSVersion(ATMega8);
  948. Label2.Visible := True;
  949. ADC2.Visible := True;
  950. PWM2.Visible := True;
  951. Label16.Visible := False;
  952. RC1.Visible := False;
  953. Label17.Visible := False;
  954. RC2.Visible := False;
  955. Servo1.Visible := False;
  956. Servo2.Visible := False;
  957. Shape1.Visible := False;
  958. Shape2.Visible := False;
  959. EditE.Visible := False;
  960. EditF.Visible := False;
  961. acUpload.Enabled := False;
  962. Label5.Visible := False;
  963. btnTone.Visible := False;
  964. end;
  965. if ((cbTPSVersion.ItemIndex = 2) or (cbTPSVersion.ItemIndex = 3)) then
  966. begin
  967. if (cbTPSVersion.ItemIndex = 2) then
  968. begin
  969. // ATMega84
  970. sps.setTPSVersion(ATTiny84);
  971. acUpload.Enabled := False;
  972. Label5.Visible := False;
  973. btnTone.Visible := False;
  974. end
  975. else
  976. begin
  977. // Arduino 328
  978. sps.setTPSVersion(Arduino);
  979. acUpload.Enabled := True;
  980. Label5.Visible := True;
  981. btnTone.Visible := True;
  982. end;
  983. Label2.Visible := True;
  984. ADC2.Visible := True;
  985. PWM2.Visible := True;
  986. Label16.Visible := True;
  987. RC1.Visible := True;
  988. Label17.Visible := True;
  989. RC2.Visible := True;
  990. Servo1.Visible := True;
  991. Servo2.Visible := True;
  992. Shape1.Visible := True;
  993. Shape2.Visible := True;
  994. EditE.Visible := True;
  995. EditF.Visible := True;
  996. end;
  997. cbCommand.Items.Clear;
  998. sps.getCommands(cbCommand.Items);
  999. end;
  1000. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  1001. begin
  1002. canClose := checkDirty();
  1003. end;
  1004. procedure TForm1.StringGrid1EditingDone(Sender: TObject);
  1005. var
  1006. Value: string;
  1007. x: integer;
  1008. begin
  1009. // die aktuelle Zeile ist auch die letzte
  1010. if ((StringGrid1.Row + 1) = StringGrid1.RowCount) then
  1011. begin
  1012. // es wurde auch was eingegeben
  1013. Value := StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row];
  1014. Value := trim(Value);
  1015. if (Value <> '') then
  1016. begin
  1017. setDirty(True);
  1018. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  1019. renumberGrid();
  1020. end;
  1021. end
  1022. else
  1023. begin
  1024. x := StringGrid1.Row;
  1025. StringGrid1.Cells[3, x] :=
  1026. sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]), HexToInt(StringGrid1.Cells[2, x]));
  1027. setDirty(True);
  1028. end;
  1029. end;
  1030. procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow: integer);
  1031. begin
  1032. try
  1033. cbCommand.ItemIndex := HexToInt(StringGrid1.Cells[1, aRow]);
  1034. cbCommandChange(Sender);
  1035. cbData.ItemIndex := HexToInt(StringGrid1.Cells[2, aRow]);
  1036. except
  1037. end;
  1038. end;
  1039. procedure TForm1.loadPreset(filename: string);
  1040. var
  1041. x: integer;
  1042. key: string;
  1043. begin
  1044. for x := 1 to 8 do
  1045. begin
  1046. key := 'preset_' + IntToStr(x);
  1047. loadSection(filename, key);
  1048. end;
  1049. checkPresets;
  1050. end;
  1051. procedure TForm1.savePreset(filename: string);
  1052. var
  1053. x: integer;
  1054. key: string;
  1055. begin
  1056. for x := 1 to 8 do
  1057. begin
  1058. key := 'preset_' + IntToStr(x);
  1059. saveSection(filename, key);
  1060. end;
  1061. end;
  1062. procedure TForm1.activateSps(enable: boolean);
  1063. begin
  1064. GBControl.Enabled := enable;
  1065. GBInternal.Enabled := enable;
  1066. GBOutput.Enabled := enable;
  1067. ;
  1068. end;
  1069. procedure TForm1.saveSection(filename: string; key: string);
  1070. begin
  1071. WriteIniBool(key, 'set', XMLPropStorage1.ReadBoolean(key + '.set', False), filename);
  1072. WriteIniBool(key, 'prg', XMLPropStorage1.ReadBoolean(key + '.prg', False), filename);
  1073. WriteIniBool(key, 'sel', XMLPropStorage1.ReadBoolean(key + '.sel', False), filename);
  1074. WriteIniBool(key, 'input1', XMLPropStorage1.ReadBoolean(key + '.input1', False), filename);
  1075. WriteIniBool(key, 'input2', XMLPropStorage1.ReadBoolean(key + '.input2', False), filename);
  1076. WriteIniBool(key, 'input3', XMLPropStorage1.ReadBoolean(key + '.input3', False), filename);
  1077. WriteIniBool(key, 'input4', XMLPropStorage1.ReadBoolean(key + '.input4', False), filename);
  1078. WriteIniInteger(key, 'adc1', XMLPropStorage1.ReadInteger(key + '.adc1', 0), filename);
  1079. WriteIniInteger(key, 'adc2', XMLPropStorage1.ReadInteger(key + '.adc2', 0), filename);
  1080. WriteIniInteger(key, 'rc1', XMLPropStorage1.ReadInteger(key + '.rc1', 0), filename);
  1081. WriteIniInteger(key, 'rc2', XMLPropStorage1.ReadInteger(key + '.rc2', 0), filename);
  1082. end;
  1083. procedure TForm1.loadSection(filename: string; key: string);
  1084. begin
  1085. XMLPropStorage1.WriteBoolean(key + '.set', ReadIniBool(key, 'set', False, filename));
  1086. XMLPropStorage1.WriteBoolean(key + '.prg', ReadIniBool(key, 'prg', False, filename));
  1087. XMLPropStorage1.WriteBoolean(key + '.sel', ReadIniBool(key, 'sel', False, filename));
  1088. XMLPropStorage1.WriteBoolean(key + '.input1', ReadIniBool(key, 'input1', False, filename));
  1089. XMLPropStorage1.WriteBoolean(key + '.input2', ReadIniBool(key, 'input2', False, filename));
  1090. XMLPropStorage1.WriteBoolean(key + '.input3', ReadIniBool(key, 'input3', False, filename));
  1091. XMLPropStorage1.WriteBoolean(key + '.input4', ReadIniBool(key, 'input4', False, filename));
  1092. XMLPropStorage1.WriteInteger(key + '.adc1', ReadIniInteger(key, 'adc1', 0, filename));
  1093. XMLPropStorage1.WriteInteger(key + '.adc2', ReadIniInteger(key, 'adc2', 0, filename));
  1094. XMLPropStorage1.WriteInteger(key + '.rc1', ReadIniInteger(key, 'rc1', 0, filename));
  1095. XMLPropStorage1.WriteInteger(key + '.rc2', ReadIniInteger(key, 'rc2', 0, filename));
  1096. end;
  1097. procedure TForm1.tbPreset1Click(Sender: TObject);
  1098. var
  1099. key: string;
  1100. begin
  1101. if Sender = tbPreset1 then
  1102. key := 'preset_1'
  1103. else
  1104. if Sender = tbPreset2 then
  1105. key := 'preset_2'
  1106. else
  1107. if Sender = tbPreset3 then
  1108. key := 'preset_3'
  1109. else
  1110. if Sender = tbPreset4 then
  1111. key := 'preset_4'
  1112. else
  1113. if Sender = tbPreset5 then
  1114. key := 'preset_5'
  1115. else
  1116. if Sender = tbPreset6 then
  1117. key := 'preset_6'
  1118. else
  1119. if Sender = tbPreset7 then
  1120. key := 'preset_7'
  1121. else
  1122. if Sender = tbPreset8 then
  1123. key := 'preset_8';
  1124. tbSel.Checked := XMLPropStorage1.ReadBoolean(key + '.prg', tbSel.Checked);
  1125. tbPrg.Checked := XMLPropStorage1.ReadBoolean(key + '.sel', tbPrg.Checked);
  1126. Din1.Checked := XMLPropStorage1.ReadBoolean(key + '.input1', Din1.Checked);
  1127. Din2.Checked := XMLPropStorage1.ReadBoolean(key + '.input2', Din2.Checked);
  1128. Din3.Checked := XMLPropStorage1.ReadBoolean(key + '.input3', Din3.Checked);
  1129. Din4.Checked := XMLPropStorage1.ReadBoolean(key + '.input4', Din4.Checked);
  1130. ADC1.Value := XMLPropStorage1.ReadInteger(key + '.adc1', ADC1.Value);
  1131. ADC2.Value := XMLPropStorage1.ReadInteger(key + '.adc2', ADC2.Value);
  1132. RC1.Value := XMLPropStorage1.ReadInteger(key + '.rc1', RC1.Value);
  1133. RC2.Value := XMLPropStorage1.ReadInteger(key + '.rc2', RC2.Value);
  1134. end;
  1135. procedure TForm1.tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: boolean);
  1136. var
  1137. key: string;
  1138. begin
  1139. if Sender = tbPreset1 then
  1140. key := 'preset_1'
  1141. else
  1142. if Sender = tbPreset2 then
  1143. key := 'preset_2'
  1144. else
  1145. if Sender = tbPreset3 then
  1146. key := 'preset_3'
  1147. else
  1148. if Sender = tbPreset4 then
  1149. key := 'preset_4'
  1150. else
  1151. if Sender = tbPreset5 then
  1152. key := 'preset_5'
  1153. else
  1154. if Sender = tbPreset6 then
  1155. key := 'preset_6'
  1156. else
  1157. if Sender = tbPreset7 then
  1158. key := 'preset_7'
  1159. else
  1160. if Sender = tbPreset8 then
  1161. key := 'preset_8';
  1162. XMLPropStorage1.WriteBoolean(key + '.set', True);
  1163. XMLPropStorage1.WriteBoolean(key + '.prg', tbPrg.Checked);
  1164. XMLPropStorage1.WriteBoolean(key + '.sel', tbSel.Checked);
  1165. XMLPropStorage1.WriteBoolean(key + '.input1', Din1.Checked);
  1166. XMLPropStorage1.WriteBoolean(key + '.input2', Din2.Checked);
  1167. XMLPropStorage1.WriteBoolean(key + '.input3', Din3.Checked);
  1168. XMLPropStorage1.WriteBoolean(key + '.input4', Din4.Checked);
  1169. XMLPropStorage1.WriteInteger(key + '.adc1', ADC1.Value);
  1170. XMLPropStorage1.WriteInteger(key + '.adc2', ADC2.Value);
  1171. XMLPropStorage1.WriteInteger(key + '.rc1', RC1.Value);
  1172. XMLPropStorage1.WriteInteger(key + '.rc2', RC2.Value);
  1173. checkPresets();
  1174. end;
  1175. procedure TForm1.tbResetClick(Sender: TObject);
  1176. begin
  1177. tbPrg.Checked := False;
  1178. tbSel.Checked := False;
  1179. Din1.Checked := False;
  1180. Din2.Checked := False;
  1181. Din3.Checked := False;
  1182. Din4.Checked := False;
  1183. ADC1.Value := 0;
  1184. ADC2.Value := 0;
  1185. RC1.Value := 8;
  1186. RC2.Value := 8;
  1187. end;
  1188. procedure TForm1.Timer1Timer(Sender: TObject);
  1189. var
  1190. jsonString: string;
  1191. Data: TJSONData;
  1192. iNetVersion, version: string;
  1193. thisVersion, iVersion: TVersionRecord;
  1194. begin
  1195. MCSLabel.AutoSize := True;
  1196. Timer1.Enabled := False;
  1197. MCSLabel.Hint := InfoBox.versionHint;
  1198. if (InfoBox.newVersion) then
  1199. begin
  1200. MCSLabel.Font.Color := clred;
  1201. MCSLabel.Hint := InfoBox.versionHint + chr($0a) + chr($0d) + MCSLSU.GetLSUText(
  1202. 'form1Captions', 'ID_CLICK_HERE', lsuCode);
  1203. end;
  1204. MCSLabel.Caption := InfoBox.versionText;
  1205. end;
  1206. procedure TForm1.renumberGrid;
  1207. var
  1208. x, i: integer;
  1209. begin
  1210. i := StringGrid1.RowCount;
  1211. for x := 1 to i - 1 do
  1212. begin
  1213. StringGrid1.Cells[0, x] := '0x' + inttohex(x - 1, 2);
  1214. if (StringGrid1.Cells[1, x] = '') then
  1215. StringGrid1.Cells[1, x] := '0';
  1216. if (StringGrid1.Cells[2, x] = '') then
  1217. StringGrid1.Cells[2, x] := '0';
  1218. StringGrid1.Cells[3, x] :=
  1219. sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]), HexToInt(StringGrid1.Cells[2, x]));
  1220. end;
  1221. end;
  1222. procedure TForm1.selectAddress(addr: byte);
  1223. begin
  1224. StringGrid1.Row := addr + 1;
  1225. Application.ProcessMessages;
  1226. end;
  1227. procedure TForm1.inputSps;
  1228. begin
  1229. sps.setDin1(Din1.Checked);
  1230. sps.setDin2(Din2.Checked);
  1231. sps.setDin3(Din3.Checked);
  1232. sps.setDin4(Din4.Checked);
  1233. sps.setADC1(ADC1.Value);
  1234. sps.setADC2(ADC2.Value);
  1235. sps.setRC1(RC1.Value);
  1236. sps.setRC2(RC2.Value);
  1237. sps.setSPrg(tbPrg.Checked);
  1238. sps.setSSel(tbSel.Checked);
  1239. end;
  1240. procedure TForm1.outputSps;
  1241. var
  1242. List: TStrings;
  1243. i: integer;
  1244. begin
  1245. if sps.isDout1() then
  1246. ShapeOut1.Brush.Color := clRed
  1247. else
  1248. ShapeOut1.Brush.Color := clWhite;
  1249. if sps.isDout2() then
  1250. ShapeOut2.Brush.Color := clRed
  1251. else
  1252. ShapeOut2.Brush.Color := clWhite;
  1253. if sps.isDout3() then
  1254. ShapeOut3.Brush.Color := clRed
  1255. else
  1256. ShapeOut3.Brush.Color := clWhite;
  1257. if sps.isDout4() then
  1258. ShapeOut4.Brush.Color := clRed
  1259. else
  1260. ShapeOut4.Brush.Color := clWhite;
  1261. PWM1.Text := IntToStr(sps.getPWM1());
  1262. PWM2.Text := IntToStr(sps.getPWM2());
  1263. Servo1.Text := IntToStr(sps.getServo1());
  1264. Shape1.Repaint;
  1265. Servo2.Text := IntToStr(sps.getServo2());
  1266. Shape2.Repaint;
  1267. EditA.Text := IntToStr(sps.getARegister());
  1268. EditB.Text := IntToStr(sps.getBRegister());
  1269. EditC.Text := IntToStr(sps.getCRegister());
  1270. EditD.Text := IntToStr(sps.getDRegister());
  1271. EditE.Text := IntToStr(sps.getERegister());
  1272. EditF.Text := IntToStr(sps.getFRegister());
  1273. EditAddr.Text := '0x' + IntToHex(sps.getAddress(), 2);
  1274. EditRAdr.Text := '0x' + IntToHex(sps.getRAdr(), 2);
  1275. EditPage.Text := '0x' + IntToHex(sps.getPage(), 2);
  1276. if (sps.getJump() > 0) then
  1277. EditJump.Text := '0x' + IntToHex(sps.getJump(), 2)
  1278. else
  1279. EditJump.Text := '';
  1280. if (sps.getTone() > 0) then
  1281. begin
  1282. ImageList2.GetBitmap(23, btnTone.Glyph);
  1283. btnTone.Caption := IntToStr(sps.getTone());
  1284. end
  1285. else
  1286. begin
  1287. ImageList2.GetBitmap(22, btnTone.Glyph);
  1288. btnTone.Caption := '';
  1289. end;
  1290. List := TStringList.Create;
  1291. try
  1292. sps.getStack(List);
  1293. lbStack.Clear;
  1294. for i := 0 to List.Count - 1 do
  1295. begin
  1296. lbStack.Items.Add(IntToStr(i) + ':' + List[i]);
  1297. end;
  1298. finally
  1299. List.Free;
  1300. end;
  1301. end;
  1302. end.