My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

create_custom_upload_command_CDC.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #
  2. # Builds custom upload command
  3. # 1) Run platformio as a subprocess to find a COM port
  4. # 2) Build the upload command
  5. # 3) Exit and let upload tool do the work
  6. #
  7. # This script runs between completion of the library/dependencies installation and compilation.
  8. #
  9. # Will continue on if a COM port isn't found so that the compilation can be done.
  10. #
  11. import sys
  12. import subprocess
  13. import platform
  14. current_OS = platform.system()
  15. from SCons.Script import DefaultEnvironment
  16. env = DefaultEnvironment()
  17. com_first = ''
  18. com_last = ''
  19. com_CDC = ''
  20. description_first = ''
  21. description_last = ''
  22. description_CDC = ''
  23. #
  24. # grab the first com port that pops up unless we find one we know for sure
  25. # is a CDC device
  26. #
  27. def get_com_port(com_search_text, descr_search_text, start):
  28. global com_first
  29. global com_last
  30. global com_CDC
  31. global description_first
  32. global description_last
  33. global description_CDC
  34. print '\nLooking for Serial Port\n'
  35. # stream output from subprocess and split it into lines
  36. pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  37. looking_for_description = False
  38. for line in iter(pio_subprocess.stdout.readline, ''):
  39. if 0 <= line.find(com_search_text):
  40. looking_for_description = True
  41. com_last = line.replace('\n', '')
  42. if com_first == '':
  43. com_first = com_last
  44. if 0 <= line.find(descr_search_text) and looking_for_description:
  45. looking_for_description = False
  46. description_last = line[ start : ]
  47. if description_first == '':
  48. description_first = description_last
  49. if 0 <= description_last.find('CDC'):
  50. com_CDC = com_last
  51. description_CDC = description_last
  52. if com_CDC == '' and not(com_first == ''):
  53. com_CDC = com_first
  54. description_CDC = description_first
  55. elif com_CDC == '':
  56. com_CDC = 'COM_PORT_NOT_FOUND'
  57. if com_CDC == 'COM_PORT_NOT_FOUND':
  58. print com_CDC, '\n'
  59. else:
  60. print 'FOUND: ' ,com_CDC
  61. print 'DESCRIPTION: ', description_CDC , '\n'
  62. if current_OS == 'Windows':
  63. get_com_port('COM', 'Hardware ID:', 13)
  64. avrdude_conf_path = env.get("PIOHOME_DIR") + '\\packages\\toolchain-atmelavr\\etc\\avrdude.conf'
  65. source_path = env.get("PROJECTBUILD_DIR") + '\\' + env.get("PIOENV") + '\\firmware.hex'
  66. upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
  67. if current_OS == 'Darwin': # MAC
  68. get_com_port('usbmodem', 'Description:', 13)
  69. avrdude_conf_path = env.get("PIOHOME_DIR") + '/packages/toolchain-atmelavr/etc/avrdude.conf'
  70. source_path = env.get("PROJECTBUILD_DIR") + '/' + env.get("PIOENV") + '/firmware.hex'
  71. upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
  72. if current_OS == 'Linux':
  73. get_com_port('/dev/tty', 'Description:', 13)
  74. avrdude_conf_path = env.get("PIOHOME_DIR") + '/packages/toolchain-atmelavr/etc/avrdude.conf'
  75. source_path = env.get("PROJECTBUILD_DIR") + '/' + env.get("PIOENV") + '/firmware.hex'
  76. upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
  77. env.Replace(
  78. UPLOADCMD = upload_string,
  79. MAXIMUM_RAM_SIZE = 8192,
  80. MAXIMUM_SIZE = 130048
  81. )