ugui.pas 53 KB

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