Parcourir la source

🚸 Firmware upload destination prompt (using Tk) (#24074)

ellensp il y a 2 ans
Parent
révision
c1ff38c7a0

+ 52
- 0
buildroot/share/PlatformIO/scripts/upload_prompt_extra_script.py Voir le fichier

@@ -0,0 +1,52 @@
1
+#
2
+# upload_prompt_extra_script.py
3
+# set the output_port
4
+#
5
+from __future__ import print_function
6
+
7
+has_tkinter = False
8
+try:
9
+	import sys
10
+	if sys.version_info[0] < 3:
11
+		import Tkinter as tk
12
+		import tkFileDialog as fileDialog
13
+		from Tkinter import Tk
14
+	else:
15
+		import tkinter as tk
16
+		from tkinter import Tk
17
+		from tkinter import filedialog as fileDialog
18
+	has_tkinter = True
19
+except:
20
+	pass
21
+
22
+import pioutil
23
+if has_tkinter and pioutil.is_pio_build():
24
+
25
+	Import("env")
26
+
27
+	def print_error(e):
28
+		print('\nUnable to find destination disk (%s)\n' %( e ) )
29
+
30
+	def before_upload(source, target, env):
31
+		#
32
+		# Find a disk for upload
33
+		#
34
+		upload_disk = ''
35
+
36
+		root = Tk() # pointing root to Tk() to use it as Tk() in program.
37
+		root.withdraw() # Hides small tkinter window.
38
+
39
+		root.attributes('-topmost', True) # Opened windows will be active. above all windows despite of selection.
40
+
41
+		upload_disk = fileDialog.askdirectory(title="Select the root of your SDCARD") # Returns opened path as str
42
+		if not upload_disk:
43
+			print_error('Canceled')
44
+			return
45
+		else:
46
+			env.Replace(
47
+				UPLOAD_FLAGS="-P$UPLOAD_PORT"
48
+			)
49
+			env.Replace(UPLOAD_PORT=upload_disk)
50
+			print('\nUpload disk: ', upload_disk, '\n')
51
+
52
+	env.AddPreAction("upload", before_upload)

+ 7
- 0
ini/stm32f1.ini Voir le fichier

@@ -148,6 +148,10 @@ upload_protocol = custom
148 148
 [env:STM32F103RE_creality]
149 149
 extends = STM32F103Rx_creality
150 150
 board   = genericSTM32F103RE
151
+extra_scripts  = ${STM32F103Rx_creality.extra_scripts}
152
+                 buildroot/share/PlatformIO/scripts/upload_prompt_extra_script.py
153
+upload_protocol = mbed
154
+
151 155
 
152 156
 [env:STM32F103RE_creality_xfer]
153 157
 extends = STM32F103Rx_creality_xfer
@@ -164,6 +168,9 @@ board_upload.offset_address = 0x08010000
164 168
 [env:STM32F103RC_creality]
165 169
 extends = STM32F103Rx_creality
166 170
 board   = genericSTM32F103RC
171
+extra_scripts  = ${STM32F103Rx_creality.extra_scripts}
172
+                 buildroot/share/PlatformIO/scripts/upload_prompt_extra_script.py
173
+upload_protocol = mbed
167 174
 
168 175
 [env:STM32F103RC_creality_xfer]
169 176
 extends = STM32F103Rx_creality_xfer

Chargement…
Annuler
Enregistrer