ugui.pas 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  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,
  9. fpjson, jsonparser, Midi;
  10. type
  11. { TForm1 }
  12. TForm1 = class(TForm)
  13. acExit: TAction;
  14. acDebug: TAction;
  15. acNextStep: TAction;
  16. acStop: TAction;
  17. acThisStep: TAction;
  18. acShowHexFile: TAction;
  19. acNew: TAction;
  20. acNewRow: TAction;
  21. acDeleteRow: TAction;
  22. acFileSave: TAction;
  23. acHelpAbout: TAction;
  24. acHexFile: TAction;
  25. acNextInsert: TAction;
  26. acSaveAs: TAction;
  27. acUpload: TAction;
  28. ActionList1: TActionList;
  29. acFileOpen: TFileOpen;
  30. btnTone: TBitBtn;
  31. cbTPSVersion: TComboBox;
  32. cbAdrActual: TCheckBox;
  33. EditDelay: TLabeledEdit;
  34. EditJump: TLabeledEdit;
  35. EditPage: TLabeledEdit;
  36. EditRAdr: TLabeledEdit;
  37. acPresetLoad: TFileOpen;
  38. acPresetSave: TFileSaveAs;
  39. GBControl: TGroupBox;
  40. ImageList2: TImageList;
  41. ImageList3: TImageList;
  42. Label3: TLabel;
  43. Label4: TLabel;
  44. Label5: TLabel;
  45. lbStack: TListBox;
  46. MCSLabel: TLabel;
  47. MenuItem1: TMenuItem;
  48. pmExamples: TPopupMenu;
  49. RC1: TSpinEdit;
  50. RC2: TSpinEdit;
  51. cbCommand: TComboBox;
  52. cbData: TComboBox;
  53. Din1: TCheckBox;
  54. Din2: TCheckBox;
  55. Din3: TCheckBox;
  56. Din4: TCheckBox;
  57. GBOutput: TGroupBox;
  58. GBInput: TGroupBox;
  59. GBInternal: TGroupBox;
  60. Label1: TLabel;
  61. Label10: TLabel;
  62. Label11: TLabel;
  63. Label12: TLabel;
  64. Label13: TLabel;
  65. Label14: TLabel;
  66. Label15: TLabel;
  67. Label16: TLabel;
  68. Label17: TLabel;
  69. Label2: TLabel;
  70. Panel2: TPanel;
  71. Panel3: TPanel;
  72. PWM1: TLabeledEdit;
  73. PWM2: TLabeledEdit;
  74. Panel1: TPanel;
  75. ADC1: TSpinEdit;
  76. ADC2: TSpinEdit;
  77. SaveDialog1: TSaveDialog;
  78. SaveHexFile: TSaveDialog;
  79. SaveBinFile: TSaveDialog;
  80. SdpoSerial1: TSdpoSerial;
  81. Servo1: TLabeledEdit;
  82. Servo2: TLabeledEdit;
  83. EditA: TLabeledEdit;
  84. EditC: TLabeledEdit;
  85. EditE: TLabeledEdit;
  86. EditB: TLabeledEdit;
  87. EditD: TLabeledEdit;
  88. EditF: TLabeledEdit;
  89. EditAddr: TLabeledEdit;
  90. Shape1: TShape;
  91. Shape2: TShape;
  92. ShapeOut1: TShape;
  93. ShapeOut2: TShape;
  94. ShapeOut3: TShape;
  95. ShapeOut4: TShape;
  96. SpeedButton1: TSpeedButton;
  97. StatusBar1: TStatusBar;
  98. StringGrid1: TStringGrid;
  99. tbPrg: TToggleBox;
  100. tbPreLoad: TToolButton;
  101. tbPreSave: TToolButton;
  102. tbSel: TToggleBox;
  103. Timer1: TTimer;
  104. ToolBar1: TToolBar;
  105. ToolBar2: TToolBar;
  106. ToolButton1: TToolButton;
  107. ToolButton10: TToolButton;
  108. ToolButton11: TToolButton;
  109. ToolButton12: TToolButton;
  110. ToolButton13: TToolButton;
  111. ToolButton14: TToolButton;
  112. ToolButton15: TToolButton;
  113. ToolButton16: TToolButton;
  114. ToolButton17: TToolButton;
  115. ToolButton18: TToolButton;
  116. tbPreset1: TToolButton;
  117. tbReset: TToolButton;
  118. ToolButton19: TToolButton;
  119. ToolButton2: TToolButton;
  120. tbPreset2: TToolButton;
  121. tbPreset3: TToolButton;
  122. tbPreset4: TToolButton;
  123. tbPreset5: TToolButton;
  124. tbPreset6: TToolButton;
  125. tbPreset7: TToolButton;
  126. tbPreset8: TToolButton;
  127. ToolButton20: TToolButton;
  128. ToolButton21: TToolButton;
  129. ToolButton3: TToolButton;
  130. ToolButton4: TToolButton;
  131. ToolButton5: TToolButton;
  132. ToolButton6: TToolButton;
  133. ToolButton7: TToolButton;
  134. ToolButton8: TToolButton;
  135. ToolButton9: TToolButton;
  136. TOpenDialogPreset: TOpenDialog;
  137. TSaveDialogPreset: TSaveDialog;
  138. XMLPropStorage1: TXMLPropStorage;
  139. procedure acDeleteRowExecute(Sender: TObject);
  140. procedure acExitExecute(Sender: TObject);
  141. procedure acFileOpenAccept(Sender: TObject);
  142. procedure acDebugExecute(Sender: TObject);
  143. procedure acHelpAboutExecute(Sender: TObject);
  144. procedure acHexFileExecute(Sender: TObject);
  145. procedure acNewExecute(Sender: TObject);
  146. procedure acNewRowExecute(Sender: TObject);
  147. procedure acNextInsertExecute(Sender: TObject);
  148. procedure acNextStepExecute(Sender: TObject);
  149. procedure acPresetLoadAccept(Sender: TObject);
  150. procedure acPresetSaveAccept(Sender: TObject);
  151. procedure acSaveAsExecute(Sender: TObject);
  152. procedure acShowHexFileExecute(Sender: TObject);
  153. procedure acStopExecute(Sender: TObject);
  154. procedure acThisStepExecute(Sender: TObject);
  155. procedure acFileSaveExecute(Sender: TObject);
  156. procedure acUploadExecute(Sender: TObject);
  157. procedure btnToneClick(Sender: TObject);
  158. procedure cbCommandChange(Sender: TObject);
  159. procedure cbDataChange(Sender: TObject);
  160. procedure cbTPSVersionChange(Sender: TObject);
  161. procedure FormActivate(Sender: TObject);
  162. procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
  163. procedure FormCreate(Sender: TObject);
  164. procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
  165. procedure MCSLabelClick(Sender: TObject);
  166. procedure MenuItem1Click(Sender: TObject);
  167. procedure mnSaveClick(Sender: TObject);
  168. procedure pmExamplesPopup(Sender: TObject);
  169. procedure Shape1Paint(Sender: TObject);
  170. procedure Shape2Paint(Sender: TObject);
  171. procedure StringGrid1EditingDone(Sender: TObject);
  172. procedure StringGrid1Selection(Sender: TObject; aCol, aRow: integer);
  173. procedure tbPreset1Click(Sender: TObject);
  174. procedure tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint;
  175. var Handled: boolean);
  176. procedure tbPrgChange(Sender: TObject);
  177. procedure tbResetClick(Sender: TObject);
  178. procedure tbSelChange(Sender: TObject);
  179. procedure Timer1Timer(Sender: TObject);
  180. procedure XMLPropStorage1RestoringProperties(Sender: TObject);
  181. procedure XMLPropStorage1SavingProperties(Sender: TObject);
  182. private
  183. { private declarations }
  184. sps: TSPS;
  185. stopit: boolean;
  186. activeFile: string;
  187. dirty: boolean;
  188. lastNote: byte;
  189. Examples: TStringList;
  190. procedure doStopExecute();
  191. procedure initMidi;
  192. procedure playNote(note: byte);
  193. procedure loadFromList(Lines: TStringList; filename: string);
  194. function readString(var line: string): boolean;
  195. procedure saveSection(filename: string; key: string);
  196. procedure loadSection(filename: string; key: string);
  197. procedure loadFile(filename: string);
  198. procedure programSps;
  199. procedure nextStep(singleStep: boolean);
  200. procedure renumberGrid;
  201. procedure saveFile(filename: string);
  202. procedure selectAddress(addr: word);
  203. procedure inputSps;
  204. procedure outputSps;
  205. procedure uploadFile;
  206. function serialUpload: string;
  207. procedure setDirty(Value: boolean);
  208. function checkDirty: boolean;
  209. procedure checkPresets;
  210. procedure makeBinFile(fileName: string);
  211. procedure makeHexFile(fileName: string);
  212. procedure setCaption;
  213. procedure addHeaderText;
  214. procedure loadPreset(filename: string);
  215. procedure savePreset(filename: string);
  216. procedure activateSps(enable: boolean);
  217. procedure enableMicrobit(enable: boolean);
  218. procedure outputMicrobit();
  219. procedure inputMicrobit();
  220. public
  221. { public declarations }
  222. end;
  223. var
  224. Form1: TForm1;
  225. implementation
  226. uses MCSAbout, uTextUi, uSelectCom, MCSTools, MCSStrings, synaser,
  227. MCSIO, mcsintelhex, MCSLSU, MCSIniFiles, MCSWinHttp, luijsonutils,
  228. uiMicrobit, uMicrobit;
  229. {$R *.lfm}
  230. procedure delayCallback(Value: integer);
  231. begin
  232. Form1.EditDelay.Text := IntToStr(Value);
  233. Application.ProcessMessages;
  234. end;
  235. { TForm1 }
  236. var
  237. lsuCode: integer;
  238. procedure TForm1.FormCreate(Sender: TObject);
  239. var
  240. line: string;
  241. begin
  242. Infobox.AppTitel := MCSLSU.GetLSUText('infobox', 'ID_APPTITLE', lsuCode);
  243. Infobox.CopyRight := MCSLSU.GetLSUText('infobox', 'ID_COPYRIGHT', lsuCode);
  244. Infobox.Build := MCSGetVersion(Application.ExeName);
  245. Infobox.AppID := 31;
  246. Infobox.AppURL :=
  247. 'http://www.wk-music.de/willie/pages/mcs/microcontroller/tps-sps-emulator.php';
  248. sps := TSPS.Create();
  249. sps.setDelayCallback(@delayCallback);
  250. addHeaderText;
  251. renumberGrid();
  252. cbTPSVersion.ItemIndex := 0;
  253. cbTPSVersionChange(Sender);
  254. acStop.Enabled := False;
  255. ToolButton18.Align := alRight;
  256. MCSLabel.Align := alRight;
  257. cbAdrActual.Enabled := False;
  258. checkPresets();
  259. tbResetClick(nil);
  260. if Application.ParamCount >= 1 then
  261. begin
  262. line := Application.Params[1];
  263. loadFile(line);
  264. end;
  265. activateSps(False);
  266. Timer1.Enabled := True;
  267. MCSLSU.MakeForm('form1', 'ID_', form1);
  268. initMidi;
  269. Examples := TStringList.Create;
  270. end;
  271. procedure TForm1.initMidi;
  272. var
  273. Value: integer;
  274. begin
  275. lastNote := 0;
  276. MidiOutput.Open(0);
  277. Value := XMLPropStorage1.ReadInteger('MidiProgram', 30);
  278. MidiOutput.Send(0, 192, Value, 0);
  279. end;
  280. procedure TForm1.playNote(note: byte);
  281. var
  282. command, velocity: byte;
  283. begin
  284. if (lastNote > 0) then
  285. begin
  286. command := $80;
  287. velocity := $7F;
  288. MidiOutput.Send(0, command, lastnote, velocity);
  289. end;
  290. if (note > 0) then
  291. begin
  292. command := $90;
  293. velocity := $7F;
  294. MidiOutput.Send(0, command, note, velocity);
  295. end;
  296. lastNote := note;
  297. end;
  298. procedure TForm1.loadFromList(Lines: TStringList; filename: string);
  299. var
  300. i, x: integer;
  301. line: string;
  302. list: TStringList;
  303. begin
  304. acNew.Execute;
  305. list := TStringList.Create;
  306. i := 1;
  307. for x := 0 to Lines.Count - 1 do
  308. begin
  309. if (i + 1 > StringGrid1.RowCount) then
  310. begin
  311. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  312. end;
  313. line := Lines[x];
  314. if (Pos('#', line) = 1) then
  315. begin
  316. line := RightstrPos(line, 2);
  317. if (Pos('TPS:', line) = 1) then
  318. begin
  319. line := RightstrPos(line, 5);
  320. cbTPSVersion.Text := line;
  321. cbTPSVersionChange(nil);
  322. end;
  323. end
  324. else
  325. begin
  326. MCSStrings.DelimSepTextToStringlist(line, '"', ',', list);
  327. if list.Count > 0 then
  328. Stringgrid1.Cells[0, i] := list[0];
  329. if list.Count > 1 then
  330. Stringgrid1.Cells[1, i] := list[1];
  331. if list.Count > 2 then
  332. Stringgrid1.Cells[2, i] := list[2];
  333. if list.Count > 3 then
  334. Stringgrid1.Cells[4, i] := list[3];
  335. list.Clear;
  336. Inc(i);
  337. end;
  338. end;
  339. list.Free;
  340. activeFile := filename;
  341. renumberGrid();
  342. addHeaderText;
  343. setCaption();
  344. setDirty(False);
  345. end;
  346. procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
  347. var
  348. line: string;
  349. begin
  350. if (SizeOF(FileNames) > 0) then
  351. begin
  352. line := FileNames[0];
  353. loadFile(line);
  354. end;
  355. end;
  356. procedure TForm1.MCSLabelClick(Sender: TObject);
  357. begin
  358. ShExec2(self.Handle, InfoBox.AppURL);
  359. end;
  360. procedure TForm1.MenuItem1Click(Sender: TObject);
  361. var
  362. i: integer;
  363. fileName, Data: string;
  364. Lines: TStringList;
  365. begin
  366. if (Sender is TMenuItem) then
  367. begin
  368. if (checkDirty()) then
  369. begin
  370. i := TMenuItem(Sender).Tag;
  371. if (i >= 0) then
  372. begin
  373. filename := examples[i];
  374. Data := DownloadFile('http://wkla.no-ip.biz/down/tps_examples/' + filename);
  375. Lines := TStringList.Create;
  376. Lines.Text := Data;
  377. loadFromList(Lines, filename);
  378. Lines.Free;
  379. end;
  380. end;
  381. end;
  382. end;
  383. procedure TForm1.mnSaveClick(Sender: TObject);
  384. begin
  385. Statusbar1.SimpleText := Sender.ClassName;
  386. end;
  387. procedure TForm1.pmExamplesPopup(Sender: TObject);
  388. var
  389. x, i, j, pos, index: integer;
  390. myName: string;
  391. myMenu, my2Menu: TMenuItem;
  392. jsonString: string;
  393. JsonObject: TJsonObject;
  394. Data, JArray: TJSONData;
  395. JItem: TJSONData;
  396. subMenuName: string;
  397. subMenu: TMenuItem;
  398. begin
  399. for i := pmExamples.Items.Count - 1 downto 0 do
  400. begin
  401. myMenu := pmExamples.Items[i];
  402. if (myMenu.Count > 0) then
  403. begin
  404. for j := myMenu.Count - 1 downto 0 do
  405. begin
  406. my2Menu := myMenu.Items[j];
  407. my2Menu.Free;
  408. end;
  409. myMenu.Clear;
  410. end;
  411. myMenu.Free;
  412. end;
  413. pmExamples.Items.Clear;
  414. Examples.Clear;
  415. try
  416. jsonString := DownloadFile('http://wkla.no-ip.biz/down/tps_examples/examples.json');
  417. Data := StringToJSONData(jsonString);
  418. JsonObject := TJSONObject(Data);
  419. i := JsonObject.Count;
  420. for x := 0 to JsonObject.Count - 1 do
  421. begin
  422. subMenuName := JsonObject.Names[x];
  423. JArray := GetJSONProp(TJSONObject(Data), subMenuName);
  424. if (JArray <> nil) then
  425. begin
  426. subMenu := TMenuItem.Create(pmExamples);
  427. subMenu.Caption := subMenuName;
  428. pmExamples.Items.Add(subMenu);
  429. for i := 1 to TJSONArray(JArray).Count do
  430. begin
  431. JItem := TJSONArray(JArray).Items[i - 1];
  432. myName := GetJsonProp(TJSONObject(JItem), 'name', '');
  433. pos := -1;
  434. index := GetJsonProp(TJSONObject(JItem), 'index', -1);
  435. if (index > -1) then
  436. begin
  437. pos := Examples.Add(GetJsonProp(TJSONObject(JItem), 'file', ''));
  438. myName := format('%.2d - %s', [index, myName]);
  439. end;
  440. myMenu := TMenuItem.Create(subMenu);
  441. myMenu.Caption := myName;
  442. myMenu.Tag := pos;
  443. if (index > -1) then
  444. begin
  445. myMenu.OnClick := @MenuItem1Click;
  446. end;
  447. subMenu.Add(myMenu);
  448. end;
  449. end;
  450. end;
  451. except
  452. end;
  453. end;
  454. procedure TForm1.Shape1Paint(Sender: TObject);
  455. var
  456. radius: integer;
  457. x, y: integer;
  458. begin
  459. radius := round(Shape1.Width / 2);
  460. Shape1.Canvas.Brush.Color := clBlack;
  461. Shape1.canvas.MoveTo(radius, radius);
  462. x := radius - round(radius * cos(degtorad(sps.getServo1())));
  463. y := radius - round(radius * sin(degtorad(sps.getServo1())));
  464. Shape1.Canvas.LineTo(x, y);
  465. end;
  466. procedure TForm1.Shape2Paint(Sender: TObject);
  467. var
  468. radius: integer;
  469. x, y: integer;
  470. begin
  471. radius := round(Shape1.Width / 2);
  472. Shape2.Canvas.Brush.Color := clBlack;
  473. Shape2.canvas.MoveTo(radius, radius);
  474. x := radius - round(radius * cos(degtorad(sps.getServo2())));
  475. y := radius - round(radius * sin(degtorad(sps.getServo2())));
  476. Shape2.Canvas.LineTo(x, y);
  477. end;
  478. procedure TForm1.acExitExecute(Sender: TObject);
  479. begin
  480. Close;
  481. end;
  482. procedure TForm1.acDeleteRowExecute(Sender: TObject);
  483. var
  484. i: integer;
  485. begin
  486. i := StringGrid1.Row;
  487. StringGrid1.DeleteRow(i);
  488. renumberGrid();
  489. end;
  490. procedure TForm1.acFileOpenAccept(Sender: TObject);
  491. var
  492. filename: string;
  493. begin
  494. filename := (Sender as TFileOpen).Dialog.FileName;
  495. loadFile(filename);
  496. end;
  497. procedure TForm1.loadFile(filename: string);
  498. var
  499. i: integer;
  500. f: Text;
  501. line: string;
  502. list: TStringList;
  503. begin
  504. if (checkDirty()) then
  505. begin
  506. if (FileExists(filename)) then
  507. begin
  508. acNew.Execute;
  509. list := TStringList.Create;
  510. i := 1;
  511. AssignFile(f, filename);
  512. Reset(f);
  513. while (not EOF(f)) do
  514. begin
  515. if (i + 1 > StringGrid1.RowCount) then
  516. begin
  517. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  518. end;
  519. readln(f, line);
  520. if (Pos('#', line) = 1) then
  521. begin
  522. line := RightstrPos(line, 2);
  523. if (Pos('TPS:', line) = 1) then
  524. begin
  525. line := RightstrPos(line, 5);
  526. cbTPSVersion.Text := line;
  527. cbTPSVersionChange(nil);
  528. end;
  529. end
  530. else
  531. begin
  532. MCSStrings.DelimSepTextToStringlist(line, '"', ',', list);
  533. if list.Count > 0 then
  534. Stringgrid1.Cells[0, i] := list[0];
  535. if list.Count > 1 then
  536. Stringgrid1.Cells[1, i] := list[1];
  537. if list.Count > 2 then
  538. Stringgrid1.Cells[2, i] := list[2];
  539. if list.Count > 3 then
  540. Stringgrid1.Cells[4, i] := list[3];
  541. list.Clear;
  542. i := i + 1;
  543. end;
  544. end;
  545. CloseFile(f);
  546. list.Free;
  547. activeFile := filename;
  548. renumberGrid();
  549. addHeaderText;
  550. setCaption();
  551. setDirty(False);
  552. end;
  553. end;
  554. end;
  555. procedure TForm1.acSaveAsExecute(Sender: TObject);
  556. var
  557. filename: string;
  558. begin
  559. if SaveDialog1.Execute() then
  560. begin
  561. filename := SaveDialog1.FileName;
  562. saveFile(filename);
  563. end;
  564. end;
  565. procedure TForm1.saveFile(filename: string);
  566. var
  567. x, i: integer;
  568. f: Text;
  569. line: string;
  570. begin
  571. if (filename = '') then
  572. begin
  573. if SaveDialog1.Execute() then
  574. begin
  575. filename := SaveDialog1.FileName;
  576. end;
  577. end;
  578. if (filename <> '') then
  579. begin
  580. AssignFile(f, filename);
  581. Rewrite(f);
  582. line := '#TPS:' + cbTPSVersion.Text;
  583. Writeln(f, line);
  584. i := StringGrid1.RowCount;
  585. for x := 1 to i - 1 do
  586. begin
  587. if (StringGrid1.Cells[1, x] <> '') then
  588. begin
  589. line := StringGrid1.Cells[0, x] + ',' + StringGrid1.Cells[1, x] +
  590. ',' + StringGrid1.Cells[2, x] + ',"' + StringGrid1.Cells[4, x] + '"';
  591. Writeln(f, line);
  592. end;
  593. end;
  594. CloseFile(f);
  595. setDirty(False);
  596. activeFile := filename;
  597. setCaption();
  598. end;
  599. end;
  600. procedure TForm1.acDebugExecute(Sender: TObject);
  601. begin
  602. if (sps.isActive()) then
  603. begin
  604. acStopExecute(Sender);
  605. end
  606. else
  607. begin
  608. activateSps(True);
  609. acDebug.Enabled := True;
  610. acDebug.ImageIndex := 57;
  611. cbAdrActual.Enabled := True;
  612. acNextStep.Enabled := False;
  613. // sps programmieren
  614. programSps();
  615. // programm starten
  616. Statusbar1.SimpleText := MCSLSU.GetLSUText('statusbar', 'ID_SPS_START', lsuCode);
  617. sps.start();
  618. stopit := False;
  619. Statusbar1.SimpleText := MCSLSU.GetLSUText('statusbar', 'ID_SPS_RUNNING', lsuCode);
  620. while (not stopit) do
  621. begin
  622. nextStep(False);
  623. if not sps.isActive() then
  624. begin
  625. stopit := True;
  626. doStopExecute(); // error in sps
  627. end;
  628. if (cbAdrActual.Checked) then
  629. selectAddress(sps.getAddress());
  630. Application.ProcessMessages;
  631. end;
  632. if sps.getLastError() <> '' then
  633. MyMsgBox(sps.getLastError(), 'Error', MB_OK + MB_ICONERROR)
  634. else
  635. Statusbar1.SimpleText := MCSLSU.GetLSUText('statusbar', 'ID_SPS_STOPPED', lsuCode);
  636. cbAdrActual.Enabled := False;
  637. acNextStep.Enabled := True;
  638. sps.doReset();
  639. end;
  640. end;
  641. procedure TForm1.acHelpAboutExecute(Sender: TObject);
  642. begin
  643. Infobox.Show;
  644. end;
  645. procedure TForm1.acHexFileExecute(Sender: TObject);
  646. var
  647. filename: string;
  648. begin
  649. filename := MCSIO.MCSExtractFileNameExlExt(activeFile) + '.hex';
  650. SaveHexFile.FileName := filename;
  651. if (SaveHexFile.Execute) then
  652. begin
  653. filename := SaveHexFile.FileName;
  654. makeHexFile(filename);
  655. end;
  656. end;
  657. procedure TForm1.acNewExecute(Sender: TObject);
  658. begin
  659. if (checkDirty()) then
  660. begin
  661. StringGrid1.RowCount := 2;
  662. StringGrid1.Clean;
  663. addHeaderText();
  664. renumberGrid();
  665. activeFile := '';
  666. setCaption();
  667. setDirty(False);
  668. end;
  669. end;
  670. procedure TForm1.acNewRowExecute(Sender: TObject);
  671. var
  672. myPos: integer;
  673. i, x: integer;
  674. eot: boolean;
  675. begin
  676. eot := False;
  677. i := StringGrid1.RowCount-1;
  678. if (i >= (sps.getE2E())) then
  679. begin
  680. LSUAutoMsgBox('Messages', 'ID_PRG_TO_LONG', MB_OK + MB_ICONERROR);
  681. exit;
  682. end;
  683. myPos := StringGrid1.Row;
  684. if (myPos = StringGrid1.RowCount - 1) then
  685. eot := True;
  686. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  687. if (not eot) then
  688. begin
  689. for i := StringGrid1.RowCount - 2 downto myPos do
  690. begin
  691. for x := 1 to StringGrid1.ColCount - 1 do
  692. begin
  693. StringGrid1.Cells[x, i + 1] := StringGrid1.Cells[x, i];
  694. end;
  695. end;
  696. for x := 1 to StringGrid1.ColCount - 1 do
  697. begin
  698. StringGrid1.Cells[x, myPos] := '';
  699. end;
  700. end;
  701. renumberGrid();
  702. end;
  703. procedure TForm1.acNextInsertExecute(Sender: TObject);
  704. var
  705. myPos: integer;
  706. i : integer;
  707. begin
  708. i := StringGrid1.RowCount-1;
  709. if (i >= (sps.getE2E())) then
  710. begin
  711. LSUAutoMsgBox('Messages', 'ID_PRG_TO_LONG', MB_OK + MB_ICONERROR);
  712. exit;
  713. end;
  714. myPos := StringGrid1.Row;
  715. if (myPos = StringGrid1.RowCount - 1) then
  716. acNewRow.Execute;
  717. StringGrid1.Row := myPos + 1;
  718. renumberGrid();
  719. end;
  720. procedure TForm1.programSps;
  721. var
  722. x, i: integer;
  723. com, Data: byte;
  724. tmp: string;
  725. begin
  726. Statusbar1.SimpleText := MCSLSU.GetLSUText('statusbar', 'ID_SPS_PROGRAMMING', lsuCode);
  727. i := StringGrid1.RowCount;
  728. for x := 1 to i - 1 do
  729. begin
  730. com := 0;
  731. Data := 0;
  732. tmp := StringGrid1.Cells[1, x];
  733. if (tmp <> '') then
  734. begin
  735. com := HexToInt(tmp);
  736. tmp := StringGrid1.Cells[2, x];
  737. if (tmp <> '') then
  738. Data := HexToInt(tmp);
  739. Data := com * 16 + Data;
  740. end;
  741. sps.writeEEProm(x - 1, Data);
  742. end;
  743. // endekennzeichnung schreiben
  744. sps.writeEEProm(i, $ff);
  745. end;
  746. procedure TForm1.acNextStepExecute(Sender: TObject);
  747. begin
  748. nextStep(True);
  749. selectAddress(sps.getAddress());
  750. end;
  751. procedure TForm1.acPresetLoadAccept(Sender: TObject);
  752. var
  753. filename: string;
  754. begin
  755. filename := (Sender as TFileOpen).Dialog.FileName;
  756. loadPreset(filename);
  757. end;
  758. procedure TForm1.acPresetSaveAccept(Sender: TObject);
  759. var
  760. filename: string;
  761. begin
  762. filename := (Sender as TFileSaveAs).Dialog.FileName;
  763. savePreset(filename);
  764. end;
  765. procedure TForm1.nextStep(singleStep: boolean);
  766. begin
  767. if (not sps.isActive()) then
  768. begin
  769. activateSps(True);
  770. programSps;
  771. sps.start();
  772. acStop.Enabled := True;
  773. acDebug.Enabled := False;
  774. end
  775. else
  776. begin
  777. acNextStep.Enabled := False;
  778. acStop.Enabled := True;
  779. inputMicrobit();
  780. inputSps();
  781. sps.nextStep();
  782. outputSps();
  783. outputMicrobit();
  784. acNextStep.Enabled := singleStep;
  785. acStop.Enabled := True;
  786. end;
  787. end;
  788. procedure TForm1.acShowHexFileExecute(Sender: TObject);
  789. var
  790. list: TStringList;
  791. i, x: integer;
  792. line, tmp: string;
  793. Value: byte;
  794. begin
  795. Form2 := TForm2.Create(self);
  796. list := TStringList.Create();
  797. line := MCSLSU.GetLSUText('hexfile', 'ID_START_LINE', lsuCode);
  798. list.add(line);
  799. i := StringGrid1.RowCount;
  800. for x := 1 to i - 1 do
  801. begin
  802. if (StringGrid1.Cells[1, x] <> '') then
  803. begin
  804. tmp := '';
  805. if (StringGrid1.Cells[1, x] = '') then
  806. begin
  807. tmp := ' ';
  808. end
  809. else
  810. begin
  811. tmp := StringGrid1.Cells[1, x];
  812. end;
  813. if (StringGrid1.Cells[2, x] = '') then
  814. begin
  815. tmp := tmp + ' ';
  816. end
  817. else
  818. begin
  819. tmp := tmp + StringGrid1.Cells[2, x];
  820. end;
  821. line := StringGrid1.Cells[0, x] + ': ' + tmp + ' ';
  822. Value := HexToInt(StringGrid1.Cells[1, x]);
  823. tmp := '';
  824. if (Value and 8) > 0 then
  825. tmp := tmp + 'X'
  826. else
  827. tmp := tmp + '0';
  828. if (Value and 4) > 0 then
  829. tmp := tmp + 'X'
  830. else
  831. tmp := tmp + '0';
  832. if (Value and 2) > 0 then
  833. tmp := tmp + 'X'
  834. else
  835. tmp := tmp + '0';
  836. if (Value and 1) > 0 then
  837. tmp := tmp + 'X'
  838. else
  839. tmp := tmp + '0';
  840. line := line + tmp + ' ';
  841. Value := HexToInt(StringGrid1.Cells[2, x]);
  842. tmp := '';
  843. if (Value and 8) > 0 then
  844. tmp := tmp + 'X'
  845. else
  846. tmp := tmp + '0';
  847. if (Value and 4) > 0 then
  848. tmp := tmp + 'X'
  849. else
  850. tmp := tmp + '0';
  851. if (Value and 2) > 0 then
  852. tmp := tmp + 'X'
  853. else
  854. tmp := tmp + '0';
  855. if (Value and 1) > 0 then
  856. tmp := tmp + 'X'
  857. else
  858. tmp := tmp + '0';
  859. line := line + tmp;
  860. line := line + ' ' + StringGrid1.Cells[3, x] + ' ,"' +
  861. StringGrid1.Cells[4, x] + '"';
  862. list.add(line);
  863. end;
  864. end;
  865. Form2.addHexFile(list);
  866. Form2.ShowModal;
  867. list.Free;
  868. end;
  869. procedure TForm1.acStopExecute(Sender: TObject);
  870. begin
  871. if (sps.isActive()) then
  872. begin
  873. stopit := True;
  874. sps.break();
  875. doStopExecute();
  876. end;
  877. end;
  878. procedure TForm1.doStopExecute();
  879. begin
  880. acDebug.ImageIndex := 40;
  881. // repeat
  882. // Application.ProcessMessages;
  883. // until (not sps.isDelayActive());
  884. sps.doReset();
  885. acStop.Enabled := False;
  886. acDebug.Enabled := True;
  887. outputSps();
  888. selectAddress(0);
  889. activateSps(False);
  890. end;
  891. procedure TForm1.acThisStepExecute(Sender: TObject);
  892. var
  893. Data, com: byte;
  894. tmp: string;
  895. begin
  896. inputSps();
  897. try
  898. tmp := StringGrid1.Cells[1, StringGrid1.Row];
  899. if (tmp <> '') then
  900. begin
  901. com := HexToInt(tmp);
  902. tmp := StringGrid1.Cells[2, StringGrid1.Row];
  903. if (tmp <> '') then
  904. Data := HexToInt(tmp);
  905. Data := com * 16 + Data;
  906. end;
  907. sps.doSingleCommand(Data);
  908. except
  909. end;
  910. outputSps();
  911. end;
  912. procedure TForm1.acFileSaveExecute(Sender: TObject);
  913. begin
  914. saveFile(activeFile);
  915. end;
  916. procedure TForm1.acUploadExecute(Sender: TObject);
  917. begin
  918. uploadFile();
  919. //serialUpload;
  920. end;
  921. procedure TForm1.btnToneClick(Sender: TObject);
  922. begin
  923. MidiOutput.SendAllSoundOff(0, 0);
  924. ImageList2.GetBitmap(22, btnTone.Glyph);
  925. end;
  926. function TForm1.serialUpload: string;
  927. var
  928. hexFile: string;
  929. begin
  930. hexFile := MCSIO.CreateUniqueFile(MCSIO.GetTempDir, 'TPS', '.hex');
  931. makeHexFile(hexFile);
  932. Result := hexFile;
  933. end;
  934. procedure TForm1.uploadFile;
  935. var
  936. line: string;
  937. comServices: TStringList;
  938. comService: string;
  939. return: integer;
  940. hexFile: string;
  941. hexFormat: TIntelHexFormat;
  942. prgMem: array of byte;
  943. i, x: integer;
  944. com, Data: byte;
  945. tmp: string;
  946. arduinoPath: string;
  947. cmd, config, mcu: string;
  948. KeyName, StringValue: string;
  949. Res: WideString;
  950. Lines: TStringList;
  951. TimeOut: integer;
  952. error: boolean;
  953. filename: string;
  954. begin
  955. error := False;
  956. if cbTPSVersion.ItemIndex = 4 then
  957. begin
  958. // microbit code
  959. SaveBinFile.FileName := 'mycobit';
  960. if (SaveBinFile.Execute) then
  961. begin
  962. filename := SaveBinFile.FileName;
  963. makeBinFile(filename);
  964. end;
  965. end
  966. else
  967. begin
  968. line := GetSerialPortNames;
  969. // if (line <> '') then
  970. begin
  971. comServices := TStringList.Create;
  972. MCSStrings.DelimTextToStringlist(line, ',', comServices);
  973. return := mrOk;
  974. line := XMLPropStorage1.ReadString('ComPort', comServices[0]);
  975. frmSelectCom := TfrmSelectCom.Create(self);
  976. frmSelectCom.cbServices.Items.AddStrings(comServices);
  977. frmSelectCom.cbServices.Text := line;
  978. return := frmSelectCom.ShowModal;
  979. comService := frmSelectCom.cbServices.Text;
  980. XMLPropStorage1.WriteString('ComPort', comService);
  981. comServices.Free;
  982. if (return = mrOk) then
  983. begin
  984. hexFile := serialUpload;
  985. SdpoSerial1.BaudRate := br__9600;
  986. if cbTPSVersion.ItemIndex = 5 then
  987. begin
  988. // Micro:bit V2 auto programm
  989. SdpoSerial1.BaudRate := br115200;
  990. end;
  991. SdpoSerial1.Device := comService;
  992. SdpoSerial1.Active := True;
  993. SdpoSerial1.WriteData('p');
  994. if (not readString(line)) then
  995. begin
  996. error := True;
  997. end;
  998. if (not error) then
  999. begin
  1000. SdpoSerial1.WriteData('w');
  1001. if (readString(line)) then
  1002. begin
  1003. if (pos('ready', line) > 0) then
  1004. begin
  1005. Lines := TStringList.Create;
  1006. Lines.LoadFromFile(hexFile);
  1007. for x := 0 to Lines.Count - 1 do
  1008. begin
  1009. SdpoSerial1.WriteData(Lines.Strings[x]);
  1010. SdpoSerial1.WriteData(CRLF);
  1011. Sleep(250);
  1012. end;
  1013. SdpoSerial1.WriteData('e');
  1014. end
  1015. else
  1016. begin
  1017. error := True;
  1018. end;
  1019. end;
  1020. end;
  1021. if (error) then
  1022. begin
  1023. LSUAutoMsgBox('Messages', 'ID_NOT_READY', MB_OK + MB_ICONERROR);
  1024. end
  1025. else
  1026. begin
  1027. LSUAutoMsgBox('Messages', 'ID_UPLOAD_OK', MB_OK + MB_ICONINFORMATION);
  1028. end;
  1029. SdpoSerial1.Active := False;
  1030. DeleteFile(hexFile);
  1031. end;
  1032. end;
  1033. end;
  1034. end;
  1035. function TForm1.readString(var line: string): boolean;
  1036. var
  1037. TimeOut: integer;
  1038. begin
  1039. Result := False;
  1040. TimeOut := 10;
  1041. while ((not SdpoSerial1.DataAvailable) and (TimeOut > 0)) do
  1042. begin
  1043. Dec(TimeOut);
  1044. Sleep(1000);
  1045. end;
  1046. if (Timeout > 0) then
  1047. begin
  1048. line := SdpoSerial1.ReadData;
  1049. Result := True;
  1050. end;
  1051. end;
  1052. procedure TForm1.setDirty(Value: boolean);
  1053. begin
  1054. if (dirty <> Value) then
  1055. begin
  1056. dirty := Value;
  1057. if (dirty) then
  1058. begin
  1059. if (Pos('*', Caption) = 0) then
  1060. begin
  1061. Caption := Caption + '*';
  1062. end;
  1063. end
  1064. else
  1065. begin
  1066. if (Pos('*', Caption) > 0) then
  1067. begin
  1068. Caption := Leftstr(Caption, Pos('*', Caption) - 1);
  1069. end;
  1070. end;
  1071. end;
  1072. end;
  1073. function TForm1.checkDirty: boolean;
  1074. var
  1075. i: integer;
  1076. begin
  1077. if (dirty) then
  1078. begin
  1079. i := MCSLSU.LSUAutoMsgBox('Messages', 'SAVE_CHANGES', MB_ICONQUESTION or
  1080. MB_YESNOCANCEL);
  1081. if (i = mrYes) then
  1082. begin
  1083. saveFile(activeFile);
  1084. Result := True;
  1085. end
  1086. else if (i = mrNo) then
  1087. begin
  1088. setDirty(False);
  1089. Result := True;
  1090. end
  1091. else
  1092. begin
  1093. Result := False;
  1094. end;
  1095. end
  1096. else
  1097. begin
  1098. Result := True;
  1099. end;
  1100. end;
  1101. procedure TForm1.checkPresets;
  1102. begin
  1103. if XMLPropStorage1.ReadBoolean('preset_1.set', False) then
  1104. tbPreset1.Caption := '1*'
  1105. else
  1106. tbPreset1.Caption := '1';
  1107. if XMLPropStorage1.ReadBoolean('preset_2.set', False) then
  1108. tbPreset2.Caption := '2*'
  1109. else
  1110. tbPreset2.Caption := '2';
  1111. if XMLPropStorage1.ReadBoolean('preset_3.set', False) then
  1112. tbPreset3.Caption := '3*'
  1113. else
  1114. tbPreset3.Caption := '3';
  1115. if XMLPropStorage1.ReadBoolean('preset_4.set', False) then
  1116. tbPreset4.Caption := '4*'
  1117. else
  1118. tbPreset4.Caption := '4';
  1119. if XMLPropStorage1.ReadBoolean('preset_5.set', False) then
  1120. tbPreset5.Caption := '5*'
  1121. else
  1122. tbPreset5.Caption := '5';
  1123. if XMLPropStorage1.ReadBoolean('preset_6.set', False) then
  1124. tbPreset6.Caption := '6*'
  1125. else
  1126. tbPreset6.Caption := '6';
  1127. if XMLPropStorage1.ReadBoolean('preset_7.set', False) then
  1128. tbPreset7.Caption := '7*'
  1129. else
  1130. tbPreset7.Caption := '7';
  1131. if XMLPropStorage1.ReadBoolean('preset_8.set', False) then
  1132. tbPreset7.Caption := '8*'
  1133. else
  1134. tbPreset7.Caption := '8';
  1135. end;
  1136. procedure TForm1.makeHexFile(fileName: string);
  1137. var
  1138. i, x: integer;
  1139. tmp: string;
  1140. hexFormat: TIntelHexFormat;
  1141. prgMem: array of byte;
  1142. com, Data: byte;
  1143. begin
  1144. i := StringGrid1.RowCount;
  1145. SetLength(prgMem, i);
  1146. for x := 1 to i - 1 do
  1147. begin
  1148. com := 0;
  1149. Data := 0;
  1150. tmp := StringGrid1.Cells[1, x];
  1151. if (tmp <> '') then
  1152. begin
  1153. com := HexToInt(tmp);
  1154. tmp := StringGrid1.Cells[2, x];
  1155. if (tmp <> '') then
  1156. Data := HexToInt(tmp);
  1157. Data := com * 16 + Data;
  1158. end;
  1159. prgMem[x - 1] := Data;
  1160. end;
  1161. hexFormat := TIntelHexFormat.Create(prgMem, 8);
  1162. tmp := hexFormat.Text;
  1163. MCSIO.StrToFile(fileName, tmp);
  1164. hexFormat.Free;
  1165. SetLength(prgMem, 0);
  1166. end;
  1167. procedure TForm1.makeBinFile(fileName: string);
  1168. var
  1169. i, x: integer;
  1170. tmp: string;
  1171. hexFormat: TIntelHexFormat;
  1172. com, Data: byte;
  1173. f: file of byte;
  1174. begin
  1175. i := StringGrid1.RowCount;
  1176. AssignFile(f, fileName);
  1177. Rewrite(f, 1);
  1178. for x := 1 to i - 1 do
  1179. begin
  1180. com := 0;
  1181. Data := 0;
  1182. tmp := StringGrid1.Cells[1, x];
  1183. if (tmp <> '') then
  1184. begin
  1185. com := HexToInt(tmp);
  1186. tmp := StringGrid1.Cells[2, x];
  1187. if (tmp <> '') then
  1188. Data := HexToInt(tmp);
  1189. Data := com * 16 + Data;
  1190. end;
  1191. Write(f, Data);
  1192. end;
  1193. CloseFile(f);
  1194. end;
  1195. procedure TForm1.setCaption;
  1196. begin
  1197. if (activeFile = '') then
  1198. begin
  1199. Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode);
  1200. end
  1201. else
  1202. begin
  1203. Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode) +
  1204. ':' + ExtractFileName(activeFile);
  1205. end;
  1206. end;
  1207. procedure TForm1.addHeaderText;
  1208. var
  1209. i: integer;
  1210. begin
  1211. for i := 0 to StringGrid1.Columns.Count - 1 do
  1212. begin
  1213. ;
  1214. StringGrid1.Columns[i].Title.Caption :=
  1215. MCSLSU.GetLSUText('form1Captions', StringGrid1.Columns[i].Title.Caption, lsuCode);
  1216. end;
  1217. StringGrid1.Cells[0, 0] := MCSLSU.GetLSUText('form1Captions',
  1218. 'ID_GRID_STORAGE', lsuCode);
  1219. StringGrid1.Repaint;
  1220. end;
  1221. procedure TForm1.cbCommandChange(Sender: TObject);
  1222. var
  1223. x: integer;
  1224. begin
  1225. cbData.Items.Clear;
  1226. x := cbCommand.ItemIndex;
  1227. sps.getDatas(x, cbData.Items);
  1228. if StringGrid1.Row > 0 then
  1229. begin
  1230. StringGrid1.Cells[1, StringGrid1.Row] := IntToHex(x, 1);
  1231. end;
  1232. end;
  1233. procedure TForm1.cbDataChange(Sender: TObject);
  1234. var
  1235. x: integer;
  1236. begin
  1237. x := cbData.ItemIndex;
  1238. if StringGrid1.Row > 0 then
  1239. begin
  1240. StringGrid1.Cells[2, StringGrid1.Row] := IntToHex(x, 1);
  1241. StringGrid1.Cells[3, StringGrid1.Row] := sps.getCommandText(cbCommand.ItemIndex, x);
  1242. end;
  1243. end;
  1244. procedure TForm1.cbTPSVersionChange(Sender: TObject);
  1245. begin
  1246. if (cbTPSVersion.ItemIndex = 0) then
  1247. begin
  1248. // HOLTEC
  1249. sps.setTPSVersion(Holtek);
  1250. Label2.Visible := True;
  1251. ADC2.Visible := True;
  1252. PWM2.Visible := False;
  1253. Label16.Visible := False;
  1254. RC1.Visible := False;
  1255. Label17.Visible := False;
  1256. RC2.Visible := False;
  1257. Servo1.Visible := False;
  1258. Servo2.Visible := False;
  1259. Shape1.Visible := False;
  1260. Shape2.Visible := False;
  1261. EditE.Visible := False;
  1262. EditF.Visible := False;
  1263. acUpload.Enabled := False;
  1264. Label5.Visible := False;
  1265. btnTone.Visible := False;
  1266. ADC1.Value := 0;
  1267. ADC1.MaxValue := 15;
  1268. ADC2.Value := 0;
  1269. ADC2.MaxValue := 15;
  1270. enableMicrobit(False);
  1271. end;
  1272. if (cbTPSVersion.ItemIndex = 1) then
  1273. begin
  1274. // ATMega8
  1275. sps.setTPSVersion(ATMega8);
  1276. Label2.Visible := True;
  1277. ADC2.Visible := True;
  1278. PWM2.Visible := True;
  1279. Label16.Visible := False;
  1280. RC1.Visible := False;
  1281. Label17.Visible := False;
  1282. RC2.Visible := False;
  1283. Servo1.Visible := False;
  1284. Servo2.Visible := False;
  1285. Shape1.Visible := False;
  1286. Shape2.Visible := False;
  1287. EditE.Visible := False;
  1288. EditF.Visible := False;
  1289. acUpload.Enabled := False;
  1290. Label5.Visible := False;
  1291. btnTone.Visible := False;
  1292. ADC1.Value := 0;
  1293. ADC1.MaxValue := 15;
  1294. ADC2.Value := 0;
  1295. ADC2.MaxValue := 15;
  1296. enableMicrobit(False);
  1297. end;
  1298. if ((cbTPSVersion.ItemIndex = 2) or (cbTPSVersion.ItemIndex = 3)) then
  1299. begin
  1300. if (cbTPSVersion.ItemIndex = 2) then
  1301. begin
  1302. // ATMega84
  1303. sps.setTPSVersion(ATTiny84);
  1304. acUpload.Enabled := False;
  1305. Label5.Visible := False;
  1306. btnTone.Visible := False;
  1307. end
  1308. else
  1309. begin
  1310. // Arduino 328
  1311. sps.setTPSVersion(Arduino);
  1312. acUpload.Enabled := True;
  1313. Label5.Visible := True;
  1314. btnTone.Visible := True;
  1315. end;
  1316. Label2.Visible := True;
  1317. ADC2.Visible := True;
  1318. PWM2.Visible := True;
  1319. Label16.Visible := True;
  1320. RC1.Visible := True;
  1321. Label17.Visible := True;
  1322. RC2.Visible := True;
  1323. Servo1.Visible := True;
  1324. Servo2.Visible := True;
  1325. Shape1.Visible := True;
  1326. Shape2.Visible := True;
  1327. EditE.Visible := True;
  1328. EditF.Visible := True;
  1329. ADC1.Value := 0;
  1330. ADC1.MaxValue := 255;
  1331. ADC2.Value := 0;
  1332. ADC2.MaxValue := 255;
  1333. enableMicrobit(False);
  1334. end;
  1335. if (cbTPSVersion.ItemIndex = 4) then
  1336. begin
  1337. // micro:bit
  1338. sps.setTPSVersion(microbit);
  1339. Label2.Visible := True;
  1340. ADC2.Visible := True;
  1341. PWM2.Visible := False;
  1342. Label16.Visible := False;
  1343. RC1.Visible := False;
  1344. Label17.Visible := False;
  1345. RC2.Visible := False;
  1346. Servo1.Visible := False;
  1347. Servo2.Visible := False;
  1348. Shape1.Visible := False;
  1349. Shape2.Visible := False;
  1350. EditE.Visible := False;
  1351. EditF.Visible := False;
  1352. acUpload.Enabled := True;
  1353. Label5.Visible := False;
  1354. btnTone.Visible := False;
  1355. ADC1.Value := 0;
  1356. ADC1.MaxValue := 15;
  1357. ADC2.Value := 0;
  1358. ADC2.MaxValue := 15;
  1359. enableMicrobit(False);
  1360. end;
  1361. if (cbTPSVersion.ItemIndex = 5) then
  1362. begin
  1363. // micro:bit v2
  1364. sps.setTPSVersion(MicroBitV2);
  1365. Label2.Visible := True;
  1366. ADC2.Visible := True;
  1367. PWM2.Visible := True;
  1368. Label16.Visible := True;
  1369. RC1.Visible := True;
  1370. Label17.Visible := True;
  1371. RC2.Visible := True;
  1372. Servo1.Visible := True;
  1373. Servo2.Visible := True;
  1374. Shape1.Visible := True;
  1375. Shape2.Visible := True;
  1376. EditE.Visible := True;
  1377. EditF.Visible := True;
  1378. acUpload.Enabled := True;
  1379. Label5.Visible := True;
  1380. btnTone.Visible := True;
  1381. ADC1.Value := 0;
  1382. ADC1.MaxValue := 15;
  1383. ADC2.Value := 0;
  1384. ADC2.MaxValue := 15;
  1385. enableMicrobit(True);
  1386. end;
  1387. cbCommand.Items.Clear;
  1388. sps.getCommands(cbCommand.Items);
  1389. end;
  1390. procedure TForm1.FormActivate(Sender: TObject);
  1391. begin
  1392. enableMicrobit(cbTPSVersion.ItemIndex = 5);
  1393. end;
  1394. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  1395. begin
  1396. canClose := checkDirty();
  1397. if canClose then
  1398. begin
  1399. if (sps.isActive()) then
  1400. begin
  1401. acStopExecute(Sender);
  1402. end;
  1403. end;
  1404. end;
  1405. procedure TForm1.StringGrid1EditingDone(Sender: TObject);
  1406. var
  1407. Value: string;
  1408. x: integer;
  1409. begin
  1410. // die aktuelle Zeile ist auch die letzte
  1411. if ((StringGrid1.Row + 1) = StringGrid1.RowCount) then
  1412. begin
  1413. // es wurde auch was eingegeben
  1414. Value := StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row];
  1415. Value := trim(Value);
  1416. if (Value <> '') then
  1417. begin
  1418. if StringGrid1.RowCount <= sps.getE2E() then begin
  1419. setDirty(True);
  1420. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  1421. renumberGrid();
  1422. end;
  1423. end;
  1424. end
  1425. else
  1426. begin
  1427. x := StringGrid1.Row;
  1428. StringGrid1.Cells[3, x] :=
  1429. sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]),
  1430. HexToInt(StringGrid1.Cells[2, x]));
  1431. setDirty(True);
  1432. end;
  1433. end;
  1434. procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow: integer);
  1435. begin
  1436. try
  1437. cbCommand.ItemIndex := HexToInt(StringGrid1.Cells[1, aRow]);
  1438. cbCommandChange(Sender);
  1439. cbData.ItemIndex := HexToInt(StringGrid1.Cells[2, aRow]);
  1440. except
  1441. end;
  1442. end;
  1443. procedure TForm1.loadPreset(filename: string);
  1444. var
  1445. x: integer;
  1446. key: string;
  1447. begin
  1448. for x := 1 to 8 do
  1449. begin
  1450. key := 'preset_' + IntToStr(x);
  1451. loadSection(filename, key);
  1452. end;
  1453. checkPresets;
  1454. end;
  1455. procedure TForm1.savePreset(filename: string);
  1456. var
  1457. x: integer;
  1458. key: string;
  1459. begin
  1460. for x := 1 to 8 do
  1461. begin
  1462. key := 'preset_' + IntToStr(x);
  1463. saveSection(filename, key);
  1464. end;
  1465. end;
  1466. procedure TForm1.activateSps(enable: boolean);
  1467. begin
  1468. GBControl.Enabled := enable;
  1469. GBInternal.Enabled := enable;
  1470. GBOutput.Enabled := enable;
  1471. end;
  1472. procedure TForm1.enableMicrobit(enable: boolean);
  1473. begin
  1474. if fMicrobit <> nil then
  1475. begin
  1476. if enable and not fMicrobit.Visible then
  1477. begin
  1478. fMicrobit.Show();
  1479. fMicrobit.Left := Left + Width + 8;
  1480. fMicrobit.Top := Top;
  1481. end;
  1482. if not enable and fMicrobit.Visible then
  1483. fMicrobit.Hide();
  1484. end;
  1485. end;
  1486. procedure TForm1.inputMicrobit();
  1487. begin
  1488. if (fMicrobit <> nil) and fMicrobit.Visible then
  1489. begin
  1490. sps.setACC(fMicrobit.accx.Value, fMicrobit.accz.Value, fMicrobit.accz.Value);
  1491. sps.setComp(fMicrobit.compass.Value);
  1492. sps.setLight(fMicrobit.light.Value);
  1493. sps.setSnd(fMicrobit.snd.Value);
  1494. sps.setGesture(fMicrobit.cbGesture.ItemIndex);
  1495. sps.setLogo(fMicrobit.tbLogo.Checked);
  1496. end;
  1497. end;
  1498. procedure TForm1.outputMicrobit();
  1499. var
  1500. image: TMBImage;
  1501. begin
  1502. if (fMicrobit <> nil) and fMicrobit.Visible then
  1503. begin
  1504. image := sps.getDisplay();
  1505. fMicrobit.setImage(image);
  1506. end;
  1507. end;
  1508. procedure TForm1.saveSection(filename: string; key: string);
  1509. begin
  1510. WriteIniBool(key, 'set', XMLPropStorage1.ReadBoolean(key + '.set', False), filename);
  1511. WriteIniBool(key, 'prg', XMLPropStorage1.ReadBoolean(key + '.prg', False), filename);
  1512. WriteIniBool(key, 'sel', XMLPropStorage1.ReadBoolean(key + '.sel', False), filename);
  1513. WriteIniBool(key, 'input1', XMLPropStorage1.ReadBoolean(key + '.input1', False),
  1514. filename);
  1515. WriteIniBool(key, 'input2', XMLPropStorage1.ReadBoolean(key + '.input2', False),
  1516. filename);
  1517. WriteIniBool(key, 'input3', XMLPropStorage1.ReadBoolean(key + '.input3', False),
  1518. filename);
  1519. WriteIniBool(key, 'input4', XMLPropStorage1.ReadBoolean(key + '.input4', False),
  1520. filename);
  1521. WriteIniInteger(key, 'adc1', XMLPropStorage1.ReadInteger(key + '.adc1', 0), filename);
  1522. WriteIniInteger(key, 'adc2', XMLPropStorage1.ReadInteger(key + '.adc2', 0), filename);
  1523. WriteIniInteger(key, 'rc1', XMLPropStorage1.ReadInteger(key + '.rc1', 0), filename);
  1524. WriteIniInteger(key, 'rc2', XMLPropStorage1.ReadInteger(key + '.rc2', 0), filename);
  1525. WriteIniBool(key, 'logo', XMLPropStorage1.ReadBoolean(key + '.logo', False), filename);
  1526. WriteIniInteger(key, 'accx', XMLPropStorage1.ReadInteger(key + '.accx', 0), filename);
  1527. WriteIniInteger(key, 'accy', XMLPropStorage1.ReadInteger(key + '.accy', 0), filename);
  1528. WriteIniInteger(key, 'accz', XMLPropStorage1.ReadInteger(key + '.accz', 0), filename);
  1529. WriteIniInteger(key, 'sound', XMLPropStorage1.ReadInteger(key + '.sound', 0),
  1530. filename);
  1531. WriteIniInteger(key, 'light', XMLPropStorage1.ReadInteger(key + '.light', 0),
  1532. filename);
  1533. WriteIniInteger(key, 'comp', XMLPropStorage1.ReadInteger(key + '.comp', 0), filename);
  1534. WriteIniInteger(key, 'gesture', XMLPropStorage1.ReadInteger(key +
  1535. '.gesture', 0), filename);
  1536. end;
  1537. procedure TForm1.loadSection(filename: string; key: string);
  1538. begin
  1539. XMLPropStorage1.WriteBoolean(key + '.set', ReadIniBool(key, 'set', False, filename));
  1540. XMLPropStorage1.WriteBoolean(key + '.prg', ReadIniBool(key, 'prg', False, filename));
  1541. XMLPropStorage1.WriteBoolean(key + '.sel', ReadIniBool(key, 'sel', False, filename));
  1542. XMLPropStorage1.WriteBoolean(key + '.input1', ReadIniBool(key,
  1543. 'input1', False, filename));
  1544. XMLPropStorage1.WriteBoolean(key + '.input2', ReadIniBool(key,
  1545. 'input2', False, filename));
  1546. XMLPropStorage1.WriteBoolean(key + '.input3', ReadIniBool(key,
  1547. 'input3', False, filename));
  1548. XMLPropStorage1.WriteBoolean(key + '.input4', ReadIniBool(key,
  1549. 'input4', False, filename));
  1550. XMLPropStorage1.WriteInteger(key + '.adc1', ReadIniInteger(key, 'adc1', 0, filename));
  1551. XMLPropStorage1.WriteInteger(key + '.adc2', ReadIniInteger(key, 'adc2', 0, filename));
  1552. XMLPropStorage1.WriteInteger(key + '.rc1', ReadIniInteger(key, 'rc1', 0, filename));
  1553. XMLPropStorage1.WriteInteger(key + '.rc2', ReadIniInteger(key, 'rc2', 0, filename));
  1554. XMLPropStorage1.WriteBoolean(key + '.logo', ReadIniBool(key, 'logo', False, filename));
  1555. XMLPropStorage1.WriteInteger(key + '.accx', ReadIniInteger(key, 'accx', 0, filename));
  1556. XMLPropStorage1.WriteInteger(key + '.accy', ReadIniInteger(key, 'accy', 0, filename));
  1557. XMLPropStorage1.WriteInteger(key + '.accz', ReadIniInteger(key, 'accz', 0, filename));
  1558. XMLPropStorage1.WriteInteger(key + '.sound', ReadIniInteger(key,
  1559. 'sound', 0, filename));
  1560. XMLPropStorage1.WriteInteger(key + '.light', ReadIniInteger(key,
  1561. 'light', 0, filename));
  1562. XMLPropStorage1.WriteInteger(key + '.comp', ReadIniInteger(key, 'comp', 0, filename));
  1563. XMLPropStorage1.WriteInteger(key + '.gesture', ReadIniInteger(key,
  1564. 'gesture', 0, filename));
  1565. end;
  1566. procedure TForm1.tbPreset1Click(Sender: TObject);
  1567. var
  1568. key: string;
  1569. begin
  1570. if Sender = tbPreset1 then
  1571. key := 'preset_1'
  1572. else
  1573. if Sender = tbPreset2 then
  1574. key := 'preset_2'
  1575. else
  1576. if Sender = tbPreset3 then
  1577. key := 'preset_3'
  1578. else
  1579. if Sender = tbPreset4 then
  1580. key := 'preset_4'
  1581. else
  1582. if Sender = tbPreset5 then
  1583. key := 'preset_5'
  1584. else
  1585. if Sender = tbPreset6 then
  1586. key := 'preset_6'
  1587. else
  1588. if Sender = tbPreset7 then
  1589. key := 'preset_7'
  1590. else
  1591. if Sender = tbPreset8 then
  1592. key := 'preset_8';
  1593. tbSel.Checked := XMLPropStorage1.ReadBoolean(key + '.prg', tbSel.Checked);
  1594. tbPrg.Checked := XMLPropStorage1.ReadBoolean(key + '.sel', tbPrg.Checked);
  1595. Din1.Checked := XMLPropStorage1.ReadBoolean(key + '.input1', Din1.Checked);
  1596. Din2.Checked := XMLPropStorage1.ReadBoolean(key + '.input2', Din2.Checked);
  1597. Din3.Checked := XMLPropStorage1.ReadBoolean(key + '.input3', Din3.Checked);
  1598. Din4.Checked := XMLPropStorage1.ReadBoolean(key + '.input4', Din4.Checked);
  1599. ADC1.Value := XMLPropStorage1.ReadInteger(key + '.adc1', ADC1.Value);
  1600. ADC2.Value := XMLPropStorage1.ReadInteger(key + '.adc2', ADC2.Value);
  1601. RC1.Value := XMLPropStorage1.ReadInteger(key + '.rc1', RC1.Value);
  1602. RC2.Value := XMLPropStorage1.ReadInteger(key + '.rc2', RC2.Value);
  1603. fMicrobit.tbLogo.Checked := XMLPropStorage1.ReadBoolean(key + '.logo',
  1604. fMicrobit.tbLogo.Checked);
  1605. fMicrobit.accx.Value := XMLPropStorage1.ReadInteger(key + '.accx',
  1606. fMicrobit.accx.Value);
  1607. fMicrobit.accy.Value := XMLPropStorage1.ReadInteger(key + '.accy',
  1608. fMicrobit.accy.Value);
  1609. fMicrobit.accz.Value := XMLPropStorage1.ReadInteger(key + '.accz',
  1610. fMicrobit.accz.Value);
  1611. fMicrobit.snd.Value := XMLPropStorage1.ReadInteger(key + '.sound',
  1612. fMicrobit.snd.Value);
  1613. fMicrobit.light.Value := XMLPropStorage1.ReadInteger(key + '.light',
  1614. fMicrobit.light.Value);
  1615. fMicrobit.compass.Value := XMLPropStorage1.ReadInteger(key + '.comp',
  1616. fMicrobit.compass.Value);
  1617. fMicrobit.cbGesture.ItemIndex :=
  1618. XMLPropStorage1.ReadInteger(key + '.gesture', fMicrobit.cbGesture.ItemIndex);
  1619. end;
  1620. procedure TForm1.tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint;
  1621. var Handled: boolean);
  1622. var
  1623. key: string;
  1624. begin
  1625. if Sender = tbPreset1 then
  1626. key := 'preset_1'
  1627. else
  1628. if Sender = tbPreset2 then
  1629. key := 'preset_2'
  1630. else
  1631. if Sender = tbPreset3 then
  1632. key := 'preset_3'
  1633. else
  1634. if Sender = tbPreset4 then
  1635. key := 'preset_4'
  1636. else
  1637. if Sender = tbPreset5 then
  1638. key := 'preset_5'
  1639. else
  1640. if Sender = tbPreset6 then
  1641. key := 'preset_6'
  1642. else
  1643. if Sender = tbPreset7 then
  1644. key := 'preset_7'
  1645. else
  1646. if Sender = tbPreset8 then
  1647. key := 'preset_8';
  1648. XMLPropStorage1.WriteBoolean(key + '.set', True);
  1649. XMLPropStorage1.WriteBoolean(key + '.prg', tbPrg.Checked);
  1650. XMLPropStorage1.WriteBoolean(key + '.sel', tbSel.Checked);
  1651. XMLPropStorage1.WriteBoolean(key + '.input1', Din1.Checked);
  1652. XMLPropStorage1.WriteBoolean(key + '.input2', Din2.Checked);
  1653. XMLPropStorage1.WriteBoolean(key + '.input3', Din3.Checked);
  1654. XMLPropStorage1.WriteBoolean(key + '.input4', Din4.Checked);
  1655. XMLPropStorage1.WriteInteger(key + '.adc1', ADC1.Value);
  1656. XMLPropStorage1.WriteInteger(key + '.adc2', ADC2.Value);
  1657. XMLPropStorage1.WriteInteger(key + '.rc1', RC1.Value);
  1658. XMLPropStorage1.WriteInteger(key + '.rc2', RC2.Value);
  1659. XMLPropStorage1.WriteBoolean(key + '.logo', fMicrobit.tbLogo.Checked);
  1660. XMLPropStorage1.WriteInteger(key + '.accx', fMicrobit.accx.Value);
  1661. XMLPropStorage1.WriteInteger(key + '.accy', fMicrobit.accy.Value);
  1662. XMLPropStorage1.WriteInteger(key + '.accz', fMicrobit.accz.Value);
  1663. XMLPropStorage1.WriteInteger(key + '.sound', fMicrobit.snd.Value);
  1664. XMLPropStorage1.WriteInteger(key + '.light', fMicrobit.light.Value);
  1665. XMLPropStorage1.WriteInteger(key + '.comp', fMicrobit.compass.Value);
  1666. XMLPropStorage1.WriteInteger(key + '.gesture', fMicrobit.cbGesture.ItemIndex);
  1667. checkPresets();
  1668. end;
  1669. procedure TForm1.tbPrgChange(Sender: TObject);
  1670. begin
  1671. if tbPrg.Checked then
  1672. begin
  1673. tbPrg.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_PRG_SEL', lsuCode);
  1674. end
  1675. else
  1676. begin
  1677. tbPrg.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_PRG_NON', lsuCode);
  1678. end;
  1679. end;
  1680. procedure TForm1.tbResetClick(Sender: TObject);
  1681. begin
  1682. tbPrg.Checked := False;
  1683. tbPrg.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_PRG_NON', lsuCode);
  1684. tbSel.Checked := False;
  1685. tbSel.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_SEL_NON', lsuCode);
  1686. Din1.Checked := False;
  1687. Din2.Checked := False;
  1688. Din3.Checked := False;
  1689. Din4.Checked := False;
  1690. ADC1.Value := 0;
  1691. ADC2.Value := 0;
  1692. RC1.Value := 8;
  1693. RC2.Value := 8;
  1694. end;
  1695. procedure TForm1.tbSelChange(Sender: TObject);
  1696. begin
  1697. if tbSel.Checked then
  1698. begin
  1699. tbSel.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_SEL_SEL', lsuCode);
  1700. end
  1701. else
  1702. begin
  1703. tbSel.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_SEL_NON', lsuCode);
  1704. end;
  1705. end;
  1706. procedure TForm1.Timer1Timer(Sender: TObject);
  1707. var
  1708. jsonString: string;
  1709. Data: TJSONData;
  1710. iNetVersion, version: string;
  1711. thisVersion, iVersion: TVersionRecord;
  1712. begin
  1713. MCSLabel.AutoSize := True;
  1714. Timer1.Enabled := False;
  1715. MCSLabel.Hint := InfoBox.versionHint;
  1716. if (InfoBox.newVersion) then
  1717. begin
  1718. MCSLabel.Font.Color := clred;
  1719. MCSLabel.Hint := InfoBox.versionHint + chr($0a) + chr($0d) +
  1720. MCSLSU.GetLSUText('form1Captions', 'ID_CLICK_HERE', lsuCode);
  1721. end;
  1722. MCSLabel.Caption := InfoBox.versionText;
  1723. end;
  1724. procedure TForm1.XMLPropStorage1RestoringProperties(Sender: TObject);
  1725. var
  1726. Uid: TGuid;
  1727. Result: HResult;
  1728. uuid: string;
  1729. begin
  1730. uuid := XMLPropStorage1.ReadString('AppUUID', '');
  1731. if uuid = '' then
  1732. begin
  1733. Result := CreateGuid(Uid);
  1734. if Result = S_OK then
  1735. begin
  1736. uuid := GuidToString(Uid);
  1737. XMLPropStorage1.WriteString('AppUUID', uuid);
  1738. end;
  1739. end;
  1740. Infobox.AppUUID := uuid;
  1741. end;
  1742. procedure TForm1.XMLPropStorage1SavingProperties(Sender: TObject);
  1743. begin
  1744. end;
  1745. procedure TForm1.renumberGrid;
  1746. var
  1747. x, i: integer;
  1748. begin
  1749. i := StringGrid1.RowCount;
  1750. for x := 1 to i - 1 do
  1751. begin
  1752. StringGrid1.Cells[0, x] := '0x' + inttohex(x - 1, 2);
  1753. if (StringGrid1.Cells[1, x] = '') then
  1754. StringGrid1.Cells[1, x] := '0';
  1755. if (StringGrid1.Cells[2, x] = '') then
  1756. StringGrid1.Cells[2, x] := '0';
  1757. StringGrid1.Cells[3, x] :=
  1758. sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]),
  1759. HexToInt(StringGrid1.Cells[2, x]));
  1760. end;
  1761. end;
  1762. procedure TForm1.selectAddress(addr: word);
  1763. begin
  1764. StringGrid1.Row := addr + 1;
  1765. Application.ProcessMessages;
  1766. end;
  1767. procedure TForm1.inputSps;
  1768. begin
  1769. sps.setDin1(Din1.Checked);
  1770. sps.setDin2(Din2.Checked);
  1771. sps.setDin3(Din3.Checked);
  1772. sps.setDin4(Din4.Checked);
  1773. sps.setADC1(ADC1.Value);
  1774. sps.setADC2(ADC2.Value);
  1775. sps.setRC1(RC1.Value);
  1776. sps.setRC2(RC2.Value);
  1777. sps.setSPrg(tbPrg.Checked);
  1778. sps.setSSel(tbSel.Checked);
  1779. end;
  1780. procedure TForm1.outputSps;
  1781. var
  1782. List: TStrings;
  1783. i: integer;
  1784. begin
  1785. if sps.isDout1() then
  1786. ShapeOut1.Brush.Color := clRed
  1787. else
  1788. ShapeOut1.Brush.Color := clWhite;
  1789. if sps.isDout2() then
  1790. ShapeOut2.Brush.Color := clRed
  1791. else
  1792. ShapeOut2.Brush.Color := clWhite;
  1793. if sps.isDout3() then
  1794. ShapeOut3.Brush.Color := clRed
  1795. else
  1796. ShapeOut3.Brush.Color := clWhite;
  1797. if sps.isDout4() then
  1798. ShapeOut4.Brush.Color := clRed
  1799. else
  1800. ShapeOut4.Brush.Color := clWhite;
  1801. PWM1.Text := IntToStr(sps.getPWM1());
  1802. PWM2.Text := IntToStr(sps.getPWM2());
  1803. Servo1.Text := IntToStr(sps.getServo1());
  1804. Shape1.Repaint;
  1805. Servo2.Text := IntToStr(sps.getServo2());
  1806. Shape2.Repaint;
  1807. EditA.Text := IntToStr(sps.getARegister());
  1808. EditB.Text := IntToStr(sps.getBRegister());
  1809. EditC.Text := IntToStr(sps.getCRegister());
  1810. EditD.Text := IntToStr(sps.getDRegister());
  1811. EditE.Text := IntToStr(sps.getERegister());
  1812. EditF.Text := IntToStr(sps.getFRegister());
  1813. EditAddr.Text := '0x' + IntToHex(sps.getAddress(), 2);
  1814. EditRAdr.Text := '0x' + IntToHex(sps.getRAdr(), 2);
  1815. EditPage.Text := '0x' + IntToHex(sps.getPage(), 2);
  1816. if (sps.getJump() > 0) then
  1817. EditJump.Text := '0x' + IntToHex(sps.getJump(), 2)
  1818. else
  1819. EditJump.Text := '';
  1820. if (sps.getTone() > 0) then
  1821. begin
  1822. ImageList2.GetBitmap(23, btnTone.Glyph);
  1823. i := round(440 * power(2.0, ((sps.getTone() - 69) / 12)));
  1824. btnTone.Caption := IntToStr(i);
  1825. if (lastNote <> sps.getTone()) then
  1826. begin
  1827. playNote(sps.getTone());
  1828. end;
  1829. btntone.Enabled := True;
  1830. end
  1831. else
  1832. begin
  1833. ImageList2.GetBitmap(22, btnTone.Glyph);
  1834. btnTone.Caption := '';
  1835. if (lastNote <> sps.getTone()) then
  1836. begin
  1837. playNote(0);
  1838. end;
  1839. btntone.Enabled := True;
  1840. end;
  1841. List := TStringList.Create;
  1842. try
  1843. sps.getStack(List);
  1844. lbStack.Clear;
  1845. for i := 0 to List.Count - 1 do
  1846. begin
  1847. lbStack.Items.Add(IntToStr(i) + ':' + List[i]);
  1848. end;
  1849. finally
  1850. List.Free;
  1851. end;
  1852. end;
  1853. end.