Переглянути джерело

[LPC176x] Update PIO extrascript (#12878)

Chris Pepper 5 роки тому
джерело
коміт
2919f3045d
2 змінених файлів з 76 додано та 83 видалено
  1. 74
    81
      Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
  2. 2
    2
      platformio.ini

+ 74
- 81
Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py Переглянути файл

@@ -10,18 +10,16 @@ target_drive = "REARM"
10 10
 import os
11 11
 import platform
12 12
 current_OS = platform.system()
13
+Import("env")
13 14
 
14
-#env_vars = subprocess.check_output('platformio run -t envdump')
15
-#env_vars = env_vars.split('\n')
16
-#for env in env_vars:
17
-#  print env
18
-#exit(0)
19
-
20
-build_type = os.environ.get("BUILD_TYPE", 'Not Set')
21
-if build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set' :
15
+def detect_error(e):
16
+    print '\nUnable to find destination disk (' + e + ')\n' \
17
+          'Please select it in platformio.ini using the upload_port keyword ' \
18
+          '(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html)\n' \
19
+          'or copy the firmware (.pioenvs/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n'
22 20
 
21
+try:
23 22
     if current_OS == 'Windows':
24
-
25 23
         #
26 24
         # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
27 25
         #   Windows - doesn't care about the disk's name, only cares about the drive letter
@@ -30,119 +28,114 @@ if build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set
30 28
         #
31 29
         # get all drives on this computer
32 30
         #
33
-
34 31
         import subprocess
35
-
36
-        driveStr = subprocess.check_output("fsutil fsinfo drives")  # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
37
-        driveStr = driveStr.strip().lstrip('Drives: ')  # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
38
-        drives = driveStr.split()  # typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
32
+        # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
33
+        driveStr = subprocess.check_output("fsutil fsinfo drives")
34
+        # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
35
+        driveStr = driveStr.strip().lstrip('Drives: ')
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 39
 
40 40
         upload_disk = 'Disk not found'
41 41
         target_file_found = False
42 42
         target_drive_found = False
43 43
         for drive in drives:
44
-          final_drive_name = drive.strip().rstrip('\\')   # typical result (string): 'C:'
45
-          try:
46
-            volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)
47
-          except Exception as e:
48
-            continue
49
-          else:
50
-            if target_drive in volume_info and target_file_found == False:  # set upload if not found target file yet
51
-              target_drive_found = True
52
-              upload_disk = final_drive_name
53
-            if target_filename in volume_info:
54
-              if target_file_found == False:
55
-                upload_disk = final_drive_name
56
-              target_file_found = True
44
+            final_drive_name = drive.strip().rstrip('\\')   # typical result (string): 'C:'
45
+            try:
46
+                volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)
47
+            except Exception as e:
48
+                continue
49
+            else:
50
+                if target_drive in volume_info and target_file_found == False:  # set upload if not found target file yet
51
+                    target_drive_found = True
52
+                    upload_disk = final_drive_name
53
+                if target_filename in volume_info:
54
+                    if target_file_found == False:
55
+                        upload_disk = final_drive_name
56
+                    target_file_found = True
57 57
 
58 58
         #
59 59
         # set upload_port to drive if found
60 60
         #
61 61
 
62 62
         if target_file_found == True or target_drive_found == True:
63
-          Import("env")
64
-          env.Replace(
65
-              UPLOAD_PORT = upload_disk
66
-          )
67
-          print 'upload disk: ' , upload_disk
63
+            env.Replace(
64
+                UPLOAD_PORT=upload_disk
65
+            )
66
+            print 'upload disk: ', upload_disk
68 67
         else:
69
-          print '\nUnable to find destination disk.  File must be copied manually. \n'
70
-
71
-
72
-    if current_OS == 'Linux':
68
+            detect_error('Autodetect Error')
73 69
 
70
+    elif current_OS == 'Linux':
74 71
         #
75 72
         # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
76 73
         #
77
-
78 74
         upload_disk = 'Disk not found'
79 75
         target_file_found = False
80 76
         target_drive_found = False
81 77
         medias = os.listdir('/media')  #
82 78
         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
-            try:
89
-              files = os.listdir('/media/' + media + '/' + drive )
90
-            except:
91
-              continue
92
-            else:
93
-              if target_filename in files:
94
-                if target_file_found == False:
95
-                  upload_disk = '/media/' + media + '/' + drive + '/'
96
-                  target_file_found = True
79
+            drives = os.listdir('/media/' + media)  #
80
+            if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
81
+                target_drive_found = True
82
+                upload_disk = '/media/' + media + '/' + target_drive + '/'
83
+            for drive in drives:
84
+                try:
85
+                    files = os.listdir('/media/' + media + '/' + drive)
86
+                except:
87
+                    continue
88
+                else:
89
+                    if target_filename in files:
90
+                        if target_file_found == False:
91
+                            upload_disk = '/media/' + media + '/' + drive + '/'
92
+                            target_file_found = True
97 93
 
98 94
         #
99 95
         # set upload_port to drive if found
100 96
         #
101 97
 
102 98
         if target_file_found == True or target_drive_found == True:
103
-          Import("env")
104
-          env.Replace(
105
-            UPLOAD_FLAGS = "-P$UPLOAD_PORT",
106
-            UPLOAD_PORT = upload_disk
107
-          )
108
-          print 'upload disk: ' , upload_disk
99
+            env.Replace(
100
+                UPLOAD_FLAGS="-P$UPLOAD_PORT",
101
+                UPLOAD_PORT=upload_disk
102
+            )
103
+            print 'upload disk: ', upload_disk
109 104
         else:
110
-           print '\nUnable to find destination disk.  File must be copied manually. \n'
111
-
112
-
113
-    if current_OS == 'Darwin':  # MAC
105
+            detect_error('Autodetect Error')
114 106
 
107
+    elif current_OS == 'Darwin':  # MAC
115 108
         #
116 109
         # platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive'
117 110
         #
118
-
119
-        import os
120 111
         upload_disk = 'Disk not found'
121
-        drives = os.listdir('/Volumes')  #  human readable names
112
+        drives = os.listdir('/Volumes')  # human readable names
122 113
         target_file_found = False
123 114
         target_drive_found = False
124 115
         if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
125
-          target_drive_found = True
126
-          upload_disk = '/Volumes/' + target_drive + '/'
116
+            target_drive_found = True
117
+            upload_disk = '/Volumes/' + target_drive + '/'
127 118
         for drive in drives:
128
-          try:
129
-            filenames = os.listdir('/Volumes/' + drive + '/')   # will get an error if the drive is protected
130
-          except:
131
-            continue
132
-          else:
133
-            if target_filename in filenames:
134
-              if target_file_found == False:
135
-                upload_disk = '/Volumes/' + drive + '/'
136
-              target_file_found = True
119
+            try:
120
+                filenames = os.listdir('/Volumes/' + drive + '/')   # will get an error if the drive is protected
121
+            except:
122
+                continue
123
+            else:
124
+                if target_filename in filenames:
125
+                    if target_file_found == False:
126
+                        upload_disk = '/Volumes/' + drive + '/'
127
+                    target_file_found = True
137 128
         #
138 129
         # set upload_port to drive if found
139 130
         #
140 131
 
141 132
         if target_file_found == True or target_drive_found == True:
142
-          Import("env")
143
-          env.Replace(
144
-              UPLOAD_PORT = upload_disk
145
-          )
146
-          print '\nupload disk: ' , upload_disk, '\n'
133
+            env.Replace(
134
+                UPLOAD_PORT=upload_disk
135
+            )
136
+            print '\nupload disk: ', upload_disk, '\n'
147 137
         else:
148
-           print '\nUnable to find destination disk.  File must be copied manually. \n'
138
+            detect_error('Autodetect Error')
139
+
140
+except Exception as e:
141
+    detect_error(str(e))

+ 2
- 2
platformio.ini Переглянути файл

@@ -161,7 +161,7 @@ src_filter        = ${common.default_src_filter} +<src/HAL/HAL_LPC1768>
161 161
 monitor_speed     = 250000
162 162
 lib_deps          = Servo
163 163
   LiquidCrystal
164
-  https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
164
+  U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
165 165
   TMCStepper@<1.0.0
166 166
 
167 167
 [env:LPC1769]
@@ -179,7 +179,7 @@ src_filter        = ${common.default_src_filter} +<src/HAL/HAL_LPC1768>
179 179
 monitor_speed     = 250000
180 180
 lib_deps          = Servo
181 181
   LiquidCrystal
182
-  https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
182
+  U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
183 183
   TMCStepper@<1.0.0
184 184
 
185 185
 #

Завантаження…
Відмінити
Зберегти