aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/chelper
diff options
context:
space:
mode:
authorDmitry Butyugin <dmbutyugin@google.com>2021-10-24 17:00:40 +0200
committerKevinOConnor <kevin@koconnor.net>2021-10-26 16:14:50 -0400
commit54e21a7c26a65fa75f3b072e5f02d277321453ca (patch)
treecbc8e2c62b5fb2a978d7d66e88a9cf182f8d3026 /klippy/chelper
parentd5a7a7f00fc9b171cdd485fb26987f4aa6eb0f6b (diff)
downloadkutter-54e21a7c26a65fa75f3b072e5f02d277321453ca.tar.gz
kutter-54e21a7c26a65fa75f3b072e5f02d277321453ca.tar.xz
kutter-54e21a7c26a65fa75f3b072e5f02d277321453ca.zip
input_shaper: Factored out AxisInputShaper class
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Diffstat (limited to 'klippy/chelper')
-rw-r--r--klippy/chelper/__init__.py5
-rw-r--r--klippy/chelper/kin_shaper.c26
2 files changed, 15 insertions, 16 deletions
diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py
index b5eb12dd..66d701d3 100644
--- a/klippy/chelper/__init__.py
+++ b/klippy/chelper/__init__.py
@@ -140,9 +140,8 @@ defs_kin_extruder = """
defs_kin_shaper = """
double input_shaper_get_step_generation_window(int n, double a[]
, double t[]);
- int input_shaper_set_shaper_params(struct stepper_kinematics *sk
- , int n_x, double a_x[], double t_x[]
- , int n_y, double a_y[], double t_y[]);
+ int input_shaper_set_shaper_params(struct stepper_kinematics *sk, char axis
+ , int n, double a[], double t[]);
int input_shaper_set_sk(struct stepper_kinematics *sk
, struct stepper_kinematics *orig_sk);
struct stepper_kinematics * input_shaper_alloc(void);
diff --git a/klippy/chelper/kin_shaper.c b/klippy/chelper/kin_shaper.c
index efba013d..133f46a9 100644
--- a/klippy/chelper/kin_shaper.c
+++ b/klippy/chelper/kin_shaper.c
@@ -38,12 +38,12 @@ shift_pulses(struct shaper_pulses *sp)
sp->pulses[i].t -= ts;
}
-static void
+static int
init_shaper(int n, double a[], double t[], struct shaper_pulses *sp)
{
if (n < 0 || n > ARRAY_SIZE(sp->pulses)) {
sp->num_pulses = 0;
- return;
+ return -1;
}
int i;
double sum_a = 0.;
@@ -57,6 +57,7 @@ init_shaper(int n, double a[], double t[], struct shaper_pulses *sp)
}
sp->num_pulses = n;
shift_pulses(sp);
+ return 0;
}
@@ -192,21 +193,20 @@ shaper_note_generation_time(struct input_shaper *is)
}
int __visible
-input_shaper_set_shaper_params(struct stepper_kinematics *sk
- , int n_x, double a_x[], double t_x[]
- , int n_y, double a_y[], double t_y[])
+input_shaper_set_shaper_params(struct stepper_kinematics *sk, char axis
+ , int n, double a[], double t[])
{
+ if (axis != 'x' && axis != 'y')
+ return -1;
struct input_shaper *is = container_of(sk, struct input_shaper, sk);
- if (is->orig_sk->active_flags & AF_X)
- init_shaper(n_x, a_x, t_x, &is->sx);
+ struct shaper_pulses *sp = axis == 'x' ? &is->sx : &is->sy;
+ int status = 0;
+ if (is->orig_sk->active_flags & (axis == 'x' ? AF_X : AF_Y))
+ status = init_shaper(n, a, t, sp);
else
- is->sx.num_pulses = 0;
- if (is->orig_sk->active_flags & AF_Y)
- init_shaper(n_y, a_y, t_y, &is->sy);
- else
- is->sy.num_pulses = 0;
+ sp->num_pulses = 0;
shaper_note_generation_time(is);
- return 0;
+ return status;
}
double __visible