ugui.pas 37 KB

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