Преглед изворни кода

[2.0.x] LPC1768 - automatic selection of upload disk (#10374)

Bob-the-Kuhn пре 6 година
родитељ
комит
85014cd132
2 измењених фајлова са 136 додато и 2 уклоњено
  1. 134
    0
      Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
  2. 2
    2
      platformio.ini

+ 134
- 0
Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py Прегледај датотеку

@@ -0,0 +1,134 @@
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
+
7
+target_filename = "FIRMWARE.CUR"
8
+target_drive = "REARM"
9
+
10
+
11
+import platform
12
+current_OS = platform.system()
13
+
14
+if current_OS == 'Windows':
15
+
16
+    #
17
+    # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
18
+    #   Windows - doesn't care about the disk's name, only cares about the drive letter
19
+    #
20
+
21
+    #
22
+    # get all drives on this computer
23
+    #
24
+
25
+    import subprocess
26
+
27
+    driveStr = subprocess.check_output("fsutil fsinfo drives")  # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
28
+    driveStr = driveStr.strip().lstrip('Drives: ')  # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
29
+    drives = driveStr.split()  # typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
30
+
31
+    #
32
+    # scan top directory of each drive for FIRMWARE.CUR
33
+    #   return first drive found
34
+    #
35
+
36
+    import os
37
+    target_file_found = False
38
+    target_drive_found = False
39
+    for drive in drives:
40
+      final_drive_name = drive.strip().rstrip('\\')   # typical result (string): 'C:'
41
+      # modified version of walklevel()
42
+      level=0
43
+      some_dir = "/"
44
+      some_dir = some_dir.rstrip(os.path.sep)
45
+      assert os.path.isdir(some_dir)
46
+      num_sep = some_dir.count(os.path.sep)
47
+      for root, dirs, files in os.walk(final_drive_name):
48
+        num_sep_this = root.count(os.path.sep)
49
+        if num_sep + level <= num_sep_this:
50
+          del dirs[:]
51
+        volume_info = subprocess.check_output('fsutil fsinfo volumeinfo ' + final_drive_name)
52
+        if target_drive in volume_info and target_file_found == False:  # set upload if not found target file yet
53
+          target_drive_found = True
54
+          upload_disk = root
55
+        if target_filename in files:
56
+          if target_file_found == False:
57
+            upload_disk = root
58
+          target_file_found = True
59
+
60
+    #
61
+    # set upload_port to drive if found
62
+    #
63
+
64
+    if target_file_found == True or target_drive_found == True:
65
+      Import("env")
66
+      env.Replace(
67
+          UPLOAD_PORT = upload_disk
68
+      )
69
+
70
+
71
+
72
+if current_OS == 'Linux':
73
+
74
+    #
75
+    # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
76
+    #
77
+
78
+    import os
79
+    target_file_found = False
80
+    target_drive_found = False
81
+    medias = os.listdir('/media')  #
82
+    for media in medias:
83
+      drives = os.listdir('/media/' + media)  #
84
+      if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
85
+        target_drive_found = True
86
+        upload_disk = '/media/' + media + '/' + target_drive + '/'
87
+      for drive in drives:
88
+        files = os.listdir('/media/' + media + '/' + drive )  #
89
+        if target_filename in files:
90
+          if target_file_found == False:
91
+            upload_disk = '/media/' + media + '/' + drive + '/'
92
+            target_file_found = True
93
+
94
+    #
95
+    # set upload_port to drive if found
96
+    #
97
+
98
+    if target_file_found == True or target_drive_found == True:
99
+      Import("env")
100
+      env.Replace(
101
+        UPLOAD_FLAGS = "-P$UPLOAD_PORT",
102
+        UPLOAD_PORT = upload_disk
103
+      )
104
+
105
+
106
+if current_OS == 'Darwin':  # MAC
107
+
108
+    #
109
+    # platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive'
110
+    #
111
+
112
+    import os
113
+    drives = os.listdir('/Volumes')  #  human readable names
114
+    target_file_found = False
115
+    target_drive_found = False
116
+    if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
117
+      target_drive_found = True
118
+      upload_disk = '/Volumes/' + drive + '/'
119
+    for drive in drives:
120
+      target_file_found = True
121
+      filenames = os.listdir('/Volumes/' + drive + '/')
122
+      if target_filename in filenames:
123
+        if target_file_found == False:
124
+          upload_disk = '/Volumes/' + drive + '/'
125
+        target_file_found = True
126
+    #
127
+    # set upload_port to drive if found
128
+    #
129
+
130
+    if target_file_found == True or target_drive_found == True:
131
+      Import("env")
132
+      env.Replace(
133
+          UPLOAD_PORT = upload_disk
134
+      )

+ 2
- 2
platformio.ini Прегледај датотеку

@@ -103,7 +103,7 @@ platform     = atmelsam
103 103
 framework    = arduino
104 104
 board        = due
105 105
 build_flags  = ${common.build_flags}
106
-  -funwind-tables 
106
+  -funwind-tables
107 107
   -mpoke-function-name
108 108
 lib_deps     = ${common.lib_deps}
109 109
 lib_ignore   = c1921b4
@@ -127,7 +127,7 @@ lib_extra_dirs  = frameworks
127 127
 lib_deps        = CMSIS-LPC1768
128 128
   https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
129 129
   TMC2130Stepper@>=2.2.1
130
-extra_scripts   = Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
130
+extra_scripts   = Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py, Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
131 131
 src_filter      = ${common.default_src_filter}
132 132
 monitor_baud    = 250000
133 133
 

Loading…
Откажи
Сачувај