@@ -255,6 +255,21 @@ function fileExists(file) {
255
255
256
256
//------------------------------------------------------------------------------
257
257
258
+ function getSingleSubfolder ( parent ) {
259
+ if ( ! dirExists ( parent ) ) {
260
+ throw `"${ parent } " is not initialized` ;
261
+ }
262
+
263
+ const folders = getFolders ( parent ) ;
264
+
265
+ if ( folders . length != 1 )
266
+ throw `Cannot find single version of "${ parent } "` ;
267
+
268
+ return path . join ( parent , folders [ 0 ] ) ;
269
+ }
270
+
271
+ //------------------------------------------------------------------------------
272
+
258
273
function readFile ( name ) {
259
274
return fs . readFileSync ( name , "utf8" ) ;
260
275
}
@@ -522,16 +537,7 @@ function getEspPackagePath(arduinoUserPath, preferencesPath, target) {
522
537
switch ( target . architecture ) {
523
538
case "esp8266" : {
524
539
const dir = path . join ( preferencesPath , "packages" , target . package , "hardware" , target . architecture ) ;
525
-
526
- if ( ! dirExists ( dir ) )
527
- throw `ESP8266 has not been installed with the Arduino Board Manager.` ;
528
-
529
- const folders = getFolders ( dir ) ;
530
-
531
- if ( folders . length != 1 )
532
- throw `There should only be one ESP8266 Package installed with the Arduino Board Manager.` ;
533
-
534
- const esp8266Path = path . join ( dir , folders [ 0 ] ) ;
540
+ const esp8266Path = getSingleSubfolder ( dir ) ;
535
541
logImportant ( `Found ESP8266 packages: ${ esp8266Path } ` ) ;
536
542
537
543
return esp8266Path ;
@@ -642,10 +648,28 @@ function getEspToolsPath(arduinoUserPath, preferencesPath, target) {
642
648
return dir ;
643
649
}
644
650
651
+ function getEspPackageTools ( packagePath ) {
652
+ const dir = path . resolve ( path . join ( packagePath , "tools" ) ) ;
653
+
654
+ if ( ! dirExists ( dir ) )
655
+ throw `Can't find hardware tools path.` ;
656
+
657
+ logVerbose ( `Tools Path: "${ dir } "` ) ;
658
+ return dir ;
659
+ }
660
+
645
661
//------------------------------------------------------------------------------
646
662
647
- function getPythonExecutable ( ) {
648
- const python = getVscodeConfigValue ( PYTHON_PYTHONPATH ) || "python" ;
663
+ function getPythonExecutable ( toolsDir ) {
664
+ let python ;
665
+ if ( getVscodeConfigValue ( PYTHON_PYTHONPATH ) ) {
666
+ python = getVscodeConfigValue ( PYTHON_PYTHONPATH ) ;
667
+ } else if ( toolsDir != undefined && dirExists ( path . join ( toolsDir , "python3" ) ) ) {
668
+ const pythonPath = getSingleSubfolder ( path . join ( toolsDir , "python3" ) ) ;
669
+ python = path . join ( pythonPath , program ( "python" ) ) ;
670
+ } else {
671
+ python = "python" ;
672
+ }
649
673
650
674
logVerbose ( `Python Executable: "${ python } "` ) ;
651
675
return python ;
@@ -698,12 +722,8 @@ function getMkSpiffs(target, espToolsPath) {
698
722
699
723
switch ( target . architecture ) {
700
724
case "esp8266" : {
701
- const folders = getFolders ( path . join ( espToolsPath , "mkspiffs" ) ) ;
702
-
703
- if ( folders . length != 1 )
704
- throw `"${ target . architecture } " not installed correctly through Arduino Board Manager` ;
705
-
706
- const mkspiffs = path . join ( espToolsPath , "mkspiffs" , folders [ 0 ] , program ( "mkspiffs" ) ) ;
725
+ const folder = getSingleSubfolder ( path . join ( espToolsPath , "mkspiffs" ) ) ;
726
+ const mkspiffs = path . join ( folder , program ( "mkspiffs" ) ) ;
707
727
708
728
if ( ! fileExists ( mkspiffs ) )
709
729
throw `"Can't locate "${ mkspiffs } "` ;
@@ -862,74 +882,24 @@ function getEspTool(target, espToolsPath) {
862
882
return configFile ;
863
883
}
864
884
885
+ let esptoolPy ;
865
886
switch ( target . architecture ) {
866
- case "esp8266" : {
867
- const folders = getFolders ( path . join ( espToolsPath , "esptool" ) ) ;
868
-
869
- if ( folders . length != 1 )
870
- throw `"${ target . architecture } " not installed correctly through Arduino Board Manager` ;
871
-
872
- const version = folders [ 0 ] ;
873
-
874
- const esptool = path . join ( espToolsPath , "esptool" , version , program ( "esptool" ) ) ;
875
-
876
- if ( ! fileExists ( esptool ) )
877
- throw `"Can't locate "${ esptool } "` ;
878
-
879
- logVerbose ( `esptool (${ version } ): ${ CYAN } ${ esptool } ` ) ;
880
-
881
- return esptool ;
882
- }
883
-
887
+ case "esp8266" :
888
+ esptoolPy = path . join ( espToolsPath , program ( "upload.py" ) ) ;
889
+ break ;
884
890
case "esp32" : {
885
- const esptoolPy = path . join ( espToolsPath , program ( "esptool.py" ) ) ;
886
-
887
- if ( ! fileExists ( esptoolPy ) )
888
- throw `"Can't locate "${ esptoolPy } "` ;
889
-
890
- logVerbose ( `esptool: ${ CYAN } ${ esptoolPy } ` ) ;
891
-
892
- return esptoolPy ;
891
+ esptoolPy = path . join ( espToolsPath , program ( "esptool.py" ) ) ;
892
+ break ;
893
893
}
894
- }
895
- }
896
-
897
- //------------------------------------------------------------------------------
898
894
899
- // -ca <address>
900
- // -cd <resetMethod>
901
- // -cp <port>
902
- // -cb <speed>
903
- // -vvv
904
-
905
- function _uploadSpiffsEspTool ( esptool , commPort , spiffsImage , spiffsOptions ) {
906
- log ( `--- Uploading SPIFFS file with esptool[.exe] ---` ) ;
907
-
908
- const uploadAddress = `0x` + toHex ( stringToInt ( spiffsOptions . spiffs_start ) , 6 ) ;
909
- const uploadSpeed = stringToInt ( spiffsOptions . speed ) ;
910
- const resetMethod = spiffsOptions . resetmethod ;
911
-
912
- logImportant ( `SPIFFS Uploading Image... (${ spiffsImage } )` ) ;
913
- logSpiffs ( `program: ${ esptool } ` ) ;
914
- logSpiffs ( `address: ${ uploadAddress } ` ) ;
915
- logSpiffs ( `reset : ${ resetMethod } ` ) ;
916
- logSpiffs ( `port : ${ commPort } ` ) ;
917
- logSpiffs ( `speed : ${ uploadSpeed } ` ) ;
918
-
919
- let args = [
920
- "-ca" , uploadAddress , // Address in flash.
921
- "-cd" , resetMethod , // Board reset method: "none", "ck", "nodemcu", or "wifio".
922
- "-cp" , commPort , // Serial Port (Default Linux: /dev/ttyUSB0, Windows: COM1, OSx: /dev/tty.usbserial).
923
- "-cb" , uploadSpeed , // Baud rate (Default: 115200).
924
- "-cf" , makeOsPath ( spiffsImage ) // SPIFFS File
925
- ] ;
895
+ }
926
896
927
- const verbosity = getVscodeConfigValue ( ESP8266FS_ESPTOOL_VERBOSITY ) ;
897
+ if ( ! fileExists ( esptoolPy ) )
898
+ throw `"Can't locate "${ esptoolPy } "` ;
928
899
929
- if ( verbosity )
930
- args . unshift ( `-${ verbosity } ` ) ;
900
+ logVerbose ( `esptool: ${ CYAN } ${ esptoolPy } ` ) ;
931
901
932
- runCommand ( makeOsPath ( esptool ) , args ) ;
902
+ return esptoolPy ;
933
903
}
934
904
935
905
//------------------------------------------------------------------------------
@@ -949,21 +919,16 @@ function _uploadSpiffsEspTool(esptool, commPort, spiffsImage, spiffsOptions) {
949
919
// --spi_connection <spi>
950
920
// --verify
951
921
952
- function _uploadSpiffsEspToolPy ( esptool , commPort , spiffsImage , spiffsOptions , target ) {
922
+ function uploadSpiffsEspToolPy ( python , esptool , commPort , spiffsImage , spiffsOptions , target ) {
953
923
log ( `--- Uploading SPIFFS file with esptool.py ---` ) ;
954
924
955
- const python = getPythonExecutable ( ) ;
956
-
957
925
const uploadAddress = `0x` + toHex ( stringToInt ( spiffsOptions . spiffs_start ) , 6 ) ;
958
926
const uploadSpeed = stringToInt ( spiffsOptions . speed ) ;
959
927
const resetMethod = spiffsOptions . resetmethod ;
960
928
961
929
const before = getVscodeConfigValue ( ESP8266FS_ESPTOOL_PY_BEFORE ) || "default_reset" ;
962
930
const after = getVscodeConfigValue ( ESP8266FS_ESPTOOL_PY_AFTER ) || "hard_reset" ;
963
931
964
- const flashMode = target . flashMode ;
965
- const flashFreq = target . flashFreq ;
966
- const flashSize = target . flashSize || "detect" ;
967
932
968
933
logImportant ( `SPIFFS Uploading Image... (${ spiffsImage } )` ) ;
969
934
logSpiffs ( `Python : ${ python } ` ) ;
@@ -973,9 +938,6 @@ function _uploadSpiffsEspToolPy(esptool, commPort, spiffsImage, spiffsOptions, t
973
938
logSpiffs ( `speed : ${ uploadSpeed } ` ) ;
974
939
logSpiffs ( `before : ${ before } ` ) ;
975
940
logSpiffs ( `after : ${ after } ` ) ;
976
- logSpiffs ( `flashMode: ${ flashMode } ` ) ;
977
- logSpiffs ( `flashFreq: ${ flashFreq } ` ) ;
978
- logSpiffs ( `flashSize: ${ flashSize } ` ) ;
979
941
980
942
const spi = getVscodeConfigValue ( ESP8266FS_ESPTOOL_PY_SPI ) || "" ;
981
943
if ( spi )
@@ -1008,12 +970,6 @@ function _uploadSpiffsEspToolPy(esptool, commPort, spiffsImage, spiffsOptions, t
1008
970
if ( compress )
1009
971
args . push ( "--compress" ) ;
1010
972
1011
- args . push (
1012
- "--flash_mode" , flashMode ,
1013
- "--flash_freq" , flashFreq ,
1014
- "--flash_size" , flashSize
1015
- ) ;
1016
-
1017
973
if ( spi )
1018
974
args . push ( "--spi-connection" , spi ) ;
1019
975
@@ -1103,14 +1059,6 @@ function _downloadSpiffsEspToolPy(esptool, commPort, spiffsImage, spiffsOptions,
1103
1059
1104
1060
runCommand ( makeOsPath ( python ) , args ) ;
1105
1061
}
1106
- //------------------------------------------------------------------------------
1107
-
1108
- function uploadSpiffsEspTool ( esptool , commPort , spiffsImage , spiffsOptions , target ) {
1109
- if ( esptool . match ( / \. p y $ / ) )
1110
- _uploadSpiffsEspToolPy ( esptool , commPort , spiffsImage , spiffsOptions , target ) ;
1111
- else
1112
- _uploadSpiffsEspTool ( esptool , commPort , spiffsImage , spiffsOptions ) ;
1113
- }
1114
1062
1115
1063
//------------------------------------------------------------------------------
1116
1064
@@ -1209,13 +1157,15 @@ async function _executeSpiffs(command) {
1209
1157
1210
1158
const arduinoUserPath = getArduinoUserPath ( ) ;
1211
1159
const espPackagePath = getEspPackagePath ( arduinoUserPath , preferencesPath , target ) ;
1160
+ const espPackageToolPath = getEspPackageTools ( espPackagePath ) ;
1212
1161
const espToolsPath = getEspToolsPath ( arduinoUserPath , preferencesPath , target ) ;
1213
1162
1214
1163
const spiffsOptions = getSpiffsOptions ( espPackagePath , target , arduinoJson , preferences ) ;
1215
1164
1216
1165
const port = getPort ( arduinoJson , preferences ) ;
1217
1166
1218
1167
const mkspiffs = getMkSpiffs ( target , espToolsPath ) ;
1168
+ const python = getPythonExecutable ( espToolsPath ) ;
1219
1169
1220
1170
// --- Ready to get down to business ---
1221
1171
@@ -1224,7 +1174,7 @@ async function _executeSpiffs(command) {
1224
1174
if ( isIP ( port ) )
1225
1175
uploadSpiffsOta ( getEspotaPy ( espPackagePath ) , port , spiffsImage ) ;
1226
1176
else
1227
- uploadSpiffsEspTool ( getEspTool ( target , espToolsPath ) , port , spiffsImage , spiffsOptions , target ) ;
1177
+ uploadSpiffsEspToolPy ( python , getEspTool ( target , espPackageToolPath ) , port , spiffsImage , spiffsOptions , target ) ;
1228
1178
1229
1179
break ;
1230
1180
}
0 commit comments