Skip to content

Commit f42519a

Browse files
ellenspLCh-77
authored andcommitted
🚸 Firmware upload destination prompt (using Tk) (MarlinFirmware#24074)
1 parent 7e95ce1 commit f42519a

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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)

ini/stm32f1.ini

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ upload_protocol = custom
148148
[env:STM32F103RE_creality]
149149
extends = STM32F103Rx_creality
150150
board = genericSTM32F103RE
151+
extra_scripts = ${STM32F103Rx_creality.extra_scripts}
152+
buildroot/share/PlatformIO/scripts/upload_prompt_extra_script.py
153+
upload_protocol = mbed
154+
151155

152156
[env:STM32F103RE_creality_xfer]
153157
extends = STM32F103Rx_creality_xfer
@@ -164,6 +168,9 @@ board_upload.offset_address = 0x08010000
164168
[env:STM32F103RC_creality]
165169
extends = STM32F103Rx_creality
166170
board = genericSTM32F103RC
171+
extra_scripts = ${STM32F103Rx_creality.extra_scripts}
172+
buildroot/share/PlatformIO/scripts/upload_prompt_extra_script.py
173+
upload_protocol = mbed
167174

168175
[env:STM32F103RC_creality_xfer]
169176
extends = STM32F103Rx_creality_xfer

0 commit comments

Comments
 (0)