Skip to content

Commit

Permalink
override mounts support
Browse files Browse the repository at this point in the history
  • Loading branch information
pellcorp committed Dec 16, 2024
1 parent 3e74100 commit 942f1a0
Show file tree
Hide file tree
Showing 16 changed files with 586 additions and 18 deletions.
107 changes: 107 additions & 0 deletions k1/apply-mount-overrides.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/sh

CONFIG_HELPER="/usr/data/pellcorp/k1/config-helper.py"

MODEL=$(/usr/bin/get_sn_mac.sh model)
if [ "$MODEL" = "CR-K1" ] || [ "$MODEL" = "K1C" ] || [ "$MODEL" = "K1 SE" ]; then
model=k1
elif [ "$MODEL" = "CR-K1 Max" ] || [ "$MODEL" = "K1 Max SE" ]; then
model=k1m
else
echo "This script is not supported for $MODEL!"
exit 1
fi

function apply_mount_overrides() {
local probe=$1
local mount=$2

return_status=0
overrides_dir=/usr/data/pellcorp/k1/mounts/$probe/$mount
if [ ! -f /usr/data/pellcorp/k1/mounts/$probe/${mount}.overrides ]; then
echo "ERROR: Probe and Mount combination not found"
exit 0 # FIXME unfortunately we are using this exit code to know overrides were applied
fi

echo "INFO: Applying mount overrides ..."
overrides_dir=/tmp/overrides.$$
mkdir $overrides_dir
file=
while IFS= read -r line; do
if echo "$line" | grep -q "^--"; then
file=$(echo $line | sed 's/-- //g')
touch $overrides_dir/$file
elif echo "$line" | grep -q "^#"; then
continue # skip comments
elif [ -n "$file" ] && [ -f $overrides_dir/$file ]; then
echo "$line" >> $overrides_dir/$file
fi
done < "/usr/data/pellcorp/k1/mounts/$probe/${mount}.overrides"

files=$(find $overrides_dir -maxdepth 1 -name "*.cfg")
for file in $files; do
file=$(basename $file)

if [ "$file" = "bltouch.cfg" ] && [ "$probe" = "bltouch" ]; then # bltouch.cfg is merged into printer.cfg
target_file=printer.cfg
elif [ "$file" = "microprobe.cfg" ] && [ "$probe" = "microprobe" ]; then # microprobe.cfg is merged into printer.cfg
target_file=printer.cfg
elif [ "$file" = "printer-${model}.cfg" ]; then
target_file=printer.cfg
else
target_file=$file
fi

if [ -f /usr/data/printer_data/config/$target_file ]; then
echo "Applying mount overrides for $target_file ..."
$CONFIG_HELPER --file $target_file --overrides $overrides_dir/$file || exit $?
fi
return_status=1
done
rm -rf $overrides_dir
sync
return $return_status
}

mode=config
if [ "$1" = "--verify" ]; then
mode=verify
shift
fi

# note for cartotouch we pass in 'cartographer' as the mount
if [ $# -eq 0 ]; then
echo "Usage: $0 <cartotouch|btteddy|microprobe|bltouch> <mount>"
exit 0
fi

probe=$1
mount=$2

if [ "$mode" = "verify" ]; then
if [ -d /usr/data/pellcorp/k1/mounts/$probe ]; then
if [ -f /usr/data/pellcorp/k1/mounts/$probe/${mount}.overrides ]; then
exit 0
else
if [ -n "$mount" ]; then
echo "ERROR: Invalid $probe mount $mount specified!"
fi
echo
echo "The following mounts are available:"
echo
files=$(find /usr/data/pellcorp/k1/mounts/$probe -maxdepth 1 -name "*.overrides")
for file in $files; do
comment=$(cat $file | grep "^#" | head -1 | sed 's/#\s*//g')
file=$(basename $file .overrides)
echo " * $file - $comment"
done
echo
exit 1
fi
else
echo "ERROR: Invalid probe $probe specified!"
exit 1
fi
else
apply_mount_overrides "$probe" "$mount"
fi
18 changes: 9 additions & 9 deletions k1/apply-overrides.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function apply_overrides() {
return_status=0
if [ -f /usr/data/pellcorp-overrides.cfg ] || [ -d /usr/data/pellcorp-overrides ]; then
echo ""
echo "Applying overrides ..."
echo "INFO: Applying overrides ..."

overrides_dir=/usr/data/pellcorp-overrides
if [ -f /usr/data/pellcorp-overrides.cfg ]; then
Expand All @@ -29,7 +29,7 @@ function apply_overrides() {
file=$(basename $file)
# special case for moonraker.secrets
if [ "$file" = "moonraker.secrets" ]; then
echo "Restoring /usr/data/printer_data/$file ..."
echo "INFO: Restoring /usr/data/printer_data/$file ..."
cp $overrides_dir/$file /usr/data/printer_data/
elif [ "$file" = "guppyconfig.json" ]; then
command=""
Expand All @@ -46,18 +46,18 @@ function apply_overrides() {
fi
fi
done
echo "Applying overrides /usr/data/guppyscreen/guppyconfig.json ..."
echo "INFO: Applying overrides /usr/data/guppyscreen/guppyconfig.json ..."
jq "$command" /usr/data/pellcorp/k1/guppyconfig.json > /usr/data/guppyscreen/guppyconfig.json
elif [ -L /usr/data/printer_data/config/$file ] || [ "$file" = "guppyscreen.cfg" ]; then
echo "Ignoring $file ..."
echo "WARN: Ignoring $file ..."
elif [ -f "/usr/data/pellcorp-backups/$file" ] || [ -f "/usr/data/pellcorp/k1/$file" ]; then
if [ -f /usr/data/printer_data/config/$file ]; then
# we renamed the SENSORLESS_PARAMS to hide it
if [ "$file" = "sensorless.cfg" ]; then
sed -i 's/gcode_macro SENSORLESS_PARAMS/gcode_macro _SENSORLESS_PARAMS/g' /usr/data/pellcorp-overrides/sensorless.cfg
fi

echo "Applying overrides for /usr/data/printer_data/config/$file ..."
echo "INFO: Applying overrides for /usr/data/printer_data/config/$file ..."
cp /usr/data/printer_data/config/$file /usr/data/printer_data/config/backups/${file}.override.bkp
$CONFIG_HELPER --file $file --overrides $overrides_dir/$file || exit $?

Expand All @@ -67,10 +67,10 @@ function apply_overrides() {
/usr/data/pellcorp/k1/config-helper.py --file moonraker.conf --remove-section "update_manager cartographer"
fi
else # if switching probes we might run into this
echo "Ignoring overrides for missing /usr/data/printer_data/config/$file"
echo "WARN: Ignoring overrides for missing /usr/data/printer_data/config/$file"
fi
elif [ "$file" != "printer.cfg.save_config" ]; then
echo "Restoring /usr/data/printer_data/config/$file ..."
echo "INFO: Restoring /usr/data/printer_data/config/$file ..."
cp $overrides_dir/$file /usr/data/printer_data/config/
fi
# fixme - we currently have no way to know if the file was updated assume if we got here it was
Expand All @@ -81,12 +81,12 @@ function apply_overrides() {
if [ -f $overrides_dir/printer.cfg.save_config ]; then
# if the printer.cfg already has SAVE_CONFIG skip applying it again
if ! grep -q "#*# <---------------------- SAVE_CONFIG ---------------------->" /usr/data/printer_data/config/printer.cfg ; then
echo "Applying save config state to /usr/data/printer_data/config/printer.cfg"
echo "INFO: Applying save config state to /usr/data/printer_data/config/printer.cfg"
echo "" >> /usr/data/printer_data/config/printer.cfg
cat $overrides_dir/printer.cfg.save_config >> /usr/data/printer_data/config/printer.cfg
return_status=1
else
echo "Skipped applying save config state to /usr/data/printer_data/config/printer.cfg"
echo "WARN: Skipped applying save config state to /usr/data/printer_data/config/printer.cfg"
fi
fi

Expand Down
3 changes: 0 additions & 3 deletions k1/btteddy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ y_offset: 0.0
sensor_type: Generic 3950
sensor_pin: eddy: gpio26
horizontal_move_z: 2.0

[force_move]
enable_force_move: True
4 changes: 2 additions & 2 deletions k1/cartographer-k1.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ bicubic_tension: 0.1

# based on https://github.com/Guilouz/Creality-Helper-Script/blob/main/files/screws-tilt-adjust/screws-tilt-adjust-k1.cfg
[screws_tilt_adjust]
screw1: 42,20
screw1: 41,20
screw1_name: front left screw
screw2: 211,20
screw2_name: front right screw
screw3: 211,190
screw3_name: rear right screw
screw4: 42,190
screw4: 41,190
screw4_name: rear left screw
speed: 100
horizontal_move_z: 5
Expand Down
33 changes: 29 additions & 4 deletions k1/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ setup_bltouch() {
cleanup_probe cartotouch
cleanup_probe beacon

# we merge bltouch.cfg into printer.cfg so that z_offset can be set
if [ -f /usr/data/printer_data/config/bltouch.cfg ]; then
rm /usr/data/printer_data/config/bltouch.cfg
fi
Expand Down Expand Up @@ -1021,12 +1022,13 @@ setup_microprobe() {
if [ $? -ne 0 ]; then
echo
echo "INFO: Setting up microprobe ..."

cleanup_probe bltouch
cleanup_probe btteddy
cleanup_probe cartotouch
cleanup_probe beacon

# we merge microprobe.cfg into printer.cfg so that z_offset can be set
if [ -f /usr/data/printer_data/config/microprobe.cfg ]; then
rm /usr/data/printer_data/config/microprobe.cfg
fi
Expand Down Expand Up @@ -1291,6 +1293,7 @@ fi
client=cli
mode=install
skip_overrides=false
mount=
# parse arguments here
while true; do
if [ "$1" = "--install" ] || [ "$1" = "--update" ] || [ "$1" = "--reinstall" ] || [ "$1" = "--clean-install" ] || [ "$1" = "--clean-update" ] || [ "$1" = "--clean-reinstall" ]; then
Expand All @@ -1300,6 +1303,10 @@ while true; do
skip_overrides=true
mode=$(echo $mode | sed 's/clean-//g')
fi
elif [ "$1" = "--mount" ]; then
shift
mount=$1
shift
elif [ "$1" = "--client" ]; then
shift
client=$1
Expand Down Expand Up @@ -1327,6 +1334,19 @@ echo
echo "INFO: Mode is $mode"
echo "INFO: Probe is $probe"

if [ -n "$mount" ]; then
/usr/data/pellcorp/k1/apply-mount-overrides.sh --verify $probe $mount
if [ $? -eq 0 ]; then
echo "INFO: Mount is $mount"
else
exit 1
fi
#elif [ "$mode" = "install" ] || [ "$mode" = "reinstall" ]; then
# a mount is only required for a brand new installation if no overrides are presnet
# echo "ERROR: --mount is a required parameter for a clean install or reinstall"
# exit 1
fi

if [ "$probe" = "cartographer" ]; then
echo
echo "ERROR: Cartographer for 4.0.0 firmware is no longer supported!"
Expand Down Expand Up @@ -1466,11 +1486,11 @@ else
fi

apply_overrides=0
apply_mount_overrides=0
# there will be no support for generating pellcorp-overrides unless you have done a factory reset
if [ -f /usr/data/pellcorp-backups/printer.factory.cfg ]; then
probe_model=${probe}

# FIXME - when we migrate cartotouch back to cartographer remember to remove this if
if [ "$probe" = "cartotouch" ]; then
probe_model=cartographer
fi
Expand All @@ -1484,7 +1504,12 @@ if [ -f /usr/data/pellcorp-backups/printer.factory.cfg ]; then
done

if [ -f /usr/data/guppyscreen/guppyconfig.json ]; then
cp /usr/data/guppyscreen/guppyconfig.json /usr/data/pellcorp-backups/
cp /usr/data/guppyscreen/guppyconfig.json /usr/data/pellcorp-backups/
fi

if [ -n "$mount" ]; then
/usr/data/pellcorp/k1/apply-mount-overrides.sh $probe $mount
apply_mount_overrides=$?
fi

if [ "$skip_overrides" != "true" ]; then
Expand Down Expand Up @@ -1514,7 +1539,7 @@ if [ $install_moonraker -ne 0 ] || [ $install_nginx -ne 0 ] || [ $install_fluidd
fi
fi

if [ $apply_overrides -ne 0 ] || [ $install_cartographer_klipper -ne 0 ] || [ $install_beacon_klipper -ne 0 ] || [ $install_kamp -ne 0 ] || [ $install_klipper -ne 0 ] || [ $install_guppyscreen -ne 0 ] || [ $setup_probe -ne 0 ] || [ $setup_probe_specific -ne 0 ]; then
if [ $apply_overrides -ne 0 ] || [ $apply_mount_overrides -ne 0 ] || [ $install_cartographer_klipper -ne 0 ] || [ $install_beacon_klipper -ne 0 ] || [ $install_kamp -ne 0 ] || [ $install_klipper -ne 0 ] || [ $install_guppyscreen -ne 0 ] || [ $setup_probe -ne 0 ] || [ $setup_probe_specific -ne 0 ]; then
if [ "$client" = "cli" ]; then
echo
echo "INFO: Restarting Klipper ..."
Expand Down
38 changes: 38 additions & 0 deletions k1/mounts/bltouch/CrTouch.overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# https://www.printables.com/model/1073375-cr-touch-mount-k1-k1maxk1c-zero-y-offset

-- bltouch.cfg
[bltouch]
x_offset: -37
y_offset: 0

-- bltouch-k1.cfg
[bed_mesh]
mesh_min: 3,5
mesh_max: 192,215

[screws_tilt_adjust]
screw1: 62,20
screw2: 232,20
screw3: 232,190
screw4: 62,190

-- bltouch-k1m.cfg
[bed_mesh]
mesh_min: 3,5
mesh_max: 192,215

[screws_tilt_adjust]
screw1: 56,23
screw2: 306,23
screw3: 285,272
screw4: 85,272

-- printer-k1.cfg
[stepper_y]
position_endstop: 226
position_max: 226

-- printer-k1m.cfg
[stepper_y]
position_endstop: 306
position_max: 306
38 changes: 38 additions & 0 deletions k1/mounts/bltouch/Default.overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# https://www.printables.com/model/666186-creality-k1-bltouch-adapter

-- bltouch.cfg
[bltouch]
x_offset: 0.0
y_offset: 25.25

-- bltouch-k1.cfg
[bed_mesh]
mesh_min: 5,30
mesh_max: 210,209

[screws_tilt_adjust]
screw1: 25,0
screw2: 195,0
screw3: 195,165
screw4: 25,165

-- bltouch-k1m.cfg
[bed_mesh]
mesh_min: 5,30
mesh_max: 285,280

[screws_tilt_adjust]
screw1: 19,0
screw2: 278,0
screw3: 248,252
screw4: 48,252

-- printer-k1.cfg
[stepper_y]
position_endstop: 210
position_max: 210

-- printer-k1m.cfg
[stepper_y]
position_endstop: 290
position_max: 290
Loading

0 comments on commit 942f1a0

Please sign in to comment.