diff options
author | Dmitry Butyugin <dmbutyugin@google.com> | 2021-10-24 17:00:40 +0200 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2021-10-26 16:14:50 -0400 |
commit | 54e21a7c26a65fa75f3b072e5f02d277321453ca (patch) | |
tree | cbc8e2c62b5fb2a978d7d66e88a9cf182f8d3026 /klippy/chelper/kin_shaper.c | |
parent | d5a7a7f00fc9b171cdd485fb26987f4aa6eb0f6b (diff) | |
download | kutter-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/kin_shaper.c')
-rw-r--r-- | klippy/chelper/kin_shaper.c | 26 |
1 files changed, 13 insertions, 13 deletions
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 |