ugui.pas 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  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. retries: integer;
  955. begin
  956. error := False;
  957. if cbTPSVersion.ItemIndex = 4 then
  958. begin
  959. // microbit code
  960. SaveBinFile.FileName := 'mycobit';
  961. if (SaveBinFile.Execute) then
  962. begin
  963. filename := SaveBinFile.FileName;
  964. makeBinFile(filename);
  965. end;
  966. end
  967. else
  968. begin
  969. line := GetSerialPortNames;
  970. // if (line <> '') then
  971. begin
  972. comServices := TStringList.Create;
  973. MCSStrings.DelimTextToStringlist(line, ',', comServices);
  974. return := mrOk;
  975. line := XMLPropStorage1.ReadString('ComPort', comServices[0]);
  976. frmSelectCom := TfrmSelectCom.Create(self);
  977. frmSelectCom.cbServices.Items.AddStrings(comServices);
  978. frmSelectCom.cbServices.Text := line;
  979. return := frmSelectCom.ShowModal;
  980. comService := frmSelectCom.cbServices.Text;
  981. XMLPropStorage1.WriteString('ComPort', comService);
  982. comServices.Free;
  983. if (return = mrOk) then
  984. begin
  985. hexFile := serialUpload;
  986. SdpoSerial1.BaudRate := br__9600;
  987. if cbTPSVersion.ItemIndex = 5 then
  988. begin
  989. // Micro:bit V2 auto programm
  990. SdpoSerial1.BaudRate := br115200;
  991. end;
  992. SdpoSerial1.Device := comService;
  993. SdpoSerial1.Active := True;
  994. error := true;
  995. while retries < 10 do
  996. begin
  997. SdpoSerial1.WriteData('p');
  998. if (readString(line)) then
  999. begin
  1000. if (pos('command', line) > 0) then
  1001. begin
  1002. retries := 10;
  1003. error := false;
  1004. end;
  1005. end;
  1006. SdpoSerial1.WriteData('h');
  1007. inc(retries);
  1008. end;
  1009. if (not error) then
  1010. begin
  1011. SdpoSerial1.WriteData('w');
  1012. if (readString(line)) then
  1013. begin
  1014. if (pos('ready', line) > 0) then
  1015. begin
  1016. Lines := TStringList.Create;
  1017. Lines.LoadFromFile(hexFile);
  1018. for x := 0 to Lines.Count - 1 do
  1019. begin
  1020. SdpoSerial1.WriteData(Lines.Strings[x]);
  1021. SdpoSerial1.WriteData(CRLF);
  1022. Sleep(250);
  1023. end;
  1024. SdpoSerial1.WriteData('e');
  1025. end
  1026. else
  1027. begin
  1028. error := True;
  1029. end;
  1030. end;
  1031. end;
  1032. if (error) then
  1033. begin
  1034. LSUAutoMsgBox('Messages', 'ID_NOT_READY', MB_OK + MB_ICONERROR);
  1035. end
  1036. else
  1037. begin
  1038. LSUAutoMsgBox('Messages', 'ID_UPLOAD_OK', MB_OK + MB_ICONINFORMATION);
  1039. end;
  1040. SdpoSerial1.Active := False;
  1041. DeleteFile(hexFile);
  1042. end;
  1043. end;
  1044. end;
  1045. end;
  1046. function TForm1.readString(var line: string): boolean;
  1047. var
  1048. TimeOut: integer;
  1049. begin
  1050. Result := False;
  1051. TimeOut := 10;
  1052. while ((not SdpoSerial1.DataAvailable) and (TimeOut > 0)) do
  1053. begin
  1054. Dec(TimeOut);
  1055. Sleep(1000);
  1056. end;
  1057. if (Timeout > 0) then
  1058. begin
  1059. line := SdpoSerial1.ReadData;
  1060. Result := True;
  1061. end;
  1062. end;
  1063. procedure TForm1.setDirty(Value: boolean);
  1064. begin
  1065. if (dirty <> Value) then
  1066. begin
  1067. dirty := Value;
  1068. if (dirty) then
  1069. begin
  1070. if (Pos('*', Caption) = 0) then
  1071. begin
  1072. Caption := Caption + '*';
  1073. end;
  1074. end
  1075. else
  1076. begin
  1077. if (Pos('*', Caption) > 0) then
  1078. begin
  1079. Caption := Leftstr(Caption, Pos('*', Caption) - 1);
  1080. end;
  1081. end;
  1082. end;
  1083. end;
  1084. function TForm1.checkDirty: boolean;
  1085. var
  1086. i: integer;
  1087. begin
  1088. if (dirty) then
  1089. begin
  1090. i := MCSLSU.LSUAutoMsgBox('Messages', 'SAVE_CHANGES', MB_ICONQUESTION or
  1091. MB_YESNOCANCEL);
  1092. if (i = mrYes) then
  1093. begin
  1094. saveFile(activeFile);
  1095. Result := True;
  1096. end
  1097. else if (i = mrNo) then
  1098. begin
  1099. setDirty(False);
  1100. Result := True;
  1101. end
  1102. else
  1103. begin
  1104. Result := False;
  1105. end;
  1106. end
  1107. else
  1108. begin
  1109. Result := True;
  1110. end;
  1111. end;
  1112. procedure TForm1.checkPresets;
  1113. begin
  1114. if XMLPropStorage1.ReadBoolean('preset_1.set', False) then
  1115. tbPreset1.Caption := '1*'
  1116. else
  1117. tbPreset1.Caption := '1';
  1118. if XMLPropStorage1.ReadBoolean('preset_2.set', False) then
  1119. tbPreset2.Caption := '2*'
  1120. else
  1121. tbPreset2.Caption := '2';
  1122. if XMLPropStorage1.ReadBoolean('preset_3.set', False) then
  1123. tbPreset3.Caption := '3*'
  1124. else
  1125. tbPreset3.Caption := '3';
  1126. if XMLPropStorage1.ReadBoolean('preset_4.set', False) then
  1127. tbPreset4.Caption := '4*'
  1128. else
  1129. tbPreset4.Caption := '4';
  1130. if XMLPropStorage1.ReadBoolean('preset_5.set', False) then
  1131. tbPreset5.Caption := '5*'
  1132. else
  1133. tbPreset5.Caption := '5';
  1134. if XMLPropStorage1.ReadBoolean('preset_6.set', False) then
  1135. tbPreset6.Caption := '6*'
  1136. else
  1137. tbPreset6.Caption := '6';
  1138. if XMLPropStorage1.ReadBoolean('preset_7.set', False) then
  1139. tbPreset7.Caption := '7*'
  1140. else
  1141. tbPreset7.Caption := '7';
  1142. if XMLPropStorage1.ReadBoolean('preset_8.set', False) then
  1143. tbPreset7.Caption := '8*'
  1144. else
  1145. tbPreset7.Caption := '8';
  1146. end;
  1147. procedure TForm1.makeHexFile(fileName: string);
  1148. var
  1149. i, x: integer;
  1150. tmp: string;
  1151. hexFormat: TIntelHexFormat;
  1152. prgMem: array of byte;
  1153. com, Data: byte;
  1154. begin
  1155. i := StringGrid1.RowCount;
  1156. SetLength(prgMem, i);
  1157. for x := 1 to i - 1 do
  1158. begin
  1159. com := 0;
  1160. Data := 0;
  1161. tmp := StringGrid1.Cells[1, x];
  1162. if (tmp <> '') then
  1163. begin
  1164. com := HexToInt(tmp);
  1165. tmp := StringGrid1.Cells[2, x];
  1166. if (tmp <> '') then
  1167. Data := HexToInt(tmp);
  1168. Data := com * 16 + Data;
  1169. end;
  1170. prgMem[x - 1] := Data;
  1171. end;
  1172. hexFormat := TIntelHexFormat.Create(prgMem, 8);
  1173. tmp := hexFormat.Text;
  1174. MCSIO.StrToFile(fileName, tmp);
  1175. hexFormat.Free;
  1176. SetLength(prgMem, 0);
  1177. end;
  1178. procedure TForm1.makeBinFile(fileName: string);
  1179. var
  1180. i, x: integer;
  1181. tmp: string;
  1182. hexFormat: TIntelHexFormat;
  1183. com, Data: byte;
  1184. f: file of byte;
  1185. begin
  1186. i := StringGrid1.RowCount;
  1187. AssignFile(f, fileName);
  1188. Rewrite(f, 1);
  1189. for x := 1 to i - 1 do
  1190. begin
  1191. com := 0;
  1192. Data := 0;
  1193. tmp := StringGrid1.Cells[1, x];
  1194. if (tmp <> '') then
  1195. begin
  1196. com := HexToInt(tmp);
  1197. tmp := StringGrid1.Cells[2, x];
  1198. if (tmp <> '') then
  1199. Data := HexToInt(tmp);
  1200. Data := com * 16 + Data;
  1201. end;
  1202. Write(f, Data);
  1203. end;
  1204. CloseFile(f);
  1205. end;
  1206. procedure TForm1.setCaption;
  1207. begin
  1208. if (activeFile = '') then
  1209. begin
  1210. Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode);
  1211. end
  1212. else
  1213. begin
  1214. Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode) +
  1215. ':' + ExtractFileName(activeFile);
  1216. end;
  1217. end;
  1218. procedure TForm1.addHeaderText;
  1219. var
  1220. i: integer;
  1221. begin
  1222. for i := 0 to StringGrid1.Columns.Count - 1 do
  1223. begin
  1224. ;
  1225. StringGrid1.Columns[i].Title.Caption :=
  1226. MCSLSU.GetLSUText('form1Captions', StringGrid1.Columns[i].Title.Caption, lsuCode);
  1227. end;
  1228. StringGrid1.Cells[0, 0] := MCSLSU.GetLSUText('form1Captions',
  1229. 'ID_GRID_STORAGE', lsuCode);
  1230. StringGrid1.Repaint;
  1231. end;
  1232. procedure TForm1.cbCommandChange(Sender: TObject);
  1233. var
  1234. x: integer;
  1235. begin
  1236. cbData.Items.Clear;
  1237. x := cbCommand.ItemIndex;
  1238. sps.getDatas(x, cbData.Items);
  1239. if StringGrid1.Row > 0 then
  1240. begin
  1241. StringGrid1.Cells[1, StringGrid1.Row] := IntToHex(x, 1);
  1242. end;
  1243. end;
  1244. procedure TForm1.cbDataChange(Sender: TObject);
  1245. var
  1246. x: integer;
  1247. begin
  1248. x := cbData.ItemIndex;
  1249. if StringGrid1.Row > 0 then
  1250. begin
  1251. StringGrid1.Cells[2, StringGrid1.Row] := IntToHex(x, 1);
  1252. StringGrid1.Cells[3, StringGrid1.Row] := sps.getCommandText(cbCommand.ItemIndex, x);
  1253. end;
  1254. end;
  1255. procedure TForm1.cbTPSVersionChange(Sender: TObject);
  1256. begin
  1257. if (cbTPSVersion.ItemIndex = 0) then
  1258. begin
  1259. // HOLTEC
  1260. sps.setTPSVersion(Holtek);
  1261. Label2.Visible := True;
  1262. ADC2.Visible := True;
  1263. PWM2.Visible := False;
  1264. Label16.Visible := False;
  1265. RC1.Visible := False;
  1266. Label17.Visible := False;
  1267. RC2.Visible := False;
  1268. Servo1.Visible := False;
  1269. Servo2.Visible := False;
  1270. Shape1.Visible := False;
  1271. Shape2.Visible := False;
  1272. EditE.Visible := False;
  1273. EditF.Visible := False;
  1274. acUpload.Enabled := False;
  1275. Label5.Visible := False;
  1276. btnTone.Visible := False;
  1277. ADC1.Value := 0;
  1278. ADC1.MaxValue := 15;
  1279. ADC2.Value := 0;
  1280. ADC2.MaxValue := 15;
  1281. enableMicrobit(False);
  1282. end;
  1283. if (cbTPSVersion.ItemIndex = 1) then
  1284. begin
  1285. // ATMega8
  1286. sps.setTPSVersion(ATMega8);
  1287. Label2.Visible := True;
  1288. ADC2.Visible := True;
  1289. PWM2.Visible := True;
  1290. Label16.Visible := False;
  1291. RC1.Visible := False;
  1292. Label17.Visible := False;
  1293. RC2.Visible := False;
  1294. Servo1.Visible := False;
  1295. Servo2.Visible := False;
  1296. Shape1.Visible := False;
  1297. Shape2.Visible := False;
  1298. EditE.Visible := False;
  1299. EditF.Visible := False;
  1300. acUpload.Enabled := False;
  1301. Label5.Visible := False;
  1302. btnTone.Visible := False;
  1303. ADC1.Value := 0;
  1304. ADC1.MaxValue := 15;
  1305. ADC2.Value := 0;
  1306. ADC2.MaxValue := 15;
  1307. enableMicrobit(False);
  1308. end;
  1309. if ((cbTPSVersion.ItemIndex = 2) or (cbTPSVersion.ItemIndex = 3)) then
  1310. begin
  1311. if (cbTPSVersion.ItemIndex = 2) then
  1312. begin
  1313. // ATMega84
  1314. sps.setTPSVersion(ATTiny84);
  1315. acUpload.Enabled := False;
  1316. Label5.Visible := False;
  1317. btnTone.Visible := False;
  1318. end
  1319. else
  1320. begin
  1321. // Arduino 328
  1322. sps.setTPSVersion(Arduino);
  1323. acUpload.Enabled := True;
  1324. Label5.Visible := True;
  1325. btnTone.Visible := True;
  1326. end;
  1327. Label2.Visible := True;
  1328. ADC2.Visible := True;
  1329. PWM2.Visible := True;
  1330. Label16.Visible := True;
  1331. RC1.Visible := True;
  1332. Label17.Visible := True;
  1333. RC2.Visible := True;
  1334. Servo1.Visible := True;
  1335. Servo2.Visible := True;
  1336. Shape1.Visible := True;
  1337. Shape2.Visible := True;
  1338. EditE.Visible := True;
  1339. EditF.Visible := True;
  1340. ADC1.Value := 0;
  1341. ADC1.MaxValue := 255;
  1342. ADC2.Value := 0;
  1343. ADC2.MaxValue := 255;
  1344. enableMicrobit(False);
  1345. end;
  1346. if (cbTPSVersion.ItemIndex = 4) then
  1347. begin
  1348. // micro:bit
  1349. sps.setTPSVersion(microbit);
  1350. Label2.Visible := True;
  1351. ADC2.Visible := True;
  1352. PWM2.Visible := False;
  1353. Label16.Visible := False;
  1354. RC1.Visible := False;
  1355. Label17.Visible := False;
  1356. RC2.Visible := False;
  1357. Servo1.Visible := False;
  1358. Servo2.Visible := False;
  1359. Shape1.Visible := False;
  1360. Shape2.Visible := False;
  1361. EditE.Visible := False;
  1362. EditF.Visible := False;
  1363. acUpload.Enabled := True;
  1364. Label5.Visible := False;
  1365. btnTone.Visible := False;
  1366. ADC1.Value := 0;
  1367. ADC1.MaxValue := 15;
  1368. ADC2.Value := 0;
  1369. ADC2.MaxValue := 15;
  1370. enableMicrobit(False);
  1371. end;
  1372. if (cbTPSVersion.ItemIndex = 5) then
  1373. begin
  1374. // micro:bit v2
  1375. sps.setTPSVersion(MicroBitV2);
  1376. Label2.Visible := True;
  1377. ADC2.Visible := True;
  1378. PWM2.Visible := True;
  1379. Label16.Visible := True;
  1380. RC1.Visible := True;
  1381. Label17.Visible := True;
  1382. RC2.Visible := True;
  1383. Servo1.Visible := True;
  1384. Servo2.Visible := True;
  1385. Shape1.Visible := True;
  1386. Shape2.Visible := True;
  1387. EditE.Visible := True;
  1388. EditF.Visible := True;
  1389. acUpload.Enabled := True;
  1390. Label5.Visible := True;
  1391. btnTone.Visible := True;
  1392. ADC1.Value := 0;
  1393. ADC1.MaxValue := 15;
  1394. ADC2.Value := 0;
  1395. ADC2.MaxValue := 15;
  1396. enableMicrobit(True);
  1397. end;
  1398. cbCommand.Items.Clear;
  1399. sps.getCommands(cbCommand.Items);
  1400. end;
  1401. procedure TForm1.FormActivate(Sender: TObject);
  1402. begin
  1403. enableMicrobit(cbTPSVersion.ItemIndex = 5);
  1404. end;
  1405. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  1406. begin
  1407. canClose := checkDirty();
  1408. if canClose then
  1409. begin
  1410. if (sps.isActive()) then
  1411. begin
  1412. acStopExecute(Sender);
  1413. end;
  1414. end;
  1415. end;
  1416. procedure TForm1.StringGrid1EditingDone(Sender: TObject);
  1417. var
  1418. Value: string;
  1419. x: integer;
  1420. begin
  1421. // die aktuelle Zeile ist auch die letzte
  1422. if ((StringGrid1.Row + 1) = StringGrid1.RowCount) then
  1423. begin
  1424. // es wurde auch was eingegeben
  1425. Value := StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row];
  1426. Value := trim(Value);
  1427. if (Value <> '') then
  1428. begin
  1429. if StringGrid1.RowCount <= sps.getE2E() then begin
  1430. setDirty(True);
  1431. StringGrid1.RowCount := StringGrid1.RowCount + 1;
  1432. renumberGrid();
  1433. end;
  1434. end;
  1435. end
  1436. else
  1437. begin
  1438. x := StringGrid1.Row;
  1439. StringGrid1.Cells[3, x] :=
  1440. sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]),
  1441. HexToInt(StringGrid1.Cells[2, x]));
  1442. setDirty(True);
  1443. end;
  1444. end;
  1445. procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow: integer);
  1446. begin
  1447. try
  1448. cbCommand.ItemIndex := HexToInt(StringGrid1.Cells[1, aRow]);
  1449. cbCommandChange(Sender);
  1450. cbData.ItemIndex := HexToInt(StringGrid1.Cells[2, aRow]);
  1451. except
  1452. end;
  1453. end;
  1454. procedure TForm1.loadPreset(filename: string);
  1455. var
  1456. x: integer;
  1457. key: string;
  1458. begin
  1459. for x := 1 to 8 do
  1460. begin
  1461. key := 'preset_' + IntToStr(x);
  1462. loadSection(filename, key);
  1463. end;
  1464. checkPresets;
  1465. end;
  1466. procedure TForm1.savePreset(filename: string);
  1467. var
  1468. x: integer;
  1469. key: string;
  1470. begin
  1471. for x := 1 to 8 do
  1472. begin
  1473. key := 'preset_' + IntToStr(x);
  1474. saveSection(filename, key);
  1475. end;
  1476. end;
  1477. procedure TForm1.activateSps(enable: boolean);
  1478. begin
  1479. GBControl.Enabled := enable;
  1480. GBInternal.Enabled := enable;
  1481. GBOutput.Enabled := enable;
  1482. end;
  1483. procedure TForm1.enableMicrobit(enable: boolean);
  1484. begin
  1485. if fMicrobit <> nil then
  1486. begin
  1487. if enable and not fMicrobit.Visible then
  1488. begin
  1489. fMicrobit.Show();
  1490. fMicrobit.Left := Left + Width + 8;
  1491. fMicrobit.Top := Top;
  1492. end;
  1493. if not enable and fMicrobit.Visible then
  1494. fMicrobit.Hide();
  1495. end;
  1496. end;
  1497. procedure TForm1.inputMicrobit();
  1498. begin
  1499. if (fMicrobit <> nil) and fMicrobit.Visible then
  1500. begin
  1501. sps.setACC(fMicrobit.accx.Value, fMicrobit.accz.Value, fMicrobit.accz.Value);
  1502. sps.setComp(fMicrobit.compass.Value);
  1503. sps.setLight(fMicrobit.light.Value);
  1504. sps.setSnd(fMicrobit.snd.Value);
  1505. sps.setGesture(fMicrobit.cbGesture.ItemIndex);
  1506. sps.setLogo(fMicrobit.tbLogo.Checked);
  1507. end;
  1508. end;
  1509. procedure TForm1.outputMicrobit();
  1510. var
  1511. image: TMBImage;
  1512. begin
  1513. if (fMicrobit <> nil) and fMicrobit.Visible then
  1514. begin
  1515. image := sps.getDisplay();
  1516. fMicrobit.setImage(image);
  1517. end;
  1518. end;
  1519. procedure TForm1.saveSection(filename: string; key: string);
  1520. begin
  1521. WriteIniBool(key, 'set', XMLPropStorage1.ReadBoolean(key + '.set', False), filename);
  1522. WriteIniBool(key, 'prg', XMLPropStorage1.ReadBoolean(key + '.prg', False), filename);
  1523. WriteIniBool(key, 'sel', XMLPropStorage1.ReadBoolean(key + '.sel', False), filename);
  1524. WriteIniBool(key, 'input1', XMLPropStorage1.ReadBoolean(key + '.input1', False),
  1525. filename);
  1526. WriteIniBool(key, 'input2', XMLPropStorage1.ReadBoolean(key + '.input2', False),
  1527. filename);
  1528. WriteIniBool(key, 'input3', XMLPropStorage1.ReadBoolean(key + '.input3', False),
  1529. filename);
  1530. WriteIniBool(key, 'input4', XMLPropStorage1.ReadBoolean(key + '.input4', False),
  1531. filename);
  1532. WriteIniInteger(key, 'adc1', XMLPropStorage1.ReadInteger(key + '.adc1', 0), filename);
  1533. WriteIniInteger(key, 'adc2', XMLPropStorage1.ReadInteger(key + '.adc2', 0), filename);
  1534. WriteIniInteger(key, 'rc1', XMLPropStorage1.ReadInteger(key + '.rc1', 0), filename);
  1535. WriteIniInteger(key, 'rc2', XMLPropStorage1.ReadInteger(key + '.rc2', 0), filename);
  1536. WriteIniBool(key, 'logo', XMLPropStorage1.ReadBoolean(key + '.logo', False), filename);
  1537. WriteIniInteger(key, 'accx', XMLPropStorage1.ReadInteger(key + '.accx', 0), filename);
  1538. WriteIniInteger(key, 'accy', XMLPropStorage1.ReadInteger(key + '.accy', 0), filename);
  1539. WriteIniInteger(key, 'accz', XMLPropStorage1.ReadInteger(key + '.accz', 0), filename);
  1540. WriteIniInteger(key, 'sound', XMLPropStorage1.ReadInteger(key + '.sound', 0),
  1541. filename);
  1542. WriteIniInteger(key, 'light', XMLPropStorage1.ReadInteger(key + '.light', 0),
  1543. filename);
  1544. WriteIniInteger(key, 'comp', XMLPropStorage1.ReadInteger(key + '.comp', 0), filename);
  1545. WriteIniInteger(key, 'gesture', XMLPropStorage1.ReadInteger(key +
  1546. '.gesture', 0), filename);
  1547. end;
  1548. procedure TForm1.loadSection(filename: string; key: string);
  1549. begin
  1550. XMLPropStorage1.WriteBoolean(key + '.set', ReadIniBool(key, 'set', False, filename));
  1551. XMLPropStorage1.WriteBoolean(key + '.prg', ReadIniBool(key, 'prg', False, filename));
  1552. XMLPropStorage1.WriteBoolean(key + '.sel', ReadIniBool(key, 'sel', False, filename));
  1553. XMLPropStorage1.WriteBoolean(key + '.input1', ReadIniBool(key,
  1554. 'input1', False, filename));
  1555. XMLPropStorage1.WriteBoolean(key + '.input2', ReadIniBool(key,
  1556. 'input2', False, filename));
  1557. XMLPropStorage1.WriteBoolean(key + '.input3', ReadIniBool(key,
  1558. 'input3', False, filename));
  1559. XMLPropStorage1.WriteBoolean(key + '.input4', ReadIniBool(key,
  1560. 'input4', False, filename));
  1561. XMLPropStorage1.WriteInteger(key + '.adc1', ReadIniInteger(key, 'adc1', 0, filename));
  1562. XMLPropStorage1.WriteInteger(key + '.adc2', ReadIniInteger(key, 'adc2', 0, filename));
  1563. XMLPropStorage1.WriteInteger(key + '.rc1', ReadIniInteger(key, 'rc1', 0, filename));
  1564. XMLPropStorage1.WriteInteger(key + '.rc2', ReadIniInteger(key, 'rc2', 0, filename));
  1565. XMLPropStorage1.WriteBoolean(key + '.logo', ReadIniBool(key, 'logo', False, filename));
  1566. XMLPropStorage1.WriteInteger(key + '.accx', ReadIniInteger(key, 'accx', 0, filename));
  1567. XMLPropStorage1.WriteInteger(key + '.accy', ReadIniInteger(key, 'accy', 0, filename));
  1568. XMLPropStorage1.WriteInteger(key + '.accz', ReadIniInteger(key, 'accz', 0, filename));
  1569. XMLPropStorage1.WriteInteger(key + '.sound', ReadIniInteger(key,
  1570. 'sound', 0, filename));
  1571. XMLPropStorage1.WriteInteger(key + '.light', ReadIniInteger(key,
  1572. 'light', 0, filename));
  1573. XMLPropStorage1.WriteInteger(key + '.comp', ReadIniInteger(key, 'comp', 0, filename));
  1574. XMLPropStorage1.WriteInteger(key + '.gesture', ReadIniInteger(key,
  1575. 'gesture', 0, filename));
  1576. end;
  1577. procedure TForm1.tbPreset1Click(Sender: TObject);
  1578. var
  1579. key: string;
  1580. begin
  1581. if Sender = tbPreset1 then
  1582. key := 'preset_1'
  1583. else
  1584. if Sender = tbPreset2 then
  1585. key := 'preset_2'
  1586. else
  1587. if Sender = tbPreset3 then
  1588. key := 'preset_3'
  1589. else
  1590. if Sender = tbPreset4 then
  1591. key := 'preset_4'
  1592. else
  1593. if Sender = tbPreset5 then
  1594. key := 'preset_5'
  1595. else
  1596. if Sender = tbPreset6 then
  1597. key := 'preset_6'
  1598. else
  1599. if Sender = tbPreset7 then
  1600. key := 'preset_7'
  1601. else
  1602. if Sender = tbPreset8 then
  1603. key := 'preset_8';
  1604. tbSel.Checked := XMLPropStorage1.ReadBoolean(key + '.prg', tbSel.Checked);
  1605. tbPrg.Checked := XMLPropStorage1.ReadBoolean(key + '.sel', tbPrg.Checked);
  1606. Din1.Checked := XMLPropStorage1.ReadBoolean(key + '.input1', Din1.Checked);
  1607. Din2.Checked := XMLPropStorage1.ReadBoolean(key + '.input2', Din2.Checked);
  1608. Din3.Checked := XMLPropStorage1.ReadBoolean(key + '.input3', Din3.Checked);
  1609. Din4.Checked := XMLPropStorage1.ReadBoolean(key + '.input4', Din4.Checked);
  1610. ADC1.Value := XMLPropStorage1.ReadInteger(key + '.adc1', ADC1.Value);
  1611. ADC2.Value := XMLPropStorage1.ReadInteger(key + '.adc2', ADC2.Value);
  1612. RC1.Value := XMLPropStorage1.ReadInteger(key + '.rc1', RC1.Value);
  1613. RC2.Value := XMLPropStorage1.ReadInteger(key + '.rc2', RC2.Value);
  1614. fMicrobit.tbLogo.Checked := XMLPropStorage1.ReadBoolean(key + '.logo',
  1615. fMicrobit.tbLogo.Checked);
  1616. fMicrobit.accx.Value := XMLPropStorage1.ReadInteger(key + '.accx',
  1617. fMicrobit.accx.Value);
  1618. fMicrobit.accy.Value := XMLPropStorage1.ReadInteger(key + '.accy',
  1619. fMicrobit.accy.Value);
  1620. fMicrobit.accz.Value := XMLPropStorage1.ReadInteger(key + '.accz',
  1621. fMicrobit.accz.Value);
  1622. fMicrobit.snd.Value := XMLPropStorage1.ReadInteger(key + '.sound',
  1623. fMicrobit.snd.Value);
  1624. fMicrobit.light.Value := XMLPropStorage1.ReadInteger(key + '.light',
  1625. fMicrobit.light.Value);
  1626. fMicrobit.compass.Value := XMLPropStorage1.ReadInteger(key + '.comp',
  1627. fMicrobit.compass.Value);
  1628. fMicrobit.cbGesture.ItemIndex :=
  1629. XMLPropStorage1.ReadInteger(key + '.gesture', fMicrobit.cbGesture.ItemIndex);
  1630. end;
  1631. procedure TForm1.tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint;
  1632. var Handled: boolean);
  1633. var
  1634. key: string;
  1635. begin
  1636. if Sender = tbPreset1 then
  1637. key := 'preset_1'
  1638. else
  1639. if Sender = tbPreset2 then
  1640. key := 'preset_2'
  1641. else
  1642. if Sender = tbPreset3 then
  1643. key := 'preset_3'
  1644. else
  1645. if Sender = tbPreset4 then
  1646. key := 'preset_4'
  1647. else
  1648. if Sender = tbPreset5 then
  1649. key := 'preset_5'
  1650. else
  1651. if Sender = tbPreset6 then
  1652. key := 'preset_6'
  1653. else
  1654. if Sender = tbPreset7 then
  1655. key := 'preset_7'
  1656. else
  1657. if Sender = tbPreset8 then
  1658. key := 'preset_8';
  1659. XMLPropStorage1.WriteBoolean(key + '.set', True);
  1660. XMLPropStorage1.WriteBoolean(key + '.prg', tbPrg.Checked);
  1661. XMLPropStorage1.WriteBoolean(key + '.sel', tbSel.Checked);
  1662. XMLPropStorage1.WriteBoolean(key + '.input1', Din1.Checked);
  1663. XMLPropStorage1.WriteBoolean(key + '.input2', Din2.Checked);
  1664. XMLPropStorage1.WriteBoolean(key + '.input3', Din3.Checked);
  1665. XMLPropStorage1.WriteBoolean(key + '.input4', Din4.Checked);
  1666. XMLPropStorage1.WriteInteger(key + '.adc1', ADC1.Value);
  1667. XMLPropStorage1.WriteInteger(key + '.adc2', ADC2.Value);
  1668. XMLPropStorage1.WriteInteger(key + '.rc1', RC1.Value);
  1669. XMLPropStorage1.WriteInteger(key + '.rc2', RC2.Value);
  1670. XMLPropStorage1.WriteBoolean(key + '.logo', fMicrobit.tbLogo.Checked);
  1671. XMLPropStorage1.WriteInteger(key + '.accx', fMicrobit.accx.Value);
  1672. XMLPropStorage1.WriteInteger(key + '.accy', fMicrobit.accy.Value);
  1673. XMLPropStorage1.WriteInteger(key + '.accz', fMicrobit.accz.Value);
  1674. XMLPropStorage1.WriteInteger(key + '.sound', fMicrobit.snd.Value);
  1675. XMLPropStorage1.WriteInteger(key + '.light', fMicrobit.light.Value);
  1676. XMLPropStorage1.WriteInteger(key + '.comp', fMicrobit.compass.Value);
  1677. XMLPropStorage1.WriteInteger(key + '.gesture', fMicrobit.cbGesture.ItemIndex);
  1678. checkPresets();
  1679. end;
  1680. procedure TForm1.tbPrgChange(Sender: TObject);
  1681. begin
  1682. if tbPrg.Checked then
  1683. begin
  1684. tbPrg.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_PRG_SEL', lsuCode);
  1685. end
  1686. else
  1687. begin
  1688. tbPrg.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_PRG_NON', lsuCode);
  1689. end;
  1690. end;
  1691. procedure TForm1.tbResetClick(Sender: TObject);
  1692. begin
  1693. tbPrg.Checked := False;
  1694. tbPrg.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_PRG_NON', lsuCode);
  1695. tbSel.Checked := False;
  1696. tbSel.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_SEL_NON', lsuCode);
  1697. Din1.Checked := False;
  1698. Din2.Checked := False;
  1699. Din3.Checked := False;
  1700. Din4.Checked := False;
  1701. ADC1.Value := 0;
  1702. ADC2.Value := 0;
  1703. RC1.Value := 8;
  1704. RC2.Value := 8;
  1705. end;
  1706. procedure TForm1.tbSelChange(Sender: TObject);
  1707. begin
  1708. if tbSel.Checked then
  1709. begin
  1710. tbSel.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_SEL_SEL', lsuCode);
  1711. end
  1712. else
  1713. begin
  1714. tbSel.Hint := MCSLSU.GetLSUText('form1Hints', 'ID_BTN_SEL_NON', lsuCode);
  1715. end;
  1716. end;
  1717. procedure TForm1.Timer1Timer(Sender: TObject);
  1718. var
  1719. jsonString: string;
  1720. Data: TJSONData;
  1721. iNetVersion, version: string;
  1722. thisVersion, iVersion: TVersionRecord;
  1723. begin
  1724. MCSLabel.AutoSize := True;
  1725. Timer1.Enabled := False;
  1726. MCSLabel.Hint := InfoBox.versionHint;
  1727. if (InfoBox.newVersion) then
  1728. begin
  1729. MCSLabel.Font.Color := clred;
  1730. MCSLabel.Hint := InfoBox.versionHint + chr($0a) + chr($0d) +
  1731. MCSLSU.GetLSUText('form1Captions', 'ID_CLICK_HERE', lsuCode);
  1732. end;
  1733. MCSLabel.Caption := InfoBox.versionText;
  1734. end;
  1735. procedure TForm1.XMLPropStorage1RestoringProperties(Sender: TObject);
  1736. var
  1737. Uid: TGuid;
  1738. Result: HResult;
  1739. uuid: string;
  1740. begin
  1741. uuid := XMLPropStorage1.ReadString('AppUUID', '');
  1742. if uuid = '' then
  1743. begin
  1744. Result := CreateGuid(Uid);
  1745. if Result = S_OK then
  1746. begin
  1747. uuid := GuidToString(Uid);
  1748. XMLPropStorage1.WriteString('AppUUID', uuid);
  1749. end;
  1750. end;
  1751. Infobox.AppUUID := uuid;
  1752. end;
  1753. procedure TForm1.XMLPropStorage1SavingProperties(Sender: TObject);
  1754. begin
  1755. end;
  1756. procedure TForm1.renumberGrid;
  1757. var
  1758. x, i: integer;
  1759. begin
  1760. i := StringGrid1.RowCount;
  1761. for x := 1 to i - 1 do
  1762. begin
  1763. StringGrid1.Cells[0, x] := '0x' + inttohex(x - 1, 2);
  1764. if (StringGrid1.Cells[1, x] = '') then
  1765. StringGrid1.Cells[1, x] := '0';
  1766. if (StringGrid1.Cells[2, x] = '') then
  1767. StringGrid1.Cells[2, x] := '0';
  1768. StringGrid1.Cells[3, x] :=
  1769. sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]),
  1770. HexToInt(StringGrid1.Cells[2, x]));
  1771. end;
  1772. end;
  1773. procedure TForm1.selectAddress(addr: word);
  1774. begin
  1775. StringGrid1.Row := addr + 1;
  1776. Application.ProcessMessages;
  1777. end;
  1778. procedure TForm1.inputSps;
  1779. begin
  1780. sps.setDin1(Din1.Checked);
  1781. sps.setDin2(Din2.Checked);
  1782. sps.setDin3(Din3.Checked);
  1783. sps.setDin4(Din4.Checked);
  1784. sps.setADC1(ADC1.Value);
  1785. sps.setADC2(ADC2.Value);
  1786. sps.setRC1(RC1.Value);
  1787. sps.setRC2(RC2.Value);
  1788. sps.setSPrg(tbPrg.Checked);
  1789. sps.setSSel(tbSel.Checked);
  1790. end;
  1791. procedure TForm1.outputSps;
  1792. var
  1793. List: TStrings;
  1794. i: integer;
  1795. begin
  1796. if sps.isDout1() then
  1797. ShapeOut1.Brush.Color := clRed
  1798. else
  1799. ShapeOut1.Brush.Color := clWhite;
  1800. if sps.isDout2() then
  1801. ShapeOut2.Brush.Color := clRed
  1802. else
  1803. ShapeOut2.Brush.Color := clWhite;
  1804. if sps.isDout3() then
  1805. ShapeOut3.Brush.Color := clRed
  1806. else
  1807. ShapeOut3.Brush.Color := clWhite;
  1808. if sps.isDout4() then
  1809. ShapeOut4.Brush.Color := clRed
  1810. else
  1811. ShapeOut4.Brush.Color := clWhite;
  1812. PWM1.Text := IntToStr(sps.getPWM1());
  1813. PWM2.Text := IntToStr(sps.getPWM2());
  1814. Servo1.Text := IntToStr(sps.getServo1());
  1815. Shape1.Repaint;
  1816. Servo2.Text := IntToStr(sps.getServo2());
  1817. Shape2.Repaint;
  1818. EditA.Text := IntToStr(sps.getARegister());
  1819. EditB.Text := IntToStr(sps.getBRegister());
  1820. EditC.Text := IntToStr(sps.getCRegister());
  1821. EditD.Text := IntToStr(sps.getDRegister());
  1822. EditE.Text := IntToStr(sps.getERegister());
  1823. EditF.Text := IntToStr(sps.getFRegister());
  1824. EditAddr.Text := '0x' + IntToHex(sps.getAddress(), 2);
  1825. EditRAdr.Text := '0x' + IntToHex(sps.getRAdr(), 2);
  1826. EditPage.Text := '0x' + IntToHex(sps.getPage(), 2);
  1827. if (sps.getJump() > 0) then
  1828. EditJump.Text := '0x' + IntToHex(sps.getJump(), 2)
  1829. else
  1830. EditJump.Text := '';
  1831. if (sps.getTone() > 0) then
  1832. begin
  1833. ImageList2.GetBitmap(23, btnTone.Glyph);
  1834. i := round(440 * power(2.0, ((sps.getTone() - 69) / 12)));
  1835. btnTone.Caption := IntToStr(i);
  1836. if (lastNote <> sps.getTone()) then
  1837. begin
  1838. playNote(sps.getTone());
  1839. end;
  1840. btntone.Enabled := True;
  1841. end
  1842. else
  1843. begin
  1844. ImageList2.GetBitmap(22, btnTone.Glyph);
  1845. btnTone.Caption := '';
  1846. if (lastNote <> sps.getTone()) then
  1847. begin
  1848. playNote(0);
  1849. end;
  1850. btntone.Enabled := True;
  1851. end;
  1852. List := TStringList.Create;
  1853. try
  1854. sps.getStack(List);
  1855. lbStack.Clear;
  1856. for i := 0 to List.Count - 1 do
  1857. begin
  1858. lbStack.Items.Add(IntToStr(i) + ':' + List[i]);
  1859. end;
  1860. finally
  1861. List.Free;
  1862. end;
  1863. end;
  1864. end.