| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #ifndef _LINE_RAMP_H__
- #define _LINE_RAMP_H__
- typedef struct {
- float target;
- float interpolation;
- float step;
- float time;
- float time_dec;
- float min_step;
- }lineramp_t;
- static __INLINE void line_ramp_set_target(lineramp_t *line, float target) {
- if (line->target != target) {
- line->target = target;
- float delta = (line->target - line->interpolation);
- if (delta >= 0) {
- line->step = delta / line->time;
- }else {
- line->step = -delta / line->time_dec;
- }
- if ((line->min_step > 0) && (line->step < line->min_step)) {
- line->step = line->min_step;
- }
- }
- }
- static __INLINE void line_ramp_init(lineramp_t *line, float time) {
- line->target = 0;
- line->interpolation = 0;
- line->step = 0;
- line->min_step = 0;
- line->time_dec = line->time = time;
- }
- static __INLINE void line_ramp_reset(lineramp_t *line, float target) {
- line->target = target;
- line->interpolation = target;
- }
- static __INLINE void line_ramp_set_time(lineramp_t *line, float time) {
- line->time_dec = line->time = time;
- }
- static __INLINE void line_ramp_set_dectime(lineramp_t *line, float time) {
- line->time_dec = time;
- }
- static __INLINE void line_ramp_set_acctime(lineramp_t *line, float time) {
- line->time = time;
- }
- static __INLINE void line_ramp_set_minstep(lineramp_t *line, float step) {
- line->min_step = step;
- }
- static __INLINE float line_ramp_get_target(lineramp_t *line) {
- return line->target;
- }
- static __INLINE float line_ramp_get_interp(lineramp_t *line) {
- return line->interpolation;
- }
- static __INLINE void line_ramp_update(lineramp_t *line) {
- float delta = (line->target - line->interpolation);
- if (delta >= 0) {
- line->step = delta / line->time;
- }else {
- line->step = -delta / line->time_dec;
- }
- }
- static __INLINE float line_ramp_step(lineramp_t *line) {
- step_towards(&line->interpolation, line->target, line->step);
- return line->interpolation;
- }
- #endif /* _LINE_RAMP_H__ */
|