t5uid1: Improve Python 3 compatibility

This commit is contained in:
Desuuuu 2023-05-26 14:05:32 +02:00
parent bd9fd732f2
commit baae7f3a71
No known key found for this signature in database
GPG Key ID: 85943F4B2C2CE0DC
3 changed files with 19 additions and 19 deletions

View File

@ -109,8 +109,8 @@ script:
{ abort_page_switch() } { abort_page_switch() }
{% elif printer.toolhead.homed_axes == "xyz" %} {% elif printer.toolhead.homed_axes == "xyz" %}
{% set t5uid1 = printer.t5uid1 %} {% set t5uid1 = printer.t5uid1 %}
{% set x = (t5uid1.limits.x_min + t5uid1.limits.x_max) / 2 %} {% set x = (t5uid1.limits.x_min + t5uid1.limits.x_max) / 2.0 %}
{% set y = (t5uid1.limits.y_min + t5uid1.limits.y_max) / 2 %} {% set y = (t5uid1.limits.y_min + t5uid1.limits.y_max) / 2.0 %}
{% if printer.gcode_move.gcode_position.z < 10 %} {% if printer.gcode_move.gcode_position.z < 10 %}
G1 Z10 F600 G1 Z10 F600
{% endif %} {% endif %}
@ -136,8 +136,8 @@ script:
{ abort_page_switch() } { abort_page_switch() }
{% elif printer.toolhead.homed_axes == "xyz" %} {% elif printer.toolhead.homed_axes == "xyz" %}
{% set t5uid1 = printer.t5uid1 %} {% set t5uid1 = printer.t5uid1 %}
{% set x = (t5uid1.limits.x_min + t5uid1.limits.x_max) / 2 %} {% set x = (t5uid1.limits.x_min + t5uid1.limits.x_max) / 2.0 %}
{% set y = (t5uid1.limits.y_min + t5uid1.limits.y_max) / 2 %} {% set y = (t5uid1.limits.y_min + t5uid1.limits.y_max) / 2.0 %}
{% if printer.gcode_move.gcode_position.z < 5 %} {% if printer.gcode_move.gcode_position.z < 5 %}
G1 Z5 F600 G1 Z5 F600
{% endif %} {% endif %}

View File

@ -102,7 +102,7 @@ script:
{% if "z" not in printer.toolhead.homed_axes %} {% if "z" not in printer.toolhead.homed_axes %}
{% do set_message("Homing required") %} {% do set_message("Homing required") %}
{% else %} {% else %}
{% set offset = data|float / 10 ** 2 %} {% set offset = data|float / 100 %}
SET_GCODE_OFFSET Z={offset} MOVE=1 SET_GCODE_OFFSET Z={offset} MOVE=1
{% do start_routine("trigger_full_update") %} {% do start_routine("trigger_full_update") %}
{% endif %} {% endif %}
@ -236,7 +236,7 @@ script:
{% if "z" not in printer.toolhead.homed_axes %} {% if "z" not in printer.toolhead.homed_axes %}
{% do set_message("Homing required") %} {% do set_message("Homing required") %}
{% else %} {% else %}
{% set offset = data|float / 10 ** 2 %} {% set offset = data|float / 100 %}
SET_GCODE_OFFSET Z={offset} MOVE=1 SET_GCODE_OFFSET Z={offset} MOVE=1
{% do start_routine("trigger_full_update") %} {% do start_routine("trigger_full_update") %}
{% endif %} {% endif %}
@ -289,8 +289,8 @@ script:
{% set hop = 5 %} {% set hop = 5 %}
{% set t5uid1 = printer.t5uid1 %} {% set t5uid1 = printer.t5uid1 %}
{% if data == 1 %} {% if data == 1 %}
{% set x = (t5uid1.limits.x_max - t5uid1.limits.x_min + t5uid1.limits.x_min_inset - t5uid1.limits.x_max_inset) / 2 %} {% set x = (t5uid1.limits.x_max - t5uid1.limits.x_min + t5uid1.limits.x_min_inset - t5uid1.limits.x_max_inset) / 2.0 %}
{% set y = (t5uid1.limits.y_max - t5uid1.limits.y_min + t5uid1.limits.y_min_inset - t5uid1.limits.y_max_inset) / 2 %} {% set y = (t5uid1.limits.y_max - t5uid1.limits.y_min + t5uid1.limits.y_min_inset - t5uid1.limits.y_max_inset) / 2.0 %}
{% elif data == 2 %} {% elif data == 2 %}
{% set x = t5uid1.limits.x_min + t5uid1.limits.x_min_inset %} {% set x = t5uid1.limits.x_min + t5uid1.limits.x_min_inset %}
{% set y = t5uid1.limits.y_min + t5uid1.limits.y_min_inset %} {% set y = t5uid1.limits.y_min + t5uid1.limits.y_min_inset %}
@ -442,7 +442,7 @@ script:
{% do set_message("Homing required") %} {% do set_message("Homing required") %}
{% else %} {% else %}
{% set t5uid1 = printer.t5uid1 %} {% set t5uid1 = printer.t5uid1 %}
{% set pos = data|float / 10 ** 1 %} {% set pos = data|float / 10 %}
{% if pos < t5uid1.limits.x_min %} {% if pos < t5uid1.limits.x_min %}
{% set pos = t5uid1.limits.x_min %} {% set pos = t5uid1.limits.x_min %}
{% elif pos > t5uid1.limits.x_max %} {% elif pos > t5uid1.limits.x_max %}
@ -465,7 +465,7 @@ script:
{% do set_message("Homing required") %} {% do set_message("Homing required") %}
{% else %} {% else %}
{% set t5uid1 = printer.t5uid1 %} {% set t5uid1 = printer.t5uid1 %}
{% set pos = data|float / 10 ** 1 %} {% set pos = data|float / 10 %}
{% if pos < t5uid1.limits.y_min %} {% if pos < t5uid1.limits.y_min %}
{% set pos = t5uid1.limits.y_min %} {% set pos = t5uid1.limits.y_min %}
{% elif pos > t5uid1.limits.y_max %} {% elif pos > t5uid1.limits.y_max %}
@ -488,7 +488,7 @@ script:
{% do set_message("Homing required") %} {% do set_message("Homing required") %}
{% else %} {% else %}
{% set t5uid1 = printer.t5uid1 %} {% set t5uid1 = printer.t5uid1 %}
{% set pos = data|float / 10 ** 1 %} {% set pos = data|float / 10 %}
{% if pos < t5uid1.limits.z_min %} {% if pos < t5uid1.limits.z_min %}
{% set pos = t5uid1.limits.z_min %} {% set pos = t5uid1.limits.z_min %}
{% elif pos > t5uid1.limits.z_max %} {% elif pos > t5uid1.limits.z_max %}

View File

@ -44,7 +44,7 @@ CONTROL_TYPES = {
def map_value_range(x, in_min, in_max, out_min, out_max): def map_value_range(x, in_min, in_max, out_min, out_max):
return int(round((x - in_min) return int(round((x - in_min)
* (out_max - out_min) * (out_max - out_min)
/ (in_max - in_min) // (in_max - in_min)
+ out_min)) + out_min))
def get_duration(seconds): def get_duration(seconds):
@ -52,9 +52,9 @@ def get_duration(seconds):
seconds = int(seconds) seconds = int(seconds)
if seconds < 0: if seconds < 0:
seconds = 0 seconds = 0
minutes = seconds / 60 minutes = seconds // 60
hours = minutes / 60 hours = minutes // 60
days = hours / 24 days = hours // 24
days %= 365 days %= 365
hours %= 24 hours %= 24
minutes %= 60 minutes %= 60
@ -830,10 +830,10 @@ class T5UID1:
and self._z_max < z_max and self._z_max < z_max
and self._z_max > z_min): and self._z_max > z_min):
z_max = self._z_max z_max = self._z_max
x_min_inset = min(self._x_min_inset, (x_max - x_min) / 2) x_min_inset = min(self._x_min_inset, (x_max - x_min) / 2.0)
x_max_inset = min(self._x_max_inset, (x_max - x_min) / 2) x_max_inset = min(self._x_max_inset, (x_max - x_min) / 2.0)
y_min_inset = min(self._y_min_inset, (y_max - y_min) / 2) y_min_inset = min(self._y_min_inset, (y_max - y_min) / 2.0)
y_max_inset = min(self._y_max_inset, (y_max - y_min) / 2) y_max_inset = min(self._y_max_inset, (y_max - y_min) / 2.0)
return { return {
'x_min': x_min, 'x_min': x_min,
'x_max': x_max, 'x_max': x_max,