ugui.pas 37 KB

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