Merge upstream changes from Marlin 2.1.2.5

This commit is contained in:
Stefan Kalscheuer
2024-11-23 13:43:26 +01:00
parent c41a85354a
commit c8ff13654b
376 changed files with 4922 additions and 3840 deletions

View File

@@ -181,7 +181,7 @@ class Protocol(object):
except ReadTimeout:
self.errors += 1
#print("Packetloss detected..")
except serial.serialutil.SerialException:
except serial.SerialException:
return
self.packet_transit = None
@@ -201,7 +201,7 @@ class Protocol(object):
def transmit_packet(self, packet):
packet = bytearray(packet)
if(self.simulate_errors > 0 and random.random() > (1.0 - self.simulate_errors)):
if (self.simulate_errors > 0 and random.random() > (1.0 - self.simulate_errors)):
if random.random() > 0.9:
#random data drop
start = random.randint(0, len(packet))

View File

@@ -22,7 +22,7 @@ from __future__ import print_function
from __future__ import division
from math import *
import sys,getopt
import sys, getopt
"Constants"
ZERO = 273.15 # zero point of Kelvin scale

View File

@@ -5,7 +5,7 @@ Extract the builds used in Github CI, so that we can run them locally
import yaml
# Set the yaml file to parse
yaml_file = '.github/workflows/test-builds.yml'
yaml_file = '.github/workflows/ci-build-tests.yml'
# Parse the yaml file, and load it into a dictionary (github_configuration)
with open(yaml_file) as f:

View File

@@ -22,43 +22,54 @@
# Generate Marlin TFT Images from bitmaps/PNG/JPG
import sys,struct
import sys, struct
from PIL import Image
def image2bin(image, output_file):
def image2bin(image, output_file, transparency):
w, h = image.size[0], image.size[1]
print(f"Converting image with dimensions {w}x{h}...")
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]))
row_sp, item_sp = (" ", "") if w >= 480 else (" ", " ")
row_end, data_end = "\n", "};\n"
f = open(output_file, 'wt')
f.write("const uint16_t image[%d] = {\n" % (h * w))
else:
f = open(output_file, 'wb')
is_cpp = False
row_sp, row_end, data_end = b"", b"", b""
f = open(output_file, 'wb')
tcolor, got_tcolor = 0, False
pixs = image.load()
for y in range(image.size[1]):
for x in range(image.size[0]):
for y in range(h):
f.write(row_sp)
for x in range(w):
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 transparency:
if not got_tcolor:
got_tcolor = True
tcolor = rgb # First pixel color is transparent
if rgb == tcolor: rgb = 1 # "color 1" is transparent
if is_cpp:
strHex = '0x{0:04X}, '.format(rgb)
strHex = item_sp + "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.write(row_end)
f.write(data_end)
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")
print("Usage: gen-tft-image.py INPUT_IMAGE.(png|bmp|jpg) OUTPUT_FILE.(cpp|bin) [--transparency]")
print("Authors: rhapsodyv, thinkyhead")
exit(1)
transparency = len(sys.argv) > 3 and sys.argv[3] == "--transparency"
output_img = sys.argv[2]
img = Image.open(sys.argv[1])
image2bin(img, output_img)
image2bin(img, output_img, transparency)

View File

@@ -1,20 +1,22 @@
#!/usr/bin/env python3
'''
languageExport.py
languageExport.py [--single]
Export LCD language strings to CSV files for easier translation.
Use importTranslations.py to import CSV into the language files.
Use languageImport.py to import CSV into the language files.
Use --single to export all languages to a single CSV file.
'''
import re
from pathlib import Path
from sys import argv
from languageUtil import namebyid
LANGHOME = "Marlin/src/lcd/language"
# Write multiple sheets if true, otherwise write one giant sheet
MULTISHEET = True
MULTISHEET = '--single' not in argv[1:]
OUTDIR = 'out-csv'
# Check for the path to the language files
@@ -28,7 +30,7 @@ LIMIT = 0
# A dictionary to contain strings for each language.
# Init with 'en' so English will always be first.
language_strings = { 'en': 0 }
language_strings = { 'en': {} }
# A dictionary to contain all distinct LCD string names
names = {}

View File

@@ -17,7 +17,7 @@ TODO: Use the defines and comments above the namespace from existing language fi
"""
import sys, re, requests, csv, datetime
from languageUtil import namebyid
#from languageUtil import namebyid
LANGHOME = "Marlin/src/lcd/language"
OUTDIR = 'out-language'
@@ -76,10 +76,10 @@ for row in reader:
# Add the named string for all the included languages
name = row[0]
for i in range(1, numcols):
str = row[i]
if str:
str_key = row[i]
if str_key:
col = columns[i]
strings_per_lang[col['lang']][col['style']][name] = str
strings_per_lang[col['lang']][col['style']][name] = str_key
# Create a folder for the imported language outfiles
from pathlib import Path
@@ -199,11 +199,11 @@ for i in range(1, numcols):
comm = ''
if lang != 'en' and 'en' in strings_per_lang:
en = strings_per_lang['en']
if name in en[style]: str = en[style][name]
elif name in en['Narrow']: str = en['Narrow'][name]
if str:
if name in en[style]: str_key = en[style][name]
elif name in en['Narrow']: str_key = en['Narrow'][name]
if str_key:
cfmt = '%%%ss// %%s' % (50 - len(val) if len(val) < 50 else 1)
comm = cfmt % (' ', str)
comm = cfmt % (' ', str_key)
# Write out the string definition
f.write(lstr_fmt % (name, val, comm))

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# marlang.py
# languageUtil.py
#
# A dictionary to contain language names

View File

@@ -1,197 +0,0 @@
#!/usr/bin/env node
//
// Formatter script for pins_MYPINS.h files
//
// Usage: mffmt [infile] [outfile]
//
// With no parameters convert STDIN to STDOUT
//
const fs = require("fs");
var do_log = false
function logmsg(msg, line='') {
if (do_log) console.log(msg, line);
}
// String lpad / rpad
String.prototype.lpad = function(len, chr) {
if (!len) return this;
if (chr === undefined) chr = ' ';
var s = this+'', need = len - s.length;
if (need > 0) s = new Array(need+1).join(chr) + s;
return s;
};
String.prototype.rpad = function(len, chr) {
if (!len) return this;
if (chr === undefined) chr = ' ';
var s = this+'', need = len - s.length;
if (need > 0) s += new Array(need+1).join(chr);
return s;
};
// Concatenate a string, adding a space if necessary
// to avoid merging two words
String.prototype.concat_with_space = function(str) {
const c = this.substr(-1), d = str.charAt(0);
if (c !== ' ' && c !== '' && d !== ' ' && d !== '')
str = ' ' + str;
return this + str;
};
const mpatt = [ '-?\\d{1,3}', 'P[A-I]\\d+', 'P\\d_\\d+', 'Pin[A-Z]\\d\\b' ],
definePatt = new RegExp(`^\\s*(//)?#define\\s+[A-Z_][A-Z0-9_]+\\s+(${mpatt.join('|')})\\s*(//.*)?$`, 'gm'),
ppad = [ 3, 4, 5, 5 ],
col_comment = 50,
col_value_rj = col_comment - 3;
var mexpr = [];
for (let m of mpatt) mexpr.push(new RegExp('^' + m + '$'));
const argv = process.argv.slice(2), argc = argv.length;
var src_file = 0, dst_file;
if (argc > 0) {
let ind = 0;
if (argv[0] == '-v') { do_log = true; ind++; }
dst_file = src_file = argv[ind++];
if (ind < argc) dst_file = argv[ind];
}
// Read from file or STDIN until it terminates
const filtered = process_text(fs.readFileSync(src_file).toString());
if (dst_file)
fs.writeFileSync(dst_file, filtered);
else
console.log(filtered);
// Find the pin pattern so non-pin defines can be skipped
function get_pin_pattern(txt) {
var r, m = 0, match_count = [ 0, 0, 0, 0 ];
var max_match_count = 0, max_match_index = -1;
definePatt.lastIndex = 0;
while ((r = definePatt.exec(txt)) !== null) {
let ind = -1;
if (mexpr.some((p) => {
ind++;
const didmatch = r[2].match(p);
return r[2].match(p);
}) ) {
const m = ++match_count[ind];
if (m > max_match_count) {
max_match_count = m;
max_match_index = ind;
}
}
}
if (max_match_index === -1) return null;
return { match:mpatt[max_match_index], pad:ppad[max_match_index] };
}
function process_text(txt) {
if (!txt.length) return '(no text)';
const patt = get_pin_pattern(txt);
if (!patt) return txt;
const pindefPatt = new RegExp(`^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+(${patt.match})\\s*(//.*)?$`),
noPinPatt = new RegExp(`^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+(-1)\\s*(//.*)?$`),
skipPatt1 = new RegExp('^(\\s*(//)?#define)\\s+(AT90USB|USBCON|(BOARD|DAC|FLASH|HAS|IS|USE)_.+|.+_(ADDRESS|AVAILABLE|BAUDRATE|CLOCK|CONNECTION|DEFAULT|ERROR|EXTRUDERS|FREQ|ITEM|MKS_BASE_VERSION|MODULE|NAME|ONLY|ORIENTATION|PERIOD|RANGE|RATE|READ_RETRIES|SERIAL|SIZE|SPI|STATE|STEP|TIMER|VERSION))\\s+(.+)\\s*(//.*)?$'),
skipPatt2 = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+(0x[0-9A-Fa-f]+|\d+|.+[a-z].+)\\s*(//.*)?$'),
skipPatt3 = /^\s*#e(lse|ndif)\b.*$/,
aliasPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+([A-Z_][A-Z0-9_()]+)\\s*(//.*)?$'),
switchPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s*(//.*)?$'),
undefPatt = new RegExp('^(\\s*(//)?#undef)\\s+([A-Z_][A-Z0-9_]+)\\s*(//.*)?$'),
defPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+([-_\\w]+)\\s*(//.*)?$'),
condPatt = new RegExp('^(\\s*(//)?#(if|ifn?def|elif)(\\s+\\S+)*)\\s+(//.*)$'),
commPatt = new RegExp('^\\s{20,}(//.*)?$');
const col_value_lj = col_comment - patt.pad - 2;
var r, out = '', check_comment_next = false;
txt.split('\n').forEach((line) => {
if (check_comment_next)
check_comment_next = ((r = commPatt.exec(line)) !== null);
if (check_comment_next)
// Comments in column 45
line = ''.rpad(col_comment) + r[1];
else if (skipPatt1.exec(line) !== null) {
//
// #define SKIP_ME
//
logmsg("skip:", line);
}
else if ((r = pindefPatt.exec(line)) !== null) {
//
// #define MY_PIN [pin]
//
logmsg("pin:", line);
const pinnum = r[4].charAt(0) == 'P' ? r[4] : r[4].lpad(patt.pad);
line = r[1] + ' ' + r[3];
line = line.rpad(col_value_lj).concat_with_space(pinnum);
if (r[5]) line = line.rpad(col_comment).concat_with_space(r[5]);
}
else if ((r = noPinPatt.exec(line)) !== null) {
//
// #define MY_PIN -1
//
logmsg("pin -1:", line);
line = r[1] + ' ' + r[3];
line = line.rpad(col_value_lj).concat_with_space('-1');
if (r[5]) line = line.rpad(col_comment).concat_with_space(r[5]);
}
else if (skipPatt2.exec(line) !== null || skipPatt3.exec(line) !== null) {
//
// #define SKIP_ME
// #else, #endif
//
logmsg("skip:", line);
}
else if ((r = aliasPatt.exec(line)) !== null) {
//
// #define ALIAS OTHER
//
logmsg("alias:", line);
line = r[1] + ' ' + r[3];
line = line.concat_with_space(r[4].lpad(col_value_rj + 1 - line.length));
if (r[5]) line = line.rpad(col_comment).concat_with_space(r[5]);
}
else if ((r = switchPatt.exec(line)) !== null) {
//
// #define SWITCH
//
logmsg("switch:", line);
line = r[1] + ' ' + r[3];
if (r[4]) line = line.rpad(col_comment).concat_with_space(r[4]);
check_comment_next = true;
}
else if ((r = defPatt.exec(line)) !== null) {
//
// #define ...
//
logmsg("def:", line);
line = r[1] + ' ' + r[3] + ' ';
line = line.concat_with_space(r[4].lpad(col_value_rj + 1 - line.length));
if (r[5]) line = line.rpad(col_comment - 1) + ' ' + r[5];
}
else if ((r = undefPatt.exec(line)) !== null) {
//
// #undef ...
//
logmsg("undef:", line);
line = r[1] + ' ' + r[3];
if (r[4]) line = line.rpad(col_comment).concat_with_space(r[4]);
}
else if ((r = condPatt.exec(line)) !== null) {
//
// #if, #ifdef, #ifndef, #elif ...
//
logmsg("cond:", line);
line = r[1].rpad(col_comment).concat_with_space(r[5]);
check_comment_next = true;
}
out += line + '\n';
});
return out.replace(/\n\n+/g, '\n\n').replace(/\n\n$/g, '\n');
}

View File

@@ -27,6 +27,13 @@ def rpad(astr, fill, c=' '):
need = fill - len(astr)
return astr if need <= 0 else astr + (need * c)
# Concatenate a string, adding a space if necessary
# to avoid merging two words
def concat_with_space(s1, s2):
if not s1.endswith(' ') and not s2.startswith(' '):
s1 += ' '
return s1 + s2
# Pin patterns
mpatt = [ r'-?\d{1,3}', r'P[A-I]\d+', r'P\d_\d+', r'Pin[A-Z]\d\b' ]
mstr = '|'.join(mpatt)
@@ -36,7 +43,7 @@ mexpr = [ re.compile(f'^{m}$') for m in mpatt ]
ppad = [ 3, 4, 5, 5 ]
# Match a define line
definePatt = re.compile(rf'^\s*(//)?#define\s+[A-Z_][A-Z0-9_]+\s+({mstr})\s*(//.*)?$')
definePinPatt = re.compile(rf'^\s*(//)?#define\s+[A-Z_][A-Z0-9_]+?_PIN\s+({mstr})\s*(//.*)?$')
def format_pins(argv):
src_file = 'stdin'
@@ -45,6 +52,7 @@ def format_pins(argv):
scnt = 0
for arg in argv:
if arg == '-v':
global do_log
do_log = True
elif scnt == 0:
# Get a source file if specified. Default destination is the same file
@@ -85,7 +93,7 @@ def get_pin_pattern(txt):
# Find the most common matching pattern
match_threshold = 5
for line in txt.split('\n'):
r = definePatt.match(line)
r = definePinPatt.match(line)
if r == None: continue
ind = -1
for p in mexpr:
@@ -135,7 +143,7 @@ def process_text(txt):
logmsg("pin:", line)
pinnum = r[4] if r[4][0] == 'P' else lpad(r[4], patt['pad'])
line = f'{r[1]} {r[3]}'
line = rpad(line, col_value_lj) + pinnum
line = concat_with_space(rpad(line, col_value_lj), pinnum)
if r[5]: line = rpad(line, col_comment) + r[5]
d['line'] = line
return True
@@ -149,7 +157,7 @@ def process_text(txt):
if r == None: return False
logmsg("pin -1:", line)
line = f'{r[1]} {r[3]}'
line = rpad(line, col_value_lj) + '-1'
line = concat_with_space(rpad(line, col_value_lj), '-1')
if r[5]: line = rpad(line, col_comment) + r[5]
d['line'] = line
return True
@@ -179,8 +187,8 @@ def process_text(txt):
if r == None: return False
logmsg("alias:", line)
line = f'{r[1]} {r[3]}'
line += lpad(r[4], col_value_rj + 1 - len(line))
if r[5]: line = rpad(line, col_comment) + r[5]
line = concat_with_space(line, lpad(r[4], col_value_rj + 1 - len(line)))
if r[5]: line = concat_with_space(rpad(line, col_comment), r[5])
d['line'] = line
return True
@@ -193,7 +201,7 @@ def process_text(txt):
if r == None: return False
logmsg("switch:", line)
line = f'{r[1]} {r[3]}'
if r[4]: line = rpad(line, col_comment) + r[4]
if r[4]: line = concat_with_space(rpad(line, col_comment), r[4])
d['line'] = line
d['check_comment_next'] = True
return True
@@ -207,7 +215,7 @@ def process_text(txt):
if r == None: return False
logmsg("def:", line)
line = f'{r[1]} {r[3]} '
line += lpad(r[4], col_value_rj + 1 - len(line))
line = concat_with_space(line, lpad(r[4], col_value_rj + 1 - len(line)))
if r[5]: line = rpad(line, col_comment - 1) + ' ' + r[5]
d['line'] = line
return True
@@ -221,7 +229,7 @@ def process_text(txt):
if r == None: return False
logmsg("undef:", line)
line = f'{r[1]} {r[3]}'
if r[4]: line = rpad(line, col_comment) + r[4]
if r[4]: line = concat_with_space(rpad(line, col_comment), r[4])
d['line'] = line
return True
@@ -233,7 +241,7 @@ def process_text(txt):
r = condPatt.match(line)
if r == None: return False
logmsg("cond:", line)
line = rpad(r[1], col_comment) + r[5]
line = concat_with_space(rpad(r[1], col_comment), r[5])
d['line'] = line
d['check_comment_next'] = True
return True
@@ -263,7 +271,7 @@ def process_text(txt):
elif tryUndef(wDict): pass #undef ...
elif tryCond(wDict): pass #if|ifdef|ifndef|elif ...
out += wDict['line'] + '\n'
out += wDict['line'].rstrip() + '\n'
return re.sub('\n\n$', '\n', re.sub(r'\n\n+', '\n\n', out))

View File

@@ -1,11 +1,6 @@
import argparse
import sys
import os
import time
import random
import serial
Import("env")
import argparse, sys, os, time, random, serial
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
import MarlinBinaryProtocol