ugui.pas 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  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. hexFileSource := TStringList.Create;
  705. for x := 1 to StringGrid1.RowCount - 1 do
  706. begin
  707. if (pos = 0) then
  708. begin
  709. line := line + 'd ';
  710. end;
  711. tmp := StringGrid1.Cells[1, x];
  712. line := line + tmp;
  713. tmp := StringGrid1.Cells[2, x];
  714. line := line + tmp;
  715. Inc(pos);
  716. if (pos = 8) then
  717. begin
  718. hexFileSource.Add(line);
  719. line := '';
  720. pos := 0;
  721. end
  722. else
  723. begin
  724. line := line + ',';
  725. end;
  726. end;
  727. if (pos = 0) then
  728. begin
  729. line := hexFileSource.Strings[hexFileSource.Count - 1];
  730. hexFileSource.Delete(hexFileSource.Count - 1);
  731. pos := 8;
  732. end;
  733. if (pos <= 7) then
  734. begin
  735. for x := pos to 7 do
  736. begin
  737. line := line + '00';
  738. if (x < 7) then
  739. line := line + ',';
  740. end;
  741. end;
  742. line := line + '*';
  743. hexFileSource.Add(line);
  744. MCSIO.StrToFile(hexFile, hexFileSource.Text);
  745. hexFileSource.Free;
  746. Result := hexFile;
  747. end;
  748. procedure TForm1.uploadFile;
  749. var
  750. line: string;
  751. comServices: TStringList;
  752. comService: string;
  753. return: integer;
  754. hexFile: string;
  755. hexFormat: TIntelHexFormat;
  756. prgMem: array of byte;
  757. i, x: integer;
  758. com, Data: byte;
  759. tmp: string;
  760. arduinoPath: string;
  761. cmd, config, mcu: string;
  762. KeyName, StringValue: string;
  763. Res: WideString;
  764. Lines: TStringList;
  765. begin
  766. line := GetSerialPortNames;
  767. // if (line <> '') then
  768. begin
  769. comServices := TStringList.Create;
  770. MCSStrings.DelimTextToStringlist(line, ',', comServices);
  771. return := mrOk;
  772. line := XMLPropStorage1.ReadString('ComPort', comServices[0]);
  773. frmSelectCom := TfrmSelectCom.Create(self);
  774. frmSelectCom.cbServices.Items.AddStrings(comServices);
  775. frmSelectCom.cbServices.Text := line;
  776. return := frmSelectCom.ShowModal;
  777. comService := frmSelectCom.cbServices.Text;
  778. XMLPropStorage1.WriteString('ComPort', comService);
  779. comServices.Free;
  780. if (return = mrOk) then
  781. begin
  782. hexFile := serialUpload;
  783. SdpoSerial1.Device := comService;
  784. SdpoSerial1.Active := True;
  785. Lines := TStringList.Create;
  786. Lines.LoadFromFile(hexFile);
  787. for x := 0 to Lines.Count - 1 do
  788. begin
  789. SdpoSerial1.WriteData(Lines.Strings[x]);
  790. SdpoSerial1.WriteData(CRLF);
  791. end;
  792. SdpoSerial1.Active := False;
  793. DeleteFile(hexFile);
  794. end;
  795. end;
  796. { else
  797. begin
  798. Application.MessageBox('Kein Comport vorhanden. EVt. Arduino nicht angeschlossen?',
  799. 'Kein Comport',
  800. MB_OK + MB_ICONEXCLAMATION);
  801. end;
  802. }
  803. end;
  804. procedure TForm1.setDirty(Value: boolean);
  805. begin
  806. if (dirty <> Value) then
  807. begin
  808. dirty := Value;
  809. if (dirty) then
  810. begin
  811. if (Pos('*', Caption) = 0) then
  812. begin
  813. Caption := Caption + '*';
  814. end;
  815. end
  816. else
  817. begin
  818. if (Pos('*', Caption) > 0) then
  819. begin
  820. Caption := Leftstr(Caption, Pos('*', Caption) - 1);
  821. end;
  822. end;
  823. end;
  824. end;
  825. function TForm1.checkDirty: boolean;
  826. var
  827. i: integer;
  828. begin
  829. if (dirty) then
  830. begin
  831. i := MCSLSU.LSUAutoMsgBox('Messages', 'SAVE_CHANGES', MB_ICONQUESTION or MB_YESNOCANCEL);
  832. if (i = mrYes) then
  833. begin
  834. saveFile(activeFile);
  835. Result := True;
  836. end
  837. else if (i = mrNo) then
  838. begin
  839. setDirty(False);
  840. Result := True;
  841. end
  842. else
  843. begin
  844. Result := False;
  845. end;
  846. end
  847. else
  848. begin
  849. Result := True;
  850. end;
  851. end;
  852. procedure TForm1.checkPresets;
  853. begin
  854. if XMLPropStorage1.ReadBoolean('preset_1.set', False) then
  855. tbPreset1.Caption := '1*'
  856. else
  857. tbPreset1.Caption := '1';
  858. if XMLPropStorage1.ReadBoolean('preset_2.set', False) then
  859. tbPreset2.Caption := '2*'
  860. else
  861. tbPreset2.Caption := '2';
  862. if XMLPropStorage1.ReadBoolean('preset_3.set', False) then
  863. tbPreset3.Caption := '3*'
  864. else
  865. tbPreset3.Caption := '3';
  866. if XMLPropStorage1.ReadBoolean('preset_4.set', False) then
  867. tbPreset4.Caption := '4*'
  868. else
  869. tbPreset4.Caption := '4';
  870. if XMLPropStorage1.ReadBoolean('preset_5.set', False) then
  871. tbPreset5.Caption := '5*'
  872. else
  873. tbPreset5.Caption := '5';
  874. if XMLPropStorage1.ReadBoolean('preset_6.set', False) then
  875. tbPreset6.Caption := '6*'
  876. else
  877. tbPreset6.Caption := '6';
  878. if XMLPropStorage1.ReadBoolean('preset_7.set', False) then
  879. tbPreset7.Caption := '7*'
  880. else
  881. tbPreset7.Caption := '7';
  882. if XMLPropStorage1.ReadBoolean('preset_8.set', False) then
  883. tbPreset7.Caption := '8*'
  884. else
  885. tbPreset7.Caption := '8';
  886. end;
  887. procedure TForm1.makeHexFile(fileName: string);
  888. var
  889. i, x: integer;
  890. tmp: string;
  891. hexFormat: TIntelHexFormat;
  892. prgMem: array of byte;
  893. com, Data: byte;
  894. begin
  895. i := StringGrid1.RowCount;
  896. SetLength(prgMem, i);
  897. for x := 1 to i - 1 do
  898. begin
  899. com := 0;
  900. Data := 0;
  901. tmp := StringGrid1.Cells[1, x];
  902. if (tmp <> '') then
  903. begin
  904. com := HexToInt(tmp);
  905. tmp := StringGrid1.Cells[2, x];
  906. if (tmp <> '') then
  907. Data := HexToInt(tmp);
  908. Data := com * 16 + Data;
  909. end;
  910. prgMem[x - 1] := Data;
  911. end;
  912. hexFormat := TIntelHexFormat.Create(prgMem, 8);
  913. tmp := hexFormat.Text;
  914. MCSIO.StrToFile(fileName, tmp);
  915. hexFormat.Free;
  916. SetLength(prgMem, 0);
  917. end;
  918. procedure TForm1.setCaption;
  919. begin
  920. if (activeFile = '') then
  921. begin
  922. Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode);
  923. end
  924. else
  925. begin
  926. Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode) + ':' + ExtractFileName(activeFile);
  927. end;
  928. end;
  929. procedure TForm1.addHeaderText;
  930. var
  931. i: integer;
  932. begin
  933. for i := 0 to StringGrid1.Columns.Count - 1 do
  934. begin
  935. ;
  936. StringGrid1.Columns[i].Title.Caption :=
  937. MCSLSU.GetLSUText('form1Captions', StringGrid1.Columns[i].Title.Caption, lsuCode);
  938. end;
  939. StringGrid1.Cells[0, 0] := MCSLSU.GetLSUText('form1Captions', 'ID_GRID_STORAGE', lsuCode);
  940. StringGrid1.Repaint;
  941. end;
  942. procedure TForm1.cbCommandChange(Sender: TObject);
  943. var
  944. x: integer;
  945. begin
  946. cbData.Items.Clear;
  947. x := cbCommand.ItemIndex;
  948. sps.getDatas(x, cbData.Items);
  949. if StringGrid1.Row > 0 then
  950. begin
  951. StringGrid1.Cells[1, StringGrid1.Row] := IntToHex(x, 1);
  952. end;
  953. end;
  954. procedure TForm1.cbDataChange(Sender: TObject);
  955. var
  956. x: integer;
  957. begin
  958. x := cbData.ItemIndex;
  959. if StringGrid1.Row > 0 then
  960. begin
  961. StringGrid1.Cells[2, StringGrid1.Row] := IntToHex(x, 1);
  962. StringGrid1.Cells[3, StringGrid1.Row] := sps.getCommandText(cbCommand.ItemIndex, x);
  963. end;
  964. end;
  965. procedure TForm1.cbTPSVersionChange(Sender: TObject);
  966. begin
  967. if (cbTPSVersion.ItemIndex = 0) then
  968. begin
  969. // HOLTEC
  970. sps.setTPSVersion(Holtek);
  971. Label2.Visible := True;
  972. ADC2.Visible := True;
  973. PWM2.Visible := False;
  974. Label16.Visible := False;
  975. RC1.Visible := False;
  976. Label17.Visible := False;
  977. RC2.Visible := False;
  978. Servo1.Visible := False;
  979. Servo2.Visible := False;
  980. Shape1.Visible := False;
  981. Shape2.Visible := False;
  982. EditE.Visible := False;
  983. EditF.Visible := False;
  984. acUpload.Enabled := False;
  985. Label5.Visible := False;
  986. btnTone.Visible := False;
  987. end;
  988. if (cbTPSVersion.ItemIndex = 1) then
  989. begin
  990. // ATMega8
  991. sps.setTPSVersion(ATMega8);
  992. Label2.Visible := True;
  993. ADC2.Visible := True;
  994. PWM2.Visible := True;
  995. Label16.Visible := False;
  996. RC1.Visible := False;
  997. Label17.Visible := False;
  998. RC2.Visible := False;
  999. Servo1.Visible := False;
  1000. Servo2.Visible := False;
  1001. Shape1.Visible := False;
  1002. Shape2.Visible := False;
  1003. EditE.Visible := False;
  1004. EditF.Visible := False;
  1005. acUpload.Enabled := False;
  1006. Label5.Visible := False;
  1007. btnTone.Visible := False;
  1008. end;
  1009. if ((cbTPSVersion.ItemIndex = 2) or (cbTPSVersion.ItemIndex = 3)) then
  1010. begin
  1011. if (cbTPSVersion.ItemIndex = 2) then
  1012. begin
  1013. // ATMega84
  1014. sps.setTPSVersion(ATTiny84);
  1015. acUpload.Enabled := False;
  1016. Label5.Visible := False;
  1017. btnTone.Visible := False;
  1018. end
  1019. else
  1020. begin
  1021. // Arduino 328
  1022. sps.setTPSVersion(Arduino);
  1023. acUpload.Enabled := True;
  1024. Label5.Visible := True;
  1025. btnTone.Visible := True;
  1026. end;
  1027. Label2.Visible := True;
  1028. ADC2.Visible := True;
  1029. PWM2.Visible := True;
  1030. Label16.Visible := True;
  1031. RC1.Visible := True;
  1032. Label17.Visible := True;
  1033. RC2.Visible := True;
  1034. Servo1.Visible := True;
  1035. Servo2.Visible := True;
  1036. Shape1.Visible := True;
  1037. Shape2.Visible := True;
  1038. EditE.Visible := True;
  1039. EditF.Visible := True;
  1040. end;
  1041. cbCommand.Items.Clear;
  1042. sps.getCommands(cbCommand.Items);
  1043. end;
  1044. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  1045. begin
  1046. canClose := checkDirty();
  1047. end;
  1048. procedure TForm1.StringGrid1EditingDone(Sender: TObject);
  1049. var
  1050. Value: string;
  1051. x: integer;
  1052. begin
  1053. // die aktuelle Zeile ist auch die letzte
  1054. if ((StringGrid1.Row + 1) = StringGrid1.RowCount) then
  1055. begin
  1056. // es wurde auch was eingegeben
  1057. Value := StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row];
  1058. Value := trim(Value);
  1059. if (Value <> '') then
  1060. begin
  1061. setDirty(True);
  1062. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  1063. renumberGrid();
  1064. end;
  1065. end
  1066. else
  1067. begin
  1068. x := StringGrid1.Row;
  1069. StringGrid1.Cells[3, x] :=
  1070. sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]), HexToInt(StringGrid1.Cells[2, x]));
  1071. setDirty(True);
  1072. end;
  1073. end;
  1074. procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow: integer);
  1075. begin
  1076. try
  1077. cbCommand.ItemIndex := HexToInt(StringGrid1.Cells[1, aRow]);
  1078. cbCommandChange(Sender);
  1079. cbData.ItemIndex := HexToInt(StringGrid1.Cells[2, aRow]);
  1080. except
  1081. end;
  1082. end;
  1083. procedure TForm1.loadPreset(filename: string);
  1084. var
  1085. x: integer;
  1086. key: string;
  1087. begin
  1088. for x := 1 to 8 do
  1089. begin
  1090. key := 'preset_' + IntToStr(x);
  1091. loadSection(filename, key);
  1092. end;
  1093. checkPresets;
  1094. end;
  1095. procedure TForm1.savePreset(filename: string);
  1096. var
  1097. x: integer;
  1098. key: string;
  1099. begin
  1100. for x := 1 to 8 do
  1101. begin
  1102. key := 'preset_' + IntToStr(x);
  1103. saveSection(filename, key);
  1104. end;
  1105. end;
  1106. procedure TForm1.activateSps(enable: boolean);
  1107. begin
  1108. GBControl.Enabled := enable;
  1109. GBInternal.Enabled := enable;
  1110. GBOutput.Enabled := enable;
  1111. ;
  1112. end;
  1113. procedure TForm1.saveSection(filename: string; key: string);
  1114. begin
  1115. WriteIniBool(key, 'set', XMLPropStorage1.ReadBoolean(key + '.set', False), filename);
  1116. WriteIniBool(key, 'prg', XMLPropStorage1.ReadBoolean(key + '.prg', False), filename);
  1117. WriteIniBool(key, 'sel', XMLPropStorage1.ReadBoolean(key + '.sel', False), filename);
  1118. WriteIniBool(key, 'input1', XMLPropStorage1.ReadBoolean(key + '.input1', False), filename);
  1119. WriteIniBool(key, 'input2', XMLPropStorage1.ReadBoolean(key + '.input2', False), filename);
  1120. WriteIniBool(key, 'input3', XMLPropStorage1.ReadBoolean(key + '.input3', False), filename);
  1121. WriteIniBool(key, 'input4', XMLPropStorage1.ReadBoolean(key + '.input4', False), filename);
  1122. WriteIniInteger(key, 'adc1', XMLPropStorage1.ReadInteger(key + '.adc1', 0), filename);
  1123. WriteIniInteger(key, 'adc2', XMLPropStorage1.ReadInteger(key + '.adc2', 0), filename);
  1124. WriteIniInteger(key, 'rc1', XMLPropStorage1.ReadInteger(key + '.rc1', 0), filename);
  1125. WriteIniInteger(key, 'rc2', XMLPropStorage1.ReadInteger(key + '.rc2', 0), filename);
  1126. end;
  1127. procedure TForm1.loadSection(filename: string; key: string);
  1128. begin
  1129. XMLPropStorage1.WriteBoolean(key + '.set', ReadIniBool(key, 'set', False, filename));
  1130. XMLPropStorage1.WriteBoolean(key + '.prg', ReadIniBool(key, 'prg', False, filename));
  1131. XMLPropStorage1.WriteBoolean(key + '.sel', ReadIniBool(key, 'sel', False, filename));
  1132. XMLPropStorage1.WriteBoolean(key + '.input1', ReadIniBool(key, 'input1', False, filename));
  1133. XMLPropStorage1.WriteBoolean(key + '.input2', ReadIniBool(key, 'input2', False, filename));
  1134. XMLPropStorage1.WriteBoolean(key + '.input3', ReadIniBool(key, 'input3', False, filename));
  1135. XMLPropStorage1.WriteBoolean(key + '.input4', ReadIniBool(key, 'input4', False, filename));
  1136. XMLPropStorage1.WriteInteger(key + '.adc1', ReadIniInteger(key, 'adc1', 0, filename));
  1137. XMLPropStorage1.WriteInteger(key + '.adc2', ReadIniInteger(key, 'adc2', 0, filename));
  1138. XMLPropStorage1.WriteInteger(key + '.rc1', ReadIniInteger(key, 'rc1', 0, filename));
  1139. XMLPropStorage1.WriteInteger(key + '.rc2', ReadIniInteger(key, 'rc2', 0, filename));
  1140. end;
  1141. procedure TForm1.tbPreset1Click(Sender: TObject);
  1142. var
  1143. key: string;
  1144. begin
  1145. if Sender = tbPreset1 then
  1146. key := 'preset_1'
  1147. else
  1148. if Sender = tbPreset2 then
  1149. key := 'preset_2'
  1150. else
  1151. if Sender = tbPreset3 then
  1152. key := 'preset_3'
  1153. else
  1154. if Sender = tbPreset4 then
  1155. key := 'preset_4'
  1156. else
  1157. if Sender = tbPreset5 then
  1158. key := 'preset_5'
  1159. else
  1160. if Sender = tbPreset6 then
  1161. key := 'preset_6'
  1162. else
  1163. if Sender = tbPreset7 then
  1164. key := 'preset_7'
  1165. else
  1166. if Sender = tbPreset8 then
  1167. key := 'preset_8';
  1168. tbSel.Checked := XMLPropStorage1.ReadBoolean(key + '.prg', tbSel.Checked);
  1169. tbPrg.Checked := XMLPropStorage1.ReadBoolean(key + '.sel', tbPrg.Checked);
  1170. Din1.Checked := XMLPropStorage1.ReadBoolean(key + '.input1', Din1.Checked);
  1171. Din2.Checked := XMLPropStorage1.ReadBoolean(key + '.input2', Din2.Checked);
  1172. Din3.Checked := XMLPropStorage1.ReadBoolean(key + '.input3', Din3.Checked);
  1173. Din4.Checked := XMLPropStorage1.ReadBoolean(key + '.input4', Din4.Checked);
  1174. ADC1.Value := XMLPropStorage1.ReadInteger(key + '.adc1', ADC1.Value);
  1175. ADC2.Value := XMLPropStorage1.ReadInteger(key + '.adc2', ADC2.Value);
  1176. RC1.Value := XMLPropStorage1.ReadInteger(key + '.rc1', RC1.Value);
  1177. RC2.Value := XMLPropStorage1.ReadInteger(key + '.rc2', RC2.Value);
  1178. end;
  1179. procedure TForm1.tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: boolean);
  1180. var
  1181. key: string;
  1182. begin
  1183. if Sender = tbPreset1 then
  1184. key := 'preset_1'
  1185. else
  1186. if Sender = tbPreset2 then
  1187. key := 'preset_2'
  1188. else
  1189. if Sender = tbPreset3 then
  1190. key := 'preset_3'
  1191. else
  1192. if Sender = tbPreset4 then
  1193. key := 'preset_4'
  1194. else
  1195. if Sender = tbPreset5 then
  1196. key := 'preset_5'
  1197. else
  1198. if Sender = tbPreset6 then
  1199. key := 'preset_6'
  1200. else
  1201. if Sender = tbPreset7 then
  1202. key := 'preset_7'
  1203. else
  1204. if Sender = tbPreset8 then
  1205. key := 'preset_8';
  1206. XMLPropStorage1.WriteBoolean(key + '.set', True);
  1207. XMLPropStorage1.WriteBoolean(key + '.prg', tbPrg.Checked);
  1208. XMLPropStorage1.WriteBoolean(key + '.sel', tbSel.Checked);
  1209. XMLPropStorage1.WriteBoolean(key + '.input1', Din1.Checked);
  1210. XMLPropStorage1.WriteBoolean(key + '.input2', Din2.Checked);
  1211. XMLPropStorage1.WriteBoolean(key + '.input3', Din3.Checked);
  1212. XMLPropStorage1.WriteBoolean(key + '.input4', Din4.Checked);
  1213. XMLPropStorage1.WriteInteger(key + '.adc1', ADC1.Value);
  1214. XMLPropStorage1.WriteInteger(key + '.adc2', ADC2.Value);
  1215. XMLPropStorage1.WriteInteger(key + '.rc1', RC1.Value);
  1216. XMLPropStorage1.WriteInteger(key + '.rc2', RC2.Value);
  1217. checkPresets();
  1218. end;
  1219. procedure TForm1.tbResetClick(Sender: TObject);
  1220. begin
  1221. tbPrg.Checked := False;
  1222. tbSel.Checked := False;
  1223. Din1.Checked := False;
  1224. Din2.Checked := False;
  1225. Din3.Checked := False;
  1226. Din4.Checked := False;
  1227. ADC1.Value := 0;
  1228. ADC2.Value := 0;
  1229. RC1.Value := 8;
  1230. RC2.Value := 8;
  1231. end;
  1232. procedure TForm1.Timer1Timer(Sender: TObject);
  1233. var
  1234. jsonString: string;
  1235. Data: TJSONData;
  1236. iNetVersion, version: string;
  1237. thisVersion, iVersion: TVersionRecord;
  1238. begin
  1239. MCSLabel.AutoSize := True;
  1240. Timer1.Enabled := False;
  1241. MCSLabel.Hint := InfoBox.versionHint;
  1242. if (InfoBox.newVersion) then
  1243. begin
  1244. MCSLabel.Font.Color := clred;
  1245. MCSLabel.Hint := InfoBox.versionHint + chr($0a) + chr($0d) + MCSLSU.GetLSUText(
  1246. 'form1Captions', 'ID_CLICK_HERE', lsuCode);
  1247. end;
  1248. MCSLabel.Caption := InfoBox.versionText;
  1249. end;
  1250. procedure TForm1.renumberGrid;
  1251. var
  1252. x, i: integer;
  1253. begin
  1254. i := StringGrid1.RowCount;
  1255. for x := 1 to i - 1 do
  1256. begin
  1257. StringGrid1.Cells[0, x] := '0x' + inttohex(x - 1, 2);
  1258. if (StringGrid1.Cells[1, x] = '') then
  1259. StringGrid1.Cells[1, x] := '0';
  1260. if (StringGrid1.Cells[2, x] = '') then
  1261. StringGrid1.Cells[2, x] := '0';
  1262. StringGrid1.Cells[3, x] :=
  1263. sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]), HexToInt(StringGrid1.Cells[2, x]));
  1264. end;
  1265. end;
  1266. procedure TForm1.selectAddress(addr: byte);
  1267. begin
  1268. StringGrid1.Row := addr + 1;
  1269. Application.ProcessMessages;
  1270. end;
  1271. procedure TForm1.inputSps;
  1272. begin
  1273. sps.setDin1(Din1.Checked);
  1274. sps.setDin2(Din2.Checked);
  1275. sps.setDin3(Din3.Checked);
  1276. sps.setDin4(Din4.Checked);
  1277. sps.setADC1(ADC1.Value);
  1278. sps.setADC2(ADC2.Value);
  1279. sps.setRC1(RC1.Value);
  1280. sps.setRC2(RC2.Value);
  1281. sps.setSPrg(tbPrg.Checked);
  1282. sps.setSSel(tbSel.Checked);
  1283. end;
  1284. procedure TForm1.outputSps;
  1285. var
  1286. List: TStrings;
  1287. i: integer;
  1288. begin
  1289. if sps.isDout1() then
  1290. ShapeOut1.Brush.Color := clRed
  1291. else
  1292. ShapeOut1.Brush.Color := clWhite;
  1293. if sps.isDout2() then
  1294. ShapeOut2.Brush.Color := clRed
  1295. else
  1296. ShapeOut2.Brush.Color := clWhite;
  1297. if sps.isDout3() then
  1298. ShapeOut3.Brush.Color := clRed
  1299. else
  1300. ShapeOut3.Brush.Color := clWhite;
  1301. if sps.isDout4() then
  1302. ShapeOut4.Brush.Color := clRed
  1303. else
  1304. ShapeOut4.Brush.Color := clWhite;
  1305. PWM1.Text := IntToStr(sps.getPWM1());
  1306. PWM2.Text := IntToStr(sps.getPWM2());
  1307. Servo1.Text := IntToStr(sps.getServo1());
  1308. Shape1.Repaint;
  1309. Servo2.Text := IntToStr(sps.getServo2());
  1310. Shape2.Repaint;
  1311. EditA.Text := IntToStr(sps.getARegister());
  1312. EditB.Text := IntToStr(sps.getBRegister());
  1313. EditC.Text := IntToStr(sps.getCRegister());
  1314. EditD.Text := IntToStr(sps.getDRegister());
  1315. EditE.Text := IntToStr(sps.getERegister());
  1316. EditF.Text := IntToStr(sps.getFRegister());
  1317. EditAddr.Text := '0x' + IntToHex(sps.getAddress(), 2);
  1318. EditRAdr.Text := '0x' + IntToHex(sps.getRAdr(), 2);
  1319. EditPage.Text := '0x' + IntToHex(sps.getPage(), 2);
  1320. if (sps.getJump() > 0) then
  1321. EditJump.Text := '0x' + IntToHex(sps.getJump(), 2)
  1322. else
  1323. EditJump.Text := '';
  1324. if (sps.getTone() > 0) then
  1325. begin
  1326. ImageList2.GetBitmap(23, btnTone.Glyph);
  1327. btnTone.Caption := IntToStr(sps.getTone());
  1328. end
  1329. else
  1330. begin
  1331. ImageList2.GetBitmap(22, btnTone.Glyph);
  1332. btnTone.Caption := '';
  1333. end;
  1334. List := TStringList.Create;
  1335. try
  1336. sps.getStack(List);
  1337. lbStack.Clear;
  1338. for i := 0 to List.Count - 1 do
  1339. begin
  1340. lbStack.Items.Add(IntToStr(i) + ':' + List[i]);
  1341. end;
  1342. finally
  1343. List.Free;
  1344. end;
  1345. end;
  1346. end.