ugui.pas 37 KB

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