TM: Optimize temp_model_set_lag
Save about 20 bytes by rewriting the sample count check
This commit is contained in:
parent
b676d395e3
commit
ddf5147f9f
|
|
@ -2545,15 +2545,16 @@ void temp_model_set_warn_beep(bool enabled)
|
||||||
static void temp_model_set_lag(uint16_t ms)
|
static void temp_model_set_lag(uint16_t ms)
|
||||||
{
|
{
|
||||||
static const uint16_t intv_ms = (uint16_t)(TEMP_MGR_INTV * 1000);
|
static const uint16_t intv_ms = (uint16_t)(TEMP_MGR_INTV * 1000);
|
||||||
temp_model::data.L = ((ms + intv_ms/2) / intv_ms) * intv_ms;
|
uint16_t samples = ((ms + intv_ms/2) / intv_ms);
|
||||||
|
|
||||||
// ensure there is at least one lag sample for filtering
|
// ensure we do not exceed the maximum lag buffer and have at least one lag sample for filtering
|
||||||
if(temp_model::data.L < intv_ms)
|
if(samples < 1)
|
||||||
temp_model::data.L = intv_ms;
|
samples = 1;
|
||||||
|
else if(samples > TEMP_MODEL_MAX_LAG_SIZE)
|
||||||
|
samples = TEMP_MODEL_MAX_LAG_SIZE;
|
||||||
|
|
||||||
// do not exceed the maximum lag buffer
|
// round back to ms
|
||||||
if(temp_model::data.L > (intv_ms * TEMP_MODEL_MAX_LAG_SIZE))
|
temp_model::data.L = samples * intv_ms;
|
||||||
temp_model::data.L = intv_ms * TEMP_MODEL_MAX_LAG_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void temp_model_set_params(float P, float U, float V, float C, float D, int16_t L, float Ta_corr, float warn, float err)
|
void temp_model_set_params(float P, float U, float V, float C, float D, int16_t L, float Ta_corr, float warn, float err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue