Merge upstream changes from Marlin 2.1.2

This commit is contained in:
Stefan Kalscheuer
2022-12-19 15:23:45 +01:00
parent fe9ea826a5
commit 67c7ce7b79
427 changed files with 10732 additions and 7834 deletions

View File

@@ -1,198 +0,0 @@
#!/usr/bin/env python3
#
# for python3.5 or higher
#-----------------------------------
# Within Marlin project MarlinFirmware/Configurations, this program visits all folders
# under .../config/examples/*, processing each Configuration.h, Configuration_adv.h,
# _Bootscreen.h, and _Statusscreen.h, to insert:
# #define CONFIG_EXAMPLES_DIR "examples/<style>/<vendor>/<model>"
# ... or similar path leading to this file.
#
# Warning: The program modifies files in place, so be sure to back them up first if needed.
# Can be run multiple times if needed. Only modifies files which don't have
# correct #define CONFIG_EXAMPLES_DIR line.
#
# Invocation:
#-------------
# 1. Change directory to your MarlinFirmware/Configurations working copy
# 2. python3 config-labels.py
#
#-----------------------------------
# 2020-05-10 GMW original
# 2020-06-05 SRL style tweaks
#-----------------------------------
#
import sys
from pathlib import Path
from distutils.dir_util import copy_tree # for copy_tree, because shutil.copytree can't handle existing files, dirs
# Modify input_examples_dir and output_examples_dir for your installation
# No trailing slash
# Setting output_examples_dir = input_examples_dir causes the program to insert into the existing files.
input_examples_dir = r'config/examples'
# output_examples_dir = input_examples_dir
output_examples_dir = r'config/examples'
#-------------------------------------
files_to_mod = ['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h', '_Statusscreen.h']
macro_name = 'CONFIG_EXAMPLES_DIR'
def_macro_name = '#define ' + macro_name
filenum = 0
different_out_dir = not (output_examples_dir == input_examples_dir)
#----------------------------------------------
def process_file(subdir: str, filename: str):
#----------------------------------------------
global filenum
filenum += 1
print(str(filenum) + ' ' + filename + ': ' + subdir)
def_line = (def_macro_name + ' "' + subdir.replace('\\', '/') + '"')
#------------------------
# Read file
#------------------------
lines = []
infilepath = Path(input_examples_dir, subdir, filename)
try:
# UTF-8 because some files contain unicode chars
with infilepath.open('rt', encoding="utf-8") as infile:
lines = infile.readlines()
except Exception as e:
print('Failed to read file: ' + str(e) )
raise Exception
lines = [line.rstrip('\r\n') for line in lines]
#------------------------
# Process lines
#------------------------
file_modified = False
# region state machine
# -1 = before pragma once;
# 0 = region to place define;
# 1 = past region to place define
region = -1
outlines = []
for line in lines:
outline = line
if (region == -1) and (def_macro_name in line):
outline = None
file_modified = True
elif (region == -1) and ('pragma once' in line):
region = 0
elif (region == 0):
if (line.strip() == ''):
pass
elif (def_macro_name in line):
region = 1
if line == def_line: # leave it as is
pass
else:
outline = def_line
file_modified = True
else: # some other string
outlines.append(def_line)
outlines.append('')
region = 1
file_modified = True
elif (region == 1):
if (def_macro_name in line):
outline = None
file_modified = True
else:
pass
# end if
if outline is not None:
outlines.append(outline)
# end for
#-------------------------
# Output file
#-------------------------
outdir = Path(output_examples_dir, subdir)
outfilepath = outdir / filename
if file_modified:
# Note: no need to create output dirs, as the initial copy_tree
# will do that.
print(' writing ' + outfilepath)
try:
# Preserve unicode chars; Avoid CR-LF on Windows.
with outfilepath.open("w", encoding="utf-8", newline='\n') as outfile:
outfile.write("\n".join(outlines) + "\n")
except Exception as e:
print('Failed to write file: ' + str(e) )
raise Exception
else:
print(' no change for ' + outfilepath)
#----------
def main():
#----------
global filenum
global input_examples_dir
global output_examples_dir
filenum = 0
#--------------------------------
# Check for requirements
#--------------------------------
input_examples_dir = input_examples_dir.strip()
input_examples_dir = input_examples_dir.rstrip('\\/')
output_examples_dir = output_examples_dir.strip()
output_examples_dir = output_examples_dir.rstrip('\\/')
for dir in (input_examples_dir, output_examples_dir):
if not Path(dir).exists():
print('Directory not found: ' + dir)
sys.exit(1)
#--------------------------------
# Copy tree if necessary.
#--------------------------------
# This includes files that are not otherwise included in the
# insertion of the define statement.
#
if different_out_dir:
print('Copying files to new directory: ' + output_examples_dir)
try:
copy_tree(input_examples_dir, output_examples_dir)
except Exception as e:
print('Failed to copy directory: ' + str(e) )
raise Exception
#-----------------------------
# Find and process files
#-----------------------------
len_input_examples_dir = 1 + len(input_examples_dir)
for filename in files_to_mod:
input_path = Path(input_examples_dir)
filepathlist = input_path.rglob(filename)
for filepath in filepathlist:
fulldirpath = str(filepath.parent)
subdir = fulldirpath[len_input_examples_dir:]
process_file(subdir, filename)
#==============
print('--- Starting config-labels ---')
main()
print('--- Done ---')

View File

@@ -22,42 +22,42 @@
# Generate Marlin TFT Images from bitmaps/PNG/JPG
import sys,re,struct
from PIL import Image,ImageDraw
import sys,struct
from PIL import Image
def image2bin(image, output_file):
if output_file.endswith(('.c', '.cpp')):
f = open(output_file, 'wt')
is_cpp = True
f.write("const uint16_t image[%d] = {\n" % (image.size[1] * image.size[0]))
else:
f = open(output_file, 'wb')
is_cpp = False
pixs = image.load()
for y in range(image.size[1]):
for x in range(image.size[0]):
R = pixs[x, y][0] >> 3
G = pixs[x, y][1] >> 2
B = pixs[x, y][2] >> 3
rgb = (R << 11) | (G << 5) | B
if is_cpp:
strHex = '0x{0:04X}, '.format(rgb)
f.write(strHex)
else:
f.write(struct.pack("B", (rgb & 0xFF)))
f.write(struct.pack("B", (rgb >> 8) & 0xFF))
if is_cpp:
f.write("\n")
if is_cpp:
f.write("};\n")
f.close()
if output_file.endswith(('.c', '.cpp')):
f = open(output_file, 'wt')
is_cpp = True
f.write("const uint16_t image[%d] = {\n" % (image.size[1] * image.size[0]))
else:
f = open(output_file, 'wb')
is_cpp = False
pixs = image.load()
for y in range(image.size[1]):
for x in range(image.size[0]):
R = pixs[x, y][0] >> 3
G = pixs[x, y][1] >> 2
B = pixs[x, y][2] >> 3
rgb = (R << 11) | (G << 5) | B
if is_cpp:
strHex = '0x{0:04X}, '.format(rgb)
f.write(strHex)
else:
f.write(struct.pack("B", (rgb & 0xFF)))
f.write(struct.pack("B", (rgb >> 8) & 0xFF))
if is_cpp:
f.write("\n")
if is_cpp:
f.write("};\n")
f.close()
if len(sys.argv) <= 2:
print("Utility to export a image in Marlin TFT friendly format.")
print("It will dump a raw bin RGB565 image or create a CPP file with an array of 16 bit image pixels.")
print("Usage: gen-tft-image.py INPUT_IMAGE.(png|bmp|jpg) OUTPUT_FILE.(cpp|bin)")
print("Author: rhapsodyv")
exit(1)
print("Utility to export a image in Marlin TFT friendly format.")
print("It will dump a raw bin RGB565 image or create a CPP file with an array of 16 bit image pixels.")
print("Usage: gen-tft-image.py INPUT_IMAGE.(png|bmp|jpg) OUTPUT_FILE.(cpp|bin)")
print("Author: rhapsodyv")
exit(1)
output_img = sys.argv[2]
img = Image.open(sys.argv[1])

View File

@@ -189,9 +189,7 @@ def Upload(source, target, env):
'BOARD_CREALITY_V427', 'BOARD_CREALITY_V431', 'BOARD_CREALITY_V452', 'BOARD_CREALITY_V453',
'BOARD_CREALITY_V24S1']
# "upload_random_name": generate a random 8.3 firmware filename to upload
upload_random_filename = marlin_motherboard in ['BOARD_CREALITY_V4', 'BOARD_CREALITY_V4210', 'BOARD_CREALITY_V422', 'BOARD_CREALITY_V423',
'BOARD_CREALITY_V427', 'BOARD_CREALITY_V431', 'BOARD_CREALITY_V452', 'BOARD_CREALITY_V453',
'BOARD_CREALITY_V24S1'] and not marlin_long_filename_host_support
upload_random_filename = upload_delete_old_bins and not marlin_long_filename_host_support
try:
@@ -304,7 +302,7 @@ def Upload(source, target, env):
except KeyboardInterrupt:
print('Aborted by user')
if filetransfer: filetransfer.abort()
if protocol:
if protocol:
protocol.disconnect()
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)
@@ -314,7 +312,7 @@ def Upload(source, target, env):
except serial.SerialException as se:
# This exception is raised only for send_ascii data (not for binary transfer)
print(f'Serial excepion: {se}, transfer aborted')
if protocol:
if protocol:
protocol.disconnect()
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)
@@ -323,7 +321,7 @@ def Upload(source, target, env):
except MarlinBinaryProtocol.FatalError:
print('Too many retries, transfer aborted')
if protocol:
if protocol:
protocol.disconnect()
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)
@@ -332,7 +330,7 @@ def Upload(source, target, env):
except Exception as ex:
print(f"\nException: {ex}, transfer aborted")
if protocol:
if protocol:
protocol.disconnect()
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)