forked from electro/esp-irblaster
smarter speed logic
This commit is contained in:
+16
-9
@@ -99,8 +99,8 @@ static void timerCallback()
|
|||||||
cels_t tout = act_temp2();
|
cels_t tout = act_temp2();
|
||||||
|
|
||||||
uint16_t old_tempSerial = gState.tempSerial;
|
uint16_t old_tempSerial = gState.tempSerial;
|
||||||
float old_tin = gState.t_actual_in;
|
// float old_tin = gState.t_actual_in;
|
||||||
float old_tout = gState.t_actual_out;
|
// float old_tout = gState.t_actual_out;
|
||||||
|
|
||||||
gState.tempSerial = act_temps_serial();
|
gState.tempSerial = act_temps_serial();
|
||||||
gState.t_actual_in = tin;
|
gState.t_actual_in = tin;
|
||||||
@@ -108,6 +108,18 @@ static void timerCallback()
|
|||||||
|
|
||||||
gState.valid_t_actual_in = gState.valid_t_actual_out = tempSensorsOk;
|
gState.valid_t_actual_in = gState.valid_t_actual_out = tempSensorsOk;
|
||||||
|
|
||||||
|
if (gState.tempSerial != old_tempSerial) {
|
||||||
|
// measuring speed of temp change
|
||||||
|
for (int i = NUM_PREVIOUS_T_INS - 1; i > 0; i--) {
|
||||||
|
gState.previous_t_ins[i] = gState.previous_t_ins[i - 1];
|
||||||
|
}
|
||||||
|
if (gState.real_direction == MOTOR_DIR_IN) {
|
||||||
|
gState.previous_t_ins[0] = tin;
|
||||||
|
} else {
|
||||||
|
gState.previous_t_ins[0] = tout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// posun rolety
|
// posun rolety
|
||||||
if (gAct.blind) {
|
if (gAct.blind) {
|
||||||
if (gState.blind_position < gSettings.blind_time) {
|
if (gState.blind_position < gSettings.blind_time) {
|
||||||
@@ -218,14 +230,9 @@ static void timerCallback()
|
|||||||
// Max time elapsed, switch even if the condition was not reached
|
// Max time elapsed, switch even if the condition was not reached
|
||||||
do_switch = true;
|
do_switch = true;
|
||||||
} else {
|
} else {
|
||||||
if (!gSettings.summer_mode && gState.tempSerial != old_tempSerial) {
|
if (!gSettings.summer_mode) {
|
||||||
// expecting some change in temps
|
// expecting some change in temps
|
||||||
float speed;
|
float speed = absf(gState.previous_t_ins[NUM_PREVIOUS_T_INS - 1] - gState.previous_t_ins[0]) / (float)NUM_PREVIOUS_T_INS;
|
||||||
if (gState.real_direction == MOTOR_DIR_IN) {
|
|
||||||
speed = absf(tin - old_tin);
|
|
||||||
} else {
|
|
||||||
speed = absf(tout - old_tout);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (speed < gSettings.t_stop_speed) {
|
if (speed < gSettings.t_stop_speed) {
|
||||||
ESP_LOGW(TAG, "Near-equilibrium reached, change dir!");
|
ESP_LOGW(TAG, "Near-equilibrium reached, change dir!");
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ enum recup_mode {
|
|||||||
RECUP_MODE_TEMP = 1,
|
RECUP_MODE_TEMP = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define NUM_PREVIOUS_T_INS 5
|
||||||
|
|
||||||
struct FanControlState {
|
struct FanControlState {
|
||||||
/**
|
/**
|
||||||
@@ -57,6 +58,8 @@ struct FanControlState {
|
|||||||
uint16_t tempSerial;
|
uint16_t tempSerial;
|
||||||
cels_t t_actual_in;
|
cels_t t_actual_in;
|
||||||
cels_t t_actual_out;
|
cels_t t_actual_out;
|
||||||
|
// buffer used to calculate the current temp change speed
|
||||||
|
cels_t previous_t_ins[NUM_PREVIOUS_T_INS];
|
||||||
|
|
||||||
secs_t real_recup_time_in;
|
secs_t real_recup_time_in;
|
||||||
secs_t real_recup_time_out;
|
secs_t real_recup_time_out;
|
||||||
|
|||||||
Reference in New Issue
Block a user