@@ -674,6 +674,15 @@ func formatCmdline(cmdline string, boardOptions map[string]string) (string, bool
674
674
return cmdline , true
675
675
}
676
676
677
+ func containsStr (s []string , e string ) bool {
678
+ for _ , a := range s {
679
+ if a == e {
680
+ return true
681
+ }
682
+ }
683
+ return false
684
+ }
685
+
677
686
func assembleCompilerCommand (boardname string , portname string , filePath string ) (bool , string , []string ) {
678
687
679
688
// get executable (self)path and use it as base for all other paths
@@ -706,6 +715,7 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
706
715
}
707
716
708
717
boardOptions ["serial.port" ] = portname
718
+ boardOptions ["serial.port.file" ] = portname
709
719
710
720
// filepath need special care; the project_name var is the filename minus its extension (hex or bin)
711
721
// if we are going to modify standard IDE files we also could pass ALL filename
@@ -734,6 +744,10 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
734
744
uploadOptions [arr [0 ]] = arr [1 ]
735
745
arr [0 ] = strings .Replace (arr [0 ], "tools." + tool + "." , "" , 1 )
736
746
boardOptions [arr [0 ]] = arr [1 ]
747
+ // we have a "=" in command line
748
+ if len (arr ) > 2 {
749
+ boardOptions [arr [0 ]] = arr [1 ] + "=" + arr [2 ]
750
+ }
737
751
}
738
752
}
739
753
file .Close ()
@@ -747,11 +761,12 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
747
761
return false , "" , nil
748
762
}
749
763
750
- boardOptions ["runtime.tools.avrdude .path" ] = path
764
+ boardOptions ["runtime.tools." + tool + " .path" ] = path
751
765
752
- cmdline := uploadOptions [ "tools." + tool + ". upload.pattern" ]
766
+ cmdline := boardOptions [ " upload.pattern" ]
753
767
// remove cmd.path as it is handled differently
754
768
cmdline = strings .Replace (cmdline , "\" {cmd.path}\" " , " " , 1 )
769
+ cmdline = strings .Replace (cmdline , "\" {path}/{cmd}\" " , " " , 1 )
755
770
cmdline = strings .Replace (cmdline , "\" " , "" , - 1 )
756
771
757
772
// split the commandline in substrings and recursively replace mapped strings
@@ -772,15 +787,25 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
772
787
773
788
mode := & serial.Mode {
774
789
BaudRate : 1200 ,
790
+ Vmin : 1 ,
791
+ Vtimeout : 0 ,
775
792
}
776
793
port , err := serial .OpenPort (portname , mode )
777
794
if err != nil {
778
795
log .Println (err )
779
796
return false , "" , nil
780
797
}
781
- time . Sleep ( time . Second / 2 )
798
+ port . SetDTR ( false )
782
799
port .Close ()
783
- time .Sleep (time .Second * 2 )
800
+ time .Sleep (time .Second / 4 * 10 )
801
+ // time.Sleep(time.Second / 4)
802
+ // wait for port to reappear
803
+ if boardOptions ["upload.wait_for_upload_port" ] == "true" {
804
+ ports , _ := serial .GetPortsList ()
805
+ for ! (containsStr (ports , portname )) {
806
+ ports , _ = serial .GetPortsList ()
807
+ }
808
+ }
784
809
}
785
810
786
811
tool = (filepath .Dir (execPath ) + "/" + boardFields [0 ] + "/tools/" + tool + "/bin/" + tool )
@@ -791,7 +816,15 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
791
816
tool = strings .Replace (tool , "/" , "\\ " , - 1 )
792
817
}
793
818
794
- return (tool != "" ), tool , cmdlineSlice
819
+ // remove blanks from cmdlineSlice
820
+ var cmdlineSliceOut []string
821
+ for _ , element := range cmdlineSlice {
822
+ if element != "" {
823
+ cmdlineSliceOut = append (cmdlineSliceOut , element )
824
+ }
825
+ }
826
+
827
+ return (tool != "" ), tool , cmdlineSliceOut
795
828
}
796
829
797
830
func findPortByName (portname string ) (* serport , bool ) {
0 commit comments