Skip to content

Commit

Permalink
Merge pull request #52 from T9Air/v3.2.2
Browse files Browse the repository at this point in the history
V3.2.2
  • Loading branch information
T9Air authored Oct 2, 2024
2 parents 433d49f + 8de4fa7 commit 21ec469
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 62 deletions.
8 changes: 4 additions & 4 deletions Interface_scripts/add_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ read -r -p "Please input the filename: " filepath
if [[ "$filepath" == "" ]]; then
echo "Exiting..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi

# Initialize line number to skip
num=1

# Check if the filename has an extension
if [[ $filepath == *.* ]]; then
if [[ $filepath == *.gcode ]]; then
# If it has an extension, do not add an extension
filepath="/home/$USER/printer_data/gcodes/$filepath"
else
Expand All @@ -36,7 +36,7 @@ fi
if [[ ! -f "$filepath" ]]; then
echo "File not found: $filepath" # Error message if file not found
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
fi

# Prompt the user for the number of lines to skip
Expand All @@ -58,5 +58,5 @@ echo "LOG_FINISHED" >> $filepath
echo "File changed!"
echo "Press any key to exit..."
read -r -n1 -s
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
4 changes: 2 additions & 2 deletions Interface_scripts/create_gcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ read -r -p "Are you sure you want to create a custom start gcode? (Y/n) " respon
if [[ "$response1" == [Nn] ]]; then
echo "Exiting..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi

Expand All @@ -41,4 +41,4 @@ nano ${filename}
echo " "
echo "Exiting..."
read -r -n1 -s
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
8 changes: 4 additions & 4 deletions Interface_scripts/edit_gcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ else
echo "Directory is empty..."
echo "Exiting..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi

Expand All @@ -34,7 +34,7 @@ read -r -p "If you want to exit, press enter. " filename
if [[ "$filename" == "" ]]; then
echo "Exiting..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi

Expand All @@ -47,7 +47,7 @@ if [[ ! -f "$filename" ]]; then
echo "File not found: $filename"
echo "Exiting..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
fi

# Inform user about exiting with ctrl+x
Expand All @@ -64,4 +64,4 @@ nano ${filename}
echo " "
echo "Exiting..."
read -r -n1 -s
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
4 changes: 2 additions & 2 deletions Interface_scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ read -r -p "Are you sure you want to proceed? (y/N)" response1
if [[ "$response1" == [Nn] ]]; then
echo "Exiting..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
bash $kpr/Interface_scripts/menu.sh home
bash "$kpr/Interface_scripts/menu.sh" home
exit 0
fi

Expand Down Expand Up @@ -72,5 +72,5 @@ echo "Installation finished!"
echo "Press any key to exit..."
read -r -n1 -s

$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
39 changes: 26 additions & 13 deletions Interface_scripts/make_restarted_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ clear
kpr="/home/$USER/Klipper_Power_Resume"

# Set the path to the log file
logpath="$kpr/log.txt"
dynamic_logpath="$kpr/dynamic_log.txt"

# Ask user the name of the file that need to be restarted
echo "Please write the name of the file you want to restart."
Expand All @@ -21,12 +21,12 @@ read -r -p "Please input the filename: " originalfilepath
if [[ "$originalfilepath" == "" ]]; then
echo "Exiting..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi

# Check if the filename has an extension
if [[ $originalfilepath == *.* ]]; then
if [[ $originalfilepath == *.gcode ]]; then
# If it has an extension, do not add an extension
originalfilepath="/home/$USER/printer_data/gcodes/$originalfilepath"
else
Expand All @@ -38,7 +38,7 @@ fi
if [[ ! -f "$originalfilepath" ]]; then
echo "File not found: $originalfilepath" # Error message if file not found
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi

Expand Down Expand Up @@ -73,7 +73,7 @@ if [[ "$starttype" == [Nn] ]]; then
echo "File not found: $startfilepath"
echo "Press any key to exit..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi
else
Expand All @@ -91,17 +91,30 @@ else
gcode="M190 S$bed_temp \nG28 \nM109 S$extruder_temp \nUNLOG_FILE"
fi

echo ""
echo "How fast do you want your printer to be moving when it is first started? (mm/s)"
read -r -p "If you don't want to specify a speed just press enter, and then the speed will be 100 mm/s. " speed

if [[ "$speed" =~ ^[0-9]+$ ]]; then
speed=$(( speed * 60 ))
else
echo "Your input is not good, the speed will be set to 100 mm/s..."
speed=6000
echo "Press any key to continue..."
read -r -n1 -s
fi

echo ""

# Get the linenumber where the printer stopped
linenumber=$(sed -n '2p' $logpath)
linenumber=$(sed -n '1p' $dynamic_logpath)

# Get the last recorded printer position
printerx=$(sed -n '3p' $logpath)
printery=$(sed -n '4p' $logpath)
printerz=$(sed -n '5p' $logpath)

speed=$(sed -n '6p' $logpath)
printerx=$(sed -n '2p' $dynamic_logpath)
printery=$(sed -n '3p' $dynamic_logpath)
printerz=$(sed -n '4p' $dynamic_logpath)

move="G0 F${speed} X${printerx} Y${printery} \nG0 Z${printerz} F150 \nG0 F${speed}"
move="G0 F${speed} X${printerx} Y${printery} \nG0 F150 Z${printerz} \nG0 F${speed}"

# Ask how many lines were skipped between logs
read -r -p "How many lines were skipped in between logs? " skippedlines
Expand Down Expand Up @@ -172,5 +185,5 @@ if [[ $run == [Yy] ]]; then
echo SDCARD_PRINT_FILE FILENAME=$filename > ~/printer_data/comms/klippy.serial
fi

$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
2 changes: 1 addition & 1 deletion Interface_scripts/menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ kpr="/home/$USER/Klipper_Power_Resume"

if [ $1 == "restart" ]; then
# Check if the last print was finished or not
finished=$(sed -n '1p' $kpr/log.txt)
finished=$(sed -n '1p' $kpr/static_log.txt)

if ! [ "$finished" == "Finished" ]; then
read -r -p "Do you want to restart your last print? (Y/n) " restart
Expand Down
38 changes: 26 additions & 12 deletions Interface_scripts/restart_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ clear
kpr="/home/$USER/Klipper_Power_Resume"

# Set the path to the log file
logpath="$kpr/log.txt"
dynamic_logpath="$kpr/dynamic_log.txt"
static_logpath="$kpr/static_log.txt"

originalfilepath=$(sed -n '1p' $logpath)
originalfilepath=$(sed -n '1p' $static_logpath)

# Check if the file exists
if [[ ! -f "$originalfilepath" ]]; then
echo "File not found: $originalfilepath" # Error message if file not found
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi

Expand Down Expand Up @@ -48,7 +49,7 @@ if [[ "$starttype" == [Nn] ]]; then
echo "File not found: $startfilepath"
echo "Press any key to exit..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi
else
Expand All @@ -66,17 +67,30 @@ else
gcode="M190 S$bed_temp \nG28 \nM109 S$extruder_temp \nUNLOG_FILE"
fi

echo ""
echo "How fast do you want your printer to be moving when it is first started? (mm/s)"
read -r -p "If you don't want to specify a speed just press enter, and then the speed will be 100 mm/s. " speed

if [[ "$speed" =~ ^[0-9]+$ ]]; then
speed=$(( speed * 60 ))
else
echo "Your input is not good, the speed will be set to 100 mm/s..."
speed=6000
echo "Press any key to continue..."
read -r -n1 -s
fi

echo ""

# Get the linenumber where the printer stopped
linenumber=$(sed -n '2p' $logpath)
linenumber=$(sed -n '1p' $dynamic_logpath)

# Get the last recorded printer position
printerx=$(sed -n '3p' $logpath)
printery=$(sed -n '4p' $logpath)
printerz=$(sed -n '5p' $logpath)

speed=$(sed -n '6p' $logpath)
printerx=$(sed -n '2p' $dynamic_logpath)
printery=$(sed -n '3p' $dynamic_logpath)
printerz=$(sed -n '4p' $dynamic_logpath)

move="G0 F${speed} X${printerx} Y${printery} \nG0 Z${printerz} F150 \nG0 F${speed}"
move="G0 F${speed} X${printerx} Y${printery} \nG0 F150 Z${printerz} \nG0 F${speed}"


# Ask how many lines were skipped between logs
Expand Down Expand Up @@ -140,7 +154,7 @@ echo ""

read -r -p "Do you want to restart the print now? (y/N) " run

echo "Finished" > $kpr/log.txt
echo "Finished" > $kpr/static_log.txt

filename=$(basename newfilepath)

Expand Down
2 changes: 1 addition & 1 deletion Interface_scripts/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ read -r -p "Are you sure you want to uninstall? You will have to redownload if y
if [[ "$response1" == [Nn] ]]; then
echo "Exiting..."
read -r -n1 -s # Wait for a keypress to prevent immediate exit
$kpr/Interface_scripts/menu.sh home
"$kpr/Interface_scripts/menu.sh" home
exit 0
fi
echo " "
Expand Down
5 changes: 4 additions & 1 deletion Roadmap/v3.2.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

| Tasks | Status |
| ----- | ------ |
| Use 2 log files instead of one; 1 static file, and 1 dynamic file | ✗ |
| Use 2 log files instead of one; 1 static file, and 1 dynamic file | ✓ |
| Fix bug where you can not input a file without .gcode when making _restarted file | ✓ |
| Fix error "ome: command not found" when going back to main menu | ✓ |
| Logging speed add too much time, remove the logging and use a user inputed speed | ✓ |

For the 2 log files, this is the difference:

Expand Down
File renamed without changes.
7 changes: 2 additions & 5 deletions finished.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash

# Truncate the file to clear it
> "/home/$USER/Klipper_Power_Resume/log.txt"

# Echo "finish" to the cleared file
echo "Finished" >> "/home/$USER/Klipper_Power_Resume/log.txt"
# Echo "Finished" to the static_log file
echo "Finished" > "/home/$USER/Klipper_Power_Resume/static_log.txt"
2 changes: 1 addition & 1 deletion kpr.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

bash /home/$USER/Klipper_Power_Resume/Interface_scripts/menu.sh restart
bash "/home/$USER/Klipper_Power_Resume/Interface_scripts/menu.sh" restart
exit 0
16 changes: 4 additions & 12 deletions log.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
#!/bin/bash

log_path="/home/$USER/Klipper_Power_Resume/log.txt"
log_path="/home/$USER/Klipper_Power_Resume/dynamic_log.txt"

file_path=$(sed -n '1p' $log_path)

linenumber=$(sed -n '2p' $log_path)
linenumber=$(sed -n '1p' $log_path)

linenumber=$((linenumber + 1))

x=$1
y=$2
z=$3

speed=$4
speed=$(( speed * 60 ))

truncate -s 0 $log_path

echo $file_path > $log_path

echo $linenumber >> $log_path
echo $linenumber > $log_path

echo $x >> $log_path
echo $y >> $log_path
echo $z >> $log_path
echo $speed >> $log_path
echo $z >> $log_path
4 changes: 2 additions & 2 deletions logger.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ verbose: False

[gcode_macro LOG_FILE]
gcode:
{% set log = printer.gcode_move %}
RUN_SHELL_COMMAND CMD=log_path PARAMS="{log.gcode_position.x} {log.gcode_position.y} {log.gcode_position.z} {log.speed}"
{% set position = printer.gcode_move.gcode_position %}
RUN_SHELL_COMMAND CMD=log_path PARAMS="{position.x} {position.y} {position.z}"

[gcode_shell_command print_finished]
command: sh /home/USER/Klipper_Power_Resume/finished.sh
Expand Down
Empty file added static_log.txt
Empty file.
4 changes: 2 additions & 2 deletions unlog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Clear log.txt and log file path to it
file_path=$1
echo "$file_path" > /home/$USER/Klipper_Power_Resume/log.txt
echo 0 >> /home/$USER/Klipper_Power_Resume/log.txt
echo "$file_path" > /home/$USER/Klipper_Power_Resume/static_log.txt
echo 0 > /home/$USER/Klipper_Power_Resume/dynamic_log.txt

0 comments on commit 21ec469

Please sign in to comment.