| 
					
				 | 
			
			
				@@ -28,6 +28,7 @@ type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     acFileSave: TAction;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     acHelpAbout: TAction;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     acHexFile: TAction;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    acNextInsert: TAction;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     acUpload: TAction;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ActionList1: TActionList;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     acFileOpen: TFileOpen;
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -79,6 +80,7 @@ type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ADC2: TSpinEdit;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     SaveDialog1: TSaveDialog;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     SaveHexFile: TSaveDialog;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    SdpoSerial1: TSdpoSerial;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     Servo1: TLabeledEdit;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     Servo2: TLabeledEdit;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     EditA: TLabeledEdit;
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -94,6 +96,7 @@ type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ShapeOut2: TShape;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ShapeOut3: TShape;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ShapeOut4: TShape;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    SpeedButton1: TSpeedButton;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     StatusBar1: TStatusBar;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     StringGrid1: TStringGrid;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     tbPrg: TToggleBox;
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -143,6 +146,7 @@ type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure acHexFileExecute(Sender: TObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure acNewExecute(Sender: TObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure acNewRowExecute(Sender: TObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    procedure acNextInsertExecute(Sender: TObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure acNextStepExecute(Sender: TObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure acPresetLoadAccept(Sender: TObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure acPresetSaveAccept(Sender: TObject);
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -185,6 +189,7 @@ type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure inputSps;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure outputSps;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure uploadFile;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    function serialUpload: string;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure setDirty(Value: boolean);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     function checkDirty: boolean;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure checkPresets;
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -519,6 +524,17 @@ begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   renumberGrid();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+procedure TForm1.acNextInsertExecute(Sender: TObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+var
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  myPos: integer;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  myPos := StringGrid1.Row;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (myPos = StringGrid1.RowCount - 1) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    acNewRow.Execute;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  StringGrid1.Row := myPos + 1;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  renumberGrid();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 procedure TForm1.programSps;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 var
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   x, i: integer;
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -728,8 +744,70 @@ end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 procedure TForm1.acUploadExecute(Sender: TObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   uploadFile();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  //serialUpload;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function TForm1.serialUpload: string;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+var
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  hexFileSource: TStringList;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  hexFile, tmp, line: string;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  pos, x: integer;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  pos := 0;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  line := '';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  hexFile := MCSIO.CreateUniqueFile(MCSIO.GetTempDir, 'TPS', '.hex');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  hexFileSource := TStringList.Create;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  for x := 1 to StringGrid1.RowCount - 1 do
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (pos = 0) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      line := line + 'd ';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    tmp := StringGrid1.Cells[1, x];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    line := line + tmp;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    tmp := StringGrid1.Cells[2, x];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    line := line + tmp;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Inc(pos);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (pos = 8) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      hexFileSource.Add(line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      line := '';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      pos := 0;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    end
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    else
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      line := line + ',';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (pos = 0) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    line := hexFileSource.Strings[hexFileSource.Count - 1];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    hexFileSource.Delete(hexFileSource.Count - 1);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pos := 8;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (pos <= 7) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for x := pos to 7 do
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      line := line + '00';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if (x < 7) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        line := line + ',';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  line := line + '*';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  hexFileSource.Add(line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  MCSIO.StrToFile(hexFile, hexFileSource.Text);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  hexFileSource.Free;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  Result := hexFile;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 procedure TForm1.uploadFile;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 var
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   line: string;
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -746,6 +824,7 @@ var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   cmd, config, mcu: string;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   KeyName, StringValue: string;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   Res: WideString;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  Lines: TStringList;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   line := GetSerialPortNames;
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -759,57 +838,27 @@ begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     frmSelectCom.cbServices.Items.AddStrings(comServices);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     frmSelectCom.cbServices.Text := line;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    line := XMLPropStorage1.ReadString('ArduinoBin', '');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (line = '') then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      KeyName := 'SOFTWARE\WOW6432Node\Arduino';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      StringValue := 'Install_Dir';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      Res := RegistryReadString(HKEY_LOCAL_MACHINE, WideString(KeyName), WideString(StringValue));
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      if Res <> '' then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        line := string(Res);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    frmSelectCom.deArduino.Text := line;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return := frmSelectCom.ShowModal;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     comService := frmSelectCom.cbServices.Text;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     XMLPropStorage1.WriteString('ComPort', comService);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    line := frmSelectCom.deArduino.Text;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    arduinoPath := MCSIO.GetNormPath(line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    XMLPropStorage1.WriteString('ArduinoBin', line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     comServices.Free;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (return = mrOk) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      hexFile := MCSIO.CreateUniqueFile(MCSIO.GetTempDir, 'TPS', '.hex');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      makeHexFile(hexFile);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      cmd := arduinoPath + 'hardware\tools\avr\bin\avrdude';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      XMLPropStorage1.WriteString('avrdude', cmd);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      hexFile := serialUpload;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      config := arduinoPath + 'hardware\tools\avr\etc\avrdude.conf';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      XMLPropStorage1.WriteString('avrdudeconf', config);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      SdpoSerial1.Device := comService;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      SdpoSerial1.Active := True;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      if (cbTPSVersion.ItemIndex = 3) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      Lines := TStringList.Create;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      Lines.LoadFromFile(hexFile);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      for x := 0 to Lines.Count - 1 do
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        mcu := 'atmega328p';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      end
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      else if (cbTPSVersion.ItemIndex = 2) then
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      begin
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        mcu := 'attiny84';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SdpoSerial1.WriteData(Lines.Strings[x]);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SdpoSerial1.WriteData(CRLF);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      XMLPropStorage1.WriteString('arduinomcu', mcu);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      line :=
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        '-C%AVRCONF% -v -v -v -p%MCU% -carduino -P\\.\%COM% -b57600 -D -Ueeprom:w:%FILE%:i';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      line := Replace2('%AVRCONF%', config, line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      line := Replace2('%MCU%', mcu, line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      line := Replace2('%COM%', comService, line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      line := Replace2('%FILE%', hexFile, line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      ExecuteProcess(cmd, line);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      SdpoSerial1.Active := False;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       DeleteFile(hexFile);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     end;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   end;
 
			 |