ugui.pas 51 KB

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