ugui.pas 51 KB

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