Skip to content

Commit

Permalink
Fix #99
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed May 10, 2024
1 parent ae34e91 commit d75cbb6
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ int klipper_request_consecutive_fail_count = 999;
char filename_buff[512] = {0};
SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
const long data_update_interval = 780;
unsigned char lock_absolute_relative_mode_swap = 0;

void semaphore_init(){
freezeRenderThreadSemaphore = xSemaphoreCreateMutex();
Expand Down Expand Up @@ -82,25 +83,29 @@ void move_printer(const char* axis, float amount, bool relative) {

char gcode[64];
const char* extra = (amount > 0) ? "+" : "";
const char* start = "";
const char* end = "";

bool absolute_coords = printer.absolute_coords;

if (absolute_coords && relative) {
send_gcode(true, "G91");
start = "G91\n";
}
else if (!absolute_coords && !relative) {
send_gcode(true, "G90");
start = "G90\n";
}

sprintf(gcode, "G1 %s%s%.3f F6000", axis, extra, amount);
send_gcode(true, gcode);

if (absolute_coords && relative) {
send_gcode(true, "G90");
end = "\nG90";
}
else if (!absolute_coords && !relative) {
send_gcode(true, "G91");
end = "\nG91";
}

sprintf(gcode, "%sG1 %s%s%.3f F6000%s", start, axis, extra, amount, end);
send_gcode(true, gcode);

lock_absolute_relative_mode_swap = 2;
}

int last_slicer_time_query = -15000;
Expand Down Expand Up @@ -192,7 +197,16 @@ void fetch_printer_data()
printer.gcode_offset[1] = status["gcode_move"]["homing_origin"][1];
printer.gcode_offset[2] = status["gcode_move"]["homing_origin"][2];
bool absolute_coords = status["gcode_move"]["absolute_coordinates"];
printer.absolute_coords = absolute_coords == true;

if (lock_absolute_relative_mode_swap > 0)
{
lock_absolute_relative_mode_swap--;
}
else
{
printer.absolute_coords = absolute_coords == true;
}

printer.speed_mult = status["gcode_move"]["speed_factor"];
printer.extrude_mult = status["gcode_move"]["extrude_factor"];
printer.feedrate_mm_per_s = status["gcode_move"]["speed"];
Expand Down

0 comments on commit d75cbb6

Please sign in to comment.