ugui.pas 38 KB

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