My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

upload_extra_script.py 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #
  2. # sets output_port
  3. # if target_filename is found then that drive is used
  4. # else if target_drive is found then that drive is used
  5. #
  6. from __future__ import print_function
  7. target_filename = "FIRMWARE.CUR"
  8. target_drive = "REARM"
  9. import os
  10. import getpass
  11. import platform
  12. current_OS = platform.system()
  13. Import("env")
  14. def print_error(e):
  15. print('\nUnable to find destination disk (%s)\n' \
  16. 'Please select it in platformio.ini using the upload_port keyword ' \
  17. '(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html) ' \
  18. 'or copy the firmware (.pio/build/%s/firmware.bin) manually to the appropriate disk\n' \
  19. %(e, env.get('PIOENV')))
  20. try:
  21. if current_OS == 'Windows':
  22. #
  23. # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
  24. # Windows - doesn't care about the disk's name, only cares about the drive letter
  25. #
  26. #
  27. # get all drives on this computer
  28. #
  29. import subprocess
  30. # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
  31. driveStr = str(subprocess.check_output("fsutil fsinfo drives"))
  32. # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
  33. # driveStr = driveStr.strip().lstrip('Drives: ') <- Doesn't work in other Languages as English. In German is "Drives:" = "Laufwerke:"
  34. FirstFound = driveStr.find(':',0,-1) # Find the first ":" and
  35. driveStr = driveStr[FirstFound + 1 : -1] # truncate to the rest
  36. # typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\',
  37. # 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
  38. drives = driveStr.split()
  39. upload_disk = 'Disk not found'
  40. target_file_found = False
  41. target_drive_found = False
  42. for drive in drives:
  43. final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:'
  44. try:
  45. volume_info = str(subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT))
  46. except Exception as e:
  47. continue
  48. else:
  49. if target_drive in volume_info and target_file_found == False: # set upload if not found target file yet
  50. target_drive_found = True
  51. upload_disk = final_drive_name
  52. if target_filename in volume_info:
  53. if target_file_found == False:
  54. upload_disk = final_drive_name
  55. target_file_found = True
  56. #
  57. # set upload_port to drive if found
  58. #
  59. if target_file_found == True or target_drive_found == True:
  60. env.Replace(
  61. UPLOAD_PORT=upload_disk
  62. )
  63. print('upload disk: ', upload_disk)
  64. else:
  65. print_error('Autodetect Error')
  66. elif current_OS == 'Linux':
  67. #
  68. # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
  69. #
  70. upload_disk = 'Disk not found'
  71. target_file_found = False
  72. target_drive_found = False
  73. drives = os.listdir(os.path.join(os.sep, 'media', getpass.getuser()))
  74. if target_drive in drives: # If target drive is found, use it.
  75. target_drive_found = True
  76. upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), target_drive) + os.sep
  77. else:
  78. for drive in drives:
  79. try:
  80. files = os.listdir(os.path.join(os.sep, 'media', getpass.getuser(), drive))
  81. except:
  82. continue
  83. else:
  84. if target_filename in files:
  85. upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), drive) + os.sep
  86. target_file_found = True
  87. break
  88. #
  89. # set upload_port to drive if found
  90. #
  91. if target_file_found or target_drive_found:
  92. env.Replace(
  93. UPLOAD_FLAGS="-P$UPLOAD_PORT",
  94. UPLOAD_PORT=upload_disk
  95. )
  96. print('upload disk: ', upload_disk)
  97. else:
  98. print_error('Autodetect Error')
  99. elif current_OS == 'Darwin': # MAC
  100. #
  101. # platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive'
  102. #
  103. upload_disk = 'Disk not found'
  104. drives = os.listdir('/Volumes') # human readable names
  105. target_file_found = False
  106. target_drive_found = False
  107. if target_drive in drives and target_file_found == False: # set upload if not found target file yet
  108. target_drive_found = True
  109. upload_disk = '/Volumes/' + target_drive + '/'
  110. for drive in drives:
  111. try:
  112. filenames = os.listdir('/Volumes/' + drive + '/') # will get an error if the drive is protected
  113. except:
  114. continue
  115. else:
  116. if target_filename in filenames:
  117. if target_file_found == False:
  118. upload_disk = '/Volumes/' + drive + '/'
  119. target_file_found = True
  120. #
  121. # set upload_port to drive if found
  122. #
  123. if target_file_found == True or target_drive_found == True:
  124. env.Replace(
  125. UPLOAD_PORT=upload_disk
  126. )
  127. print('\nupload disk: ', upload_disk, '\n')
  128. else:
  129. print_error('Autodetect Error')
  130. except Exception as e:
  131. print_error(str(e))