This commit is contained in:
2020-10-06 19:33:37 -05:00
1774 changed files with 89990 additions and 22172 deletions

View File

@ -0,0 +1,201 @@
#!/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
import os
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 = os.path.join(input_examples_dir, subdir, filename)
try:
# UTF-8 because some files contain unicode chars
with open(infilepath, '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 = os.path.join(output_examples_dir, subdir)
outfilepath = os.path.join(outdir, filename)
if file_modified:
# Note: no need to create output dirs, as the initial copy_tree
# will do that.
print(' writing ' + str(outfilepath))
try:
# Preserve unicode chars; Avoid CR-LF on Windows.
with open(outfilepath, "w", encoding="utf-8", newline='\n') as outfile:
outfile.write("\n".join(outlines))
outfile.write("\n")
except Exception as e:
print('Failed to write file: ' + str(e) )
raise Exception
else:
print(' no change for ' + str(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 (os.path.exists(dir)):
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 = len(input_examples_dir);
len_input_examples_dir += 1
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

@ -2,10 +2,10 @@
"""Thermistor Value Lookup Table Generator
Generates lookup to temperature values for use in a microcontroller in C format based on:
http://en.wikipedia.org/wiki/Steinhart-Hart_equation
https://en.wikipedia.org/wiki/Steinhart-Hart_equation
The main use is for Arduino programs that read data from the circuit board described here:
http://reprap.org/wiki/Temperature_Sensor_v2.0
https://reprap.org/wiki/Temperature_Sensor_v2.0
Usage: python createTemperatureLookupMarlin.py [options]

View File

@ -38,10 +38,12 @@ for (let m of mpatt) mexpr.push(new RegExp('^' + m + '$'));
const argv = process.argv.slice(2), argc = argv.length;
var src_file = 0, src_name = 'STDIN', dst_file;
var src_file = 0, src_name = 'STDIN', dst_file, do_log = false;
if (argc > 0) {
src_file = src_name = argv[0];
dst_file = argv[argc > 1 ? 1 : 0];
let ind = 0;
if (argv[0] == '-v') { do_log = true; ind++; }
dst_file = src_file = src_name = argv[ind++];
if (ind < argc) dst_file = argv[ind];
}
// Read from file or STDIN until it terminates
@ -81,7 +83,7 @@ function process_text(txt) {
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*(//.*)?$'),
defPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+([-_\\w]+)\\s*(//.*)?$'),
condPatt = new RegExp('^(\\s*(//)?#(if|ifn?def|else|elif)(\\s+\\S+)*)\\s+(//.*)$'),
commPatt = new RegExp('^\\s{20,}(//.*)?$');
const col_value_lj = col_comment - patt.pad - 2;
@ -98,6 +100,7 @@ function process_text(txt) {
//
// #define MY_PIN [pin]
//
if (do_log) console.log("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) + pinnum;
@ -107,31 +110,57 @@ function process_text(txt) {
//
// #define MY_PIN -1
//
if (do_log) console.log("pin -1:", line);
line = r[1] + ' ' + r[3];
line = line.rpad(col_value_lj) + '-1';
if (r[5]) line = line.rpad(col_comment) + r[5];
}
else if ((r = skipPatt.exec(line)) !== null) {
//
// #define SKIP_ME
//
if (do_log) console.log("skip:", line);
}
else if ((r = aliasPatt.exec(line)) !== null) {
//
// #define ALIAS OTHER
//
if (do_log) console.log("alias:", line);
line = r[1] + ' ' + r[3];
line += r[4].lpad(col_value_rj + 1 - line.length);
if (r[5]) line = line.rpad(col_comment) + r[5];
}
else if ((r = switchPatt.exec(line)) !== null) {
//
// #define SWITCH
//
if (do_log) console.log("switch:", line);
line = r[1] + ' ' + r[3];
if (r[4]) line = line.rpad(col_comment) + r[4];
check_comment_next = true;
}
else if ((r = defPatt.exec(line)) !== null) {
line = r[1] + ' ' + r[3] + ' ' + r[4];
if (r[5]) line = line.rpad(col_comment) + r[5];
//
// #define ...
//
if (do_log) console.log("def:", line);
line = r[1] + ' ' + r[3] + ' ';
line += 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 ...
//
if (do_log) console.log("undef:", line);
line = r[1] + ' ' + r[3];
if (r[4]) line = line.rpad(col_comment) + r[4];
}
else if ((r = condPatt.exec(line)) !== null) {
//
// #if ...
//
if (do_log) console.log("cond:", line);
line = r[1].rpad(col_comment) + r[5];
check_comment_next = true;
}