ugui.pas 36 KB

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