better log messages

master
Ondřej Hruška 2 years ago
parent 5f10760f0d
commit ebc4f7b165
  1. 79
      main/fancontrol.c
  2. 3
      main/fancontrol.h

@ -22,6 +22,7 @@ static void invalidate_temps();
void settings_blind_time_set(uint16_t blind_time) void settings_blind_time_set(uint16_t blind_time)
{ {
// if the blind is surely at the end
bool nadoraz = (gState.blind_position >= gSettings.blind_time) || (gState.blind_position >= blind_time); bool nadoraz = (gState.blind_position >= gSettings.blind_time) || (gState.blind_position >= blind_time);
gSettings.blind_time = blind_time; gSettings.blind_time = blind_time;
@ -76,6 +77,18 @@ void fancontrol_init()
xTaskCreate(fanctltask, "fc", FCTL_TASK_STACK, NULL, FCTL_TASK_PRIO, NULL); xTaskCreate(fanctltask, "fc", FCTL_TASK_STACK, NULL, FCTL_TASK_PRIO, NULL);
} }
static const char * vent_mode_labels[] = {
[VENT_MODE_OFF] = "OFF",
[VENT_MODE_FREE] = "FREE",
[VENT_MODE_OUT] = "OUT",
[VENT_MODE_IN] = "IN",
[VENT_MODE_RECUP] = "RECUP",
};
static const char * recup_mode_labels[] = {
[RECUP_MODE_TIME] = "TIME",
[RECUP_MODE_TEMP] = "TEMP",
};
static void timerCallback() static void timerCallback()
{ {
@ -128,7 +141,7 @@ static void timerCallback()
if (gState.blind_position >= gSettings.blind_time) { if (gState.blind_position >= gSettings.blind_time) {
act_motor_power_set(gState.set_power); act_motor_power_set(gState.set_power);
} }
if (gState.t_aggr_cnt > UNIDIR_T_MEAS_PERIOD) { if (gState.ramp >= gSettings.ramp_time * 2) {
end_temp_meas = true; end_temp_meas = true;
} }
break; break;
@ -138,7 +151,7 @@ static void timerCallback()
if (gState.blind_position >= gSettings.blind_time) { if (gState.blind_position >= gSettings.blind_time) {
act_motor_power_set(gState.set_power); act_motor_power_set(gState.set_power);
} }
if (gState.t_aggr_cnt > UNIDIR_T_MEAS_PERIOD) { if (gState.ramp >= gSettings.ramp_time * 2) {
end_temp_meas = true; end_temp_meas = true;
} }
break; break;
@ -163,7 +176,7 @@ static void timerCallback()
const int16_t ideal_delta = gState.t_indoor - gState.t_outdoor; const int16_t ideal_delta = gState.t_indoor - gState.t_outdoor;
int16_t stop_delta = ((int32_t) ideal_delta int16_t stop_delta = ((int32_t) ideal_delta
* (int32_t) (100 - gSettings.recup_factor)) / 100; * (int32_t) (100 - gSettings.recup_factor)) / 100;
int16_t delta; int16_t delta = 0;
bool allow_temp_switch = false; bool allow_temp_switch = false;
if (gState.real_direction == MOTOR_DIR_OUT) { if (gState.real_direction == MOTOR_DIR_OUT) {
@ -179,6 +192,8 @@ static void timerCallback()
} }
} }
ESP_LOGI(TAG, "Delta now %d, max %d, stop %d (RF %d%%), allow_switch %d Cx10", delta, ideal_delta, stop_delta, gSettings.recup_factor, allow_temp_switch);
if (allow_temp_switch) { if (allow_temp_switch) {
if (gSettings.summer_mode) { if (gSettings.summer_mode) {
if (ideal_delta < 0) { if (ideal_delta < 0) {
@ -227,22 +242,28 @@ static void timerCallback()
gState.instantaneous_vent_mode = gState.effective_vent_mode; gState.instantaneous_vent_mode = gState.effective_vent_mode;
} }
// Measure temperatures
int16_t t1 = act_temp1();
int16_t t2 = act_temp2();
gState.t_actual_in = t1;
gState.t_actual_out = t2;
gState.valid_t_actual_in = gState.valid_t_actual_out = tempSensorsOk;
if (end_temp_meas) { if (end_temp_meas) {
if (gState.t_aggr_cnt > 0) {
int16_t t1 = (int16_t) (gState.t1_aggr / (int32_t) gState.t_aggr_cnt);
int16_t t2 = (int16_t) (gState.t2_aggr / (int32_t) gState.t_aggr_cnt);
switch (gState.real_direction) { switch (gState.real_direction) {
case MOTOR_DIR_IN: case MOTOR_DIR_IN:
gState.t_outdoor = t2; gState.t_outdoor = gState.t_actual_out;
gState.t_inflow = t1; gState.t_inflow = gState.t_actual_in;
gState.valid_t_outdoor = gState.valid_t_inflow = true; gState.valid_t_outdoor = gState.valid_t_inflow = true;
if (gState.effective_vent_mode == VENT_MODE_IN) { if (gState.effective_vent_mode == VENT_MODE_IN) {
gState.valid_t_indoor = gState.valid_t_exhaust = false; gState.valid_t_indoor = gState.valid_t_exhaust = false;
} }
break; break;
case MOTOR_DIR_OUT: case MOTOR_DIR_OUT:
gState.t_indoor = t1; gState.t_indoor = gState.t_actual_in;
gState.t_exhaust = t2; gState.t_exhaust = gState.t_actual_out;
gState.valid_t_indoor = gState.valid_t_exhaust = true; gState.valid_t_indoor = gState.valid_t_exhaust = true;
if (gState.effective_vent_mode == VENT_MODE_OUT) { if (gState.effective_vent_mode == VENT_MODE_OUT) {
gState.valid_t_outdoor = gState.valid_t_inflow = false; gState.valid_t_outdoor = gState.valid_t_inflow = false;
@ -250,40 +271,13 @@ static void timerCallback()
break; break;
} }
} }
gState.t1_aggr = gState.t2_aggr = 0;
gState.t_aggr_cnt = 0;
}
// Measure temperatures
int16_t t1 = act_temp1();
int16_t t2 = act_temp2();
gState.t_actual_in = t1;
gState.t_actual_out = t2;
gState.valid_t_actual_in = gState.valid_t_actual_out = tempSensorsOk;
if (gState.effective_vent_mode == VENT_MODE_IN
|| gState.effective_vent_mode == VENT_MODE_OUT
|| gState.effective_vent_mode == VENT_MODE_RECUP) {
if (gAct.dir == gState.real_direction
&& gState.ramp >= gSettings.ramp_time) {
gState.t1_aggr += t1;
gState.t2_aggr += t2;
gState.t_aggr_cnt++;
}
}
ESP_LOGI(TAG, ESP_LOGI(TAG,
"Mode %d (ef %d, inst %d), Dir %d (real %d), PW %d (ramp %d), Blind %d (ramp %d)", "%s (ef %s, inst %s), rt %ds %d%%m, Tid %d%s, Tod %d%s, Tit %d%s, Teh %d%s, T1 %d%s, T2 %d%s Cx10",
gState.set_vent_mode, gState.effective_vent_mode, gState.instantaneous_vent_mode, vent_mode_labels[gState.set_vent_mode], vent_mode_labels[gState.effective_vent_mode], vent_mode_labels[gState.instantaneous_vent_mode],
gAct.dir, gState.real_direction, gState.run_time,
gAct.power, gState.ramp, gAct.power,
gAct.blind, gState.blind_position
);
ESP_LOGI(TAG,
"Tin %d%s, Tout %d%s, T<- %d%s, T-> %d%s, T1 %d%s, T2 %d%s",
gState.t_indoor, gState.t_indoor,
gState.valid_t_indoor ? "" : "!", gState.valid_t_indoor ? "" : "!",
gState.t_outdoor, gState.t_outdoor,
@ -308,7 +302,6 @@ void fan_set_vent_mode(enum ventilation_mode mode)
} }
gState.set_vent_mode = mode; gState.set_vent_mode = mode;
gState.t1_aggr = gState.t2_aggr = gState.t_aggr_cnt = 0;
if (gState.set_power != 0 || mode == VENT_MODE_FREE) { if (gState.set_power != 0 || mode == VENT_MODE_FREE) {
gState.effective_vent_mode = mode; gState.effective_vent_mode = mode;
} else if (gState.set_power == 0) { } else if (gState.set_power == 0) {

@ -82,9 +82,6 @@ struct FanControlState {
* "stav chodu motoru". 0=stop, ramp_time = jede. * "stav chodu motoru". 0=stop, ramp_time = jede.
*/ */
uint16_t ramp; uint16_t ramp;
int32_t t1_aggr;
int32_t t2_aggr;
uint32_t t_aggr_cnt;
// helper counters that increment hour counters when overflow // helper counters that increment hour counters when overflow
uint16_t uptime_secs; uint16_t uptime_secs;

Loading…
Cancel
Save