blob: d952f7fe3dda75b90be1729184ce470187bbd2fb (
plain) (
tree)
|
|
#include "control.h"
#include <stdio.h>
int
cc_step(cc_t *cc, int steps)
{
float tmp = cc->mod;
cc->mod += steps * cc->step;
if (cc->value+cc->mod > cc->max) {
cc->mod = 0;
cc->target = cc->max;
} else if (cc->value+cc->mod < cc->min) {
cc->mod = 0;
cc->target = cc->min;
}
return cc->mod != tmp;
}
void
cc_prep(cc_t *cc)
{
if (cc->mod) {
cc->target = cc->value + cc->mod;
}
}
void
cc_fix(cc_t *cc)
{
cc->value = cc->target;
cc->mod = 0;
}
void
cc_reset(cc_t *cc)
{
cc->target = cc->def;
}
float
cc_iget(cc_t *cc, unsigned int i, unsigned int max)
{
/*
v/t_s: value/time start
v/t_e: value/time end
y = m*x + b
m = (v_e - v_s) / (t_e - t_s)
b = v_s - m * t_s
*/
float m = (cc->target - cc->value) / (max - 0);
float b = cc->value /* + m * 0 */;
return m * i + b;
}
const char *
cc_to_str(cc_t *cc)
{
static char buf[128];
snprintf(buf, sizeof buf, "[%s:v:%.2f_m:%.2f_t:%.2f]", cc->name, cc->value, cc->mod, cc->target);
return buf;
}
|